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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java (+61 lines)
Lines 12-21 Link Here
12
12
13
import org.eclipse.core.runtime.CoreException;
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.Signature;
15
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.search.SearchMatch;
17
import org.eclipse.jdt.core.search.SearchMatch;
17
import org.eclipse.jdt.core.search.SearchPattern;
18
import org.eclipse.jdt.core.search.SearchPattern;
19
import org.eclipse.jdt.core.util.IConstantPoolConstant;
20
import org.eclipse.jdt.core.util.IConstantPoolEntry;
18
import org.eclipse.jdt.internal.compiler.ast.*;
21
import org.eclipse.jdt.internal.compiler.ast.*;
22
import org.eclipse.jdt.internal.compiler.codegen.ConstantPool;
19
import org.eclipse.jdt.internal.compiler.lookup.Binding;
23
import org.eclipse.jdt.internal.compiler.lookup.Binding;
20
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
24
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
21
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding;
Lines 125-130 Link Here
125
	}
129
	}
126
	return level;
130
	return level;
127
}
131
}
132
protected int matchConstructor(char[][] parameterTypes) {
133
	// declaring type, simple name has already been matched by matchIndexEntry()
134
	// parameter types
135
	int parameterCount = this.pattern.parameterCount;
136
	if (parameterCount > -1) {
137
		if (parameterTypes == null) return INACCURATE_MATCH;
138
		if (parameterCount != parameterTypes.length) return IMPOSSIBLE_MATCH;
139
		for (int i = 0; i < parameterCount; i++) {
140
			// TODO (frederic) use this call to refine accuracy on parameter types
141
//			int newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, constructor.parameters[i]);
142
			return resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], parameterTypes[i]);
143
		}
144
	}
145
	return IMPOSSIBLE_MATCH;
146
}
128
protected int matchContainer() {
147
protected int matchContainer() {
129
	if (this.pattern.findReferences) return ALL_CONTAINER; // handles both declarations + references & just references
148
	if (this.pattern.findReferences) return ALL_CONTAINER; // handles both declarations + references & just references
130
	// COMPILATION_UNIT_CONTAINER - implicit constructor call: case of Y extends X and Y doesn't define any constructor
149
	// COMPILATION_UNIT_CONTAINER - implicit constructor call: case of Y extends X and Y doesn't define any constructor
Lines 340-345 Link Here
340
	}
359
	}
341
	return level;
360
	return level;
