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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+26 lines)
Lines 9285-9290 Link Here
9285
		removeClasspathEntry(JAVA_PROJECT, new Path("/JavaSearchBugs/lib/b211366.jar"));
9285
		removeClasspathEntry(JAVA_PROJECT, new Path("/JavaSearchBugs/lib/b211366.jar"));
9286
	}
9286
	}
9287
}
9287
}
9288
public void testBug211366_OrPattern() throws CoreException {
9289
	addLibraryEntry(JAVA_PROJECT, "/JavaSearchBugs/lib/b211366.jar", false);
9290
	try {
9291
		IType type = getClassFile("JavaSearchBugs", "lib/b211366.jar", "test", "Bug.class").getType();
9292
		SearchPattern rightPattern = SearchPattern.createPattern(type, REFERENCES);
9293
		SearchPattern leftPattern = SearchPattern.createPattern(type, DECLARATIONS);
9294
		SearchPattern pattern = SearchPattern.createOrPattern(leftPattern, rightPattern);
9295
		new SearchEngine(workingCopies).search(
9296
			pattern,
9297
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
9298
			getJavaSearchScope(),
9299
			this.resultCollector,
9300
			null
9301
		);
9302
		assertSearchResults(
9303
			"lib/b211366.jar pack.Test [No source] EXACT_MATCH\n" + 
9304
			"lib/b211366.jar pack.TestInner$Member [No source] EXACT_MATCH\n" + 
9305
			"lib/b211366.jar void pack.TestMembers.method(java.lang.Object, java.lang.String) [No source] EXACT_MATCH\n" + 
9306
			"lib/b211366.jar pack.TestMembers.field [No source] EXACT_MATCH\n" +
9307
			"lib/b211366.jar test.Bug [No source] EXACT_MATCH"
9308
		);
9309
	}
9310
	finally {
9311
		removeClasspathEntry(JAVA_PROJECT, new Path("/JavaSearchBugs/lib/b211366.jar"));
9312
	}
9313
}
9288
9314
9289
/**
9315
/**
9290
 * @bug 211857: [search] Standard annotations references not found on binary fields and methods when no source is attached
9316
 * @bug 211857: [search] Standard annotations references not found on binary fields and methods when no source is attached
(-)search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java (-7 / +20 lines)
Lines 147-156 Link Here
147
 */
147
 */
