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 (-8 / +16 lines)
Lines 592-610 Link Here
592
		this.deltaListener.getCompilationUnitAST(this.workingCopy));
592
		this.deltaListener.getCompilationUnitAST(this.workingCopy));
593
}
593
}
594
/*
594
/*
595
 * Ensures that the AST broadcasted during a reconcile operation is correct.
595
 * Ensures that no AST is broadcasted during a reconcile operation if the working copy being reconciled 
596
 * (case of a working copy being reconciled with NO changes, creating AST and no problem detection)
596
 * has NO changes and NO problem detection is requested)
597
 */
597
 */
598
public void testBroadcastAST3() throws JavaModelException {
598
public void testBroadcastAST3() throws JavaModelException {
599
	this.workingCopy.reconcile(AST.JLS3, false/*don't force problem detection*/, null/*primary owner*/, null/*no progress*/);
599
	this.workingCopy.reconcile(AST.JLS3, false/*don't force problem detection*/, null/*primary owner*/, null/*no progress*/);
600
	assertASTNodeEquals(
600
	assertASTNodeEquals(
601
		"Unexpected ast",
601
		"Unexpected ast",
602
		"package p1;\n" +
602
		"null",
603
		"import p2.*;\n" +
604
		"public class X {\n" +
605
		"  public void foo(){\n" +
606
		"  }\n" +
607
		"}\n",
608
		this.deltaListener.getCompilationUnitAST(this.workingCopy));
603
		this.deltaListener.getCompilationUnitAST(this.workingCopy));
609
}
604
}
610
/*
605
/*
Lines 2260-2265 Link Here
2260
	);
2255
	);
2261
}
2256
}
2262
/*
2257
/*
2258
 * Ensures that the problem requestor is not called when the source
2259
 * to reconcile is the same as the current contents, 
2260
 * no ast is requested, no problem is requested and problem requestor is not active.
2261
 * (regression test for bug 179258 simple reconcile starts problem finder - main thread waiting)
2262
 * 
2263
 */
2264
public void testNoChanges3() throws JavaModelException {
2265
	setWorkingCopyContents(this.workingCopy.getSource());
2266
	this.problemRequestor.isActive = false;
2267
	this.workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
2268
	assertProblems("Unexpected problems", "");
2269
}
2270
/*
2263
 * Ensures that using a non-generic method with no parameter and with a raw receiver type doesn't create a type safety warning
2271
 * 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)
2272
 * (regression test for bug 105756 [1.5][model] Incorrect warning on using raw types)
2265
 */
2273
 */
(-)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 (-70 / +77 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,
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);

Return to bug 179258