342
}
361
}
362
public int resolveLevel(IConstantPoolEntry entry) {
363
	if (entry.getKind() != IConstantPoolConstant.CONSTANT_Methodref) {
364
		return IMPOSSIBLE_MATCH;
365
	}
366
	char[] methodName = entry.getMethodName();
367
	if (!CharOperation.equals(ConstantPool.Init, methodName)) return IMPOSSIBLE_MATCH;
368
	int level = IMPOSSIBLE_MATCH;
369
	if (methodName != null) {
370
		char[] methodDescriptor = entry.getMethodDescriptor();
371
		char[] returnType = Signature.getReturnType(methodDescriptor);
372
		returnType = Signature.toCharArray(returnType);
373
		CharOperation.replace(returnType, '/', '.');
374
		char[][] tempParameterTypes = Signature.getParameterTypes(methodDescriptor);
375
		int length = tempParameterTypes.length;
376
		char[][] parameterTypes = null;
377
		if (length != 0) {
378
			parameterTypes = new char[length][];
379
			for (int i = 0, max = parameterTypes.length; i < max; i++) {
380
				parameterTypes[i] = Signature.toCharArray(tempParameterTypes[i]);
381
				CharOperation.replace(parameterTypes[i], '/', '.');
382
			}
383
		} else {
384
			parameterTypes = tempParameterTypes;
385
		}
386
		char[] className = entry.getClassName();
387
		CharOperation.replace(className, '/', '.');
388
		return resolveLevel(className, parameterTypes);
389
	}
390
	return level;
391
}
343
protected int resolveLevel(ConstructorDeclaration constructor, boolean checkDeclarations) {
392
protected int resolveLevel(ConstructorDeclaration constructor, boolean checkDeclarations) {
344
	int referencesLevel = IMPOSSIBLE_MATCH;
393
	int referencesLevel = IMPOSSIBLE_MATCH;
345
	if (this.pattern.findReferences) {
394
	if (this.pattern.findReferences) {
Lines 376-379 Link Here
376
public String toString() {
425
public String toString() {
377
	return "Locator for " + this.pattern.toString(); //$NON-NLS-1$
426
	return "Locator for " + this.pattern.toString(); //$NON-NLS-1$
378
}
427
}
428
protected int resolveLevel(char[] declaringClassName, char[][] parameterTypes) {
429
	int methodLevel = matchConstructor(parameterTypes);
430
	if (methodLevel == IMPOSSIBLE_MATCH) {
431
		return IMPOSSIBLE_MATCH;
432
	}
433
	// declaring type
434
	char[] qualifiedPattern = qualifiedPattern(this.pattern.declaringSimpleName, this.pattern.declaringQualification);
435
	if (qualifiedPattern == null) return methodLevel; // since any declaring class will do
436
437
	int declaringLevel = resolveLevelForType(qualifiedPattern, declaringClassName);
438
	return methodLevel > declaringLevel ? declaringLevel : methodLevel; // return the weaker match
439
}
379
}
440
}
(-)search/org/eclipse/jdt/internal/core/search/matching/PackageReferenceLocator.java (-1 / +1 lines)
Lines 311-317 Link Here
311
			// check that type is located inside this instance of a package fragment
311
			// check that type is located inside this instance of a package fragment
312
			if (!isDeclaringPackageFragment((IPackageFragment)((InternalSearchPattern) this.pattern).focus, (ReferenceBinding)binding))
312
			if (!isDeclaringPackageFragment((IPackageFragment)((InternalSearchPattern) this.pattern).focus, (ReferenceBinding)binding))
313
				return IMPOSSIBLE_MATCH;
313
				return IMPOSSIBLE_MATCH;
314
		}				
314
		}
315
		return ACCURATE_MATCH;
315
		return ACCURATE_MATCH;
316
	}
316
	}
317
	return IMPOSSIBLE_MATCH;
317
	return IMPOSSIBLE_MATCH;
