List of usage examples for org.eclipse.jdt.core.dom NameEnvironmentWithProgress NameEnvironmentWithProgress
public NameEnvironmentWithProgress(Classpath[] paths, String[] initialFileNames, IProgressMonitor monitor)
From source file:org.eclipse.jdt.core.dom.CompilationUnitResolver.java
License:Open Source License
public static void resolve(String[] sourceUnits, String[] encodings, String[] bindingKeys, FileASTRequestor requestor, int apiLevel, Map options, List classpaths, int flags, IProgressMonitor monitor) {//w w w . j a va 2s .c o m INameEnvironmentWithProgress environment = null; CancelableProblemFactory problemFactory = null; try { if (monitor != null) { int amountOfWork = (sourceUnits.length + bindingKeys.length) * 2; // 1 for beginToCompile, 1 for resolve monitor.beginTask("", amountOfWork); //$NON-NLS-1$ } Classpath[] allEntries = new Classpath[classpaths.size()]; classpaths.toArray(allEntries); environment = new NameEnvironmentWithProgress(allEntries, null, monitor); problemFactory = new CancelableProblemFactory(monitor); CompilerOptions compilerOptions = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); compilerOptions.ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0; CompilationUnitResolver resolver = new CompilationUnitResolver(environment, getHandlingPolicy(), compilerOptions, getRequestor(), problemFactory, monitor, false); resolver.resolve(sourceUnits, encodings, bindingKeys, requestor, apiLevel, options, flags); if (NameLookup.VERBOSE && (environment instanceof CancelableNameEnvironment)) { CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment; System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " //$NON-NLS-1$ + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " //$NON-NLS-1$ + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$ } } finally { if (monitor != null) monitor.done(); if (environment != null) { environment.setMonitor(null); // don't hold a reference to this external object } if (problemFactory != null) { problemFactory.monitor = null; // don't hold a reference to this external object } } }
From source file:org.eclipse.jdt.core.dom.CompilationUnitResolver.java
License:Open Source License
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; CompilationUnitResolver resolver = null; try {/*from ww w. j a va 2 s .co m*/ if (javaProject == null) { Classpath[] allEntries = new 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 = getCompilerOptions(options, (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0); boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0; compilerOptions.ignoreMethodBodies = ignoreMethodBodies; // GROOVY start CompilerUtils.configureOptionsBasedOnNature(compilerOptions, javaProject); // GROOVY end resolver = new CompilationUnitResolver(environment, getHandlingPolicy(), compilerOptions, getRequestor(), problemFactory, monitor, javaProject != null); boolean analyzeAndGenerateCode = !ignoreMethodBodies; unit = resolver.resolve(null, // no existing compilation unit declaration sourceUnit, nodeSearcher, true, // method verification analyzeAndGenerateCode, // analyze code analyzeAndGenerateCode); // generate code 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 = parse(sourceUnit, nodeSearcher, options, flags); 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; } return unitDeclaration; } if (NameLookup.VERBOSE && environment instanceof CancelableNameEnvironment) { CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment; System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " //$NON-NLS-1$ + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " //$NON-NLS-1$ + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$ } return unit; } finally { if (environment != null) { // don't hold a reference to this external object environment.setMonitor(null); } if (problemFactory != null) { problemFactory.monitor = null; // don't hold a reference to this external object } } }