Search in sources :

Example 1 with Compilation

use of apex.jorje.semantic.ast.compilation.Compilation in project pmd by pmd.

the class ApexMultifileVisitorTest method parseAndVisitForString.

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;
}
Also used : Compilation(apex.jorje.semantic.ast.compilation.Compilation) LanguageVersionHandler(net.sourceforge.pmd.lang.LanguageVersionHandler)

Example 2 with Compilation

use of apex.jorje.semantic.ast.compilation.Compilation in project pmd by pmd.

the class ApexParser method parse.

public ApexNode<Compilation> parse(final Reader reader) {
    try {
        final String sourceCode = IOUtils.toString(reader);
        final Compilation astRoot = parseApex(sourceCode);
        final ApexTreeBuilder treeBuilder = new ApexTreeBuilder(sourceCode);
        suppressMap = new HashMap<>();
        if (astRoot == null) {
            throw new ParseException("Couldn't parse the source - there is not root node - Syntax Error??");
        }
        return treeBuilder.build(astRoot);
    } catch (IOException e) {
        throw new ParseException(e);
    }
}
Also used : Compilation(apex.jorje.semantic.ast.compilation.Compilation) ParseException(net.sourceforge.pmd.lang.ast.ParseException) IOException(java.io.IOException)

Example 3 with Compilation

use of apex.jorje.semantic.ast.compilation.Compilation in project pmd by pmd.

the class ApexCompilerSoqlTest method testSoqlCompilation.

@Test
public void testSoqlCompilation() {
    ApexParser parser = new ApexParser(new ApexParserOptions());
    ApexNode<Compilation> cu = parser.parse(new StringReader(CODE));
    Assert.assertNotNull(cu);
}
Also used : Compilation(apex.jorje.semantic.ast.compilation.Compilation) ApexParserOptions(net.sourceforge.pmd.lang.apex.ApexParserOptions) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 4 with Compilation

use of apex.jorje.semantic.ast.compilation.Compilation in project pmd by pmd.

the class ApexParserTest method parsesRealWorldClasses.

@Test
public void parsesRealWorldClasses() throws Exception {
    File directory = new File("src/test/resources");
    File[] fList = directory.listFiles();
    for (File file : fList) {
        if (file.isFile() && file.getName().endsWith(".cls")) {
            String sourceCode = FileUtils.readFileToString(file);
            ApexNode<Compilation> rootNode = parse(sourceCode);
            Assert.assertNotNull(rootNode);
        }
    }
}
Also used : Compilation(apex.jorje.semantic.ast.compilation.Compilation) File(java.io.File) Test(org.junit.Test)

Example 5 with Compilation

use of apex.jorje.semantic.ast.compilation.Compilation in project pmd by pmd.

the class ApexParserTest method verifyEndLine.

@Test
public void verifyEndLine() {
    String code = // line 1
    "public class SimpleClass {\n" + // line 2
    "    public void method1() {\n" + // line 3
    "    }\n" + // line 4
    "    public void method2() {\n" + // line 5
    "    }\n" + // line 6
    "}\n";
    ApexNode<Compilation> rootNode = parse(code);
    Node method1 = rootNode.jjtGetChild(1);
    assertEquals("Wrong begin line", 2, method1.getBeginLine());
    assertEquals("Wrong end line", 3, method1.getEndLine());
    Node method2 = rootNode.jjtGetChild(2);
    assertEquals("Wrong begin line", 4, method2.getBeginLine());
    assertEquals("Wrong end line", 5, method2.getEndLine());
}
Also used : Compilation(apex.jorje.semantic.ast.compilation.Compilation) Node(net.sourceforge.pmd.lang.ast.Node) Test(org.junit.Test)

Aggregations

Compilation (apex.jorje.semantic.ast.compilation.Compilation)7 Test (org.junit.Test)4 LanguageVersionHandler (net.sourceforge.pmd.lang.LanguageVersionHandler)2 File (java.io.File)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ApexParserOptions (net.sourceforge.pmd.lang.apex.ApexParserOptions)1 ASTMethod (net.sourceforge.pmd.lang.apex.ast.ASTMethod)1 ApexParserTest (net.sourceforge.pmd.lang.apex.ast.ApexParserTest)1 ApexParserVisitorAdapter (net.sourceforge.pmd.lang.apex.ast.ApexParserVisitorAdapter)1 ApexSignatureMatcher (net.sourceforge.pmd.lang.apex.metrics.ApexSignatureMatcher)1 ApexOperationSigMask (net.sourceforge.pmd.lang.apex.metrics.signature.ApexOperationSigMask)1 Node (net.sourceforge.pmd.lang.ast.Node)1 ParseException (net.sourceforge.pmd.lang.ast.ParseException)1