(-)search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java (+201 lines)
Lines 14-19 Link Here
14
import org.eclipse.jdt.core.*;
14
import org.eclipse.jdt.core.*;
15
import org.eclipse.jdt.core.compiler.CharOperation;
15
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.search.*;
16
import org.eclipse.jdt.core.search.*;
17
import org.eclipse.jdt.core.util.ByteCodeVisitorAdapter;
18
import org.eclipse.jdt.core.util.ClassFormatException;
19
import org.eclipse.jdt.core.util.IClassFileReader;
20
import org.eclipse.jdt.core.util.ICodeAttribute;
21
import org.eclipse.jdt.core.util.IConstantPoolEntry;
22
import org.eclipse.jdt.core.util.IMethodInfo;
17
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
23
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
18
import org.eclipse.jdt.internal.compiler.classfmt.FieldInfo;
24
import org.eclipse.jdt.internal.compiler.classfmt.FieldInfo;
19
import org.eclipse.jdt.internal.compiler.classfmt.MethodInfo;
25
import org.eclipse.jdt.internal.compiler.classfmt.MethodInfo;
Lines 24-29 Link Here
24
30
25
public class ClassFileMatchLocator implements IIndexConstants {
31
public class ClassFileMatchLocator implements IIndexConstants {
26
32
33
private static final class ReferenceMatcher extends ByteCodeVisitorAdapter {
34
	
35
	SearchPattern pattern;
36
	MatchLocator locator;
37
	IMethodInfo methodInfo;
38
	BinaryType binaryType;
39
	BinaryTypeBinding binding;
40
	
41
	public ReferenceMatcher(
42
			SearchPattern pattern,
43
			MatchLocator locator,
44
			IMethodInfo methodInfo,
45
			BinaryType binaryType,
46
			BinaryTypeBinding binding) {
47
		this.pattern = pattern;
48
		this.locator = locator;
49
		this.binaryType = binaryType;
50
		this.binding = binding;
51
		this.methodInfo = methodInfo;
52
	}
53
54
	public void _invokeinterface(int pc,
55
			int index,
56
			byte nargs,
57
			IConstantPoolEntry constantInterfaceMethodref) {
58
		matchMethod(constantInterfaceMethodref);
59
	}
60
61
	public void _invokespecial(int pc, int index, IConstantPoolEntry constantMethodref) {
62
		matchMethod(constantMethodref);
63
	}
64
65
	public void _invokestatic(int pc, int index, IConstantPoolEntry constantMethodref) {
66
		matchMethod(constantMethodref);
67
	}
68
69
	public void _invokevirtual(int pc, int index, IConstantPoolEntry constantMethodref) {
70
		matchMethod(constantMethodref);
71
	}
72
73
	private void matchMethod(IConstantPoolEntry entry) {
74
		int level = locator.patternLocator.resolveLevel(entry);
75
		if (level != PatternLocator.IMPOSSIBLE_MATCH) {
76
			// report match
77
			int accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE;
78
			IMethod methodHandle = this.binaryType.getMethod(
79
				new String(this.methodInfo.isConstructor() ? this.binding.compoundName[this.binding.compoundName.length-1] : this.methodInfo.getName()),
80
				CharOperation.toStrings(Signature.getParameterTypes(convertClassFileFormat(this.methodInfo.getDescriptor()))));
81
			MethodReferenceMatch match = new MethodReferenceMatch(
82
					methodHandle,
83
					accuracy,
84
					-1,
85
					0,
86
					this.methodInfo.isConstructor(),
87
					false,
88
					false,
89
					locator.getParticipant(),
90
					null);
91
			try {
92
				locator.report(match);
93
			} catch (CoreException e) {
94
				// ignore
95
			}
96
		}
97
	}
98
	
99
	public void _getfield(int pc, int index, IConstantPoolEntry constantFieldref) {
100
		matchField(constantFieldref, true);
101
	}
102
	public void _getstatic(int pc, int index, IConstantPoolEntry constantFieldref) {
103
		matchField(constantFieldref, true);
104
	}
105
	public void _putfield(int pc, int index, IConstantPoolEntry constantFieldref) {
106
		matchField(constantFieldref, false);
107
	}
108
	public void _putstatic(int pc, int index, IConstantPoolEntry constantFieldref) {
109
		matchField(constantFieldref, false);
110
	}
111
	private void matchField(IConstantPoolEntry entry, boolean isReadAccess) {
112
		int level = locator.patternLocator.resolveLevel(entry);
113
		if (level != PatternLocator.IMPOSSIBLE_MATCH) {
114
			// report match
115
			int accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE : SearchMatch.A_INACCURATE;
116
			IMethod methodHandle = this.binaryType.getMethod(
117
				new String(this.methodInfo.isConstructor() ? this.binding.compoundName[this.binding.compoundName.length-1] : this.methodInfo.getName()),
118
				CharOperation.toStrings(Signature.getParameterTypes(convertClassFileFormat(this.methodInfo.getDescriptor()))));
119
			FieldReferenceMatch match = new FieldReferenceMatch(
120
					methodHandle,
121
					accuracy,
122
					-1,
123
					0,
124
					isReadAccess,
125
					!isReadAccess,
126
					false,
127
					locator.getParticipant(),
128
					null);
129
			try {
130
				locator.report(match);
131
			} catch (CoreException e) {
132
				// ignore
133
			}
134
		}
135
	}
136
}
27
private static final long TARGET_ANNOTATION_BITS = 
137
private static final long TARGET_ANNOTATION_BITS = 
28
	TagBits.AnnotationForType |
138
	TagBits.AnnotationForType |
29
	TagBits.AnnotationForParameter |
139
	TagBits.AnnotationForParameter |
Lines 151-156 Link Here
151
	// check annotations references
261
	// check annotations references
152
	matchAnnotations(pattern, locator, classFile, info);
262
	matchAnnotations(pattern, locator, classFile, info);
153
263
264
	if (searchForReferences(pattern)) {
265
		matchReferences(pattern, locator, classFile, info);
266
	}
154
	// check class definition
267
	// check class definition
155
	BinaryType binaryType = (BinaryType) classFile.getType();
268
	BinaryType binaryType = (BinaryType) classFile.getType();
156
	if (matchBinary(pattern, info, null)) {
269
	if (matchBinary(pattern, info, null)) {
Lines 304-309 Link Here
304
		}
417
		}
305
	}
418
	}
