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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java (-4 / +4 lines)
Lines 46-52 Link Here
46
				FieldPattern fieldPattern = (FieldPattern) this.pattern;
46
				FieldPattern fieldPattern = (FieldPattern) this.pattern;
47
				char[] declaringType = CharOperation.concat(fieldPattern.declaringQualification, fieldPattern.declaringSimpleName, '.');
47
				char[] declaringType = CharOperation.concat(fieldPattern.declaringQualification, fieldPattern.declaringSimpleName, '.');
48
				if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) {
48
				if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) {
49
					declarationsLevel = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
49
					declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
50
				}
50
				}
51
			}
51
			}
52
		}
52
		}
Lines 60-66 Link Here
60
		// must be a write only access with an initializer
60
		// must be a write only access with an initializer
61
		if (this.pattern.writeAccess && !this.pattern.readAccess && node.initialization != null)
61
		if (this.pattern.writeAccess && !this.pattern.readAccess && node.initialization != null)
62
			if (matchesName(this.pattern.name, node.name))
62
			if (matchesName(this.pattern.name, node.name))
63
				referencesLevel = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
63
				referencesLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
64
64
65
	int declarationsLevel = IMPOSSIBLE_MATCH;
65
	int declarationsLevel = IMPOSSIBLE_MATCH;
66
	if (this.pattern.findDeclarations) {
66
	if (this.pattern.findDeclarations) {
Lines 69-75 Link Here
69
			case AbstractVariableDeclaration.ENUM_CONSTANT :
69
			case AbstractVariableDeclaration.ENUM_CONSTANT :
70
				if (matchesName(this.pattern.name, node.name))
70
				if (matchesName(this.pattern.name, node.name))
71
					if (matchesTypeReference(((FieldPattern)this.pattern).typeSimpleName, node.type))
71
					if (matchesTypeReference(((FieldPattern)this.pattern).typeSimpleName, node.type))
72
						declarationsLevel = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
72
						declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
73
				break;
73
				break;
74
		}
74
		}
75
	}
75
	}
Lines 131-137 Link Here
131
protected int matchReference(Reference node, MatchingNodeSet nodeSet, boolean writeOnlyAccess) {
131
protected int matchReference(Reference node, MatchingNodeSet nodeSet, boolean writeOnlyAccess) {
132
	if (node instanceof FieldReference) {
132
	if (node instanceof FieldReference) {
133
		if (matchesName(this.pattern.name, ((FieldReference) node).token))
133
		if (matchesName(this.pattern.name, ((FieldReference) node).token))
134
			return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
134
			return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
135
		return IMPOSSIBLE_MATCH;
135
		return IMPOSSIBLE_MATCH;
136
	}
136
	}
137
	return super.matchReference(node, nodeSet, writeOnlyAccess);
137
	return super.matchReference(node, nodeSet, writeOnlyAccess);
(-)search/org/eclipse/jdt/internal/core/search/matching/DeclarationOfReferencedTypesPattern.java (-1 / +1 lines)
Lines 23-28 Link Here
23
23
24
	this.enclosingElement = enclosingElement;
24
	this.enclosingElement = enclosingElement;
25
	this.knownTypes = new SimpleSet();
25
	this.knownTypes = new SimpleSet();
26
	((InternalSearchPattern)this).mustResolve = true;
26
	this.mustResolve = true;
27
}
27
}
28
}
28
}
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodPattern.java (-5 / +5 lines)
Lines 119-125 Link Here
119
		this.parameterCount = -1;
119
		this.parameterCount = -1;
120
	}
120
	}
121
	this.declaringType = declaringType;
121
	this.declaringType = declaringType;
122
	((InternalSearchPattern)this).mustResolve = mustResolve();
122
	this.mustResolve = mustResolve();
123
}
123
}
124
/*
124
/*
125
 * Instanciate a method pattern with signatures for generics search
125
 * Instanciate a method pattern with signatures for generics search
Lines 195-201 Link Here
195
195
196
	// Store type signatures and arguments for method
196
	// Store type signatures and arguments for method
197
	this.methodArguments = extractMethodArguments(method);
197
	this.methodArguments = extractMethodArguments(method);
198
	if (hasMethodArguments())  ((InternalSearchPattern)this).mustResolve = true;
198
	if (hasMethodArguments())  this.mustResolve = true;
199
}
199
}
200
/*
200
/*
201
 * Instanciate a method pattern with signatures for generics search
201
 * Instanciate a method pattern with signatures for generics search
Lines 253-259 Link Here
253
253
254
	// Store type signatures and arguments for method
254
	// Store type signatures and arguments for method
255
	this.methodArguments = arguments;
255
	this.methodArguments = arguments;
256
	if (hasMethodArguments())  ((InternalSearchPattern)this).mustResolve = true;
256
	if (hasMethodArguments())  this.mustResolve = true;
257
}
257
}
258
public void decodeIndexKey(char[] key) {
258
public void decodeIndexKey(char[] key) {
259
	int last = key.length - 1;
259
	int last = key.length - 1;
Lines 289-295 Link Here
289
boolean hasMethodParameters() {
289
boolean hasMethodParameters() {
290
	return this.methodParameters;
290
	return this.methodParameters;
291
}
291
}
292
boolean isPolymorphicSearch() {
292
public boolean isPolymorphicSearch() {
293
	return this.findReferences;
293
	return this.findReferences;
294
}
294
}
295
public boolean matchesDecodedKey(SearchPattern decodedPattern) {
295
public boolean matchesDecodedKey(SearchPattern decodedPattern) {
Lines 317-323 Link Here
317
			if (this.parameterQualifications[i] != null) return true;
317
			if (this.parameterQualifications[i] != null) return true;
318
	return false;
318
	return false;
319
}
319
}
320
EntryResult[] queryIn(Index index) throws IOException {
320
public EntryResult[] queryIn(Index index) throws IOException {
321
	char[] key = this.selector; // can be null
321
	char[] key = this.selector; // can be null
322
	int matchRule = getMatchRule();
322
	int matchRule = getMatchRule();
323
323
(-)search/org/eclipse/jdt/internal/core/search/matching/AndPattern.java (-2 / +2 lines)
Lines 36-42 Link Here
36
36
37
public AndPattern(SearchPattern leftPattern, SearchPattern rightPattern) {
37
public AndPattern(SearchPattern leftPattern, SearchPattern rightPattern) {
38
	super(AND_PATTERN, combinedMatchRule(leftPattern.getMatchRule(), rightPattern.getMatchRule()));
38
	super(AND_PATTERN, combinedMatchRule(leftPattern.getMatchRule(), rightPattern.getMatchRule()));
39
	((InternalSearchPattern) this).mustResolve = ((InternalSearchPattern) leftPattern).mustResolve || ((InternalSearchPattern) rightPattern).mustResolve;
39
	this.mustResolve = leftPattern.mustResolve || rightPattern.mustResolve;
40
40
41
	SearchPattern[] leftPatterns = leftPattern instanceof AndPattern ? ((AndPattern) leftPattern).patterns : null;
41
	SearchPattern[] leftPatterns = leftPattern instanceof AndPattern ? ((AndPattern) leftPattern).patterns : null;
42
	SearchPattern[] rightPatterns = rightPattern instanceof AndPattern ? ((AndPattern) rightPattern).patterns : null;
42
	SearchPattern[] rightPatterns = rightPattern instanceof AndPattern ? ((AndPattern) rightPattern).patterns : null;
Lines 62-68 Link Here
62
/* (non-Javadoc)
62
/* (non-Javadoc)
63
 * @see org.eclipse.jdt.internal.core.search.matching.InternalSearchPattern#currentPattern()
63
 * @see org.eclipse.jdt.internal.core.search.matching.InternalSearchPattern#currentPattern()
64
 */
64
 */
65
SearchPattern currentPattern() {
65
public SearchPattern currentPattern() {
66
	return this.patterns[this.current++];
66
	return this.patterns[this.current++];
67
}
67
}
68
68
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationLocator.java (-1 / +1 lines)
Lines 33-39 Link Here
33
//public int match(Reference node, MatchingNodeSet nodeSet) - SKIP IT
33
//public int match(Reference node, MatchingNodeSet nodeSet) - SKIP IT
34
public int match(TypeDeclaration node, MatchingNodeSet nodeSet) {
34
public int match(TypeDeclaration node, MatchingNodeSet nodeSet) {
35
	if (this.pattern.simpleName == null || matchesName(this.pattern.simpleName, node.name))
35
	if (this.pattern.simpleName == null || matchesName(this.pattern.simpleName, node.name))
36
		return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
36
		return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
37
37
38
	return IMPOSSIBLE_MATCH;
38
	return IMPOSSIBLE_MATCH;
39
}
39
}
(-)search/org/eclipse/jdt/internal/core/search/matching/QualifiedTypeDeclarationPattern.java (-1 / +1 lines)
Lines 26-32 Link Here
26
	this.simpleName = (this.isCaseSensitive || this.isCamelCase) ? simpleName : CharOperation.toLowerCase(simpleName);
