Merge branch 'java-grammar' into grammar-dimensions
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 {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
@ -3025,15 +3025,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. */
|
||||
|
@ -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>
|
||||
|
||||
|
@ -15,6 +15,10 @@
|
||||
<property name="generic-sideeffect-visitor-interface-file"
|
||||
value="${target-package-dir}/${generic-sideeffect-visitor-interface-name}.java" />
|
||||
|
||||
<property name="ast-core-package" value="net.sourceforge.pmd.lang.ast" />
|
||||
<property name="ast-impl-package" value="${ast-core-package}.impl.javacc" />
|
||||
|
||||
|
||||
<!-- TARGETS -->
|
||||
|
||||
<target name="alljavacc"
|
||||
@ -123,25 +127,18 @@
|
||||
</replacevalue>
|
||||
</replace>
|
||||
|
||||
<replace token="new Token()" value="net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken.undefined()">
|
||||
<fileset dir="${target-package-dir}"/>
|
||||
|
||||
<replace token="new Token()" value="${ast-impl-package}.JavaccToken.undefined()">
|
||||
<fileset dir="${target-package-dir}" />
|
||||
</replace>
|
||||
|
||||
<replace token=" Token " value=" net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken ">
|
||||
<fileset dir="${target-package-dir}"/>
|
||||
</replace>
|
||||
<!-- Map Javacc names to our names -->
|
||||
|
||||
<replace token="(Token " value="(net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken ">
|
||||
<fileset dir="${target-package-dir}"/>
|
||||
</replace>
|
||||
|
||||
<replace token=" Token(" value=" net.sourceforge.pmd.lang.ast.impl.JavaccToken(">
|
||||
<fileset dir="${target-package-dir}"/>
|
||||
</replace>
|
||||
|
||||
<replace token=";Token " value=";net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken ">
|
||||
<fileset dir="${target-package-dir}"/>
|
||||
</replace>
|
||||
<replaceregexp flags="g">
|
||||
<regexp pattern="\bToken\b" />
|
||||
<substitution expression="${ast-impl-package}.JavaccToken" />
|
||||
<fileset dir="${target-package-dir}" />
|
||||
</replaceregexp>
|
||||
|
||||
|
||||
<replace file="${target-package-dir}/JavaParserTokenManager.java">
|
||||
@ -177,8 +174,8 @@
|
||||
|
||||
|
||||
<replace file="${target-package-dir}/JavaParserTokenManager.java"
|
||||
token="public class JavaParserTokenManager"
|
||||
value="import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; public class JavaParserTokenManager extends net.sourceforge.pmd.lang.ast.impl.javacc.AbstractTokenManager" />
|
||||
token="class JavaParserTokenManager"
|
||||
value="class JavaParserTokenManager extends net.sourceforge.pmd.lang.ast.AbstractTokenManager" />
|
||||
<replace file="${target-package-dir}/JavaParser.java"
|
||||
token="throw new Error"
|
||||
value="throw new RuntimeException" />
|
||||
@ -193,8 +190,6 @@
|
||||
<!-- We perform most changes like adding default methods, etc on this one -->
|
||||
<!-- Changes are then copied on other visitors -->
|
||||
<replace file="${base-visitor-interface-file}">
|
||||
<replacefilter token="public interface" value="
|
||||
public interface" />
|
||||
<replacefilter token="JavaParserVisitor" value="${base-visitor-interface-name}" />
|
||||
<replacefilter token="SimpleNode" value="JavaNode" />
|
||||
<!-- Default methods -->
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user