From 56fc980e22846f11b4a553b6f8d535b121f9ae8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 12 Dec 2020 23:28:51 +0100 Subject: [PATCH 1/6] Cleanup tests Replace a duplicated function --- .../pmd/lang/apex/ast/ApexParserTest.java | 10 +--- .../pmd/lang/java/ast/SimpleNodeTest.java | 20 +++---- .../pmd/lang/ast/test/TestUtils.kt | 9 ++++ .../lang/modelica/ast/ModelicaCoordsTest.kt | 49 ++++++++--------- .../pmd/lang/scala/ast/ScalaTreeTests.kt | 32 +++++------ .../pmd/lang/xml/XmlParserTest.java | 53 ++++++------------- 6 files changed, 67 insertions(+), 106 deletions(-) diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java index 34982e3b91..bebc2eacde 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.apex.ast; +import static net.sourceforge.pmd.lang.ast.test.TestUtilsKt.assertPosition; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertEquals; @@ -194,13 +195,4 @@ public class ApexParserTest extends ApexParserTestBase { } return result; } - - // TEST HELPER - - private static void assertPosition(Node node, int beginLine, int beginColumn, int endLine, int endColumn) { - assertEquals("Wrong begin line", beginLine, node.getBeginLine()); - assertEquals("Wrong begin column", beginColumn, node.getBeginColumn()); - assertEquals("Wrong end line", endLine, node.getEndLine()); - assertEquals("Wrong end column", endColumn, node.getEndColumn()); - } } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/SimpleNodeTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/SimpleNodeTest.java index 2d1dc1cb61..08077df94a 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/SimpleNodeTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/SimpleNodeTest.java @@ -16,6 +16,7 @@ import org.junit.Ignore; import org.junit.Test; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.test.TestUtilsKt; import net.sourceforge.pmd.lang.java.JavaParsingHelper; @Ignore("This test is Java specific even though parts of it should apply to any language implementation") @@ -26,19 +27,19 @@ public class SimpleNodeTest extends BaseParserTest { @Test public void testMethodDiffLines() { List methods = java.getNodes(ASTMethodDeclaration.class, METHOD_DIFF_LINES); - verifyNode(methods.iterator().next(), 2, 9, 4, 3); + TestUtilsKt.assertPosition(methods.iterator().next(), 2, 9, 4, 3); } @Test public void testMethodSameLine() { List methods = java.getNodes(ASTMethodDeclaration.class, METHOD_SAME_LINE); - verifyNode(methods.iterator().next(), 2, 9, 2, 22); + TestUtilsKt.assertPosition(methods.iterator().next(), 2, 9, 2, 22); } @Test public void testNoLookahead() { List uCD = java.getNodes(ASTClassOrInterfaceDeclaration.class, NO_LOOKAHEAD); - verifyNode(uCD.iterator().next(), 1, 8, 1, 21); + TestUtilsKt.assertPosition(uCD.iterator().next(), 1, 8, 1, 21); } @Test @@ -69,7 +70,7 @@ public class SimpleNodeTest extends BaseParserTest { public void testColumnsOnQualifiedName() { for (Node node : java.getNodes(ASTName.class, QUALIFIED_NAME)) { if (node.getImage().equals("java.io.File")) { - verifyNode(node, 1, 8, 1, 20); + TestUtilsKt.assertPosition(node, 1, 8, 1, 20); } } } @@ -78,10 +79,10 @@ public class SimpleNodeTest extends BaseParserTest { public void testLineNumbersForNameSplitOverTwoLines() { for (Node node : java.getNodes(ASTName.class, BROKEN_LINE_IN_NAME)) { if (node.getImage().equals("java.io.File")) { - verifyNode(node, 1, 8, 2, 5); + TestUtilsKt.assertPosition(node, 1, 8, 2, 5); } if (node.getImage().equals("Foo")) { - verifyNode(node, 2, 15, 2, 19); + TestUtilsKt.assertPosition(node, 2, 15, 2, 19); } } } @@ -256,13 +257,6 @@ public class SimpleNodeTest extends BaseParserTest { assertTrue(nodes.get(0) instanceof ASTFieldDeclaration); } - private void verifyNode(Node node, int beginLine, int beginCol, int endLine, int endCol) { - assertEquals("Unexpected beginning line: ", beginLine, node.getBeginLine()); - assertEquals("Unexpected beginning column: ", beginCol, node.getBeginColumn()); - assertEquals("Unexpected ending line:", endLine, node.getEndLine()); - assertEquals("Unexpected ending column:", endCol, node.getEndColumn()); - } - private static final String HAS_EXPLICIT_EXTENDS = "public class Test extends Foo {}"; private static final String NO_EXPLICIT_EXTENDS = "public class Test {}"; diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt index caaca5ca62..932fa04b1e 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt @@ -9,6 +9,7 @@ import io.kotest.matchers.equalityMatcher import io.kotest.matchers.should import net.sourceforge.pmd.Report import net.sourceforge.pmd.RuleViolation +import net.sourceforge.pmd.lang.ast.Node import kotlin.reflect.KCallable import kotlin.reflect.jvm.isAccessible import kotlin.test.assertEquals @@ -91,3 +92,11 @@ fun assertSuppressed(report: Report, size: Int): List { it::getText shouldBe """package TestPackage package EmptyPackage end EmptyPackage; end TestPackage""" - it.assertBounds(1, 1, 4, 16) + it.assertPosition(1, 1, 4, 16) child { it::getText shouldBe "package" - it.assertBounds(1, 1, 1, 8) + it.assertPosition(1, 1, 1, 8) child { it::getText shouldBe "package" - it.assertBounds(1, 1, 1, 8) + it.assertPosition(1, 1, 1, 8) } } child { @@ -52,7 +52,7 @@ end TestPackage""" package EmptyPackage end EmptyPackage; end TestPackage""" - it.assertBounds(1, 9, 4, 16) + it.assertPosition(1, 9, 4, 16) child { it::getText shouldBe """TestPackage @@ -60,56 +60,56 @@ end TestPackage""" end EmptyPackage; end TestPackage""" - it.assertBounds(1, 9, 4, 16) + it.assertPosition(1, 9, 4, 16) child { it::getText shouldBe "TestPackage" - it.assertBounds(1, 9, 1, 20) + it.assertPosition(1, 9, 1, 20) } child { it::getText shouldBe """package EmptyPackage end EmptyPackage;""" - it.assertBounds(2, 3, 3, 20) + it.assertPosition(2, 3, 3, 20) child { it::getText shouldBe """package EmptyPackage end EmptyPackage;""" - it.assertBounds(2, 3, 3, 20) + it.assertPosition(2, 3, 3, 20) child { it::getText shouldBe """package EmptyPackage end EmptyPackage""" - it.assertBounds(2, 3, 3, 19) + it.assertPosition(2, 3, 3, 19) child { it::getText shouldBe """package EmptyPackage end EmptyPackage""" - it.assertBounds(2, 3, 3, 19) + it.assertPosition(2, 3, 3, 19) it.isPartial shouldBe false child { it::getText shouldBe "package" - it.assertBounds(2, 3, 2, 10) + it.assertPosition(2, 3, 2, 10) child { it::getText shouldBe "package" - it.assertBounds(2, 3, 2, 10) + it.assertPosition(2, 3, 2, 10) } } child { it::getText shouldBe """EmptyPackage end EmptyPackage""" - it.assertBounds(2, 11, 3, 19) + it.assertPosition(2, 11, 3, 19) child { it::getText shouldBe """EmptyPackage end EmptyPackage""" - it.assertBounds(2, 11, 3, 19) + it.assertPosition(2, 11, 3, 19) it.simpleClassName shouldBe "EmptyPackage" child { it::getText shouldBe "EmptyPackage" - it.assertBounds(2, 11, 2, 23) + it.assertPosition(2, 11, 2, 23) } child { @@ -117,20 +117,20 @@ end TestPackage""" it.firstToken::isImplicit shouldBe true it.lastToken shouldBe it.firstToken - it.assertBounds(3, 3, 3, 3) + it.assertPosition(3, 3, 3, 3) child { it::getText shouldBe "" it.firstToken::isImplicit shouldBe true it.lastToken shouldBe it.firstToken - it.assertBounds(3, 3, 3, 3) + it.assertPosition(3, 3, 3, 3) } } child { it::getText shouldBe "EmptyPackage" it::getImage shouldBe "EmptyPackage" - it.assertBounds(3, 7, 3, 19) + it.assertPosition(3, 7, 3, 19) } } } @@ -140,7 +140,7 @@ end TestPackage""" } child { it::getText shouldBe "TestPackage" - it.assertBounds(4, 5, 4, 16) + it.assertPosition(4, 5, 4, 16) } } } @@ -151,10 +151,3 @@ end TestPackage""" fun String.parseModelica(): ASTStoredDefinition = ModelicaParsingHelper.DEFAULT.parse(this) - -fun Node.assertBounds(bline: Int, bcol: Int, eline: Int, ecol: Int) { - this::getBeginLine shouldBe bline - this::getBeginColumn shouldBe bcol - this::getEndLine shouldBe eline - this::getEndColumn shouldBe ecol -} diff --git a/pmd-scala-modules/pmd-scala-common/src/test/kotlin/net/sourceforge/pmd/lang/scala/ast/ScalaTreeTests.kt b/pmd-scala-modules/pmd-scala-common/src/test/kotlin/net/sourceforge/pmd/lang/scala/ast/ScalaTreeTests.kt index 39a29064df..0b4fece447 100644 --- a/pmd-scala-modules/pmd-scala-common/src/test/kotlin/net/sourceforge/pmd/lang/scala/ast/ScalaTreeTests.kt +++ b/pmd-scala-modules/pmd-scala-common/src/test/kotlin/net/sourceforge/pmd/lang/scala/ast/ScalaTreeTests.kt @@ -6,9 +6,8 @@ package net.sourceforge.pmd.lang.scala.ast import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.should -import net.sourceforge.pmd.lang.LanguageRegistry -import net.sourceforge.pmd.lang.ast.Node import net.sourceforge.pmd.lang.ast.test.matchNode +import net.sourceforge.pmd.lang.ast.test.assertPosition import net.sourceforge.pmd.lang.ast.test.shouldBe class ScalaTreeTests : FunSpec({ @@ -23,54 +22,54 @@ class Foo { """.trim().parseScala() should matchNode { child { - it.assertBounds(bline = 1, bcol = 1, eline = 3, ecol = 2) + it.assertPosition(bline = 1, bcol = 1, eline = 3, ecol = 2) it::isImplicit shouldBe false child { - it.assertBounds(bline = 1, bcol = 7, eline = 1, ecol = 10) + it.assertPosition(bline = 1, bcol = 7, eline = 1, ecol = 10) it::isImplicit shouldBe false } child { - it.assertBounds(bline = 1, bcol = 11, eline = 1, ecol = 11) // node has zero length + it.assertPosition(bline = 1, bcol = 11, eline = 1, ecol = 11) // node has zero length it::isImplicit shouldBe true child { - it.assertBounds(bline = 1, bcol = 11, eline = 1, ecol = 11) // node has zero length + it.assertPosition(bline = 1, bcol = 11, eline = 1, ecol = 11) // node has zero length it::isImplicit shouldBe true } } child { - it.assertBounds(bline = 1, bcol = 11, eline = 3, ecol = 2) + it.assertPosition(bline = 1, bcol = 11, eline = 3, ecol = 2) it::isImplicit shouldBe false child { - it.assertBounds(bline = 2, bcol = 2, eline = 2, ecol = 2) // node has zero length + it.assertPosition(bline = 2, bcol = 2, eline = 2, ecol = 2) // node has zero length it::isImplicit shouldBe true child { - it.assertBounds(bline = 2, bcol = 2, eline = 2, ecol = 2) // node has zero length + it.assertPosition(bline = 2, bcol = 2, eline = 2, ecol = 2) // node has zero length it::isImplicit shouldBe true } } child { - it.assertBounds(bline = 2, bcol = 2, eline = 2, ecol = 12) + it.assertPosition(bline = 2, bcol = 2, eline = 2, ecol = 12) it::isImplicit shouldBe false child { - it.assertBounds(bline = 2, bcol = 6, eline = 2, ecol = 7) + it.assertPosition(bline = 2, bcol = 6, eline = 2, ecol = 7) it::isImplicit shouldBe false child { - it.assertBounds(bline = 2, bcol = 6, eline = 2, ecol = 7) + it.assertPosition(bline = 2, bcol = 6, eline = 2, ecol = 7) it::isImplicit shouldBe false } } child { - it.assertBounds(bline = 2, bcol = 10, eline = 2, ecol = 12) + it.assertPosition(bline = 2, bcol = 10, eline = 2, ecol = 12) } } } @@ -80,10 +79,3 @@ class Foo { }) fun String.parseScala(): ASTSource = ScalaParsingHelper.DEFAULT.parse(this) - -fun Node.assertBounds(bline: Int, bcol: Int, eline: Int, ecol: Int) { - this::getBeginLine shouldBe bline - this::getBeginColumn shouldBe bcol - this::getEndLine shouldBe eline - this::getEndColumn shouldBe ecol -} diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserTest.java index 591fad6ee9..8d1195fc9c 100644 --- a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserTest.java +++ b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserTest.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.xml; +import static net.sourceforge.pmd.lang.ast.test.TestUtilsKt.assertPosition; import static net.sourceforge.pmd.lang.xml.XmlParsingHelper.XML; import java.io.ByteArrayOutputStream; @@ -52,37 +53,37 @@ public class XmlParserTest { Node document = XML.parse(XML_TEST); assertNode(document, "document", 2); - assertLineNumbers(document, 1, 1, 19, 14); + assertPosition(document, 1, 1, 19, 14); Node dtdElement = document.getChild(0); assertNode(dtdElement, "rootElement", 0); - assertLineNumbers(dtdElement, 2, 1, 11, 1); + assertPosition(dtdElement, 2, 1, 11, 1); Node rootElement = document.getChild(1); assertNode(rootElement, "rootElement", 7); - assertLineNumbers(rootElement, 12, 1, 19, 14); + assertPosition(rootElement, 12, 1, 19, 14); assertTextNode(rootElement.getChild(0), "\\n "); - assertLineNumbers(rootElement.getChild(0), 12, 14, 13, 4); + assertPosition(rootElement.getChild(0), 12, 14, 13, 4); assertNode(rootElement.getChild(1), "comment", 0); - assertLineNumbers(rootElement.getChild(1), 13, 5, 13, 29); + assertPosition(rootElement.getChild(1), 13, 5, 13, 29); assertTextNode(rootElement.getChild(2), "\\n "); - assertLineNumbers(rootElement.getChild(2), 13, 30, 14, 4); + assertPosition(rootElement.getChild(2), 13, 30, 14, 4); Node child1 = rootElement.getChild(3); assertNode(child1, "child1", 1, "test", "1"); - assertLineNumbers(child1, 14, 5, 15, 13); + assertPosition(child1, 14, 5, 15, 13); assertTextNode(child1.getChild(0), "entity: Copyright: PMD\\n "); - assertLineNumbers(child1.getChild(0), 14, 22, 15, 4); + assertPosition(child1.getChild(0), 14, 22, 15, 4); assertTextNode(rootElement.getChild(4), "\\n "); - assertLineNumbers(rootElement.getChild(4), 15, 14, 16, 4); + assertPosition(rootElement.getChild(4), 15, 14, 16, 4); Node child2 = rootElement.getChild(5); assertNode(child2, "child2", 3); - assertLineNumbers(child2, 16, 5, 18, 13); + assertPosition(child2, 16, 5, 18, 13); assertTextNode(child2.getChild(0), "\\n "); - assertLineNumbers(child2.getChild(0), 16, 13, 17, 6); + assertPosition(child2.getChild(0), 16, 13, 17, 6); assertTextNode(child2.getChild(1), " cdata section ", "cdata-section"); - assertLineNumbers(child2.getChild(1), 17, 7, 17, 33); + assertPosition(child2.getChild(1), 17, 7, 17, 33); assertTextNode(child2.getChild(2), "\\n "); - assertLineNumbers(child2.getChild(2), 17, 34, 18, 4); + assertPosition(child2.getChild(2), 17, 34, 18, 4); assertTextNode(rootElement.getChild(6), "\\n"); - assertLineNumbers(rootElement.getChild(6), 18, 14, 18, 14); + assertPosition(rootElement.getChild(6), 18, 14, 18, 14); } /** @@ -330,7 +331,7 @@ public class XmlParserTest { Node document = XmlParsingHelper.XML.withParserOptions(options).parse(xml); Assert.assertNotNull(document); assertNode(document.getChild(0), "mypi", 0); - assertLineNumbers(document.getChild(0), 1, 22, 1, 29); + assertPosition(document.getChild(0), 1, 22, 1, 29); } @Test @@ -341,7 +342,7 @@ public class XmlParserTest { @Test public void testAutoclosingElementLength() { final String xml = ""; - assertLineNumbers(XML.parse(xml), 1, 1, 1, xml.length()); + assertPosition(XML.parse(xml), 1, 1, 1, xml.length()); } /** @@ -408,24 +409,4 @@ public class XmlParserTest { Assert.assertFalse(attributeIterator.hasNext()); } - /** - * Assert the line numbers of a node. - * - * @param node - * the node - * @param beginLine - * the begin line - * @param beginColumn - * the begin column - * @param endLine - * the end line - * @param endColumn - * the end column - */ - private void assertLineNumbers(Node node, int beginLine, int beginColumn, int endLine, int endColumn) { - Assert.assertEquals("begin line wrong", beginLine, node.getBeginLine()); - Assert.assertEquals("begin column wrong", beginColumn, node.getBeginColumn()); - Assert.assertEquals("end line wrong", endLine, node.getEndLine()); - Assert.assertEquals("end column wrong", endColumn, node.getEndColumn()); - } } From 053c439a43d39797a08c09f7dcb17470272ab1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 14 Dec 2020 13:12:14 +0100 Subject: [PATCH 2/6] Escape special chars correctly in test output --- .../sourceforge/pmd/lang/java/ast/Bug1429.txt | 2 +- .../pmd/lang/java/ast/ParserCornerCases.txt | 26 ++-- .../pmd/lang/java/ast/ParserCornerCases17.txt | 42 +++--- .../pmd/lang/java/ast/ParserCornerCases18.txt | 28 ++-- .../pmd/lang/java/ast/SwitchStatements.txt | 2 +- .../ast/jdkversiontests/java15/TextBlocks.txt | 133 +++--------------- .../java15p/PatternMatchingInstanceof.txt | 16 +-- .../ast/jdkversiontests/java15p/Records.txt | 4 +- .../pmd/lang/ast/test/NodePrinters.kt | 4 +- 9 files changed, 84 insertions(+), 173 deletions(-) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/Bug1429.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/Bug1429.txt index c185aa487a..b1a0d5889e 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/Bug1429.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/Bug1429.txt @@ -91,7 +91,7 @@ | +- MethodCall[@CompileTimeConstant = "false", @Image = "concat", @MethodName = "concat", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "result", @Name = "result", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- ArgumentList[@Size = "1"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ":", @Empty = "false", @Image = "":"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ":", @Empty = "false", @Image = "\":\"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- ArgumentList[@Size = "1"] | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "value", @Name = "value", @ParenthesisDepth = "0", @Parenthesized = "false"] +- ReturnStatement[] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases.txt index 51a5694e6f..6fc2e4a168 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases.txt @@ -44,7 +44,7 @@ | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | +- ArgumentList[@Size = "1"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Outer constructor", @Empty = "false", @Image = ""Outer constructor"", @Length = "17", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Outer constructor", @Empty = "false", @Image = "\"Outer constructor\"", @Length = "17", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "Outer$Inner", @CanonicalName = "Outer.Inner", @EffectiveVisibility = "package", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "true", @PackageName = "", @PackagePrivate = "true", @Record = "false", @RegularClass = "true", @SimpleName = "Inner", @TopLevel = "false", @Visibility = "package"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceBody[@Size = "1"] @@ -58,7 +58,7 @@ | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | +- ArgumentList[@Size = "1"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Inner constructor", @Empty = "false", @Image = ""Inner constructor"", @Length = "17", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Inner constructor", @Empty = "false", @Image = "\"Inner constructor\"", @Length = "17", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "Child", @CanonicalName = "Child", @EffectiveVisibility = "package", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "true", @Record = "false", @RegularClass = "true", @SimpleName = "Child", @TopLevel = "true", @Visibility = "package"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ExtendsList[@Size = "1"] @@ -82,7 +82,7 @@ | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | +- ArgumentList[@Size = "1"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Child constructor", @Empty = "false", @Image = ""Child constructor"", @Length = "17", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Child constructor", @Empty = "false", @Image = "\"Child constructor\"", @Length = "17", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "ParserCornerCases", @CanonicalName = "ParserCornerCases", @EffectiveVisibility = "public", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "false", @Record = "false", @RegularClass = "true", @SimpleName = "ParserCornerCases", @TopLevel = "true", @Visibility = "public"] | +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"] | +- ExtendsList[@Size = "1"] @@ -153,7 +153,7 @@ | | | +- TypeArguments[@Diamond = "false", @Size = "1"] | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "foo", @Empty = "false", @Image = ""foo"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "foo", @Empty = "false", @Image = "\"foo\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] @@ -164,7 +164,7 @@ | | +- TypeArguments[@Diamond = "false", @Size = "1"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | | +- ArgumentList[@Size = "1"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "bar", @Empty = "false", @Image = ""bar"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "bar", @Empty = "false", @Image = "\"bar\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "package", @Image = "thisGeneric", @Name = "thisGeneric", @Overridden = "false", @Varargs = "false", @Visibility = "package", @Void = "false"] | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | +- TypeParameters[@Size = "1"] @@ -206,7 +206,7 @@ | +- MethodCall[@CompileTimeConstant = "false", @Image = "append", @MethodName = "append", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- AmbiguousName[@CompileTimeConstant = "false", @Image = "buf", @Name = "buf", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- ArgumentList[@Size = "1"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "shift ", @Empty = "false", @Image = ""shift "", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "shift ", @Empty = "false", @Image = "\"shift \"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "PmdTestParent", @CanonicalName = "PmdTestParent", @EffectiveVisibility = "package", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "true", @Record = "false", @RegularClass = "true", @SimpleName = "PmdTestParent", @TopLevel = "true", @Visibility = "package"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceBody[@Size = "1"] @@ -295,7 +295,7 @@ | +- ExpressionStatement[] | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "name", @Name = "name", @ParenthesisDepth = "0", @Parenthesized = "false"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "test", @Empty = "false", @Image = ""test"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "test", @Empty = "false", @Image = "\"test\"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "SimpleBeanUser2", @CanonicalName = "SimpleBeanUser2", @EffectiveVisibility = "package", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "true", @Record = "false", @RegularClass = "true", @SimpleName = "SimpleBeanUser2", @TopLevel = "true", @Visibility = "package"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ExtendsList[@Size = "1"] @@ -318,7 +318,7 @@ | +- ExpressionStatement[] | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "name", @Name = "name", @ParenthesisDepth = "0", @Parenthesized = "false"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "test2", @Empty = "false", @Image = ""test2"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "test2", @Empty = "false", @Image = "\"test2\"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "TestParseAnnototation", @CanonicalName = "TestParseAnnototation", @EffectiveVisibility = "package", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "true", @Record = "false", @RegularClass = "true", @SimpleName = "TestParseAnnototation", @TopLevel = "true", @Visibility = "package"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceBody[@Size = "1"] @@ -335,7 +335,7 @@ | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "SuppressWarnings"] | | | | +- AnnotationMemberList[@Size = "1"] | | | | +- MemberValuePair[@Image = "value", @Name = "value", @Shorthand = "true"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "unchecked", @Empty = "false", @Image = ""unchecked"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "unchecked", @Empty = "false", @Image = "\"unchecked\"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- PrimitiveType[@Kind = "int"] | | | +- VariableDeclarator[@Initializer = "true", @Name = "i"] | | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "i", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] @@ -356,7 +356,7 @@ | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "SuppressWarnings"] | | | | +- AnnotationMemberList[@Size = "1"] | | | | +- MemberValuePair[@Image = "value", @Name = "value", @Shorthand = "true"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "unchecked", @Empty = "false", @Image = ""unchecked"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "unchecked", @Empty = "false", @Image = "\"unchecked\"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "Iterator"] | | | +- VariableDeclarator[@Initializer = "true", @Name = "it"] | | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "it", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] @@ -388,7 +388,7 @@ | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "SuppressWarnings"] | | | +- AnnotationMemberList[@Size = "1"] | | | +- MemberValuePair[@Image = "value", @Name = "value", @Shorthand = "true"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "unchecked", @Empty = "false", @Image = ""unchecked"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "unchecked", @Empty = "false", @Image = "\"unchecked\"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | | +- VariableDeclarator[@Initializer = "false", @Name = "s"] | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "s", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] @@ -439,7 +439,7 @@ | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | | +- VariableDeclarator[@Initializer = "true", @Name = "fish"] | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "fish", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "salmon", @Empty = "false", @Image = ""salmon"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "salmon", @Empty = "false", @Image = "\"salmon\"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- ReturnStatement[] | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "fish", @Name = "fish", @ParenthesisDepth = "0", @Parenthesized = "false"] +- ClassOrInterfaceDeclaration[@Abstract = "false", @Annotation = "false", @Anonymous = "false", @BinaryName = "SuperTest", @CanonicalName = "SuperTest", @EffectiveVisibility = "package", @Enum = "false", @Final = "false", @Interface = "false", @Local = "false", @Nested = "false", @PackageName = "", @PackagePrivate = "true", @Record = "false", @RegularClass = "true", @SimpleName = "SuperTest", @TopLevel = "true", @Visibility = "package"] @@ -617,7 +617,7 @@ | +- Block[@Size = "0", @containsComment = "false"] +- IfStatement[@Else = "false"] | +- MethodCall[@CompileTimeConstant = "false", @Image = "equals", @MethodName = "equals", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "a", @Empty = "false", @Image = ""a"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "a", @Empty = "false", @Image = "\"a\"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- ArgumentList[@Size = "1"] | | +- MethodCall[@CompileTimeConstant = "false", @Image = "getName", @MethodName = "getName", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- ClassLiteral[@CompileTimeConstant = "false", @ParenthesisDepth = "1", @Parenthesized = "true"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt index 968bad85f9..698aeedd4d 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt @@ -249,7 +249,7 @@ | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | | +- VariableDeclarator[@Initializer = "true", @Name = "dayOfWeekArg"] | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "dayOfWeekArg", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Wednesday", @Empty = "false", @Image = ""Wednesday"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Wednesday", @Empty = "false", @Image = "\"Wednesday\"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] @@ -259,44 +259,44 @@ | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "dayOfWeekArg", @Name = "dayOfWeekArg", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- SwitchFallthroughBranch[@Default = "false"] | | | +- SwitchLabel[@Default = "false"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Monday", @Empty = "false", @Image = ""Monday"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Monday", @Empty = "false", @Image = "\"Monday\"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- ExpressionStatement[] | | | | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "typeOfDay", @Name = "typeOfDay", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Start of work week", @Empty = "false", @Image = ""Start of work week"", @Length = "18", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Start of work week", @Empty = "false", @Image = "\"Start of work week\"", @Length = "18", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = "false"] | | | +- SwitchLabel[@Default = "false"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Tuesday", @Empty = "false", @Image = ""Tuesday"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Tuesday", @Empty = "false", @Image = "\"Tuesday\"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- SwitchFallthroughBranch[@Default = "false"] | | | +- SwitchLabel[@Default = "false"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Wednesday", @Empty = "false", @Image = ""Wednesday"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Wednesday", @Empty = "false", @Image = "\"Wednesday\"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- SwitchFallthroughBranch[@Default = "false"] | | | +- SwitchLabel[@Default = "false"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Thursday", @Empty = "false", @Image = ""Thursday"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Thursday", @Empty = "false", @Image = "\"Thursday\"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- ExpressionStatement[] | | | | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "typeOfDay", @Name = "typeOfDay", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Midweek", @Empty = "false", @Image = ""Midweek"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Midweek", @Empty = "false", @Image = "\"Midweek\"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = "false"] | | | +- SwitchLabel[@Default = "false"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Friday", @Empty = "false", @Image = ""Friday"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Friday", @Empty = "false", @Image = "\"Friday\"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- ExpressionStatement[] | | | | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "typeOfDay", @Name = "typeOfDay", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "End of work week", @Empty = "false", @Image = ""End of work week"", @Length = "16", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "End of work week", @Empty = "false", @Image = "\"End of work week\"", @Length = "16", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = "false"] | | | +- SwitchLabel[@Default = "false"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Saturday", @Empty = "false", @Image = ""Saturday"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Saturday", @Empty = "false", @Image = "\"Saturday\"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- SwitchFallthroughBranch[@Default = "false"] | | | +- SwitchLabel[@Default = "false"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Sunday", @Empty = "false", @Image = ""Sunday"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Sunday", @Empty = "false", @Image = "\"Sunday\"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- ExpressionStatement[] | | | | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- VariableAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "typeOfDay", @Name = "typeOfDay", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Weekend", @Empty = "false", @Image = ""Weekend"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Weekend", @Empty = "false", @Image = "\"Weekend\"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = "true"] | | +- SwitchLabel[@Default = "true"] @@ -305,7 +305,7 @@ | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "IllegalArgumentException"] | | +- ArgumentList[@Size = "1"] | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "+", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Invalid day of the week: ", @Empty = "false", @Image = ""Invalid day of the week: "", @Length = "25", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Invalid day of the week: ", @Empty = "false", @Image = "\"Invalid day of the week: \"", @Length = "25", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "dayOfWeekArg", @Name = "dayOfWeekArg", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- ReturnStatement[] | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "typeOfDay", @Name = "typeOfDay", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -358,7 +358,7 @@ | | +- MethodCall[@CompileTimeConstant = "false", @Image = "add", @MethodName = "add", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "list", @Name = "list", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- ArgumentList[@Size = "1"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "A", @Empty = "false", @Image = ""A"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "A", @Empty = "false", @Image = "\"A\"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "List"] @@ -387,7 +387,7 @@ | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "MyClass"] | | +- TypeArguments[@Diamond = "true", @Size = "0"] | +- ArgumentList[@Size = "1"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "true", @Image = """", @Length = "0", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "true", @Image = "\"\"", @Length = "0", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- MethodDeclaration[@Abstract = "false", @Arity = "0", @EffectiveVisibility = "public", @Image = "theTryWithResourcesStatement", @Name = "theTryWithResourcesStatement", @Overridden = "false", @Varargs = "false", @Visibility = "public", @Void = "true"] | +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"] | +- VoidType[] @@ -400,7 +400,7 @@ | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | | +- VariableDeclarator[@Initializer = "true", @Name = "path"] | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "path", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "/foo", @Empty = "false", @Image = ""/foo"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "/foo", @Empty = "false", @Image = "\"/foo\"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- TryStatement[@TryWithResources = "true"] | | +- ResourceList[@Size = "1", @TrailingSemiColon = "false"] | | | +- Resource[@ConciseResource = "false", @StableName = "br"] @@ -430,13 +430,13 @@ | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | | +- VariableDeclarator[@Initializer = "true", @Name = "outputFileName"] | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "outputFileName", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "/foo-out", @Empty = "false", @Image = ""/foo-out"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "/foo-out", @Empty = "false", @Image = "\"/foo-out\"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | | +- VariableDeclarator[@Initializer = "true", @Name = "zipFileName"] | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "zipFileName", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "/foo.zip", @Empty = "false", @Image = ""/foo.zip"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "/foo.zip", @Empty = "false", @Image = "\"/foo.zip\"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | +- ClassOrInterfaceType[@FullyQualified = "true", @SimpleName = "Charset"] @@ -446,7 +446,7 @@ | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- ClassOrInterfaceType[@FullyQualified = "true", @SimpleName = "Charset"] | | +- ArgumentList[@Size = "1"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "US-ASCII", @Empty = "false", @Image = ""US-ASCII"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "US-ASCII", @Empty = "false", @Image = "\"US-ASCII\"", @Length = "8", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | +- ClassOrInterfaceType[@FullyQualified = "true", @SimpleName = "Path"] @@ -508,7 +508,7 @@ | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | +- ArgumentList[@Size = "1"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "line.separator", @Empty = "false", @Image = ""line.separator"", @Length = "14", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "line.separator", @Empty = "false", @Image = "\"line.separator\"", @Length = "14", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] @@ -547,7 +547,7 @@ | | | +- ConstructorCall[@AnonymousClass = "false", @CompileTimeConstant = "false", @DiamondTypeArgs = "false", @MethodName = "new", @ParenthesisDepth = "0", @Parenthesized = "false", @QualifiedInstanceCreation = "false"] | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "File"] | | | | +- ArgumentList[@Size = "1"] - | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "foo", @Empty = "false", @Image = ""foo"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "foo", @Empty = "false", @Image = "\"foo\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- ArgumentList[@Size = "0"] | | +- Block[@Size = "1", @containsComment = "false"] | | +- ThrowStatement[] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases18.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases18.txt index 00a3930c96..934e32b8a6 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases18.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases18.txt @@ -33,7 +33,7 @@ | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "f", @Name = "f", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ArgumentList[@Size = "0"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ".java", @Empty = "false", @Image = "".java"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ".java", @Empty = "false", @Image = "\".java\"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "FileFilter"] @@ -49,7 +49,7 @@ | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "f", @Name = "f", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ArgumentList[@Size = "0"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ".java", @Empty = "false", @Image = "".java"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ".java", @Empty = "false", @Image = "\".java\"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "FileFilter"] @@ -65,7 +65,7 @@ | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "f", @Name = "f", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ArgumentList[@Size = "0"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ".java", @Empty = "false", @Image = "".java"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ".java", @Empty = "false", @Image = "\".java\"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "FileFilter"] @@ -81,7 +81,7 @@ | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "f", @Name = "f", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ArgumentList[@Size = "0"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ".java", @Empty = "false", @Image = "".java"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = ".java", @Empty = "false", @Image = "\".java\"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- ExpressionStatement[] | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "forEach", @MethodName = "forEach", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "parallel", @MethodName = "parallel", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -148,7 +148,7 @@ | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "f", @Name = "f", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ArgumentList[@Size = "0"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "q", @Empty = "false", @Image = ""q"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "q", @Empty = "false", @Image = "\"q\"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- ExpressionStatement[] | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "filterFiles", @MethodName = "filterFiles", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- ArgumentList[@Size = "1"] @@ -184,7 +184,7 @@ | | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "f", @Name = "f", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ArgumentList[@Size = "0"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "q", @Empty = "false", @Image = ""q"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "q", @Empty = "false", @Image = "\"q\"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] @@ -198,7 +198,7 @@ | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "user.name", @Empty = "false", @Image = ""user.name"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "user.name", @Empty = "false", @Image = "\"user.name\"", @Length = "9", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "Callable"] @@ -208,7 +208,7 @@ | | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "c", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] | | | +- LambdaExpression[@BlockBody = "false", @CompileTimeConstant = "false", @ExpressionBody = "true", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- LambdaParameterList[@Size = "0"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "done", @Empty = "false", @Image = ""done"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "done", @Empty = "false", @Image = "\"done\"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "Runnable"] @@ -223,7 +223,7 @@ | | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "done", @Empty = "false", @Image = ""done"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "done", @Empty = "false", @Image = "\"done\"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "Supplier"] @@ -242,7 +242,7 @@ | | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "hi", @Empty = "false", @Image = ""hi"", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "hi", @Empty = "false", @Image = "\"hi\"", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | | +- PrimitiveType[@Kind = "boolean"] @@ -282,7 +282,7 @@ | | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "hi", @Empty = "false", @Image = ""hi"", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "hi", @Empty = "false", @Image = "\"hi\"", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- ExpressionStatement[] | | | +- MethodCall[@CompileTimeConstant = "false", @Image = "run", @MethodName = "run", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "r1", @Name = "r1", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -513,7 +513,7 @@ | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | +- ArgumentList[@Size = "1"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "later", @Empty = "false", @Image = ""later"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "later", @Empty = "false", @Image = "\"later\"", @Length = "5", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- MethodDeclaration[@Abstract = "false", @Arity = "1", @EffectiveVisibility = "private", @Image = "doPrivileged", @Name = "doPrivileged", @Overridden = "false", @Varargs = "false", @Visibility = "private", @Void = "false"] | | +- ModifierList[@EffectiveModifiers = "{private}", @ExplicitModifiers = "{private}"] | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] @@ -709,7 +709,7 @@ | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | +- ArgumentList[@Size = "1"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "run", @Empty = "false", @Image = ""run"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "run", @Empty = "false", @Image = "\"run\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- MethodDeclaration[@Abstract = "false", @Arity = "0", @EffectiveVisibility = "public", @Image = "typeAnnotations", @Name = "typeAnnotations", @Overridden = "false", @Varargs = "false", @Visibility = "public", @Void = "true"] | | +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"] | | +- VoidType[] @@ -1092,4 +1092,4 @@ | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] +- ArgumentList[@Size = "1"] - +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "true", @Image = """", @Length = "0", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "true", @Image = "\"\"", @Length = "0", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchStatements.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchStatements.txt index bcba0a3909..1f72870a4c 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchStatements.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchStatements.txt @@ -33,7 +33,7 @@ | | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | +- ArgumentList[@Size = "1"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "1", @Empty = "false", @Image = ""1"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "1", @Empty = "false", @Image = "\"1\"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- BreakStatement[@Label = null] +- SwitchFallthroughBranch[@Default = "true"] +- SwitchLabel[@Default = "true"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15/TextBlocks.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15/TextBlocks.txt index 364cba52b2..63e3d9eac1 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15/TextBlocks.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15/TextBlocks.txt @@ -23,18 +23,7 @@ | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "html"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "html", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " - -

