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

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java (-10 / +38 lines)
Lines 19-25 Link Here
19
import org.eclipse.jdt.core.JavaModelException;
19
import org.eclipse.jdt.core.JavaModelException;
20
import org.eclipse.jdt.core.WorkingCopyOwner;
20
import org.eclipse.jdt.core.WorkingCopyOwner;
21
import org.eclipse.jdt.core.compiler.CharOperation;
21
import org.eclipse.jdt.core.compiler.CharOperation;
22
import org.eclipse.jdt.internal.codeassist.complete.CompletionNodeDetector;
23
import org.eclipse.jdt.internal.codeassist.complete.CompletionParser;
22
import org.eclipse.jdt.internal.codeassist.complete.CompletionParser;
24
import org.eclipse.jdt.internal.codeassist.impl.AssistCompilationUnit;
23
import org.eclipse.jdt.internal.codeassist.impl.AssistCompilationUnit;
25
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
24
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
Lines 188-200 Link Here
188
							}
187
							}
189
						} else {
188
						} else {
190
							FieldDeclaration fieldDeclaration = fields[i];
189
							FieldDeclaration fieldDeclaration = fields[i];
191
							if (fieldDeclaration.initialization != null &&
190
							if (fieldDeclaration.initialization != null) {
192
									fieldDeclaration.initialization.sourceStart <= astNode.sourceStart &&
193
									astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) {
194
								// completion is inside a field initializer
191
								// completion is inside a field initializer
195
								searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc);
192
								searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc);
193
								// remove this field from visibleFields list because completion is being asked in its
194
								// intialization and so this has not yet been declared successfully.
195
								if (this.visibleFields.size > 0 && this.visibleFields.contains(fieldDeclaration.binding)) {
196
									this.visibleFields.remove(fieldDeclaration.binding);
197
								}
196
								break done;
198
								break done;
197
							}
199
							}
200
							/*(Incase fieldDeclaration != null is not sufficient to infer that
201
							  proposal is being asked inside initializer of field decl, use the below if
202
							  block instead of the above)
203
							if (fieldDeclaration.initialization != null) {
204
							 
205
								if (fieldDeclaration.initialization.sourceEnd > 0) {
206
									if (fieldDeclaration.initialization.sourceStart <= astNode.sourceStart &&
207
											astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) {
208
										// completion is inside a field initializer
209
										searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc);
210
									}
211
								} else { // The sourceEnd may not yet be set
212
									CompletionNodeDetector detector = new CompletionNodeDetector(this.assistNode, fieldDeclaration.initialization);
213
									if (detector.containsCompletionNode()) {
214
										searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc);
215
									}
216
								}
217
								// remove this field from visibleFields list because completion is being asked in its
218
								// intialization and so this has not yet been declared successfully.
219
								if (this.visibleFields.size > 0 && this.visibleFields.contains(fieldDeclaration.binding)) {
220
									this.visibleFields.remove(fieldDeclaration.binding);
221
								}
222
							}*/
198
						}
223
						}
199
					}
224
					}
200
				}
225
				}
Lines 724-734 Link Here
724
						// If the local variable declaration's initialization statement itself has the completion,
749
						// If the local variable declaration's initialization statement itself has the completion,
725
						// then don't propose the local variable
750
						// then don't propose the local variable
