View | Details | Raw Unified | Return to bug 177174
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-2 / +4 lines)
Lines 879-885 Link Here
879
	this.variablesCounter = new int[30];
879
	this.variablesCounter = new int[30];
880
	
880
	
881
	// javadoc support
881
	// javadoc support
882
	this.javadocParser = new JavadocParser(this);
882
	this.javadocParser = createJavadocParser();
883
}
883
}
884
protected void annotationRecoveryCheckPoint(int start, int end) {
884
protected void annotationRecoveryCheckPoint(int start, int end) {
885
	if(this.lastCheckPoint > start && this.lastCheckPoint < end) {
885
	if(this.lastCheckPoint > start && this.lastCheckPoint < end) {
Lines 7808-7814 Link Here
7808
protected FieldDeclaration createFieldDeclaration(char[] fieldDeclarationName, int sourceStart, int sourceEnd) {
7808
protected FieldDeclaration createFieldDeclaration(char[] fieldDeclarationName, int sourceStart, int sourceEnd) {
7809
	return new FieldDeclaration(fieldDeclarationName, sourceStart, sourceEnd);
7809
	return new FieldDeclaration(fieldDeclarationName, sourceStart, sourceEnd);
7810
}
7810
}
7811
7811
protected JavadocParser createJavadocParser() {
7812
	return new JavadocParser(this);
7813
}
7812
protected LocalDeclaration createLocalDeclaration(char[] localDeclarationName, int sourceStart, int sourceEnd) {
7814
protected LocalDeclaration createLocalDeclaration(char[] localDeclarationName, int sourceStart, int sourceEnd) {
7813
	return new LocalDeclaration(localDeclarationName, sourceStart, sourceEnd);
7815
	return new LocalDeclaration(localDeclarationName, sourceStart, sourceEnd);
7814
}
7816
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/select/SelectionParser.java (-1 / +3 lines)
Lines 52-58 Link Here
52
	
52
	
53
public SelectionParser(ProblemReporter problemReporter) {
53
public SelectionParser(ProblemReporter problemReporter) {
54
	super(problemReporter);
54
	super(problemReporter);
55
	this.javadocParser = new SelectionJavadocParser(this);
56
	this.javadocParser.checkDocComment = true;
55
	this.javadocParser.checkDocComment = true;
57
}
56
}
58
public char[] assistIdentifier(){
57
public char[] assistIdentifier(){
Lines 968-973 Link Here
968
public ImportReference createAssistPackageReference(char[][] tokens, long[] positions){
967
public ImportReference createAssistPackageReference(char[][] tokens, long[] positions){
969
	return new SelectionOnPackageReference(tokens, positions);
968
	return new SelectionOnPackageReference(tokens, positions);
970
}
969
}
970
protected JavadocParser createJavadocParser() {
971
	return new SelectionJavadocParser(this);
972
}
971
protected LocalDeclaration createLocalDeclaration(char[] assistName,int sourceStart,int sourceEnd) {
973
protected LocalDeclaration createLocalDeclaration(char[] assistName,int sourceStart,int sourceEnd) {
972
	if (this.indexOfAssistIdentifier() < 0) {
974
	if (this.indexOfAssistIdentifier() < 0) {
973
		return super.createLocalDeclaration(assistName, sourceStart, sourceEnd);
975
		return super.createLocalDeclaration(assistName, sourceStart, sourceEnd);
(-)codeassist/org/eclipse/jdt/internal/codeassist/UnresolvedReferenceNameFinder.java (-99 / +95 lines)
Lines 34-40 Link Here
34
34
35
public class UnresolvedReferenceNameFinder extends ASTVisitor {
35
public class UnresolvedReferenceNameFinder extends ASTVisitor {
36
	private static final int MAX_LINE_COUNT = 100;
36
	private static final int MAX_LINE_COUNT = 100;
37
	private static final int FAKE_BLOCKS_COUNT = 50;
37
	private static final int FAKE_BLOCKS_COUNT = 20;
38
	
38
	
39
	public static interface UnresolvedReferenceNameRequestor {
39
	public static interface UnresolvedReferenceNameRequestor {
40
		public void acceptName(char[] name);
40
		public void acceptName(char[] name);
Lines 42-47 Link Here
42
	
42
	
43
	private UnresolvedReferenceNameRequestor requestor;
43
	private UnresolvedReferenceNameRequestor requestor;
44
	
44
	
45
	private CompletionEngine completionEngine;
45
	private CompletionParser parser;
46
	private CompletionParser parser;
46
	private CompletionScanner completionScanner;
47
	private CompletionScanner completionScanner;
47
	
48
	
Lines 55-60 Link Here
55
	private SimpleSetOfCharArray acceptedNames = new SimpleSetOfCharArray();
56
	private SimpleSetOfCharArray acceptedNames = new SimpleSetOfCharArray();
56
	
57
	
57
	public UnresolvedReferenceNameFinder(CompletionEngine completionEngine) {
58
	public UnresolvedReferenceNameFinder(CompletionEngine completionEngine) {
59
		this.completionEngine = completionEngine;
58
		this.parser = completionEngine.parser;
60
		this.parser = completionEngine.parser;
59
		this.completionScanner = (CompletionScanner) parser.scanner;
61
		this.completionScanner = (CompletionScanner) parser.scanner;
60
	} 
62
	} 
Lines 62-67 Link Here
62
	private void acceptName(char[] name) {
64
	private void acceptName(char[] name) {
63
		// the null check is added to fix bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=166570
65
		// the null check is added to fix bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=166570
64
		if (name == null) return;
66
		if (name == null) return;
67
						
68
		if (!CharOperation.prefixEquals(this.completionEngine.completionToken, name, false /* ignore case */)
69
				&& !(this.completionEngine.options.camelCaseMatch && CharOperation.camelCaseMatch(this.completionEngine.completionToken, name))) return;
65
		
70
		
66
		if (acceptedNames.includes(name)) return;
71
		if (acceptedNames.includes(name)) return;
67
		
72
		
Lines 71-88 Link Here
71
		this.requestor.acceptName(name);
76
		this.requestor.acceptName(name);
72
	}
77
	}
73
	
78
	
74
	public void find(char[] startWith, Initializer initializer, ClassScope scope, int from, UnresolvedReferenceNameRequestor nameRequestor) {
79
	public void find(
75
		MethodDeclaration fakeMethod = this.findAfter(startWith, scope, from, initializer.bodyEnd, MAX_LINE_COUNT, false, nameRequestor);
80
			char[] startWith,
81
			Initializer initializer,
82
			ClassScope scope,
83
			int from,
84
			char[][] discouragedNames,
85
			UnresolvedReferenceNameRequestor nameRequestor) {
86
		MethodDeclaration fakeMethod = 
87
			this.findAfter(startWith, scope, from, initializer.bodyEnd, MAX_LINE_COUNT, false, discouragedNames, nameRequestor);
76
		if (fakeMethod != null) fakeMethod.traverse(this, scope);
88
		if (fakeMethod != null) fakeMethod.traverse(this, scope);
77
	}
89
	}
78
	
90
	
79
	public void find(char[] startWith, AbstractMethodDeclaration methodDeclaration, int from, UnresolvedReferenceNameRequestor nameRequestor) {
91
	public void find(
80
		MethodDeclaration fakeMethod = this.findAfter(startWith, methodDeclaration.scope, from, methodDeclaration.bodyEnd, MAX_LINE_COUNT, false, nameRequestor);
92
			char[] startWith,
93
			AbstractMethodDeclaration methodDeclaration,
94
			int from,
95
			char[][] discouragedNames,
96
			UnresolvedReferenceNameRequestor nameRequestor) {
97
		MethodDeclaration fakeMethod = 
98
			this.findAfter(startWith, methodDeclaration.scope, from, methodDeclaration.bodyEnd, MAX_LINE_COUNT, false, discouragedNames, nameRequestor);
81
		if (fakeMethod != null) fakeMethod.traverse(this, methodDeclaration.scope.classScope());
99
		if (fakeMethod != null) fakeMethod.traverse(this, methodDeclaration.scope.classScope());
82
	}
100
	}
83
	
101
	
84
	public void findAfter(char[] startWith, Scope scope, ClassScope classScope, int from, int to, UnresolvedReferenceNameRequestor nameRequestor) {
102
	public void findAfter(
85
		MethodDeclaration fakeMethod = this.findAfter(startWith, scope, from, to, MAX_LINE_COUNT / 2, true, nameRequestor);
103
			char[] startWith,
104
			Scope scope,
105
			ClassScope classScope,
106
			int from,
107
			int to,
108
			char[][] discouragedNames,
109
			UnresolvedReferenceNameRequestor nameRequestor) {
110
		MethodDeclaration fakeMethod =
111
			this.findAfter(startWith, scope, from, to, MAX_LINE_COUNT / 2, true, discouragedNames, nameRequestor);
86
		if (fakeMethod != null) fakeMethod.traverse(this, classScope);
112
		if (fakeMethod != null) fakeMethod.traverse(this, classScope);
87
	}
113
	}
88
	
114
	
Lines 93-107 Link Here
93
			int to,
119
			int to,
94
			int maxLineCount,
120
			int maxLineCount,
95
			boolean outsideEnclosingBlock,
121
			boolean outsideEnclosingBlock,
122
			char[][] discouragedNames,
96
			UnresolvedReferenceNameRequestor nameRequestor) {
123
			UnresolvedReferenceNameRequestor nameRequestor) {
97
		this.requestor = nameRequestor;
124
		this.requestor = nameRequestor;
98
		
125
		
99
		// reinitialize completion scanner to be usable as a normal scanner
126
		// reinitialize completion scanner to be usable as a normal scanner
100
		this.completionScanner.cursorLocation = 0;
127
		this.completionScanner.cursorLocation = 0;
101
		
128
		
102
		// reinitialize completionIdentifier
103
		this.completionScanner.prefix = startWith;
104
		
105
		if (!outsideEnclosingBlock) {
129
		if (!outsideEnclosingBlock) {
106
			// compute location of the end of the current block
130
			// compute location of the end of the current block
107
			this.completionScanner.resetTo(from + 1, to);
131
			this.completionScanner.resetTo(from + 1, to);
Lines 121-127 Link Here
121
			end = maxEnd < to ? maxEnd : to;
145
			end = maxEnd < to ? maxEnd : to;
122
		}
146
		}
123
		
147
		
124
		this.completionScanner.startRecordingIdentifiers();
148
		this.parser.startRecordingIdentifiers(from, end);
125
		
149
		
126
		MethodDeclaration fakeMethod = this.parser.parseSomeStatements(
150
		MethodDeclaration fakeMethod = this.parser.parseSomeStatements(
127
				from,
151
				from,
Lines 129-137 Link Here
129
				outsideEnclosingBlock ? FAKE_BLOCKS_COUNT : 0,
153
				outsideEnclosingBlock ? FAKE_BLOCKS_COUNT : 0,
130
				s.compilationUnitScope().referenceContext);
154
				s.compilationUnitScope().referenceContext);
131
		
155
		
132
		this.completionScanner.stopRecordingIdentifiers();
156
		this.parser.stopRecordingIdentifiers();
133
		
157
		
134
		if(!this.initPotentialNamesTables()) return null;
158
		if(!this.initPotentialNamesTables(discouragedNames)) return null;
135
		
159
		
136
		this.parentsPtr = -1;
160
		this.parentsPtr = -1;
137
		this.parents = new ASTNode[10];
161
		this.parents = new ASTNode[10];
Lines 139-146 Link Here
139
		return fakeMethod;
163
		return fakeMethod;
140
	}
164
	}
141
	
165
	
142
	public void findBefore(char[] startWith, Scope scope, ClassScope classScope, int from, int to, UnresolvedReferenceNameRequestor nameRequestor) {
166
	public void findBefore(
143
		MethodDeclaration fakeMethod = this.findBefore(startWith, scope, from, to, MAX_LINE_COUNT / 2, nameRequestor);
167
			char[] startWith,
168
			Scope scope,
169
			ClassScope classScope,
170
			int from,
171
			int recordTo,
172
			int parseTo,
173
			char[][] discouragedNames,
174
			UnresolvedReferenceNameRequestor nameRequestor) {
175
		MethodDeclaration fakeMethod =
176
			this.findBefore(startWith, scope, from, recordTo, parseTo, MAX_LINE_COUNT / 2, discouragedNames, nameRequestor);
144
		if (fakeMethod != null) fakeMethod.traverse(this, classScope);
177
		if (fakeMethod != null) fakeMethod.traverse(this, classScope);
145
	}
178
	}
146
	
179
	
Lines 148-167 Link Here
148
			char[] startWith,
181
			char[] startWith,
149
			Scope s,
182
			Scope s,
150
			int from,
183
			int from,
151
			int to,
184
			int recordTo,
185
			int parseTo,
152
			int maxLineCount,
186
			int maxLineCount,
187
			char[][] discouragedNames,
153
			UnresolvedReferenceNameRequestor nameRequestor) {
188
			UnresolvedReferenceNameRequestor nameRequestor) {
154
		this.requestor = nameRequestor;
189
		this.requestor = nameRequestor;
155
		
190
		
156
		// reinitialize completion scanner to be usable as a normal scanner
191
		// reinitialize completion scanner to be usable as a normal scanner
157
		this.completionScanner.cursorLocation = 0;
192
		this.completionScanner.cursorLocation = 0;
158
		
193
		
159
		// reinitialize completionIdentifier
160
		this.completionScanner.prefix = startWith;
161
		
162
		int minStart =
194
		int minStart =
163
			this.completionScanner.getLineStart(
195
			this.completionScanner.getLineStart(
164
					Util.getLineNumber(to, this.completionScanner.lineEnds, 0, this.completionScanner.linePtr) - maxLineCount);
196
					Util.getLineNumber(recordTo, this.completionScanner.lineEnds, 0, this.completionScanner.linePtr) - maxLineCount);
165
		
197
		
166
		int start;
198
		int start;
167
		int fakeBlocksCount;
199
		int fakeBlocksCount;
Lines 173-189 Link Here
173
			fakeBlocksCount = FAKE_BLOCKS_COUNT;
205
			fakeBlocksCount = FAKE_BLOCKS_COUNT;
174
		}
206
		}
175
		
207
		
176
		this.completionScanner.startRecordingIdentifiers();
208
		this.parser.startRecordingIdentifiers(start, recordTo);
177
		
209
		
178
		MethodDeclaration fakeMethod = this.parser.parseSomeStatements(
210
		MethodDeclaration fakeMethod = this.parser.parseSomeStatements(
179
				start,
211
				start,
180
				to,
212
				parseTo,
181
				fakeBlocksCount,
213
				fakeBlocksCount,
182
				s.compilationUnitScope().referenceContext);
214
				s.compilationUnitScope().referenceContext);
183
		
215
		
184
		this.completionScanner.stopRecordingIdentifiers();
216
		this.parser.stopRecordingIdentifiers();
185
		
217
		
186
		if(!this.initPotentialNamesTables()) return null;
218
		if(!this.initPotentialNamesTables(discouragedNames)) return null;
187
		
219
		
188
		this.parentsPtr = -1;
220
		this.parentsPtr = -1;
189
		this.parents = new ASTNode[10];
221
		this.parents = new ASTNode[10];
Lines 191-237 Link Here
191
		return fakeMethod;
223
		return fakeMethod;
192
	}
224
	}
193
	
225
	
194
	private boolean initPotentialNamesTables() {
226
	private boolean initPotentialNamesTables(char[][] discouragedNames) {
195
		char[][] pvns = this.completionScanner.potentialVariableNames;
227
		char[][] pvns = this.parser.potentialVariableNames;
196
		int[] pvnss = this.completionScanner.potentialVariableNameStarts;
228
		int[] pvnss = this.parser.potentialVariableNameStarts;
197
		int pvnsPtr = this.completionScanner.potentialVariableNamesPtr;
229
		int pvnsPtr = this.parser.potentialVariableNamesPtr;
198
		
230
		
199
		if (pvnsPtr < 0) return false; // there is no potential names
231
		if (pvnsPtr < 0) return false; // there is no potential names
200
		
232
		
201
		// remove null
233
		// remove null and discouragedNames
234
		int discouragedNamesCount = discouragedNames == null ? 0 : discouragedNames.length;
202
		int j = -1;
235
		int j = -1;
203
		for (int i = 0; i <= pvnsPtr; i++) {
236
		next : for (int i = 0; i <= pvnsPtr; i++) {
204
			if (pvns[i] != null) {
237
			char[] temp = pvns[i];
205
				char[] temp = pvns[i];
206
				pvns[i] = null;
207
				pvns[++j] = temp;
208
				pvnss[j] = pvnss[i];
209
				
210
			}
211
		}
212
		pvnsPtr = j;
213
		
214
		if (pvnsPtr < 0) return false; // there is no potential names
215
		
216
		if (pvnsPtr > 0) {
217
			// sort by position
218
			quickSort(pvnss, pvns, 0, pvnsPtr);
219
			
238
			
220
			// remove double
239
			if (temp == null) continue next;
221
			j = 0;
240
			
222
			for (int i = 1; i <= pvnsPtr; i++) {
241
			for (int k = 0; k < discouragedNamesCount; k++) {
223
				if (pvnss[i] != pvnss[j]) {
242
				if (CharOperation.equals(temp, discouragedNames[k], false)) {
224
					char[] temp = pvns[i];
243
					continue next;
225
					pvns[i] = null;
226
					pvns[++j] = temp;
227
					pvnss[j] = pvnss[i];
228
				} else {
229
					pvns[i] = null;
230
				}
244
				}
231
			}
245
			}
232
			
246
			
233
			pvnsPtr = j;
247
			pvns[i] = null;
248
			pvns[++j] = temp;
249
			pvnss[j] = pvnss[i];
234
		}
250
		}
251
		pvnsPtr = j;
252
		
253
		if (pvnsPtr < 0) return false; // there is no potential names
235
		
254
		
236
		this.potentialVariableNames = pvns;
255
		this.potentialVariableNames = pvns;
237
		this.potentialVariableNameStarts = pvnss;
256
		this.potentialVariableNameStarts = pvnss;
Lines 240-277 Link Here
240
		return true;
259
		return true;
241
	}
260
	}
242
	
261
	
243
	private static void quickSort(int[] list1, char[][] list2, int left, int right) {
244
		int original_left= left;
245
		int original_right= right;
246
		int mid= list1[left + (right - left) / 2];
247
		do {
248
			while (list1[left] < mid) {
249
				left++;
250
			}
251
			while (mid < list1[right]) {
252
				right--;
253
			}
254
			if (left <= right) {
255
				int tmp1= list1[left];
256
				list1[left]= list1[right];
257
				list1[right]= tmp1;
258
				
259
				char[] tmp2= list2[left];
260
				list2[left]= list2[right];
261
				list2[right]= tmp2;
262
				
263
				left++;
264
				right--;
265
			}
266
		} while (left <= right);
267
		if (original_left < right) {
268
			quickSort(list1, list2, original_left, right);
269
		}
270
		if (left < original_right) {
271
			quickSort(list1, list2, left, original_right);
272
		}
273
	}
274
	
275
	private void popParent() {
262
	private void popParent() {
276
		this.parentsPtr--;
263
		this.parentsPtr--;
277
	}
264
	}
Lines 302-312 Link Here
302
	} 
289
	} 
303
	
290
	
304
	public boolean visit(Block block, BlockScope blockScope) {
291
	public boolean visit(Block block, BlockScope blockScope) {
292
		ASTNode enclosingDeclaration = getEnclosingDeclaration();
293
		removeLocals(block.statements, enclosingDeclaration.sourceStart, block.sourceEnd);
305
		pushParent(block);
294
		pushParent(block);
306
		return true;
295
		return true;
307
	}
296
	}
308
	
297
	
309
	public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope classScope) {
298
	public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope classScope) {
299
		if (!constructorDeclaration.isDefaultConstructor && !constructorDeclaration.isClinit()) {
300
			removeLocals(
301
					constructorDeclaration.arguments,
302
					constructorDeclaration.declarationSourceStart,
303
					constructorDeclaration.declarationSourceEnd);
304
			removeLocals(
305
					constructorDeclaration.statements,
306
					constructorDeclaration.declarationSourceStart,
307
					constructorDeclaration.declarationSourceEnd);
308
		}
310
		pushParent(constructorDeclaration);
309
		pushParent(constructorDeclaration);
311
		return true;
310
		return true;
312
	}
311
	}
Lines 322-327 Link Here
322
	}
321
	}
323
	
322
	
324
	public boolean visit(MethodDeclaration methodDeclaration, ClassScope classScope) {
323
	public boolean visit(MethodDeclaration methodDeclaration, ClassScope classScope) {
324
		removeLocals(
325
				methodDeclaration.arguments,
326
				methodDeclaration.declarationSourceStart,
327
				methodDeclaration.declarationSourceEnd);
328
		removeLocals(
329
				methodDeclaration.statements,
330
				methodDeclaration.declarationSourceStart,
331
				methodDeclaration.declarationSourceEnd);
325
		pushParent(methodDeclaration);
332
		pushParent(methodDeclaration);
326
		return true;
333
		return true;
327
	}
334
	}
Lines 339-346 Link Here
339
	}
346
	}
340
	
347
	
341
	public void endVisit(Block block, BlockScope blockScope) {
348
	public void endVisit(Block block, BlockScope blockScope) {
342
		ASTNode enclosingDeclaration = getEnclosingDeclaration();
343
		removeLocals(block.statements, enclosingDeclaration.sourceStart, block.sourceEnd);
344
		popParent();
349
		popParent();
345
	}
350
	}
346
	
351
	
Lines 375-388 Link Here
375
	}