Hello, world

- - -", @Empty = "false", @Image = """" - - -

Hello, world

- - - """", @Length = "66", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "\n \n

Hello, world

\n \n\n", @Empty = "false", @Image = "\"\"\"\n \n \n

Hello, world

\n \n \n \"\"\"", @Length = "66", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- ExpressionStatement[] | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -47,14 +36,7 @@ | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "query"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "query", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "SELECT `EMP_ID`, `LAST_NAME` FROM `EMPLOYEE_TB` -WHERE `CITY` = 'INDIANAPOLIS' -ORDER BY `EMP_ID`, `LAST_NAME`; -", @Empty = "false", @Image = """" - SELECT `EMP_ID`, `LAST_NAME` FROM `EMPLOYEE_TB` - WHERE `CITY` = 'INDIANAPOLIS' - ORDER BY `EMP_ID`, `LAST_NAME`; - """", @Length = "110", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "SELECT `EMP_ID`, `LAST_NAME` FROM `EMPLOYEE_TB`\nWHERE `CITY` = \'INDIANAPOLIS\'\nORDER BY `EMP_ID`, `LAST_NAME`;\n", @Empty = "false", @Image = "\"\"\"\n SELECT `EMP_ID`, `LAST_NAME` FROM `EMPLOYEE_TB`\n WHERE `CITY` = \'INDIANAPOLIS\'\n ORDER BY `EMP_ID`, `LAST_NAME`;\n \"\"\"", @Length = "110", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- ExpressionStatement[] | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -72,7 +54,7 @@ ORDER BY `EMP_ID`, `LAST_NAME`; | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "ScriptEngineManager"] | | +- ArgumentList[@Size = "0"] | +- ArgumentList[@Size = "1"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "js", @Empty = "false", @Image = ""js"", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "js", @Empty = "false", @Image = "\"js\"", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "Object"] @@ -81,35 +63,13 @@ ORDER BY `EMP_ID`, `LAST_NAME`; | +- MethodCall[@CompileTimeConstant = "false", @Image = "eval", @MethodName = "eval", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "engine", @Name = "engine", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- ArgumentList[@Size = "1"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "function hello() { - print('"Hello, world"'); -} - -hello(); -", @Empty = "false", @Image = """" - function hello() { - print('"Hello, world"'); - } - - hello(); - """", @Length = "60", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "function hello() {\n print(\'\"Hello, world\"\');\n}\n\nhello();\n", @Empty = "false", @Image = "\"\"\"\n function hello() {\n print(\'\"Hello, world\"\');\n }\n \n hello();\n \"\"\"", @Length = "60", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "htmlWithEscapes"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "htmlWithEscapes", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " - -

