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

(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-3 / +30 lines)
Lines 56-62 Link Here
56
protected boolean isVirtualInvoke(MethodBinding method, MessageSend messageSend) {
56
protected boolean isVirtualInvoke(MethodBinding method, MessageSend messageSend) {
57
	return !method.isStatic() && !method.isPrivate() && !messageSend.isSuperAccess();
57
	return !method.isStatic() && !method.isPrivate() && !messageSend.isSuperAccess();
58
}
58
}
59
//public int match(ASTNode node, MatchingNodeSet nodeSet) - SKIP IT
59
public int match(ASTNode node, MatchingNodeSet nodeSet) {
60
	int declarationsLevel = IMPOSSIBLE_MATCH;
61
	if (this.pattern.findReferences) {
62
		if (node instanceof ImportReference) {
63
			// With static import, we can have static method reference in import reference
64
			ImportReference importRef = (ImportReference) node;
65
			int length = importRef.tokens.length-1;
66
			if (importRef.isStatic() && !importRef.onDemand && matchesName(this.pattern.selector, importRef.tokens[length])) {
67
				char[][] compoundName = new char[length][];
68
				System.arraycopy(importRef.tokens, 0, compoundName, 0, length);
69
				char[] declaringType = CharOperation.concat(pattern.declaringQualification, pattern.declaringSimpleName, '.');
70
				if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) {
71
					declarationsLevel = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
72
				}
73
			}
74
		}
75
	}
76
	return nodeSet.addMatch(node, declarationsLevel);
77
}
60
//public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
78
//public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
61
//public int match(Expression node, MatchingNodeSet nodeSet) - SKIP IT
79
//public int match(Expression node, MatchingNodeSet nodeSet) - SKIP IT
62
//public int match(FieldDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
80
//public int match(FieldDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
Lines 107-116 Link Here
107
125
108
protected int matchContainer() {
126
protected int matchContainer() {
109
	if (this.pattern.findReferences) {
127
	if (this.pattern.findReferences) {
110
		// need to look almost everywhere to find in javadocs
128
		// need to look almost everywhere to find in javadocs and static import
111
		return CLASS_CONTAINER | METHOD_CONTAINER | FIELD_CONTAINER;
129
		return ALL_CONTAINER;
112
	}
130
	}
113
	return CLASS_CONTAINER;
131
	return CLASS_CONTAINER;
132
}
133
/* (non-Javadoc)
134
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchLevelAndReportImportRef(org.eclipse.jdt.internal.compiler.ast.ImportReference, org.eclipse.jdt.internal.compiler.lookup.Binding, org.eclipse.jdt.internal.core.search.matching.MatchLocator)
135
 * Accept to report match of static field on static import
136
 */
137
protected void matchLevelAndReportImportRef(ImportReference importRef, Binding binding, MatchLocator locator) throws CoreException {
138
	if (importRef.isStatic() && binding instanceof MethodBinding) {
139
		super.matchLevelAndReportImportRef(importRef, binding, locator);
140
	}
114
}
141
}
115
protected int matchMethod(MethodBinding method) {
142
protected int matchMethod(MethodBinding method) {
116
	if (!matchesName(this.pattern.selector, method.selector)) return IMPOSSIBLE_MATCH;
143
	if (!matchesName(this.pattern.selector, method.selector)) return IMPOSSIBLE_MATCH;
(-)search/org/eclipse/jdt/internal/core/search/matching/PackageReferenceLocator.java (+4 lines)
Lines 129-134 Link Here
129
			FieldBinding fieldBinding = (FieldBinding) binding;
129
			FieldBinding fieldBinding = (FieldBinding) binding;
130
			if (!fieldBinding.isStatic()) return;
130
			if (!fieldBinding.isStatic()) return;
131
			refBinding = fieldBinding.declaringClass;
131
			refBinding = fieldBinding.declaringClass;
132
		} else if (binding instanceof MethodBinding) {
133
			MethodBinding methodBinding = (MethodBinding) binding;
134
			if (!methodBinding.isStatic()) return;
135
			refBinding = methodBinding.declaringClass;
132
		} else if (binding instanceof MemberTypeBinding) {
136
		} else if (binding instanceof MemberTypeBinding) {
133
			MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
137
			MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
134
			if (!memberBinding.isStatic()) return;
138
			if (!memberBinding.isStatic()) return;
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java (-3 / +30 lines)
Lines 123-132 Link Here
123
			FieldBinding fieldBinding = (FieldBinding) binding;
123
			FieldBinding fieldBinding = (FieldBinding) binding;
124
			if (!fieldBinding.isStatic()) return;
124
			if (!fieldBinding.isStatic()) return;
125
			refBinding = fieldBinding.declaringClass;
125
			refBinding = fieldBinding.declaringClass;
126
		} else if (binding instanceof MethodBinding) {
127
			MethodBinding methodBinding = (MethodBinding) binding;
128
			if (!methodBinding.isStatic()) return;
129
			refBinding = methodBinding.declaringClass;
126
		} else if (binding instanceof MemberTypeBinding) {
130
		} else if (binding instanceof MemberTypeBinding) {
127
			MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
131
			MemberTypeBinding memberBinding = (MemberTypeBinding) binding;
128
			if (!memberBinding.isStatic()) return;
132
			if (!memberBinding.isStatic()) return;
129
		}
133
		}
134
		// resolve and report
135
		int level = resolveLevel(refBinding);
136
		if (level >= INACCURATE_MATCH) {
137
			matchReportImportRef(
138
				importRef, 
139
				binding, 
140
				locator.createImportHandle(importRef), 
141
				level == ACCURATE_MATCH
142
					? SearchMatch.A_ACCURATE
143
					: SearchMatch.A_INACCURATE,
144
				locator);
145
		}
146
		return;
130
	}
147
	}
131
	super.matchLevelAndReportImportRef(importRef, refBinding, locator);
148
	super.matchLevelAndReportImportRef(importRef, refBinding, locator);
132
}
149
}
Lines 159-169 Link Here
159
	}
176
	}
160
	
177
	
161
	// Try to find best selection for match
178
	// Try to find best selection for match
179
	ReferenceBinding typeBinding = null;
180
	boolean lastButOne = false;
162
	if (binding instanceof ReferenceBinding) {
181
	if (binding instanceof ReferenceBinding) {
163
		ReferenceBinding typeBinding = (ReferenceBinding) binding;
182
		typeBinding = (ReferenceBinding) binding;
183
	} else if (binding instanceof FieldBinding) { // may happen for static import
184
		typeBinding = ((FieldBinding)binding).declaringClass;
185
		lastButOne = importRef.isStatic() && !importRef.onDemand;
186
	} else if (binding instanceof MethodBinding) { // may happen for static import
187
		typeBinding = ((MethodBinding)binding).declaringClass;
188
		lastButOne = importRef.isStatic() && !importRef.onDemand;
189
	}
190
	if (typeBinding != null) {
164
		int lastIndex = importRef.tokens.length - 1;
191
		int lastIndex = importRef.tokens.length - 1;
165
		if (importRef.isStatic() && !importRef.onDemand && !typeBinding.isMemberType()) {
192
		if (lastButOne) {
166
			// for field static import, do not use last token
193
			// for field or method static import, use last but one token
167
			lastIndex--;
194
			lastIndex--;
168
		}
195
		}
169
		if (typeBinding instanceof ProblemReferenceBinding) {
196
		if (typeBinding instanceof ProblemReferenceBinding) {

Return to bug 83319