26
	this.simpleName = (this.isCaseSensitive || this.isCamelCase) ? simpleName : CharOperation.toLowerCase(simpleName);
27
	this.typeSuffix = typeSuffix;
27
	this.typeSuffix = typeSuffix;
28
28
29
	((InternalSearchPattern)this).mustResolve = this.qualification != null || typeSuffix != TYPE_SUFFIX;
29
	this.mustResolve = this.qualification != null || typeSuffix != TYPE_SUFFIX;
30
}
30
}
31
public QualifiedTypeDeclarationPattern(char[] qualification, int qualificationMatchRule, char[] simpleName, char typeSuffix, int matchRule) {
31
public QualifiedTypeDeclarationPattern(char[] qualification, int qualificationMatchRule, char[] simpleName, char typeSuffix, int matchRule) {
32
	this(qualification, simpleName, typeSuffix, matchRule);
32
	this(qualification, simpleName, typeSuffix, matchRule);
(-)search/org/eclipse/jdt/internal/core/search/matching/OrPattern.java (-6 / +6 lines)
Lines 29-36 Link Here
29
29
30
	public OrPattern(SearchPattern leftPattern, SearchPattern rightPattern) {
30
	public OrPattern(SearchPattern leftPattern, SearchPattern rightPattern) {
31
		super(Math.max(leftPattern.getMatchRule(), rightPattern.getMatchRule()));
31
		super(Math.max(leftPattern.getMatchRule(), rightPattern.getMatchRule()));
32
		((InternalSearchPattern)this).kind = OR_PATTERN;
32
		this.kind = OR_PATTERN;
33
		((InternalSearchPattern)this).mustResolve = ((InternalSearchPattern) leftPattern).mustResolve || ((InternalSearchPattern) rightPattern).mustResolve;
33
		this.mustResolve = leftPattern.mustResolve || rightPattern.mustResolve;
34
34
35
		SearchPattern[] leftPatterns = leftPattern instanceof OrPattern ? ((OrPattern) leftPattern).patterns : null;
35
		SearchPattern[] leftPatterns = leftPattern instanceof OrPattern ? ((OrPattern) leftPattern).patterns : null;
36
		SearchPattern[] rightPatterns = rightPattern instanceof OrPattern ? ((OrPattern) rightPattern).patterns : null;
36
		SearchPattern[] rightPatterns = rightPattern instanceof OrPattern ? ((OrPattern) rightPattern).patterns : null;
Lines 53-64 Link Here
53
			this.matchCompatibility |= ((JavaSearchPattern) this.patterns[i]).matchCompatibility;
53
			this.matchCompatibility |= ((JavaSearchPattern) this.patterns[i]).matchCompatibility;
54
		}
54
		}
55
	}
55
	}
56
	void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor progressMonitor) throws IOException {
56
	public void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor progressMonitor) throws IOException {
57
		// per construction, OR pattern can only be used with a PathCollector (which already gather results using a set)
57
		// per construction, OR pattern can only be used with a PathCollector (which already gather results using a set)
58
		try {
58
		try {
59
			index.startQuery();
59
			index.startQuery();
60
			for (int i = 0, length = this.patterns.length; i < length; i++)
60
			for (int i = 0, length = this.patterns.length; i < length; i++)
61
				((InternalSearchPattern)this.patterns[i]).findIndexMatches(index, requestor, participant, scope, progressMonitor);
61
				this.patterns[i].findIndexMatches(index, requestor, participant, scope, progressMonitor);
62
		} finally {
62
		} finally {
63
			index.stopQuery();
63
			index.stopQuery();
64
		}
64
		}
Lines 72-80 Link Here
72
		return (this.matchCompatibility & R_ERASURE_MATCH) != 0;
72
		return (this.matchCompatibility & R_ERASURE_MATCH) != 0;
73
	}
73
	}
74
74
75
	boolean isPolymorphicSearch() {
75
	public boolean isPolymorphicSearch() {
76
		for (int i = 0, length = this.patterns.length; i < length; i++)
76
		for (int i = 0, length = this.patterns.length; i < length; i++)
77
			if (((InternalSearchPattern) this.patterns[i]).isPolymorphicSearch()) return true;
77
			if (this.patterns[i].isPolymorphicSearch()) return true;
78
		return false;
78
		return false;
79
	}
79
	}
80
80
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-9 / +9 lines)
Lines 166-172 Link Here
166
	}
166
	}
167
}
167
}
168
168
169
public static SearchDocument[] addWorkingCopies(InternalSearchPattern pattern, SearchDocument[] indexMatches, org.eclipse.jdt.core.ICompilationUnit[] copies, SearchParticipant participant) {
169
public static SearchDocument[] addWorkingCopies(SearchPattern pattern, SearchDocument[] indexMatches, org.eclipse.jdt.core.ICompilationUnit[] copies, SearchParticipant participant) {
170
	if (copies == null) return indexMatches;
170
	if (copies == null) return indexMatches;
171
	// working copies take precedence over corresponding compilation units
171
	// working copies take precedence over corresponding compilation units
172
	HashMap workingCopyDocuments = workingCopiesThatCanSeeFocus(copies, pattern.focus, pattern.isPolymorphicSearch(), participant);
172
	HashMap workingCopyDocuments = workingCopiesThatCanSeeFocus(copies, pattern.focus, pattern.isPolymorphicSearch(), participant);
Lines 200-206 Link Here
200
	return matches;
200
	return matches;
201
}
201
}
202
202
203
public static void setFocus(InternalSearchPattern pattern, IJavaElement focus) {
203
public static void setFocus(SearchPattern pattern, IJavaElement focus) {
204
	pattern.focus = focus;
204
	pattern.focus = focus;
205
}
205
}
206
206
Lines 265-271 Link Here
265
/**
265
/**
266
 * Query a given index for matching entries. Assumes the sender has opened the index and will close when finished.
266
 * Query a given index for matching entries. Assumes the sender has opened the index and will close when finished.
267
 */
267
 */
268
public static void findIndexMatches(InternalSearchPattern pattern, Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor monitor) throws IOException {
268
public static void findIndexMatches(SearchPattern pattern, Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor monitor) throws IOException {
269
	pattern.findIndexMatches(index, requestor, participant, scope, monitor);
269
	pattern.findIndexMatches(index, requestor, participant, scope, monitor);
270
}
270
}
271
271
Lines 276-282 Link Here
276
	return element;
276
	return element;
277
}
277
}
278
278
279
public static IJavaElement projectOrJarFocus(InternalSearchPattern pattern) {
279
public static IJavaElement projectOrJarFocus(SearchPattern pattern) {
280
	return pattern == null || pattern.focus == null ? null : getProjectOrJar(pattern.focus);
280
	return pattern == null || pattern.focus == null ? null : getProjectOrJar(pattern.focus);
281
}
281
}
282
282
Lines 967-973 Link Here
967
	initialize(javaProject, length);
967
	initialize(javaProject, length);
968
968
969
	// create and resolve binding (equivalent to beginCompilation() in Compiler)
969
	// create and resolve binding (equivalent to beginCompilation() in Compiler)
970
	boolean mustResolvePattern = ((InternalSearchPattern)this.pattern).mustResolve;
970
	boolean mustResolvePattern = this.pattern.mustResolve;
971
	boolean mustResolve = mustResolvePattern;
971
	boolean mustResolve = mustResolvePattern;
972
	this.patternLocator.mayBeGeneric = this.options.sourceLevel >= ClassFileConstants.JDK1_5;
972
	this.patternLocator.mayBeGeneric = this.options.sourceLevel >= ClassFileConstants.JDK1_5;
973
	boolean bindingsWereCreated = mustResolve;
973
	boolean bindingsWereCreated = mustResolve;
Lines 1206-1212 Link Here
1206
				}
1206
				}
1207
				previousJavaProject = javaProject;
1207
				previousJavaProject = javaProject;
1208
			}
1208
			}
1209
			matchSet.add(new PossibleMatch(this, resource, openable, searchDocument, ((InternalSearchPattern) this.pattern).mustResolve));
1209
			matchSet.add(new PossibleMatch(this, resource, openable, searchDocument,this.pattern.mustResolve));
1210
		}
1210
		}
1211
1211
1212
		// last project
1212
		// last project
Lines 1250-1256 Link Here
1250
			locatePackageDeclarations(patterns[i], participant, projects);
1250
			locatePackageDeclarations(patterns[i], participant, projects);
1251
		}
1251
		}