380
	}
376
	
381
	
377
	public void endVisit(MethodDeclaration methodDeclaration, ClassScope classScope) {
382
	public void endVisit(MethodDeclaration methodDeclaration, ClassScope classScope) {
378
		removeLocals(
379
				methodDeclaration.arguments,
380
				methodDeclaration.declarationSourceStart,
381
				methodDeclaration.declarationSourceEnd);
382
		removeLocals(
383
				methodDeclaration.statements,
384
				methodDeclaration.declarationSourceStart,
385
				methodDeclaration.declarationSourceEnd);
386
		endVisitPreserved(
383
		endVisitPreserved(
387
				methodDeclaration.bodyStart,
384
				methodDeclaration.bodyStart,
388
				methodDeclaration.bodyEnd);
385
				methodDeclaration.bodyEnd);
Lines 390-396 Link Here
390
	}
387
	}
391
	
388
	
392
	public void endVisit(TypeDeclaration typeDeclaration, BlockScope blockScope) {
389
	public void endVisit(TypeDeclaration typeDeclaration, BlockScope blockScope) {
393
		removeFields(typeDeclaration);
394
		endVisitRemoved(typeDeclaration.sourceStart, typeDeclaration.declarationSourceEnd);
390
		endVisitRemoved(typeDeclaration.sourceStart, typeDeclaration.declarationSourceEnd);
395
		popParent();
391
		popParent();
396
	}
392
	}
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-77 / +50 lines)
Lines 220-225 Link Here
220
	private final static char[] ON_DEMAND = ".*".toCharArray();  //$NON-NLS-1$
