Search in sources :

Example 1 with INameEnvironmentWithProgress

use of org.eclipse.jdt.internal.core.INameEnvironmentWithProgress in project che by eclipse.

the class CheCompilationUnitResolver method resolve.

public static CompilationUnitDeclaration resolve(org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, IJavaProject javaProject, List classpaths, NodeSearcher nodeSearcher, Map options, WorkingCopyOwner owner, int flags, IProgressMonitor monitor) throws JavaModelException {
    CompilationUnitDeclaration unit = null;
    INameEnvironmentWithProgress environment = null;
    CancelableProblemFactory problemFactory = null;
    CheCompilationUnitResolver resolver = null;
    try {
        if (javaProject == null) {
            FileSystem.Classpath[] allEntries = new FileSystem.Classpath[classpaths.size()];
            classpaths.toArray(allEntries);
            environment = new NameEnvironmentWithProgress(allEntries, null, monitor);
        } else {
            environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor);
        }
        problemFactory = new CancelableProblemFactory(monitor);
        CompilerOptions compilerOptions = CompilationUnitResolver.getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
        boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
        compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
        resolver = new CheCompilationUnitResolver(environment, CompilationUnitResolver.getHandlingPolicy(), compilerOptions, CompilationUnitResolver.getRequestor(), problemFactory, monitor, javaProject != null);
        boolean analyzeAndGenerateCode = !ignoreMethodBodies;
        unit = resolver.resolve(// no existing compilation unit declaration
        null, sourceUnit, nodeSearcher, // method verification
        true, // analyze code
        analyzeAndGenerateCode, // generate code
        analyzeAndGenerateCode);
        if (resolver.hasCompilationAborted) {
            // the bindings could not be resolved due to missing types in name environment
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
            CompilationUnitDeclaration unitDeclaration = CompilationUnitResolver.parse(sourceUnit, nodeSearcher, options, flags);
            if (unit != null) {
                final int problemCount = unit.compilationResult.problemCount;
                if (problemCount != 0) {
                    unitDeclaration.compilationResult.problems = new CategorizedProblem[problemCount];
                    System.arraycopy(unit.compilationResult.problems, 0, unitDeclaration.compilationResult.problems, 0, problemCount);
                    unitDeclaration.compilationResult.problemCount = problemCount;
                }
            } else if (resolver.abortProblem != null) {
                unitDeclaration.compilationResult.problemCount = 1;
                unitDeclaration.compilationResult.problems = new CategorizedProblem[] { resolver.abortProblem };
            }
            return unitDeclaration;
        }
        if (NameLookup.VERBOSE && environment instanceof CancelableNameEnvironment) {
            CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment;
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms");
            //$NON-NLS-1$ //$NON-NLS-2$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms");
        }
        return unit;
    } finally {
        if (environment != null) {
            // don't hold a reference to this external object
            environment.setMonitor(null);
        }
        if (problemFactory != null) {
            // don't hold a reference to this external object
            problemFactory.monitor = null;
        }
    }
}
Also used : JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) INameEnvironmentWithProgress(org.eclipse.jdt.internal.core.INameEnvironmentWithProgress) INameEnvironmentWithProgress(org.eclipse.jdt.internal.core.INameEnvironmentWithProgress) CategorizedProblem(org.eclipse.jdt.core.compiler.CategorizedProblem) CancelableProblemFactory(org.eclipse.jdt.internal.core.CancelableProblemFactory) CompilationUnitDeclaration(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) CancelableNameEnvironment(org.eclipse.jdt.internal.core.CancelableNameEnvironment)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)1 CategorizedProblem (org.eclipse.jdt.core.compiler.CategorizedProblem)1 CompilationUnitDeclaration (org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration)1 CompilerOptions (org.eclipse.jdt.internal.compiler.impl.CompilerOptions)1 CancelableNameEnvironment (org.eclipse.jdt.internal.core.CancelableNameEnvironment)1 CancelableProblemFactory (org.eclipse.jdt.internal.core.CancelableProblemFactory)1 INameEnvironmentWithProgress (org.eclipse.jdt.internal.core.INameEnvironmentWithProgress)1 JavaProject (org.eclipse.jdt.internal.core.JavaProject)1