Example usage for org.eclipse.jdt.core.dom AST JLS10

List of usage examples for org.eclipse.jdt.core.dom AST JLS10

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom AST JLS10.

Prototype

int JLS10

To view the source code for org.eclipse.jdt.core.dom AST JLS10.

Click Source Link

Document

Constant for indicating the AST API that handles JLS10.

Usage

From source file:org.springframework.ide.vscode.boot.java.handlers.BootJavaReferencesHandler.java

License:Open Source License

private List<? extends Location> provideReferences(TextDocument document, int offset) throws Exception {
    ASTParser parser = ASTParser.newParser(AST.JLS10);
    Map<String, String> options = JavaCore.getOptions();
    JavaCore.setComplianceOptions(JavaCore.VERSION_10, options);
    parser.setCompilerOptions(options);// w  w  w . j  a  v a2 s  .  co  m
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    parser.setStatementsRecovery(true);
    parser.setBindingsRecovery(true);
    parser.setResolveBindings(true);

    String[] classpathEntries = getClasspathEntries(document);
    String[] sourceEntries = new String[] {};
    parser.setEnvironment(classpathEntries, sourceEntries, null, true);

    String docURI = document.getUri();
    String unitName = docURI.substring(docURI.lastIndexOf("/"));
    parser.setUnitName(unitName);
    parser.setSource(document.get(0, document.getLength()).toCharArray());

    CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    ASTNode node = NodeFinder.perform(cu, offset, 0);

    if (node != null) {
        return provideReferencesForAnnotation(node, offset, document);
    }

    return null;
}