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

(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionUnitStructureRequestor.java (+9 lines)
Lines 59-64 Link Here
59
	
59
	
60
	private Map bindingCache;
60
	private Map bindingCache;
61
	private Map elementCache;
61
	private Map elementCache;
62
	private Map elementWithProblemCache;
62
	
63
	
63
	public CompletionUnitStructureRequestor(
64
	public CompletionUnitStructureRequestor(
64
			ICompilationUnit unit,
65
			ICompilationUnit unit,
Lines 67-78 Link Here
67
			ASTNode assistNode,
68
			ASTNode assistNode,
68
			Map bindingCache,
69
			Map bindingCache,
69
			Map elementCache,
70
			Map elementCache,
71
			Map elementWithProblemCache,
70
			Map newElements) {
72
			Map newElements) {
71
		super(unit, unitInfo, newElements);
73
		super(unit, unitInfo, newElements);
72
		this.parser = parser;
74
		this.parser = parser;
73
		this.assistNode = assistNode;
75
		this.assistNode = assistNode;
74
		this.bindingCache = bindingCache;
76
		this.bindingCache = bindingCache;
75
		this.elementCache = elementCache;
77
		this.elementCache = elementCache;
78
		this.elementWithProblemCache = elementWithProblemCache;
76
	}
79
	}
77
	
80
	
78
	protected Annotation createAnnotation(JavaElement parent, String name) {
81
	protected Annotation createAnnotation(JavaElement parent, String name) {
Lines 85-90 Link Here
85
		if (fieldInfo.node.binding != null) {
88
		if (fieldInfo.node.binding != null) {
86
			this.bindingCache.put(field, fieldInfo.node.binding);
89
			this.bindingCache.put(field, fieldInfo.node.binding);
87
			this.elementCache.put(fieldInfo.node.binding, field);
90
			this.elementCache.put(fieldInfo.node.binding, field);
91
		} else {
92
			this.elementWithProblemCache.put(fieldInfo.node, field);
88
		}
93
		}
89
		return field;
94
		return field;
90
	}
95
	}
Lines 108-113 Link Here
108
		if (methodInfo.node.binding != null) {
113
		if (methodInfo.node.binding != null) {
109
			this.bindingCache.put(method, methodInfo.node.binding);
114
			this.bindingCache.put(method, methodInfo.node.binding);
110
			this.elementCache.put(methodInfo.node.binding, method);
115
			this.elementCache.put(methodInfo.node.binding, method);
116
		} else {
117
			this.elementWithProblemCache.put(methodInfo.node, method);
111
		}
118
		}
112
		return method;
119
		return method;
113
	}
120
	}
Lines 122-127 Link Here
122
		if (typeInfo.node.binding != null) {
129
		if (typeInfo.node.binding != null) {
123
			this.bindingCache.put(type, typeInfo.node.binding);
130
			this.bindingCache.put(type, typeInfo.node.binding);
124
			this.elementCache.put(typeInfo.node.binding, type);
131
			this.elementCache.put(typeInfo.node.binding, type);
132
		} else {
133
			this.elementWithProblemCache.put(typeInfo.node, type);
125
		}
134
		}
126
		return type;
135
		return type;
127
	}
136
	}
(-)codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java (-3 / +21 lines)
Lines 86-91 Link Here
86
	private boolean hasComputedEnclosingJavaElements;
86
	private boolean hasComputedEnclosingJavaElements;
87
	Map bindingsToNodes;
87
	Map bindingsToNodes;
88
	private Map bindingsToHandles;
88
	private Map bindingsToHandles;
89
	private Map nodesWithProblemsToHandles;
89
	private ICompilationUnit compilationUnit;
90
	private ICompilationUnit compilationUnit;
90
	
91
	
91
	public InternalExtendedCompletionContext(
92
	public InternalExtendedCompletionContext(
Lines 117-122 Link Here
117
			
118
			
118
			HashMap handleToBinding = new HashMap();
119
			HashMap handleToBinding = new HashMap();
119
			HashMap bindingToHandle = new HashMap();
120
			HashMap bindingToHandle = new HashMap();
121
			HashMap nodeWithProblemToHandle = new HashMap();
120
			HashMap handleToInfo = new HashMap();
122
			HashMap handleToInfo = new HashMap();
121
			
123
			
122
			org.eclipse.jdt.core.ICompilationUnit handle = new AssistCompilationUnit(original, this.owner, handleToBinding, handleToInfo);
124
			org.eclipse.jdt.core.ICompilationUnit handle = new AssistCompilationUnit(original, this.owner, handleToBinding, handleToInfo);
Lines 132-137 Link Here
132
						this.assistNode,
134
						this.assistNode,
133
						handleToBinding,
135
						handleToBinding,
134
						bindingToHandle,
136
						bindingToHandle,
137
						nodeWithProblemToHandle,
135
						handleToInfo);
138
						handleToInfo);
