Example usage for org.eclipse.jdt.internal.compiler.ast CompilationUnitDeclaration hasFunctionalTypes

List of usage examples for org.eclipse.jdt.internal.compiler.ast CompilationUnitDeclaration hasFunctionalTypes

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast CompilationUnitDeclaration hasFunctionalTypes.

Prototype

public boolean hasFunctionalTypes() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java

License:Open Source License

protected boolean buildStructure(OpenableElementInfo info, final IProgressMonitor pm, Map newElements,
        File underlyingResource) throws JavaModelException {
    CompilationUnitElementInfo unitInfo = (CompilationUnitElementInfo) info;

    // ensure buffer is opened
    IBuffer buffer = getBufferManager().getBuffer(CompilationUnit.this);
    if (buffer == null) {
        openBuffer(pm, unitInfo); // open buffer independently from the info, since we are building the info
    }//from  w w w .j  av a 2s  . co  m

    // generate structure and compute syntax problems if needed
    CompilationUnitStructureRequestor requestor = new CompilationUnitStructureRequestor(this, unitInfo,
            newElements, manager);
    JavaModelManager.PerWorkingCopyInfo perWorkingCopyInfo = getPerWorkingCopyInfo();
    IJavaProject project = getJavaProject();

    boolean createAST;
    boolean resolveBindings;
    int reconcileFlags;
    HashMap problems;
    if (info instanceof ASTHolderCUInfo) {
        ASTHolderCUInfo astHolder = (ASTHolderCUInfo) info;
        createAST = astHolder.astLevel != NO_AST;
        resolveBindings = astHolder.resolveBindings;
        reconcileFlags = astHolder.reconcileFlags;
        problems = astHolder.problems;
    } else {
        createAST = false;
        resolveBindings = true;
        reconcileFlags = 0;
        problems = null;
    }
    boolean computeProblems = false;
    //   boolean computeProblems = perWorkingCopyInfo != null && perWorkingCopyInfo.isActive() && project != null && JavaProject
    //         .hasJavaNature(project.getProject());
    IProblemFactory problemFactory = new DefaultProblemFactory();
    Map options = project == null ? JavaCore.getOptions() : project.getOptions(true);
    if (!computeProblems) {
        // disable task tags checking to speed up parsing
        options.put(JavaCore.COMPILER_TASK_TAGS, ""); //$NON-NLS-1$
    }
    CompilerOptions compilerOptions = new CompilerOptions(options);
    compilerOptions.ignoreMethodBodies = (reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
    SourceElementParser parser = new SourceElementParser(requestor, problemFactory, compilerOptions,
            true/*report local declarations*/,
            !createAST /*optimize string literals only if not creating a DOM AST*/);
    parser.reportOnlyOneSyntaxError = !computeProblems;
    parser.setMethodsFullRecovery(true);
    parser.setStatementsRecovery((reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);

    if (!computeProblems && !resolveBindings && !createAST) // disable javadoc parsing if not computing problems, not resolving and not creating ast
        parser.javadocParser.checkDocComment = false;
    requestor.parser = parser;

    // update timestamp (might be IResource.NULL_STAMP if original does not exist)
    if (underlyingResource == null) {
        underlyingResource = resource();
    }
    // underlying resource is null in the case of a working copy on a class file in a jar
    if (underlyingResource != null)
        unitInfo.timestamp = (underlyingResource).lastModified();

    // compute other problems if needed
    CompilationUnitDeclaration compilationUnitDeclaration = null;
    CompilationUnit source = cloneCachingContents();
    try {
        if (computeProblems) {
            //         if (problems == null) {
            //            // report problems to the problem requestor
            //            problems = new HashMap();
            //            compilationUnitDeclaration = CompilationUnitProblemFinder
            //                  .process(source, parser, this.owner, problems, createAST, reconcileFlags, pm);
            //            try {
            //               perWorkingCopyInfo.beginReporting();
            //               for (Iterator iteraror = problems.values().iterator(); iteraror.hasNext();) {
            //                  CategorizedProblem[] categorizedProblems = (CategorizedProblem[]) iteraror.next();
            //                  if (categorizedProblems == null) continue;
            //                  for (int i = 0, length = categorizedProblems.length; i < length; i++) {
            //                     perWorkingCopyInfo.acceptProblem(categorizedProblems[i]);
            //                  }
            //               }
            //            } finally {
            //               perWorkingCopyInfo.endReporting();
            //            }
            //         } else {
            //            // collect problems
            //            compilationUnitDeclaration = CompilationUnitProblemFinder
            //                  .process(source, parser, this.owner, problems, createAST, reconcileFlags, pm);
            //         }
        } else {
            compilationUnitDeclaration = parser.parseCompilationUnit(source,
                    true /*full parse to find local elements*/, pm);
        }

        if (createAST) {
            //         int astLevel = ((ASTHolderCUInfo) info).astLevel;
            //         org.eclipse.jdt.core.dom.CompilationUnit cu = AST
            //               .convertCompilationUnit(astLevel, compilationUnitDeclaration, options, computeProblems, source, reconcileFlags, pm);
            //         ((ASTHolderCUInfo) info).ast = cu;
        }
    } finally {
        if (compilationUnitDeclaration != null) {
            unitInfo.hasFunctionalTypes = compilationUnitDeclaration.hasFunctionalTypes();
            compilationUnitDeclaration.cleanUp();
        }
    }

    return unitInfo.isStructureKnown();
}