220
	private final static char[] ON_DEMAND = ".*".toCharArray();  //$NON-NLS-1$
221
	private final static char[] IMPORT_END = ";\n".toCharArray();  //$NON-NLS-1$
221
	private final static char[] IMPORT_END = ";\n".toCharArray();  //$NON-NLS-1$
222
	
222
	
223
	private final static char[] JAVA_LANG_OBJECT_SIGNATURE = 
224
		createTypeSignature(CharOperation.concatWith(JAVA_LANG, '.'), OBJECT);
225
	private final static char[] JAVA_LANG_NAME =
226
		CharOperation.concatWith(JAVA_LANG, '.');
227
	
223
	private final static int NONE = 0;
228
	private final static int NONE = 0;
224
	private final static int SUPERTYPE = 1;
229
	private final static int SUPERTYPE = 1;
225
	private final static int SUBTYPE = 2;
230
	private final static int SUBTYPE = 2;
Lines 629-634 Link Here
629
		}
634
		}
630
		this.acceptedTypes = null; // reset
635
		this.acceptedTypes = null; // reset
631
	}
636
	}
637
	
638
	public void acceptUnresolvedName(char[] name) {
639
		int relevance = computeBaseRelevance();
640
		relevance += computeRelevanceForResolution(false);
641
		relevance += computeRelevanceForInterestingProposal();
642
		relevance += computeRelevanceForCaseMatching(completionToken, name);
643
		relevance += computeRelevanceForQualification(false);
644
		relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for local variable
645
		CompletionEngine.this.noProposal = false;
646
		if(!CompletionEngine.this.requestor.isIgnored(CompletionProposal.LOCAL_VARIABLE_REF)) {
647
			CompletionProposal proposal = CompletionEngine.this.createProposal(CompletionProposal.LOCAL_VARIABLE_REF, CompletionEngine.this.actualCompletionPosition);
648
			proposal.setSignature(JAVA_LANG_OBJECT_SIGNATURE);
649
			proposal.setPackageName(JAVA_LANG_NAME);
650
			proposal.setTypeName(OBJECT);
651
			proposal.setName(name);
652
			proposal.setCompletion(name);
653
			proposal.setFlags(Flags.AccDefault);
654
			proposal.setReplaceRange(CompletionEngine.this.startPosition - CompletionEngine.this.offset, CompletionEngine.this.endPosition - CompletionEngine.this.offset);
655
			proposal.setRelevance(relevance);
656
			CompletionEngine.this.requestor.accept(proposal);
657
			if(DEBUG) {
658
				CompletionEngine.this.printDebug(proposal);
659
			}
660
		}
661
	}
632
662
633
	// this code is derived from MethodBinding#areParametersCompatibleWith(TypeBinding[])
663
	// this code is derived from MethodBinding#areParametersCompatibleWith(TypeBinding[])
634
	private final boolean areParametersCompatibleWith(TypeBinding[] parameters, TypeBinding[] arguments, boolean isVarargs) {
664
	private final boolean areParametersCompatibleWith(TypeBinding[] parameters, TypeBinding[] arguments, boolean isVarargs) {
Lines 892-898 Link Here
892
					char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, singleNameReference);
922
					char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, singleNameReference);
893
					
923
					
894
					findUnresolvedReference(
924
					findUnresolvedReference(
895
							singleNameReference.sourceStart - 1,
925
							singleNameReference.sourceStart,
896
							singleNameReference.sourceEnd,
926
							singleNameReference.sourceEnd,
897
							(BlockScope)scope,
927
							(BlockScope)scope,
898
							alreadyDefinedName);
928
							alreadyDefinedName);
Lines 1449-1455 Link Here
1449
							char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, FakeInvocationSite);
1479
							char[][] alreadyDefinedName = computeAlreadyDefinedName((BlockScope)scope, FakeInvocationSite);
1450
							
1480
							
1451
							findUnresolvedReference(
1481
							findUnresolvedReference(
1452
									memberValuePair.sourceStart - 1,
1482
									memberValuePair.sourceStart,
1453
									memberValuePair.sourceEnd,
1483
									memberValuePair.sourceEnd,
1454
									(BlockScope)scope,
1484
									(BlockScope)scope,
1455
									alreadyDefinedName);
1485
									alreadyDefinedName);
Lines 7111-7126 Link Here
7111
				type.resolvedType != null &&
7141
				type.resolvedType != null &&