136
			
139
			
137
			CompletionElementNotifier notifier =
140
			CompletionElementNotifier notifier =
Lines 149-154 Link Here
149
					new HashMap());
152
					new HashMap());
150
			
153
			
151
			this.bindingsToHandles = bindingToHandle;
154
			this.bindingsToHandles = bindingToHandle;
155
			this.nodesWithProblemsToHandles = nodeWithProblemToHandle;
152
			this.compilationUnit = handle;
156
			this.compilationUnit = handle;
153
		}
157
		}
154
	}
158
	}
Lines 218-229 Link Here
218
		ReferenceContext referenceContext = binding.declaringScope.referenceContext();
222
		ReferenceContext referenceContext = binding.declaringScope.referenceContext();
219
		if (referenceContext instanceof AbstractMethodDeclaration) {
223
		if (referenceContext instanceof AbstractMethodDeclaration) {
220
			AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
224
			AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext;
221
			parent = this.getJavaElementOfCompilationUnit(methodDeclaration.binding);
225
			parent = this.getJavaElementOfCompilationUnit(methodDeclaration, methodDeclaration.binding);
222
		} else if (referenceContext instanceof TypeDeclaration){
226
		} else if (referenceContext instanceof TypeDeclaration){
223
			// Local variable is declared inside an initializer
227
			// Local variable is declared inside an initializer
224
			TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
228
			TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext;
225
			
229
			
226
			IType type = (IType)this.getJavaElementOfCompilationUnit(typeDeclaration.binding);
230
			IType type = (IType)this.getJavaElementOfCompilationUnit(typeDeclaration, typeDeclaration.binding);
227
			if (type != null) {
231
			if (type != null) {
228
				try {
232
				try {
229
					IInitializer[] initializers = type.getInitializers();
233
					IInitializer[] initializers = type.getInitializers();
Lines 268-273 Link Here
268
		return (JavaElement)this.bindingsToHandles.get(binding);
272
		return (JavaElement)this.bindingsToHandles.get(binding);
269
	}
273
	}
270
	
274
	
275
	private JavaElement getJavaElementOfCompilationUnit(ASTNode node, Binding binding) {
276
		if (!this.hasComputedEnclosingJavaElements) {
277
			computeEnclosingJavaElements();
278
		}
279
		if (binding != null) {
280
			if (this.bindingsToHandles == null) return null;
281
			return (JavaElement)this.bindingsToHandles.get(binding);
282
		} else {
283
			if (this.nodesWithProblemsToHandles == null) return null;
284
			return (JavaElement)this.nodesWithProblemsToHandles.get(node);
285
		}
286
	}
287
	
271
	private TypeBinding getTypeFromSignature(String typeSignature, Scope scope) {
288
	private TypeBinding getTypeFromSignature(String typeSignature, Scope scope) {
272
		TypeBinding assignableTypeBinding = null;
289
		TypeBinding assignableTypeBinding = null;
273
		
290
		
Lines 353-359 Link Here
353
			next : for (int i = 0; i < size; i++) {
370
			next : for (int i = 0; i < size; i++) {
354
				LocalVariableBinding binding = (LocalVariableBinding) visibleLocalVariables.elementAt(i);
371
				LocalVariableBinding binding = (LocalVariableBinding) visibleLocalVariables.elementAt(i);
355
				if (assignableTypeBinding != null && !binding.type.isCompatibleWith(assignableTypeBinding)) continue next;
372
				if (assignableTypeBinding != null && !binding.type.isCompatibleWith(assignableTypeBinding)) continue next;
356
				result[elementCount++] = getJavaElement(binding);
373
				JavaElement localVariable = getJavaElement(binding);
374
				if (localVariable != null) result[elementCount++] = localVariable;
357
			}
375
			}
358
		
376
		
359
		}
377
		}
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceType.java (-1 / +12 lines)
Lines 29-34 Link Here
29
	private Map infoCache;
29
	private Map infoCache;
30
	
30
	
31
	private String uniqueKey;
31
	private String uniqueKey;
32
	private boolean isResolved;
32
	
33
	
33
	public AssistSourceType(JavaElement parent, String name, Map bindingCache, Map infoCache) {
34
	public AssistSourceType(JavaElement parent, String name, Map bindingCache, Map infoCache) {
34
		super(parent, name, null);
35
		super(parent, name, null);
Lines 54-67 Link Here
54
		if (this.uniqueKey == null) {
55
		if (this.uniqueKey == null) {
55
			Binding binding = (Binding) this.bindingCache.get(this);
56
			Binding binding = (Binding) this.bindingCache.get(this);
56
			if (binding != null) {
57
			if (binding != null) {
58
				this.isResolved = true;
57
				this.uniqueKey = new String(binding.computeUniqueKey());
59
				this.uniqueKey = new String(binding.computeUniqueKey());
60
			} else {
61
				this.isResolved = false;
62
				try {
63
					this.uniqueKey = getKey(this, false/*don't open*/);
64
				} catch (JavaModelException e) {
65
					// happen only if force open is true
66
					return null;
67
				}
58
			}
68
			}
59
		}
69
		}
60
		return this.uniqueKey;
70
		return this.uniqueKey;
61
	}
71
	}
62
	
72
	
63
	public boolean isResolved() {
73
	public boolean isResolved() {
64
		return getKey() != null;
74
		getKey();
75
		return this.isResolved;
65
	}
76
	}
66
	
77
	
67
	protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) {
78
	protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) {
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceMethod.java (-1 / +12 lines)
Lines 26-31 Link Here
26
	private Map infoCache;
26
	private Map infoCache;
27
	
27
	
28
	private String uniqueKey;
28
	private String uniqueKey;
29
	private boolean isResolved;
29
	
30
	
30
	public AssistSourceMethod(JavaElement parent, String name, String[] parameterTypes, Map bindingCache, Map infoCache) {
31
	public AssistSourceMethod(JavaElement parent, String name, String[] parameterTypes, Map bindingCache, Map infoCache) {
31
		super(parent, name, parameterTypes, null);
32
		super(parent, name, parameterTypes, null);
Lines 44-57 Link Here
44
		if (this.uniqueKey == null) {
45
		if (this.uniqueKey == null) {
45
			Binding binding = (Binding) this.bindingCache.get(this);
46
			Binding binding = (Binding) this.bindingCache.get(this);
46
			if (binding != null) {
47
			if (binding != null) {
48
				this.isResolved = true;
47
				this.uniqueKey = new String(binding.computeUniqueKey());
49
				this.uniqueKey = new String(binding.computeUniqueKey());
50
			} else {
51
				this.isResolved = false;
52
				try {
53
					this.uniqueKey = getKey(this, false/*don't open*/);
54
				} catch (JavaModelException e) {
55
					// happen only if force open is true
56
					return null;
57
				}
48
			}
58
			}
49
		}
59
		}
50
		return this.uniqueKey;
60
		return this.uniqueKey;
51
	}
61
	}
52
	
62
	
53
	public boolean isResolved() {
63
	public boolean isResolved() {
54
		return getKey() != null;
64
		getKey();
65
		return this.isResolved;
55
	}
66
	}
56
	
67
	
57
	protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) {
68
	protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) {
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistSourceField.java (-1 / +12 lines)
Lines 25-30 Link Here
25
	private Map infoCache;
25
	private Map infoCache;
26
	
26
	
27
	private String uniqueKey;
27
	private String uniqueKey;
28
	private boolean isResolved;
28
	
29
	
29
	public AssistSourceField(JavaElement parent, String name, Map bindingCache, Map infoCache) {
30
	public AssistSourceField(JavaElement parent, String name, Map bindingCache, Map infoCache) {
30
		super(parent, name, null);
31
		super(parent, name, null);
Lines 43-56 Link Here
43
		if (this.uniqueKey == null) {
44
		if (this.uniqueKey == null) {
44
			Binding binding = (Binding) this.bindingCache.get(this);
45
			Binding binding = (Binding) this.bindingCache.get(this);
45
			if (binding != null) {
46
			if (binding != null) {
47
				this.isResolved = true;
46
				this.uniqueKey = new String(binding.computeUniqueKey());
48
				this.uniqueKey = new String(binding.computeUniqueKey());
49
			} else {
50
				this.isResolved = false;
51
				try {
52
					this.uniqueKey = getKey(this, false/*don't open*/);
53
				} catch (JavaModelException e) {
54
					// happen only if force open is true
55
					return null;
56
				}
47
			}
57
			}
48
		}
58
		}
49
		return this.uniqueKey;
59
		return this.uniqueKey;
50
	}
60
	}
51
	
61
	
52
	public boolean isResolved() {
62
	public boolean isResolved() {
53
		return getKey() != null;
63
		getKey();
64
		return this.isResolved;
54
	}
65
	}
55
	
66
	
56
	protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) {
67
	protected void toStringInfo(int tab, StringBuffer buffer, Object info,boolean showResolvedInfo) {
(-)src/org/eclipse/jdt/core/tests/model/CompletionContextTests.java (+85 lines)
Lines 4779-4782 Link Here
4779
		"}",
4779
		"}",
4780
		result.context);
4780
		result.context);
4781
}
4781
}
4782
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=230885
4783
public void test0163() throws JavaModelException {
4784
	this.workingCopies = new ICompilationUnit[3];
4785
	this.workingCopies[0] = getWorkingCopy(
4786
		"/Completion/src3/test/X.java",
4787
		"public class Foo  {\n"+
4788
		"\n"+
4789
		"        private void addDepencency(int source, int target, int depth) {\n"+
4790
		"        }\n"+
4791
		"\n"+
4792
		"        private void addDataDependencies(int source) {\n"+
4793
		"                addD/**/\n"+
4794
		"        }\n"+
4795
		"\n"+
4796
		"        private void addDataDependencies(int source) {\n"+
4797
		"        }\n"+
4798
		"}");
4799
	
4800
	
4801
	String str = this.workingCopies[0].getSource();
4802
	int tokenStart = str.lastIndexOf("addD/**/");
4803
	int tokenEnd = tokenStart + "addD".length() - 1;
4804
	int cursorLocation = str.lastIndexOf("addD/**/") + "addD".length();
4805
4806
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "I");
4807
	
4808
	String jclPath = getExternalJCLPathString();
4809
	assertResults(
4810
		"completion offset="+(cursorLocation)+"\n" +
4811
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4812
		"completion token=\"addD\"\n" +
4813
		"completion token kind=TOKEN_KIND_NAME\n" +
4814
		"expectedTypesSignatures=null\n" +
4815
		"expectedTypesKeys=null\n" +
4816
		"completion token location={STATEMENT_START}\n" +
4817
		"visibleElements={\n" +
4818
		"	source [in addDataDependencies(int) [in Foo [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4819
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4820
		"}",
4821
		result.context);
4822
}
4823
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=230885
4824
public void test0164() throws JavaModelException {
4825
	this.workingCopies = new ICompilationUnit[3];
4826
	this.workingCopies[0] = getWorkingCopy(
4827
		"/Completion/src3/test/X.java",
4828
		"public class Foo  {\n"+
4829
		"\n"+
4830
		"        private void addDepencency(int source, int target, int depth) {\n"+
4831
		"        }\n"+
4832
		"\n"+
4833
		"        private int addDataDependencies(int source) {\n"+
4834
		"        }\n"+
4835
		"\n"+
4836
		"        private int addDataDependencies(int source) {\n"+
4837
		"                addD/**/\n"+
4838
		"        }\n"+
4839
		"\n"+
4840
		"        private int addDataDependencies(int source) {\n"+
4841
		"        }\n"+
4842
		"}");
4843
	
4844
	
4845
	String str = this.workingCopies[0].getSource();
4846
	int tokenStart = str.lastIndexOf("addD/**/");
4847
	int tokenEnd = tokenStart + "addD".length() - 1;
4848
	int cursorLocation = str.lastIndexOf("addD/**/") + "addD".length();
4849
4850
	CompletionResult result = contextComplete(this.workingCopies[0], cursorLocation, false, true, "I");
4851
	
4852
	String jclPath = getExternalJCLPathString();
4853
	assertResults(
4854
		"completion offset="+(cursorLocation)+"\n" +
4855
		"completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" +
4856
		"completion token=\"addD\"\n" +
4857
		"completion token kind=TOKEN_KIND_NAME\n" +
4858
		"expectedTypesSignatures=null\n" +
4859
		"expectedTypesKeys=null\n" +
4860
		"completion token location={STATEMENT_START}\n" +
4861
		"visibleElements={\n" +
4862
		"	source [in addDataDependencies(int)#2 [in Foo [in [Working copy] X.java [in test [in src3 [in Completion]]]]]],\n" +
4863
		"	hashCode() {key=Ljava/lang/Object;.hashCode()I} [in Object [in Object.class [in java.lang [in "+jclPath+"]]]],\n" +
4864
		"}",
4865
		result.context);
4866
}
4782
}
4867
}

Return to bug 230885