Hello, world

- - -", @Empty = "false", @Image = """" - - -

Hello, world

- - - """", @Length = "71", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "\r\n \r\n

Hello, world

\r\n \r\n\r\n", @Empty = "false", @Image = "\"\"\"\n \\r\n \\r\n

Hello, world

\\r\n \\r\n \\r\n \"\"\"", @Length = "71", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- ExpressionStatement[] | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -122,91 +82,61 @@ hello(); | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "season"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "season", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "winter", @Empty = "false", @Image = """" - winter"""", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "winter", @Empty = "false", @Image = "\"\"\"\n winter\"\"\"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "period"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "period", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "winter -", @Empty = "false", @Image = """" - winter - """", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "winter\n", @Empty = "false", @Image = "\"\"\"\n winter\n \"\"\"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "greeting"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "greeting", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Hi, "Bob" -", @Empty = "false", @Image = """" - Hi, "Bob" - """", @Length = "10", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Hi, \"Bob\"\n", @Empty = "false", @Image = "\"\"\"\n Hi, \"Bob\"\n \"\"\"", @Length = "10", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "salutation"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "salutation", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Hi, - "Bob" -", @Empty = "false", @Image = """" - Hi, - "Bob" - """", @Length = "11", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Hi,\n \"Bob\"\n", @Empty = "false", @Image = "\"\"\"\n Hi,\n \"Bob\"\n \"\"\"", @Length = "11", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "empty"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "empty", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "true", @Image = """" - """", @Length = "0", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "true", @Image = "\"\"\"\n \"\"\"", @Length = "0", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "quote"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "quote", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "" -", @Empty = "false", @Image = """" - " - """", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "\"\n", @Empty = "false", @Image = "\"\"\"\n \"\n \"\"\"", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "backslash"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "backslash", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " -", @Empty = "false", @Image = """" - \ - """", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "\\\n", @Empty = "false", @Image = "\"\"\"\n \\\\\n \"\"\"", @Length = "2", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "normalStringLiteral"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "normalStringLiteral", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "test", @Empty = "false", @Image = ""test"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "test", @Empty = "false", @Image = "\"test\"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "code"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "code", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "String text = """ - A text block inside a text block -"""; -", @Empty = "false", @Image = """" - String text = """ - A text block inside a text block - """; - """", @Length = "60", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "String text = \"\"\"\n A text block inside a text block\n\"\"\";\n", @Empty = "false", @Image = "\"\"\"\n String text = \\\"\"\"\n A text block inside a text block\n \\\"\"\";\n \"\"\"", @Length = "60", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "text"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "text", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", @Empty = "false", @Image = """" - Lorem ipsum dolor sit amet, consectetur adipiscing - elit, sed do eiusmod tempor incididunt ut labore - et dolore magna aliqua. - """", @Length = "123", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", @Empty = "false", @Image = "\"\"\"\n Lorem ipsum dolor sit amet, consectetur adipiscing \\\n elit, sed do eiusmod tempor incididunt ut labore \\\n et dolore magna aliqua.\\\n \"\"\"", @Length = "123", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- ExpressionStatement[] | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -219,14 +149,7 @@ hello(); | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "colors"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "colors", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "red -green -blue -", @Empty = "false", @Image = """" - red s - greens - blue s - """", @Length = "21", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "red \ngreen \nblue \n", @Empty = "false", @Image = "\"\"\"\n red \\s\n green\\s\n blue \\s\n \"\"\"", @Length = "21", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- ExpressionStatement[] | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -239,12 +162,7 @@ blue | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "emptyLine"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "emptyLine", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " -test -", @Empty = "false", @Image = """" - -test -"""", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "\ntest\n", @Empty = "false", @Image = "\"\"\"\n\ntest\n\"\"\"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- ExpressionStatement[] | +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -254,19 +172,14 @@ test | +- MethodCall[@CompileTimeConstant = "false", @Image = "replaceAll", @MethodName = "replaceAll", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "emptyLine", @Name = "emptyLine", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- ArgumentList[@Size = "2"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " -", @Empty = "false", @Image = "" -"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "false", @Image = """", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "\n", @Empty = "false", @Image = "\"\\n\"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "false", @Image = "\"\"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- LocalVariableDeclaration[@EffectiveVisibility = "local", @Final = "false", @TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "bs"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "bs", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " est -", @Empty = "false", @Image = """" - \test - """", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "\\test\n", @Empty = "false", @Image = "\"\"\"\n \\\\test\n \"\"\"", @Length = "6", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "true"] +- ExpressionStatement[] +- MethodCall[@CompileTimeConstant = "false", @Image = "println", @MethodName = "println", @ParenthesisDepth = "0", @Parenthesized = "false"] +- FieldAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "out", @Name = "out", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -276,7 +189,5 @@ test +- MethodCall[@CompileTimeConstant = "false", @Image = "replaceAll", @MethodName = "replaceAll", @ParenthesisDepth = "0", @Parenthesized = "false"] +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "bs", @Name = "bs", @ParenthesisDepth = "0", @Parenthesized = "false"] +- ArgumentList[@Size = "2"] - +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = " -", @Empty = "false", @Image = "" -"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] - +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "false", @Image = """", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "\n", @Empty = "false", @Image = "\"\\n\"", @Length = "1", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "", @Empty = "false", @Image = "\"\"", @Length = "4", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15p/PatternMatchingInstanceof.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15p/PatternMatchingInstanceof.txt index 67127598d6..5853cd3aa5 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15p/PatternMatchingInstanceof.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15p/PatternMatchingInstanceof.txt @@ -7,7 +7,7 @@ | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "s"] | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "private", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "true", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "false", @Name = "s", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "private"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "other string", @Empty = "false", @Image = ""other string"", @Length = "12", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "other string", @Empty = "false", @Image = "\"other string\"", @Length = "12", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] +- MethodDeclaration[@Abstract = "false", @Arity = "0", @EffectiveVisibility = "public", @Image = "test", @Name = "test", @Overridden = "false", @Varargs = "false", @Visibility = "public", @Void = "true"] | +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"] | +- VoidType[] @@ -18,7 +18,7 @@ | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "Object"] | | +- VariableDeclarator[@Initializer = "true", @Name = "obj"] | | +- VariableDeclaratorId[@ArrayType = "false", @EffectiveVisibility = "local", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @Final = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "obj", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "local"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "abc", @Empty = "false", @Image = ""abc"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "abc", @Empty = "false", @Image = "\"abc\"", @Length = "3", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- IfStatement[@Else = "true"] | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "instanceof", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "obj", @Name = "obj", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -35,7 +35,7 @@ | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | | +- ArgumentList[@Size = "1"] | | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "+", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "a) obj == s: ", @Empty = "false", @Image = ""a) obj == s: "", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "a) obj == s: ", @Empty = "false", @Image = "\"a) obj == s: \"", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "==", @ParenthesisDepth = "1", @Parenthesized = "true"] | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "obj", @Name = "obj", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "s", @Name = "s", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -47,7 +47,7 @@ | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | +- ArgumentList[@Size = "1"] | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "+", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "b) obj == s: ", @Empty = "false", @Image = ""b) obj == s: "", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "b) obj == s: ", @Empty = "false", @Image = "\"b) obj == s: \"", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "==", @ParenthesisDepth = "1", @Parenthesized = "true"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "obj", @Name = "obj", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "s", @Name = "s", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -68,7 +68,7 @@ | | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | | +- ArgumentList[@Size = "1"] | | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "+", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "c) obj == s: ", @Empty = "false", @Image = ""c) obj == s: "", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "c) obj == s: ", @Empty = "false", @Image = "\"c) obj == s: \"", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "==", @ParenthesisDepth = "1", @Parenthesized = "true"] | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "obj", @Name = "obj", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "s", @Name = "s", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -80,7 +80,7 @@ | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | +- ArgumentList[@Size = "1"] | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "+", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "d) obj == s: ", @Empty = "false", @Image = ""d) obj == s: "", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "d) obj == s: ", @Empty = "false", @Image = "\"d) obj == s: \"", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "==", @ParenthesisDepth = "1", @Parenthesized = "true"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "obj", @Name = "obj", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "s", @Name = "s", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -106,7 +106,7 @@ | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | | +- ArgumentList[@Size = "1"] | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "+", @ParenthesisDepth = "0", @Parenthesized = "false"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "e) obj == s: ", @Empty = "false", @Image = ""e) obj == s: "", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "e) obj == s: ", @Empty = "false", @Image = "\"e) obj == s: \"", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "==", @ParenthesisDepth = "1", @Parenthesized = "true"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "obj", @Name = "obj", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "s", @Name = "s", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -132,7 +132,7 @@ | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "System"] | +- ArgumentList[@Size = "1"] | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "+", @ParenthesisDepth = "0", @Parenthesized = "false"] - | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "f) obj == s: ", @Empty = "false", @Image = ""f) obj == s: "", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "f) obj == s: ", @Empty = "false", @Image = "\"f) obj == s: \"", @Length = "13", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | +- InfixExpression[@CompileTimeConstant = "false", @Operator = "==", @ParenthesisDepth = "1", @Parenthesized = "true"] | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "obj", @Name = "obj", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "s", @Name = "s", @ParenthesisDepth = "0", @Parenthesized = "false"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15p/Records.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15p/Records.txt index bad5cddde6..146428c941 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15p/Records.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java15p/Records.txt @@ -67,7 +67,7 @@ | | | +- ConstructorCall[@AnonymousClass = "false", @CompileTimeConstant = "false", @DiamondTypeArgs = "false", @MethodName = "new", @ParenthesisDepth = "0", @Parenthesized = "false", @QualifiedInstanceCreation = "false"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "IllegalArgumentException"] | | | +- ArgumentList[@Size = "1"] - | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "too big", @Empty = "false", @Image = ""too big"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "too big", @Empty = "false", @Image = "\"too big\"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- ExpressionStatement[] | | | +- AssignmentExpression[@CompileTimeConstant = "false", @Compound = "false", @Operator = "=", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- FieldAccess[@AccessType = "WRITE", @CompileTimeConstant = "false", @Image = "real", @Name = "real", @ParenthesisDepth = "0", @Parenthesized = "false"] @@ -118,7 +118,7 @@ | | +- TypeExpression[@CompileTimeConstant = "false", @ParenthesisDepth = "0", @Parenthesized = "false"] | | | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | | +- ArgumentList[@Size = "3"] - | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "(%d,%d)", @Empty = "false", @Image = ""(%d,%d)"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] + | | +- StringLiteral[@CompileTimeConstant = "true", @ConstValue = "(%d,%d)", @Empty = "false", @Image = "\"(%d,%d)\"", @Length = "7", @ParenthesisDepth = "0", @Parenthesized = "false", @TextBlock = "false"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "lo", @Name = "lo", @ParenthesisDepth = "0", @Parenthesized = "false"] | | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "hi", @Name = "hi", @ParenthesisDepth = "0", @Parenthesized = "false"] | +- MethodDeclaration[@Abstract = "false", @Arity = "0", @EffectiveVisibility = "public", @Image = "foo", @Name = "foo", @Overridden = "false", @Varargs = "false", @Visibility = "public", @Void = "true"] diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt index 25ebe215a3..eacb1292b0 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt @@ -6,8 +6,8 @@ package net.sourceforge.pmd.lang.ast.test import net.sourceforge.pmd.lang.ast.Node import net.sourceforge.pmd.lang.rule.xpath.Attribute +import net.sourceforge.pmd.util.StringUtil import net.sourceforge.pmd.util.treeexport.TextTreeRenderer -import org.apache.commons.lang3.StringEscapeUtils /** * Prints just the structure, like so: @@ -68,7 +68,7 @@ open class BaseNodeAttributePrinter : TextTreeRenderer(true, -1) { protected open fun valueToString(value: Any?): String? { return when (value) { - is String -> "\"" + StringEscapeUtils.unescapeJava(value) + "\"" + is String -> "\"" + StringUtil.escapeJava(value) + "\"" is Char -> '\''.toString() + value.toString().replace("'".toRegex(), "\\'") + '\''.toString() is Enum<*> -> value.enumDeclaringClass.simpleName + "." + value.name is Class<*> -> value.canonicalName?.let { "$it.class" } From 2ac5a4907e1e79eedb795750ffefc6e8cc5a9be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 12 Dec 2020 23:01:06 +0100 Subject: [PATCH 3/6] Remove XML dom rule --- .../pmd/lang/xml/rule/AbstractDomXmlRule.java | 131 ----------- .../lang/xml/rule/AbstractDomXmlRuleTest.java | 213 ------------------ 2 files changed, 344 deletions(-) delete mode 100644 pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/AbstractDomXmlRule.java delete mode 100644 pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/rule/AbstractDomXmlRuleTest.java diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/AbstractDomXmlRule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/AbstractDomXmlRule.java deleted file mode 100644 index 13f3ebb65a..0000000000 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/AbstractDomXmlRule.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.xml.rule; - -import org.w3c.dom.Attr; -import org.w3c.dom.CharacterData; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Entity; -import org.w3c.dom.EntityReference; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.Notation; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.xml.ast.XmlNode; - -/** - * This is a base class for XML Java bases rules that which to visit the nodes - * using the DOM. Subclasses should override the DOM appropriate method and can - * call super to visit children. - */ -public class AbstractDomXmlRule extends AbstractXmlRule { - - @Override - protected void visit(XmlNode node, RuleContext ctx) { - final Node domNode = node.getNode(); - - // Visit the node - visitDomNode(node, domNode, ctx); - - // Visit attributes - visitAttributeNodes(node, domNode, ctx); - } - - protected void visitDomNode(XmlNode node, Node domNode, RuleContext ctx) { - switch (domNode.getNodeType()) { - case Node.CDATA_SECTION_NODE: - visit(node, (CharacterData) domNode, ctx); - break; - case Node.COMMENT_NODE: - visit(node, (Comment) domNode, ctx); - break; - case Node.DOCUMENT_NODE: - visit(node, (Document) domNode, ctx); - break; - case Node.DOCUMENT_TYPE_NODE: - visit(node, (DocumentType) domNode, ctx); - break; - case Node.ELEMENT_NODE: - visit(node, (Element) domNode, ctx); - break; - case Node.ENTITY_NODE: - visit(node, (Entity) domNode, ctx); - break; - case Node.ENTITY_REFERENCE_NODE: - visit(node, (EntityReference) domNode, ctx); - break; - case Node.NOTATION_NODE: - visit(node, (Notation) domNode, ctx); - break; - case Node.PROCESSING_INSTRUCTION_NODE: - visit(node, (ProcessingInstruction) domNode, ctx); - break; - case Node.TEXT_NODE: - visit(node, (Text) domNode, ctx); - break; - default: - throw new RuntimeException("Unexpected node type: " + domNode.getNodeType() + " on node: " + domNode); - } - } - - protected void visitAttributeNodes(XmlNode node, Node domNode, RuleContext ctx) { - NamedNodeMap attributes = domNode.getAttributes(); - if (attributes != null) { - for (int i = 0; i < attributes.getLength(); i++) { - visit(node, (Attr) attributes.item(i), ctx); - } - } - } - - protected void visit(XmlNode node, Attr attr, RuleContext ctx) { - // does nothing by default since attributes are leaf nodes - } - - protected void visit(XmlNode node, CharacterData characterData, RuleContext ctx) { - super.visit(node, ctx); - } - - protected void visit(XmlNode node, Comment comment, RuleContext ctx) { - super.visit(node, ctx); - } - - protected void visit(XmlNode node, Document document, RuleContext ctx) { - super.visit(node, ctx); - } - - protected void visit(XmlNode node, DocumentType documentType, RuleContext ctx) { - super.visit(node, ctx); - } - - protected void visit(XmlNode node, Element element, RuleContext ctx) { - super.visit(node, ctx); - } - - protected void visit(XmlNode node, Entity entity, RuleContext ctx) { - super.visit(node, ctx); - } - - protected void visit(XmlNode node, EntityReference entityReference, RuleContext ctx) { - super.visit(node, ctx); - } - - protected void visit(XmlNode node, Notation notation, RuleContext ctx) { - super.visit(node, ctx); - } - - protected void visit(XmlNode node, ProcessingInstruction processingInstruction, RuleContext ctx) { - super.visit(node, ctx); - } - - protected void visit(XmlNode node, Text text, RuleContext ctx) { - super.visit(node, ctx); - } -} diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/rule/AbstractDomXmlRuleTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/rule/AbstractDomXmlRuleTest.java deleted file mode 100644 index 19d8ea3c70..0000000000 --- a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/rule/AbstractDomXmlRuleTest.java +++ /dev/null @@ -1,213 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.xml.rule; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.w3c.dom.Attr; -import org.w3c.dom.CharacterData; -import org.w3c.dom.Comment; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Entity; -import org.w3c.dom.EntityReference; -import org.w3c.dom.Notation; -import org.w3c.dom.ProcessingInstruction; -import org.w3c.dom.Text; - -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.xml.XmlParserOptions; -import net.sourceforge.pmd.lang.xml.XmlParsingHelper; -import net.sourceforge.pmd.lang.xml.ast.XmlNode; - -public class AbstractDomXmlRuleTest { - - @Test - public void testVisit() throws Exception { - String source = "]>TEXT>&entity;<"; - XmlParserOptions parserOptions = new XmlParserOptions(); - parserOptions.setExpandEntityReferences(false); - - XmlNode xmlNode = XmlParsingHelper.XML.withParserOptions(parserOptions).parse(source); - MyRule rule = new MyRule(); - rule.apply(xmlNode, null); - - List visited = rule.visitedNodes.get("Attr"); - assertEquals(1, visited.size()); - assertEquals("abc", visited.get(0).getLocalName()); - - visited = rule.visitedNodes.get("CharacterData"); - assertEquals(1, visited.size()); - assertEquals("cdata!", ((CharacterData) visited.get(0)).getData()); - - visited = rule.visitedNodes.get("Comment"); - assertEquals("Comment", ((Comment) visited.get(0)).getData()); - - visited = rule.visitedNodes.get("Document"); - assertEquals(1, visited.size()); - - visited = rule.visitedNodes.get("DocumentType"); - assertEquals("testDoc", ((DocumentType) visited.get(0)).getName()); - - visited = rule.visitedNodes.get("Element"); - assertEquals(2, visited.size()); - assertEquals("foo", visited.get(0).getLocalName()); - assertEquals("bar", visited.get(1).getLocalName()); - - // TODO Figure out how to trigger this. - // visited = rule.visitedNodes.get("Entity"); - // assertEquals(0, visited.size()); - - visited = rule.visitedNodes.get("EntityReference"); - assertEquals(1, visited.size()); - assertEquals("entity", ((EntityReference) visited.get(0)).getNodeName()); - - // TODO Figure out how to trigger this. - // visited = rule.visitedNodes.get("Notation"); - // assertEquals(0, visited.size()); - - visited = rule.visitedNodes.get("ProcessingInstruction"); - assertEquals(1, visited.size()); - assertEquals("mypi", ((ProcessingInstruction) visited.get(0)).getTarget()); - - visited = rule.visitedNodes.get("Text"); - assertEquals(3, visited.size()); - assertEquals("TEXT", ((Text) visited.get(0)).getData()); - assertEquals(">", ((Text) visited.get(1)).getData()); - String text = ((Text) visited.get(2)).getData(); - if ("<".equals(text)) { - // java13 and later don't expand entities if setExpandEntityReferences==false - assertEquals("<", ((Text) visited.get(2)).getData()); - } else { - assertEquals("e<", ((Text) visited.get(2)).getData()); - } - } - - @Test - public void dtdIsNotLookedUp() { - String source = "" + ""; - XmlParserOptions parserOptions = new XmlParserOptions(); - parserOptions.setLookupDescriptorDoc(false); - XmlNode xmlNode = XmlParsingHelper.XML.withParserOptions(parserOptions).parse(source); - // no exception should be thrown - - MyRule rule = new MyRule(); - rule.apply(xmlNode, null); - - // first element is still parsed - assertNotNull(rule.visitedNodes.get("Element")); - - } - - @Test - public void xsdIsNotLookedUp() { - String source = " " - + "" + ""; - XmlNode xmlNode = XmlParsingHelper.XML.parse(source); - // no exception should be thrown - // first element is still parsed - MyRule rule = new MyRule(); - rule.apply(xmlNode, null); - - assertNotNull(rule.visitedNodes.get("Element")); - - } - - private static class MyRule extends AbstractDomXmlRule { - final Map> visitedNodes = new HashMap<>(); - - MyRule() { - - } - - private void visit(String key, org.w3c.dom.Node node) { - List nodes = visitedNodes.get(key); - if (nodes == null) { - nodes = new ArrayList<>(); - visitedNodes.put(key, nodes); - } - nodes.add(node); - } - - @Override - protected void visit(XmlNode node, Attr attr, RuleContext ctx) { - visit("Attr", attr); - super.visit(node, attr, ctx); - } - - @Override - protected void visit(XmlNode node, CharacterData characterData, RuleContext ctx) { - visit("CharacterData", characterData); - super.visit(node, characterData, ctx); - } - - @Override - protected void visit(XmlNode node, Comment comment, RuleContext ctx) { - visit("Comment", comment); - super.visit(node, comment, ctx); - } - - @Override - protected void visit(XmlNode node, Document document, RuleContext ctx) { - visit("Document", document); - super.visit(node, document, ctx); - } - - @Override - protected void visit(XmlNode node, DocumentType documentType, RuleContext ctx) { - visit("DocumentType", documentType); - super.visit(node, documentType, ctx); - } - - @Override - protected void visit(XmlNode node, Element element, RuleContext ctx) { - visit("Element", element); - super.visit(node, element, ctx); - } - - @Override - protected void visit(XmlNode node, Entity entity, RuleContext ctx) { - visit("Entity", entity); - super.visit(node, entity, ctx); - } - - @Override - protected void visit(XmlNode node, EntityReference entityReference, RuleContext ctx) { - visit("EntityReference", entityReference); - super.visit(node, entityReference, ctx); - } - - @Override - protected void visit(XmlNode node, Notation notation, RuleContext ctx) { - visit("Notation", notation); - super.visit(node, notation, ctx); - } - - @Override - protected void visit(XmlNode node, ProcessingInstruction processingInstruction, RuleContext ctx) { - visit("ProcessingInstruction", processingInstruction); - super.visit(node, processingInstruction, ctx); - } - - @Override - protected void visit(XmlNode node, Text text, RuleContext ctx) { - visit("Text", text); - super.visit(node, text, ctx); - } - } -} From f6b1acbdd51b007809a511e6cb23984ba7292380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 12 Dec 2020 23:18:00 +0100 Subject: [PATCH 4/6] Remove xml parser options --- .../pmd/lang/ast/test/NodePrinters.kt | 19 + .../pmd/lang/wsdl/rule/AbstractWsdlRule.java | 20 - .../sourceforge/pmd/lang/xml/XmlHandler.java | 5 - .../sourceforge/pmd/lang/xml/XmlParser.java | 2 +- .../pmd/lang/xml/XmlParserOptions.java | 209 --------- .../lang/xml/ast/internal/XmlParserImpl.java | 26 +- .../pmd/lang/xml/rule/AbstractXmlRule.java | 66 +-- .../lang/wsdl/rule/AbstractWsdlRuleTest.java | 51 --- .../pmd/lang/xml/XmlParserOptionsTest.java | 168 ------- .../pmd/lang/xml/XmlParserTest.java | 412 ------------------ .../pmd/lang/xml/ast/XmlCoordinatesTest.java | 42 ++ .../pmd/lang/xml/ast/XmlParserTest.java | 43 ++ .../lang/xml/rule/AbstractXmlRuleTest.java | 50 --- .../pmd/lang/xml/ast/testdata/bug1518.txt | 69 +++ .../{parsertests => ast/testdata}/bug1518.xml | 0 .../pmd/lang/xml/ast/testdata/sampleNs.txt | 22 + .../pmd/lang/xml/ast/testdata/sampleNs.xml | 21 + .../pmd/lang/xml/ast/testdata/sampleXml.txt | 20 + .../pmd/lang/xml/ast/testdata/sampleXml.xml | 9 + .../pmd/lang/xml/ast/testdata/xmlCoords.txt | 17 + .../pmd/lang/xml/ast/testdata/xmlCoords.xml | 22 + 21 files changed, 296 insertions(+), 997 deletions(-) delete mode 100644 pmd-xml/src/main/java/net/sourceforge/pmd/lang/wsdl/rule/AbstractWsdlRule.java delete mode 100644 pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParserOptions.java delete mode 100644 pmd-xml/src/test/java/net/sourceforge/pmd/lang/wsdl/rule/AbstractWsdlRuleTest.java delete mode 100644 pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserOptionsTest.java delete mode 100644 pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserTest.java create mode 100644 pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlCoordinatesTest.java create mode 100644 pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlParserTest.java delete mode 100644 pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/rule/AbstractXmlRuleTest.java create mode 100644 pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.txt rename pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/{parsertests => ast/testdata}/bug1518.xml (100%) create mode 100644 pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.txt create mode 100644 pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.xml create mode 100644 pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.txt create mode 100644 pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.xml create mode 100644 pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/xmlCoords.txt create mode 100644 pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/xmlCoords.xml diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt index eacb1292b0..2e1c806cf3 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt @@ -33,6 +33,25 @@ open class RelevantAttributePrinter : BaseNodeAttributePrinter() { } +/** + * Only prints the begin/end coordinates. + */ +object CoordinatesPrinter : BaseNodeAttributePrinter() { + + private val Considered = setOf("BeginLine", "EndLine", "BeginColumn", "EndColumn") + + override fun fillAttributes(node: Node, result: MutableList) { + result += AttributeInfo("BeginLine", node.beginLine) + result += AttributeInfo("EndLine", node.endLine) + result += AttributeInfo("EndColumn", node.endColumn) + result += AttributeInfo("BeginColumn", node.beginColumn) + } + + override fun ignoreAttribute(node: Node, attribute: Attribute): Boolean = + attribute.name !in Considered + +} + /** * Base attribute printer, subclass to filter attributes. */ diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/wsdl/rule/AbstractWsdlRule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/wsdl/rule/AbstractWsdlRule.java deleted file mode 100644 index e348d84583..0000000000 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/wsdl/rule/AbstractWsdlRule.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.wsdl.rule; - -import net.sourceforge.pmd.lang.LanguageRegistry; -import net.sourceforge.pmd.lang.wsdl.WsdlLanguageModule; -import net.sourceforge.pmd.lang.xml.rule.AbstractXmlRule; - -/** - * Created by bernardo-macedo on 24.06.15. - */ -public class AbstractWsdlRule extends AbstractXmlRule { - - public AbstractWsdlRule() { - super(LanguageRegistry.getLanguage(WsdlLanguageModule.NAME)); - } - -} diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlHandler.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlHandler.java index 97d79e8b5d..16280f3b27 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlHandler.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlHandler.java @@ -13,11 +13,6 @@ import net.sourceforge.pmd.lang.ParserOptions; */ public class XmlHandler extends AbstractPmdLanguageVersionHandler { - @Override - public ParserOptions getDefaultParserOptions() { - return new XmlParserOptions(); - } - @Override public Parser getParser(ParserOptions parserOptions) { return new XmlParser(parserOptions); diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParser.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParser.java index 7b3a9a2935..6fec27a40f 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParser.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParser.java @@ -23,7 +23,7 @@ public class XmlParser extends AbstractParser { @Override public RootXmlNode parse(String fileName, Reader source) throws ParseException { - return new XmlParserImpl((XmlParserOptions) parserOptions).parse(source); + return new XmlParserImpl().parse(source); } } diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParserOptions.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParserOptions.java deleted file mode 100644 index b752d32b90..0000000000 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParserOptions.java +++ /dev/null @@ -1,209 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.xml; - -import java.io.ByteArrayInputStream; -import java.util.Objects; - -import org.xml.sax.EntityResolver; -import org.xml.sax.InputSource; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.lang.ParserOptions; -import net.sourceforge.pmd.properties.PropertyDescriptor; -import net.sourceforge.pmd.properties.PropertyFactory; - -/** - * @deprecated Parser options will be removed with 7.0, these options - * will assume their default values then. - */ -@Deprecated -public class XmlParserOptions extends ParserOptions { - - // Note: The UI order values are chosen to be larger than those built into - // XPathRule. - public static final PropertyDescriptor COALESCING_DESCRIPTOR = - PropertyFactory.booleanProperty("coalescing") - .desc("deprecated!Specifies that the XML parser convert CDATA nodes to Text nodes and append it to the adjacent (if any) text node.") - .defaultValue(false) - .build(); - public static final PropertyDescriptor EXPAND_ENTITY_REFERENCES_DESCRIPTOR = - PropertyFactory.booleanProperty("expandEntityReferences") - .desc("deprecated!Specifies that the XML parser expand entity reference nodes.") - .defaultValue(true) - .build(); - public static final PropertyDescriptor IGNORING_COMMENTS_DESCRIPTOR = - PropertyFactory.booleanProperty("ignoringComments") - .desc("deprecated!Specifies that the XML parser ignore comments.") - .defaultValue(false) - .build(); - public static final PropertyDescriptor IGNORING_ELEMENT_CONTENT_WHITESPACE_DESCRIPTOR = - PropertyFactory.booleanProperty("ignoringElementContentWhitespace") - .desc("deprecated!Specifies that the XML parser eliminate whitespace in element content. Setting this to 'true' will force validating.") - .defaultValue(false) - .build(); - public static final PropertyDescriptor NAMESPACE_AWARE_DESCRIPTOR = - PropertyFactory.booleanProperty("namespaceAware") - .desc("deprecated!Specifies that the XML parser will provide support for XML namespaces.") - .defaultValue(true) - .build(); - public static final PropertyDescriptor VALIDATING_DESCRIPTOR = - PropertyFactory.booleanProperty("validating") - .desc("deprecated!Specifies that the XML parser will validate documents as they are parsed. This only works for DTDs.") - .defaultValue(false) - .build(); - public static final PropertyDescriptor XINCLUDE_AWARE_DESCRIPTOR = - PropertyFactory.booleanProperty("xincludeAware") - .desc("deprecated!Specifies that the XML parser will process XInclude markup.") - .defaultValue(false) - .build(); - public static final PropertyDescriptor LOOKUP_DESCRIPTOR_DTD = - PropertyFactory.booleanProperty("xincludeAware") - .desc("deprecated!Specifies whether XML parser will attempt to lookup the DTD.") - .defaultValue(false) - .build(); - - public static final EntityResolver SILENT_ENTITY_RESOLVER = (publicId, systemId) -> new InputSource(new ByteArrayInputStream("".getBytes())); - - private boolean coalescing; - private boolean expandEntityReferences; - private boolean ignoringComments; - private boolean ignoringElementContentWhitespace; - private boolean namespaceAware; - private boolean validating; - private boolean xincludeAware; - private boolean lookupDescriptorDoc; - - public XmlParserOptions() { - this.coalescing = COALESCING_DESCRIPTOR.defaultValue(); - this.expandEntityReferences = EXPAND_ENTITY_REFERENCES_DESCRIPTOR.defaultValue(); - this.ignoringComments = IGNORING_COMMENTS_DESCRIPTOR.defaultValue(); - this.ignoringElementContentWhitespace = IGNORING_ELEMENT_CONTENT_WHITESPACE_DESCRIPTOR.defaultValue(); - this.namespaceAware = NAMESPACE_AWARE_DESCRIPTOR.defaultValue(); - this.validating = VALIDATING_DESCRIPTOR.defaultValue(); - this.xincludeAware = XINCLUDE_AWARE_DESCRIPTOR.defaultValue(); - this.lookupDescriptorDoc = LOOKUP_DESCRIPTOR_DTD.defaultValue(); - } - - public XmlParserOptions(Rule rule) { - this.coalescing = rule.getProperty(COALESCING_DESCRIPTOR); - this.expandEntityReferences = rule.getProperty(EXPAND_ENTITY_REFERENCES_DESCRIPTOR); - this.ignoringComments = rule.getProperty(IGNORING_COMMENTS_DESCRIPTOR); - this.ignoringElementContentWhitespace = rule.getProperty(IGNORING_ELEMENT_CONTENT_WHITESPACE_DESCRIPTOR); - this.namespaceAware = rule.getProperty(NAMESPACE_AWARE_DESCRIPTOR); - this.validating = rule.getProperty(VALIDATING_DESCRIPTOR); - this.xincludeAware = rule.getProperty(XINCLUDE_AWARE_DESCRIPTOR); - this.lookupDescriptorDoc = rule.getProperty(LOOKUP_DESCRIPTOR_DTD); - } - - /** - * - * @return the configured entity resolver. If {@link #lookupDescriptorDoc} - * is false it would normally force the XML parser to use its own - * resolver - */ - public EntityResolver getEntityResolver() { - if (!lookupDescriptorDoc) { - return SILENT_ENTITY_RESOLVER; - } else { - return null; - } - } - - public boolean isLookupDescriptorDoc() { - return lookupDescriptorDoc; - } - - public void setLookupDescriptorDoc(boolean lookupDescriptorDoc) { - this.lookupDescriptorDoc = lookupDescriptorDoc; - } - - public boolean isCoalescing() { - return this.coalescing; - } - - public void setCoalescing(boolean coalescing) { - this.coalescing = coalescing; - } - - public boolean isExpandEntityReferences() { - return this.expandEntityReferences; - } - - public void setExpandEntityReferences(boolean expandEntityReferences) { - this.expandEntityReferences = expandEntityReferences; - } - - public boolean isIgnoringComments() { - return this.ignoringComments; - } - - public void setIgnoringComments(boolean ignoringComments) { - this.ignoringComments = ignoringComments; - } - - public boolean isIgnoringElementContentWhitespace() { - return this.ignoringElementContentWhitespace; - } - - public void setIgnoringElementContentWhitespace(boolean ignoringElementContentWhitespace) { - this.ignoringElementContentWhitespace = ignoringElementContentWhitespace; - } - - public boolean isNamespaceAware() { - return this.namespaceAware; - } - - public void setNamespaceAware(boolean namespaceAware) { - this.namespaceAware = namespaceAware; - } - - public boolean isValidating() { - return this.validating; - } - - public void setValidating(boolean validating) { - this.validating = validating; - } - - public boolean isXincludeAware() { - return this.xincludeAware; - } - - public void setXincludeAware(boolean xincludeAware) { - this.xincludeAware = xincludeAware; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + (coalescing ? 1231 : 1237); - result = prime * result + (expandEntityReferences ? 1231 : 1237); - result = prime * result + (ignoringComments ? 1231 : 1237); - result = prime * result + (ignoringElementContentWhitespace ? 1231 : 1237); - result = prime * result + (namespaceAware ? 1231 : 1237); - result = prime * result + (validating ? 1231 : 1237); - result = prime * result + (xincludeAware ? 1231 : 1237); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null || getClass() != obj.getClass()) { - return false; - } - final XmlParserOptions that = (XmlParserOptions) obj; - return Objects.equals(this.getSuppressMarker(), that.getSuppressMarker()) - && this.coalescing == that.coalescing && this.expandEntityReferences == that.expandEntityReferences - && this.ignoringComments == that.ignoringComments - && this.ignoringElementContentWhitespace == that.ignoringElementContentWhitespace - && this.namespaceAware == that.namespaceAware && this.validating == that.validating - && this.xincludeAware == that.xincludeAware; - } -} diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java index ddc433af6f..dd94aaa7ba 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java @@ -21,19 +21,12 @@ import org.xml.sax.SAXException; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.RootNode; -import net.sourceforge.pmd.lang.xml.XmlParserOptions; import net.sourceforge.pmd.lang.xml.ast.XmlNode; -public class XmlParserImpl { +public final class XmlParserImpl { - private final XmlParserOptions parserOptions; - private Map nodeCache = new HashMap<>(); - - - public XmlParserImpl(XmlParserOptions parserOptions) { - this.parserOptions = parserOptions; - } + private final Map nodeCache = new HashMap<>(); private Document parseDocument(String xmlData) throws ParseException { @@ -41,17 +34,16 @@ public class XmlParserImpl { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(parserOptions.isNamespaceAware()); - dbf.setValidating(parserOptions.isValidating()); - dbf.setIgnoringComments(parserOptions.isIgnoringComments()); - dbf.setIgnoringElementContentWhitespace(parserOptions.isIgnoringElementContentWhitespace()); - dbf.setExpandEntityReferences(parserOptions.isExpandEntityReferences()); - dbf.setCoalescing(parserOptions.isCoalescing()); - dbf.setXIncludeAware(parserOptions.isXincludeAware()); + dbf.setNamespaceAware(true); + dbf.setValidating(false); + dbf.setIgnoringComments(false); + dbf.setIgnoringElementContentWhitespace(false); + dbf.setExpandEntityReferences(true); + dbf.setCoalescing(false); + dbf.setXIncludeAware(false); dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); DocumentBuilder documentBuilder = dbf.newDocumentBuilder(); - documentBuilder.setEntityResolver(parserOptions.getEntityResolver()); return documentBuilder.parse(new InputSource(new StringReader(xmlData))); } catch (ParserConfigurationException | SAXException | IOException e) { throw new ParseException(e); diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/AbstractXmlRule.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/AbstractXmlRule.java index 136ba4634a..6b2d9be243 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/AbstractXmlRule.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/AbstractXmlRule.java @@ -4,74 +4,12 @@ package net.sourceforge.pmd.lang.xml.rule; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.Language; -import net.sourceforge.pmd.lang.LanguageRegistry; -import net.sourceforge.pmd.lang.ParserOptions; -import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.rule.AbstractRule; -import net.sourceforge.pmd.lang.xml.XmlLanguageModule; -import net.sourceforge.pmd.lang.xml.XmlParserOptions; -import net.sourceforge.pmd.lang.xml.ast.XmlNode; -import net.sourceforge.pmd.properties.PropertyDescriptor; /** - * This is a base class for XML Java bases rules. Subclasses should override - * {@link #visit(XmlNode, RuleContext)} and can call super to visit - * children. + * This is a base class for XML Java bases rules. */ -public class AbstractXmlRule extends AbstractRule { +public abstract class AbstractXmlRule extends AbstractRule { - @Deprecated - public static final PropertyDescriptor COALESCING_DESCRIPTOR = XmlParserOptions.COALESCING_DESCRIPTOR; - @Deprecated - public static final PropertyDescriptor EXPAND_ENTITY_REFERENCES_DESCRIPTOR = XmlParserOptions.EXPAND_ENTITY_REFERENCES_DESCRIPTOR; - @Deprecated - public static final PropertyDescriptor IGNORING_COMMENTS_DESCRIPTOR = XmlParserOptions.IGNORING_COMMENTS_DESCRIPTOR; - @Deprecated - public static final PropertyDescriptor IGNORING_ELEMENT_CONTENT_WHITESPACE_DESCRIPTOR = XmlParserOptions.IGNORING_ELEMENT_CONTENT_WHITESPACE_DESCRIPTOR; - @Deprecated - public static final PropertyDescriptor NAMESPACE_AWARE_DESCRIPTOR = XmlParserOptions.NAMESPACE_AWARE_DESCRIPTOR; - @Deprecated - public static final PropertyDescriptor VALIDATING_DESCRIPTOR = XmlParserOptions.VALIDATING_DESCRIPTOR; - @Deprecated - public static final PropertyDescriptor XINCLUDE_AWARE_DESCRIPTOR = XmlParserOptions.XINCLUDE_AWARE_DESCRIPTOR; - public AbstractXmlRule() { - super.setLanguage(LanguageRegistry.getLanguage(XmlLanguageModule.NAME)); - defineProperties(); - } - - protected AbstractXmlRule(Language language) { - super.setLanguage(language); - defineProperties(); - } - - private void defineProperties() { - definePropertyDescriptor(COALESCING_DESCRIPTOR); - definePropertyDescriptor(EXPAND_ENTITY_REFERENCES_DESCRIPTOR); - definePropertyDescriptor(IGNORING_COMMENTS_DESCRIPTOR); - definePropertyDescriptor(IGNORING_ELEMENT_CONTENT_WHITESPACE_DESCRIPTOR); - definePropertyDescriptor(NAMESPACE_AWARE_DESCRIPTOR); - definePropertyDescriptor(VALIDATING_DESCRIPTOR); - definePropertyDescriptor(XINCLUDE_AWARE_DESCRIPTOR); - } - - @Override - public ParserOptions getParserOptions() { - return new XmlParserOptions(this); - } - - @Override - public void apply(Node target, RuleContext ctx) { - visit((XmlNode) target, ctx); - } - - protected void visit(XmlNode node, RuleContext ctx) { - final int numChildren = node.getNumChildren(); - for (int i = 0; i < numChildren; i++) { - XmlNode child = (XmlNode) node.getChild(i); - visit(child, ctx); - } - } } diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/wsdl/rule/AbstractWsdlRuleTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/wsdl/rule/AbstractWsdlRuleTest.java deleted file mode 100644 index 62578df6f3..0000000000 --- a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/wsdl/rule/AbstractWsdlRuleTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.wsdl.rule; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.xml.XmlParsingHelper; -import net.sourceforge.pmd.lang.xml.ast.XmlNode; - -public class AbstractWsdlRuleTest { - - @Test - public void testVisit() throws Exception { - String source = ""; - XmlNode xmlNode = XmlParsingHelper.WSDL.parse(source); - - MyRule rule = new MyRule(); - rule.apply(xmlNode, null); - - assertEquals(3, rule.visitedNodes.size()); - assertEquals("document", rule.visitedNodes.get(0).toString()); - assertEquals("foo", rule.visitedNodes.get(1).toString()); - assertEquals("bar", rule.visitedNodes.get(2).toString()); - } - - private static class MyRule extends AbstractWsdlRule { - final List visitedNodes = new ArrayList<>(); - - MyRule() { - } - - @Override - public void start(RuleContext ctx) { - visitedNodes.clear(); - } - - @Override - protected void visit(XmlNode node, RuleContext ctx) { - visitedNodes.add(node); - super.visit(node, ctx); - } - } -} diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserOptionsTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserOptionsTest.java deleted file mode 100644 index 547ea01bbe..0000000000 --- a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserOptionsTest.java +++ /dev/null @@ -1,168 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.xml; - -import static net.sourceforge.pmd.lang.ParserOptionsTestUtils.verifyOptionsEqualsHashcode; -import static net.sourceforge.pmd.util.CollectionUtil.listOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Test; - -import net.sourceforge.pmd.lang.ParserOptions; -import net.sourceforge.pmd.lang.xml.rule.AbstractXmlRule; -import net.sourceforge.pmd.properties.PropertyDescriptor; - -public class XmlParserOptionsTest { - - @Test - public void testDefaults() { - XmlParserOptions options = new XmlParserOptions(); - assertFalse(options.isCoalescing()); - assertTrue(options.isExpandEntityReferences()); - assertFalse(options.isIgnoringComments()); - assertFalse(options.isIgnoringElementContentWhitespace()); - assertTrue(options.isNamespaceAware()); - assertFalse(options.isValidating()); - assertFalse(options.isXincludeAware()); - - MyRule rule = new MyRule(); - options = (XmlParserOptions) rule.getParserOptions(); - assertFalse(options.isCoalescing()); - assertTrue(options.isExpandEntityReferences()); - assertFalse(options.isIgnoringComments()); - assertFalse(options.isIgnoringElementContentWhitespace()); - assertTrue(options.isNamespaceAware()); - assertFalse(options.isValidating()); - assertFalse(options.isXincludeAware()); - } - - @Test - public void testConstructor() { - MyRule rule = new MyRule(); - - rule.setProperty(XmlParserOptions.COALESCING_DESCRIPTOR, true); - assertTrue(((XmlParserOptions) rule.getParserOptions()).isCoalescing()); - rule.setProperty(XmlParserOptions.COALESCING_DESCRIPTOR, false); - assertFalse(((XmlParserOptions) rule.getParserOptions()).isCoalescing()); - - rule.setProperty(XmlParserOptions.EXPAND_ENTITY_REFERENCES_DESCRIPTOR, true); - assertTrue(((XmlParserOptions) rule.getParserOptions()).isExpandEntityReferences()); - rule.setProperty(XmlParserOptions.EXPAND_ENTITY_REFERENCES_DESCRIPTOR, false); - assertFalse(((XmlParserOptions) rule.getParserOptions()).isExpandEntityReferences()); - - rule.setProperty(XmlParserOptions.IGNORING_COMMENTS_DESCRIPTOR, true); - assertTrue(((XmlParserOptions) rule.getParserOptions()).isIgnoringComments()); - rule.setProperty(XmlParserOptions.IGNORING_COMMENTS_DESCRIPTOR, false); - assertFalse(((XmlParserOptions) rule.getParserOptions()).isIgnoringComments()); - - rule.setProperty(XmlParserOptions.IGNORING_ELEMENT_CONTENT_WHITESPACE_DESCRIPTOR, true); - assertTrue(((XmlParserOptions) rule.getParserOptions()).isIgnoringElementContentWhitespace()); - rule.setProperty(XmlParserOptions.IGNORING_ELEMENT_CONTENT_WHITESPACE_DESCRIPTOR, false); - assertFalse(((XmlParserOptions) rule.getParserOptions()).isIgnoringElementContentWhitespace()); - - rule.setProperty(XmlParserOptions.NAMESPACE_AWARE_DESCRIPTOR, true); - assertTrue(((XmlParserOptions) rule.getParserOptions()).isNamespaceAware()); - rule.setProperty(XmlParserOptions.NAMESPACE_AWARE_DESCRIPTOR, false); - assertFalse(((XmlParserOptions) rule.getParserOptions()).isNamespaceAware()); - - rule.setProperty(XmlParserOptions.VALIDATING_DESCRIPTOR, true); - assertTrue(((XmlParserOptions) rule.getParserOptions()).isValidating()); - rule.setProperty(XmlParserOptions.VALIDATING_DESCRIPTOR, false); - assertFalse(((XmlParserOptions) rule.getParserOptions()).isValidating()); - - rule.setProperty(XmlParserOptions.XINCLUDE_AWARE_DESCRIPTOR, true); - assertTrue(((XmlParserOptions) rule.getParserOptions()).isXincludeAware()); - rule.setProperty(XmlParserOptions.XINCLUDE_AWARE_DESCRIPTOR, false); - assertFalse(((XmlParserOptions) rule.getParserOptions()).isXincludeAware()); - } - - @Test - public void testSetters() { - XmlParserOptions options = new XmlParserOptions(); - - options.setSuppressMarker("foo"); - assertEquals("foo", options.getSuppressMarker()); - - options.setCoalescing(true); - assertTrue(options.isCoalescing()); - options.setCoalescing(false); - assertFalse(options.isCoalescing()); - - options.setExpandEntityReferences(true); - assertTrue(options.isExpandEntityReferences()); - options.setExpandEntityReferences(false); - assertFalse(options.isExpandEntityReferences()); - - options.setIgnoringComments(true); - assertTrue(options.isIgnoringComments()); - options.setIgnoringComments(false); - assertFalse(options.isIgnoringComments()); - - options.setIgnoringElementContentWhitespace(true); - assertTrue(options.isIgnoringElementContentWhitespace()); - options.setIgnoringElementContentWhitespace(false); - assertFalse(options.isIgnoringElementContentWhitespace()); - - options.setNamespaceAware(true); - assertTrue(options.isNamespaceAware()); - options.setNamespaceAware(false); - assertFalse(options.isNamespaceAware()); - - options.setValidating(true); - assertTrue(options.isValidating()); - options.setValidating(false); - assertFalse(options.isValidating()); - - options.setXincludeAware(true); - assertTrue(options.isXincludeAware()); - options.setXincludeAware(false); - assertFalse(options.isXincludeAware()); - } - - @Test - public void testEqualsHashcode() throws Exception { - List> properties = listOf(XmlParserOptions.COALESCING_DESCRIPTOR, - XmlParserOptions.EXPAND_ENTITY_REFERENCES_DESCRIPTOR, - XmlParserOptions.IGNORING_COMMENTS_DESCRIPTOR, - XmlParserOptions.IGNORING_ELEMENT_CONTENT_WHITESPACE_DESCRIPTOR, - XmlParserOptions.NAMESPACE_AWARE_DESCRIPTOR, - XmlParserOptions.VALIDATING_DESCRIPTOR, - XmlParserOptions.XINCLUDE_AWARE_DESCRIPTOR); - - for (PropertyDescriptor property : properties) { - MyRule rule = new MyRule(); - rule.setProperty(property, true); - ParserOptions options1 = rule.getParserOptions(); - rule.setProperty(property, false); - ParserOptions options2 = rule.getParserOptions(); - rule.setProperty(property, true); - ParserOptions options3 = rule.getParserOptions(); - rule.setProperty(property, false); - ParserOptions options4 = rule.getParserOptions(); - verifyOptionsEqualsHashcode(options1, options2, options3, options4); - } - - XmlParserOptions options1 = new XmlParserOptions(); - options1.setSuppressMarker("foo"); - XmlParserOptions options2 = new XmlParserOptions(); - options2.setSuppressMarker("bar"); - XmlParserOptions options3 = new XmlParserOptions(); - options3.setSuppressMarker("foo"); - XmlParserOptions options4 = new XmlParserOptions(); - options4.setSuppressMarker("bar"); - verifyOptionsEqualsHashcode(options1, options2, options3, options4); - } - - private static final class MyRule extends AbstractXmlRule { - } - - public static junit.framework.Test suite() { - return new junit.framework.JUnit4TestAdapter(XmlParserOptionsTest.class); - } -} diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserTest.java deleted file mode 100644 index 8d1195fc9c..0000000000 --- a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/XmlParserTest.java +++ /dev/null @@ -1,412 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.xml; - -import static net.sourceforge.pmd.lang.ast.test.TestUtilsKt.assertPosition; -import static net.sourceforge.pmd.lang.xml.XmlParsingHelper.XML; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; -import java.util.Iterator; -import java.util.Locale; - -import org.junit.Assert; -import org.junit.Test; - -import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.rule.xpath.Attribute; -import net.sourceforge.pmd.lang.xml.ast.XmlNode; -import net.sourceforge.pmd.lang.xml.ast.internal.XmlParserImpl; -import net.sourceforge.pmd.util.StringUtil; - -/** - * Unit test for the {@link XmlParserImpl}. - */ -public class XmlParserTest { - - private static final String XML_TEST = "\n" + "\n" + "\n" - + "\n" + "\n" + "\n" - + "\n" + "]\n" + ">\n" + "\n" - + " \n" + " entity: &pmd;\n" + " \n" - + " \n" + " \n" + " \n" + ""; - - private static final String XML_NAMESPACE_TEST = "\n" - + "\n" + " \n" - + " entity: &\n" + " \n" + " \n" - + " \n" + " \n" + ""; - - private static final String XML_INVALID_WITH_DTD = "\n" + "\n" + "\n" + "]\n" + ">\n" + "\n" - + " \n" + ""; - - /** - * See bug #1054: XML Rules ever report a line -1 and not the line/column - * where the error occurs - * - */ - @Test - public void testLineNumbers() { - Node document = XML.parse(XML_TEST); - - assertNode(document, "document", 2); - assertPosition(document, 1, 1, 19, 14); - Node dtdElement = document.getChild(0); - assertNode(dtdElement, "rootElement", 0); - assertPosition(dtdElement, 2, 1, 11, 1); - Node rootElement = document.getChild(1); - assertNode(rootElement, "rootElement", 7); - assertPosition(rootElement, 12, 1, 19, 14); - assertTextNode(rootElement.getChild(0), "\\n "); - assertPosition(rootElement.getChild(0), 12, 14, 13, 4); - assertNode(rootElement.getChild(1), "comment", 0); - assertPosition(rootElement.getChild(1), 13, 5, 13, 29); - assertTextNode(rootElement.getChild(2), "\\n "); - assertPosition(rootElement.getChild(2), 13, 30, 14, 4); - Node child1 = rootElement.getChild(3); - assertNode(child1, "child1", 1, "test", "1"); - assertPosition(child1, 14, 5, 15, 13); - assertTextNode(child1.getChild(0), "entity: Copyright: PMD\\n "); - assertPosition(child1.getChild(0), 14, 22, 15, 4); - assertTextNode(rootElement.getChild(4), "\\n "); - assertPosition(rootElement.getChild(4), 15, 14, 16, 4); - Node child2 = rootElement.getChild(5); - assertNode(child2, "child2", 3); - assertPosition(child2, 16, 5, 18, 13); - assertTextNode(child2.getChild(0), "\\n "); - assertPosition(child2.getChild(0), 16, 13, 17, 6); - assertTextNode(child2.getChild(1), " cdata section ", "cdata-section"); - assertPosition(child2.getChild(1), 17, 7, 17, 33); - assertTextNode(child2.getChild(2), "\\n "); - assertPosition(child2.getChild(2), 17, 34, 18, 4); - assertTextNode(rootElement.getChild(6), "\\n"); - assertPosition(rootElement.getChild(6), 18, 14, 18, 14); - } - - /** - * Verifies the default parsing behavior of the XML parser. - */ - @Test - public void testDefaultParsing() { - Node document = XML.parse(XML_TEST); - - assertNode(document, "document", 2); - Node dtdElement = document.getChild(0); - assertNode(dtdElement, "rootElement", 0); - Node rootElement = document.getChild(1); - assertNode(rootElement, "rootElement", 7); - assertTextNode(rootElement.getChild(0), "\\n "); - assertNode(rootElement.getChild(1), "comment", 0); - assertTextNode(rootElement.getChild(2), "\\n "); - Node child1 = rootElement.getChild(3); - assertNode(child1, "child1", 1, "test", "1"); - assertTextNode(child1.getChild(0), "entity: Copyright: PMD\\n "); - assertTextNode(rootElement.getChild(4), "\\n "); - Node child2 = rootElement.getChild(5); - assertNode(child2, "child2", 3); - assertTextNode(child2.getChild(0), "\\n "); - assertTextNode(child2.getChild(1), " cdata section ", "cdata-section"); - assertTextNode(child2.getChild(2), "\\n "); - assertTextNode(rootElement.getChild(6), "\\n"); - } - - /** - * Verifies the parsing behavior of the XML parser with coalescing enabled. - */ - @Test - public void testParsingCoalescingEnabled() { - XmlParserOptions parserOptions = new XmlParserOptions(); - parserOptions.setCoalescing(true); - Node document = XML.withParserOptions(parserOptions).parse(XML_TEST); - - assertNode(document, "document", 2); - Node dtdElement = document.getChild(0); - assertNode(dtdElement, "rootElement", 0); - Node rootElement = document.getChild(1); - assertNode(rootElement, "rootElement", 7); - assertTextNode(rootElement.getChild(0), "\\n "); - assertNode(rootElement.getChild(1), "comment", 0); - assertTextNode(rootElement.getChild(2), "\\n "); - Node child1 = rootElement.getChild(3); - assertNode(child1, "child1", 1, "test", "1"); - assertTextNode(child1.getChild(0), "entity: Copyright: PMD\\n "); - assertTextNode(rootElement.getChild(4), "\\n "); - Node child2 = rootElement.getChild(5); - assertNode(child2, "child2", 1); - assertTextNode(child2.getChild(0), "\\n cdata section \\n "); - assertTextNode(rootElement.getChild(6), "\\n"); - } - - /** - * Verifies the parsing behavior of the XML parser if entities are not - * expanded. - */ - @Test - public void testParsingDoNotExpandEntities() { - XmlParserOptions parserOptions = new XmlParserOptions(); - parserOptions.setExpandEntityReferences(false); - Node document = XML.withParserOptions(parserOptions).parse(XML_TEST); - - assertNode(document, "document", 2); - Node dtdElement = document.getChild(0); - assertNode(dtdElement, "rootElement", 0); - Node rootElement = document.getChild(1); - assertNode(rootElement, "rootElement", 7); - assertTextNode(rootElement.getChild(0), "\\n "); - assertNode(rootElement.getChild(1), "comment", 0); - assertTextNode(rootElement.getChild(2), "\\n "); - Node child1 = rootElement.getChild(3); - assertNode(child1, "child1", 3, "test", "1"); - assertTextNode(child1.getChild(0), "entity: "); - assertNode(child1.getChild(1), "pmd", 0); - // with java13, expandEntityReferences=false works correctly, and the - // entity &pmd; is not expanded - String text = child1.getChild(2).getImage(); - if ("\n ".equals(text)) { - // java13 and later - assertTextNode(child1.getChild(2), "\\n "); - } else { - assertTextNode(child1.getChild(2), "Copyright: PMD\\n "); - } - assertTextNode(rootElement.getChild(4), "\\n "); - Node child2 = rootElement.getChild(5); - assertNode(child2, "child2", 3); - assertTextNode(child2.getChild(0), "\\n "); - assertTextNode(child2.getChild(1), " cdata section ", "cdata-section"); - assertTextNode(child2.getChild(2), "\\n "); - assertTextNode(rootElement.getChild(6), "\\n"); - } - - /** - * Verifies the parsing behavior of the XML parser if ignoring comments. - */ - @Test - public void testParsingIgnoreComments() { - XmlParserOptions parserOptions = new XmlParserOptions(); - parserOptions.setIgnoringComments(true); - Node document = XML.withParserOptions(parserOptions).parse(XML_TEST); - - assertNode(document, "document", 2); - Node dtdElement = document.getChild(0); - assertNode(dtdElement, "rootElement", 0); - Node rootElement = document.getChild(1); - assertNode(rootElement, "rootElement", 5); - assertTextNode(rootElement.getChild(0), "\\n \\n "); - Node child1 = rootElement.getChild(1); - assertNode(child1, "child1", 1, "test", "1"); - assertTextNode(child1.getChild(0), "entity: Copyright: PMD\\n "); - assertTextNode(rootElement.getChild(2), "\\n "); - Node child2 = rootElement.getChild(3); - assertNode(child2, "child2", 3); - assertTextNode(child2.getChild(0), "\\n "); - assertTextNode(child2.getChild(1), " cdata section ", "cdata-section"); - assertTextNode(child2.getChild(2), "\\n "); - assertTextNode(rootElement.getChild(4), "\\n"); - } - - /** - * Verifies the parsing behavior of the XML parser if ignoring whitespaces - * in elements. - */ - @Test - public void testParsingIgnoreElementContentWhitespace() { - XmlParserOptions parserOptions = new XmlParserOptions(); - parserOptions.setIgnoringElementContentWhitespace(true); - Node document = XML.withParserOptions(parserOptions).parse(XML_TEST); - - assertNode(document, "document", 2); - Node dtdElement = document.getChild(0); - assertNode(dtdElement, "rootElement", 0); - Node rootElement = document.getChild(1); - assertNode(rootElement, "rootElement", 3); - assertNode(rootElement.getChild(0), "comment", 0); - Node child1 = rootElement.getChild(1); - assertNode(child1, "child1", 1, "test", "1"); - assertTextNode(child1.getChild(0), "entity: Copyright: PMD\\n "); - Node child2 = rootElement.getChild(2); - assertNode(child2, "child2", 3); - assertTextNode(child2.getChild(0), "\\n "); - assertTextNode(child2.getChild(1), " cdata section ", "cdata-section"); - assertTextNode(child2.getChild(2), "\\n "); - } - - /** - * Verifies the default parsing behavior of the XML parser with namespaces. - */ - @Test - public void testDefaultParsingNamespaces() { - Node document = XML.parse(XML_NAMESPACE_TEST); - - assertNode(document, "document", 1); - Node rootElement = document.getChild(0); - assertNode(rootElement, "pmd:rootElement", 7, "xmlns:pmd", "http://pmd.sf.net"); - Assert.assertEquals("http://pmd.sf.net", ((XmlNode) rootElement).getNode().getNamespaceURI()); - Assert.assertEquals("pmd", ((XmlNode) rootElement).getNode().getPrefix()); - Assert.assertEquals("rootElement", ((XmlNode) rootElement).getNode().getLocalName()); - Assert.assertEquals("pmd:rootElement", ((XmlNode) rootElement).getNode().getNodeName()); - assertTextNode(rootElement.getChild(0), "\\n "); - assertNode(rootElement.getChild(1), "comment", 0); - assertTextNode(rootElement.getChild(2), "\\n "); - Node child1 = rootElement.getChild(3); - assertNode(child1, "pmd:child1", 1, "test", "1"); - assertTextNode(child1.getChild(0), "entity: &\\n "); - assertTextNode(rootElement.getChild(4), "\\n "); - Node child2 = rootElement.getChild(5); - assertNode(child2, "pmd:child2", 3); - assertTextNode(child2.getChild(0), "\\n "); - assertTextNode(child2.getChild(1), " cdata section ", "cdata-section"); - assertTextNode(child2.getChild(2), "\\n "); - assertTextNode(rootElement.getChild(6), "\\n"); - } - - /** - * Verifies the default parsing behavior of the XML parser with namespaces - * but not namespace aware. - */ - @Test - public void testParsingNotNamespaceAware() { - XmlParserOptions parserOptions = new XmlParserOptions(); - parserOptions.setNamespaceAware(false); - Node document = XML.withParserOptions(parserOptions).parse(XML_NAMESPACE_TEST); - - assertNode(document, "document", 1); - Node rootElement = document.getChild(0); - assertNode(rootElement, "pmd:rootElement", 7, "xmlns:pmd", "http://pmd.sf.net"); - Assert.assertNull(((XmlNode) rootElement).getNode().getNamespaceURI()); - Assert.assertNull(((XmlNode) rootElement).getNode().getPrefix()); - Assert.assertNull(((XmlNode) rootElement).getNode().getLocalName()); - Assert.assertEquals("pmd:rootElement", ((XmlNode) rootElement).getNode().getNodeName()); - assertTextNode(rootElement.getChild(0), "\\n "); - assertNode(rootElement.getChild(1), "comment", 0); - assertTextNode(rootElement.getChild(2), "\\n "); - Node child1 = rootElement.getChild(3); - assertNode(child1, "pmd:child1", 1, "test", "1"); - assertTextNode(child1.getChild(0), "entity: &\\n "); - assertTextNode(rootElement.getChild(4), "\\n "); - Node child2 = rootElement.getChild(5); - assertNode(child2, "pmd:child2", 3); - assertTextNode(child2.getChild(0), "\\n "); - assertTextNode(child2.getChild(1), " cdata section ", "cdata-section"); - assertTextNode(child2.getChild(2), "\\n "); - assertTextNode(rootElement.getChild(6), "\\n"); - } - - /** - * Verifies the parsing behavior of the XML parser with validation on. - * - * @throws UnsupportedEncodingException - * error - */ - @Test - public void testParsingWithValidation() throws UnsupportedEncodingException { - XmlParserOptions parserOptions = new XmlParserOptions(); - parserOptions.setValidating(true); - PrintStream oldErr = System.err; - Locale oldLocale = Locale.getDefault(); - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - System.setErr(new PrintStream(bos)); - Locale.setDefault(Locale.ENGLISH); - Node document = XML.withParserOptions(parserOptions).parse(XML_INVALID_WITH_DTD); - Assert.assertNotNull(document); - String output = bos.toString("UTF-8"); - Assert.assertTrue(output.contains("Element type \"invalidChild\" must be declared.")); - Assert.assertTrue(output.contains("The content of element type \"rootElement\" must match \"(child)\".")); - Assert.assertEquals(2, document.getNumChildren()); - Assert.assertEquals("invalidChild", String.valueOf(document.getChild(1).getChild(1))); - } finally { - System.setErr(oldErr); - Locale.setDefault(oldLocale); - } - } - - @Test - public void testWithProcessingInstructions() { - String xml = "]>TEXT>&myentity;<"; - XmlParserOptions options = new XmlParserOptions(); - options.setExpandEntityReferences(false); - Node document = XmlParsingHelper.XML.withParserOptions(options).parse(xml); - Assert.assertNotNull(document); - assertNode(document.getChild(0), "mypi", 0); - assertPosition(document.getChild(0), 1, 22, 1, 29); - } - - @Test - public void testBug1518() throws Exception { - XML.parseResource("parsertests/bug1518.xml"); - } - - @Test - public void testAutoclosingElementLength() { - final String xml = ""; - assertPosition(XML.parse(xml), 1, 1, 1, xml.length()); - } - - /** - * Asserts a single node inclusive attributes. - * - * @param node - * the node - * @param toString - * the to String representation to expect - * @param childs - * number of childs - * @param atts - * attributes - each object pair forms one attribute: first name, - * then value. - */ - private void assertNode(Node node, String toString, int childs, Object... atts) { - Assert.assertEquals(toString, String.valueOf(node)); - Assert.assertEquals(childs, node.getNumChildren()); - Iterator attributeIterator = node.getXPathAttributesIterator(); - if (atts != null) { - for (int i = 0; i < atts.length; i += 2) { - Assert.assertTrue(attributeIterator.hasNext()); - String name = String.valueOf(atts[i]); - Object value = atts[i + 1]; - Attribute attribute = attributeIterator.next(); - Assert.assertEquals(name, attribute.getName()); - Assert.assertEquals(value, attribute.getValue()); - } - } - Assert.assertFalse(attributeIterator.hasNext()); - } - - /** - * Assert a single text node. - * - * @param node - * the node to check - * @param text - * the text to expect - */ - private void assertTextNode(Node node, String text) { - assertTextNode(node, text, "text"); - } - - /** - * Assert a single text node. - * - * @param node - * the node to check - * @param text - * the text to expect - * @param toString - * the to string representation - */ - private void assertTextNode(Node node, String text, String toString) { - Assert.assertEquals(toString, String.valueOf(node)); - Assert.assertEquals(0, node.getNumChildren()); - Assert.assertEquals(text, StringUtil.escapeWhitespace(node.getImage())); - Iterator attributeIterator = node.getXPathAttributesIterator(); - Assert.assertTrue(attributeIterator.hasNext()); - Attribute attribute = attributeIterator.next(); - Assert.assertEquals("Image", attribute.getName()); - Assert.assertEquals(text, StringUtil.escapeWhitespace(attribute.getValue())); - Assert.assertFalse(attributeIterator.hasNext()); - } - -} diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlCoordinatesTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlCoordinatesTest.java new file mode 100644 index 0000000000..777dc49bd1 --- /dev/null +++ b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlCoordinatesTest.java @@ -0,0 +1,42 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.xml.ast; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.junit.Test; + +import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper; +import net.sourceforge.pmd.lang.ast.test.BaseTreeDumpTest; +import net.sourceforge.pmd.lang.ast.test.CoordinatesPrinter; +import net.sourceforge.pmd.lang.ast.test.TestUtilsKt; +import net.sourceforge.pmd.lang.xml.XmlParsingHelper; + +public class XmlCoordinatesTest extends BaseTreeDumpTest { + + public XmlCoordinatesTest() { + super(CoordinatesPrinter.INSTANCE, ".xml"); + } + + @Override + public @NonNull BaseParsingHelper getParser() { + return XmlParsingHelper.XML.withResourceContext(getClass(), "testdata"); + } + + /** + * See bug #1054: XML Rules ever report a line -1 and not the line/column + * where the error occurs + */ + @Test + public void testLineNumbers() { + doTest("xmlCoords"); + } + + @Test + public void testAutoclosingElementLength() { + final String xml = ""; + TestUtilsKt.assertPosition(XmlParsingHelper.XML.parse(xml), 1, 1, 1, xml.length()); + } + +} diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlParserTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlParserTest.java new file mode 100644 index 0000000000..c2dc80c646 --- /dev/null +++ b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlParserTest.java @@ -0,0 +1,43 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.xml.ast; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.junit.Test; + +import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper; +import net.sourceforge.pmd.lang.ast.test.BaseTreeDumpTest; +import net.sourceforge.pmd.lang.ast.test.RelevantAttributePrinter; +import net.sourceforge.pmd.lang.xml.XmlParsingHelper; + +public class XmlParserTest extends BaseTreeDumpTest { + + public XmlParserTest() { + super(new RelevantAttributePrinter(), ".xml"); + } + + @Override + public @NonNull BaseParsingHelper getParser() { + return XmlParsingHelper.XML.withResourceContext(getClass(), "testdata"); + } + + /** + * Verifies the default parsing behavior of the XML parser. + */ + @Test + public void testDefaultParsing() { + doTest("sampleXml"); + } + + @Test + public void testNamespaces() { + doTest("sampleNs"); + } + + @Test + public void testBug1518() { + doTest("bug1518"); + } +} diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/rule/AbstractXmlRuleTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/rule/AbstractXmlRuleTest.java deleted file mode 100644 index f8d7d63016..0000000000 --- a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/rule/AbstractXmlRuleTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.xml.rule; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.xml.XmlParsingHelper; -import net.sourceforge.pmd.lang.xml.ast.XmlNode; - -public class AbstractXmlRuleTest { - - @Test - public void testVisit() throws Exception { - String source = ""; - XmlNode xmlNode = XmlParsingHelper.XML.parse(source); - MyRule rule = new MyRule(); - rule.apply(xmlNode, null); - - assertEquals(3, rule.visitedNodes.size()); - assertEquals("document", rule.visitedNodes.get(0).toString()); - assertEquals("foo", rule.visitedNodes.get(1).toString()); - assertEquals("bar", rule.visitedNodes.get(2).toString()); - } - - private static class MyRule extends AbstractXmlRule { - final List visitedNodes = new ArrayList<>(); - - MyRule() { - } - - @Override - public void start(RuleContext ctx) { - visitedNodes.clear(); - } - - @Override - protected void visit(XmlNode node, RuleContext ctx) { - visitedNodes.add(node); - super.visit(node, ctx); - } - } -} diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.txt b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.txt new file mode 100644 index 0000000000..238556b80b --- /dev/null +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.txt @@ -0,0 +1,69 @@ ++- document[] + +- deployment-plan[@global-variables = "false", @xmlns = "http://xmlns.oracle.com/weblogic/deployment-plan", @xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance", @xsi:schemaLocation = "http://xmlns.oracle.com/weblogic/deployment-plan http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd"] + +- text[@Image = " + "] + +- application-name[] + | +- text[@Image = "app"] + +- text[@Image = " + "] + +- variable-definition[] + | +- text[@Image = " + "] + | +- variable[] + | | +- text[@Image = " + "] + | | +- name[] + | | | +- text[@Image = "Application_Module_Web_ContextRoot"] + | | +- text[@Image = " + "] + | | +- value[@xsi:nil = "false"] + | | | +- text[@Image = "ikb.adf.kreda.abw.webapp-Abnahmetest-ohne-SSO"] + | | +- text[@Image = " + "] + | +- text[@Image = " + "] + +- text[@Image = " + "] + +- module-override[] + | +- text[@Image = " + "] + | +- module-name[] + | | +- text[@Image = "ikb.adf.kreda.abw.ear"] + | +- text[@Image = " + "] + | +- module-type[] + | | +- text[@Image = "ear"] + | +- text[@Image = " + "] + | +- module-descriptor[@external = "false"] + | | +- text[@Image = " + "] + | | +- root-element[] + | | | +- text[@Image = "application"] + | | +- text[@Image = " + "] + | | +- uri[] + | | | +- text[@Image = "META-INF/application.xml"] + | | +- text[@Image = " + "] + | | +- variable-assignment[] + | | | +- text[@Image = " + "] + | | | +- name[] + | | | | +- text[@Image = "Application_Module_Web_ContextRoot"] + | | | +- text[@Image = " + "] + | | | +- xpath[] + | | | | +- text[@Image = "/application/module/web/[context-root="ikb.adf.kreda.abw.webapp-Local-ohne-SSO"]"] + | | | +- text[@Image = " + "] + | | | +- operation[] + | | | | +- text[@Image = "replace"] + | | | +- text[@Image = " + "] + | | +- text[@Image = " + "] + | +- text[@Image = " + "] + +- text[@Image = " +"] diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/parsertests/bug1518.xml b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.xml similarity index 100% rename from pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/parsertests/bug1518.xml rename to pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.xml diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.txt b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.txt new file mode 100644 index 0000000000..14d8a5cf04 --- /dev/null +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.txt @@ -0,0 +1,22 @@ ++- document[] + +- comment[] + +- rootElement[] + +- rootElement[] + +- text[@Image = " + "] + +- comment[] + +- text[@Image = " + "] + +- child1[@test = "1"] + | +- text[@Image = "entity: Copyright: PMD + "] + +- text[@Image = " + "] + +- child2[] + | +- text[@Image = " + "] + | +- cdata-section[@Image = " cdata section "] + | +- text[@Image = " + "] + +- text[@Image = " +"] diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.xml b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.xml new file mode 100644 index 0000000000..3d242f0de8 --- /dev/null +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.xml @@ -0,0 +1,21 @@ + + + + + + + + + + ] + > + + + entity: &pmd; + + + + + diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.txt b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.txt new file mode 100644 index 0000000000..967dc4b8a5 --- /dev/null +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.txt @@ -0,0 +1,20 @@ ++- document[] + +- pmd:rootElement[@xmlns:pmd = "http://pmd.sf.net"] + +- text[@Image = " + "] + +- comment[] + +- text[@Image = " + "] + +- pmd:child1[@test = "1"] + | +- text[@Image = "entity: & + "] + +- text[@Image = " + "] + +- pmd:child2[] + | +- text[@Image = " + "] + | +- cdata-section[@Image = " cdata section "] + | +- text[@Image = " + "] + +- text[@Image = " +"] diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.xml b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.xml new file mode 100644 index 0000000000..6e0e76f927 --- /dev/null +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.xml @@ -0,0 +1,9 @@ + + + + entity: & + + + + + diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/xmlCoords.txt b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/xmlCoords.txt new file mode 100644 index 0000000000..c946430434 --- /dev/null +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/xmlCoords.txt @@ -0,0 +1,17 @@ ++- document[@BeginColumn = 1, @BeginLine = 1, @EndColumn = 14, @EndLine = 22] + +- comment[@BeginColumn = 1, @BeginLine = 2, @EndColumn = 12, @EndLine = 2] + +- rootElement[@BeginColumn = 1, @BeginLine = 4, @EndColumn = 9, @EndLine = 13] + +- rootElement[@BeginColumn = 1, @BeginLine = 14, @EndColumn = 14, @EndLine = 22] + +- text[@BeginColumn = 14, @BeginLine = 14, @EndColumn = 4, @EndLine = 15] + +- comment[@BeginColumn = 5, @BeginLine = 15, @EndColumn = 29, @EndLine = 15] + +- text[@BeginColumn = 30, @BeginLine = 15, @EndColumn = 4, @EndLine = 16] + +- child1[@BeginColumn = 5, @BeginLine = 16, @EndColumn = 13, @EndLine = 17] + | +- text[@BeginColumn = 22, @BeginLine = 16, @EndColumn = 4, @EndLine = 17] + +- text[@BeginColumn = 14, @BeginLine = 17, @EndColumn = 4, @EndLine = 18] + +- child2[@BeginColumn = 5, @BeginLine = 18, @EndColumn = 13, @EndLine = 20] + | +- text[@BeginColumn = 13, @BeginLine = 18, @EndColumn = 8, @EndLine = 19] + | +- cdata-section[@BeginColumn = 9, @BeginLine = 19, @EndColumn = 35, @EndLine = 19] + | +- text[@BeginColumn = 36, @BeginLine = 19, @EndColumn = 4, @EndLine = 20] + +- text[@BeginColumn = 14, @BeginLine = 20, @EndColumn = 4, @EndLine = 21] + +- child3[@BeginColumn = 5, @BeginLine = 21, @EndColumn = 20, @EndLine = 21] + +- text[@BeginColumn = 21, @BeginLine = 21, @EndColumn = 21, @EndLine = 21] diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/xmlCoords.xml b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/xmlCoords.xml new file mode 100644 index 0000000000..a3ed9805ee --- /dev/null +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/xmlCoords.xml @@ -0,0 +1,22 @@ + + + + + + + + + + ] + > + + + entity: &pmd; + + + + + + From ca4b96ef13b8f277fa88577bdfceac2d4208f055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 14 Dec 2020 13:11:44 +0100 Subject: [PATCH 5/6] Fix reference files --- .../pmd/lang/xml/ast/testdata/bug1518.txt | 65 +++++++------------ .../pmd/lang/xml/ast/testdata/sampleNs.txt | 21 ++---- .../pmd/lang/xml/ast/testdata/sampleXml.txt | 21 ++---- 3 files changed, 36 insertions(+), 71 deletions(-) diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.txt b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.txt index 238556b80b..cbb8c4a578 100644 --- a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.txt +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/bug1518.txt @@ -1,69 +1,48 @@ +- document[] +- deployment-plan[@global-variables = "false", @xmlns = "http://xmlns.oracle.com/weblogic/deployment-plan", @xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance", @xsi:schemaLocation = "http://xmlns.oracle.com/weblogic/deployment-plan http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd"] - +- text[@Image = " - "] + +- text[@Image = "\n "] +- application-name[] | +- text[@Image = "app"] - +- text[@Image = " - "] + +- text[@Image = "\n "] +- variable-definition[] - | +- text[@Image = " - "] + | +- text[@Image = "\n "] | +- variable[] - | | +- text[@Image = " - "] + | | +- text[@Image = "\n "] | | +- name[] | | | +- text[@Image = "Application_Module_Web_ContextRoot"] - | | +- text[@Image = " - "] + | | +- text[@Image = "\n "] | | +- value[@xsi:nil = "false"] | | | +- text[@Image = "ikb.adf.kreda.abw.webapp-Abnahmetest-ohne-SSO"] - | | +- text[@Image = " - "] - | +- text[@Image = " - "] - +- text[@Image = " - "] + | | +- text[@Image = "\n "] + | +- text[@Image = "\n "] + +- text[@Image = "\n "] +- module-override[] - | +- text[@Image = " - "] + | +- text[@Image = "\n "] | +- module-name[] | | +- text[@Image = "ikb.adf.kreda.abw.ear"] - | +- text[@Image = " - "] + | +- text[@Image = "\n "] | +- module-type[] | | +- text[@Image = "ear"] - | +- text[@Image = " - "] + | +- text[@Image = "\n "] | +- module-descriptor[@external = "false"] - | | +- text[@Image = " - "] + | | +- text[@Image = "\n "] | | +- root-element[] | | | +- text[@Image = "application"] - | | +- text[@Image = " - "] + | | +- text[@Image = "\n "] | | +- uri[] | | | +- text[@Image = "META-INF/application.xml"] - | | +- text[@Image = " - "] + | | +- text[@Image = "\n "] | | +- variable-assignment[] - | | | +- text[@Image = " - "] + | | | +- text[@Image = "\n "] | | | +- name[] | | | | +- text[@Image = "Application_Module_Web_ContextRoot"] - | | | +- text[@Image = " - "] + | | | +- text[@Image = "\n "] | | | +- xpath[] - | | | | +- text[@Image = "/application/module/web/[context-root="ikb.adf.kreda.abw.webapp-Local-ohne-SSO"]"] - | | | +- text[@Image = " - "] + | | | | +- text[@Image = "/application/module/web/[context-root=\"ikb.adf.kreda.abw.webapp-Local-ohne-SSO\"]"] + | | | +- text[@Image = "\n "] | | | +- operation[] | | | | +- text[@Image = "replace"] - | | | +- text[@Image = " - "] - | | +- text[@Image = " - "] - | +- text[@Image = " - "] - +- text[@Image = " -"] + | | | +- text[@Image = "\n "] + | | +- text[@Image = "\n "] + | +- text[@Image = "\n "] + +- text[@Image = "\n"] diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.txt b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.txt index 14d8a5cf04..79fe784f37 100644 --- a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.txt +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleNs.txt @@ -2,21 +2,14 @@ +- comment[] +- rootElement[] +- rootElement[] - +- text[@Image = " - "] + +- text[@Image = "\n "] +- comment[] - +- text[@Image = " - "] + +- text[@Image = "\n "] +- child1[@test = "1"] - | +- text[@Image = "entity: Copyright: PMD - "] - +- text[@Image = " - "] + | +- text[@Image = "entity: Copyright: PMD\n "] + +- text[@Image = "\n "] +- child2[] - | +- text[@Image = " - "] + | +- text[@Image = "\n "] | +- cdata-section[@Image = " cdata section "] - | +- text[@Image = " - "] - +- text[@Image = " -"] + | +- text[@Image = "\n "] + +- text[@Image = "\n"] diff --git a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.txt b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.txt index 967dc4b8a5..40035dc0ef 100644 --- a/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.txt +++ b/pmd-xml/src/test/resources/net/sourceforge/pmd/lang/xml/ast/testdata/sampleXml.txt @@ -1,20 +1,13 @@ +- document[] +- pmd:rootElement[@xmlns:pmd = "http://pmd.sf.net"] - +- text[@Image = " - "] + +- text[@Image = "\n "] +- comment[] - +- text[@Image = " - "] + +- text[@Image = "\n "] +- pmd:child1[@test = "1"] - | +- text[@Image = "entity: & - "] - +- text[@Image = " - "] + | +- text[@Image = "entity: &\n "] + +- text[@Image = "\n "] +- pmd:child2[] - | +- text[@Image = " - "] + | +- text[@Image = "\n "] | +- cdata-section[@Image = " cdata section "] - | +- text[@Image = " - "] - +- text[@Image = " -"] + | +- text[@Image = "\n "] + +- text[@Image = "\n"] From d877bdb7795113623930736a3a12304b30a68f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 14 Dec 2020 13:35:18 +0100 Subject: [PATCH 6/6] Readd some deleted tests --- .../lang/xml/ast/internal/XmlParserImpl.java | 5 ++++ .../pmd/lang/xml/ast/XmlParserTest.java | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java index dd94aaa7ba..fce625bb8d 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/internal/XmlParserImpl.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd.lang.xml.ast.internal; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.Reader; import java.io.StringReader; @@ -16,6 +17,7 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.io.IOUtils; import org.w3c.dom.Document; import org.w3c.dom.Node; +import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -25,6 +27,8 @@ import net.sourceforge.pmd.lang.xml.ast.XmlNode; public final class XmlParserImpl { + // never throws on unresolved resource + private static final EntityResolver SILENT_ENTITY_RESOLVER = (publicId, systemId) -> new InputSource(new ByteArrayInputStream("".getBytes())); private final Map nodeCache = new HashMap<>(); @@ -44,6 +48,7 @@ public final class XmlParserImpl { dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); DocumentBuilder documentBuilder = dbf.newDocumentBuilder(); + documentBuilder.setEntityResolver(SILENT_ENTITY_RESOLVER); return documentBuilder.parse(new InputSource(new StringReader(xmlData))); } catch (ParserConfigurationException | SAXException | IOException e) { throw new ParseException(e); diff --git a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlParserTest.java b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlParserTest.java index c2dc80c646..a44de6da72 100644 --- a/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlParserTest.java +++ b/pmd-xml/src/test/java/net/sourceforge/pmd/lang/xml/ast/XmlParserTest.java @@ -40,4 +40,29 @@ public class XmlParserTest extends BaseTreeDumpTest { public void testBug1518() { doTest("bug1518"); } + + + @Test + public void dtdIsNotLookedUp() { + // no exception should be thrown + XmlParsingHelper.XML.parse( + "" + + ""); + } + + @Test + public void xsdIsNotLookedUp() { + // no exception should be thrown + XmlParsingHelper.XML.parse( + " " + + "" + + ""); + } + + }