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

(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-46 / +37 lines)
Lines 21-27 Link Here
21
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
21
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
22
import org.eclipse.jdt.internal.compiler.lookup.*;
22
import org.eclipse.jdt.internal.compiler.lookup.*;
23
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
23
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
24
import org.eclipse.jdt.internal.core.JavaElement;
25
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
24
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
26
25
27
public class MethodLocator extends PatternLocator {
26
public class MethodLocator extends PatternLocator {
Lines 498-509 Link Here
498
	IType type = locator.lookupType(declaringClass);
497
	IType type = locator.lookupType(declaringClass);
499
	if (type == null) return; // case of a secondary type
498
	if (type == null) return; // case of a secondary type
500
499
501
	char[] bindingSelector = methodBinding.selector;
500
	// Report match for binary
502
	boolean isBinary = type.isBinary();
501
	if (type.isBinary()) {
503
	IMethod method = null;
502
		IMethod method = null;
504
	TypeBinding[] parameters = methodBinding.original().parameters;
503
		TypeBinding[] parameters = methodBinding.original().parameters;
505
	int parameterLength = parameters.length;
504
		int parameterLength = parameters.length;
506
	if (isBinary) {
507
		char[][] parameterTypes = new char[parameterLength][];
505
		char[][] parameterTypes = new char[parameterLength][];
508
		for (int i = 0; i<parameterLength; i++) {
506
		for (int i = 0; i<parameterLength; i++) {
509
			char[] typeName = parameters[i].qualifiedSourceName();
507
			char[] typeName = parameters[i].qualifiedSourceName();
Lines 513-560 Link Here
513
			parameterTypes[i] = typeName;
511
			parameterTypes[i] = typeName;
514
		}
512
		}
515
		method = locator.createBinaryMethodHandle(type, methodBinding.selector, parameterTypes);
513
		method = locator.createBinaryMethodHandle(type, methodBinding.selector, parameterTypes);
516
	} else {
514
		if (method == null || knownMethods.addIfNotIncluded(method) == null) return;
517
		String[] parameterTypes = new String[parameterLength];
515
	
518
		for (int i = 0; i  < parameterLength; i++) {
516
		IResource resource = type.getResource();
519
			char[] typeName = parameters[i].shortReadableName();
520
			if (parameters[i].isMemberType()) {
521
				typeName = CharOperation.subarray(typeName, CharOperation.indexOf('.', typeName)+1, typeName.length);
522
			}
523
			parameterTypes[i] = Signature.createTypeSignature(typeName, false);
524
		}
525
		method = type.getMethod(new String(bindingSelector), parameterTypes);
526
	}
527
	if (method == null || knownMethods.addIfNotIncluded(method) == null) return;
528
529
	IResource resource = type.getResource();
530
	IBinaryType info = null;
531
	if (isBinary) {
532
		if (resource == null)
517
		if (resource == null)
533
			resource = type.getJavaProject().getProject();
518
			resource = type.getJavaProject().getProject();
534
		info = locator.getBinaryInfo((org.eclipse.jdt.internal.core.ClassFile)type.getClassFile(), resource);
519
		IBinaryType info = locator.getBinaryInfo((org.eclipse.jdt.internal.core.ClassFile)type.getClassFile(), resource);
535
		locator.reportBinaryMemberDeclaration(resource, method, methodBinding, info, SearchMatch.A_ACCURATE);
520
		locator.reportBinaryMemberDeclaration(resource, method, methodBinding, info, SearchMatch.A_ACCURATE);
536
	} else {
521
		return;
537
		if (declaringClass instanceof ParameterizedTypeBinding)
522
	}
538
			declaringClass = ((ParameterizedTypeBinding) declaringClass).genericType();
523
539
		ClassScope scope = ((SourceTypeBinding) declaringClass).scope;
524
	// When source is available, report match if method is found in the declaring type
540
		if (scope != null) {
525
	IResource resource = type.getResource();
541
			TypeDeclaration typeDecl = scope.referenceContext;
526
	if (declaringClass instanceof ParameterizedTypeBinding)
542
			AbstractMethodDeclaration methodDecl = null;
527
		declaringClass = ((ParameterizedTypeBinding) declaringClass).genericType();
543
			AbstractMethodDeclaration[] methodDecls = typeDecl.methods;
528
	ClassScope scope = ((SourceTypeBinding) declaringClass).scope;
544
			for (int i = 0, length = methodDecls.length; i < length; i++) {
529
	if (scope != null) {
545
				if (CharOperation.equals(bindingSelector, methodDecls[i].selector)) {
530
		TypeDeclaration typeDecl = scope.referenceContext;
546
					methodDecl = methodDecls[i];
531
		AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(methodBinding.original());
547
					break;
532
		if (methodDecl != null) {
548
				}
533
			// Create method handle from method declaration
549
			}
534
			String methodName = new String(methodBinding.selector);
550
			if (methodDecl != null) {
535
			Argument[] arguments = methodDecl.arguments;
551
				int offset = methodDecl.sourceStart;
536
			int length = arguments == null ? 0 : arguments.length;
552
				Binding binding = methodDecl.binding;
537
			String[] parameterTypes = new String[length];
553
				if (binding != null)
538
			for (int i = 0; i  < length; i++) {
554
					method = (IMethod) ((JavaElement) method).resolved(binding);
539
				char[][] typeName = arguments[i].type.getParameterizedTypeName();
555
				this.match = new MethodDeclarationMatch(method, SearchMatch.A_ACCURATE, offset, methodDecl.sourceEnd-offset+1, locator.getParticipant(), resource);
540
				parameterTypes[i] = Signature.createTypeSignature(CharOperation.concatWith(typeName, '.'), false);
556
				locator.report(this.match);
541
			}
557
			}
542
			IMethod method = type.getMethod(methodName, parameterTypes);
543
			if (method == null || knownMethods.addIfNotIncluded(method) == null) return;
544
545
			// Create and report corresponding match
546
			int offset = methodDecl.sourceStart;
547
			this.match = new MethodDeclarationMatch(method, SearchMatch.A_ACCURATE, offset, methodDecl.sourceEnd-offset+1, locator.getParticipant(), resource);
548
			locator.report(this.match);
558
		}
549
		}
559
	}
550
	}
560
}
551
}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java (-1 / +1 lines)
Lines 508-514 Link Here
508
		"src/p/X.java void p.X.foo(int, String, X) [foo(int i, String s, X x)]\n" +
