View | Details | Raw Unified | Return to bug 179258 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/ReconcilerTests.java (+13 lines)
Lines 2260-2265 Link Here
2260
	);
2260
	);
2261
}
2261
}
2262
/*
2262
/*
2263
 * Ensures that the problem requestor is not called when the source
2264
 * to reconcile is the same as the current contents, 
2265
 * no ast is requested, no problem is requested and problem requestor is not active.
2266
 * (regression test for bug 179258 simple reconcile starts problem finder - main thread waiting)
2267
 * 
2268
 */
2269
public void testNoChanges3() throws JavaModelException {
2270
	setWorkingCopyContents(this.workingCopy.getSource());
2271
	this.problemRequestor.isActive = false;
2272
	this.workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
2273
	assertProblems("Unexpected problems", "");
2274
}
2275
/*
2263
 * Ensures that using a non-generic method with no parameter and with a raw receiver type doesn't create a type safety warning
2276
 * Ensures that using a non-generic method with no parameter and with a raw receiver type doesn't create a type safety warning
2264
 * (regression test for bug 105756 [1.5][model] Incorrect warning on using raw types)
2277
 * (regression test for bug 105756 [1.5][model] Incorrect warning on using raw types)
2265
 */
2278
 */
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (-1 / +2 lines)
Lines 70-75 Link Here
70
		public StringBuffer problems;
70
		public StringBuffer problems;
71
		public int problemCount;
71
		public int problemCount;
72
		protected char[] unitSource;
72
		protected char[] unitSource;
73
		public boolean isActive = true;
73
		public ProblemRequestor() {
74
		public ProblemRequestor() {
74
			initialize(null);
75
			initialize(null);
75
		}
76
		}
Lines 85-91 Link Here
85
				this.problems.append("----------\n");
86
				this.problems.append("----------\n");
86
		}
87
		}
87
		public boolean isActive() {
88
		public boolean isActive() {
88
			return true;
89
			return this.isActive;
89
		}
90
		}
90
		public void initialize(char[] source) {
91
		public void initialize(char[] source) {
91
			this.problems = new StringBuffer();
92
			this.problems = new StringBuffer();
(-)model/org/eclipse/jdt/core/compiler/ReconcileContext.java (-1 / +1 lines)
Lines 98-104 Link Here
98
		parser.setSource(workingCopy);
98
		parser.setSource(workingCopy);
99
		return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);		
99
		return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);		
100
	}
100
	}
101
	return this.operation.makeConsistent(this.workingCopy, null/*don't report problems to the working copy's problem requestor*/);
101
	return this.operation.makeConsistent(this.workingCopy);
102
}
102
}
103
103
104
/**
104
/**
(-)model/org/eclipse/jdt/internal/core/ReconcileWorkingCopyOperation.java (-67 / +82 lines)
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,
194
						this.workingCopyOwner,
195
						this.problems,
196
						this.astLevel != ICompilationUnit.NO_AST/*creating AST if level is not NO_AST */,
197
						reconcileFlags,
198
						this.progressMonitor);
199
				if (this.progressMonitor != null) this.progressMonitor.worked(1);
200
			}
201
			
202
			// create AST if needed
203
			if (this.astLevel != ICompilationUnit.NO_AST) {
204
				Map options = workingCopy.getJavaProject().getOptions(true);
205
				if (unit == null) { 
206
					// problem detection not forced or non-Java project -> no bindings
207
					ASTParser parser = ASTParser.newParser(this.astLevel);
208
					parser.setCompilerOptions(options);
209
					parser.setStatementsRecovery((this.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
210
					parser.setSource(workingCopy);
211
					this.ast = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.progressMonitor);		
212
				} else {
213
					// convert AST
214
					this.ast =
215
						AST.convertCompilationUnit(
216
							this.astLevel,
217
							unit,
187
							contents,
218
							contents,
188
							this.workingCopyOwner,
219
							options,
189
							problemMap,
220
							this.resolveBindings,
190
							this.astLevel != ICompilationUnit.NO_AST/*creating AST if level is not NO_AST */,
221
							workingCopy,
191
							reconcileFlags,
222
							reconcileFlags,
192
							this.progressMonitor);
223
							this.progressMonitor);
193
					if (this.progressMonitor != null) this.progressMonitor.worked(1);
224
				}
194
225
				if (this.ast != null) {
195
					// create AST if needed
226
					this.deltaBuilder.delta = new JavaElementDelta(workingCopy);
196
					if (this.astLevel != ICompilationUnit.NO_AST && unit != null) {
227
					this.deltaBuilder.delta.changedAST(this.ast);
197
						Map options = workingCopy.getJavaProject().getOptions(true);
228
				}
198
						this.ast =
229
				if (this.progressMonitor != null) this.progressMonitor.worked(1);
199
							AST.convertCompilationUnit(
230
			}
200
								this.astLevel,
231
	    } catch (JavaModelException e) {
201
								unit,
232
	    	if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()))
202
								contents,
233
	    		throw e;
203
								options,
234
	    	// else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore
204
								true/*isResolved*/,
235
	    	// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919)
205
								workingCopy,
236
	    } finally {
206
								reconcileFlags,
237
	        if (unit != null) {
207
								this.progressMonitor);
238
	            unit.cleanUp();
208
						if (this.ast != null) {
239
	        }
209
							this.deltaBuilder.delta = new JavaElementDelta(workingCopy);
240
	    }
210
							this.deltaBuilder.delta.changedAST(this.ast);
241
		return this.ast;
211
						}
212
						if (this.progressMonitor != null) this.progressMonitor.worked(1);
213
					}
214
			    } catch (JavaModelException e) {
215
			    	if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()))
216
			    		throw e;
217
			    	// else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore
218
			    	// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919)
219
			    } finally {
220
			        if (unit != null) {
221
			            unit.cleanUp();
222
			        }
223
			    }
224
			} // else working copy not in a Java project
225
			return this.ast;
226
		}
227
		return null;
228
	}
242
	}
243
	
229
	private void notifyParticipants(final CompilationUnit workingCopy) {
244
	private void notifyParticipants(final CompilationUnit workingCopy) {
230
		IJavaProject javaProject = getWorkingCopy().getJavaProject();
245
		IJavaProject javaProject = getWorkingCopy().getJavaProject();
231
		CompilationParticipant[] participants = JavaModelManager.getJavaModelManager().compilationParticipants.getCompilationParticipants(javaProject);
246
		CompilationParticipant[] participants = JavaModelManager.getJavaModelManager().compilationParticipants.getCompilationParticipants(javaProject);

Return to bug 179258