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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-42 / +46 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 436-483 Link Here
436
		// fall thru if its a constructor with a synthetic argument... find it the slower way
436
		// fall thru if its a constructor with a synthetic argument... find it the slower way
437
		ClassFileReader reader = classFileReader(type);
437
		ClassFileReader reader = classFileReader(type);
438
		if (reader != null) {
438
		if (reader != null) {
439
			IBinaryMethod[] methods = reader.getMethods();
439
			// build arguments names
440
			if (methods != null) {
440
			boolean firstIsSynthetic = false;
441
				// build arguments names
441
			if (reader.isMember() && method.isConstructor() && !Flags.isStatic(reader.getModifiers())) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=48261
442
				boolean firstIsSynthetic = false;
442
				firstIsSynthetic = true;
443
				if (reader.isMember() && method.isConstructor() && !Flags.isStatic(reader.getModifiers())) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=48261
443
				argCount++;
444
					firstIsSynthetic = true;
444
			}
445
					argCount++;
445
			char[][] argumentTypeNames = new char[argCount][];
446
				}
446
			for (int i = 0; i < argCount; i++) {
447
				char[][] argumentTypeNames = new char[argCount][];
447
				char[] typeName = null;
448
				for (int i = 0; i < argCount; i++) {
448
				if (i == 0 && firstIsSynthetic) {
449
					char[] typeName = null;
449
					typeName = type.getDeclaringType().getFullyQualifiedName().toCharArray();
450
					if (i == 0 && firstIsSynthetic) {
450
				} else if (arguments != null) {
451
						typeName = type.getDeclaringType().getFullyQualifiedName().toCharArray();
451
					TypeReference typeRef = arguments[firstIsSynthetic ? i - 1 : i].type;
452
					} else if (arguments != null) {
452
					typeName = CharOperation.concatWith(typeRef.getTypeName(), '.');
453
						TypeReference typeRef = arguments[firstIsSynthetic ? i - 1 : i].type;
453
					for (int k = 0, dim = typeRef.dimensions(); k < dim; k++)
454
						typeName = CharOperation.concatWith(typeRef.getTypeName(), '.');
454
						typeName = CharOperation.concat(typeName, new char[] {'[', ']'});
455
						for (int k = 0, dim = typeRef.dimensions(); k < dim; k++)
455
				}
456
							typeName = CharOperation.concat(typeName, new char[] {'[', ']'});
456
				if (typeName == null) {
457
					}
457
					// invalid type name
458
					if (typeName == null) {
458
					return null;
459
						// invalid type name
459
				}
460
						return null;
460
				argumentTypeNames[i] = typeName;
461
					}
461
			}
462
					argumentTypeNames[i] = typeName;
462
			// return binary method
463
				}
463
			IMethod binaryMethod = createBinaryMethodHandle(type, method.selector, argumentTypeNames);
464
464
			if (binaryMethod == null) {
465
				// return binary method
465
				// when first attempt fails, try with similar matches if any...
466
				IMethod binaryMethod = createBinaryMethodHandle(type, method.selector, argumentTypeNames);
466
				PossibleMatch similarMatch = this.currentPossibleMatch.getSimilarMatch();
467
				if (binaryMethod == null) {
467
				while (similarMatch != null) {
468
					// when first attempt fails, try with similar matches if any...
468
					type = ((ClassFile)similarMatch.openable).getType();
469
					PossibleMatch similarMatch = this.currentPossibleMatch.getSimilarMatch();
469
					binaryMethod = createBinaryMethodHandle(type, method.selector, argumentTypeNames);
470
					while (similarMatch != null) {
470
					if (binaryMethod != null) {
471
						type = ((ClassFile)similarMatch.openable).getType();
471
						return binaryMethod;
472
						binaryMethod = createBinaryMethodHandle(type, method.selector, argumentTypeNames);
473
						if (binaryMethod != null) {
474
							return binaryMethod;
475
						}
476
						similarMatch = similarMatch.getSimilarMatch();
477
					}
472
					}
473
					similarMatch = similarMatch.getSimilarMatch();
478
				}
474
				}
479
				return binaryMethod;
480
			}
475
			}
