Merge branch 'java-grammar' into grammar-switches
This commit is contained in:
@ -71,11 +71,21 @@
|
||||
<artifactId>system-rules</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-lang-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
|
@ -8,6 +8,7 @@ import java.util.Stack;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClassOrInterface;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserTrigger;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorReducedAdapter;
|
||||
|
||||
/**
|
||||
@ -34,6 +35,11 @@ public class ApexMultifileVisitor extends ApexParserVisitorReducedAdapter {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTUserTrigger node, Object data) {
|
||||
return data; // ignore
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object visit(ASTMethod node, Object data) {
|
||||
|
@ -4,14 +4,12 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ASTFieldTest {
|
||||
public class ASTFieldTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testGetType() {
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
@ -13,7 +11,7 @@ import org.junit.Test;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ASTMethodTest {
|
||||
public class ASTMethodTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testConstructorName() {
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
@ -13,7 +11,7 @@ import org.junit.Test;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ASTNewKeyValueObjectExpressionTest {
|
||||
public class ASTNewKeyValueObjectExpressionTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testParameterName() {
|
||||
|
@ -4,14 +4,12 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ASTSoqlExpressionTest {
|
||||
public class ASTSoqlExpressionTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testQuery() {
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Assert;
|
||||
@ -13,7 +11,7 @@ import org.junit.Test;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ASTUserClassTest {
|
||||
public class ASTUserClassTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testClassName() {
|
||||
|
@ -4,14 +4,12 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ASTUserEnumTest {
|
||||
public class ASTUserEnumTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testEnumName() {
|
||||
|
@ -4,14 +4,12 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ASTUserInterfaceTest {
|
||||
public class ASTUserInterfaceTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testInterfaceName() {
|
||||
|
@ -4,14 +4,12 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ASTUserTriggerTest {
|
||||
public class ASTUserTriggerTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testTriggerName() {
|
||||
|
@ -4,27 +4,18 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ApexParserOptions;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ApexCompilerSoqlTest {
|
||||
public class ApexCompilerSoqlTest extends ApexParserTestBase {
|
||||
|
||||
private static final String CODE = "public class Foo {\n"
|
||||
+ " public List<SObject> test1() {\n"
|
||||
+ " return Database.query(\'Select Id from Account LIMIT 100\');\n"
|
||||
+ " }\n"
|
||||
+ "}\n";
|
||||
+ " public List<SObject> test1() {\n"
|
||||
+ " return Database.query(\'Select Id from Account LIMIT 100\');\n"
|
||||
+ " }\n"
|
||||
+ "}\n";
|
||||
|
||||
@Test
|
||||
public void testSoqlCompilation() {
|
||||
ApexParser parser = new ApexParser(new ApexParserOptions());
|
||||
ApexNode<Compilation> cu = parser.parse(new StringReader(CODE));
|
||||
Assert.assertNotNull(cu);
|
||||
apex.parse(CODE);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@ -22,14 +21,14 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ApexParserTest {
|
||||
public class ApexParserTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void understandsSimpleFile() {
|
||||
|
||||
// Setup
|
||||
String code = "@isTest\n public class SimpleClass {\n" + " @isTest\n public static void testAnything() {\n"
|
||||
+ " \n" + " }\n" + "}";
|
||||
+ " \n" + " }\n" + "}";
|
||||
|
||||
// Exercise
|
||||
ApexNode<Compilation> rootNode = parse(code);
|
||||
@ -136,7 +135,7 @@ public class ApexParserTest {
|
||||
|
||||
/**
|
||||
* See bug #1485
|
||||
*
|
||||
*
|
||||
* @see <a href="https://sourceforge.net/p/pmd/bugs/1485/">#1485 [apex] Analysis of some apex classes cause a stackoverflow error</a>
|
||||
*/
|
||||
@Test
|
||||
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ApexParserTestBase {
|
||||
|
||||
protected final ApexParsingHelper apex = ApexParsingHelper.DEFAULT.withResourceContext(getClass());
|
||||
|
||||
|
||||
protected ApexNode<Compilation> parse(String code) {
|
||||
return (ApexNode<Compilation>) apex.parse(code);
|
||||
}
|
||||
|
||||
protected ApexNode<Compilation> parseResource(String code) {
|
||||
return (ApexNode<Compilation>) apex.parseResource(code);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ApexParserOptions;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ApexParserTestHelpers {
|
||||
private ApexParserTestHelpers() { }
|
||||
|
||||
public static ApexNode<Compilation> parse(String code) {
|
||||
ApexParser parser = new ApexParser(new ApexParserOptions());
|
||||
Reader reader = new StringReader(code);
|
||||
return parser.parse(reader);
|
||||
}
|
||||
|
||||
}
|
@ -4,8 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import static net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers.parse;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@ -17,7 +15,7 @@ import net.sourceforge.pmd.lang.ast.Node;
|
||||
|
||||
import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
|
||||
public class ApexParserXPathTest {
|
||||
public class ApexParserXPathTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testBooleanExpressions() throws Exception {
|
||||
|
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.apex.ast;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
|
||||
import net.sourceforge.pmd.lang.ast.RootNode;
|
||||
import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper;
|
||||
|
||||
public class ApexParsingHelper extends BaseParsingHelper<ApexParsingHelper, RootNode> {
|
||||
|
||||
public static final ApexParsingHelper DEFAULT = new ApexParsingHelper(Params.getDefaultProcess());
|
||||
|
||||
|
||||
private ApexParsingHelper(Params p) {
|
||||
super(ApexLanguageModule.NAME, RootNode.class, p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ApexParsingHelper clone(Params params) {
|
||||
return new ApexParsingHelper(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcessing(LanguageVersionHandler handler, LanguageVersion lversion, RootNode rootNode) {
|
||||
super.postProcessing(handler, lversion, rootNode);
|
||||
handler.getMultifileFacade().start(rootNode);
|
||||
}
|
||||
}
|
@ -19,11 +19,11 @@ import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class ApexQualifiedNameTest {
|
||||
public class ApexQualifiedNameTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testClass() {
|
||||
ApexNode<Compilation> root = ApexParserTestHelpers.parse("public class Foo {}");
|
||||
ApexNode<Compilation> root = parse("public class Foo {}");
|
||||
|
||||
ApexQualifiedName qname = ASTUserClass.class.cast(root).getQualifiedName();
|
||||
assertEquals("c__Foo", qname.toString());
|
||||
@ -35,7 +35,7 @@ public class ApexQualifiedNameTest {
|
||||
|
||||
@Test
|
||||
public void testNestedClass() {
|
||||
ApexNode<Compilation> root = ApexParserTestHelpers.parse("public class Foo { class Bar {}}");
|
||||
ApexNode<Compilation> root = parse("public class Foo { class Bar {}}");
|
||||
|
||||
ApexQualifiedName qname = root.getFirstDescendantOfType(ASTUserClass.class).getQualifiedName();
|
||||
assertEquals("c__Foo.Bar", qname.toString());
|
||||
@ -47,7 +47,7 @@ public class ApexQualifiedNameTest {
|
||||
|
||||
@Test
|
||||
public void testSimpleMethod() {
|
||||
ApexNode<Compilation> root = ApexParserTestHelpers.parse("public class Foo { String foo() {}}");
|
||||
ApexNode<Compilation> root = parse("public class Foo { String foo() {}}");
|
||||
ApexQualifiedName qname = root.getFirstDescendantOfType(ASTMethod.class).getQualifiedName();
|
||||
assertEquals("c__Foo#foo()", qname.toString());
|
||||
assertEquals(1, qname.getClasses().length);
|
||||
@ -58,7 +58,7 @@ public class ApexQualifiedNameTest {
|
||||
|
||||
@Test
|
||||
public void testMethodWithArguments() {
|
||||
ApexNode<Compilation> root = ApexParserTestHelpers.parse("public class Foo { String foo(String h, Foo g) {}}");
|
||||
ApexNode<Compilation> root = parse("public class Foo { String foo(String h, Foo g) {}}");
|
||||
ApexQualifiedName qname = root.getFirstDescendantOfType(ASTMethod.class).getQualifiedName();
|
||||
assertEquals("c__Foo#foo(String,Foo)", qname.toString());
|
||||
assertEquals(1, qname.getClasses().length);
|
||||
@ -69,7 +69,7 @@ public class ApexQualifiedNameTest {
|
||||
|
||||
@Test
|
||||
public void testOverLoads() {
|
||||
ApexNode<Compilation> root = ApexParserTestHelpers.parse("public class Foo { "
|
||||
ApexNode<Compilation> root = parse("public class Foo { "
|
||||
+ "String foo(String h) {} "
|
||||
+ "String foo(int c) {}"
|
||||
+ "String foo(Foo c) {}}");
|
||||
@ -88,7 +88,7 @@ public class ApexQualifiedNameTest {
|
||||
|
||||
@Test
|
||||
public void testTrigger() {
|
||||
ApexNode<Compilation> root = ApexParserTestHelpers.parse("trigger myAccountTrigger on Account (before insert, before update) {}");
|
||||
ApexNode<Compilation> root = parse("trigger myAccountTrigger on Account (before insert, before update) {}");
|
||||
|
||||
|
||||
List<ASTMethod> methods = root.findDescendantsOfType(ASTMethod.class);
|
||||
|
@ -7,27 +7,21 @@ package net.sourceforge.pmd.lang.apex.metrics;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClassOrInterface;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserTestBase;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorAdapter;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.impl.AbstractApexClassMetric;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.impl.AbstractApexOperationMetric;
|
||||
import net.sourceforge.pmd.lang.apex.multifile.ApexMultifileVisitorTest;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKey;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKeyUtil;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricMemoizer;
|
||||
@ -38,21 +32,15 @@ import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class ApexProjectMirrorTest {
|
||||
public class ApexProjectMirrorTest extends ApexParserTestBase {
|
||||
|
||||
private static ApexNode<Compilation> acu;
|
||||
private MetricKey<ASTUserClassOrInterface<?>> classMetricKey = MetricKeyUtil.of(null, new RandomClassMetric());
|
||||
private MetricKey<ASTMethod> opMetricKey = MetricKeyUtil.of(null, new RandomOperationMetric());
|
||||
|
||||
|
||||
static {
|
||||
try {
|
||||
acu = parseAndVisitForString(
|
||||
IOUtils.toString(ApexMultifileVisitorTest.class.getResourceAsStream("MetadataDeployController.cls"),
|
||||
StandardCharsets.UTF_8));
|
||||
} catch (IOException ioe) {
|
||||
// Should definitely not happen
|
||||
}
|
||||
@Before
|
||||
public void setup() {
|
||||
acu = parseResource("../multifile/MetadataDeployController.cls");
|
||||
}
|
||||
|
||||
|
||||
@ -101,7 +89,7 @@ public class ApexProjectMirrorTest {
|
||||
public Object visit(ASTUserClass node, Object data) {
|
||||
MetricMemoizer<ASTUserClassOrInterface<?>> clazz = toplevel.getClassMemoizer(node.getQualifiedName());
|
||||
result.add((int) ApexMetricsComputer.getInstance().computeForType(classMetricKey, node, force,
|
||||
MetricOptions.emptyOptions(), clazz));
|
||||
MetricOptions.emptyOptions(), clazz));
|
||||
return super.visit(node, data);
|
||||
}
|
||||
}, null);
|
||||
@ -110,15 +98,7 @@ public class ApexProjectMirrorTest {
|
||||
}
|
||||
|
||||
|
||||
static ApexNode<Compilation> parseAndVisitForString(String source) {
|
||||
LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(ApexLanguageModule.NAME)
|
||||
.getDefaultVersion().getLanguageVersionHandler();
|
||||
ApexNode<Compilation> acu = ApexParserTestHelpers.parse(source);
|
||||
languageVersionHandler.getSymbolFacade().start(acu);
|
||||
return acu;
|
||||
}
|
||||
|
||||
private class RandomOperationMetric extends AbstractApexOperationMetric {
|
||||
private static class RandomOperationMetric extends AbstractApexOperationMetric {
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
@ -129,7 +109,7 @@ public class ApexProjectMirrorTest {
|
||||
}
|
||||
}
|
||||
|
||||
private class RandomClassMetric extends AbstractApexClassMetric {
|
||||
private static class RandomClassMetric extends AbstractApexClassMetric {
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
|
@ -8,18 +8,12 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexNode;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserTest;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserTestHelpers;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserTestBase;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorAdapter;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.ApexSignatureMatcher;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.signature.ApexOperationSigMask;
|
||||
@ -29,7 +23,7 @@ import apex.jorje.semantic.ast.compilation.Compilation;
|
||||
/**
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class ApexMultifileVisitorTest extends ApexParserTest {
|
||||
public class ApexMultifileVisitorTest extends ApexParserTestBase {
|
||||
|
||||
@Test
|
||||
public void testProjectMirrorNotNull() {
|
||||
@ -39,9 +33,7 @@ public class ApexMultifileVisitorTest extends ApexParserTest {
|
||||
|
||||
@Test
|
||||
public void testOperationsAreThere() throws IOException {
|
||||
ApexNode<Compilation> acu = parseAndVisitForString(
|
||||
IOUtils.toString(ApexMultifileVisitorTest.class.getResourceAsStream("MetadataDeployController.cls"),
|
||||
StandardCharsets.UTF_8));
|
||||
ApexNode<Compilation> acu = parseResource("MetadataDeployController.cls");
|
||||
|
||||
final ApexSignatureMatcher toplevel = ApexProjectMirror.INSTANCE;
|
||||
|
||||
@ -61,12 +53,4 @@ public class ApexMultifileVisitorTest extends ApexParserTest {
|
||||
}
|
||||
|
||||
|
||||
static ApexNode<Compilation> parseAndVisitForString(String source) {
|
||||
LanguageVersionHandler languageVersionHandler = LanguageRegistry.getLanguage(ApexLanguageModule.NAME)
|
||||
.getDefaultVersion().getLanguageVersionHandler();
|
||||
ApexNode<Compilation> acu = ApexParserTestHelpers.parse(source);
|
||||
languageVersionHandler.getSymbolFacade().start(acu);
|
||||
languageVersionHandler.getMultifileFacade().start(acu);
|
||||
return acu;
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@
|
||||
<property name="base-ast-package" value="net.sourceforge.pmd.lang.ast" />
|
||||
<property name="base-ast-package.dir" value="${target}/net/sourceforge/pmd/lang/ast" />
|
||||
|
||||
<property name="target-package" value="${base-ast-package}.impl.javacc" />
|
||||
<property name="target-package.dir" value="${base-ast-package.dir}/impl/javacc" />
|
||||
<property name="target-package" value="${base-ast-package}" />
|
||||
<property name="target-package.dir" value="${base-ast-package.dir}" />
|
||||
|
||||
|
||||
<target name="alljavacc"
|
||||
@ -114,7 +114,7 @@
|
||||
|
||||
<replace file="${tmp-package.dir}/TokenMgrError.java">
|
||||
<replacetoken><![CDATA["Lexical error at line "]]></replacetoken>
|
||||
<replacevalue>"Lexical error in file " + net.sourceforge.pmd.lang.ast.impl.javacc.AbstractTokenManager.getFileName() + " at line "</replacevalue>
|
||||
<replacevalue>"Lexical error in file " + net.sourceforge.pmd.lang.ast.AbstractTokenManager.getFileName() + " at line "</replacevalue>
|
||||
</replace>
|
||||
|
||||
<move overwrite="true"
|
||||
|
@ -2,7 +2,7 @@
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.ast.impl.javacc;
|
||||
package net.sourceforge.pmd.lang.ast;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
@ -2,7 +2,7 @@
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.ast.impl.javacc;
|
||||
package net.sourceforge.pmd.lang.ast;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
@ -11,6 +11,7 @@ import java.io.StringReader;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.impl.TokenDocument;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
|
||||
|
||||
/**
|
||||
* This stream buffers the whole file in memory before parsing,
|
||||
@ -18,6 +19,8 @@ import net.sourceforge.pmd.lang.ast.impl.TokenDocument;
|
||||
* The buffer is assumed to be composed of only ASCII characters,
|
||||
* and the stream unescapes Unicode escapes. The {@link #getTokenDocument() token document}
|
||||
* stores the original file with escapes and all.
|
||||
*
|
||||
* TODO this is to be moved into the impl.javacc subpackage
|
||||
*/
|
||||
public class JavaCharStream extends JavaCharStreamBase {
|
||||
|
@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.ast;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
@ -689,7 +690,7 @@ public interface NodeStream<T extends Node> extends Iterable<@NonNull T> {
|
||||
* Returns the first element of this stream, or {@code null} if the
|
||||
* stream is empty.
|
||||
*
|
||||
* <p>If you'd rather continue processingthe first element as a node
|
||||
* <p>If you'd rather continue processing the first element as a node
|
||||
* stream, you can use {@link #take(int) take(1)}.
|
||||
*
|
||||
* <p>This is equivalent to {@link #get(int) get(0)}.
|
||||
@ -703,6 +704,26 @@ public interface NodeStream<T extends Node> extends Iterable<@NonNull T> {
|
||||
@Nullable T first();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the first element of this stream, or throws a {@link NoSuchElementException}
|
||||
* if the stream is empty.
|
||||
*
|
||||
* @return the first element of this stream
|
||||
*
|
||||
* @see #first(Predicate)
|
||||
* @see #first(Class)
|
||||
* @see #firstOpt()
|
||||
*/
|
||||
@NonNull
|
||||
default T firstOrThrow() {
|
||||
T first = first();
|
||||
if (first == null) {
|
||||
throw new NoSuchElementException("Empty node stream");
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an optional containing the first element of this stream,
|
||||
* or an empty optional if the stream is empty.
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.ast.impl.javacc;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.CharStream;
|
||||
import net.sourceforge.pmd.lang.ast.JavaCharStream;
|
||||
import net.sourceforge.pmd.lang.ast.SimpleCharStream;
|
||||
import net.sourceforge.pmd.lang.ast.impl.TokenDocument;
|
||||
|
||||
@SuppressWarnings("PMD.UnusedFormalParameter") // for later
|
||||
public final class CharStreamFactory {
|
||||
|
||||
private CharStreamFactory() {
|
||||
// util class
|
||||
}
|
||||
|
||||
/**
|
||||
* A char stream that doesn't perform any escape translation.
|
||||
*/
|
||||
public static CharStream simpleCharStream(Reader input) {
|
||||
return simpleCharStream(input, TokenDocument::new);
|
||||
}
|
||||
|
||||
/**
|
||||
* A char stream that doesn't perform any escape translation.
|
||||
*/
|
||||
public static CharStream simpleCharStream(Reader input, Function<? super String, ? extends TokenDocument> documentMaker) {
|
||||
return new SimpleCharStream(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* A char stream that translates java unicode sequences.
|
||||
*/
|
||||
public static CharStream javaCharStream(Reader input) {
|
||||
return javaCharStream(input, TokenDocument::new);
|
||||
}
|
||||
|
||||
/**
|
||||
* A char stream that translates java unicode sequences.
|
||||
*/
|
||||
public static CharStream javaCharStream(Reader input, Function<? super String, ? extends TokenDocument> documentMaker) {
|
||||
String source = toString(input);
|
||||
return new JavaCharStream(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This shouldn't be used. IOExceptions should be handled properly,
|
||||
* ie it should be expected that creating a parse may throw an IOException,
|
||||
* in both CPD and PMD
|
||||
*/
|
||||
@Deprecated
|
||||
public static String toString(Reader dstream) {
|
||||
try (Reader r = dstream) {
|
||||
return IOUtils.toString(r);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -199,7 +199,7 @@ abstract class AxisStream<T extends Node> extends IteratorBasedNStream<T> {
|
||||
|
||||
@Override
|
||||
protected <S extends Node> NodeStream<S> copyWithFilter(Filtermap<Node, S> filterMap) {
|
||||
return new FilteredDescendantStream<>(node, filterMap);
|
||||
return new FilteredDescendantOrSelfStream<>(node, filterMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,7 +32,7 @@ options {
|
||||
PARSER_BEGIN(CppParser)
|
||||
package net.sourceforge.pmd.lang.cpp.ast;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream;
|
||||
import net.sourceforge.pmd.lang.ast.CharStream;
|
||||
import net.sourceforge.pmd.lang.ast.TokenMgrError;
|
||||
|
||||
public final class CppParser {
|
||||
|
@ -36,7 +36,7 @@
|
||||
javacchome="${javacc-home.path}" />
|
||||
<replace file="${target}/net/sourceforge/pmd/lang/cpp/ast/CppParserTokenManager.java"
|
||||
token="class CppParserTokenManager"
|
||||
value="class CppParserTokenManager extends net.sourceforge.pmd.lang.ast.impl.javacc.AbstractTokenManager" />
|
||||
value="class CppParserTokenManager extends net.sourceforge.pmd.lang.ast.AbstractTokenManager" />
|
||||
<delete file="${target}/net/sourceforge/pmd/lang/cpp/ast/CharStream.java" />
|
||||
<delete file="${target}/net/sourceforge/pmd/lang/cpp/ast/ParseException.java" />
|
||||
<delete file="${target}/net/sourceforge/pmd/lang/cpp/ast/TokenMgrError.java" />
|
||||
|
@ -8,7 +8,7 @@ import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.SimpleCharStream;
|
||||
import net.sourceforge.pmd.lang.ast.SimpleCharStream;
|
||||
|
||||
/**
|
||||
* A SimpleCharStream, that supports the continuation of lines via backslash+newline,
|
||||
|
@ -250,7 +250,7 @@ package net.sourceforge.pmd.lang.java.ast;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream;
|
||||
import net.sourceforge.pmd.lang.ast.CharStream;
|
||||
import net.sourceforge.pmd.lang.ast.GenericToken;
|
||||
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
|
||||
import net.sourceforge.pmd.lang.ast.TokenMgrError;
|
||||
@ -394,7 +394,7 @@ TOKEN_MGR_DECLS :
|
||||
|
||||
SPECIAL_TOKEN :
|
||||
{
|
||||
// those are private, just for code organisation
|
||||
// those are private, just for code organisation
|
||||
< #HORIZONTAL_WHITESPACE: [" ", "\t", "\f"] >
|
||||
| < #LINE_TERMINATOR: "\n" | "\r" | "\r\n" >
|
||||
// this one is pushed, notice the (..)+ construct, to avoid
|
||||
@ -1551,7 +1551,7 @@ ASTCompilationUnit CompilationUnit() :
|
||||
<EOF>
|
||||
{
|
||||
jjtThis.setComments(token_source.comments);
|
||||
jjtThis.setTokenDocument(((net.sourceforge.pmd.lang.ast.impl.javacc.JavaCharStream) token_source.input_stream).getTokenDocument());
|
||||
jjtThis.setTokenDocument(((net.sourceforge.pmd.lang.ast.JavaCharStream) token_source.input_stream).getTokenDocument());
|
||||
return jjtThis;
|
||||
}
|
||||
}
|
||||
@ -1721,7 +1721,7 @@ void ClassOrInterfaceBodyDeclaration():
|
||||
( LOOKAHEAD(3) ClassOrInterfaceDeclaration(modifiers)
|
||||
| LOOKAHEAD({isKeyword("enum")}) EnumDeclaration(modifiers)
|
||||
| LOOKAHEAD( [ TypeParameters() ] <IDENTIFIER> "(" ) ConstructorDeclaration(modifiers)
|
||||
| LOOKAHEAD( Type() <IDENTIFIER> ( "[" "]" )* ( "," | "=" | ";" ) ) FieldDeclaration(modifiers)
|
||||
| LOOKAHEAD( Type() <IDENTIFIER> (AnnotationList() "[" "]")* ( "," | "=" | ";" ) ) FieldDeclaration(modifiers)
|
||||
| LOOKAHEAD(2) MethodDeclaration(modifiers)
|
||||
| LOOKAHEAD(2) AnnotationTypeDeclaration(modifiers)
|
||||
)
|
||||
@ -1739,14 +1739,20 @@ void FieldDeclaration(int modifiers) :
|
||||
void VariableDeclarator() :
|
||||
{}
|
||||
{
|
||||
VariableDeclaratorId() [ "=" VariableInitializer() ]
|
||||
VariableIdWithDims() [ "=" VariableInitializer() ]
|
||||
}
|
||||
|
||||
// TODO use ArrayDimensions
|
||||
void VariableDeclaratorId() :
|
||||
{}
|
||||
{
|
||||
<IDENTIFIER> { setLastTokenImage(jjtThis); } ( "[" "]" { jjtThis.bumpArrayDepth(); })*
|
||||
<IDENTIFIER> { setLastTokenImage(jjtThis); }
|
||||
}
|
||||
|
||||
void VariableIdWithDims() #VariableDeclaratorId :
|
||||
{}
|
||||
{
|
||||
<IDENTIFIER> { setLastTokenImage(jjtThis); }
|
||||
[ Dims() ]
|
||||
}
|
||||
|
||||
void ReceiverParameter():
|
||||
@ -1777,7 +1783,7 @@ void MethodDeclaration(int modifiers) :
|
||||
ResultType()
|
||||
<IDENTIFIER> { setLastTokenImage(jjtThis); }
|
||||
FormalParameters()
|
||||
( "[" "]" )* // TODO use ArrayDimensions
|
||||
[ Dims() ]
|
||||
[ ThrowsList() ]
|
||||
( Block() | ";" )
|
||||
}
|
||||
@ -1790,18 +1796,36 @@ void FormalParameters() :
|
||||
}
|
||||
|
||||
void FormalParameter() :
|
||||
{boolean isFinal = false;}
|
||||
{
|
||||
isFinal=LocalVarModifierList() {jjtThis.setFinal(isFinal);}
|
||||
FormalParamType() ("|" FormalParamType())* // remove this stuff when #2202 is merged
|
||||
VariableIdWithDims()
|
||||
}
|
||||
|
||||
void FormalParamType() #void:
|
||||
{}
|
||||
{
|
||||
( "final" {jjtThis.setFinal(true);} | Annotation() )*
|
||||
Type() ("|" Type())*
|
||||
// TODO there may be annotations before the "..." of the varargs
|
||||
// the ... is treated analogously to a pair of brackets
|
||||
// the sensible way to parse it would probably be to push an ArrayType with ArrayTypeDim for the "..."
|
||||
[ "..." {jjtThis.setVarargs();} ]
|
||||
VariableDeclaratorId()
|
||||
PrimitiveType() [ LOOKAHEAD(2) VarargsDimensions() #ArrayType(2) ]
|
||||
| ClassOrInterfaceType() [ LOOKAHEAD(2) VarargsDimensions() #ArrayType(2) ]
|
||||
}
|
||||
|
||||
void VarargsDimensions() #ArrayDimensions:
|
||||
{}
|
||||
{
|
||||
// like ArrayDimensions but allows for a varargs ellipsis at the end ("...")
|
||||
LOOKAHEAD(AnnotationList() "[") (LOOKAHEAD(AnnotationList() "[") ArrayTypeDim())+ [ VarargsDim() ]
|
||||
| VarargsDim()
|
||||
}
|
||||
|
||||
void VarargsDim() #ArrayTypeDim:
|
||||
{}
|
||||
{
|
||||
TypeAnnotListNoInject() "..." {jjtThis.setVarargs();}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ConstructorDeclaration(int modifiers) :
|
||||
{jjtThis.setModifiers(modifiers);
|
||||
JavaccToken t;}
|
||||
@ -1927,15 +1951,10 @@ void AnnotatedClassOrInterfaceType() #void:
|
||||
* See https://docs.oracle.com/javase/specs/jls/se10/html/jls-8.html#jls-UnannType
|
||||
*/
|
||||
void Type() #void:
|
||||
{}
|
||||
{
|
||||
JavaccToken t;
|
||||
}
|
||||
{
|
||||
// lookahead to catch arrays of primitive types.
|
||||
// we can't lookahead for just PrimitiveType() "["
|
||||
// because the "[" may be preceded by annotations
|
||||
LOOKAHEAD(PrimitiveType() ArrayTypeDim() | <IDENTIFIER>) ReferenceType()
|
||||
| PrimitiveType()
|
||||
PrimitiveType() [ LOOKAHEAD(2) Dims() #ArrayType(2) ]
|
||||
| ClassOrInterfaceType() [ LOOKAHEAD(2) Dims() #ArrayType(2) ]
|
||||
}
|
||||
|
||||
void Dims() #ArrayDimensions:
|
||||
@ -2522,16 +2541,14 @@ void LambdaParameterList():
|
||||
void LambdaParameter():
|
||||
{
|
||||
boolean isVarType = false;
|
||||
ASTLambdaParameter me = jjtThis;
|
||||
boolean isFinal = false;
|
||||
}
|
||||
{
|
||||
[
|
||||
isFinal=LocalVarModifierList() {jjtThis.setFinal(isFinal);}
|
||||
isVarType=LambdaParameterType() { jjtThis.setVarType(); }
|
||||
[ "..." {jjtThis.setVarargs();} ]
|
||||
isFinal=LocalVarModifierList() {jjtThis.setFinal(isFinal);}
|
||||
isVarType=LambdaParameterType()
|
||||
]
|
||||
VariableDeclaratorId()
|
||||
VariableIdWithDims()
|
||||
}
|
||||
|
||||
/** Returns true if this is "var". */
|
||||
@ -2539,8 +2556,8 @@ boolean LambdaParameterType() #void :
|
||||
{}
|
||||
{
|
||||
LOOKAHEAD( { jdkVersion >= 11 && isKeyword("var") } )
|
||||
<IDENTIFIER> { return true; }
|
||||
| Type() { return false; }
|
||||
<IDENTIFIER> { return true; }
|
||||
| FormalParamType() { return false; }
|
||||
}
|
||||
|
||||
void Literal() #void :
|
||||
@ -2967,10 +2984,19 @@ void CatchClause() :
|
||||
{}
|
||||
{
|
||||
"catch"
|
||||
"(" FormalParameter() ")"
|
||||
"(" CatchParameter() ")"
|
||||
Block()
|
||||
}
|
||||
|
||||
|
||||
void CatchParameter():
|
||||
{boolean isFinal = false; boolean multi=false;}
|
||||
{
|
||||
isFinal=LocalVarModifierList() {jjtThis.setFinal(isFinal);}
|
||||
( AnnotatedClassOrInterfaceType() ( "|" AnnotatedClassOrInterfaceType() {multi=true;} )* ) #UnionType(multi)
|
||||
VariableDeclaratorId()
|
||||
}
|
||||
|
||||
void FinallyClause() :
|
||||
{}
|
||||
{
|
||||
@ -2990,15 +3016,15 @@ void AssertStatement() :
|
||||
void RUNSIGNEDSHIFT() #void:
|
||||
{}
|
||||
{
|
||||
LOOKAHEAD({ JavaTokenFactory.getRealKind(getToken(1)) == RUNSIGNEDSHIFT})
|
||||
">" ">" ">"
|
||||
LOOKAHEAD({ JavaTokenFactory.getRealKind(getToken(1)) == RUNSIGNEDSHIFT})
|
||||
">" ">" ">"
|
||||
}
|
||||
|
||||
void RSIGNEDSHIFT() #void:
|
||||
{}
|
||||
{
|
||||
LOOKAHEAD({ JavaTokenFactory.getRealKind(getToken(1)) == RSIGNEDSHIFT})
|
||||
">" ">"
|
||||
LOOKAHEAD({ JavaTokenFactory.getRealKind(getToken(1)) == RSIGNEDSHIFT})
|
||||
">" ">"
|
||||
}
|
||||
|
||||
/* Annotation syntax follows. */
|
||||
@ -3125,7 +3151,7 @@ void AnnotationMethodDeclaration(int modifiers) #MethodDeclaration:
|
||||
Type() #ResultType
|
||||
t=<IDENTIFIER>
|
||||
("(" ")") #FormalParameters(true)
|
||||
( "[" "]" )* // TODO use ArrayTypeDims
|
||||
[ Dims() ]
|
||||
[ DefaultValue() ] ";"
|
||||
{
|
||||
jjtThis.setImage(t.image);
|
||||
|
@ -88,6 +88,17 @@
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>add-kotlin-test-sources</id>
|
||||
<goals>
|
||||
<goal>add-test-source</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>${project.basedir}/src/test/kotlin</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user