List of usage examples for org.eclipse.jdt.core ICompilationUnit FORCE_PROBLEM_DETECTION
int FORCE_PROBLEM_DETECTION
To view the source code for org.eclipse.jdt.core ICompilationUnit FORCE_PROBLEM_DETECTION.
Click Source Link
From source file:cideplus.ui.astview.ASTView.java
License:Open Source License
private CompilationUnit createAST(ITypeRoot input, int astLevel, int offset) throws JavaModelException, CoreException { long startTime; long endTime; CompilationUnit root;/* w ww .j ava 2 s.co m*/ if ((getCurrentInputKind() == ASTInputKindAction.USE_RECONCILE)) { final IProblemRequestor problemRequestor = new IProblemRequestor() { //strange: don't get bindings when supplying null as problemRequestor public void acceptProblem(IProblem problem) { /*not interested*/} public void beginReporting() { /*not interested*/} public void endReporting() { /*not interested*/} public boolean isActive() { return true; } }; WorkingCopyOwner workingCopyOwner = new WorkingCopyOwner() { @Override public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) { return problemRequestor; } }; ICompilationUnit wc = input.getWorkingCopy(workingCopyOwner, null); try { int reconcileFlags = ICompilationUnit.FORCE_PROBLEM_DETECTION; if (fStatementsRecovery) reconcileFlags |= ICompilationUnit.ENABLE_STATEMENTS_RECOVERY; if (fBindingsRecovery) reconcileFlags |= ICompilationUnit.ENABLE_BINDINGS_RECOVERY; if (fIgnoreMethodBodies) reconcileFlags |= ICompilationUnit.IGNORE_METHOD_BODIES; startTime = System.currentTimeMillis(); root = wc.reconcile(getCurrentASTLevel(), reconcileFlags, null, null); endTime = System.currentTimeMillis(); } finally { wc.discardWorkingCopy(); } } else if (input instanceof ICompilationUnit && (getCurrentInputKind() == ASTInputKindAction.USE_CACHE)) { ICompilationUnit cu = (ICompilationUnit) input; startTime = System.currentTimeMillis(); root = SharedASTProvider.getAST(cu, SharedASTProvider.WAIT_NO, null); endTime = System.currentTimeMillis(); } else { ASTParser parser = ASTParser.newParser(astLevel); parser.setResolveBindings(fCreateBindings); if (input instanceof ICompilationUnit) { parser.setSource((ICompilationUnit) input); } else { parser.setSource((IClassFile) input); } parser.setStatementsRecovery(fStatementsRecovery); parser.setBindingsRecovery(fBindingsRecovery); parser.setIgnoreMethodBodies(fIgnoreMethodBodies); if (getCurrentInputKind() == ASTInputKindAction.USE_FOCAL) { parser.setFocalPosition(offset); } startTime = System.currentTimeMillis(); root = (CompilationUnit) parser.createAST(null); endTime = System.currentTimeMillis(); } if (root != null) { updateContentDescription(input, root, endTime - startTime); } return root; }
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; }//from www . j a va 2 s. c om 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.core.reconcile.AJReconcileWorkingCopyOperation.java
License:Open Source License
/** * @exception JavaModelException if setting the source * of the original compilation unit fails *///from w w w. ja va 2s. c o m protected void executeOperation() throws JavaModelException { checkCanceled(); try { beginTask(Messages.element_reconciling, 2); CompilationUnit workingCopy = getWorkingCopy(); boolean wasConsistent = workingCopy.isConsistent(); // check is problem requestor is active IProblemRequestor problemRequestor = workingCopy.getPerWorkingCopyInfo(); if (problemRequestor != null) problemRequestor = ((JavaModelManager.PerWorkingCopyInfo) problemRequestor).getProblemRequestor(); boolean defaultRequestorIsActive = problemRequestor != null && problemRequestor.isActive(); IProblemRequestor ownerProblemRequestor = this.workingCopyOwner.getProblemRequestor(workingCopy); boolean ownerRequestorIsActive = ownerProblemRequestor != null && ownerProblemRequestor != problemRequestor && ownerProblemRequestor.isActive(); this.requestorIsActive = defaultRequestorIsActive || ownerRequestorIsActive; // create the delta builder (this remembers the current content of the cu) this.deltaBuilder = new JavaElementDeltaBuilder(workingCopy); // make working copy consistent if needed and compute AST if needed makeConsistent(workingCopy); // notify reconcile participants only if working copy was not consistent or if forcing problem detection // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=177319) if (!wasConsistent || ((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0)) { notifyParticipants(workingCopy); // recreate ast if one participant reset it if (this.ast == null) makeConsistent(workingCopy); } // report problems if (this.problems != null && (((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) || !wasConsistent)) { if (defaultRequestorIsActive) { reportProblems(workingCopy, problemRequestor); } if (ownerRequestorIsActive) { reportProblems(workingCopy, ownerProblemRequestor); } } // register the deltas // AspectJ Change Begin JavaElementDelta delta = getDelta(deltaBuilder); if (delta != null) { addReconcileDelta(workingCopy, delta); } // AspectJ Change End } finally { done(); } }
From source file:org.eclipse.ajdt.core.reconcile.AJReconcileWorkingCopyOperation.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, 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; }//from w w w .ja va 2 s . com 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; if (workingCopy instanceof AJCompilationUnit) { source = ((AJCompilationUnit) workingCopy).ajCloneCachingContents(); } else { 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 = AJCompilationUnitProblemFinder.processAJ(source, this.workingCopyOwner, this.problems, this.astLevel != ICompilationUnit.NO_AST/*creating AST if level is not NO_AST */, reconcileFlags, this.progressMonitor); 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, 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.core.tests.problemfinding.AbstractProblemFindingTests.java
License:Apache License
/** * @throws JavaModelException//from w ww.jav a2 s .c om */ private void assertNoProblems(CompilationUnit unit) throws JavaModelException { HashMap<String, CategorizedProblem[]> problems = new HashMap<String, CategorizedProblem[]>(); AJCompilationUnitProblemFinder.processAJ( unit, AJWorkingCopyOwner.INSTANCE, problems, true, ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.FORCE_PROBLEM_DETECTION, null); MockProblemRequestor.filterAllWarningProblems(problems); assertEquals("Should not have any problems in " + unit + " but found:\n" //$NON-NLS-1$ + MockProblemRequestor.printProblems(problems), 0, problems.size()); }
From source file:org.eclipse.ajdt.core.tests.problemfinding.Bug273691Reconciling.java
License:Open Source License
private HashMap doFind(ICompilationUnit unit) throws JavaModelException { HashMap problems = new HashMap(); if (unit instanceof AJCompilationUnit) { AJCompilationUnitProblemFinder.processAJ((AJCompilationUnit) unit, AJWorkingCopyOwner.INSTANCE, problems, true,// ww w .ja v a 2 s .com ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.FORCE_PROBLEM_DETECTION, null); } else { // Requires JDT Weaving CompilationUnitProblemFinder.process((CompilationUnit) unit, null, DefaultWorkingCopyOwner.PRIMARY, problems, true, ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.FORCE_PROBLEM_DETECTION, null); } return problems; }
From source file:org.eclipse.ajdt.core.tests.problemfinding.ProblemFinderTests.java
License:Open Source License
/** * project should have no problems at first * @throws Exception/*from w w w. j a va 2s .c o m*/ */ public void testNoProblemsMyAspect() throws Exception { HashMap problems = new HashMap(); AJCompilationUnitProblemFinder.processAJ( myAspectCU, AJWorkingCopyOwner.INSTANCE, problems, true, ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.FORCE_PROBLEM_DETECTION, null); MockProblemRequestor.filterAllWarningProblems(problems); assertEquals("Should not have any problems in " + myAspectCU + " but found:\n" //$NON-NLS-1$ + MockProblemRequestor.printProblems(problems), 0, problems.size()); }
From source file:org.eclipse.ajdt.core.tests.problemfinding.ProblemFinderTests.java
License:Open Source License
public void testNoProblemsOtherClass() throws Exception { HashMap problems = new HashMap(); AJCompilationUnitProblemFinder.processAJ( otherClassCU, AJWorkingCopyOwner.INSTANCE, problems, true, ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.FORCE_PROBLEM_DETECTION, null);/* w w w. j av a 2s. c om*/ MockProblemRequestor.filterAllWarningProblems(problems); assertEquals("Should not have any problems in " + otherClassCU + " but found:\n" //$NON-NLS-1$ + MockProblemRequestor.printProblems(problems), 0, problems.size()); }
From source file:org.eclipse.ajdt.core.tests.problemfinding.ProblemFinderTests.java
License:Open Source License
public void testNoProblemsDemo() throws Exception { HashMap problems = new HashMap(); AJCompilationUnitProblemFinder.processAJ( demoCU, AJWorkingCopyOwner.INSTANCE, problems, true, ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.FORCE_PROBLEM_DETECTION, null);//from w ww . j ava 2 s . c o m MockProblemRequestor.filterAllWarningProblems(problems); assertEquals("Should not have any problems in " + demoCU + " but found:\n" //$NON-NLS-1$ + MockProblemRequestor.printProblems(problems), 0, problems.size()); }
From source file:org.eclipse.ajdt.core.tests.problemfinding.ProblemFinderTests.java
License:Open Source License
public void testNoProblemsMyAspectCU() throws Exception { HashMap problems = new HashMap(); // these next two test super classes and interfaces AJCompilationUnitProblemFinder.processAJ( myAspectCU2, AJWorkingCopyOwner.INSTANCE, problems, true, ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY | ICompilationUnit.FORCE_PROBLEM_DETECTION, null);// ww w .j ava 2s. c om MockProblemRequestor.filterAllWarningProblems(problems); assertEquals("Should not have any problems in " + myAspectCU2 + " but found:\n" //$NON-NLS-1$ + MockProblemRequestor.printProblems(problems), 0, problems.size()); }