726
						if (local.declaration.initialization != null) {
751
						if (local.declaration.initialization != null) {
727
							if(local.declaration.initialization.sourceEnd > 0) {
752
							/*(use this if-else block if it is found that local.declaration.initialization != null is not sufficient to 
728
									if (this.assistNode.sourceEnd <= local.declaration.initialization.sourceEnd
753
							  guarantee that proposal is being asked inside a local variable declaration's initializer)
729
											&& this.assistNode.sourceStart >= local.declaration.initialization.sourceStart) {
754
							 if(local.declaration.initialization.sourceEnd > 0) {
730
										continue next;
755
								if (this.assistNode.sourceEnd <= local.declaration.initialization.sourceEnd
731
									}
756
										&& this.assistNode.sourceStart >= local.declaration.initialization.sourceStart) {
757
									continue next;
758
								}
732
							} else {
759
							} else {
733
								CompletionNodeDetector detector = new CompletionNodeDetector(
760
								CompletionNodeDetector detector = new CompletionNodeDetector(
734
										this.assistNode,
761
										this.assistNode,
Lines 736-742 Link Here
736
								if (detector.containsCompletionNode()) {
763
								if (detector.containsCompletionNode()) {
737
									continue next;
764
									continue next;
738
								}
765
								}
739
							}
766
							}*/
767
							continue next;
740
						}
768
						}
741
						for (int f = 0; f < localsFound.size; f++) {
769
						for (int f = 0; f < localsFound.size; f++) {
742
							LocalVariableBinding otherLocal =
770
							LocalVariableBinding otherLocal =
(-)src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java (-1 / +135 lines)
Lines 4002-4008 Link Here
4002
		"expectedTypesKeys={I}\n" +
4002
		"expectedTypesKeys={I}\n" +
4003
		"completion token location=UNKNOWN\n" +
4003
		"completion token location=UNKNOWN\n" +
4004
		"visibleElements={\n" +
4004
		"visibleElements={\n" +
4005
		"	field1 {key=Ltest/X;.field1)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4006
		"	field0 {key=Ltest/X;.field0)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4005
		"	field0 {key=Ltest/X;.field0)I} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
4007
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4006
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4008
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4007
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
Lines 5291-5294 Link Here
5291
		"}",
5290
		"}",
5292
		result.context);
5291
		result.context);
5293
}
5292
}
5293
5294
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312603
5295
public void test0174() throws JavaModelException {
5296
	this.workingCopies = new ICompilationUnit[3];
5297
	this.workingCopies[0] = getWorkingCopy(
5298
		"/Completion/src3/test/X.java",
5299
		"package test;\n" +
5300
		"import java.text.MessageFormat;\n" +
5301
		"public class X {\n" +
5302
		"    String fooBar = \"Hi\";" +
5303
		"	 String furchtbar= MessageFormat.format\n" +
5304
		"}");
5305
5306
	String str = this.workingCopies[0].getSource();
5307
	int tokenStart = str.lastIndexOf("format");
5308
	int tokenEnd = tokenStart + "format".length() - 1;
5309
	int cursorLocation = str.lastIndexOf("format") + "format".length();
5310
5311
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
5312
	String jclPath = getExternalJCLPathString();
5313
	assertResults(
5314
		"completion offset="+(cursorLocation)+"\n" +
5315
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
5316
		"completion token=\"format\"\n" +
5317
		"completion token kind=TOKEN_KIND_NAME\n" +
5318
		"expectedTypesSignatures={Ljava.lang.String;}\n" +
5319
		"expectedTypesKeys={Ljava/lang/String;}\n" +
5320
		"completion token location=UNKNOWN\n" +
5321
		"enclosingElement=furchtbar {key=Ltest/X;.furchtbar)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]]\n" +
5322
		"visibleElements={\n" +
5323
		"	fooBar {key=Ltest/X;.fooBar)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
5324
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5325
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5326
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5327
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5328
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5329
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5330
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5331
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
5332
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5333
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5334
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
5335
		"}",
5336
		result.context);
5337
}
5338
5339
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312603
5340
public void test0175() throws JavaModelException {
5341
	this.workingCopies = new ICompilationUnit[3];
5342
	this.workingCopies[0] = getWorkingCopy(
5343
		"/Completion/src3/test/X.java",
5344
		"package test;\n" +
5345
		"import java.text.MessageFormat;\n" +
5346
		"public class X {\n" +
5347
		"    String fooBar = \"Hi\";" +
5348
		"	 String furchtbar= new String(String.format;\n" +
5349
		"}");
5350
5351
	String str = this.workingCopies[0].getSource();
5352
	int tokenStart = str.lastIndexOf("format");
5353
	int tokenEnd = tokenStart + "format".length() - 1;
5354
	int cursorLocation = str.lastIndexOf("format") + "format".length();
5355
5356
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
5357
	String jclPath = getExternalJCLPathString();
5358
	assertResults(
5359
		"completion offset="+(cursorLocation)+"\n" +
5360
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
5361
		"completion token=\"format\"\n" +
5362
		"completion token kind=TOKEN_KIND_NAME\n" +
5363
		"expectedTypesSignatures=null\n" +
5364
		"expectedTypesKeys=null\n" +
5365
		"completion token location=UNKNOWN\n" +
5366
		"enclosingElement=X {key=Ltest/X;} [in [Working copy] X.java [in test [in src3 [in Completion]]]]\n" +
5367
		"visibleElements={\n" +
5368
		"	fooBar {key=Ltest/X;.fooBar)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
5369
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5370
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5371
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5372
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5373
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5374
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5375
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5376
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
5377
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5378
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5379
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
5380
		"}",
5381
		result.context);
5382
}
5383
5384
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312603
5385
public void test0176() throws JavaModelException {
5386
	this.workingCopies = new ICompilationUnit[3];
5387
	this.workingCopies[0] = getWorkingCopy(
5388
		"/Completion/src3/test/X.java",
5389
		"package test;\n" +
5390
		"import java.text.MessageFormat;\n" +
5391
		"public class X {\n" +
5392
		"    String fooBar = \"Hi\";" +
5393
		"	 String furchtbar= (fooBar = new String(String.format;\n" +
5394
		"}");
5395
5396
	String str = this.workingCopies[0].getSource();
5397
	int tokenStart = str.lastIndexOf("format");
5398
	int tokenEnd = tokenStart + "format".length() - 1;
5399
	int cursorLocation = str.lastIndexOf("format") + "format".length();
5400
5401
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, true, true);
5402
	String jclPath = getExternalJCLPathString();