148
public void locateMatches(MatchLocator locator, ClassFile classFile, IBinaryType info) throws CoreException {
148
public void locateMatches(MatchLocator locator, ClassFile classFile, IBinaryType info) throws CoreException {
149
	SearchPattern pattern = locator.pattern;
149
	SearchPattern pattern = locator.pattern;
150
150
	// check annotations references
151
	// check annotations references
151
	if (((InternalSearchPattern)pattern).kind == TYPE_REF_PATTERN) {
152
	matchAnnotations(pattern, locator, classFile, info);
152
		matchAnnotations((TypeReferencePattern)pattern, locator, classFile, info);
153
	}
154
153
155
	// check class definition
154
	// check class definition
156
	BinaryType binaryType = (BinaryType) classFile.getType();
155
	BinaryType binaryType = (BinaryType) classFile.getType();
Lines 308-320 Link Here
308
/*
307
/*
309
 * Look for annotations references
308
 * Look for annotations references
310
 */
309
 */
311
void matchAnnotations(TypeReferencePattern pattern, MatchLocator locator, ClassFile classFile, IBinaryType binaryType) throws CoreException {
310
void matchAnnotations(SearchPattern pattern, MatchLocator locator, ClassFile classFile, IBinaryType binaryType) throws CoreException {
311
	// Only process TypeReference patterns
312
	switch (((InternalSearchPattern)pattern).kind) {
313
		case TYPE_REF_PATTERN:
314
			break;
315
		case OR_PATTERN:
316
			SearchPattern[] patterns = ((OrPattern) pattern).patterns;
317
			for (int i = 0, length = patterns.length; i < length; i++) {
318
				matchAnnotations(patterns[i], locator, classFile, binaryType);
319
			}
320
			// fall through default to return
321
		default:
322
			return;
323
	}
324
	TypeReferencePattern typeReferencePattern  = (TypeReferencePattern) pattern;
312
325
313
	// Look for references in class annotations
326
	// Look for references in class annotations
314
	IBinaryAnnotation[] annotations = binaryType.getAnnotations();
327
	IBinaryAnnotation[] annotations = binaryType.getAnnotations();
315
	BinaryType classFileBinaryType = (BinaryType) classFile.getType();
328
	BinaryType classFileBinaryType = (BinaryType) classFile.getType();
316
	BinaryTypeBinding binaryTypeBinding = null;
329
	BinaryTypeBinding binaryTypeBinding = null;
317
	if (checkAnnotations(pattern, annotations, binaryType.getTagBits())) {
330
	if (checkAnnotations(typeReferencePattern, annotations, binaryType.getTagBits())) {
318
		classFileBinaryType = new ResolvedBinaryType((JavaElement) classFileBinaryType.getParent(), classFileBinaryType.getElementName(), classFileBinaryType.getKey());
331
		classFileBinaryType = new ResolvedBinaryType((JavaElement) classFileBinaryType.getParent(), classFileBinaryType.getElementName(), classFileBinaryType.getKey());
319
		locator.reportBinaryMemberDeclaration(null, classFileBinaryType, null, binaryType, SearchMatch.A_ACCURATE);
332
		locator.reportBinaryMemberDeclaration(null, classFileBinaryType, null, binaryType, SearchMatch.A_ACCURATE);
320
	}
333
	}
Lines 324-330 Link Here
324
	if (methods != null) {
337
	if (methods != null) {
325
		for (int i = 0, max = methods.length; i < max; i++) {
338
		for (int i = 0, max = methods.length; i < max; i++) {
326
			MethodInfo method = methods[i];
339
			MethodInfo method = methods[i];
327
			if (checkAnnotations(pattern, method.getAnnotations(), method.getTagBits())) {
340
			if (checkAnnotations(typeReferencePattern, method.getAnnotations(), method.getTagBits())) {
328
					binaryTypeBinding = locator.cacheBinaryType(classFileBinaryType, binaryType);
341
					binaryTypeBinding = locator.cacheBinaryType(classFileBinaryType, binaryType);
329
					IMethod methodHandle = classFileBinaryType.getMethod(
342
					IMethod methodHandle = classFileBinaryType.getMethod(
330
						new String(method.isConstructor() ? binaryTypeBinding.compoundName[binaryTypeBinding.compoundName.length-1] : method.getSelector()),
343
						new String(method.isConstructor() ? binaryTypeBinding.compoundName[binaryTypeBinding.compoundName.length-1] : method.getSelector()),
Lines 339-345 Link Here
339
	if (fields != null) {
352
	if (fields != null) {
340
		for (int i = 0, max = fields.length; i < max; i++) {
353
		for (int i = 0, max = fields.length; i < max; i++) {
341
			FieldInfo field = fields[i];
354
			FieldInfo field = fields[i];
342
			if (checkAnnotations(pattern, field.getAnnotations(), field.getTagBits())) {
355
			if (checkAnnotations(typeReferencePattern, field.getAnnotations(), field.getTagBits())) {
343
					IField fieldHandle = classFileBinaryType.getField(new String(field.getName()));
356
					IField fieldHandle = classFileBinaryType.getField(new String(field.getName()));
344
					locator.reportBinaryMemberDeclaration(null, fieldHandle, null, binaryType, SearchMatch.A_ACCURATE);
357
					locator.reportBinaryMemberDeclaration(null, fieldHandle, null, binaryType, SearchMatch.A_ACCURATE);
345
			}
358
			}

Return to bug 211366