306
}
419
}
420
private void matchReferences(SearchPattern pattern, MatchLocator locator, ClassFile classFile, IBinaryType info) throws CoreException {
421
	BinaryType binaryType = (BinaryType) classFile.getType();
422
	BinaryTypeBinding binding = locator.cacheBinaryType(binaryType, info);
423
	if (binding == null) return;
424
	// filter out element not in hierarchy scope
425
	if (!locator.typeInHierarchy(binding)) return;
426
	int kind = ((InternalSearchPattern)pattern).kind;
427
	switch (kind) {
428
		case CONSTRUCTOR_PATTERN :
429
		case FIELD_PATTERN :
430
		case METHOD_PATTERN :
431
		case SUPER_REF_PATTERN :
432
		case PKG_REF_PATTERN :
433
		case TYPE_REF_PATTERN :
434
			matchReferences(kind, binaryType, pattern, locator, classFile, info, binding);
435
			break;
436
		case OR_PATTERN :
437
			SearchPattern[] patterns = ((OrPattern) pattern).patterns;
438
			for (int i = 0, length = patterns.length; i < length; i++) {
439
				matchReferences(patterns[i], locator, classFile, info);
440
				break;
441
			}
442
	}
443
}
444
/*
445
 * Match references
446
 */
447
private void matchReferences(
448
		int kind,
449
		BinaryType binaryType,
450
		SearchPattern pattern,
451
		MatchLocator locator,
452
		ClassFile classFile,
453
		IBinaryType info,
454
		BinaryTypeBinding binding) throws CoreException {
455
456
	if (classFile != null) {
457
		IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(classFile, IClassFileReader.METHOD_BODIES | IClassFileReader.METHOD_INFOS);
458
		if (classFileReader != null) {
459
			switch(kind) {
460
				case FIELD_PATTERN :
461
				case CONSTRUCTOR_PATTERN :
462
				case METHOD_PATTERN :
463
					IMethodInfo[] methodInfos = classFileReader.getMethodInfos();
464
					for (int i = 0, max = methodInfos.length; i < max; i++) {
465
						IMethodInfo methodInfo = methodInfos[i];
466
						matches(methodInfo, pattern, locator, binaryType, binding);
467
					}
468
					break;
469
//				case SUPER_REF_PATTERN :
470
//				case PKG_REF_PATTERN :
471
//				case TYPE_REF_PATTERN :
472
			}
473
		}
474
	}
475
}
476
private void matches(IMethodInfo methodInfo, SearchPattern pattern, MatchLocator locator, BinaryType binaryType, BinaryTypeBinding binding) {
477
	ICodeAttribute codeAttribute = methodInfo.getCodeAttribute();
478
	if (codeAttribute != null) {
479
		try {
480
			ReferenceMatcher methodReferenceMatcher = new ReferenceMatcher(pattern, locator, methodInfo, binaryType, binding);
481
			codeAttribute.traverse(methodReferenceMatcher);
482
		} catch (ClassFormatException e) {
483
			// ignore
484
		}
485
	}
486
}
487
private boolean searchForReferences(SearchPattern pattern) {
488
	switch (((InternalSearchPattern)pattern).kind) {
489
		case CONSTRUCTOR_PATTERN :
490
			return ((ConstructorPattern) pattern).findReferences;
491
		case FIELD_PATTERN :
492
			return ((FieldPattern) pattern).findReferences;
493
		case METHOD_PATTERN :
494
			return ((MethodPattern) pattern).findReferences;
495
		case SUPER_REF_PATTERN :
496
			return true;
497
		case PKG_REF_PATTERN :
498
			return true;
499
		case OR_PATTERN :
500
			SearchPattern[] patterns = ((OrPattern) pattern).patterns;
501
			for (int i = 0, length = patterns.length; i < length; i++) {
502
				if (searchForReferences(patterns[i])) return true;
503
			}
504
	}
505
	return false;
506
}
507
307
/*
508
/*
308
 * Look for annotations references
509
 * Look for annotations references
309
 */