7112
				type.resolvedType.problemId() == ProblemReasons.NoError){
7142
				type.resolvedType.problemId() == ProblemReasons.NoError){
7113
			
7143
			
7114
			final int discouragedNamesCount = discouragedNames == null ? 0 : discouragedNames.length;
7115
			final ArrayList proposedNames = new ArrayList();
7144
			final ArrayList proposedNames = new ArrayList();
7116
			
7145
			
7117
			UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor nameRequestor = 
7146
			UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor nameRequestor = 
7118
				new UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor() {
7147
				new UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor() {
7119
					public void acceptName(char[] name) {
7148
					public void acceptName(char[] name) {
7120
						for (int i = 0; i < discouragedNamesCount; i++) {
7121
							if (CharOperation.equals(discouragedNames[i], name, false)) return;
7122
						}
7123
						
7124
						int relevance = computeBaseRelevance();
7149
						int relevance = computeBaseRelevance();
7125
						relevance += computeRelevanceForInterestingProposal();
7150
						relevance += computeRelevanceForInterestingProposal();
7126
						relevance += computeRelevanceForCaseMatching(completionToken, name);
7151
						relevance += computeRelevanceForCaseMatching(completionToken, name);
Lines 7159-7164 Link Here
7159
						completionToken,
7184
						completionToken,
7160
						md,
7185
						md,
7161
						variable.declarationSourceEnd + 1,
7186
						variable.declarationSourceEnd + 1,
7187
						discouragedNames,
7162
						nameRequestor);
7188
						nameRequestor);
7163
			} else if (referenceContext instanceof TypeDeclaration) {
7189
			} else if (referenceContext instanceof TypeDeclaration) {
7164
				TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
7190
				TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
Lines 7175-7180 Link Here
7175
										initializer,
7201
										initializer,
7176
										typeDeclaration.scope,
7202
										typeDeclaration.scope,
7177
										variable.declarationSourceEnd + 1,
7203
										variable.declarationSourceEnd + 1,
7204
										discouragedNames,
7178
										nameRequestor);
7205
										nameRequestor);
7179
								break done;
7206
								break done;
7180
							}
7207
							}
Lines 7193-7234 Link Here
7193
	}
7220
	}
7194
	
7221
	
7195
	private char[][] findUnresolvedReferenceAfter(int from, BlockScope scope, final char[][] discouragedNames) {
7222
	private char[][] findUnresolvedReferenceAfter(int from, BlockScope scope, final char[][] discouragedNames) {
7196
		final int discouragedNamesCount = discouragedNames == null ? 0 : discouragedNames.length;
7197
		final ArrayList proposedNames = new ArrayList();
7223
		final ArrayList proposedNames = new ArrayList();
7198
		
7224
		
7199
		UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor nameRequestor = 
7225
		UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor nameRequestor = 
7200
			new UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor() {
7226
			new UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor() {
7201
				public void acceptName(char[] name) {
7227
				public void acceptName(char[] name) {
7202
					for (int i = 0; i < discouragedNamesCount; i++) {
7228
					CompletionEngine.this.acceptUnresolvedName(name);
7203
						if (CharOperation.equals(discouragedNames[i], name, false)) return;
7204
					}
7205
					
7206
					int relevance = computeBaseRelevance();
7207
					relevance += computeRelevanceForResolution(false);
7208
					relevance += computeRelevanceForInterestingProposal();
7209
					relevance += computeRelevanceForCaseMatching(completionToken, name);
7210
					relevance += computeRelevanceForQualification(false);
7211
					relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for local variable
7212
					CompletionEngine.this.noProposal = false;
7213
					if(!CompletionEngine.this.requestor.isIgnored(CompletionProposal.LOCAL_VARIABLE_REF)) {
7214
						CompletionProposal proposal = CompletionEngine.this.createProposal(CompletionProposal.LOCAL_VARIABLE_REF, CompletionEngine.this.actualCompletionPosition);
7215
						proposal.setSignature(
7216
							createTypeSignature(
7217
									CharOperation.concatWith(JAVA_LANG, '.'),
7218
									OBJECT));
7219
						proposal.setPackageName(CharOperation.concatWith(JAVA_LANG, '.'));
7220
						proposal.setTypeName(OBJECT);
7221
						proposal.setName(name);
7222
						proposal.setCompletion(name);
7223
						proposal.setFlags(Flags.AccDefault);
7224
						proposal.setReplaceRange(CompletionEngine.this.startPosition - CompletionEngine.this.offset, CompletionEngine.this.endPosition - CompletionEngine.this.offset);
7225
						proposal.setRelevance(relevance);
7226
						CompletionEngine.this.requestor.accept(proposal);
7227
						if(DEBUG) {
7228
							CompletionEngine.this.printDebug(proposal);
7229
						}
7230
					}
7231
					
7232
					proposedNames.add(name);
7229
					proposedNames.add(name);
7233
				}
7230
				}
7234
			};
7231
			};
Lines 7244-7249 Link Here
7244
					md.scope.classScope(),
7241
					md.scope.classScope(),
7245
					from,
7242
					from,
7246
					md.bodyEnd,
7243
					md.bodyEnd,
7244
					discouragedNames,
7247
					nameRequestor);
7245
					nameRequestor);
7248
		} else if (referenceContext instanceof TypeDeclaration) {
7246
		} else if (referenceContext instanceof TypeDeclaration) {
7249
			TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
7247
			TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
Lines 7261-7266 Link Here
7261
										typeDeclaration.scope,
7259
										typeDeclaration.scope,
7262
										from,
7260
										from,
7263
										initializer.bodyEnd,
7261
										initializer.bodyEnd,
7262
										discouragedNames,
7264
										nameRequestor);
7263
										nameRequestor);
7265
							break done;
7264
							break done;
7266
						}
7265
						}
Lines 7277-7284 Link Here
7277
		return null;
7276
		return null;
7278
	}
7277
	}
7279
	
7278
	
7280
	private void findUnresolvedReference(int beforeIndex, int afterIndex, BlockScope scope, char[][] discouragedNames) {
7279
	private void findUnresolvedReference(int completedNameStart, int completedNameEnd, BlockScope scope, char[][] discouragedNames) {
7281
		char[][] foundNames = findUnresolvedReferenceBefore(beforeIndex, scope, discouragedNames);
7280
		char[][] foundNames = findUnresolvedReferenceBefore(completedNameStart - 1, completedNameEnd, scope, discouragedNames);
7282
		if (foundNames != null && foundNames.length > 1) {
7281
		if (foundNames != null && foundNames.length > 1) {
7283
			int discouragedNamesLength = discouragedNames.length;
7282
			int discouragedNamesLength = discouragedNames.length;
7284
			int foundNamesLength = foundNames.length;
7283
			int foundNamesLength = foundNames.length;
Lines 7286-7331 Link Here
7286
			System.arraycopy(discouragedNames, 0, discouragedNames = new char[newLength][], 0, discouragedNamesLength);
7285
			System.arraycopy(discouragedNames, 0, discouragedNames = new char[newLength][], 0, discouragedNamesLength);
7287
			System.arraycopy(foundNames, 0, discouragedNames, discouragedNamesLength, foundNamesLength);
7286
			System.arraycopy(foundNames, 0, discouragedNames, discouragedNamesLength, foundNamesLength);
7288
		}
7287
		}
7289
		findUnresolvedReferenceAfter(afterIndex, scope, discouragedNames);
7288
		findUnresolvedReferenceAfter(completedNameEnd + 1, scope, discouragedNames);
7290
	}
7289
	}
7291
	
7290
	
7292
	private char[][] findUnresolvedReferenceBefore(int to, BlockScope scope, final char[][] discouragedNames) {
7291
	private char[][] findUnresolvedReferenceBefore(int recordTo, int parseTo, BlockScope scope, final char[][] discouragedNames) {
7293
		final int discouragedNamesCount = discouragedNames == null ? 0 : discouragedNames.length;
7294
		final ArrayList proposedNames = new ArrayList();
7292
		final ArrayList proposedNames = new ArrayList();
7295
		
7293
		
7296
		UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor nameRequestor = 
7294
		UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor nameRequestor = 
7297
			new UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor() {
7295
			new UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor() {
7298
				public void acceptName(char[] name) {
7296
				public void acceptName(char[] name) {
7299
					for (int i = 0; i < discouragedNamesCount; i++) {
7297
					CompletionEngine.this.acceptUnresolvedName(name);
7300
						if (CharOperation.equals(discouragedNames[i], name, false)) return;
7301
					}
7302
					
7303
					int relevance = computeBaseRelevance();
7304
					relevance += computeRelevanceForResolution(false);
7305
					relevance += computeRelevanceForInterestingProposal();
7306
					relevance += computeRelevanceForCaseMatching(completionToken, name);
7307
					relevance += computeRelevanceForQualification(false);
7308
					relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for local variable
7309
					CompletionEngine.this.noProposal = false;
7310
					if(!CompletionEngine.this.requestor.isIgnored(CompletionProposal.LOCAL_VARIABLE_REF)) {
7311
						CompletionProposal proposal = CompletionEngine.this.createProposal(CompletionProposal.LOCAL_VARIABLE_REF, CompletionEngine.this.actualCompletionPosition);
7312
						proposal.setSignature(
7313
							createTypeSignature(
7314
									CharOperation.concatWith(JAVA_LANG, '.'),
7315
									OBJECT));
7316
						proposal.setPackageName(CharOperation.concatWith(JAVA_LANG, '.'));
7317
						proposal.setTypeName(OBJECT);
7318
						proposal.setName(name);
7319
						proposal.setCompletion(name);
7320
						proposal.setFlags(Flags.AccDefault);
7321
						proposal.setReplaceRange(CompletionEngine.this.startPosition - CompletionEngine.this.offset, CompletionEngine.this.endPosition - CompletionEngine.this.offset);
7322
						proposal.setRelevance(relevance);
7323
						CompletionEngine.this.requestor.accept(proposal);
7324
						if(DEBUG) {
7325
							CompletionEngine.this.printDebug(proposal);
7326
						}
7327
					}
7328
					
7329
					proposedNames.add(name);
7298
					proposedNames.add(name);
7330
				}
7299
				}
7331
			};
7300
			};
Lines 7345-7351 Link Here
7345
					md.scope,
7314
					md.scope,
7346
					md.scope.classScope(),
7315
					md.scope.classScope(),
7347
					md.bodyStart,
7316
					md.bodyStart,
7348
					to,
7317
					recordTo,
7318
					parseTo,
7319
					discouragedNames,
7349
					nameRequestor);
7320
					nameRequestor);
