Lines 22-27
Link Here
|
22 |
import org.eclipse.jdt.core.compiler.CompilationParticipant; |
22 |
import org.eclipse.jdt.core.compiler.CompilationParticipant; |
23 |
import org.eclipse.jdt.core.compiler.ReconcileContext; |
23 |
import org.eclipse.jdt.core.compiler.ReconcileContext; |
24 |
import org.eclipse.jdt.core.dom.AST; |
24 |
import org.eclipse.jdt.core.dom.AST; |
|
|
25 |
import org.eclipse.jdt.core.dom.ASTParser; |
25 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
26 |
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
26 |
import org.eclipse.jdt.internal.core.util.Messages; |
27 |
import org.eclipse.jdt.internal.core.util.Messages; |
27 |
import org.eclipse.jdt.internal.core.util.Util; |
28 |
import org.eclipse.jdt.internal.core.util.Util; |
Lines 52-57
Link Here
|
52 |
WorkingCopyOwner workingCopyOwner; |
53 |
WorkingCopyOwner workingCopyOwner; |
53 |
public org.eclipse.jdt.core.dom.CompilationUnit ast; |
54 |
public org.eclipse.jdt.core.dom.CompilationUnit ast; |
54 |
public JavaElementDeltaBuilder deltaBuilder; |
55 |
public JavaElementDeltaBuilder deltaBuilder; |
|
|
56 |
public boolean requestorIsActive; |
55 |
|
57 |
|
56 |
public ReconcileWorkingCopyOperation(IJavaElement workingCopy, int astLevel, int reconcileFlags, WorkingCopyOwner workingCopyOwner) { |
58 |
public ReconcileWorkingCopyOperation(IJavaElement workingCopy, int astLevel, int reconcileFlags, WorkingCopyOwner workingCopyOwner) { |
57 |
super(new IJavaElement[] {workingCopy}); |
59 |
super(new IJavaElement[] {workingCopy}); |
Lines 71-104
Link Here
|
71 |
|
73 |
|
72 |
CompilationUnit workingCopy = getWorkingCopy(); |
74 |
CompilationUnit workingCopy = getWorkingCopy(); |
73 |
boolean wasConsistent = workingCopy.isConsistent(); |
75 |
boolean wasConsistent = workingCopy.isConsistent(); |
|
|
76 |
|
77 |
// check is problem requestor is active |
74 |
IProblemRequestor problemRequestor = workingCopy.getPerWorkingCopyInfo(); |
78 |
IProblemRequestor problemRequestor = workingCopy.getPerWorkingCopyInfo(); |
75 |
if (problemRequestor != null) { |
79 |
if (problemRequestor != null) |
76 |
problemRequestor = ((JavaModelManager.PerWorkingCopyInfo)problemRequestor).getProblemRequestor(); |
80 |
problemRequestor = ((JavaModelManager.PerWorkingCopyInfo)problemRequestor).getProblemRequestor(); |
77 |
} |
81 |
boolean defaultRequestorIsActive = problemRequestor != null && problemRequestor.isActive(); |
78 |
IProblemRequestor ownerProblemRequestor = this.workingCopyOwner.getProblemRequestor(workingCopy); |
82 |
IProblemRequestor ownerProblemRequestor = this.workingCopyOwner.getProblemRequestor(workingCopy); |
79 |
this.resolveBindings |= problemRequestor != null && problemRequestor.isActive(); |
83 |
boolean ownerRequestorIsActive = ownerProblemRequestor != null && ownerProblemRequestor != problemRequestor && ownerProblemRequestor.isActive(); |
|
|
84 |
this.requestorIsActive = defaultRequestorIsActive || ownerRequestorIsActive; |
80 |
|
85 |
|
81 |
// create the delta builder (this remembers the current content of the cu) |
86 |
// create the delta builder (this remembers the current content of the cu) |
82 |
this.deltaBuilder = new JavaElementDeltaBuilder(workingCopy); |
87 |
this.deltaBuilder = new JavaElementDeltaBuilder(workingCopy); |
83 |
|
88 |
|
84 |
// make working copy consistent if needed and compute AST if needed |
89 |
// make working copy consistent if needed and compute AST if needed |
85 |
makeConsistent(workingCopy, problemRequestor); |
90 |
makeConsistent(workingCopy); |
86 |
|
91 |
|
87 |
// notify reconcile participants only if working copy was not consistent or if forcing problem detection |
92 |
// notify reconcile participants only if working copy was not consistent or if forcing problem detection |
88 |
// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=177319) |
93 |
// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=177319) |
89 |
if (!wasConsistent || ((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0)) |
94 |
if (!wasConsistent || ((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0)) { |
90 |
notifyParticipants(workingCopy); |
95 |
notifyParticipants(workingCopy); |
91 |
|
96 |
|
92 |
// recreate ast if needed |
97 |
// recreate ast if one participant reset it |
93 |
if (this.ast == null && (this.astLevel > ICompilationUnit.NO_AST || this.resolveBindings)) |
98 |
if (this.ast == null) |
94 |
makeConsistent(workingCopy, problemRequestor); |
99 |
makeConsistent(workingCopy); |
|
|
100 |
} |
95 |
|
101 |
|
96 |
// report problems |
102 |
// report problems |
97 |
if (this.problems != null && (((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) || !wasConsistent)) { |
103 |
if (this.problems != null && (((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) || !wasConsistent)) { |
98 |
if (problemRequestor != null) { |
104 |
if (defaultRequestorIsActive) { |
99 |
reportProblems(workingCopy, problemRequestor); |
105 |
reportProblems(workingCopy, problemRequestor); |
100 |
} |
106 |
} |
101 |
if (ownerProblemRequestor != null && ownerProblemRequestor != problemRequestor) { |
107 |
if (ownerRequestorIsActive) { |
102 |
reportProblems(workingCopy, ownerProblemRequestor); |
108 |
reportProblems(workingCopy, ownerProblemRequestor); |
103 |
} |
109 |
} |
104 |
} |
110 |
} |
Lines 157-231
Link Here
|
157 |
* Makes the given working copy consistent, computes the delta and computes an AST if needed. |
163 |
* Makes the given working copy consistent, computes the delta and computes an AST if needed. |
158 |
* Returns the AST. |
164 |
* Returns the AST. |
159 |
*/ |
165 |
*/ |
160 |
public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(CompilationUnit workingCopy, IProblemRequestor problemRequestor) throws JavaModelException { |
166 |
public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(CompilationUnit workingCopy) throws JavaModelException { |
161 |
if (!workingCopy.isConsistent()) { |
167 |
if (!workingCopy.isConsistent()) { |
162 |
// make working copy consistent |
168 |
// make working copy consistent |
163 |
if (this.problems == null) this.problems = new HashMap(); |
169 |
if (this.problems == null) this.problems = new HashMap(); |
|
|
170 |
this.resolveBindings = this.requestorIsActive; |
164 |
this.ast = workingCopy.makeConsistent(this.astLevel, this.resolveBindings, reconcileFlags, this.problems, this.progressMonitor); |
171 |
this.ast = workingCopy.makeConsistent(this.astLevel, this.resolveBindings, reconcileFlags, this.problems, this.progressMonitor); |
165 |
this.deltaBuilder.buildDeltas(); |
172 |
this.deltaBuilder.buildDeltas(); |
166 |
if (this.ast != null && this.deltaBuilder.delta != null) |
173 |
if (this.ast != null && this.deltaBuilder.delta != null) |
167 |
this.deltaBuilder.delta.changedAST(this.ast); |
174 |
this.deltaBuilder.delta.changedAST(this.ast); |
168 |
return this.ast; |
175 |
return this.ast; |
169 |
} |
176 |
} |
170 |
if (this.ast != null) return this.ast; // no need to recompute AST if known already |
177 |
if (this.ast != null) |
171 |
if (((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) || this.resolveBindings) { |
178 |
return this.ast; // no need to recompute AST if known already |
172 |
if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())) { |
179 |
|
173 |
HashMap problemMap; |
180 |
CompilationUnitDeclaration unit = null; |
174 |
if (this.problems == null) { |
181 |
char[] contents = null; |
175 |
problemMap = new HashMap(); |
182 |
try { |
176 |
if ((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) |
183 |
// find problems if needed |
177 |
this.problems = problemMap; |
184 |
if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()) |
178 |
} else |
185 |
&& (this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) { |
179 |
problemMap = this.problems; |
186 |
this.resolveBindings = this.requestorIsActive; |
180 |
CompilationUnitDeclaration unit = null; |
187 |
if (this.problems == null) |
181 |
try { |
188 |
this.problems = new HashMap(); |
182 |
// find problems |
189 |
contents = workingCopy.getContents(); |
183 |
char[] contents = workingCopy.getContents(); |
190 |
unit = |
184 |
unit = |
191 |
CompilationUnitProblemFinder.process( |
185 |
CompilationUnitProblemFinder.process( |
192 |
workingCopy, |
186 |
workingCopy, |
193 |
contents, |
187 |
contents, |
194 |
this.workingCopyOwner, |
188 |
this.workingCopyOwner, |
195 |
this.problems, |
189 |
problemMap, |
196 |
this.astLevel != ICompilationUnit.NO_AST/*creating AST if level is not NO_AST */, |
190 |
this.astLevel != ICompilationUnit.NO_AST/*creating AST if level is not NO_AST */, |
197 |
reconcileFlags, |
191 |
reconcileFlags, |
198 |
this.progressMonitor); |
192 |
this.progressMonitor); |
199 |
if (this.progressMonitor != null) this.progressMonitor.worked(1); |
193 |
if (this.progressMonitor != null) this.progressMonitor.worked(1); |
200 |
} |
194 |
|
201 |
|
195 |
// create AST if needed |
202 |
// create AST if needed |
196 |
if (this.astLevel != ICompilationUnit.NO_AST && unit != null) { |
203 |
if (this.astLevel != ICompilationUnit.NO_AST |
197 |
Map options = workingCopy.getJavaProject().getOptions(true); |
204 |
&& unit !=null/*unit is null if working copy is consistent && (problem detection not forced || non-Java project) -> don't create AST as per API*/) { |
198 |
this.ast = |
205 |
Map options = workingCopy.getJavaProject().getOptions(true); |
199 |
AST.convertCompilationUnit( |
206 |
// convert AST |
200 |
this.astLevel, |
207 |
this.ast = |
201 |
unit, |
208 |
AST.convertCompilationUnit( |
202 |
contents, |
209 |
this.astLevel, |
203 |
options, |
210 |
unit, |
204 |
true/*isResolved*/, |
211 |
contents, |
205 |
workingCopy, |
212 |
options, |
206 |
reconcileFlags, |
213 |
this.resolveBindings, |
207 |
this.progressMonitor); |
214 |
workingCopy, |
208 |
if (this.ast != null) { |
215 |
reconcileFlags, |
209 |
this.deltaBuilder.delta = new JavaElementDelta(workingCopy); |
216 |
this.progressMonitor); |
210 |
this.deltaBuilder.delta.changedAST(this.ast); |
217 |
if (this.ast != null) { |
211 |
} |
218 |
this.deltaBuilder.delta = new JavaElementDelta(workingCopy); |
212 |
if (this.progressMonitor != null) this.progressMonitor.worked(1); |
219 |
this.deltaBuilder.delta.changedAST(this.ast); |
213 |
} |
220 |
} |
214 |
} catch (JavaModelException e) { |
221 |
if (this.progressMonitor != null) this.progressMonitor.worked(1); |
215 |
if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())) |
222 |
} |
216 |
throw e; |
223 |
} catch (JavaModelException e) { |
217 |
// else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore |
224 |
if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())) |
218 |
// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919) |
225 |
throw e; |
219 |
} finally { |
226 |
// else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore |
220 |
if (unit != null) { |
227 |
// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919) |
221 |
unit.cleanUp(); |
228 |
} finally { |
222 |
} |
229 |
if (unit != null) { |
223 |
} |
230 |
unit.cleanUp(); |
224 |
} // else working copy not in a Java project |
231 |
} |
225 |
return this.ast; |
232 |
} |
226 |
} |
233 |
return this.ast; |
227 |
return null; |
|
|
228 |
} |
234 |
} |
|
|
235 |
|
229 |
private void notifyParticipants(final CompilationUnit workingCopy) { |
236 |
private void notifyParticipants(final CompilationUnit workingCopy) { |
230 |
IJavaProject javaProject = getWorkingCopy().getJavaProject(); |
237 |
IJavaProject javaProject = getWorkingCopy().getJavaProject(); |
231 |
CompilationParticipant[] participants = JavaModelManager.getJavaModelManager().compilationParticipants.getCompilationParticipants(javaProject); |
238 |
CompilationParticipant[] participants = JavaModelManager.getJavaModelManager().compilationParticipants.getCompilationParticipants(javaProject); |