508
		"src/p/X.java void p.X.foo(int, String, X) [foo(int i, String s, X x)]\n" +
509
		"src/p/Y.java void p.Y.bar() [bar()]\n" +
509
		"src/p/Y.java void p.Y.bar() [bar()]\n" +
510
		"src/p/Z.java void p.Z.foo(int, String, X) [foo(int i, String s, X x)]\n" +
510
		"src/p/Z.java void p.Z.foo(int, String, X) [foo(int i, String s, X x)]\n" +
511
		"src/p/A.java void p.A.foo(int, String, X) [foo()]",
511
		"src/p/A.java void p.A.foo(int, String, X) [foo(int i, String s, X x)]",
512
		this.resultCollector);
512
		this.resultCollector);
513
}
513
}
514
514
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+38 lines)
Lines 9189-9194 Link Here
9189
}
9189
}
9190
9190
9191
/**
9191
/**
9192
 * @bug 207657: [search] Exception when refactoring member type to top-level.
9193
 * @test Ensure that searching method reference does not find wrong interface call
9194
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=207657"
9195
 */
9196
public void testBug207657() throws CoreException {
9197
	workingCopies = new ICompilationUnit[1];
9198
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/test/Relationship.java",
9199
		"package test;\n" + 
9200
		"public class Relationship {\n" + 
9201
		"    static public class End extends ConnectionEnd<Visitor> {\n" +
9202
		"        public void accept(Visitor visitor) {\n" + 
9203
		"            visitor.visitRelationshipEnd(this);\n" + 
9204
		"        }\n" + 
9205
		"    }\n" + 
9206
		"}\n" +
9207
		"interface Visitor {\n" + 
9208
		"    boolean visitRelationshipEnd(Relationship.End end);\n" + 
9209
		"    boolean visitAssociationEnd(Association.End end);\n" + 
9210
		"}\n" +
9211
		"abstract class ConnectionEnd<V extends Visitor> {\n" + 
9212
		"    public abstract void accept( V visitor );\n" + 
9213
		"}\n" +
9214
		"class Association extends Relationship {\n" + 
9215
		"    static public class RelEnd extends Relationship.End {\n" + 
9216
		"        public void accept(Visitor visitor) {\n" + 
9217
		"            visitor.visitAssociationEnd(this);\n" + 
9218
		"        }\n" + 
9219
		"    }\n" + 
9220
		"}\n"
9221
	);
9222
	IType type = this.workingCopies[0].getType("Relationship").getType("End");
9223
	searchDeclarationsOfSentMessages(type, this.resultCollector);
9224
	assertSearchResults(
9225
		"src/test/Relationship.java boolean test.Visitor.visitRelationshipEnd(Relationship.End) [visitRelationshipEnd(Relationship.End end)] EXACT_MATCH"
9226
	);
9227
}
9228
9229
/**
9192
 * @bug 209054: [search] for references to method finds wrong interface call
9230
 * @bug 209054: [search] for references to method finds wrong interface call
9193
 * @test Ensure that searching method reference does not find wrong interface call
9231
 * @test Ensure that searching method reference does not find wrong interface call
9194
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=209054"
9232
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=209054"

Return to bug 207657