510
 */
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (+99 lines)
Lines 17-22 Link Here
17
import org.eclipse.jdt.core.*;
17
import org.eclipse.jdt.core.*;
18
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.CharOperation;
19
import org.eclipse.jdt.core.search.*;
19
import org.eclipse.jdt.core.search.*;
20
import org.eclipse.jdt.core.util.IConstantPoolConstant;
21
import org.eclipse.jdt.core.util.IConstantPoolEntry;
20
import org.eclipse.jdt.internal.compiler.ast.*;
22
import org.eclipse.jdt.internal.compiler.ast.*;
21
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
23
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
22
import org.eclipse.jdt.internal.compiler.lookup.*;
24
import org.eclipse.jdt.internal.compiler.lookup.*;
Lines 603-608 Link Here
603
		: resolveLevelForType(qualifiedPattern, method.declaringClass);
605
		: resolveLevelForType(qualifiedPattern, method.declaringClass);
604
	return methodLevel > declaringLevel ? declaringLevel : methodLevel; // return the weaker match
606
	return methodLevel > declaringLevel ? declaringLevel : methodLevel; // return the weaker match
605
}
607
}
608
protected int resolveLevel(char[] methodName, char[] declaringClassName, char[][] parameterTypes, char[] returnType) {
609
	int methodLevel = matchMethod(methodName, parameterTypes, returnType);
610
	if (methodLevel == IMPOSSIBLE_MATCH) {
611
		return IMPOSSIBLE_MATCH;
612
	}
613
614
	// declaring type
615
	char[] qualifiedPattern = qualifiedPattern(this.pattern.declaringSimpleName, this.pattern.declaringQualification);
616
	if (qualifiedPattern == null) return methodLevel; // since any declaring class will do
617
618
	int declaringLevel = resolveLevelForType(qualifiedPattern, declaringClassName);
619
	return methodLevel > declaringLevel ? declaringLevel : methodLevel; // return the weaker match
620
}
621
protected int matchMethod(char[] methodName, char[][] parameterTypes, char[] returnType) {
622
	if (!matchesName(this.pattern.selector, methodName)) return IMPOSSIBLE_MATCH;
623
624
	int level = ACCURATE_MATCH;
625
	// look at return type only if declaring type is not specified
626
	if (this.pattern.declaringSimpleName == null) {
627
		// TODO (frederic) use this call to refine accuracy on return type
628
		// int newLevel = resolveLevelForType(this.pattern.returnSimpleName, this.pattern.returnQualification, this.pattern.returnTypeArguments, 0, method.returnType);
629
		int newLevel = resolveLevelForType(this.pattern.returnSimpleName, this.pattern.returnQualification, returnType);
630
		if (level > newLevel) {
631
			if (newLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH;
632
			level = newLevel; // can only be downgraded
633
		}
634
	}
635
636
	// parameter types
637
	int parameterCount = this.pattern.parameterSimpleNames == null ? -1 : this.pattern.parameterSimpleNames.length;
638
	if (parameterCount > -1) {
639
		// global verification
640
		if (parameterCount != parameterTypes.length) return IMPOSSIBLE_MATCH;
641
642
		// verify each parameter
643
		for (int i = 0; i < parameterCount; i++) {
644
			char[] parameterType = parameterTypes[i];
645
			int newLevel = IMPOSSIBLE_MATCH;
646
			if (CharOperation.indexOf('$', parameterType) != -1) {
647
				// only compare source name for member type (bug 41018)
648
				newLevel = CharOperation.match(this.pattern.parameterSimpleNames[i], getSimpleName(parameterType), this.isCaseSensitive)
649
					? ACCURATE_MATCH
650
					: IMPOSSIBLE_MATCH;
651
			} else {
652
				newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], parameterType);
653
			}
654
			if (level > newLevel) {
655
				if (newLevel == IMPOSSIBLE_MATCH) {
656
					return IMPOSSIBLE_MATCH;
657
				}
658
				level = newLevel; // can only be downgraded
659
			}
660
		}
661
	}