5403
	assertResults(
5404
		"completion offset="+(cursorLocation)+"\n" +
5405
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
5406
		"completion token=\"format\"\n" +
5407
		"completion token kind=TOKEN_KIND_NAME\n" +
5408
		"expectedTypesSignatures=null\n" +
5409
		"expectedTypesKeys=null\n" +
5410
		"completion token location=UNKNOWN\n" +
5411
		"enclosingElement=X {key=Ltest/X;} [in [Working copy] X.java [in test [in src3 [in Completion]]]]\n" +
5412
		"visibleElements={\n" +
5413
		"	fooBar {key=Ltest/X;.fooBar)Ljava/lang/String;} [in X [in [Working copy] X.java [in test [in src3 [in Completion]]]]],\n" +
5414
		"	wait(long, int) {key=Ljava/lang/Object;.wait(JI)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5415
		"	wait(long) {key=Ljava/lang/Object;.wait(J)V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5416
		"	wait() {key=Ljava/lang/Object;.wait()V|Ljava/lang/IllegalMonitorStateException;|Ljava/lang/InterruptedException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5417
		"	toString() {key=Ljava/lang/Object;.toString()Ljava/lang/String;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5418
		"	notifyAll() {key=Ljava/lang/Object;.notifyAll()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5419
		"	notify() {key=Ljava/lang/Object;.notify()V|Ljava/lang/IllegalMonitorStateException;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5420
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5421
		"	getClass() {key=Ljava/lang/Object;.getClass()Ljava/lang/Class;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
5422
		"	finalize() {key=Ljava/lang/Object;.finalize()V|Ljava/lang/Throwable;} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5423
		"	equals(java.lang.Object) {key=Ljava/lang/Object;.equals(Ljava/lang/Object;)Z} [in Object [in Object.class [in java.lang [in " + jclPath + "]]]],\n" +
5424
		"	clone() {key=Ljava/lang/Object;.clone()Ljava/lang/Object;|Ljava/lang/CloneNotSupportedException;} [in Object [in Object.class [in java.lang [in " + jclPath +"]]]],\n" +
5425
		"}",
5426
		result.context);
5427
}
5294
}
5428
}

Return to bug 312603