summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-07-28 15:32:14 (EDT)
committerpelder2006-07-28 15:32:14 (EDT)
commit3574cd8017fe41298997e26c0fd8e35b9583a65e (patch)
tree893b80f08ba2017368362c5ee01873e5a1749c01
parent6699bf3fb5a6fd6c0ac45a513ddab2af4bec4a97 (diff)
downloadorg.eclipse.jet-3574cd8017fe41298997e26c0fd8e35b9583a65e.zip
org.eclipse.jet-3574cd8017fe41298997e26c0fd8e35b9583a65e.tar.gz
org.eclipse.jet-3574cd8017fe41298997e26c0fd8e35b9583a65e.tar.bz2
[147714] Allow namespace-less tags that expect no content to appear as <tag ...> as well the standard <tag .../>
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java44
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java2
-rw-r--r--tests/org.eclipse.jet.tests/data/bug147714.jet11
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java43
4 files changed, 83 insertions, 17 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 4bb2ef0..b50d4cf 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
@@ -572,27 +572,39 @@ class ASTCompilerParseListener implements JETParseEventListener2
TagDefinition td = tagLibManager.getTagDefinition(tagName);
- XMLBodyElement decl = ast.createXMLBodyElement(
- start.getLine(),
- start.getCol(),
- start.getCursor(),
- stop.getCursor(),
- tagName,
- attributeMap,
- td);
-
- if (elementStack.isEmpty())
+ if(!td.isContentAllowed() && tagName.indexOf(':') == -1)
{
- compilationUnit.getInternalBodyElements().addBodyElement(decl);
+ // bug 147714: for DPTK compatibility, allow empty tags to appear as <tagname ...> instead of <tagname .../>
+ // We only allow this for tags that have no namespace (as DPTK did not support namespaces).
+ recordProblem(ParseProblemSeverity.WARNING, Problem.TagCannotHaveContent,
+ JET2Messages.JET2Compiler_TagCannotHaveContent,
+ new Object [0], start.getCursor(), stop.getCursor(), start.getLine(), start.getCol());
+ handleXMLEmptyTag(tagName, start, stop, attributeMap);
}
else
{
- XMLBodyElement topElement = elementStack.peek();
-
- topElement.getInternalBodyElements().addBodyElement(decl);
+ XMLBodyElement decl = ast.createXMLBodyElement(
+ start.getLine(),
+ start.getCol(),
+ start.getCursor(),
+ stop.getCursor(),
+ tagName,
+ attributeMap,
+ td);
+
+ if (elementStack.isEmpty())
+ {
+ compilationUnit.getInternalBodyElements().addBodyElement(decl);
+ }
+ else
+ {
+ XMLBodyElement topElement = elementStack.peek();
+
+ topElement.getInternalBodyElements().addBodyElement(decl);
+ }
+
+ elementStack.push(decl);
}
-
- elementStack.push(decl);
}
/**
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java
index a3f4f85..3f2bbf4 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/taglib/TagDefinitionImpl.java
@@ -246,7 +246,7 @@ public final class TagDefinitionImpl implements TagDefinition
{
boolean allowed = false;
if (kind == CustomTagKind.FUNCTION || kind == CustomTagKind.CONTAINER || kind == CustomTagKind.CONDITIONAL
- || kind == CustomTagKind.ITERATING)
+ || kind == CustomTagKind.ITERATING || kind == CustomTagKind.OTHER)
{
allowed = true;
}
diff --git a/tests/org.eclipse.jet.tests/data/bug147714.jet b/tests/org.eclipse.jet.tests/data/bug147714.jet
new file mode 100644
index 0000000..ec12e85
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/bug147714.jet
@@ -0,0 +1,11 @@
+<%-- Bug 147714 requests the JET compiler to treat <tag ...> as <tag .../> if tag is an emptyTag.
+This is for compatibility with DPTK: http://www.alphaworks.ibm.com/tech/dptk.
+Since DPTK does not use namespace prefixes, the fix only applies to tags with not prefix.
+--%>
+<%@taglib id="org.eclipse.jet.controlTags" prefix="c" %>
+<%@taglib id="org.eclipse.jet.tests.TestLibrary" prefix="" %>
+
+<%-- line 8: expect error --%><c:get select="$foo">
+<%-- line 9: expect ok --%><c:get select="$foo"/>
+<%-- line 10: expect warning --%><nl>
+<%-- line 11: expect ok --%><nl/>
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
index 1339b0b..4034d98 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java
@@ -6,8 +6,11 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
@@ -20,11 +23,13 @@ import org.eclipse.jet.compiler.JET2Declaration;
import org.eclipse.jet.compiler.JET2Directive;
import org.eclipse.jet.compiler.JET2Expression;
import org.eclipse.jet.compiler.JET2Scriptlet;
+import org.eclipse.jet.compiler.Problem;
import org.eclipse.jet.compiler.TextElement;
import org.eclipse.jet.compiler.XMLBodyElement;
import org.eclipse.jet.compiler.XMLBodyElementEnd;
import org.eclipse.jet.compiler.XMLEmptyElement;
import org.eclipse.jet.internal.compiler.TemplateRunner;
+import org.eclipse.jet.internal.parser.ParseProblemSeverity;
import org.eclipse.jet.taglib.TagLibraryReference;
import org.eclipse.jet.tests.FileUtils;
@@ -253,4 +258,42 @@ public class TestJET2Parser extends TestCase {
}
+ public void testBug147714() throws MalformedURLException, FileNotFoundException, IOException {
+ String url = "platform:/plugin/org.eclipse.jet.tests/data/bug147714.jet";
+
+ InputStream is = getFileContentsAsStream(url);
+
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ List problems = new ArrayList(cu.getProblems());
+
+ assertEquals("Number of problems", 2, problems.size());
+
+ // problems are not guaranteed to be in line order (should they)
+ Collections.sort(problems, new Comparator() {
+
+ public int compare(Object arg0, Object arg1) {
+ Problem p0 = (Problem) arg0;
+ Problem p1 = (Problem) arg1;
+ int lineCompare = p0.getLineNumber() - p1.getLineNumber();
+ if(lineCompare == 0) {
+ return p0.getColOffset() - p1.getColOffset();
+ } else {
+ return lineCompare;
+ }
+ }});
+
+ Problem[] problem = (Problem[]) problems.toArray(new Problem[problems.size()]);
+
+
+ // This assertions correspond to comments in bug147714.jet
+ assertEquals("Problem 1 line number", 8, problem[0].getLineNumber());
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problem[0].getSeverity());
+
+ assertEquals("Problem 2 line number", 10, problem[1].getLineNumber());
+ assertEquals("Problem 2 severity", ParseProblemSeverity.WARNING, problem[1].getSeverity());
+
+
+ }
}