662
663
	return level;
664
}
665
public int resolveLevel(IConstantPoolEntry entry) {
666
	switch(entry.getKind()) {
667
		case IConstantPoolConstant.CONSTANT_Methodref :
668
		case IConstantPoolConstant.CONSTANT_InterfaceMethodref :
669
			break;
670
		default:
671
			return IMPOSSIBLE_MATCH;
672
	}
673
	char[] methodName = entry.getMethodName();
674
	int level = IMPOSSIBLE_MATCH;
675
	if (methodName != null) {
676
		char[] methodDescriptor = entry.getMethodDescriptor();
677
		char[] returnType = Signature.getReturnType(methodDescriptor);
678
		returnType = Signature.toCharArray(returnType);
679
		CharOperation.replace(returnType, '/', '.');
680
		char[][] tempParameterTypes = Signature.getParameterTypes(methodDescriptor);
681
		int length = tempParameterTypes.length;
682
		char[][] parameterTypes = null;
683
		if (length != 0) {
684
			parameterTypes = new char[length][];
685
			for (int i = 0, max = parameterTypes.length; i < max; i++) {
686
				parameterTypes[i] = Signature.toCharArray(tempParameterTypes[i]);
687
				CharOperation.replace(parameterTypes[i], '/', '.');
688
			}
689
		} else {
690
			parameterTypes = tempParameterTypes;
691
		}
692
		char[] className = entry.getClassName();
693
		CharOperation.replace(className, '/', '.');
694
		return resolveLevel(methodName, className, parameterTypes, returnType);
695
	}
696
	return level;
697
}
698
private char[] getSimpleName(char[] typeName) {
699
	int index = CharOperation.lastIndexOf('.', typeName);
700
	if (index == -1) {
701
		return typeName;
702
	}
703
	return CharOperation.subarray(typeName, index + 1, typeName.length);
704
}
606
protected int resolveLevel(MessageSend messageSend) {
705
protected int resolveLevel(MessageSend messageSend) {
607
	MethodBinding method = messageSend.binding;
706
	MethodBinding method = messageSend.binding;
608
	if (method == null) {
707
	if (method == null) {
(-)search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java (+62 lines)
Lines 14-19 Link Here
14
import org.eclipse.jdt.core.*;
14
import org.eclipse.jdt.core.*;
15
import org.eclipse.jdt.core.compiler.*;
15
import org.eclipse.jdt.core.compiler.*;
16
import org.eclipse.jdt.core.search.*;
16
import org.eclipse.jdt.core.search.*;
17
import org.eclipse.jdt.core.util.IConstantPoolEntry;
17
import org.eclipse.jdt.internal.compiler.ast.*;
18
import org.eclipse.jdt.internal.compiler.ast.*;
18
import org.eclipse.jdt.internal.compiler.lookup.*;
19
import org.eclipse.jdt.internal.compiler.lookup.*;
19
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
20
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
Lines 756-761 Link Here
756
	}
757
	}
757
	return IMPOSSIBLE_MATCH;
758
	return IMPOSSIBLE_MATCH;
758
}
759
}
760
/**
761
 * Returns whether the given type binding matches the given simple name pattern 
762
 * and qualification pattern.
763
 * Note that from since 3.1, this method resolve to accurate member or local types
764
 * even if they are not fully qualified (ie. X.Member instead of p.X.Member).
765
 * Returns ACCURATE_MATCH if it does.
766
 * Returns INACCURATE_MATCH if resolve failed.
767
 * Returns IMPOSSIBLE_MATCH if it doesn't.
768
 */
