summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-08-01 15:28:39 (EDT)
committer pelder2006-08-01 15:28:39 (EDT)
commit4de576ab6dd7e46c7840cf0284873111d7ced7b3 (patch)
tree859a9b7794f172ec50c786ed3dc414f2759cdce9
parent0a56e57ddb7e15cb46ea567f381edf36a13f02f2 (diff)
downloadorg.eclipse.jet-4de576ab6dd7e46c7840cf0284873111d7ced7b3.zip
org.eclipse.jet-4de576ab6dd7e46c7840cf0284873111d7ced7b3.tar.gz
org.eclipse.jet-4de576ab6dd7e46c7840cf0284873111d7ced7b3.tar.bz2
[144781] Transform JETExceptions raised by the JET Parser into Problem instances with appropriate location information. Change messages issued in some cases to be more meaningful. Update Parser JUnits.
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/compiler/ASTCompilerParseListener.java13
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CommentElementDelegate.java10
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerErrorUtil.java90
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/DeclarationElementDelegate.java10
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/ErrorRedirectingCoreElementDelegate.java63
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/XMLElementDelegate.java26
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETParser.java31
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java2
-rw-r--r--tests/org.eclipse.jet.tests/data/attributeParsingErrors.jet6
-rw-r--r--tests/org.eclipse.jet.tests/data/unclosedXMLEnd.jet4
-rw-r--r--tests/org.eclipse.jet.tests/data/unclosedXMLStart.jet4
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJET2Parser.java189
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/compiler/TestJETParser.java15
13 files changed, 372 insertions, 91 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 f8e6911..96d516a 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
@@ -30,6 +30,7 @@ import java.util.Set;
import org.eclipse.emf.codegen.jet.JETException;
import org.eclipse.jet.internal.compiler.CommentElementDelegate;
import org.eclipse.jet.internal.compiler.DeclarationElementDelegate;
+import org.eclipse.jet.internal.compiler.ErrorRedirectingCoreElementDelegate;
import org.eclipse.jet.internal.compiler.XMLElementDelegate;
import org.eclipse.jet.internal.l10n.JET2Messages;
import org.eclipse.jet.internal.parser.JETCoreElement;
@@ -648,12 +649,12 @@ class ASTCompilerParseListener implements JETParseEventListener2
directive.getDirectives().add("start"); //$NON-NLS-1$
directive.getDirectives().add("end"); //$NON-NLS-1$
JETCoreElement[] coreElements = new JETCoreElement []{
- directive,
- new JETParser.Expression(),
- new CommentElementDelegate(),
- new DeclarationElementDelegate(),
- new JETParser.Scriptlet(),
- new XMLElementDelegate(), };
+ new ErrorRedirectingCoreElementDelegate(directive),
+ new ErrorRedirectingCoreElementDelegate(new JETParser.Expression()),
+ new ErrorRedirectingCoreElementDelegate(new CommentElementDelegate()),
+ new ErrorRedirectingCoreElementDelegate(new DeclarationElementDelegate()),
+ new ErrorRedirectingCoreElementDelegate(new JETParser.Scriptlet()),
+ new ErrorRedirectingCoreElementDelegate(new XMLElementDelegate()), };
parser = new JETParser(reader, this, coreElements);
this.beginPageProcessing();
try
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CommentElementDelegate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CommentElementDelegate.java
index a53a51d..12ba899 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CommentElementDelegate.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CommentElementDelegate.java
@@ -18,7 +18,6 @@
package org.eclipse.jet.internal.compiler;
-import org.eclipse.emf.codegen.CodeGenPlugin;
import org.eclipse.emf.codegen.jet.JETException;
import org.eclipse.jet.internal.parser.JETCoreElement;
import org.eclipse.jet.internal.parser.JETMark;
@@ -69,16 +68,19 @@ public class CommentElementDelegate implements JETCoreElement
{
return false;
}
+ JETMark elementStart = reader.mark();
reader.advance(elementOpen.length());
JETMark start = reader.mark();
JETMark stop = reader.skipUntil(elementClose);
if (stop == null)
{
- throw new JETException(CodeGenPlugin.getPlugin().getString(
- "jet.error.unterminated", new Object []{ elementOpen, reader.mark().toString() })); //$NON-NLS-1$
+ CompilerErrorUtil.recordUnterminatedElement(jet2Listener, elementClose, elementStart, reader);
+ }
+ else
+ {
+ jet2Listener.handleComment(start, stop);
}
- jet2Listener.handleComment(start, stop);
return true;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerErrorUtil.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerErrorUtil.java
new file mode 100644
index 0000000..a17858c
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/CompilerErrorUtil.java
@@ -0,0 +1,90 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.compiler;
+
+
+import java.text.MessageFormat;
+
+import org.eclipse.jet.compiler.Problem;
+import org.eclipse.jet.internal.l10n.JET2Messages;
+import org.eclipse.jet.internal.parser.JETMark;
+import org.eclipse.jet.internal.parser.JETParseEventListener2;
+import org.eclipse.jet.internal.parser.JETReader;
+import org.eclipse.jet.internal.parser.ParseProblemSeverity;
+
+
+/**
+ * Utility class to aid in handling file errors
+ */
+public class CompilerErrorUtil
+{
+
+ /**
+ *
+ */
+ private CompilerErrorUtil()
+ {
+ }
+
+ /**
+ * Record a parse error for a JET element whose close sequence is missing.
+ * @param listener the JETParseEventLister2
+ * @param expectedCloseSequence the expected close sequence
+ * @param elementStart the JETMark for the start of the element
+ * @param reader the current JETReader
+ */
+ public static void recordUnterminatedElement(
+ JETParseEventListener2 listener,
+ String expectedCloseSequence,
+ JETMark elementStart,
+ JETReader reader)
+ {
+ // FIXME: Note that we use XPath_Expected (text: Expected: {0}) because the message "jet.error.unterminated"
+ // in the codegen plug-in is incorrect.
+ listener.recordProblem(
+ ParseProblemSeverity.ERROR,
+ Problem.UnterminatedXMLTag,
+ JET2Messages.XPath_Expected,
+ new Object []{ expectedCloseSequence },
+ elementStart.getCursor(),
+ reader.mark().getCursor(),
+ elementStart.getLine(),
+ elementStart.getCol());
+
+ }
+
+ /**
+ * Return the formatted error message for an unterminated string.
+ * @param openSequence
+ * @param expectedCloseSequence
+ * @param reader
+ * @return
+ */
+ public static String getUnterminatedMessage(String openSequence, String expectedCloseSequence, JETReader reader) {
+ // This method encapsulates the retrieval of the 'unterminated' error message. Because this message is part
+ // of EMF Codegen, and it is incorect (it incorrectly uses the first argument twice), we centralize
+ // access to it, and implement the 'fix' once.
+ // This is the 'unfixed' code:
+// final String msg = CodeGenPlugin.getPlugin().getString(
+// "jet.error.unterminated", //$NON-NLS-1$
+// new Object []{ openSequence, reader.mark().toString() });
+
+ // FIXME: Note that we use XPath_Expected (text: Expected: {0}) because the message "jet.error.unterminated"
+ // in the codegen plug-in is incorrect.
+ return MessageFormat.format(JET2Messages.XPath_Expected, new Object[] {expectedCloseSequence});
+ }
+}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/DeclarationElementDelegate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/DeclarationElementDelegate.java
index 5323e81..ac83aac 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/DeclarationElementDelegate.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/DeclarationElementDelegate.java
@@ -17,7 +17,6 @@
package org.eclipse.jet.internal.compiler;
-import org.eclipse.emf.codegen.CodeGenPlugin;
import org.eclipse.emf.codegen.jet.JETException;
import org.eclipse.jet.internal.parser.JETCoreElement;
import org.eclipse.jet.internal.parser.JETMark;
@@ -54,16 +53,19 @@ public class DeclarationElementDelegate implements JETCoreElement
{
return false;
}
+ JETMark elementStart = reader.mark();
reader.advance(declOpen.length());
JETMark start = reader.mark();
JETMark stop = reader.skipUntil(declClose);
if (stop == null)
{
- throw new JETException(CodeGenPlugin.getPlugin().getString(
- "jet.error.unterminated", new Object []{ declOpen, reader.mark().toString() })); //$NON-NLS-1$
+ CompilerErrorUtil.recordUnterminatedElement(jet2Listener, declClose, elementStart, reader);
+ }
+ else
+ {
+ jet2Listener.handleDeclaration(start, stop);
}
- jet2Listener.handleDeclaration(start, stop);
return true;
}
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/ErrorRedirectingCoreElementDelegate.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/ErrorRedirectingCoreElementDelegate.java
new file mode 100644
index 0000000..6cf84fc
--- /dev/null
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/compiler/ErrorRedirectingCoreElementDelegate.java
@@ -0,0 +1,63 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+package org.eclipse.jet.internal.compiler;
+
+import org.eclipse.emf.codegen.jet.JETException;
+import org.eclipse.jet.compiler.Problem;
+import org.eclipse.jet.internal.parser.JETCoreElement;
+import org.eclipse.jet.internal.parser.JETMark;
+import org.eclipse.jet.internal.parser.JETParseEventListener;
+import org.eclipse.jet.internal.parser.JETParseEventListener2;
+import org.eclipse.jet.internal.parser.JETParser;
+import org.eclipse.jet.internal.parser.JETReader;
+import org.eclipse.jet.internal.parser.ParseProblemSeverity;
+
+/**
+ * A JETCoreElement that delegates its accept the the passed core element, but records any JETException
+ * as errors on a JETParseEventListener2.
+ */
+public class ErrorRedirectingCoreElementDelegate implements JETCoreElement
+{
+
+ private final JETCoreElement delegate;
+
+ public ErrorRedirectingCoreElementDelegate(JETCoreElement delegate) {
+ this.delegate = delegate;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jet.internal.parser.JETCoreElement#accept(org.eclipse.jet.internal.parser.JETParseEventListener, org.eclipse.jet.internal.parser.JETReader, org.eclipse.jet.internal.parser.JETParser)
+ */
+ public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser)
+ {
+ boolean isAccepted = true;
+ JETMark start = reader.mark();
+ try {
+ isAccepted = delegate.accept(listener, reader, parser);
+ }
+ catch(JETException e) {
+ if(listener instanceof JETParseEventListener2)
+ {
+ JETParseEventListener2 listener2 = (JETParseEventListener2)listener;
+ listener2.recordProblem(ParseProblemSeverity.ERROR, Problem.JETException, e.getLocalizedMessage(), new Object[0],
+ start.getCursor(), reader.mark().getCursor(), start.getLine(), start.getCol());
+ }
+ }
+ return isAccepted;
+ }
+
+}
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 bf07860..58ef03b 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
@@ -21,7 +21,6 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.eclipse.emf.codegen.CodeGenPlugin;
import org.eclipse.emf.codegen.jet.JETException;
import org.eclipse.jet.compiler.Problem;
import org.eclipse.jet.internal.l10n.JET2Messages;
@@ -92,17 +91,7 @@ public class XMLElementDelegate implements JETCoreElement
JETMark endTagMark = reader.skipUntil(XML_TAG_CLOSE);
if (endTagMark == null)
{
- Object[] msgArgs = new Object []{ elementOpen, reader.mark().toString() };
- String msg = CodeGenPlugin.getPlugin().getString("jet.error.unterminated", msgArgs); //$NON-NLS-1$
- JETMark errorMark = reader.mark();
- jet2Listener.recordProblem(
- ParseProblemSeverity.ERROR,
- Problem.UnterminatedXMLTag,
- msg,
- msgArgs,
- start.getCursor(),
- errorMark.getCursor(),
- start.getLine(), start.getCol());
+ CompilerErrorUtil.recordUnterminatedElement(jet2Listener, XML_TAG_CLOSE, start, reader);
return true;
}
@@ -152,18 +141,7 @@ public class XMLElementDelegate implements JETCoreElement
}
if (reader.peekChar() != '>')
{
- // jet2Listener.recordProblem(Severity.ERROR, );
- Object[] msgArgs = new Object []{ elementOpen, reader.mark().toString() };
- String msg = CodeGenPlugin.getPlugin().getString("jet.error.unterminated", msgArgs); //$NON-NLS-1$
- JETMark errorMark = reader.mark();
- jet2Listener.recordProblem(
- ParseProblemSeverity.ERROR,
- Problem.UnterminatedXMLTag,
- msg,
- msgArgs,
- start.getCursor(),
- errorMark.getCursor(),
- start.getLine(), start.getCol());
+ CompilerErrorUtil.recordUnterminatedElement(jet2Listener, ">", start, reader); //$NON-NLS-1$
}
reader.nextChar();
JETMark stop = reader.mark();
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 94d13c8..7be9a5d 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
@@ -79,6 +79,7 @@ import java.util.Map;
import org.eclipse.emf.codegen.CodeGenPlugin;
import org.eclipse.emf.codegen.jet.JETException;
+import org.eclipse.jet.internal.compiler.CompilerErrorUtil;
/**
@@ -388,7 +389,7 @@ public class JETParser
{
public boolean accept(JETParseEventListener listener, JETReader reader, JETParser parser) throws JETException
{
- String close, open, end_open = null;
+ String close, open;
Map attrs = null;
if (reader.matches(parser.getOpenScriptlet()))
@@ -403,28 +404,11 @@ public class JETParser
reader.advance(open.length());
- if (end_open != null)
- {
- attrs = reader.parseTagAttributes();
-
- reader.skipSpaces();
- if (!reader.matches(end_open))
- {
- throw new JETException(CodeGenPlugin.getPlugin().getString(
- "jet.error.unterminated", //$NON-NLS-1$
- new Object []{ open, reader.mark().toString() }));
- }
- reader.advance(end_open.length());
- reader.skipSpaces();
- }
-
JETMark start = reader.mark();
JETMark stop = reader.skipUntil(close);
if (stop == null)
{
- throw new JETException(CodeGenPlugin.getPlugin().getString(
- "jet.error.unterminated", //$NON-NLS-1$
- new Object []{ open, reader.mark().toString() }));
+ throw new JETException(CompilerErrorUtil.getUnterminatedMessage(open, close, reader));
}
listener.handleScriptlet(start, stop, attrs);
return true;
@@ -454,9 +438,7 @@ public class JETParser
JETMark stop = reader.skipUntil(close);
if (stop == null)
{
- throw new JETException(CodeGenPlugin.getPlugin().getString(
- "jet.error.unterminated", //$NON-NLS-1$
- new Object []{ open, reader.mark().toString() }));
+ throw new JETException(CompilerErrorUtil.getUnterminatedMessage(open, close, reader));
}
listener.handleExpression(start, stop, attrs);
return true;
@@ -555,9 +537,8 @@ public class JETParser
reader.skipSpaces();
if (!reader.matches(parser.getCloseDirective()))
{
- throw new JETException(CodeGenPlugin.getPlugin().getString(
- "jet.error.unterminated", //$NON-NLS-1$
- new Object []{ parser.getOpenDirective(), reader.mark().toString() }));
+ throw new JETException(CompilerErrorUtil.getUnterminatedMessage(parser.getOpenDirective(),
+ parser.getCloseDirective(), reader));
}
else
{
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java
index 5a8c95d..6742a44 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/internal/parser/JETReader.java
@@ -529,7 +529,7 @@ public class JETReader
skipSpaces();
if (peekChar() != '=')
{
- throw new JETException(CodeGenPlugin.getPlugin().getString("jet.error.attr.novalue", new Object []{ name, mark().toString() })); //$NON-NLS-1$
+ throw new JETException(CodeGenPlugin.getPlugin().getString("jet.error.param.novalue", new Object []{ name, mark().toString() })); //$NON-NLS-1$
}
attributeMarks[2] = mark(); // equals
nextChar();
diff --git a/tests/org.eclipse.jet.tests/data/attributeParsingErrors.jet b/tests/org.eclipse.jet.tests/data/attributeParsingErrors.jet
new file mode 100644
index 0000000..99bf3cc
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/data/attributeParsingErrors.jet
@@ -0,0 +1,6 @@
+<%@taglib prefix="c" id="org.eclipse.jet.controlTags"%>
+
+<%-- The following line is missing a double quote (") on the 'var' attribute --%>
+<c:iterate select="foo" var="bar>
+ some text parameterized by bar: <c:get select="$bar"/>
+</c:iterate> \ No newline at end of file
diff --git a/tests/org.eclipse.jet.tests/data/unclosedXMLEnd.jet b/tests/org.eclipse.jet.tests/data/unclosedXMLEnd.jet
index 188636c..08f095f 100644
--- a/tests/org.eclipse.jet.tests/data/unclosedXMLEnd.jet
+++ b/tests/org.eclipse.jet.tests/data/unclosedXMLEnd.jet
@@ -1,3 +1,3 @@
-<%@jet package="org.eclipse.emf.examples.test" class="Foo" %>
+<%@taglib id="org.eclipse.jet.controlTags" prefix="test" %>
-</test:start
+</test:include
diff --git a/tests/org.eclipse.jet.tests/data/unclosedXMLStart.jet b/tests/org.eclipse.jet.tests/data/unclosedXMLStart.jet
index d3e55e0..31f3ccf 100644
--- a/tests/org.eclipse.jet.tests/data/unclosedXMLStart.jet
+++ b/tests/org.eclipse.jet.tests/data/unclosedXMLStart.jet
@@ -1,3 +1,3 @@
-<%@jet package="org.eclipse.emf.examples.test" class="Foo" %>
+<%@taglib id="org.eclipse.jet.controlTags" prefix="test" %>
-<test:start attr="foo"
+<test:include template="foo"
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 1089556..cb59f25 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
@@ -258,7 +258,7 @@ public class TestJET2Parser extends TestCase {
}
- public void testBug147714() throws MalformedURLException, FileNotFoundException, IOException {
+ public void testXMLStartAsEmpty_bug147714() throws MalformedURLException, FileNotFoundException, IOException {
String url = "platform:/plugin/org.eclipse.jet.tests/data/bug147714.jet";
InputStream is = getFileContentsAsStream(url);
@@ -266,10 +266,169 @@ public class TestJET2Parser extends TestCase {
JET2CompilationUnit cu = new JET2CompilationUnit();
cu.parse(is, "UTF-8");
- List problems = new ArrayList(cu.getProblems());
+ Problem[] problems = getSortedProblems(cu);
+
+ assertEquals("Number of problems", 2, problems.length);
+
+
+ // This assertions correspond to comments in bug147714.jet
+ assertEquals("Problem 1 line number", 8, problems[0].getLineNumber());
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
+ assertEquals("Problem 1 id", Problem.MissingXmlEndTag, problems[0].getId());
+
+ assertEquals("Problem 2 line number", 10, problems[1].getLineNumber());
+ assertEquals("Problem 2 severity", ParseProblemSeverity.WARNING, problems[1].getSeverity());
+ assertEquals("Problem 2 id", Problem.TagInterpretedAsEmptyTag, problems[1].getId());
+
+
+ }
+
+ public void testUnclosedCommnetErrors() throws Exception {
+ String url = "platform:/plugin/org.eclipse.jet.tests/data/unclosedComment.jet";
+
+ InputStream is = getFileContentsAsStream(url);
+
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ Problem[] problems = getSortedProblems(cu);
+
+ assertEquals("Number of problems", 1, problems.length);
+
+
+ // This assertions correspond to comments in bug147714.jet
+ assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
+ assertEquals("Problem 1 id", Problem.UnterminatedXMLTag, problems[0].getId());
+
+ }
+
+ public void testUnclosedDeclarationErrors() throws Exception {
+ String url = "platform:/plugin/org.eclipse.jet.tests/data/unclosedDeclaration.jet";
+
+ InputStream is = getFileContentsAsStream(url);
+
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ Problem[] problems = getSortedProblems(cu);
+
+ assertEquals("Number of problems", 1, problems.length);
+
+
+ // This assertions correspond to comments in bug147714.jet
+ assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
+ assertEquals("Problem 1 id", Problem.UnterminatedXMLTag, problems[0].getId());
+
+ }
+
+ public void testUnclosedDirectiveErrors() throws Exception {
+ String url = "platform:/plugin/org.eclipse.jet.tests/data/unclosedDirective.jet";
+
+ InputStream is = getFileContentsAsStream(url);
+
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ Problem[] problems = getSortedProblems(cu);
+
+ assertEquals("Number of problems", 1, problems.length);
+
+
+ // This assertions correspond to comments in bug147714.jet
+ assertEquals("Problem 1 line number", 1, problems[0].getLineNumber());
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
+ assertEquals("Problem 1 id", Problem.JETException, problems[0].getId());
+
+ }
+
+ public void testUnclosedExpressionErrors() throws Exception {
+ String url = "platform:/plugin/org.eclipse.jet.tests/data/unclosedExpression.jet";
+
+ InputStream is = getFileContentsAsStream(url);
+
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ Problem[] problems = getSortedProblems(cu);
+
+ assertEquals("Number of problems", 1, problems.length);
- assertEquals("Number of problems", 2, problems.size());
+ // This assertions correspond to comments in bug147714.jet
+ assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
+ assertEquals("Problem 1 id", Problem.JETException, problems[0].getId());
+
+ }
+
+ public void testUnclosedScriptletErrors() throws Exception {
+ String url = "platform:/plugin/org.eclipse.jet.tests/data/unclosedScriplet.jet";
+
+ InputStream is = getFileContentsAsStream(url);
+
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ Problem[] problems = getSortedProblems(cu);
+
+ assertEquals("Number of problems", 1, problems.length);
+
+
+ // This assertions correspond to comments in bug147714.jet
+ assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
+ assertEquals("Problem 1 id", Problem.JETException, problems[0].getId());
+
+ }
+
+ public void testUnclosedXMLEndErrors() throws Exception {
+ String url = "platform:/plugin/org.eclipse.jet.tests/data/unclosedXMLEnd.jet";
+
+ InputStream is = getFileContentsAsStream(url);
+
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ Problem[] problems = getSortedProblems(cu);
+
+ assertEquals("Number of problems", 1, problems.length);
+
+
+ // This assertions correspond to comments in bug147714.jet
+ assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
+ assertEquals("Problem 1 id", Problem.UnterminatedXMLTag, problems[0].getId());
+
+ }
+
+ public void testUnclosedXMLStartErrors() throws Exception {
+ String url = "platform:/plugin/org.eclipse.jet.tests/data/unclosedXMLStart.jet";
+
+ InputStream is = getFileContentsAsStream(url);
+
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ Problem[] problems = getSortedProblems(cu);
+
+ assertEquals("Number of problems", 1, problems.length);
+
+
+ // This assertions correspond to comments in bug147714.jet
+ assertEquals("Problem 1 line number", 3, problems[0].getLineNumber());
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
+ assertEquals("Problem 1 id", Problem.UnterminatedXMLTag, problems[0].getId());
+
+ }
+
+ /**
+ * @param cu
+ * @return
+ */
+ private Problem[] getSortedProblems(JET2CompilationUnit cu) {
+ List problems = new ArrayList(cu.getProblems());
// problems are not guaranteed to be in line order (should they)
Collections.sort(problems, new Comparator() {
@@ -285,17 +444,25 @@ public class TestJET2Parser extends TestCase {
}});
Problem[] problem = (Problem[]) problems.toArray(new Problem[problems.size()]);
+ return problem;
+ }
+
+ public void testAttributeParsingErrors() throws Exception {
+ String url = "platform:/plugin/org.eclipse.jet.tests/data/attributeParsingErrors.jet";
+ InputStream is = getFileContentsAsStream(url);
- // 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 1 id", Problem.MissingXmlEndTag, problem[0].getId());
-
- assertEquals("Problem 2 line number", 10, problem[1].getLineNumber());
- assertEquals("Problem 2 severity", ParseProblemSeverity.WARNING, problem[1].getSeverity());
- assertEquals("Problem 2 id", Problem.TagInterpretedAsEmptyTag, problem[1].getId());
+ JET2CompilationUnit cu = new JET2CompilationUnit();
+ cu.parse(is, "UTF-8");
+
+ Problem[] problems = getSortedProblems(cu);
+ assertTrue("At least one problem", problems.length > 0);
+ assertEquals("Problem 1 severity", ParseProblemSeverity.ERROR, problems[0].getSeverity());
+ assertEquals("Problem 1 id", Problem.JETException, problems[0].getId());
+ assertEquals("Problem 1 line number", 4, problems[0].getLineNumber());
+
+
}
}
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 247fc8b..3ddd6e6 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
@@ -254,6 +254,7 @@ public class TestJETParser extends TestCase {
AllJET2SyntaxListener listener = new AllJET2SyntaxListener(reader);
JETParser.Directive directive = new JETParser.Directive();
directive.getDirectives().add("jet");
+ directive.getDirectives().add("taglib");
JETCoreElement[] coreElements = new JETCoreElement[] {
directive,
@@ -289,12 +290,7 @@ public class TestJETParser extends TestCase {
String urlString = "platform:/plugin/org.eclipse.jet.tests/data/unclosedComment.jet";
String openChars = "<%--";
- try {
- doUnclosedElementTest(urlString, openChars, 0);
- fail();
- } catch(JETException e) {
- // success.
- }
+ doUnclosedElementTest(urlString, openChars, Problem.UnterminatedXMLTag);
}
@@ -303,12 +299,7 @@ public class TestJETParser extends TestCase {
String urlString = "platform:/plugin/org.eclipse.jet.tests/data/unclosedDeclaration.jet";
String openChars = "<%!";
- try {
- doUnclosedElementTest(urlString, openChars, 0);
- fail();
- } catch(JETException e) {
- // success.
- }
+ doUnclosedElementTest(urlString, openChars, Problem.UnterminatedXMLTag);
}
public void testUnclosedDirective() throws Exception {