476
			return binaryMethod;
477
		}
478
		if (BasicSearchEngine.VERBOSE) {
479
			System.out.println("Not able to createHandle for the method " + //$NON-NLS-1$
480
					CharOperation.charToString(method.selector) + " May miss some results");  //$NON-NLS-1$
481
		}
481
		}
482
		return null;
482
		return null;
483
	}
483
	}
Lines 2145-2151 Link Here
2145
		if (enclosingElement == null) {
2145
		if (enclosingElement == null) {
2146
			enclosingElement = createHandle(method, parent);
2146
			enclosingElement = createHandle(method, parent);
2147
		}
2147
		}
2148
		reportMatching(typeParameters, enclosingElement, parent, method.binding, nodeSet);
2148
		if (enclosingElement != null) {
2149
			reportMatching(typeParameters, enclosingElement, parent, method.binding, nodeSet);
2150
		}
2149
	}
2151
	}
2150
2152
2151
	// report annotations
2153
	// report annotations
Lines 2153-2159 Link Here
2153
		if (enclosingElement == null) {
2155
		if (enclosingElement == null) {
2154
			enclosingElement = createHandle(method, parent);
2156
			enclosingElement = createHandle(method, parent);
2155
		}
2157
		}
2156
		reportMatching(method.annotations, enclosingElement, null, method.binding, nodeSet, true, true);
2158
		if (enclosingElement != null) {
2159
			reportMatching(method.annotations, enclosingElement, null, method.binding, nodeSet, true, true);
2160
		}
2157
	}
2161
	}
2158
2162
2159
	// references in this method
2163
	// references in this method
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+33 lines)
Lines 11533-11536 Link Here
11533
		getWorkspace().setDescription(preferences);
11533
		getWorkspace().setDescription(preferences);
11534
	}
11534
	}
11535
}
11535
}
11536
11537
/**
11538
 * @bug 288174: [search] NPE while searching for annotation references in
11539
 *      rt.jar of JRE 6.0
11540
 * @test Ensure that no NPE occurs when searching for both ANNOTATION_TYPE
11541
 *       and TYPE references from an inner enum declared in a binary type.
11542
 *       This same test also ensures that there is no NPE even if the source
11543
 *       has a method that does not exist in the class file.
11544
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=306196"
11545
 */
11546
public void testBug306196() throws Exception {
11547
	final String libPath = "/JavaSearchBugs/lib/b306196.jar";
11548
	addLibraryEntry(JAVA_PROJECT, libPath, false);
11549
	try {
11550
		IPackageFragmentRoot root = getPackageFragmentRoot(libPath);
11551
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { root });
11552
		SearchPattern leftPattern = createPattern("*", ANNOTATION_TYPE, REFERENCES, false);
11553
		SearchPattern rightPattern = createPattern("*", TYPE, REFERENCES, false);
11554
		new SearchEngine().search(SearchPattern.createOrPattern( leftPattern, rightPattern),
11555
				new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
11556
				this.resultCollector, null);
11557
		assertSearchResults("lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
11558
				+ "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
11559
				+ "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
11560
				+ "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
11561
				+ "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
11562
				+ "lib/b306196.jar java.lang.String pkg.<anonymous>.aFunc(java.lang.Object) EXACT_MATCH\n"
11563
				+ "lib/b306196.jar java.lang.String pkg.B306196$anEnum.aFunc(java.lang.Object) EXACT_MATCH\n"
11564
				+ "lib/b306196.jar java.lang.String pkg.B306196$anEnum.aFunc(java.lang.Object) EXACT_MATCH");
11565
	} finally {
11566
		removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
11567
	}
11568
}
11536
}
11569
}

Return to bug 306196