769
protected int resolveLevelForType(char[] simpleNamePattern, char[] qualificationPattern, char[] typeName) {
770
//	return resolveLevelForType(qualifiedPattern(simpleNamePattern, qualificationPattern), type);
771
	char[] qualifiedPattern = qualifiedPattern(simpleNamePattern, qualificationPattern);
772
	int level = resolveLevelForType(qualifiedPattern, typeName);
773
	if (level == ACCURATE_MATCH) return level;
774
	switch (this.matchMode) {
775
		case SearchPattern.R_PREFIX_MATCH:
776
			if (CharOperation.prefixEquals(qualifiedPattern, typeName, this.isCaseSensitive)) {
777
				return ACCURATE_MATCH;
778
			}
779
			break;
780
		case SearchPattern.R_CAMELCASE_MATCH:
781
			if ((qualifiedPattern.length>0 && typeName.length>0 && qualifiedPattern[0] == typeName[0])) {
782
				if (CharOperation.camelCaseMatch(qualifiedPattern, typeName, false)) {
783
					return ACCURATE_MATCH;
784
				}
785
				if (!this.isCaseSensitive && CharOperation.prefixEquals(qualifiedPattern, typeName, false)) {
786
					return ACCURATE_MATCH;
787
				}
788
			}
789
			break;
790
		case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH:
791
			if ((qualifiedPattern.length>0 && typeName.length>0 && qualifiedPattern[0] == typeName[0])) {
792
				if (CharOperation.camelCaseMatch(qualifiedPattern, typeName, true)) {
793
					return ACCURATE_MATCH;
794
				}
795
			}
796
			break;
797
		default:
798
			if (CharOperation.match(qualifiedPattern, typeName, this.isCaseSensitive)) {
799
				return ACCURATE_MATCH;
800
			}
801
	}
802
	return IMPOSSIBLE_MATCH;
803
}
759
804
760
/**
805
/**
761
 * Returns whether the given type binding matches the given qualified pattern.
806
 * Returns whether the given type binding matches the given qualified pattern.
Lines 781-786 Link Here
781
		? ACCURATE_MATCH
826
		? ACCURATE_MATCH
782
		: IMPOSSIBLE_MATCH;
827
		: IMPOSSIBLE_MATCH;
783
}
828
}
829
/**
830
 * Returns whether the given type binding matches the given qualified pattern.
831
 * Returns ACCURATE_MATCH if it does.
832
 * Returns INACCURATE_MATCH if resolve failed.
833
 * Returns IMPOSSIBLE_MATCH if it doesn't.
834
 */
835
protected int resolveLevelForType(char[] qualifiedPattern, char[] typeName) {
836
	if (qualifiedPattern == null) return ACCURATE_MATCH;
837
838
	return CharOperation.match(qualifiedPattern, typeName, this.isCaseSensitive)
839
		? ACCURATE_MATCH
840
		: IMPOSSIBLE_MATCH;
841
}
784
/* (non-Javadoc)
842
/* (non-Javadoc)
785
 * Resolve level for type with a given binding with all pattern information.
843
 * Resolve level for type with a given binding with all pattern information.
786
 */
844
 */
Lines 953-958 Link Here
953
	}
1011
	}
954
	return level;
1012
	return level;
