List of usage examples for org.eclipse.jdt.internal.core CompilationUnitProblemFinder process
public static CompilationUnitDeclaration process(CompilationUnit unitElement, WorkingCopyOwner workingCopyOwner, HashMap problems, boolean creatingAST, int reconcileFlags, IProgressMonitor monitor) throws JavaModelException
From source file:org.codehaus.jdt.groovy.model.GroovyReconcileWorkingCopyOperation.java
License:Open Source License
public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(CompilationUnit workingCopy) throws JavaModelException { if (!workingCopy.isConsistent()) { // make working copy consistent if (this.problems == null) this.problems = new HashMap(); this.resolveBindings = this.requestorIsActive; this.ast = workingCopy.makeConsistent(this.astLevel, this.resolveBindings, this.reconcileFlags, this.problems, this.progressMonitor); this.deltaBuilder.buildDeltas(); if (this.ast != null && this.deltaBuilder.delta != null) this.deltaBuilder.delta.changedAST(this.ast); return this.ast; }// www .j a v a2 s . c o m if (this.ast != null) return this.ast; // no need to recompute AST if known already CompilationUnitDeclaration unit = null; try { JavaModelManager.getJavaModelManager().abortOnMissingSource.set(Boolean.TRUE); CompilationUnit source = workingCopy.cloneCachingContents(); // find problems if needed if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()) && (this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) { this.resolveBindings = this.requestorIsActive; if (this.problems == null) this.problems = new HashMap(); unit = CompilationUnitProblemFinder.process(source, this.workingCopyOwner, this.problems, this.astLevel != ICompilationUnit.NO_AST/* creating AST if level is not NO_AST */, this.reconcileFlags, this.progressMonitor); // GROOVY cache the ModuleNode in the ModuleNodeMapper if (unit instanceof GroovyCompilationUnitDeclaration) { // should always be true ModuleNodeMapper.getInstance().maybeCacheModuleNode(workingCopy.getPerWorkingCopyInfo(), (GroovyCompilationUnitDeclaration) unit); } // GROOVY end if (this.progressMonitor != null) this.progressMonitor.worked(1); } // create AST if needed if (this.astLevel != ICompilationUnit.NO_AST && unit != null/* * unit is null if working copy is consistent && (problem * detection not forced || non-Java project) -> don't create * AST as per API */) { Map options = workingCopy.getJavaProject().getOptions(true); // convert AST this.ast = AST.convertCompilationUnit(this.astLevel, unit, options, this.resolveBindings, source, this.reconcileFlags, this.progressMonitor); if (this.ast != null) { if (this.deltaBuilder.delta == null) { this.deltaBuilder.delta = new JavaElementDelta(workingCopy); } this.deltaBuilder.delta.changedAST(this.ast); } if (this.progressMonitor != null) this.progressMonitor.worked(1); } } catch (JavaModelException e) { if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())) throw e; // else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919) } finally { JavaModelManager.getJavaModelManager().abortOnMissingSource.set(null); if (unit != null) { unit.cleanUp(); } } return this.ast; }
From source file:org.eclipse.ajdt.ui.tests.reconciling.ProblemFinderTests4.java
License:Open Source License
public void testJavaFile() throws Exception { // Open in AJ Editor in order to force code transformation final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IFileEditorInput input = new FileEditorInput(inJavaFile); IDE.openEditor(page, input, AspectJEditor.ASPECTJ_EDITOR_ID); HashMap problems = new HashMap(); CompilationUnitProblemFinder.process( inJavaFileCU, AJWorkingCopyOwner.INSTANCE, problems, true, ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.FORCE_PROBLEM_DETECTION, null);//from w w w . j a va2 s. c o m MockProblemRequestor.filterAllWarningProblems(problems); assertEquals("Should not have any problems in " + inJavaFileCU + " but found:\n" //$NON-NLS-1$ + MockProblemRequestor.printProblems(problems), 0, problems.size()); }