From f72810088d2c7f3c29fbde185b25cfc72fc1fbcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 20 Dec 2019 18:29:30 +0100 Subject: [PATCH] REVERT ME Remove some diff --- pmd-javascript/pom.xml | 10 - .../pmd/lang/ecmascript/ast/ASTAstRoot.java | 4 +- .../ecmascript/ast/ASTFunctionNodeTest.java | 4 +- .../ecmascript/ast/ASTTryStatementTest.java | 2 +- .../ecmascript/ast/EcmascriptParserTest.java | 26 +-- .../ast/EcmascriptParserTestBase.java | 35 ++-- .../lang/ecmascript/ast/JsParsingHelper.java | 25 --- pmd-jsp/pom.xml | 10 - .../pmd/lang/jsp/ast/AbstractJspNodesTst.java | 62 +++++- .../pmd/lang/jsp/ast/JspDocStyleTest.java | 197 +++++++++--------- .../pmd/lang/jsp/ast/JspPageStyleTest.java | 38 ++-- .../pmd/lang/jsp/ast/JspParsingHelper.java | 25 --- pmd-plsql/pom.xml | 10 - .../lang/plsql/AbstractPLSQLParserTst.java | 133 +++++++++++- .../pmd/lang/plsql/PLSQLParserTest.java | 77 +++++++ .../pmd/lang/plsql/PLSQLXPathRuleTest.java | 14 +- .../pmd/lang/plsql/PlsqlParsingHelper.java | 30 --- .../plsql/ast/ASTComparisonConditionTest.java | 2 +- .../plsql/ast/ASTCompoundConditionTest.java | 2 +- .../lang/plsql/ast/AnonymousBlockTest.java | 18 +- .../pmd/lang/plsql/ast/CreateTableTest.java | 17 +- .../lang/plsql/ast/CursorAttributesTest.java | 7 +- .../pmd/lang/plsql/ast/CursorForLoopTest.java | 15 +- .../lang/plsql/ast/CursorWithWithTest.java | 10 +- .../lang/plsql/ast/DeleteStatementTest.java | 10 +- .../lang/plsql/ast/ExecuteImmediateTest.java | 18 +- .../pmd/lang/plsql/ast/FunctionsTest.java | 18 +- .../pmd/lang/plsql/ast/IfStatementTest.java | 2 +- .../lang/plsql/ast/InsertIntoClauseTest.java | 25 ++- .../pmd/lang/plsql/ast/JoinClauseTest.java | 68 ++++-- .../plsql/ast/OrderByExpressionsTest.java | 11 +- .../pmd/lang/plsql/ast/PLSQLParserTest.java | 76 ------- .../pmd/lang/plsql/ast/RecordTypeTest.java | 11 +- .../lang/plsql/ast/SelectExpressionsTest.java | 29 ++- .../lang/plsql/ast/SelectForUpdateTest.java | 14 +- .../plsql/ast/SelectHierarchicalTest.java | 11 +- .../plsql/ast/SelectIntoStatementTest.java | 51 +++-- .../plsql/ast/SelectIntoWithGroupByTest.java | 26 ++- .../pmd/lang/plsql/ast/SelectUnionTest.java | 11 +- .../ast/TableCollectionExpressionTest.java | 18 +- .../plsql/ast/TrimWithRecordTypeTest.java | 11 +- .../lang/plsql/ast/UpdateStatementTest.java | 7 +- .../pmd/lang/plsql/ast/ViewTest.java | 25 ++- .../pmd/lang/plsql/ast/WhereClauseTest.java | 74 ++++--- .../pmd/lang/plsql/ast/XMLElementTest.java | 8 +- .../pmd/lang/plsql/ast/XMLTableTest.java | 10 +- .../dfa/StatementAndBraceFinderTest.java | 35 ++-- .../pmd/lang/scala/ast/BaseScalaTest.java | 14 -- .../lang/scala/ast/ScalaParsingHelper.java | 56 ----- .../pmd/lang/scala/rule/ScalaRuleTest.java | 46 +++- .../pmd/lang/scala/rule/XPathRuleTest.java | 31 ++- pmd-visualforce/pom.xml | 10 - .../sourceforge/pmd/lang/vf/VfParserTest.java | 48 +++++ .../pmd/lang/vf/ast/AbstractVfNodesTest.java | 64 +++++- .../pmd/lang/vf/ast/VfDocStyleTest.java | 163 ++++++++------- .../pmd/lang/vf/ast/VfPageStyleTest.java | 8 +- .../pmd/lang/vf/ast/VfParserTest.java | 29 --- .../pmd/lang/vf/ast/VfParsingHelper.java | 22 -- pmd-xml/pom.xml | 10 - .../pmd/lang/xml/XmlParserOptionsTest.java | 4 +- .../pmd/lang/xml/XmlParserTest.java | 75 +++++-- .../pmd/lang/xml/XmlParsingHelper.java | 33 --- 62 files changed, 1169 insertions(+), 786 deletions(-) delete mode 100644 pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/JsParsingHelper.java delete mode 100644 pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/ast/JspParsingHelper.java create mode 100644 pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/PLSQLParserTest.java delete mode 100644 pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/PlsqlParsingHelper.java delete mode 100644 pmd-plsql/src/test/java/net/sourceforge/pmd/lang/plsql/ast/PLSQLParserTest.java delete mode 100644 pmd-scala/src/test/java/net/sourceforge/pmd/lang/scala/ast/BaseScalaTest.java delete mode 100644 pmd-scala/src/test/java/net/sourceforge/pmd/lang/scala/ast/ScalaParsingHelper.java create mode 100644 pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/VfParserTest.java delete mode 100644 pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java delete mode 100644 pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParsingHelper.java delete mode 100644 pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParsingHelper.java diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index a2df98aeff..28115957d3 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -96,15 +96,5 @@ pmd-test test - - org.junit.vintage - junit-vintage-engine - test - - - net.sourceforge.pmd - pmd-lang-test - test - diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAstRoot.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAstRoot.java index b4976f84e1..1da66dbed0 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAstRoot.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAstRoot.java @@ -6,9 +6,7 @@ package net.sourceforge.pmd.lang.ecmascript.ast; import org.mozilla.javascript.ast.AstRoot; -import net.sourceforge.pmd.lang.ast.RootNode; - -public class ASTAstRoot extends AbstractEcmascriptNode implements RootNode { +public class ASTAstRoot extends AbstractEcmascriptNode { public ASTAstRoot(AstRoot astRoot) { super(astRoot); } diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionNodeTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionNodeTest.java index 40726ff26a..ef040c68b2 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionNodeTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTFunctionNodeTest.java @@ -11,7 +11,7 @@ public class ASTFunctionNodeTest extends EcmascriptParserTestBase { @Test public void testGetBody() { - ASTAstRoot node = js.parse("function foo() { var a = 'a'; }"); + ASTAstRoot node = parse("function foo() { var a = 'a'; }"); ASTFunctionNode fn = node.getFirstDescendantOfType(ASTFunctionNode.class); Assert.assertFalse(fn.isClosure()); EcmascriptNode body = fn.getBody(); @@ -20,7 +20,7 @@ public class ASTFunctionNodeTest extends EcmascriptParserTestBase { @Test public void testGetBodyFunctionClosureExpression() { - ASTAstRoot node = js18.parse("(function(x) x*x)"); + ASTAstRoot node = parse18("(function(x) x*x)"); ASTFunctionNode fn = node.getFirstDescendantOfType(ASTFunctionNode.class); Assert.assertTrue(fn.isClosure()); EcmascriptNode body = fn.getBody(); diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTTryStatementTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTTryStatementTest.java index 40dcb6c097..738676eabc 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTTryStatementTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTTryStatementTest.java @@ -17,7 +17,7 @@ import org.mozilla.javascript.ast.AstRoot; public class ASTTryStatementTest extends EcmascriptParserTestBase { private ASTTryStatement getTryStmt(String js) { - EcmascriptNode node = this.js.parse(js); + EcmascriptNode node = parse(js); List trys = node.findDescendantsOfType(ASTTryStatement.class); Assert.assertEquals(1, trys.size()); ASTTryStatement tryStmt = trys.get(0); diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java index 15d69e3f72..3c6c300e59 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java @@ -32,7 +32,7 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase { @Test public void testLineNumbers() { final String SOURCE_CODE = "function a() {" + PMD.EOL + " alert('hello');" + PMD.EOL + "}" + PMD.EOL; - EcmascriptNode node = js.parse(SOURCE_CODE); + EcmascriptNode node = parse(SOURCE_CODE); assertEquals(1, node.getBeginLine()); assertEquals(1, node.getBeginColumn()); assertEquals(3, node.getEndLine()); @@ -69,7 +69,7 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase { MyEcmascriptRule rule = new MyEcmascriptRule(); RuleContext ctx = new RuleContext(); - rule.apply(Arrays.asList(js.parse(source)), ctx); + rule.apply(Arrays.asList(parse(source)), ctx); assertEquals("Scope from 2 to 4", output.get(0)); assertEquals("Scope from 4 to 6", output.get(1)); @@ -80,7 +80,7 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase { */ @Test public void testArrayAccess() { - EcmascriptNode node = js.parse("function a() { b['a'] = 1; c[1] = 2; }"); + EcmascriptNode node = parse("function a() { b['a'] = 1; c[1] = 2; }"); List arrays = node.findDescendantsOfType(ASTElementGet.class); assertEquals("b", arrays.get(0).getTarget().getImage()); assertEquals("a", arrays.get(0).getElement().getImage()); @@ -94,9 +94,9 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase { */ @Test public void testArrayMethod() { - EcmascriptNode rootNode = js.parse( - "function test(){\n" + " a(); // OK\n" + " b.c(); // OK\n" + " d[0](); // OK\n" - + " e[0].f(); // OK\n" + " y.z[0](); // FAIL ==> java.lang.NullPointerException\n" + "}"); + EcmascriptNode rootNode = parse( + "function test(){\n" + " a(); // OK\n" + " b.c(); // OK\n" + " d[0](); // OK\n" + + " e[0].f(); // OK\n" + " y.z[0](); // FAIL ==> java.lang.NullPointerException\n" + "}"); List calls = rootNode.findDescendantsOfType(ASTFunctionCall.class); List results = new ArrayList<>(); @@ -129,7 +129,7 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase { */ @Test public void testCaseAsIdentifier() { - ASTAstRoot rootNode = js.parse("function f(a){\n" + " a.case.flag = 1;\n" + " return;\n" + "}"); + ASTAstRoot rootNode = parse("function f(a){\n" + " a.case.flag = 1;\n" + " return;\n" + "}"); ASTBlock block = rootNode.getFirstDescendantOfType(ASTBlock.class); assertFalse(block.jjtGetChild(0) instanceof ASTEmptyExpression); assertTrue(block.jjtGetChild(0) instanceof ASTExpressionStatement); @@ -163,9 +163,9 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase { */ @Test public void testVoidKeyword() { - ASTAstRoot rootNode = js.parse("function f(matchFn, fieldval, n){\n" - + " return (matchFn)?(matcharray = eval(matchFn+\"('\"+fieldval+\"','\"+n.id+\"')\")):void(0);\n" - + "}\n"); + ASTAstRoot rootNode = parse("function f(matchFn, fieldval, n){\n" + + " return (matchFn)?(matcharray = eval(matchFn+\"('\"+fieldval+\"','\"+n.id+\"')\")):void(0);\n" + + "}\n"); ASTUnaryExpression unary = rootNode.getFirstDescendantOfType(ASTUnaryExpression.class); assertEquals("void", unary.getImage()); } @@ -175,9 +175,9 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase { */ @Test public void testXorAssignment() { - ASTAstRoot rootNode = js.parse("function f() { var x = 2; x ^= 2; x &= 2; x |= 2; " - + "x &&= true; x ||= false; x *= 2; x /= 2; x %= 2; x += 2; x -= 2; " - + "x <<= 2; x >>= 2; x >>>= 2; }"); + ASTAstRoot rootNode = parse("function f() { var x = 2; x ^= 2; x &= 2; x |= 2; " + + "x &&= true; x ||= false; x *= 2; x /= 2; x %= 2; x += 2; x -= 2; " + + "x <<= 2; x >>= 2; x >>>= 2; }"); ASTAssignment infix = rootNode.getFirstDescendantOfType(ASTAssignment.class); assertEquals("^=", infix.getImage()); } diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTestBase.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTestBase.java index cf6eade47e..bb9df1d72d 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTestBase.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTestBase.java @@ -4,21 +4,32 @@ package net.sourceforge.pmd.lang.ecmascript.ast; -import net.sourceforge.pmd.lang.ParserOptions; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; + import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions; -import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions.Version; public abstract class EcmascriptParserTestBase { - - protected final JsParsingHelper js = JsParsingHelper.DEFAULT.withResourceContext(getClass()); - - protected final JsParsingHelper js18 = JsParsingHelper.DEFAULT.withResourceContext(getClass()) - .withParserOptions(parserVersion(Version.VERSION_1_8)); - - public ParserOptions parserVersion(EcmascriptParserOptions.Version version) { - EcmascriptParserOptions parserOptions = new EcmascriptParserOptions(); - parserOptions.setRhinoLanguageVersion(version); - return parserOptions; + public ASTAstRoot parse(String code) { + EcmascriptParser parser = new EcmascriptParser(new EcmascriptParserOptions()); + Reader sourceCode = new StringReader(code); + return (ASTAstRoot) parser.parse(sourceCode); } + public ASTAstRoot parse18(String code) { + EcmascriptParserOptions parserOptions = new EcmascriptParserOptions(); + parserOptions.setRhinoLanguageVersion(EcmascriptParserOptions.Version.VERSION_1_8); + EcmascriptParser parser = new EcmascriptParser(parserOptions); + Reader sourceCode = new StringReader(code); + return (ASTAstRoot) parser.parse(sourceCode); + } + + public String dump(EcmascriptNode node) { + DumpFacade dumpFacade = new DumpFacade(); + StringWriter writer = new StringWriter(); + dumpFacade.initializeWith(writer, "", true, node); + dumpFacade.visit(node, ""); + return writer.toString(); + } } diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/JsParsingHelper.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/JsParsingHelper.java deleted file mode 100644 index 833d9e62ff..0000000000 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/JsParsingHelper.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.ecmascript.ast; - -import org.jetbrains.annotations.NotNull; - -import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper; -import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule; - -public final class JsParsingHelper extends BaseParsingHelper { - - public static final JsParsingHelper DEFAULT = new JsParsingHelper(Params.getDefaultProcess()); - - private JsParsingHelper(@NotNull Params params) { - super(EcmascriptLanguageModule.NAME, ASTAstRoot.class, params); - } - - @NotNull - @Override - protected JsParsingHelper clone(@NotNull Params params) { - return new JsParsingHelper(params); - } -} diff --git a/pmd-jsp/pom.xml b/pmd-jsp/pom.xml index d0dbb6455b..a0052f7229 100644 --- a/pmd-jsp/pom.xml +++ b/pmd-jsp/pom.xml @@ -93,20 +93,10 @@ junit test - - org.junit.vintage - junit-vintage-engine - test - net.sourceforge.pmd pmd-test test - - net.sourceforge.pmd - pmd-lang-test - test - diff --git a/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/ast/AbstractJspNodesTst.java b/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/ast/AbstractJspNodesTst.java index fd8c4082fb..3cd7977511 100644 --- a/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/ast/AbstractJspNodesTst.java +++ b/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/ast/AbstractJspNodesTst.java @@ -4,8 +4,68 @@ package net.sourceforge.pmd.lang.jsp.ast; +import static org.junit.Assert.assertEquals; + +import java.io.StringReader; +import java.util.HashSet; +import java.util.Set; + +import net.sourceforge.pmd.lang.ast.JavaCharStream; +import net.sourceforge.pmd.lang.ast.Node; + public abstract class AbstractJspNodesTst { - protected JspParsingHelper jsp = JspParsingHelper.DEFAULT.withResourceContext(getClass()); + public void assertNumberOfNodes(Class clazz, String source, int number) { + Set nodes = getNodes(clazz, source); + assertEquals("Exactly " + number + " element(s) expected", number, nodes.size()); + } + + /** + * Run the JSP parser on the source, and return the nodes of type clazz. + * + * @param clazz + * @param source + * @return Set + */ + public Set getNodes(Class clazz, String source) { + JspParser parser = new JspParser(new JavaCharStream(new StringReader(source))); + Node rootNode = parser.CompilationUnit(); + Set nodes = new HashSet<>(); + addNodeAndSubnodes(rootNode, nodes, clazz); + return nodes; + } + + /** + * Return a subset of allNodes, containing the items in allNodes that are of + * the given type. + * + * @param clazz + * @param allNodes + * @return Set + */ + public Set getNodesOfType(Class clazz, Set allNodes) { + Set result = new HashSet<>(); + for (Node node : allNodes) { + if (clazz.equals(node.getClass())) { + result.add((T) node); + } + } + return result; + } + + /** + * Add the given node and its subnodes to the set of nodes. If clazz is not + * null, only nodes of the given class are put in the set of nodes. + */ + private void addNodeAndSubnodes(Node node, Set nodes, Class clazz) { + if (null != node) { + if ((null == clazz) || (clazz.equals(node.getClass()))) { + nodes.add((T) node); + } + for (int i = 0; i < node.jjtGetNumChildren(); i++) { + addNodeAndSubnodes(node.jjtGetChild(i), nodes, clazz); + } + } + } } diff --git a/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/ast/JspDocStyleTest.java b/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/ast/JspDocStyleTest.java index 26a54a3f8b..c62d1fc5b5 100644 --- a/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/ast/JspDocStyleTest.java +++ b/pmd-jsp/src/test/java/net/sourceforge/pmd/lang/jsp/ast/JspDocStyleTest.java @@ -9,11 +9,11 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; +import java.util.Set; import org.junit.Ignore; import org.junit.Test; @@ -33,8 +33,7 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testSimplestJsp() { - List nodes = jsp.getNodes(ASTElement.class, TEST_SIMPLEST_HTML); - assertEquals("Exactly " + 1 + " element(s) expected", 1, nodes.size()); + assertNumberOfNodes(ASTElement.class, TEST_SIMPLEST_HTML, 1); } /** @@ -42,22 +41,22 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testElementAttributeAndNamespace() { - ASTCompilationUnit root = jsp.parse(TEST_ELEMENT_AND_NAMESPACE); + Set nodes = getNodes(null, TEST_ELEMENT_AND_NAMESPACE); - List elementNodes = root.findDescendantsOfType(ASTElement.class); + Set elementNodes = getNodesOfType(ASTElement.class, nodes); assertEquals("One element node expected!", 1, elementNodes.size()); - ASTElement element = elementNodes.get(0); + ASTElement element = elementNodes.iterator().next(); assertEquals("Correct name expected!", "h:html", element.getName()); - assertTrue("Has namespace prefix!", element.isHasNamespacePrefix()); - assertTrue("Element is empty!", element.isEmpty()); + assertEquals("Has namespace prefix!", true, element.isHasNamespacePrefix()); + assertEquals("Element is empty!", true, element.isEmpty()); assertEquals("Correct namespace prefix of element expected!", "h", element.getNamespacePrefix()); assertEquals("Correct local name of element expected!", "html", element.getLocalName()); - List attributeNodes = root.findDescendantsOfType(ASTAttribute.class); + Set attributeNodes = getNodesOfType(ASTAttribute.class, nodes); assertEquals("One attribute node expected!", 1, attributeNodes.size()); - ASTAttribute attribute = attributeNodes.get(0); + ASTAttribute attribute = attributeNodes.iterator().next(); assertEquals("Correct name expected!", "MyNsPrefix:MyAttr", attribute.getName()); - assertTrue("Has namespace prefix!", attribute.isHasNamespacePrefix()); + assertEquals("Has namespace prefix!", true, attribute.isHasNamespacePrefix()); assertEquals("Correct namespace prefix of element expected!", "MyNsPrefix", attribute.getNamespacePrefix()); assertEquals("Correct local name of element expected!", "MyAttr", attribute.getLocalName()); @@ -70,26 +69,32 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testAttributeValueContainingHash() { - ASTCompilationUnit root = jsp.parse(TEST_ATTRIBUTE_VALUE_CONTAINING_HASH); + Set nodes = getNodes(null, TEST_ATTRIBUTE_VALUE_CONTAINING_HASH); - List attrsList = root.findDescendantsOfType(ASTAttribute.class); - assertEquals("Three attributes expected!", 3, attrsList.size()); + Set attributes = getNodesOfType(ASTAttribute.class, nodes); + assertEquals("Three attributes expected!", 3, attributes.size()); + + List attrsList = new ArrayList<>(attributes); + Collections.sort(attrsList, new Comparator() { + public int compare(ASTAttribute arg0, ASTAttribute arg1) { + return arg0.getName().compareTo(arg1.getName()); + } + }); ASTAttribute attr = attrsList.get(0); - - assertEquals("Correct attribute name expected!", "something", attr.getName()); - assertEquals("Correct attribute value expected!", "#yes#", - attr.getFirstDescendantOfType(ASTAttributeValue.class).getImage()); - - attr = attrsList.get(1); assertEquals("Correct attribute name expected!", "foo", attr.getName()); assertEquals("Correct attribute value expected!", "CREATE", - attr.getFirstDescendantOfType(ASTAttributeValue.class).getImage()); + attr.getFirstDescendantOfType(ASTAttributeValue.class).getImage()); - attr = attrsList.get(2); + attr = attrsList.get(1); assertEquals("Correct attribute name expected!", "href", attr.getName()); assertEquals("Correct attribute value expected!", "#", - attr.getFirstDescendantOfType(ASTAttributeValue.class).getImage()); + attr.getFirstDescendantOfType(ASTAttributeValue.class).getImage()); + + attr = attrsList.get(2); + assertEquals("Correct attribute name expected!", "something", attr.getName()); + assertEquals("Correct attribute value expected!", "#yes#", + attr.getFirstDescendantOfType(ASTAttributeValue.class).getImage()); } /** @@ -97,10 +102,10 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testCData() { - List cdataNodes = jsp.getNodes(ASTCData.class, TEST_CDATA); + Set cdataNodes = getNodes(ASTCData.class, TEST_CDATA); assertEquals("One CDATA node expected!", 1, cdataNodes.size()); - ASTCData cdata = cdataNodes.get(0); + ASTCData cdata = cdataNodes.iterator().next(); assertEquals("Content incorrectly parsed!", " some ]] ]> ", cdata.getImage()); } @@ -109,14 +114,14 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testDoctype() { - ASTCompilationUnit root = jsp.parse(TEST_DOCTYPE); + Set nodes = getNodes(null, TEST_DOCTYPE); - List docTypeDeclarations = root.findDescendantsOfType(ASTDoctypeDeclaration.class); + Set docTypeDeclarations = getNodesOfType(ASTDoctypeDeclaration.class, nodes); assertEquals("One doctype declaration expected!", 1, docTypeDeclarations.size()); ASTDoctypeDeclaration docTypeDecl = docTypeDeclarations.iterator().next(); assertEquals("Correct doctype-name expected!", "html", docTypeDecl.getName()); - List externalIds = root.findDescendantsOfType(ASTDoctypeExternalId.class); + Set externalIds = getNodesOfType(ASTDoctypeExternalId.class, nodes); assertEquals("One doctype external id expected!", 1, externalIds.size()); ASTDoctypeExternalId externalId = externalIds.iterator().next(); assertEquals("Correct external public id expected!", "-//W3C//DTD XHTML 1.1//EN", externalId.getPublicId()); @@ -131,7 +136,7 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testComment() { - List comments = jsp.getNodes(ASTCommentTag.class, TEST_COMMENT); + Set comments = getNodes(ASTCommentTag.class, TEST_COMMENT); assertEquals("One comment expected!", 1, comments.size()); ASTCommentTag comment = comments.iterator().next(); assertEquals("Correct comment content expected!", "comment", comment.getImage()); @@ -142,7 +147,7 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testHtmlScript() { - List scripts = jsp.getNodes(ASTHtmlScript.class, TEST_HTML_SCRIPT); + Set scripts = getNodes(ASTHtmlScript.class, TEST_HTML_SCRIPT); assertEquals("One script expected!", 1, scripts.size()); ASTHtmlScript script = scripts.iterator().next(); assertEquals("Correct script content expected!", "Script!", script.getImage()); @@ -154,7 +159,7 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testImportHtmlScript() { - List scripts = jsp.getNodes(ASTHtmlScript.class, TEST_IMPORT_JAVASCRIPT); + Set scripts = getNodes(ASTHtmlScript.class, TEST_IMPORT_JAVASCRIPT); assertEquals("One script expected!", 1, scripts.size()); ASTHtmlScript script = scripts.iterator().next(); List value = script.findDescendantsOfType(ASTAttributeValue.class); @@ -166,7 +171,7 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testHtmlScriptWithAttribute() { - List scripts = jsp.getNodes(ASTHtmlScript.class, TEST_HTML_SCRIPT_WITH_ATTRIBUTE); + Set scripts = getNodes(ASTHtmlScript.class, TEST_HTML_SCRIPT_WITH_ATTRIBUTE); assertEquals("One script expected!", 1, scripts.size()); ASTHtmlScript script = scripts.iterator().next(); assertEquals("Correct script content expected!", "Script!", script.getImage()); @@ -179,11 +184,11 @@ public class JspDocStyleTest extends AbstractJspNodesTst { */ @Test public void testComplexHtmlScript() { - List script = jsp.getNodes(ASTHtmlScript.class, TEST_COMPLEX_SCRIPT); + Set script = getNodes(ASTHtmlScript.class, TEST_COMPLEX_SCRIPT); assertEquals("One script expected!", 1, script.size()); ASTHtmlScript next = script.iterator().next(); assertTrue(next.getImage().contains("