955
}
1013
}
1014
public int resolveLevel(IConstantPoolEntry entry) {
1015
	// override if the pattern can match the binding
1016
	return INACCURATE_MATCH;
1017
}
956
public String toString(){
1018
public String toString(){
957
	return "SearchPattern"; //$NON-NLS-1$
1019
	return "SearchPattern"; //$NON-NLS-1$
958
}
1020
}
(-)search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java (+30 lines)
Lines 15-20 Link Here
15
import org.eclipse.jdt.core.*;
15
import org.eclipse.jdt.core.*;
16
import org.eclipse.jdt.core.compiler.CharOperation;
16
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.core.search.*;
17
import org.eclipse.jdt.core.search.*;
18
import org.eclipse.jdt.core.util.IConstantPoolConstant;
19
import org.eclipse.jdt.core.util.IConstantPoolEntry;
18
import org.eclipse.jdt.internal.compiler.ast.*;
20
import org.eclipse.jdt.internal.compiler.ast.*;
19
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
21
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
20
import org.eclipse.jdt.internal.compiler.lookup.*;
22
import org.eclipse.jdt.internal.compiler.lookup.*;
Lines 119-124 Link Here
119
	int typeLevel = resolveLevelForType(fieldBinding.type);
121
	int typeLevel = resolveLevelForType(fieldBinding.type);
120
	return declaringLevel > typeLevel ? typeLevel : declaringLevel; // return the weaker match
122
	return declaringLevel > typeLevel ? typeLevel : declaringLevel; // return the weaker match
121
}
123
}
124
protected int matchField(char[] declaringClass, char[] fieldName, char[] fieldType) {
125
	if (!matchesName(this.pattern.name, fieldName)) return IMPOSSIBLE_MATCH;
126
127
	FieldPattern fieldPattern = (FieldPattern)this.pattern;
128
	// TODO need to handle the array length case
129
	
130
	// Note there is no dynamic lookup for field access
131
	CharOperation.replace(declaringClass, '/', '.');
132
	int declaringLevel = resolveLevelForType(fieldPattern.declaringSimpleName, fieldPattern.declaringQualification, declaringClass);
133
	if (declaringLevel == IMPOSSIBLE_MATCH) return IMPOSSIBLE_MATCH;
134
135
	// look at field type only if declaring type is not specified
136
	if (fieldPattern.declaringSimpleName == null) return declaringLevel;
137
138
	// TODO might need to handle generic type
139
	fieldType = Signature.toCharArray(fieldType);
140
	CharOperation.replace(fieldType, '/', '.');
141
	int typeLevel = resolveLevelForType(
142
			fieldPattern.typeSimpleName,
143
			fieldPattern.typeQualification,
144
			fieldType);
145
	return declaringLevel > typeLevel ? typeLevel : declaringLevel; // return the weaker match
146
}
122
/* (non-Javadoc)
147
/* (non-Javadoc)
123
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchLevelAndReportImportRef(org.eclipse.jdt.internal.compiler.ast.ImportReference, org.eclipse.jdt.internal.compiler.lookup.Binding, org.eclipse.jdt.internal.core.search.matching.MatchLocator)
148
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchLevelAndReportImportRef(org.eclipse.jdt.internal.compiler.ast.ImportReference, org.eclipse.jdt.internal.compiler.lookup.Binding, org.eclipse.jdt.internal.core.search.matching.MatchLocator)
124
 * Accept to report match of static field on static import
149
 * Accept to report match of static field on static import
Lines 309-314 Link Here
309
334
310
	return matchField((FieldBinding) binding, true);
335
	return matchField((FieldBinding) binding, true);
311
}
336
}
337
public int resolveLevel(IConstantPoolEntry entry) {
338
	if (entry.getKind() != IConstantPoolConstant.CONSTANT_Fieldref) return IMPOSSIBLE_MATCH;
339
340
	return matchField(entry.getClassName(), entry.getFieldName(), entry.getFieldDescriptor());
341
}
312
protected int resolveLevel(NameReference nameRef) {
342
protected int resolveLevel(NameReference nameRef) {
313
	if (nameRef instanceof SingleNameReference)
343
	if (nameRef instanceof SingleNameReference)
314
		return resolveLevel(nameRef.binding);
344
		return resolveLevel(nameRef.binding);

Return to bug 127442