1252
	} else if (searchPattern instanceof PackageDeclarationPattern) {
1252
	} else if (searchPattern instanceof PackageDeclarationPattern) {
1253
		IJavaElement focus = ((InternalSearchPattern) searchPattern).focus;
1253
		IJavaElement focus = searchPattern.focus;
1254
		if (focus != null) {
1254
		if (focus != null) {
1255
			if (encloses(focus)) {
1255
			if (encloses(focus)) {
1256
				SearchMatch match = new PackageDeclarationMatch(focus.getAncestor(IJavaElement.PACKAGE_FRAGMENT), SearchMatch.A_ACCURATE, -1, -1, participant, focus.getResource());
1256
				SearchMatch match = new PackageDeclarationMatch(focus.getAncestor(IJavaElement.PACKAGE_FRAGMENT), SearchMatch.A_ACCURATE, -1, -1, participant, focus.getResource());
Lines 1593-1599 Link Here
1593
		// Move getMethodBodies to #parseAndBuildings(...) method to allow possible match resolution management
1593
		// Move getMethodBodies to #parseAndBuildings(...) method to allow possible match resolution management
1594
		//getMethodBodies(unit);
1594
		//getMethodBodies(unit);
1595
1595
1596
		boolean mustResolve = (((InternalSearchPattern)this.pattern).mustResolve || possibleMatch.nodeSet.mustResolve);
1596
		boolean mustResolve = (this.pattern.mustResolve || possibleMatch.nodeSet.mustResolve);
1597
		if (bindingsWereCreated && mustResolve) {
1597
		if (bindingsWereCreated && mustResolve) {
1598
			if (unit.types != null) {
1598
			if (unit.types != null) {
1599
				if (BasicSearchEngine.VERBOSE)
1599
				if (BasicSearchEngine.VERBOSE)
Lines 2139-2145 Link Here
2139
					enclosingElement = createHandle(method, parent);
2139
					enclosingElement = createHandle(method, parent);
2140
				}
2140
				}
2141
				if (encloses(enclosingElement)) {
2141
				if (encloses(enclosingElement)) {
2142
					if (((InternalSearchPattern)this.pattern).mustResolve) {
2142
					if (this.pattern.mustResolve) {
2143
						// Visit only if the pattern must resolve
2143
						// Visit only if the pattern must resolve
2144
						MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, nodes, nodeSet, this);
2144
						MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, nodes, nodeSet, this);
2145
						method.traverse(declarationVisitor, (ClassScope) null);
2145
						method.traverse(declarationVisitor, (ClassScope) null);
(-)search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java (-2 / +2 lines)
Lines 35-41 Link Here
35
//public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
35
//public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
36
public int match(TypeReference node, MatchingNodeSet nodeSet) {
36
public int match(TypeReference node, MatchingNodeSet nodeSet) {
37
	if (this.pattern.superSimpleName == null)
37
	if (this.pattern.superSimpleName == null)
38
		return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
38
		return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
39
39
40
	char[] typeRefSimpleName = null;
40
	char[] typeRefSimpleName = null;
41
	if (node instanceof SingleTypeReference) {
41
	if (node instanceof SingleTypeReference) {
Lines 45-51 Link Here
45
		typeRefSimpleName = tokens[tokens.length-1];
45
		typeRefSimpleName = tokens[tokens.length-1];
46
	}
46
	}
47
	if (matchesName(this.pattern.superSimpleName, typeRefSimpleName))
47
	if (matchesName(this.pattern.superSimpleName, typeRefSimpleName))
48
		return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
48
		return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
49
49
50
	return IMPOSSIBLE_MATCH;
50
	return IMPOSSIBLE_MATCH;
51
}
51
}
(-)search/org/eclipse/jdt/internal/core/search/matching/JavaSearchPattern.java (-1 / +1 lines)
Lines 81-87 Link Here
81
81
82
	protected JavaSearchPattern(int patternKind, int matchRule) {
82
	protected JavaSearchPattern(int patternKind, int matchRule) {
83
		super(matchRule);
83
		super(matchRule);
84
		((InternalSearchPattern)this).kind = patternKind;
84
		this.kind = patternKind;
85
		// Use getMatchRule() instead of matchRule as super constructor may modify its value
85
		// Use getMatchRule() instead of matchRule as super constructor may modify its value
86
		// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=81377
86
		// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=81377
87
		int rule = getMatchRule();
87
		int rule = getMatchRule();
(-)search/org/eclipse/jdt/internal/core/search/matching/IntersectingPattern.java (-3 / +3 lines)
Lines 35-42 Link Here
35
	try {
35
	try {
36
		index.startQuery();
36
		index.startQuery();
37
		do {
37
		do {
38
			SearchPattern pattern = ((InternalSearchPattern) this).currentPattern();
38
			SearchPattern pattern = currentPattern();
39
			EntryResult[] entries = ((InternalSearchPattern)pattern).queryIn(index);
39
			EntryResult[] entries = pattern.queryIn(index);
40
			if (entries == null) return;
40
			if (entries == null) return;
41
41
42
			SearchPattern decodedResult = pattern.getBlankPattern();
42
			SearchPattern decodedResult = pattern.getBlankPattern();
Lines 71-77 Link Here
71
	Object[] names = intersectedNames.values;
71
	Object[] names = intersectedNames.values;
72
	for (int i = 0, l = names.length; i < l; i++)
72
	for (int i = 0, l = names.length; i < l; i++)
73
		if (names[i] != null)
73
		if (names[i] != null)
74
			((InternalSearchPattern) this).acceptMatch((String) names[i], containerPath, separator, null/*no pattern*/, requestor, participant, scope); // AndPatterns cannot provide the decoded result
74
			acceptMatch((String) names[i], containerPath, separator, null/*no pattern*/, requestor, participant, scope); // AndPatterns cannot provide the decoded result
75
}
75
}
76
/**
76
/**
77
 * Returns whether another query must be done.
77
 * Returns whether another query must be done.
(-)search/org/eclipse/jdt/internal/core/search/matching/DeclarationOfAccessedFieldsPattern.java (-1 / +1 lines)
Lines 24-29 Link Here
24
24
25
	this.enclosingElement = enclosingElement;
25
	this.enclosingElement = enclosingElement;
26
	this.knownFields = new SimpleSet();
26
	this.knownFields = new SimpleSet();
27
	((InternalSearchPattern)this).mustResolve = true;
27
	this.mustResolve = true;
28
}
28
}
29
}
29
}
(-)search/org/eclipse/jdt/internal/core/search/matching/VariableLocator.java (-1 / +1 lines)
Lines 56-62 Link Here
56
protected int matchReference(Reference node, MatchingNodeSet nodeSet, boolean writeOnlyAccess) {
56
protected int matchReference(Reference node, MatchingNodeSet nodeSet, boolean writeOnlyAccess) {
57
	if (node instanceof NameReference) {
57
	if (node instanceof NameReference) {
58
		if (this.pattern.name == null) {
58
		if (this.pattern.name == null) {
59
			return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
59
			return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
60
		} else if (node instanceof SingleNameReference) {
60
		} else if (node instanceof SingleNameReference) {
61
			if (matchesName(this.pattern.name, ((SingleNameReference) node).token))
61
			if (matchesName(this.pattern.name, ((SingleNameReference) node).token))
62
				return nodeSet.addMatch(node, POSSIBLE_MATCH);
62
				return nodeSet.addMatch(node, POSSIBLE_MATCH);
(-)search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferencePattern.java (-3 / +3 lines)
Lines 152-158 Link Here
152
152
153
	this.superQualification = this.isCaseSensitive ? superQualification : CharOperation.toLowerCase(superQualification);
153
	this.superQualification = this.isCaseSensitive ? superQualification : CharOperation.toLowerCase(superQualification);
154
	this.superSimpleName = (this.isCaseSensitive || this.isCamelCase) ? superSimpleName : CharOperation.toLowerCase(superSimpleName);
154
	this.superSimpleName = (this.isCaseSensitive || this.isCamelCase) ? superSimpleName : CharOperation.toLowerCase(superSimpleName);
155
	((InternalSearchPattern)this).mustResolve = superQualification != null;
155
	this.mustResolve = superQualification != null;
156
	this.superRefKind = superRefKind;
156
	this.superRefKind = superRefKind;
157
}
157
}
158
public SuperTypeReferencePattern(
158
public SuperTypeReferencePattern(
Lines 164-170 Link Here
164
164
165
	this(superQualification, superSimpleName, superRefKind, matchRule);
165
	this(superQualification, superSimpleName, superRefKind, matchRule);
166
	this.typeSuffix = typeSuffix;
166
	this.typeSuffix = typeSuffix;
167
	((InternalSearchPattern)this).mustResolve = superQualification != null || typeSuffix != TYPE_SUFFIX;
167
	this.mustResolve = superQualification != null || typeSuffix != TYPE_SUFFIX;
168
}
168
}
169
SuperTypeReferencePattern(int matchRule) {
169
SuperTypeReferencePattern(int matchRule) {
170
	super(SUPER_REF_PATTERN, matchRule);
170
	super(SUPER_REF_PATTERN, matchRule);
Lines 241-247 Link Here
241
241
242
	return matchesName(this.superSimpleName, pattern.superSimpleName);
242
	return matchesName(this.superSimpleName, pattern.superSimpleName);
243
}
243
}
244
EntryResult[] queryIn(Index index) throws IOException {
244
public EntryResult[] queryIn(Index index) throws IOException {
245
	char[] key = this.superSimpleName; // can be null
245
	char[] key = this.superSimpleName; // can be null
246
	int matchRule = getMatchRule();
246
	int matchRule = getMatchRule();
247
247
(-)search/org/eclipse/jdt/internal/core/search/matching/FieldPattern.java (-1 / +1 lines)
Lines 49-55 Link Here
49
	this.typeQualification = this.isCaseSensitive ? typeQualification : CharOperation.toLowerCase(typeQualification);
49
	this.typeQualification = this.isCaseSensitive ? typeQualification : CharOperation.toLowerCase(typeQualification);
50
	this.typeSimpleName = (this.isCaseSensitive || this.isCamelCase) ? typeSimpleName : CharOperation.toLowerCase(typeSimpleName);
50
	this.typeSimpleName = (this.isCaseSensitive || this.isCamelCase) ? typeSimpleName : CharOperation.toLowerCase(typeSimpleName);
51
51
52
	((InternalSearchPattern)this).mustResolve = mustResolve();
52
	this.mustResolve = mustResolve();
53
}
53
}
54
/*
54
/*
55
 * Instantiate a field pattern with additional information for generic search
55
 * Instantiate a field pattern with additional information for generic search
(-)search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java (-7 / +7 lines)
Lines 38-44 Link Here
38
38
39
	if (!matchParametersCount(node, ((ExplicitConstructorCall) node).arguments)) return IMPOSSIBLE_MATCH;
39
	if (!matchParametersCount(node, ((ExplicitConstructorCall) node).arguments)) return IMPOSSIBLE_MATCH;
40
40
41
	return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
41
	return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
42
}
42
}
43
public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) {
43
public int match(ConstructorDeclaration node, MatchingNodeSet nodeSet) {
44
	int referencesLevel = this.pattern.findReferences ? matchLevelForReferences(node) : IMPOSSIBLE_MATCH;
44
	int referencesLevel = this.pattern.findReferences ? matchLevelForReferences(node) : IMPOSSIBLE_MATCH;
Lines 58-64 Link Here
58
58
59
	if (!matchParametersCount(node, allocation.arguments)) return IMPOSSIBLE_MATCH;
59
	if (!matchParametersCount(node, allocation.arguments)) return IMPOSSIBLE_MATCH;
60
60
61
	return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
61
	return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
62
}
62
}
63
public int match(FieldDeclaration field, MatchingNodeSet nodeSet) {
63
public int match(FieldDeclaration field, MatchingNodeSet nodeSet) {
64
	if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
64
	if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
Lines 73-79 Link Here
73
73
74
	if (!matchParametersCount(field, allocation.arguments)) return IMPOSSIBLE_MATCH;
74
	if (!matchParametersCount(field, allocation.arguments)) return IMPOSSIBLE_MATCH;
75
75
76
	return nodeSet.addMatch(field, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
76
	return nodeSet.addMatch(field, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
77
}
77
}
78
//public int match(MethodDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
78
//public int match(MethodDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
79
/**
79
/**
Lines 83-89 Link Here
83
public int match(MessageSend msgSend, MatchingNodeSet nodeSet)  {
83
public int match(MessageSend msgSend, MatchingNodeSet nodeSet)  {
84
	if ((msgSend.bits & ASTNode.InsideJavadoc) == 0) return IMPOSSIBLE_MATCH;
84
	if ((msgSend.bits & ASTNode.InsideJavadoc) == 0) return IMPOSSIBLE_MATCH;
85
	if (this.pattern.declaringSimpleName == null || CharOperation.equals(msgSend.selector, this.pattern.declaringSimpleName)) {
85
	if (this.pattern.declaringSimpleName == null || CharOperation.equals(msgSend.selector, this.pattern.declaringSimpleName)) {
86
		return nodeSet.addMatch(msgSend, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
86
		return nodeSet.addMatch(msgSend, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
87
	}
87
	}
88
	return IMPOSSIBLE_MATCH;
88
	return IMPOSSIBLE_MATCH;
89
}
89
}
Lines 92-98 Link Here
92
	if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
92
	if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
93
93
94
	// need to look for a generated default constructor
94
	// need to look for a generated default constructor
95
	return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
95
	return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
96
}
96
}
97
//public int match(TypeReference node, MatchingNodeSet nodeSet) - SKIP IT
97
//public int match(TypeReference node, MatchingNodeSet nodeSet) - SKIP IT
98
98
Lines 146-152 Link Here
146
		int argsLength = args == null ? 0 : args.length;
146
		int argsLength = args == null ? 0 : args.length;
147
		if (length != argsLength) return IMPOSSIBLE_MATCH;
147
		if (length != argsLength) return IMPOSSIBLE_MATCH;
148
	}
148
	}
149
	return ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
149
	return this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
150
}
150
}
151
protected int matchLevelForDeclarations(ConstructorDeclaration constructor) {
151
protected int matchLevelForDeclarations(ConstructorDeclaration constructor) {
152
	// constructor name is stored in selector field
152
	// constructor name is stored in selector field
Lines 165-171 Link Here
165
		if (constructor.typeParameters == null || constructor.typeParameters.length != this.pattern.constructorArguments.length) return IMPOSSIBLE_MATCH;
165
		if (constructor.typeParameters == null || constructor.typeParameters.length != this.pattern.constructorArguments.length) return IMPOSSIBLE_MATCH;
166
	}
166
	}
167
167
168
	return ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
168
	return this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
169
}
169
}
170
boolean matchParametersCount(ASTNode node, Expression[] args) {
170
boolean matchParametersCount(ASTNode node, Expression[] args) {
171
	if (this.pattern.parameterSimpleNames != null && (!this.pattern.varargs || ((node.bits & ASTNode.InsideJavadoc) != 0))) {
171
	if (this.pattern.parameterSimpleNames != null && (!this.pattern.varargs || ((node.bits & ASTNode.InsideJavadoc) != 0))) {
(-)search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java (-2 / +2 lines)
Lines 64-70 Link Here
64
public static final int RULE_MASK = RAW_MASK; // no other values for the while...
64
public static final int RULE_MASK = RAW_MASK; // no other values for the while...
65
65
66
public static PatternLocator patternLocator(SearchPattern pattern) {
66
public static PatternLocator patternLocator(SearchPattern pattern) {
67
	switch (((InternalSearchPattern)pattern).kind) {
67
	switch (pattern.kind) {
68
		case IIndexConstants.PKG_REF_PATTERN :
68
		case IIndexConstants.PKG_REF_PATTERN :
69
			return new PackageReferenceLocator((PackageReferencePattern) pattern);
69
			return new PackageReferenceLocator((PackageReferencePattern) pattern);
70
		case IIndexConstants.PKG_DECL_PATTERN :
70
		case IIndexConstants.PKG_DECL_PATTERN :
Lines 120-126 Link Here
120
	this.isErasureMatch = (matchRule & SearchPattern.R_ERASURE_MATCH) != 0;
120
	this.isErasureMatch = (matchRule & SearchPattern.R_ERASURE_MATCH) != 0;
121
	this.isEquivalentMatch = (matchRule & SearchPattern.R_EQUIVALENT_MATCH) != 0;
121
	this.isEquivalentMatch = (matchRule & SearchPattern.R_EQUIVALENT_MATCH) != 0;
122
	this.matchMode = matchRule & JavaSearchPattern.MATCH_MODE_MASK;
122
	this.matchMode = matchRule & JavaSearchPattern.MATCH_MODE_MASK;
123
	this.mustResolve = ((InternalSearchPattern)pattern).mustResolve;
123
	this.mustResolve = pattern.mustResolve;
124
}
124
}
125
/*
125
/*
126
 * Clear caches
126
 * Clear caches
(-)search/org/eclipse/jdt/internal/core/search/matching/InternalSearchPattern.java (-103 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core.search.matching;
12
13
import java.io.IOException;
14
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.search.*;
18
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
19
import org.eclipse.jdt.internal.core.index.*;
20
import org.eclipse.jdt.internal.core.search.*;
21
22
/**
23
 * Internal search pattern implementation
24
 */
25
public abstract class InternalSearchPattern {
26
27
	/**
28
	 *  The focus element (used for reference patterns)
29
	 */
30
	IJavaElement focus;
31
32
	int kind;
33
	boolean mustResolve = true;
34
35
	void acceptMatch(String relativePath, String containerPath, char separator, SearchPattern pattern, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope) {
36
37
		if (scope instanceof JavaSearchScope) {
38
			JavaSearchScope javaSearchScope = (JavaSearchScope) scope;
39
			// Get document path access restriction from java search scope
40
			// Note that requestor has to verify if needed whether the document violates the access restriction or not
41
			AccessRuleSet access = javaSearchScope.getAccessRuleSet(relativePath, containerPath);
42
			if (access != JavaSearchScope.NOT_ENCLOSED) { // scope encloses the document path
43
				StringBuffer documentPath = new StringBuffer(containerPath.length() + 1 + relativePath.length());
44
				documentPath.append(containerPath);
45
				documentPath.append(separator);
46
				documentPath.append(relativePath);
47
				if (!requestor.acceptIndexMatch(documentPath.toString(), pattern, participant, access))
48
					throw new OperationCanceledException();
49
			}
50
		} else {
51
			StringBuffer buffer = new StringBuffer(containerPath.length() + 1 + relativePath.length());
52
			buffer.append(containerPath);
53
			buffer.append(separator);
54
			buffer.append(relativePath);
55
			String documentPath = buffer.toString();
56
			if (scope.encloses(documentPath))
57
				if (!requestor.acceptIndexMatch(documentPath, pattern, participant, null))
58
					throw new OperationCanceledException();
59
60
		}
61
	}
62
	SearchPattern currentPattern() {
63
		return (SearchPattern) this;
64
	}
65
	/**
66
	 * Query a given index for matching entries. Assumes the sender has opened the index and will close when finished.
67
	 */
68
	void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor monitor) throws IOException {
69
		if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
70
		try {
71
			index.startQuery();
72
			SearchPattern pattern = currentPattern();
73
			EntryResult[] entries = ((InternalSearchPattern)pattern).queryIn(index);
74
			if (entries == null) return;
75
76
			SearchPattern decodedResult = pattern.getBlankPattern();
77
			String containerPath = index.containerPath;
78
			char separator = index.separator;
79
			for (int i = 0, l = entries.length; i < l; i++) {
80
				if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
81
82
				EntryResult entry = entries[i];
83
				decodedResult.decodeIndexKey(entry.getWord());
84
				if (pattern.matchesDecodedKey(decodedResult)) {
85
					// TODO (kent) some clients may not need the document names
86
					String[] names = entry.getDocumentNames(index);
87
					for (int j = 0, n = names.length; j < n; j++)
88
						acceptMatch(names[j], containerPath, separator, decodedResult, requestor, participant, scope);
89
				}
90
			}
91
		} finally {
92
			index.stopQuery();
93
		}
94
	}
95
	boolean isPolymorphicSearch() {
96
		return false;
97
	}
98
	EntryResult[] queryIn(Index index) throws IOException {
99
		SearchPattern pattern = (SearchPattern) this;
100
		return index.query(pattern.getIndexCategories(), pattern.getIndexKey(), pattern.getMatchRule());
101
	}
102
103
}
(-)search/org/eclipse/jdt/internal/core/search/matching/PackageReferenceLocator.java (-2 / +2 lines)
Lines 312-320 Link Here
312
		}
312
		}
313
	}
313
	}
314
	if (compoundName != null && matchesName(this.pattern.pkgName, CharOperation.concatWith(compoundName, '.'))) {
314
	if (compoundName != null && matchesName(this.pattern.pkgName, CharOperation.concatWith(compoundName, '.'))) {
315
		if (((InternalSearchPattern) this.pattern).focus instanceof IPackageFragment && binding instanceof ReferenceBinding) {
315
		if (this.pattern.focus instanceof IPackageFragment && binding instanceof ReferenceBinding) {
316
			// check that type is located inside this instance of a package fragment
316
			// check that type is located inside this instance of a package fragment
317
			if (!isDeclaringPackageFragment((IPackageFragment)((InternalSearchPattern) this.pattern).focus, (ReferenceBinding)binding))
317
			if (!isDeclaringPackageFragment((IPackageFragment) this.pattern.focus, (ReferenceBinding)binding))
318
				return IMPOSSIBLE_MATCH;
318
				return IMPOSSIBLE_MATCH;
319
		}
319
		}
320
		return ACCURATE_MATCH;
320
		return ACCURATE_MATCH;
(-)search/org/eclipse/jdt/internal/core/search/matching/PackageDeclarationPattern.java (-1 / +1 lines)
Lines 20-26 Link Here
20
	super(PKG_DECL_PATTERN, matchRule);
20
	super(PKG_DECL_PATTERN, matchRule);
21
	this.pkgName = pkgName;
21
	this.pkgName = pkgName;
22
}
22
}
23
EntryResult[] queryIn(Index index) {
23
public EntryResult[] queryIn(Index index) {
24
	// package declarations are not indexed
24
	// package declarations are not indexed
25
	return null;
25
	return null;
26
}
26
}
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java (-4 / +4 lines)
Lines 66-72 Link Here
66
	if (!(node instanceof NameReference)) return IMPOSSIBLE_MATCH;
66
	if (!(node instanceof NameReference)) return IMPOSSIBLE_MATCH;
67
67
68
	if (this.pattern.simpleName == null)
68
	if (this.pattern.simpleName == null)
69
		return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
69
		return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
70
70
71
	if (node instanceof SingleNameReference) {
71
	if (node instanceof SingleNameReference) {
72
		if (matchesName(this.pattern.simpleName, ((SingleNameReference) node).token))
72
		if (matchesName(this.pattern.simpleName, ((SingleNameReference) node).token))
Lines 83-93 Link Here
83
//public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
83
//public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
84
public int match(TypeReference node, MatchingNodeSet nodeSet) {
84
public int match(TypeReference node, MatchingNodeSet nodeSet) {
85
	if (this.pattern.simpleName == null)
85
	if (this.pattern.simpleName == null)
86
		return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
86
		return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
87
87
88
	if (node instanceof SingleTypeReference) {
88
	if (node instanceof SingleTypeReference) {
89
		if (matchesName(this.pattern.simpleName, ((SingleTypeReference) node).token))
89
		if (matchesName(this.pattern.simpleName, ((SingleTypeReference) node).token))
90
			return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
90
			return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
91
	} else {
91
	} else {
92
		char[][] tokens = ((QualifiedTypeReference) node).tokens;
92
		char[][] tokens = ((QualifiedTypeReference) node).tokens;
93
		for (int i = 0, max = tokens.length; i < max; i++)
93
		for (int i = 0, max = tokens.length; i < max; i++)
Lines 485-491 Link Here
485
	if (refBinding.isLocalType()) {
485
	if (refBinding.isLocalType()) {
486
		// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=82673
486
		// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=82673
487
		LocalTypeBinding local = (LocalTypeBinding) refBinding.erasure();
487
		LocalTypeBinding local = (LocalTypeBinding) refBinding.erasure();
488
		IJavaElement focus = ((InternalSearchPattern)this.pattern).focus;
488
		IJavaElement focus = this.pattern.focus;
489
		if (focus != null && local.enclosingMethod != null && focus.getParent().getElementType() == IJavaElement.METHOD) {
489
		if (focus != null && local.enclosingMethod != null && focus.getParent().getElementType() == IJavaElement.METHOD) {
490
			IMethod method = (IMethod) focus.getParent();
490
			IMethod method = (IMethod) focus.getParent();
491
			if (!CharOperation.equals(local.enclosingMethod.selector, method.getElementName().toCharArray())) {
491
			if (!CharOperation.equals(local.enclosingMethod.selector, method.getElementName().toCharArray())) {
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeReferencePattern.java (-1 / +1 lines)
Lines 52-58 Link Here
52
		else
52
		else
53
			this.segmentsSize = this.segments.length;
53
			this.segmentsSize = this.segments.length;
54
54
55
		((InternalSearchPattern)this).mustResolve = true; // always resolve (in case of a simple name reference being a potential match)
55
		this.mustResolve = true; // always resolve (in case of a simple name reference being a potential match)
56
	}
56
	}
57
	/*
57
	/*
58
	 * Instantiate a type reference pattern with additional information for generics search
58
	 * Instantiate a type reference pattern with additional information for generics search
(-)search/org/eclipse/jdt/internal/core/search/matching/MultiTypeDeclarationPattern.java (-2 / +2 lines)
Lines 59-65 Link Here
59
	}
59
	}
60
	this.typeSuffix = typeSuffix;
60
	this.typeSuffix = typeSuffix;
61
61
62
	((InternalSearchPattern)this).mustResolve = typeSuffix != TYPE_SUFFIX; // only used to report type declarations, not their positions
62
	this.mustResolve = typeSuffix != TYPE_SUFFIX; // only used to report type declarations, not their positions
63
}
63
}
64
MultiTypeDeclarationPattern(int matchRule) {
64
MultiTypeDeclarationPattern(int matchRule) {
65
	super(TYPE_DECL_PATTERN, matchRule);
65
	super(TYPE_DECL_PATTERN, matchRule);
Lines 104-110 Link Here
104
			break;
104
			break;
105
	return count < max;
105
	return count < max;
106
}
106
}
107
EntryResult[] queryIn(Index index) throws IOException {
107
public EntryResult[] queryIn(Index index) throws IOException {
108
	if (this.simpleNames == null) {
108
	if (this.simpleNames == null) {
109
		// if no simple names then return all possible ones from index
109
		// if no simple names then return all possible ones from index
110
		return index.query(getIndexCategories(), null, -1); // match rule is irrelevant when the key is null
110
		return index.query(getIndexCategories(), null, -1); // match rule is irrelevant when the key is null
(-)search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java (-3 / +3 lines)
Lines 174-180 Link Here
174
174
175
	// Report as many accurate matches as possible
175
	// Report as many accurate matches as possible
176
	int accuracy = SearchMatch.A_ACCURATE;
176
	int accuracy = SearchMatch.A_ACCURATE;
177
	boolean mustResolve = ((InternalSearchPattern)pattern).mustResolve;
177
	boolean mustResolve = pattern.mustResolve;
178
	if (mustResolve) {
178
	if (mustResolve) {
179
		BinaryTypeBinding binding = locator.cacheBinaryType(binaryType, info);
179
		BinaryTypeBinding binding = locator.cacheBinaryType(binaryType, info);
180
		if (binding != null) {
180
		if (binding != null) {
Lines 309-315 Link Here
309
 */
309
 */
310
private void matchAnnotations(SearchPattern pattern, MatchLocator locator, ClassFile classFile, IBinaryType binaryType) throws CoreException {
310
private void matchAnnotations(SearchPattern pattern, MatchLocator locator, ClassFile classFile, IBinaryType binaryType) throws CoreException {
311
	// Only process TypeReference patterns
311
	// Only process TypeReference patterns
312
	switch (((InternalSearchPattern)pattern).kind) {
312
	switch (pattern.kind) {
313
		case TYPE_REF_PATTERN:
313
		case TYPE_REF_PATTERN:
314
			break;
314
			break;
315
		case OR_PATTERN:
315
		case OR_PATTERN:
Lines 373-379 Link Here
373
 * Default is to return false.
373
 * Default is to return false.
374
 */
374
 */
375
boolean matchBinary(SearchPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) {
375
boolean matchBinary(SearchPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) {
376
	switch (((InternalSearchPattern)pattern).kind) {
376
	switch (pattern.kind) {
377
		case CONSTRUCTOR_PATTERN :
377
		case CONSTRUCTOR_PATTERN :
378
			return matchConstructor((ConstructorPattern) pattern, binaryInfo, enclosingBinaryType);
378
			return matchConstructor((ConstructorPattern) pattern, binaryInfo, enclosingBinaryType);
379
		case FIELD_PATTERN :
379
		case FIELD_PATTERN :
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeParameterLocator.java (-2 / +2 lines)
Lines 37-43 Link Here
37
		if (this.pattern.findReferences) {
37
		if (this.pattern.findReferences) {
38
			if (node instanceof SingleTypeReference) { // Type parameter cannot be qualified
38
			if (node instanceof SingleTypeReference) { // Type parameter cannot be qualified
39
				if (matchesName(this.pattern.name, ((SingleTypeReference) node).token)) {
39
				if (matchesName(this.pattern.name, ((SingleTypeReference) node).token)) {
40
					int level = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
40
					int level = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
41
					return nodeSet.addMatch(node, level);
41
					return nodeSet.addMatch(node, level);
42
				}
42
				}
43
			}
43
			}
Lines 52-58 Link Here
52
	public int match(TypeParameter node, MatchingNodeSet nodeSet) {
52
	public int match(TypeParameter node, MatchingNodeSet nodeSet) {
53
		if (this.pattern.findDeclarations) {
53
		if (this.pattern.findDeclarations) {
54
			if (matchesName(this.pattern.name, node.name)) {
54
			if (matchesName(this.pattern.name, node.name)) {
55
				int level = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
55
				int level = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
56
				return nodeSet.addMatch(node, level);
56
				return nodeSet.addMatch(node, level);
57
			}
57
			}
58
		}
58
		}
(-)search/org/eclipse/jdt/internal/core/search/matching/DeclarationOfReferencedMethodsPattern.java (-1 / +1 lines)
Lines 26-31 Link Here
26
26
27
	this.enclosingElement = enclosingElement;
27
	this.enclosingElement = enclosingElement;
28
	this.knownMethods = new SimpleSet();
28
	this.knownMethods = new SimpleSet();
29
	((InternalSearchPattern)this).mustResolve = true;
29
	this.mustResolve = true;
30
}
30
}
31
}
31
}
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationPattern.java (-2 / +2 lines)
Lines 152-158 Link Here
152
	this.simpleName = (this.isCaseSensitive || this.isCamelCase) ? simpleName : CharOperation.toLowerCase(simpleName);
152
	this.simpleName = (this.isCaseSensitive || this.isCamelCase) ? simpleName : CharOperation.toLowerCase(simpleName);
153
	this.typeSuffix = typeSuffix;
153
	this.typeSuffix = typeSuffix;
154
154
155
	((InternalSearchPattern)this).mustResolve = (this.pkg != null && this.enclosingTypeNames != null) || typeSuffix != TYPE_SUFFIX;
155
	this.mustResolve = (this.pkg != null && this.enclosingTypeNames != null) || typeSuffix != TYPE_SUFFIX;
156
}
156
}
157
TypeDeclarationPattern(int matchRule) {
157
TypeDeclarationPattern(int matchRule) {
158
	super(TYPE_DECL_PATTERN, matchRule);
158
	super(TYPE_DECL_PATTERN, matchRule);
Lines 255-261 Link Here
255
	}
255
	}
256
	return true;
256
	return true;
257
}
257
}
258
EntryResult[] queryIn(Index index) throws IOException {
258
public EntryResult[] queryIn(Index index) throws IOException {
259
	char[] key = this.simpleName; // can be null
259
	char[] key = this.simpleName; // can be null
260
	int matchRule = getMatchRule();
260
	int matchRule = getMatchRule();
261
261
(-)search/org/eclipse/jdt/internal/core/search/matching/LocalVariableLocator.java (-2 / +2 lines)
Lines 28-40 Link Here
28
		// must be a write only access with an initializer
28
		// must be a write only access with an initializer
29
		if (this.pattern.writeAccess && !this.pattern.readAccess && node.initialization != null)
29
		if (this.pattern.writeAccess && !this.pattern.readAccess && node.initialization != null)
30
			if (matchesName(this.pattern.name, node.name))
30
			if (matchesName(this.pattern.name, node.name))
31
				referencesLevel = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
31
				referencesLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
32
32
33
	int declarationsLevel = IMPOSSIBLE_MATCH;
33
	int declarationsLevel = IMPOSSIBLE_MATCH;
34
	if (this.pattern.findDeclarations)
34
	if (this.pattern.findDeclarations)
35
		if (matchesName(this.pattern.name, node.name))
35
		if (matchesName(this.pattern.name, node.name))
36
			if (node.declarationSourceStart == getLocalVariable().declarationSourceStart)
36
			if (node.declarationSourceStart == getLocalVariable().declarationSourceStart)
37
				declarationsLevel = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
37
				declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
38
38
39
	return nodeSet.addMatch(node, referencesLevel >= declarationsLevel ? referencesLevel : declarationsLevel); // use the stronger match
39
	return nodeSet.addMatch(node, referencesLevel >= declarationsLevel ? referencesLevel : declarationsLevel); // use the stronger match
40
}
40
}
(-)search/org/eclipse/jdt/internal/core/search/matching/SecondaryTypeDeclarationPattern.java (-1 / +1 lines)
Lines 40-46 Link Here
40
/* (non-Javadoc)
40
/* (non-Javadoc)
41
 * @see org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern#queryIn(org.eclipse.jdt.internal.core.index.Index)
41
 * @see org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern#queryIn(org.eclipse.jdt.internal.core.index.Index)
42
 */
42
 */
43
EntryResult[] queryIn(Index index) throws IOException {
43
public EntryResult[] queryIn(Index index) throws IOException {
44
	return index.query(CATEGORIES, SECONDARY_PATTERN_KEY, R_PATTERN_MATCH | R_CASE_SENSITIVE);
44
	return index.query(CATEGORIES, SECONDARY_PATTERN_KEY, R_PATTERN_MATCH | R_CASE_SENSITIVE);
45
}
45
}
46
46
(-)search/org/eclipse/jdt/internal/core/search/matching/ConstructorPattern.java (-4 / +4 lines)
Lines 112-118 Link Here
112
	} else {
112
	} else {
113
		this.parameterCount = -1;
113
		this.parameterCount = -1;
114
	}
114
	}
115
	((InternalSearchPattern)this).mustResolve = mustResolve();
115
	this.mustResolve = mustResolve();
116
}
116
}
117
/*
117
/*
118
 * Instanciate a method pattern with signatures for generics search
118
 * Instanciate a method pattern with signatures for generics search
Lines 174-180 Link Here
174
174
175
	// Store type signatures and arguments for method
175
	// Store type signatures and arguments for method
176
	this.constructorArguments = extractMethodArguments(method);
176
	this.constructorArguments = extractMethodArguments(method);
177
	if (hasConstructorArguments())  ((InternalSearchPattern)this).mustResolve = true;
177
	if (hasConstructorArguments())  this.mustResolve = true;
178
}
178
}
179
/*
179
/*
180
 * Instanciate a method pattern with signatures for generics search
180
 * Instanciate a method pattern with signatures for generics search
Lines 223-229 Link Here
223
			this.constructorArguments = getTypeArguments()[0];
223
			this.constructorArguments = getTypeArguments()[0];
224
		}
224
		}
225
	}
225
	}
226
	if (hasConstructorArguments())  ((InternalSearchPattern)this).mustResolve = true;
226
	if (hasConstructorArguments())  this.mustResolve = true;
227
}
227
}
228
public void decodeIndexKey(char[] key) {
228
public void decodeIndexKey(char[] key) {
229
	int last = key.length - 1;
229
	int last = key.length - 1;
Lines 274-280 Link Here
274
			if (this.parameterQualifications[i] != null) return true;
274
			if (this.parameterQualifications[i] != null) return true;
275
	return this.findReferences; // need to check resolved default constructors and explicit constructor calls
275
	return this.findReferences; // need to check resolved default constructors and explicit constructor calls
276
}
276
}
277
EntryResult[] queryIn(Index index) throws IOException {
277
public EntryResult[] queryIn(Index index) throws IOException {
278
	char[] key = this.declaringSimpleName; // can be null
278
	char[] key = this.declaringSimpleName; // can be null
279
	int matchRule = getMatchRule();
279
	int matchRule = getMatchRule();
280
280
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-7 / +7 lines)
Lines 102-108 Link Here
102
				System.arraycopy(importRef.tokens, 0, compoundName, 0, length);
102
				System.arraycopy(importRef.tokens, 0, compoundName, 0, length);
103
				char[] declaringType = CharOperation.concat(this.pattern.declaringQualification, this.pattern.declaringSimpleName, '.');
103
				char[] declaringType = CharOperation.concat(this.pattern.declaringQualification, this.pattern.declaringSimpleName, '.');
104
				if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) {
104
				if (matchesName(declaringType, CharOperation.concatWith(compoundName, '.'))) {
105
					declarationsLevel = ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
105
					declarationsLevel = this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
106
				}
106
				}
107
			}
107
			}
108
		}
108
		}
Lines 119-125 Link Here
119
	if (!matchesName(this.pattern.selector, node.selector)) return IMPOSSIBLE_MATCH;
119
	if (!matchesName(this.pattern.selector, node.selector)) return IMPOSSIBLE_MATCH;
120
120
121
	// Verify parameters types
121
	// Verify parameters types
122
	boolean resolve = ((InternalSearchPattern)this.pattern).mustResolve;
122
	boolean resolve = this.pattern.mustResolve;
123
	if (this.pattern.parameterSimpleNames != null) {
123
	if (this.pattern.parameterSimpleNames != null) {
124
		int length = this.pattern.parameterSimpleNames.length;
124
		int length = this.pattern.parameterSimpleNames.length;
125
		ASTNode[] args = node.arguments;
125
		ASTNode[] args = node.arguments;
Lines 129-135 Link Here
129
			if (args != null && !matchesTypeReference(this.pattern.parameterSimpleNames[i], ((Argument) args[i]).type)) {
129
			if (args != null && !matchesTypeReference(this.pattern.parameterSimpleNames[i], ((Argument) args[i]).type)) {
130
				// Do not return as impossible when source level is at least 1.5
130
				// Do not return as impossible when source level is at least 1.5
131
				if (this.mayBeGeneric) {
131
				if (this.mayBeGeneric) {
132
					if (!((InternalSearchPattern)this.pattern).mustResolve) {
132
					if (!this.pattern.mustResolve) {
133
						// Set resolution flag on node set in case of types was inferred in parameterized types from generic ones...
133
						// Set resolution flag on node set in case of types was inferred in parameterized types from generic ones...
134
					 	// (see  bugs https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990, 96761, 96763)
134
					 	// (see  bugs https://bugs.eclipse.org/bugs/show_bug.cgi?id=79990, 96761, 96763)
135
						nodeSet.mustResolve = true;
135
						nodeSet.mustResolve = true;
Lines 156-162 Link Here
156
156
157
	if (!matchesName(this.pattern.selector, node.name)) return IMPOSSIBLE_MATCH;
157
	if (!matchesName(this.pattern.selector, node.name)) return IMPOSSIBLE_MATCH;
158
158
159
	return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
159
	return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
160
}
160
}
161
public int match(MessageSend node, MatchingNodeSet nodeSet) {
161
public int match(MessageSend node, MatchingNodeSet nodeSet) {
162
	if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
162
	if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH;
Lines 169-175 Link Here
169
		if (length != argsLength) return IMPOSSIBLE_MATCH;
169
		if (length != argsLength) return IMPOSSIBLE_MATCH;
170
	}
170
	}
171
171
172
	return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
172
	return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
173
}
173
}
174
//public int match(Reference node, MatchingNodeSet nodeSet) - SKIP IT
174
//public int match(Reference node, MatchingNodeSet nodeSet) - SKIP IT
175
public int match(Annotation node, MatchingNodeSet nodeSet) {
175
public int match(Annotation node, MatchingNodeSet nodeSet) {
Lines 183-189 Link Here
183
		pair = node.memberValuePairs()[i];
183
		pair = node.memberValuePairs()[i];
184
		if (matchesName(this.pattern.selector, pair.name)) {
184
		if (matchesName(this.pattern.selector, pair.name)) {
185
			ASTNode possibleNode = (node instanceof SingleMemberAnnotation) ? (ASTNode) node : pair;
185
			ASTNode possibleNode = (node instanceof SingleMemberAnnotation) ? (ASTNode) node : pair;
186
			return nodeSet.addMatch(possibleNode, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
186
			return nodeSet.addMatch(possibleNode, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
187
		}
187
		}
188
	}
188
	}
189
	return IMPOSSIBLE_MATCH;
189
	return IMPOSSIBLE_MATCH;
Lines 337-343 Link Here
337
		methodReferenceMatch.localElement(localElement);
337
		methodReferenceMatch.localElement(localElement);
338
		this.match = methodReferenceMatch;
338
		this.match = methodReferenceMatch;
339
		if (this.pattern.findReferences && reference instanceof MessageSend) {
339
		if (this.pattern.findReferences && reference instanceof MessageSend) {
340
			IJavaElement focus = ((InternalSearchPattern) this.pattern).focus;
340
			IJavaElement focus = this.pattern.focus;
341
			// verify closest match if pattern was bound
341
			// verify closest match if pattern was bound
342
			// (see bug 70827)
342
			// (see bug 70827)
343
			if (focus != null && focus.getElementType() == IJavaElement.METHOD) {
343
			if (focus != null && focus.getElementType() == IJavaElement.METHOD) {
(-)search/org/eclipse/jdt/internal/core/search/matching/PackageReferencePattern.java (-2 / +2 lines)
Lines 28-38 Link Here
28
	if (pkgName == null || pkgName.length == 0) {
28
	if (pkgName == null || pkgName.length == 0) {
29
		this.pkgName = null;
29
		this.pkgName = null;
30
		this.segments = new char[][] {CharOperation.NO_CHAR};
30
		this.segments = new char[][] {CharOperation.NO_CHAR};
31
		((InternalSearchPattern)this).mustResolve = false;
31
		this.mustResolve = false;
32
	} else {
32
	} else {
33
		this.pkgName = (this.isCaseSensitive || this.isCamelCase) ? pkgName : CharOperation.toLowerCase(pkgName);
33
		this.pkgName = (this.isCaseSensitive || this.isCamelCase) ? pkgName : CharOperation.toLowerCase(pkgName);
34
		this.segments = CharOperation.splitOn('.', this.pkgName);
34
		this.segments = CharOperation.splitOn('.', this.pkgName);
35
		((InternalSearchPattern)this).mustResolve = true;
35
		this.mustResolve = true;
36
	}
36
	}
37
}
37
}
38
PackageReferencePattern(int matchRule) {
38
PackageReferencePattern(int matchRule) {
(-)search/org/eclipse/jdt/core/search/SearchPattern.java (-1 / +111 lines)
Lines 10-22 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.search;
11
package org.eclipse.jdt.core.search;
12
12
13
import java.io.IOException;
14
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.OperationCanceledException;
13
import org.eclipse.jdt.core.*;
17
import org.eclipse.jdt.core.*;
14
import org.eclipse.jdt.core.compiler.*;
18
import org.eclipse.jdt.core.compiler.*;
15
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
19
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
20
import org.eclipse.jdt.internal.compiler.env.AccessRuleSet;
16
import org.eclipse.jdt.internal.compiler.parser.Scanner;
21
import org.eclipse.jdt.internal.compiler.parser.Scanner;
17
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
22
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
18
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
23
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;
19
import org.eclipse.jdt.internal.core.LocalVariable;
24
import org.eclipse.jdt.internal.core.LocalVariable;
25
import org.eclipse.jdt.internal.core.index.EntryResult;
26
import org.eclipse.jdt.internal.core.index.Index;
27
import org.eclipse.jdt.internal.core.search.IndexQueryRequestor;
28
import org.eclipse.jdt.internal.core.search.JavaSearchScope;
20
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
29
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
21
import org.eclipse.jdt.internal.core.search.matching.*;
30
import org.eclipse.jdt.internal.core.search.matching.*;
22
31
Lines 43-49 Link Here
43
 * @see #createPattern(String, int, int, int)
52
 * @see #createPattern(String, int, int, int)
44
 * @since 3.0
53
 * @since 3.0
45
 */
54
 */
46
public abstract class SearchPattern extends InternalSearchPattern {
55
public abstract class SearchPattern {
47
56
48
	// Rules for pattern matching: (exact, prefix, pattern) [ | case sensitive]
57
	// Rules for pattern matching: (exact, prefix, pattern) [ | case sensitive]
49
	/**
58
	/**
Lines 197-202 Link Here
197
206
198
	private int matchRule;
207
	private int matchRule;
199
208
209
	/**
210
	 * The focus element (used for reference patterns)
211
	 * @noreference This field is not intended to be referenced by clients. 
212
	 */
213
	public IJavaElement focus;
214
215
	/**
216
	 * @noreference This field is not intended to be referenced by clients.
217
	 */
218
	public int kind;
219
	
220
	/**
221
	 * @noreference This field is not intended to be referenced by clients.
222
	 */
223
	public boolean mustResolve = true;
224
	
200
/**
225
/**
201
 * Creates a search pattern with the rule to apply for matching index keys.
226
 * Creates a search pattern with the rule to apply for matching index keys.
202
 * It can be exact match, prefix match, pattern match or regexp match.
227
 * It can be exact match, prefix match, pattern match or regexp match.
Lines 244-250 Link Here
244
		this.matchRule &= ~R_PREFIX_MATCH;
269
		this.matchRule &= ~R_PREFIX_MATCH;
245
	}
270
	}
246
}
271
}
272
/**
273
 * @noreference This method is not intended to be referenced by clients.
274
 * @nooverride This method is not intended to be re-implemented or extended by clients.
275
 */
276
public void acceptMatch(String relativePath, String containerPath, char separator, SearchPattern pattern, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope) {
277
278
	if (scope instanceof JavaSearchScope) {
279
		JavaSearchScope javaSearchScope = (JavaSearchScope) scope;
280
		// Get document path access restriction from java search scope
281
		// Note that requestor has to verify if needed whether the document violates the access restriction or not
282
		AccessRuleSet access = javaSearchScope.getAccessRuleSet(relativePath, containerPath);
283
		if (access != JavaSearchScope.NOT_ENCLOSED) { // scope encloses the document path
284
			StringBuffer documentPath = new StringBuffer(containerPath.length() + 1 + relativePath.length());
285
			documentPath.append(containerPath);
286
			documentPath.append(separator);
287
			documentPath.append(relativePath);
288
			if (!requestor.acceptIndexMatch(documentPath.toString(), pattern, participant, access))
289
				throw new OperationCanceledException();
290
		}
291
	} else {
292
		StringBuffer buffer = new StringBuffer(containerPath.length() + 1 + relativePath.length());
293
		buffer.append(containerPath);
294
		buffer.append(separator);
295
		buffer.append(relativePath);
296
		String documentPath = buffer.toString();
297
		if (scope.encloses(documentPath))
298
			if (!requestor.acceptIndexMatch(documentPath, pattern, participant, null))
299
				throw new OperationCanceledException();
247
300
301
	}
302
}
303
/**
304
 * @noreference This method is not intended to be referenced by clients. 
305
 * @nooverride This method is not intended to be re-implemented or extended by clients.
306
 */
307
public SearchPattern currentPattern() {
308
	return this;
309
}
248
/**
310
/**
249
 * Answers true if the pattern matches the given name using CamelCase rules, or
311
 * Answers true if the pattern matches the given name using CamelCase rules, or
250
 * false otherwise. char[] CamelCase matching does NOT accept explicit wild-cards
312
 * false otherwise. char[] CamelCase matching does NOT accept explicit wild-cards
Lines 1991-1996 Link Here
1991
	// called from findIndexMatches(), override as necessary
2053
	// called from findIndexMatches(), override as necessary
1992
}
2054
}
1993
/**
2055
/**
2056
 * Query a given index for matching entries. Assumes the sender has opened the index and will close when finished.
2057
 * 
2058
 * @noreference This method is not intended to be referenced by clients. 
2059
 * @nooverride This method is not intended to be re-implemented or extended by clients.
2060
 */
2061
public void findIndexMatches(Index index, IndexQueryRequestor requestor, SearchParticipant participant, IJavaSearchScope scope, IProgressMonitor monitor) throws IOException {
2062
	if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
2063
	try {
2064
		index.startQuery();
2065
		SearchPattern pattern = currentPattern();
2066
		EntryResult[] entries = pattern.queryIn(index);
2067
		if (entries == null) return;
2068
2069
		SearchPattern decodedResult = pattern.getBlankPattern();
2070
		String containerPath = index.containerPath;
2071
		char separator = index.separator;
2072
		for (int i = 0, l = entries.length; i < l; i++) {
2073
			if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
2074
2075
			EntryResult entry = entries[i];
2076
			decodedResult.decodeIndexKey(entry.getWord());
2077
			if (pattern.matchesDecodedKey(decodedResult)) {
2078
				// TODO (kent) some clients may not need the document names
2079
				String[] names = entry.getDocumentNames(index);
2080
				for (int j = 0, n = names.length; j < n; j++)
2081
					acceptMatch(names[j], containerPath, separator, decodedResult, requestor, participant, scope);
2082
			}
2083
		}
2084
	} finally {
2085
		index.stopQuery();
2086
	}
2087
}
2088
/**
1994
 * Returns a blank pattern that can be used as a record to decode an index key.
2089
 * Returns a blank pattern that can be used as a record to decode an index key.
1995
 * <p>
2090
 * <p>
1996
 * Implementors of this method should return a new search pattern that is going to be used
2091
 * Implementors of this method should return a new search pattern that is going to be used
Lines 2044-2049 Link Here
2044
	return this.matchRule;
2139
	return this.matchRule;
2045
}
2140
}
2046
/**
2141
/**
2142
 * @noreference This method is not intended to be referenced by clients. 
2143
 * @nooverride This method is not intended to be re-implemented or extended by clients.
2144
 */
2145
public boolean isPolymorphicSearch() {
2146
	return false;
2147
}
2148
/**
2047
 * Returns whether this pattern matches the given pattern (representing a decoded index key).
2149
 * Returns whether this pattern matches the given pattern (representing a decoded index key).
2048
 * <p>
2150
 * <p>
2049
 * This method should be re-implemented in subclasses that need to narrow down the
2151
 * This method should be re-implemented in subclasses that need to narrow down the
Lines 2254-2259 Link Here
2254
}
2356
}
2255
2357
2256
/**
2358
/**
2359
 * @noreference This method is not intended to be referenced by clients. 
2360
 * @nooverride This method is not intended to be re-implemented or extended by clients.
2361
 */
2362
public EntryResult[] queryIn(Index index) throws IOException {
2363
	return index.query(getIndexCategories(), getIndexKey(), getMatchRule());
2364
}
2365
2366
/**
2257
 * @see java.lang.Object#toString()
2367
 * @see java.lang.Object#toString()
2258
 */
2368
 */
2259
public String toString() {
2369
public String toString() {

Return to bug 247835