7350
		} else if (referenceContext instanceof TypeDeclaration) {
7321
		} else if (referenceContext instanceof TypeDeclaration) {
7351
			TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
7322
			TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
Lines 7357-7364 Link Here
7357
					for (int i = 0; i < fields.length; i++) {
7328
					for (int i = 0; i < fields.length; i++) {
7358
						if (fields[i] instanceof Initializer) {
7329
						if (fields[i] instanceof Initializer) {
7359
							Initializer initializer = (Initializer) fields[i];
7330
							Initializer initializer = (Initializer) fields[i];
7360
							if (initializer.block.sourceStart <= to &&
7331
							if (initializer.block.sourceStart <= recordTo &&
7361
									to < initializer.bodyEnd) {
7332
									recordTo < initializer.bodyEnd) {
7362
					
7333
					
7363
								UnresolvedReferenceNameFinder nameFinder = new UnresolvedReferenceNameFinder(this);
7334
								UnresolvedReferenceNameFinder nameFinder = new UnresolvedReferenceNameFinder(this);
7364
								nameFinder.findBefore(
7335
								nameFinder.findBefore(
Lines 7366-7372 Link Here
7366
										typeDeclaration.scope,
7337
										typeDeclaration.scope,
7367
										typeDeclaration.scope,
7338
										typeDeclaration.scope,
7368
										initializer.block.sourceStart,
7339
										initializer.block.sourceStart,
7369
										to,
7340
										recordTo,
7341
										parseTo,
7342
										discouragedNames,
7370
										nameRequestor);
7343
										nameRequestor);
7371
								break done;
7344
								break done;
7372
							}
7345
							}
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionScanner.java (-83 lines)
Lines 40-55 Link Here
40
40
41
	public static final char[] EmptyCompletionIdentifier = {};
41
	public static final char[] EmptyCompletionIdentifier = {};
42
	
42
	
43
	public boolean record = false;
44
	public char[] prefix;
45
	public int currentToken;
46
	public int currentTokenStart;
47
	public int lastUsedToken;
48
	public int lastUsedTokenStart;
49
	public int potentialVariableNamesPtr; 
50
	public char[][] potentialVariableNames;
51
	public int[] potentialVariableNameStarts;
52
	
53
public CompletionScanner(long sourceLevel) {
43
public CompletionScanner(long sourceLevel) {
54
	super(
44
	super(
55
		false /*comment*/, 
45
		false /*comment*/, 
Lines 60-84 Link Here
60
		null/*taskPriorities*/,
50
		null/*taskPriorities*/,
61
		true/*taskCaseSensitive*/);
51
		true/*taskCaseSensitive*/);
62
}
52
}
63
private void addPotentialName(char[] name, int start) {
64
	int length = this.potentialVariableNames.length;
65
	if (this.potentialVariableNamesPtr >= length - 1) {
66
		System.arraycopy(
67
				this.potentialVariableNames, 
68
				0,
69
				this.potentialVariableNames = new char[length * 2][],
70
				0,
71
				length);
72
		System.arraycopy(
73
				this.potentialVariableNameStarts,
74
				0,
75
				this.potentialVariableNameStarts = new int[length * 2],
76
				0,
77
				length);
78
	}
79
	this.potentialVariableNames[++this.potentialVariableNamesPtr] = name;
80
	this.potentialVariableNameStarts[this.potentialVariableNamesPtr] = start;
81
}
82
/* 
53
/* 
83
 * Truncate the current identifier if it is containing the cursor location. Since completion is performed
54
 * Truncate the current identifier if it is containing the cursor location. Since completion is performed
84
 * on an identifier prefix.
55
 * on an identifier prefix.
Lines 131-162 Link Here
131
	return super.getCurrentTokenSourceString();
102
	return super.getCurrentTokenSourceString();
132
}
103
}
133
public int getNextToken() throws InvalidInputException {
104
public int getNextToken() throws InvalidInputException {
134
	int nextToken = this.getNextToken0();
135
	if (this.record) {
136
		switch (nextToken) {
137
			case TokenNameIdentifier:
138
				if (this.currentToken != TokenNameDOT) {
139
					char[] identifier = this.getCurrentIdentifierSource();
140
					if (!Character.isUpperCase(identifier[0]) && 
141
							CharOperation.prefixEquals(this.prefix, identifier, true)) {
142
						this.addPotentialName(identifier, this.startPosition);
143
					}
144
				}
145
				break;
146
			case TokenNameLPAREN :
147
			case TokenNameLBRACE :
148
				if (this.currentToken == TokenNameIdentifier) {
149
					this.removePotentialNamesAt(this.currentTokenStart);
150
					
151
				}
152
				break;
153
		}
154
	}
155
	this.currentToken = nextToken;
156
	this.currentTokenStart = this.startPosition;
157
	return nextToken;
158
}
159
private int getNextToken0() throws InvalidInputException {
160
105
161
	this.wasAcr = false;
106
	this.wasAcr = false;
162
	this.unicodeCharSize = 0;
107
	this.unicodeCharSize = 0;
Lines 868-890 Link Here
868
public final void jumpOverBlock() {
813
public final void jumpOverBlock() {
869
	this.jumpOverMethodBody();
814
	this.jumpOverMethodBody();
870
}
815
}
871
public void removePotentialNamesAt(int position) {
872
	for (int i = 0; i <= this.potentialVariableNamesPtr; i++) {
873
		int namePosition = this.potentialVariableNameStarts[i];
874
		if (namePosition == position) {
875
			this.potentialVariableNames[i] = null;
876
		}
877
	}
878
}
879
public void resetTo(int begin, int end) {
880
	if (this.record) {
881
		this.currentToken = -1;
882
		this.currentTokenStart = 0;
883
		this.lastUsedToken = -1;
884
		this.lastUsedTokenStart = 0;
885
	}
886
	super.resetTo(begin, end);
887
}
888
///*
816
///*
889
// * In case we actually read a keyword, but the cursor is located inside,
817
// * In case we actually read a keyword, but the cursor is located inside,
890
// * we pretend we read an identifier.
818
// * we pretend we read an identifier.
Lines 919-933 Link Here
919
	}
847
	}
920
	return token;
848
	return token;
921
}
849
}
922
923
public void startRecordingIdentifiers() {
924
	this.record = true;
925
	
926
	this.potentialVariableNamesPtr = -1; 
927
	this.potentialVariableNames = new char[10][];
928
	this.potentialVariableNameStarts = new int[10];
929
}
930
public void stopRecordingIdentifiers() {
931
	this.record = true;
932
}
933
}
850
}
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-71 / +122 lines)
Lines 28-34 Link Here
28
import org.eclipse.jdt.internal.compiler.problem.*;
28
import org.eclipse.jdt.internal.compiler.problem.*;
29
import org.eclipse.jdt.internal.compiler.util.Util;
29
import org.eclipse.jdt.internal.compiler.util.Util;
30
import org.eclipse.jdt.core.compiler.CharOperation;
30
import org.eclipse.jdt.core.compiler.CharOperation;
31
import org.eclipse.jdt.core.compiler.InvalidInputException;
32
import org.eclipse.jdt.internal.codeassist.impl.*;
31
import org.eclipse.jdt.internal.codeassist.impl.*;
33
32
34
public class CompletionParser extends AssistParser {
33
public class CompletionParser extends AssistParser {
Lines 141-152 Link Here
141
	int labelPtr = -1;
140
	int labelPtr = -1;
142
141
143
	boolean isAlreadyAttached;
142
	boolean isAlreadyAttached;
143
	
144
	public boolean record = false;
145
	public boolean skipRecord = false;
146
	public int recordFrom;
147
	public int recordTo;
148
	public int potentialVariableNamesPtr; 
149
	public char[][] potentialVariableNames;
150
	public int[] potentialVariableNameStarts;
151
	public int[] potentialVariableNameEnds;
152
	
144
public CompletionParser(ProblemReporter problemReporter) {
153
public CompletionParser(ProblemReporter problemReporter) {
145
	super(problemReporter);
154
	super(problemReporter);
146
	this.reportSyntaxErrorIsRequired = false;
155
	this.reportSyntaxErrorIsRequired = false;
147
	this.javadocParser = new CompletionJavadocParser(this);
148
	this.javadocParser.checkDocComment = true;
156
	this.javadocParser.checkDocComment = true;
149
}
157
}
158
private void addPotentialName(char[] potentialVariableName, int start, int end) {
159
	int length = this.potentialVariableNames.length;
160
	if (this.potentialVariableNamesPtr >= length - 1) {
161
		System.arraycopy(
162
				this.potentialVariableNames, 
163
				0,
164
				this.potentialVariableNames = new char[length * 2][],
165
				0,
166
				length);
167
		System.arraycopy(
168
				this.potentialVariableNameStarts,
169
				0,
170
				this.potentialVariableNameStarts = new int[length * 2],
171
				0,
172
				length);
173
		System.arraycopy(
174
				this.potentialVariableNameEnds,
175
				0,
176
				this.potentialVariableNameEnds = new int[length * 2],
177
				0,
178
				length);
179
	}
180
	this.potentialVariableNames[++this.potentialVariableNamesPtr] = potentialVariableName;
181
	this.potentialVariableNameStarts[this.potentialVariableNamesPtr] = start;
182
	this.potentialVariableNameEnds[this.potentialVariableNamesPtr] = end;
183
}
184
public void startRecordingIdentifiers(int from, int to) {
185
	this.record = true;
186
	this.skipRecord = false;
187
	this.recordFrom = from;
188
	this.recordTo = to;
189
	
190
	this.potentialVariableNamesPtr = -1; 
191
	this.potentialVariableNames = new char[10][];
192
	this.potentialVariableNameStarts = new int[10];
193
	this.potentialVariableNameEnds = new int[10];
194
}
195
public void stopRecordingIdentifiers() {
196
	this.record = true;
197
	this.skipRecord = false;
198
}
150
public char[] assistIdentifier(){
199
public char[] assistIdentifier(){
151
	return ((CompletionScanner)scanner).completionIdentifier;
200
	return ((CompletionScanner)scanner).completionIdentifier;
152
}
201
}
Lines 2193-2199 Link Here
2193
	if(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_PARAMETERIZED_CAST) {
2242
	if(topKnownElementKind(COMPLETION_OR_ASSIST_PARSER) == K_PARAMETERIZED_CAST) {
2194
		popElement(K_PARAMETERIZED_CAST);
2243
		popElement(K_PARAMETERIZED_CAST);
2195
	}
2244
	}
2196
	super.consumeInsideCastExpressionLL1();
2245
	if (!this.record) {
2246
		super.consumeInsideCastExpressionLL1();
2247
	} else {
2248
		boolean temp = this.skipRecord;
2249
		try {
2250
			this.skipRecord = true;
2251
			super.consumeInsideCastExpressionLL1();
2252
			if (this.record) {
2253
				Expression typeReference = this.expressionStack[this.expressionPtr];
2254
				if (!isAlreadyPotentialName(typeReference.sourceStart)) {
2255
					this.addPotentialName(null, typeReference.sourceStart, typeReference.sourceEnd);
2256
				}
2257
			}
2258
		} finally {
2259
			this.skipRecord = temp;
2260
		}
2261
	}
2197
	pushOnElementStack(K_CAST_STATEMENT);
2262
	pushOnElementStack(K_CAST_STATEMENT);
2198
}
2263
}
2199
protected void consumeInsideCastExpressionWithQualifiedGenerics() {
2264
protected void consumeInsideCastExpressionWithQualifiedGenerics() {
Lines 2594-2599 Link Here
2594
	this.popElement(K_BETWEEN_ANNOTATION_NAME_AND_RPAREN);
2659
	this.popElement(K_BETWEEN_ANNOTATION_NAME_AND_RPAREN);
2595
	super.consumeSingleMemberAnnotation();
2660
	super.consumeSingleMemberAnnotation();
2596
}
2661
}
2662
protected void consumeStatementBreakWithLabel() {
2663
	super.consumeStatementBreakWithLabel();
2664
	if (this.record) {
2665
		ASTNode breakStatement = this.astStack[this.astPtr];
2666
		if (!isAlreadyPotentialName(breakStatement.sourceStart)) {
2667
			this.addPotentialName(null, breakStatement.sourceStart, breakStatement.sourceEnd);
2668
		}
2669
	}
2670
	
2671
}
2597
protected void consumeStatementLabel() {
2672
protected void consumeStatementLabel() {
2598
	this.popElement(K_LABEL);
2673
	this.popElement(K_LABEL);
2599
	super.consumeStatementLabel();
2674
	super.consumeStatementLabel();
Lines 3622-3634 Link Here
3622
3697
3623
	return ref;
3698
	return ref;
3624
}
3699
}
3700
protected NameReference getUnspecifiedReference() {
3701
	NameReference nameReference = super.getUnspecifiedReference();
3702
	if (this.record) {
3703
		recordReference(nameReference);
3704
	}
3705
	return nameReference;
3706
}
3625
protected NameReference getUnspecifiedReferenceOptimized() {
3707
protected NameReference getUnspecifiedReferenceOptimized() {
3626
	if (this.identifierLengthStack[this.identifierLengthPtr] > 1) { // reducing a qualified name
3708
	if (this.identifierLengthStack[this.identifierLengthPtr] > 1) { // reducing a qualified name
3627
		// potential receiver is being poped, so reset potential receiver
3709
		// potential receiver is being poped, so reset potential receiver
3628
		this.invocationType = NO_RECEIVER;
3710
		this.invocationType = NO_RECEIVER;
3629
		this.qualifier = -1;
3711
		this.qualifier = -1;
3630
	}
3712
	}
3631
	return super.getUnspecifiedReferenceOptimized();
3713
	NameReference nameReference = super.getUnspecifiedReferenceOptimized();
3714
	if (this.record) {
3715
		recordReference(nameReference);
3716
	}
3717
	return nameReference;
3718
}
3719
private boolean isAlreadyPotentialName(int identifierStart) {
3720
	if (this.potentialVariableNamesPtr < 0) return false;
3721
	
3722
	return identifierStart <= this.potentialVariableNameEnds[this.potentialVariableNamesPtr];
3723
}
3724
protected int indexOfAssistIdentifier(boolean useGenericsStack) {
3725
	if (this.record) return -1; // when names are recorded there is no assist identifier
3726
	return super.indexOfAssistIdentifier(useGenericsStack);
3632
}
3727
}
3633
public void initialize() {
3728
public void initialize() {
3634
	super.initialize();
3729
	super.initialize();
Lines 3868-3940 Link Here
3868
		expressionStack[expressionPtr] = fr;
3963
		expressionStack[expressionPtr] = fr;
3869
	}
3964
	}
3870
}
3965
}
3871
protected boolean moveRecoveryCheckpoint() {
3872
	CompletionScanner completionScanner = (CompletionScanner) this.scanner;
3873
	boolean recordIdentifers = completionScanner.record;
3874
	if (!recordIdentifers) {
3875
		return super.moveRecoveryCheckpoint();
3876
	}
3877
3878
	completionScanner.record = false;
3879
3880
	int pos = this.lastCheckPoint;
3881
	int curTok = completionScanner.lastUsedToken;
3882
	int curTokStart = completionScanner.lastUsedTokenStart;
3883
3884
	/* reset this.scanner, and move checkpoint by one token */
3885
	this.scanner.startPosition = pos;
3886
	this.scanner.currentPosition = pos;
3887
	this.scanner.diet = false; // quit jumping over method bodies
3888
3889
	completionScanner.currentToken = curTok;
3890
	completionScanner.currentTokenStart = curTokStart;
3891
3892
	/* if about to restart, then no need to shift token */
3893
	if (this.restartRecovery){
3894
		this.lastIgnoredToken = -1;
3895
		this.scanner.insideRecovery = true;
3896
		completionScanner.record = true;
3897
		return true;
3898
	}
3899
3900
	/* protect against shifting on an invalid token */
3901
	this.lastIgnoredToken = this.nextIgnoredToken;
3902
	this.nextIgnoredToken = -1;
3903
	do {
3904
		try {
3905
			this.nextIgnoredToken = this.scanner.getNextToken();
3906
			if(this.scanner.currentPosition == this.scanner.startPosition){
3907
				this.scanner.currentPosition++; // on fake completion identifier
3908
				this.nextIgnoredToken = -1;
3909
			}
3910
3911
		} catch(InvalidInputException e){
3912
			pos = this.scanner.currentPosition;
3913
		}
3914
	} while (this.nextIgnoredToken < 0);
3915
3916
	if (this.nextIgnoredToken == TokenNameEOF) { // no more recovery after this point
3917
		if (this.currentToken == TokenNameEOF) { // already tried one iteration on EOF
3918
			completionScanner.record = true;
3919
			return false;
3920
		}
3921
	}
3922
	this.lastCheckPoint = this.scanner.currentPosition;
3923
	completionScanner.lastUsedToken = this.nextIgnoredToken;
3924
	completionScanner.lastUsedTokenStart = this.lastCheckPoint;
3925
3926
	/* reset this.scanner again to previous checkpoint location*/
3927
	this.scanner.startPosition = pos;
3928
	this.scanner.currentPosition = pos;
3929
	this.scanner.commentPtr = -1;
3930
	this.scanner.foundTaskCount = 0;
3931
3932
	completionScanner.currentToken = curTok;
3933
	completionScanner.currentTokenStart = curTokStart;
3934
	completionScanner.record = true;
3935
3936
	return true;
3937
}
3938
public void recordCompletionOnReference(){
3966
public void recordCompletionOnReference(){
3939
3967
3940
	if (currentElement instanceof RecoveredType){
3968
	if (currentElement instanceof RecoveredType){
Lines 3951-3956 Link Here
3951
	if (!diet) return; // only record references attached to types
3979
	if (!diet) return; // only record references attached to types
3952
3980
3953
}
3981
}
3982
private void recordReference(NameReference nameReference) {
3983
	if (!this.skipRecord &&
3984
			this.recordFrom <= nameReference.sourceStart &&
3985
			nameReference.sourceEnd <= this.recordTo &&
3986
			!isAlreadyPotentialName(nameReference.sourceStart)) {
3987
		char[] token;
3988
		if (nameReference instanceof SingleNameReference) {
3989
			token = ((SingleNameReference) nameReference).token;
3990
		} else {
3991
			token = ((QualifiedNameReference) nameReference).tokens[0];
3992
		}
3993
		
3994
		// Most of the time a name which start with an uppercase is a type name.
3995
		// As we don't want to resolve names to avoid to slow down performances then this name will be ignored
3996
		if (Character.isUpperCase(token[0])) return;
3997
		
3998
		addPotentialName(token, nameReference.sourceStart, nameReference.sourceEnd);
3999
	}
4000
}
3954
public void recoveryExitFromVariable() {
4001
public void recoveryExitFromVariable() {
3955
	if(currentElement != null && currentElement instanceof RecoveredLocalVariable) {
4002
	if(currentElement != null && currentElement instanceof RecoveredLocalVariable) {
3956
		RecoveredElement oldElement = currentElement;
4003
		RecoveredElement oldElement = currentElement;
Lines 4123-4128 Link Here
4123
	}
4170
	}
4124
}
4171
}
4125
4172
4173
protected JavadocParser createJavadocParser() {
4174
	return new CompletionJavadocParser(this);
4175
}
4176
4126
protected FieldDeclaration createFieldDeclaration(char[] assistName, int sourceStart, int sourceEnd) {
4177
protected FieldDeclaration createFieldDeclaration(char[] assistName, int sourceStart, int sourceEnd) {
4127
	if (this.indexOfAssistIdentifier() < 0 || (currentElement instanceof RecoveredUnit && ((RecoveredUnit)currentElement).typeCount == 0)) {
4178
	if (this.indexOfAssistIdentifier() < 0 || (currentElement instanceof RecoveredUnit && ((RecoveredUnit)currentElement).typeCount == 0)) {
4128
		return super.createFieldDeclaration(assistName, sourceStart, sourceEnd);
4179
		return super.createFieldDeclaration(assistName, sourceStart, sourceEnd);
(-)workspace/Completion/src/CompletionCastIsParent2.java (-5 lines)
Removed Link Here
1
public class CompletionCastIsParent2 {
2
	XX11 foo() {
3
		return (XX11)xx
4
	}
5
}
(-)workspace/Completion/src/CompletionCastIsParent1.java (-27 lines)
Removed Link Here
1
public class CompletionCastIsParent1 {
2
	Object zzOb;
3
	XX00 zz00;
4
	XX01 zz01;
5
	XX02 zz02;
6
	XX10 zz10;
7
	XX11 zz11;
8
	XX12 zz12;
9
	XX20 zz20;
10
	XX21 zz21;
11
	XX22 zz22;
12
	
13
	Object zzObM(){}
14
	XX00 zz00M(){}
15
	XX01 zz01M(){}
16
	XX02 zz02M(){}
17
	XX10 zz10M(){}
18
	XX11 zz11M(){}
19
	XX12 zz12M(){}
20
	XX20 zz20M(){}
21
	XX21 zz21M(){}
22
	XX22 zz22M(){}
23
	
24
	XX11 foo() {
25
		return (XX11)zz
26
	}
27
}
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (-41 / +248 lines)
Lines 2512-2570 Link Here
2512
2512
2513
2513
2514
public void testCompletionCastIsParent1() throws JavaModelException {
2514
public void testCompletionCastIsParent1() throws JavaModelException {
2515
	CompletionTestsRequestor requestor = new CompletionTestsRequestor();
2515
	this.workingCopies = new ICompilationUnit[1];
2516
	ICompilationUnit cu= getCompilationUnit("Completion", "src", "", "CompletionCastIsParent1.java");
2516
	this.workingCopies[0] = getWorkingCopy(
2517
		"/Completion/src/CompletionCastIsParent1.java.java",
2518
		"public class CompletionCastIsParent1 {\n"+
2519
		"	Object zzOb;\n"+
2520
		"	XX00 zz00;\n"+
2521
		"	XX01 zz01;\n"+
2522
		"	XX02 zz02;\n"+
2523
		"	XX10 zz10;\n"+
2524
		"	XX11 zz11;\n"+
2525
		"	XX12 zz12;\n"+
2526
		"	XX20 zz20;\n"+
2527
		"	XX21 zz21;\n"+
2528
		"	XX22 zz22;\n"+
2529
		"	\n"+
2530
		"	Object zzObM(){}\n"+
2531
		"	XX00 zz00M(){}\n"+
2532
		"	XX01 zz01M(){}\n"+
2533
		"	XX02 zz02M(){}\n"+
2534
		"	XX10 zz10M(){}\n"+
2535
		"	XX11 zz11M(){}\n"+
2536
		"	XX12 zz12M(){}\n"+
2537
		"	XX20 zz20M(){}\n"+
2538
		"	XX21 zz21M(){}\n"+
2539
		"	XX22 zz22M(){}\n"+
2540
		"	\n"+
2541
		"	XX11 foo() {\n"+
2542
		"		return (XX11)zz\n"+
2543
		"	}\n"+
2544
		"}\n");
2517
2545
2518
	String str = cu.getSource();
2546
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
2547
	String str = this.workingCopies[0].getSource();
2519
	String completeBehind = "zz";
2548
	String completeBehind = "zz";
2520
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
2549
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
2521
	cu.codeComplete(cursorLocation, requestor);
2550
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
2522
2551
2523
	assertEquals(
2552
	assertResults(
2524
		"element:zz00    completion:zz00    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2553
			"zz00[FIELD_REF]{zz00, LCompletionCastIsParent1;, LXX00;, zz00, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2525
		"element:zz00M    completion:zz00M()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2554
			"zz00M[METHOD_REF]{zz00M(), LCompletionCastIsParent1;, ()LXX00;, zz00M, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2526
		"element:zz01    completion:zz01    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2555
			"zz02[FIELD_REF]{zz02, LCompletionCastIsParent1;, LXX02;, zz02, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2527
		"element:zz01M    completion:zz01M()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2556
			"zz02M[METHOD_REF]{zz02M(), LCompletionCastIsParent1;, ()LXX02;, zz02M, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2528
		"element:zz02    completion:zz02    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2557
			"zz10[FIELD_REF]{zz10, LCompletionCastIsParent1;, LXX10;, zz10, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2529
		"element:zz02M    completion:zz02M()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2558
			"zz10M[METHOD_REF]{zz10M(), LCompletionCastIsParent1;, ()LXX10;, zz10M, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2530
		"element:zz10    completion:zz10    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2559
			"zz12[FIELD_REF]{zz12, LCompletionCastIsParent1;, LXX12;, zz12, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2531
		"element:zz10M    completion:zz10M()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2560
			"zz12M[METHOD_REF]{zz12M(), LCompletionCastIsParent1;, ()LXX12;, zz12M, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2532
		"element:zz11    completion:zz11    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2561
			"zz20[FIELD_REF]{zz20, LCompletionCastIsParent1;, LXX20;, zz20, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2533
		"element:zz11M    completion:zz11M()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2562
			"zz20M[METHOD_REF]{zz20M(), LCompletionCastIsParent1;, ()LXX20;, zz20M, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2534
		"element:zz12    completion:zz12    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2563
			"zz22[FIELD_REF]{zz22, LCompletionCastIsParent1;, LXX22;, zz22, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2535
		"element:zz12M    completion:zz12M()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2564
			"zz22M[METHOD_REF]{zz22M(), LCompletionCastIsParent1;, ()LXX22;, zz22M, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2536
		"element:zz20    completion:zz20    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2565
			"zz01[FIELD_REF]{zz01, LCompletionCastIsParent1;, LXX01;, zz01, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2537
		"element:zz20M    completion:zz20M()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2566
			"zz01M[METHOD_REF]{zz01M(), LCompletionCastIsParent1;, ()LXX01;, zz01M, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2538
		"element:zz21    completion:zz21    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2567
			"zz21[FIELD_REF]{zz21, LCompletionCastIsParent1;, LXX21;, zz21, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2539
		"element:zz21M    completion:zz21M()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2568
			"zz21M[METHOD_REF]{zz21M(), LCompletionCastIsParent1;, ()LXX21;, zz21M, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2540
		"element:zz22    completion:zz22    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2569
			"zzOb[FIELD_REF]{zzOb, LCompletionCastIsParent1;, Ljava.lang.Object;, zzOb, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2541
		"element:zz22M    completion:zz22M()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2570
			"zzObM[METHOD_REF]{zzObM(), LCompletionCastIsParent1;, ()Ljava.lang.Object;, zzObM, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2542
		"element:zzOb    completion:zzOb    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2571
			"zz11[FIELD_REF]{zz11, LCompletionCastIsParent1;, LXX11;, zz11, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2543
		"element:zzObM    completion:zzObM()    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXPECTED_TYPE + R_UNQUALIFIED+ R_NON_RESTRICTED),
2572
			"zz11M[METHOD_REF]{zz11M(), LCompletionCastIsParent1;, ()LXX11;, zz11M, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}",
2544
		requestor.getResults());
2573
			requestor.getResults());
2545
}
2574
}
2546
2575
2547
2576
2548
public void testCompletionCastIsParent2() throws JavaModelException {
2577
public void testCompletionCastIsParent2() throws JavaModelException {
2549
	CompletionTestsRequestor requestor = new CompletionTestsRequestor();
2578
	this.workingCopies = new ICompilationUnit[1];
2550
	ICompilationUnit cu= getCompilationUnit("Completion", "src", "", "CompletionCastIsParent2.java");
2579
	this.workingCopies[0] = getWorkingCopy(
2580
		"/Completion/src/CompletionCastIsParent2.java.java",
2581
		"public class CompletionCastIsParent2 {\n"+
2582
		"	XX11 foo() {\n"+
2583
		"		return (XX11)xx\n"+
2584
		"	}\n"+
2585
		"}\n");
2551
2586
2552
	String str = cu.getSource();
2587
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
2588
	String str = this.workingCopies[0].getSource();
2553
	String completeBehind = "xx";
2589
	String completeBehind = "xx";
2554
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
2590
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
2555
	cu.codeComplete(cursorLocation, requestor);
2591
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
2556
2592
2557
	assertEquals(
2593
	assertResults(
2558
		"element:XX00    completion:XX00    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2594
			"XX00[TYPE_REF]{XX00, , LXX00;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2559
		"element:XX01    completion:XX01    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2595
			"XX01[TYPE_REF]{XX01, , LXX01;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2560
		"element:XX02    completion:XX02    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2596
			"XX02[TYPE_REF]{XX02, , LXX02;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2561
		"element:XX10    completion:XX10    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2597
			"XX10[TYPE_REF]{XX10, , LXX10;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2562
		"element:XX11    completion:XX11    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2598
			"XX12[TYPE_REF]{XX12, , LXX12;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2563
		"element:XX12    completion:XX12    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2599
			"XX20[TYPE_REF]{XX20, , LXX20;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2564
		"element:XX20    completion:XX20    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2600
			"XX21[TYPE_REF]{XX21, , LXX21;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2565
		"element:XX21    completion:XX21    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"\n" +
2601
			"XX22[TYPE_REF]{XX22, , LXX22;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n"+
2566
		"element:XX22    completion:XX22    relevance:"+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_UNQUALIFIED+ R_NON_RESTRICTED),
2602
			"XX11[TYPE_REF]{XX11, , LXX11;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_EXACT_EXPECTED_TYPE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}",
2567
		requestor.getResults());
2603
			requestor.getResults());
2568
}
2604
}
2569
2605
2570
public void testCompletionCatchArgumentName() throws JavaModelException {
2606
public void testCompletionCatchArgumentName() throws JavaModelException {
Lines 15669-15674 Link Here
15669
			"zzz1[LOCAL_VARIABLE_REF]{zzz1, null, Ljava.lang.Object;, zzz1, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
15705
			"zzz1[LOCAL_VARIABLE_REF]{zzz1, null, Ljava.lang.Object;, zzz1, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
15670
			requestor.getResults());
15706
			requestor.getResults());
15671
}
15707
}
15708
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177174
15709
public void testNameWithUnresolvedReferences012() throws JavaModelException {
15710
	this.workingCopies = new ICompilationUnit[1];
15711
	
15712
	this.workingCopies[0] = getWorkingCopy(
15713
			"/Completion/src3/test/Test.java",
15714
			"package test;\n" +
15715
			"public class Test {\n" +
15716
			"   void foo() {\n" +
15717
			"      zzzlala = 0;\n" +
15718
			"      zzzlabel : {\n" +
15719
			"        /**/zzzla\n" +
15720
			"      }\n" +
15721
			"   }\n" +
15722
			"}\n");
15723
	
15724
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
15725
	
15726
	String str = this.workingCopies[0].getSource();
15727
	String completeBehind = "/**/zzzla";
15728
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15729
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
15730
	
15731
	assertResults(
15732
			"zzzlala[LOCAL_VARIABLE_REF]{zzzlala, null, Ljava.lang.Object;, zzzlala, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
15733
			requestor.getResults());
15734
}
15735
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177174
15736
public void testNameWithUnresolvedReferences013() throws JavaModelException {
15737
	this.workingCopies = new ICompilationUnit[1];
15738
	
15739
	this.workingCopies[0] = getWorkingCopy(
15740
			"/Completion/src3/test/Test.java",
15741
			"package test;\n" +
15742
			"public class Test {\n" +
15743
			"   void foo() {\n" +
15744
			"      zzzlala = 0;\n" +
15745
			"      zzzlabel1 : {\n" +
15746
			"        /**/zzzla\n" +
15747
			"        {\n" +
15748
			"          break zzzlabel2;\n" +
15749
			"        }\n" +
15750
			"      }\n" +
15751
			"   }\n" +
15752
			"}\n");
15753
	
15754
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
15755
	
15756
	String str = this.workingCopies[0].getSource();
15757
	String completeBehind = "/**/zzzla";
15758
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15759
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
15760
	
15761
	assertResults(
15762
			"zzzlala[LOCAL_VARIABLE_REF]{zzzlala, null, Ljava.lang.Object;, zzzlala, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
15763
			requestor.getResults());
15764
}
15765
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177174
15766
public void testNameWithUnresolvedReferences014() throws JavaModelException {
15767
	this.workingCopies = new ICompilationUnit[1];
15768
	
15769
	this.workingCopies[0] = getWorkingCopy(
15770
			"/Completion/src3/test/Test.java",
15771
			"package test;\n" +
15772
			"public class Test {\n" +
15773
			"   void foo() {\n" +
15774
			"      {\n" +
15775
			"        break;\n" +
15776
			"      }\n" +
15777
			"      zzznotlabel = 25;\n" +
15778
			"      {\n" +
15779
			"        /**/zzznotla\n" +
15780
			"      }\n" +
15781
			"   }\n" +
15782
			"}\n");
15783
	
15784
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
15785
	
15786
	String str = this.workingCopies[0].getSource();
15787
	String completeBehind = "/**/zzznotla";
15788
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15789
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
15790
	
15791
	assertResults(
15792
			"zzznotlabel[LOCAL_VARIABLE_REF]{zzznotlabel, null, Ljava.lang.Object;, zzznotlabel, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
15793
			requestor.getResults());
15794
}
15795
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177174
15796
public void testNameWithUnresolvedReferences015() throws JavaModelException {
15797
	this.workingCopies = new ICompilationUnit[1];
15798
	
15799
	this.workingCopies[0] = getWorkingCopy(
15800
			"/Completion/src3/test/Test.java",
15801
			"package test;\n" +
15802
			"public class Test {\n" +
15803
			"   int foo() {\n" +
15804
			"      zzz1 = 0;\n" +
15805
			"      if (false) return (ZZZ2) var;\n" +
15806
			"      zz\n" +
15807
			"   }\n" +
15808
			"}\n");
15809
	
15810
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
15811
	
15812
	String str = this.workingCopies[0].getSource();
15813
	String completeBehind = "zz";
15814
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15815
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
15816
	
15817
	assertResults(
15818
			"zzz1[LOCAL_VARIABLE_REF]{zzz1, null, Ljava.lang.Object;, zzz1, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
15819
			requestor.getResults());
15820
}
15821
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177174
15822
public void testNameWithUnresolvedReferences016() throws JavaModelException {
15823
	this.workingCopies = new ICompilationUnit[1];
15824
	
15825
	this.workingCopies[0] = getWorkingCopy(
15826
			"/Completion/src3/test/Test.java",
15827
			"package test;\n" +
15828
			"public class Test {\n" +
15829
			"   int foo() {\n" +
15830
			"      zzz1 = 0;\n" +
15831
			"      return (zzz2) zz;\n" +
15832
			"   }\n" +
15833
			"}\n");
15834
	
15835
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
15836
	
15837
	String str = this.workingCopies[0].getSource();
15838
	String completeBehind = "zz";
15839
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15840
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
15841
	
15842
	assertResults(
15843
			"zzz1[LOCAL_VARIABLE_REF]{zzz1, null, Ljava.lang.Object;, zzz1, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
15844
			requestor.getResults());
15845
}
15846
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177174
15847
public void testNameWithUnresolvedReferences017() throws JavaModelException {
15848
	this.workingCopies = new ICompilationUnit[1];
15849
	
15850
	this.workingCopies[0] = getWorkingCopy(
15851
			"/Completion/src3/test/Test.java",
15852
			"package test;\n" +
15853
			"public class Test {\n" +
15854
			"   void foo() {\n" +
15855
			"      {\n" +
15856
			"         final int zzz1 = 0;\n" +
15857
			"         class Local {\n" +
15858
			"            void bar() {n" +
15859
			"               zzz1 = 24;\n" +
15860
			"               zzz2 = 24;\n" +
15861
			"            }\n" +
15862
			"         }\n" +
15863
			"      }\n" +
15864
			"      zz\n" +
15865
			"   }\n" +
15866
			"}\n");
15867
	
15868
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
15869
	
15870
	String str = this.workingCopies[0].getSource();
15871
	String completeBehind = "zz";
15872
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15873
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
15874
	
15875
	assertResults(
15876
			"zzz2[LOCAL_VARIABLE_REF]{zzz2, null, Ljava.lang.Object;, zzz2, null, " + (R_DEFAULT + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED) + "}",
15877
			requestor.getResults());
15878
}
15672
public void testParameterNames1() throws CoreException, IOException {
15879
public void testParameterNames1() throws CoreException, IOException {
15673
	Hashtable options = JavaCore.getOptions();
15880
	Hashtable options = JavaCore.getOptions();
15674
	Object timeout = options.get(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC);
15881
	Object timeout = options.get(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC);

Return to bug 177174