summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-06-01 11:41:20 (EDT)
committerpelder2006-06-01 11:41:20 (EDT)
commit760fa0da6aa11913e1c0ab161799827d19a5181f (patch)
treedf50d7c6f9fb1ddc4fc3b9c99cb28fc04b4e8a74
parent11ac38e9db82e5b4325738a1cfcaca9635724225 (diff)
downloadorg.eclipse.jet-760fa0da6aa11913e1c0ab161799827d19a5181f.zip
org.eclipse.jet-760fa0da6aa11913e1c0ab161799827d19a5181f.tar.gz
org.eclipse.jet-760fa0da6aa11913e1c0ab161799827d19a5181f.tar.bz2
[144774] Issue warning on tag that have a valid tag library prefix but an invalid name.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java5
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java6
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java24
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java23
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java2
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties1
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener2.java1
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java12
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java5
9 files changed, 75 insertions, 4 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
index 70c660e..4bb2ef0 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java
@@ -655,4 +655,9 @@ class ASTCompilerParseListener implements JETParseEventListener2
this.endPageProcessing();
}
+
+ public boolean isKnownInvalidTagName(String tagName)
+ {
+ return tagLibManager.isKnownInvalidTagName(tagName);
+ }
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java
index cfe7bb4..d87c8d5 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/Problem.java
@@ -110,6 +110,12 @@ public class Problem
*/
public static final int UnsupportedDirective = 15;
+ /**
+ * A tag that has a known tag library prefix, but is not a recognized name. Usually
+ * indicates a typographical error.
+ */
+ public static final int UnknownXMLTag = 16;
+
private final String originatingFileName;
private final int id;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java
index 636e2a7..dc68b15 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/TagLibraryUsageManager.java
@@ -146,6 +146,30 @@ public class TagLibraryUsageManager
return knownTag;
}
+ /**
+ * Test whether the tag name passed is known to be an invalid name by the manager. The tag name
+ * is known to be invalid if it has a known prefix, but an unknown unqualified tag name.
+ * @return <code>true</code> if the tag matches one of the libraries, <code>false</code> otherwise.
+ */
+ public boolean isKnownInvalidTagName(String tagName) {
+ boolean knownInvalidTagName = false;
+
+ int sepIndex = tagName.indexOf(':');
+ String prefix = sepIndex == -1 ? "" : tagName.substring(0, sepIndex); //$NON-NLS-1$
+ String tagNCName = sepIndex == -1 ? tagName : tagName.substring(sepIndex + 1);
+ String id = getLibraryIdFromPrefix(prefix.toLowerCase());
+ if (id != null)
+ {
+ TagLibrary tagLibrary = TagLibraryManager.getInstance().getTagLibrary(id);
+ if (tagLibrary != null && prefix.length() > 0)
+ {
+ knownInvalidTagName = !tagLibrary.hasTag(tagNCName);
+ }
+ }
+ return knownInvalidTagName;
+
+ }
+
public TagLibraryReference[] getTagLibraryReferences()
{
List result = new ArrayList(predefinedLibraryMap.size() + tagLibraries.size());
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java
index 8d5a054..bf07860 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java
@@ -18,7 +18,7 @@ package org.eclipse.jet.internal.compiler;
import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.emf.codegen.CodeGenPlugin;
@@ -80,7 +80,8 @@ public class XMLElementDelegate implements JETCoreElement
String tagName = reader.parseToken(false, false /*don't skip spaces*/);
- if (!jet2Listener.isKnownTag(tagName))
+ boolean knownInvalidTagName = jet2Listener.isKnownInvalidTagName(tagName);
+ if (!jet2Listener.isKnownTag(tagName) && !knownInvalidTagName)
{
reader.reset(start);
return false;
@@ -115,7 +116,8 @@ public class XMLElementDelegate implements JETCoreElement
}
else
{
- attributeMap = new HashMap();
+ // use Linked hash map to keep attributes in order of declaration
+ attributeMap = new LinkedHashMap();
reader.skipSpaces();
while (reader.peekChar() != '>' && reader.peekChar() != '/')
{
@@ -165,7 +167,20 @@ public class XMLElementDelegate implements JETCoreElement
}
reader.nextChar();
JETMark stop = reader.mark();
- if (isEmptyTag)
+ if(knownInvalidTagName)
+ {
+ jet2Listener.recordProblem(
+ ParseProblemSeverity.WARNING,
+ Problem.UnknownXMLTag,
+ JET2Messages.XMLElementDelegate_UnknownXMLTag,
+ new Object[] {tagName},
+ start.getCursor(),
+ stop.getCursor(),
+ start.getLine(), start.getCol());
+ reader.reset(start);
+ return false;
+ }
+ else if (isEmptyTag)
{
jet2Listener.handleXMLEmptyTag(tagName, start, stop, attributeMap);
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
index 5a71371..9e77691 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.java
@@ -97,6 +97,8 @@ public class JET2Messages extends NLS
public static String XMLElementDelegate_DuplicateAttribute;
+ public static String XMLElementDelegate_UnknownXMLTag;
+
public static String XPath_NoElementSelected;
public static String GetTag_NoResult;
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
index 142f5b7..aac3993 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/l10n/JET2Messages.properties
@@ -73,6 +73,7 @@ ProjectTemplateBundleSupplier_CouldNotRead=Could not be read: {0}
XMLElementDelegate_DuplicateAttribute=Duplicate attribute definition
+XMLElementDelegate_UnknownXMLTag=Unknown tag ''{0}''
XPath_NoElementSelected=The XPath expression in the "{0}" attribute did not return an element.
XPath_NoValueForAttribute=Could not find value for attribute "{0}"
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener2.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener2.java
index 422c628..469a112 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener2.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParseEventListener2.java
@@ -23,6 +23,7 @@ public interface JETParseEventListener2 extends JETParseEventListener
boolean isKnownTag(String tagName);
+ boolean isKnownInvalidTagName(String tagName);
/**
* Record a parsing problem.
* @param severity
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java
index b0db8b1..cb7fc25 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java
@@ -239,6 +239,18 @@ public class JETParser
throw new IllegalStateException();
}
}
+
+ public boolean isKnownInvalidTagName(String tagName)
+ {
+ if (delegate instanceof JETParseEventListener2)
+ {
+ return ((JETParseEventListener2)delegate).isKnownInvalidTagName(tagName);
+ }
+ else
+ {
+ throw new IllegalStateException();
+ }
+ }
}
/**
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java
index 24a3e62..247fc8b 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java
@@ -239,6 +239,11 @@ public class TestJETParser extends TestCase {
problems.add(new SavedProblem(severity, problemId, message, msgArgs, start, end, line));
}
+
+ public boolean isKnownInvalidTagName(String tagName) {
+ // TODO Auto-generated method stub
+ return false;
+ }
}
private AllJET2SyntaxListener doJET2Parse(String urlString) throws IOException, MalformedURLException, FileNotFoundException, JETException {