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

Collapse All | Expand All

(-)search/org/eclipse/jdt/core/search/PackageReferenceMatch.java (-17 / +34 lines)
Lines 22-43 Link Here
22
 * 
22
 * 
23
 * @since 3.0
23
 * @since 3.0
24
 */
24
 */
25
public class PackageReferenceMatch extends SearchMatch {
25
public class PackageReferenceMatch extends ReferenceMatch {
26
26
27
	/**
27
/**
28
	 * Creates a new package reference match.
28
 * Creates a new package reference match.
29
	 * 
29
 * 
30
	 * @param enclosingElement the inner-most enclosing member that references this package
30
 * @param enclosingElement the inner-most enclosing member that references this package
31
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
31
 * @param localElement the nearest local element enclosing this package reference
32
	 * @param offset the offset the match starts at, or -1 if unknown
32
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
33
	 * @param length the length of the match, or -1 if unknown
33
 * @param offset the offset the match starts at, or -1 if unknown
34
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
34
 * @param length the length of the match, or -1 if unknown
35
	 * comment, and <code>false</code> otherwise
35
 * @param insideDocComment <code>true</code> if this search match is inside a doc
36
	 * @param participant the search participant that created the match
36
 * 				comment, and <code>false</code> otherwise
37
	 * @param resource the resource of the element
37
 * @param participant the search participant that created the match
38
	 */
38
 * @param resource the resource of the element
39
	public PackageReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
39
 */
40
		super(enclosingElement, accuracy, offset, length, participant, resource);
40
public PackageReferenceMatch(IJavaElement enclosingElement, IJavaElement localElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
41
		setInsideDocComment(insideDocComment);
41
	super(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource);
42
	}
42
}
43
44
/**
45
 * Creates a new package reference match.
46
 * 
47
 * @param enclosingElement the inner-most enclosing member that references this package
48
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
49
 * @param offset the offset the match starts at, or -1 if unknown
50
 * @param length the length of the match, or -1 if unknown
51
 * @param insideDocComment <code>true</code> if this search match is inside a doc
52
 * 				comment, and <code>false</code> otherwise
53
 * @param participant the search participant that created the match
54
 * @param resource the resource of the element
55
 *  @deprecated
56
 */
57
public PackageReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
58
	super(enclosingElement, null, accuracy, offset, length, insideDocComment, participant, resource);
59
}
43
}
60
}
(-)search/org/eclipse/jdt/core/search/FieldReferenceMatch.java (-41 / +59 lines)
Lines 22-71 Link Here
22
 * 
22
 * 
23
 * @since 3.0
23
 * @since 3.0
24
 */
24
 */
25
public class FieldReferenceMatch extends SearchMatch {
25
public class FieldReferenceMatch extends ReferenceMatch {
26
26
27
	private boolean isReadAccess;
27
	private boolean isReadAccess;
28
	private boolean isWriteAccess;
28
	private boolean isWriteAccess;
29
29
30
	/**
30
/**
31
	 * Creates a new field reference match.
31
 * Creates a new field reference match.
32
	 * 
32
 * 
33
	 * @param enclosingElement the inner-most enclosing member that references this field
33
 * @param enclosingElement the inner-most enclosing member that references this field
34
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
34
 * @param localElement the nearest local element enclosing this field reference
35
	 * @param offset the offset the match starts at, or -1 if unknown
35
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
36
	 * @param length the length of the match, or -1 if unknown
36
 * @param offset the offset the match starts at, or -1 if unknown
37
	 * @param isReadAccess whether the match represents a read access
37
 * @param length the length of the match, or -1 if unknown
38
	 * @param isWriteAccess whether the match represents a write access
38
 * @param isReadAccess whether the match represents a read access
39
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
39
 * @param isWriteAccess whether the match represents a write access
40
	 * comment, and <code>false</code> otherwise
40
 * @param insideDocComment <code>true</code> if this search match is inside a doc
41
	 * @param participant the search participant that created the match
41
 * 	comment, and <code>false</code> otherwise
42
	 * @param resource the resource of the element
42
 * @param participant the search participant that created the match
43
	 */
43
 * @param resource the resource of the element
44
	public FieldReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean isReadAccess, boolean isWriteAccess, boolean insideDocComment, SearchParticipant participant, IResource resource) {
44
 */
45
		super(enclosingElement, accuracy, offset, length, participant, resource);
45
public FieldReferenceMatch(IJavaElement enclosingElement, IJavaElement localElement, int accuracy, int offset, int length, boolean isReadAccess, boolean isWriteAccess, boolean insideDocComment, SearchParticipant participant, IResource resource) {
46
		this.isReadAccess = isReadAccess;
46
	super(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource);
47
		this.isWriteAccess = isWriteAccess;
47
	this.isReadAccess = isReadAccess;
48
		setInsideDocComment(insideDocComment);
48
	this.isWriteAccess = isWriteAccess;
49
	}
49
}
50
	
50
51
	/**
51
/**
52
	 * Returns whether the field reference is a read access to the field.
52
 * Creates a new field reference match.
53
	 * Note that a field reference can be read and written at once in case of compound assignments (e.g. i += 0;)
53
 * 
54
	 * 
54
 * @param enclosingElement the inner-most enclosing member that references this field
55
	 * @return whether the field reference is a read access to the field.
55
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
56
	 */
56
 * @param offset the offset the match starts at, or -1 if unknown
57
	public final boolean isReadAccess() {
57
 * @param length the length of the match, or -1 if unknown
58
		return this.isReadAccess;
58
 * @param isReadAccess whether the match represents a read access
59
	}
59
 * @param isWriteAccess whether the match represents a write access
60
 * @param insideDocComment <code>true</code> if this search match is inside a doc
61
 * comment, and <code>false</code> otherwise
62
 * @param participant the search participant that created the match
63
 * @param resource the resource of the element
64
 *  @deprecated
65
 */
66
public FieldReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean isReadAccess, boolean isWriteAccess, boolean insideDocComment, SearchParticipant participant, IResource resource) {
67
	this(enclosingElement, null, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource);
68
}
60
69
61
	/**
70
/**
62
	 * Returns whether the field reference is a write access to the field.
71
 * Returns whether the field reference is a read access to the field.
63
	 * Note that a field reference can be read and written at once in case of compound assignments (e.g. i += 0;)
72
 * Note that a field reference can be read and written at once in case of compound assignments (e.g. i += 0;)
64
	 * 
73
 * 
65
	 * @return whether the field reference is a write access to the field.
74
 * @return whether the field reference is a read access to the field.
66
	 */
75
 */
67
	public final boolean isWriteAccess() {
76
public final boolean isReadAccess() {
68
		return this.isWriteAccess;
77
	return this.isReadAccess;
69
	}
78
}
70
	
79
80
/**
81
 * Returns whether the field reference is a write access to the field.
82
 * Note that a field reference can be read and written at once in case of compound assignments (e.g. i += 0;)
83
 * 
84
 * @return whether the field reference is a write access to the field.
85
 */
86
public final boolean isWriteAccess() {
87
	return this.isWriteAccess;
88
}
71
}
89
}
(-)search/org/eclipse/jdt/core/search/TypeParameterReferenceMatch.java (-18 / +35 lines)
Lines 14-20 Link Here
14
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.IJavaElement;
15
15
16
/**
16
/**
17
 * A Java search match that represents a type parameter declaration or reference.
17
 * A Java search match that represents a type parameter reference.
18
 * The element is the inner-most enclosing member that references this type parameter.
18
 * The element is the inner-most enclosing member that references this type parameter.
19
 * <p>
19
 * <p>
20
 * This class is intended to be instantiated and subclassed by clients.
20
 * This class is intended to be instantiated and subclassed by clients.
Lines 22-43 Link Here
22
 * 
22
 * 
23
 * @since 3.1
23
 * @since 3.1
24
 */
24
 */
25
public class TypeParameterReferenceMatch extends SearchMatch {
25
public class TypeParameterReferenceMatch extends ReferenceMatch {
26
26
27
	/**
27
/**
28
	 * Creates a new field reference match.
28
 * Creates a new type parameter reference match.
29
	 * 
29
 * 
30
	 * @param enclosingElement the inner-most enclosing member that references this field
30
 * @param enclosingElement the inner-most enclosing member that references this field
31
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
31
 * @param localElement the nearest local element enclosing this type parameter reference
32
	 * @param offset the offset the match starts at, or -1 if unknown
32
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
33
	 * @param length the length of the match, or -1 if unknown
33
 * @param offset the offset the match starts at, or -1 if unknown
34
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
34
 * @param length the length of the match, or -1 if unknown
35
	 * comment, and <code>false</code> otherwise
35
 * @param insideDocComment <code>true</code> if this search match is inside a doc
36
	 * @param participant the search participant that created the match
36
 * 				comment, and <code>false</code> otherwise
37
	 * @param resource the resource of the element
37
 * @param participant the search participant that created the match
38
	 */
38
 * @param resource the resource of the element
39
	public TypeParameterReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
39
 */
40
		super(enclosingElement, accuracy, offset, length, participant, resource);
40
public TypeParameterReferenceMatch(IJavaElement enclosingElement, IJavaElement localElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
41
		setInsideDocComment(insideDocComment);
41
	super(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource);
42
	}
42
}
43
44
/**
45
 * Creates a new type parameter reference match.
46
 * 
47
 * @param enclosingElement the inner-most enclosing member that references this field
48
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
49
 * @param offset the offset the match starts at, or -1 if unknown
50
 * @param length the length of the match, or -1 if unknown
51
 * @param insideDocComment <code>true</code> if this search match is inside a doc
52
 * 				comment, and <code>false</code> otherwise
53
 * @param participant the search participant that created the match
54
 * @param resource the resource of the element
55
 *  @deprecated
56
 */
57
public TypeParameterReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
58
	super(enclosingElement, null, accuracy, offset, length, insideDocComment, participant, resource);
59
}
43
}
60
}
(-)search/org/eclipse/jdt/core/search/MethodReferenceMatch.java (-100 / +126 lines)
Lines 22-129 Link Here
22
 * 
22
 * 
23
 * @since 3.0
23
 * @since 3.0
24
 */
24
 */
25
public class MethodReferenceMatch extends SearchMatch {
25
public class MethodReferenceMatch extends ReferenceMatch {
26
	private boolean constructor;
26
	private boolean constructor;
27
	private boolean synthetic;
27
	private boolean synthetic;
28
	private boolean superInvocation;
28
	private boolean superInvocation;
29
29
30
	/**
30
/**
31
	 * Creates a new method reference match.
31
 * Creates a new method reference match.
32
	 * 
32
 * 
33
	 * @param enclosingElement the inner-most enclosing member that references this method
33
 * @param enclosingElement the inner-most enclosing member that references this method
34
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
34
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
35
	 * @param offset the offset the match starts at, or -1 if unknown
35
 * @param offset the offset the match starts at, or -1 if unknown
36
	 * @param length the length of the match, or -1 if unknown
36
 * @param length the length of the match, or -1 if unknown
37
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
37
 * @param insideDocComment <code>true</code> if this search match is inside a doc
38
	 * comment, and <code>false</code> otherwise
38
 * 				comment, and <code>false</code> otherwise
39
	 * @param participant the search participant that created the match
39
 * @param participant the search participant that created the match
40
	 * @param resource the resource of the element
40
 * @param resource the resource of the element
41
	 */
41
 */
42
	public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
42
public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
43
		super(enclosingElement, accuracy, offset, length, participant, resource);
43
	super(enclosingElement, null, accuracy, offset, length, insideDocComment, participant, resource);
44
		setInsideDocComment(insideDocComment);
44
}
45
	}
45
46
46
/**
47
	/**
47
 * Creates a new method reference match.
48
	 * Creates a new method reference match.
48
 * 
49
	 * 
49
 * @param enclosingElement the inner-most enclosing member that references this method
50
	 * @param enclosingElement the inner-most enclosing member that references this method
50
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
51
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
51
 * @param offset the offset the match starts at, or -1 if unknown
52
	 * @param offset the offset the match starts at, or -1 if unknown
52
 * @param length the length of the match, or -1 if unknown
53
	 * @param length the length of the match, or -1 if unknown
53
 * @param constructor <code>true</code> if this search match a constructor
54
	 * @param constructor <code>true</code> if this search match a constructor
54
 * <code>false</code> otherwise
55
	 * <code>false</code> otherwise
55
 * @param synthetic <code>true</code> if this search match a synthetic element
56
	 * @param synthetic <code>true</code> if this search match a synthetic element
56
 * <code>false</code> otherwise
57
	 * <code>false</code> otherwise
57
 * @param insideDocComment <code>true</code> if this search match is inside a doc
58
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
58
 * comment, and <code>false</code> otherwise
59
	 * comment, and <code>false</code> otherwise
59
 * @param participant the search participant that created the match
60
	 * @param participant the search participant that created the match
60
 * @param resource the resource of the element
61
	 * @param resource the resource of the element
61
 * @since 3.1
62
	 * @since 3.1
62
 */
63
	 */
63
public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean constructor, boolean synthetic, boolean insideDocComment, SearchParticipant participant, IResource resource) {
64
	public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean constructor, boolean synthetic, boolean insideDocComment, SearchParticipant participant, IResource resource) {
64
	this(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource);
65
		this(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource);
65
	this.constructor = constructor;
66
		this.constructor = constructor;
66
	this.synthetic = synthetic;
67
		this.synthetic = synthetic;
67
}
68
	}
68
69
69
/**
70
	/**
70
 * Creates a new method reference match.
71
	 * Creates a new method reference match.
71
 * 
72
	 * 
72
 * @param enclosingElement the inner-most enclosing member that references this method
73
	 * @param enclosingElement the inner-most enclosing member that references this method
73
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
74
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
74
 * @param offset the offset the match starts at, or -1 if unknown
75
	 * @param offset the offset the match starts at, or -1 if unknown
75
 * @param length the length of the match, or -1 if unknown
76
	 * @param length the length of the match, or -1 if unknown
76
 * @param constructor <code>true</code> if this search matches a constructor
77
	 * @param constructor <code>true</code> if this search matches a constructor
77
 * 				<code>false</code> otherwise
78
	 * <code>false</code> otherwise
78
 * @param synthetic <code>true</code> if this search matches a synthetic element
79
	 * @param synthetic <code>true</code> if this search matches a synthetic element
79
 * 				<code>false</code> otherwise
80
	 * <code>false</code> otherwise
80
 * @param superInvocation <code>true</code> if this search matches a super-type invocation
81
	 * @param superInvocation <code>true</code> if this search matches a super-type invocation
81
 * 				element <code>false</code> otherwise
82
	 * element <code>false</code> otherwise
82
 * @param insideDocComment <code>true</code> if this search match is inside a doc
83
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
83
 * 				comment, and <code>false</code> otherwise
84
	 * comment, and <code>false</code> otherwise
84
 * @param participant the search participant that created the match
85
	 * @param participant the search participant that created the match
85
 * @param resource the resource of the element
86
	 * @param resource the resource of the element
86
 * @since 3.3
87
	 * @since 3.3
87
 */
88
	 */
88
public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean constructor, boolean synthetic, boolean superInvocation, boolean insideDocComment, SearchParticipant participant, IResource resource) {
89
	public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean constructor, boolean synthetic, boolean superInvocation, boolean insideDocComment, SearchParticipant participant, IResource resource) {
89
	this(enclosingElement, accuracy, offset, length, constructor, synthetic, insideDocComment, participant, resource);
90
		this(enclosingElement, accuracy, offset, length, constructor, synthetic, insideDocComment, participant, resource);
90
	this.superInvocation = superInvocation;
91
		this.superInvocation = superInvocation;
91
}
92
	}
92
93
93
/**
94
	/**
94
 * Creates a new method reference match.
95
	 * Returns whether the reference is on a constructor.
95
 * 
96
	 *
96
 * @param enclosingElement the inner-most enclosing member that references this method
97
	 * @return Returns whether the reference is on a constructor or not.
97
 * @param localElement the nearest local element enclosing this method reference
98
	 * @since 3.1
98
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
99
	 */
99
 * @param offset the offset the match starts at, or -1 if unknown
100
	public final boolean isConstructor() {
100
 * @param length the length of the match, or -1 if unknown
101
		return this.constructor;
101
 * @param constructor <code>true</code> if this search matches a constructor
102
	}
102
 * 				<code>false</code> otherwise
103
	
103
 * @param synthetic <code>true</code> if this search matches a synthetic element
104
	/**
104
 * 				<code>false</code> otherwise
105
	 * Returns whether the reference is on a synthetic element.
105
 * @param superInvocation <code>true</code> if this search matches a super-type invocation
106
	 * Note that this field is only used for constructor reference. This happens when default constructor
106
 * 				element <code>false</code> otherwise
107
	 * declaration is used or implicit super constructor is called.
107
 * @param insideDocComment <code>true</code> if this search match is inside a doc
108
	 * 
108
 * 				comment, and <code>false</code> otherwise
109
	 * @return whether the reference is synthetic or not.
109
 * @param participant the search participant that created the match
110
	 * @since 3.1
110
 * @param resource the resource of the element
111
	 */
111
 * @since 3.4
112
	public final boolean isSynthetic() {
112
 */
113
		return this.synthetic;
113
public MethodReferenceMatch(IJavaElement enclosingElement, IJavaElement localElement, int accuracy, int offset, int length, boolean constructor, boolean synthetic, boolean superInvocation, boolean insideDocComment, SearchParticipant participant, IResource resource) {
114
	}
114
	super(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource);
115
115
	this.constructor = constructor;
116
	/**
116
	this.synthetic = synthetic;
117
	 * Returns whether the reference is on a message sent from a type
117
	this.superInvocation = superInvocation;
118
	 * which is a super type of the searched method declaring type.
118
}
119
	 * If <code>true</code>, the method called at run-time may or may not be
119
120
	 * the search target, depending on the run-time type of the receiver object.
120
/**
121
	 * 
121
 * Returns whether the reference is on a constructor.
122
	 * @return <code>true</code> if the reference is on a message sent from
122
 *
123
	 * a super-type of the searched method declaring class, <code>false </code> otherwise
123
 * @return Returns whether the reference is on a constructor or not.
124
	 * @since 3.3
124
 * @since 3.1
125
	 */
125
 */
126
	public boolean isSuperInvocation() {
126
public final boolean isConstructor() {
127
		return this.superInvocation;
127
	return this.constructor;
128
	}
128
}
129
130
/**
131
 * Returns whether the reference is on a synthetic element.
132
 * Note that this field is only used for constructor reference. This happens when default constructor
133
 * declaration is used or implicit super constructor is called.
134
 * 
135
 * @return whether the reference is synthetic or not.
136
 * @since 3.1
137
 */
138
public final boolean isSynthetic() {
139
	return this.synthetic;
140
}
141
142
/**
143
 * Returns whether the reference is on a message sent from a type
144
 * which is a super type of the searched method declaring type.
145
 * If <code>true</code>, the method called at run-time may or may not be
146
 * the search target, depending on the run-time type of the receiver object.
147
 * 
148
 * @return <code>true</code> if the reference is on a message sent from
149
 * a super-type of the searched method declaring class, <code>false </code> otherwise
150
 * @since 3.3
151
 */
152
public boolean isSuperInvocation() {
153
	return this.superInvocation;
154
}
129
}
155
}
(-)search/org/eclipse/jdt/core/search/LocalVariableReferenceMatch.java (-39 / +58 lines)
Lines 22-70 Link Here
22
 * 
22
 * 
23
 * @since 3.0
23
 * @since 3.0
24
 */
24
 */
25
public class LocalVariableReferenceMatch extends SearchMatch {
25
public class LocalVariableReferenceMatch extends ReferenceMatch {
26
26
27
	private boolean isReadAccess;
27
	private boolean isReadAccess;
28
	private boolean isWriteAccess;
28
	private boolean isWriteAccess;
29
29
30
	/**
30
/**
31
	 * Creates a new local variable reference match.
31
 * Creates a new local variable reference match.
32
	 * 
32
 * 
33
	 * @param enclosingElement the inner-most enclosing member that references this local variable
33
 * @param enclosingElement the inner-most enclosing member that references this local variable
34
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
34
 * @param localElement the nearest local element enclosing this local variable reference
35
	 * @param offset the offset the match starts at, or -1 if unknown
35
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
36
	 * @param length the length of the match, or -1 if unknown
36
 * @param offset the offset the match starts at, or -1 if unknown
37
	 * @param isReadAccess whether the match represents a read access
37
 * @param length the length of the match, or -1 if unknown
38
	 * @param isWriteAccess whethre the match represents a write access
38
 * @param isReadAccess whether the match represents a read access
39
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
39
 * @param isWriteAccess whethre the match represents a write access
40
	 * comment, and <code>false</code> otherwise
40
 * @param insideDocComment <code>true</code> if this search match is inside a doc
41
	 * @param participant the search participant that created the match
41
 * comment, and <code>false</code> otherwise
42
	 * @param resource the resource of the element
42
 * @param participant the search participant that created the match
43
	 */
43
 * @param resource the resource of the element
44
	public LocalVariableReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean isReadAccess, boolean isWriteAccess, boolean insideDocComment, SearchParticipant participant, IResource resource) {
44
 */
45
		super(enclosingElement, accuracy, offset, length, participant, resource);
45
public LocalVariableReferenceMatch(IJavaElement enclosingElement, IJavaElement localElement, int accuracy, int offset, int length, boolean isReadAccess, boolean isWriteAccess, boolean insideDocComment, SearchParticipant participant, IResource resource) {
46
		this.isReadAccess = isReadAccess;
46
	super(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource);
47
		this.isWriteAccess = isWriteAccess;
47
	this.isReadAccess = isReadAccess;
48
		setInsideDocComment(insideDocComment);
48
	this.isWriteAccess = isWriteAccess;
49
	}
49
}
50
50
51
	/**
51
/**
52
	 * Returns whether the local variable reference is a read access to the variable.
52
 * Creates a new local variable reference match.
53
	 * Note that a local variable reference can be read and written at once in case of compound assignments (e.g. i += 0;)
53
 * 
54
	 * 
54
 * @param enclosingElement the inner-most enclosing member that references this local variable
55
	 * @return whether the local variable reference is a read access to the variable.
55
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
56
	 */
56
 * @param offset the offset the match starts at, or -1 if unknown
57
	public final boolean isReadAccess() {
57
 * @param length the length of the match, or -1 if unknown
58
		return this.isReadAccess;
58
 * @param isReadAccess whether the match represents a read access
59
	}
59
 * @param isWriteAccess whether the match represents a write access
60
 * @param insideDocComment <code>true</code> if this search match is inside a doc
61
 * comment, and <code>false</code> otherwise
62
 * @param participant the search participant that created the match
63
 * @param resource the resource of the element
64
 *  @deprecated
65
 */
66
public LocalVariableReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean isReadAccess, boolean isWriteAccess, boolean insideDocComment, SearchParticipant participant, IResource resource) {
67
	this(enclosingElement, null, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource);
68
}
60
69
61
	/**
70
/**
62
	 * Returns whether the local variable reference is a write access to the variable.
71
 * Returns whether the local variable reference is a read access to the variable.
63
	 * Note that a local variable reference can be read and written at once in case of compound assignments (e.g. i += 0;)
72
 * Note that a local variable reference can be read and written at once in case of compound assignments (e.g. i += 0;)
64
	 * 
73
 * 
65
	 * @return whether the local variable reference is a write access to the variable.
74
 * @return whether the local variable reference is a read access to the variable.
66
	 */
75
 */
67
	public final boolean isWriteAccess() {
76
public final boolean isReadAccess() {
68
		return this.isWriteAccess;
77
	return this.isReadAccess;
69
	}
78
}
79
80
/**
81
 * Returns whether the local variable reference is a write access to the variable.
82
 * Note that a local variable reference can be read and written at once in case of compound assignments (e.g. i += 0;)
83
 * 
84
 * @return whether the local variable reference is a write access to the variable.
85
 */
86
public final boolean isWriteAccess() {
87
	return this.isWriteAccess;
88
}
70
}
89
}
(-)search/org/eclipse/jdt/core/search/TypeReferenceMatch.java (-63 / +109 lines)
Lines 11-17 Link Here
11
package org.eclipse.jdt.core.search;
11
package org.eclipse.jdt.core.search;
12
12
13
import org.eclipse.core.resources.IResource;
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.jdt.core.IField;
14
import org.eclipse.jdt.core.IJavaElement;
15
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.ILocalVariable;
15
17
16
/**
18
/**
17
 * A Java search match that represents a type reference.
19
 * A Java search match that represents a type reference.
Lines 22-96 Link Here
22
 * 
24
 * 
23
 * @since 3.0
25
 * @since 3.0
24
 */
26
 */
25
public class TypeReferenceMatch extends SearchMatch {
27
public class TypeReferenceMatch extends ReferenceMatch {
26
28
27
	private IJavaElement localElement;
29
	IJavaElement[] otherElements;
28
	private IJavaElement[] otherElements;
29
30
30
	/**
31
/**
31
	 * Creates a new type reference match.
32
 * Creates a new type reference match.
32
	 * 
33
 * 
33
	 * @param enclosingElement the inner-most enclosing member that references this type
34
 * @param enclosingElement the inner-most enclosing member that references this type
34
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
35
 * @param localElement the nearest local element enclosing this type reference
35
	 * @param offset the offset the match starts at, or -1 if unknown
36
 * @param otherElements possible other elements concerned by this type reference
36
	 * @param length the length of the match, or -1 if unknown
37
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
37
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
38
 * @param offset the offset the match starts at, or -1 if unknown
38
	 * comment, and <code>false</code> otherwise
39
 * @param length the length of the match, or -1 if unknown
39
	 * @param participant the search participant that created the match
40
 * @param insideDocComment <code>true</code> if this search match is inside a doc
40
	 * @param resource the resource of the element
41
 * 				comment, and <code>false</code> otherwise
41
	 */
42
 * @param participant the search participant that created the match
42
	public TypeReferenceMatch(IJavaElement enclosingElement, int accuracy,	int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
43
 * @param resource the resource of the element
43
		super(enclosingElement, accuracy, offset, length, participant, resource);
44
 */
44
		setInsideDocComment(insideDocComment);
45
public TypeReferenceMatch(IJavaElement enclosingElement, IJavaElement localElement, IJavaElement[] otherElements, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
45
	}
46
	super(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource);
47
	this.otherElements = otherElements;
48
}
46
49
47
	/**
50
/**
48
	 * Returns the local element of this search match.
51
 * Creates a new type reference match.
49
	 * This may be a local variable which declaring type is the referenced one
52
 * 
50
	 * or a type parameter which extends it.
53
 * @param enclosingElement the inner-most enclosing member that references this type
51
	 * 
54
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
52
	 * @return the element of the search match, or <code>null</code> if none or there's
55
 * @param offset the offset the match starts at, or -1 if unknown
53
	 * 	no more specific local element than the element itself ({@link SearchMatch#getElement()}).
56
 * @param length the length of the match, or -1 if unknown
54
	 * @since 3.2
57
 * @param insideDocComment <code>true</code> if this search match is inside a doc
55
	 */
58
 * 				comment, and <code>false</code> otherwise
56
	public final IJavaElement getLocalElement() {
59
 * @param participant the search participant that created the match
57
		return this.localElement;
60
 * @param resource the resource of the element
58
	}
61
 *	@deprecated
62
 */
63
public TypeReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
64
	super(enclosingElement, null, accuracy, offset, length, insideDocComment, participant, resource);
65
}
59
66
60
	/**
67
/**
61
	 * Returns other enclosing elements of this search match.
68
 * Returns the other enclosing elements of this search match.
62
	 *
69
 *<p>
63
	 * If {@link #getLocalElement()} is not <code>null</code>, these may be other
70
 * The search match will have other elements (e.g. this method will not return 
64
	 * local elements such as additional local variables of a multiple local
71
 * <code>null</code>), if and only if it corresponds to a multiple fields declaration
65
	 * variables declaration. Otherwise, these may be other elements such as
72
 * or a multiple local variables declaration.
66
	 * additional fields of a multiple fields declaration.
73
 * </p><p>
67
	 * 
74
 * If the search match has a local element (e.g. if {@link #getLocalElement()}
68
	 * @return the other elements of the search match, or <code>null</code> if none
75
 * does not return <code>null</code>), then all the other elements will be also
69
	 * @since 3.2
76
 * local variables. Otherwise, all the other elements will be fields (see {@link IField}).
70
	 */
77
 * </p><p>
71
	public final IJavaElement[] getOtherElements() {
78
 * For example,
79
 * <ul>
80
 * 	<li>searching the reference to the type <code>Test</code> in the
81
 * 		following snippet:
82
 *         <pre>
83
 *         public class Test {
84
 *             Test test1, test2, test3;
85
 *             void method() {}
86
 *         }
87
 *         </pre>
88
 * 		will return one match which will have its other elements set to 
89
 * 		an array with two fields: {@link IField test2} and {@link IField test3}.
90
 * 	</li>
91
 * 	<li>searching the reference to the type <code>Test</code> in the
92
 * 		following snippet:
93
 * 		<pre>
94
 *         public class Test {
95
 *             String str;
96
 *             void method() {
97
 *                 Test local1, local2, local3;
98
 *             }
99
 *         }
100
 *         </pre>
101
 * 		will return one match which will have its other elements set to 
102
 * 		an array with two local variables: {@link ILocalVariable local2} and
103
 * 		{@link ILocalVariable local3}.
104
 * 	</li>
105
 * </ul>
106
 * 
107
 * @return the other elements of the search match, or <code>null</code> if none
108
 */
109
public final IJavaElement[] getOtherElements() {
110
	if (this.localElement == null || this.localElement.getElementType() != IJavaElement.ANNOTATION) {
72
		return this.otherElements;
111
		return this.otherElements;
73
	}
112
	}
113
	return null;
114
}
74
115
75
	/**
116
/**
76
	 * Sets the local element of this search match.
117
 * Sets the local element of this search match.
77
	 * 
118
 * 
78
	 * @param localElement A more specific local element that corresponds to the match,
119
 * @param localElement A more specific local element that corresponds to the match,
79
	 * 	or <code>null</code> if none
120
 * 	or <code>null</code> if none
80
	 * @since 3.2
121
 * @since 3.2
81
	 */
122
 * @deprecated Use the constructor instead to initialize the field
82
	public final void setLocalElement(IJavaElement localElement) {
123
 * 	{@link ReferenceMatch#localElement}.
83
		this.localElement = localElement;
124
 */
84
	}
125
public final void setLocalElement(IJavaElement localElement) {
126
	this.localElement = localElement;
127
}
85
128
86
	/**
129
/**
87
	 * Sets the other elements of this search match.
130
 * Sets the other elements of this search match.
88
	 * 
131
 * 
89
	 * @param otherElements the other elements of the match,
132
 * @see #getOtherElements()
90
	 * 	or <code>null</code> if none
133
 * 
91
	 * @since 3.2
134
 * @param otherElements the other elements of the match,
92
	 */
135
 * 	or <code>null</code> if none
93
	public final void setOtherElements(IJavaElement[] otherElements) {
136
 * @since 3.2
94
		this.otherElements = otherElements;
137
 * @deprecated Use the constructor instead to initialize the field {@link #otherElements}.
95
	}
138
 */
139
public final void setOtherElements(IJavaElement[] otherElements) {
140
	this.otherElements = otherElements;
141
}
96
}
142
}
(-)search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java (-4 / +10 lines)
Lines 307-313 Link Here
307
/*
307
/*
308
 * Look for annotations references
308
 * Look for annotations references
309
 */
309
 */
310
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 (((InternalSearchPattern)pattern).kind) {
313
		case TYPE_REF_PATTERN:
313
		case TYPE_REF_PATTERN:
Lines 329-335 Link Here
329
	BinaryTypeBinding binaryTypeBinding = null;
329
	BinaryTypeBinding binaryTypeBinding = null;
330
	if (checkAnnotations(typeReferencePattern, annotations, binaryType.getTagBits())) {
330
	if (checkAnnotations(typeReferencePattern, annotations, binaryType.getTagBits())) {
331
		classFileBinaryType = new ResolvedBinaryType((JavaElement) classFileBinaryType.getParent(), classFileBinaryType.getElementName(), classFileBinaryType.getKey());
331
		classFileBinaryType = new ResolvedBinaryType((JavaElement) classFileBinaryType.getParent(), classFileBinaryType.getElementName(), classFileBinaryType.getKey());
332
		SearchMatch match = new TypeReferenceMatch(classFileBinaryType, SearchMatch.A_ACCURATE, -1, 0, false, locator.getParticipant(), locator.currentPossibleMatch.resource);
332
		// TODO 3.4 M7 (frederic) - bug 209996: see how create the annotation handle from the binary and put it in the local element
333
		IJavaElement localElement = null;
334
		SearchMatch match = new TypeReferenceMatch(classFileBinaryType, localElement, null, SearchMatch.A_ACCURATE, -1, 0, false, locator.getParticipant(), locator.currentPossibleMatch.resource);
333
		locator.report(match);
335
		locator.report(match);
334
	}
336
	}
335
337
Lines 343-349 Link Here
343
					IMethod methodHandle = classFileBinaryType.getMethod(
345
					IMethod methodHandle = classFileBinaryType.getMethod(
344
						new String(method.isConstructor() ? binaryTypeBinding.compoundName[binaryTypeBinding.compoundName.length-1] : method.getSelector()),
346
						new String(method.isConstructor() ? binaryTypeBinding.compoundName[binaryTypeBinding.compoundName.length-1] : method.getSelector()),
345
						CharOperation.toStrings(Signature.getParameterTypes(convertClassFileFormat(method.getMethodDescriptor()))));
347
						CharOperation.toStrings(Signature.getParameterTypes(convertClassFileFormat(method.getMethodDescriptor()))));
346
					SearchMatch match = new TypeReferenceMatch(methodHandle, SearchMatch.A_ACCURATE, -1, 0, false, locator.getParticipant(), locator.currentPossibleMatch.resource);
348
					// TODO 3.4 M7 (frederic) - bug 209996: see how create the annotation handle from the binary and put it in the local element
349
					IJavaElement localElement = null;
350
					SearchMatch match = new TypeReferenceMatch(methodHandle, localElement, null, SearchMatch.A_ACCURATE, -1, 0, false, locator.getParticipant(), locator.currentPossibleMatch.resource);
347
					locator.report(match);
351
					locator.report(match);
348
			}
352
			}
349
		}
353
		}
Lines 356-362 Link Here
356
			FieldInfo field = fields[i];
360
			FieldInfo field = fields[i];
357
			if (checkAnnotations(typeReferencePattern, field.getAnnotations(), field.getTagBits())) {
361
			if (checkAnnotations(typeReferencePattern, field.getAnnotations(), field.getTagBits())) {
358
					IField fieldHandle = classFileBinaryType.getField(new String(field.getName()));
362
					IField fieldHandle = classFileBinaryType.getField(new String(field.getName()));
359
					SearchMatch match = new TypeReferenceMatch(fieldHandle, SearchMatch.A_ACCURATE, -1, 0, false, locator.getParticipant(), locator.currentPossibleMatch.resource);
363
					// TODO 3.4 M7 (frederic) - bug 209996: see how create the annotation handle from the binary and put it in the local element
364
					IJavaElement localElement = null;
365
					SearchMatch match = new TypeReferenceMatch(fieldHandle, localElement, null, SearchMatch.A_ACCURATE, -1, 0, false, locator.getParticipant(), locator.currentPossibleMatch.resource);
360
					locator.report(match);
366
					locator.report(match);
361
			}
367
			}
362
		}
368
		}
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-2 / +2 lines)
Lines 316-322 Link Here
316
/**
316
/**
317
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchReportReference(org.eclipse.jdt.internal.compiler.ast.ASTNode, org.eclipse.jdt.core.IJavaElement, Binding, int, org.eclipse.jdt.internal.core.search.matching.MatchLocator)
317
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchReportReference(org.eclipse.jdt.internal.compiler.ast.ASTNode, org.eclipse.jdt.core.IJavaElement, Binding, int, org.eclipse.jdt.internal.core.search.matching.MatchLocator)
318
 */
318
 */
319
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
319
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
320
	MethodBinding methodBinding = (reference instanceof MessageSend) ? ((MessageSend)reference).binding: ((elementBinding instanceof MethodBinding) ? (MethodBinding) elementBinding : null);
320
	MethodBinding methodBinding = (reference instanceof MessageSend) ? ((MessageSend)reference).binding: ((elementBinding instanceof MethodBinding) ? (MethodBinding) elementBinding : null);
321
	if (this.isDeclarationOfReferencedMethodsPattern) {
321
	if (this.isDeclarationOfReferencedMethodsPattern) {
322
		if (methodBinding == null) return;
322
		if (methodBinding == null) return;
Lines 331-337 Link Here
331
			reportDeclaration(methodBinding, locator, declPattern.knownMethods);
331
			reportDeclaration(methodBinding, locator, declPattern.knownMethods);
332
		}
332
		}
333
	} else {
333
	} else {
334
		match = locator.newMethodReferenceMatch(element, elementBinding, accuracy, -1, -1, false /*not constructor*/, false/*not synthetic*/, reference);
334
		match = locator.newMethodReferenceMatch(element, localElement, elementBinding, accuracy, -1, -1, false /*not constructor*/, false/*not synthetic*/, reference);
335
		if (this.pattern.findReferences && reference instanceof MessageSend) {
335
		if (this.pattern.findReferences && reference instanceof MessageSend) {
336
			IJavaElement focus = ((InternalSearchPattern) this.pattern).focus;
336
			IJavaElement focus = ((InternalSearchPattern) this.pattern).focus;
337
			// verify closest match if pattern was bound
337
			// verify closest match if pattern was bound
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java (-68 / +2 lines)
Lines 278-284 Link Here
278
			int offset = arrayRef.sourceStart;
278
			int offset = arrayRef.sourceStart;
279
			int length = arrayRef.sourceEnd-offset+1;
279
			int length = arrayRef.sourceEnd-offset+1;
280
			if (this.match == null) {
280
			if (this.match == null) {
281
				this.match = locator.newTypeReferenceMatch(element, elementBinding, accuracy, offset, length, arrayRef);
281
				this.match = locator.newTypeReferenceMatch(element, null, null, elementBinding, accuracy, offset, length, arrayRef);
282
			} else {
282
			} else {
283
				this.match.setOffset(offset);
283
				this.match.setOffset(offset);
284
				this.match.setLength(length);
284
				this.match.setLength(length);
Lines 295-306 Link Here
295
	locator.reportAccurateTypeReference(match, arrayRef, this.pattern.simpleName);
295
	locator.reportAccurateTypeReference(match, arrayRef, this.pattern.simpleName);
296
}
296
}
297
/**
297
/**
298
 * Reports the match of the given reference.
299
 */
300
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
301
	matchReportReference(reference, element, null, null, elementBinding, accuracy, locator);
302
}
303
/**
304
 * Reports the match of the given reference. Also provide a local and other elements to eventually report in match.
298
 * Reports the match of the given reference. Also provide a local and other elements to eventually report in match.
305
 */
299
 */
306
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
300
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
Lines 311-320 Link Here
311
	}
305
	}
312
	
306
	
313
	// Create search match
307
	// Create search match
314
	TypeReferenceMatch refMatch = locator.newTypeReferenceMatch(element, elementBinding, accuracy, reference);
308
	this.match = locator.newTypeReferenceMatch(element, localElement, otherElements, elementBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference);
315
	refMatch.setLocalElement(localElement);
316
	refMatch.setOtherElements(otherElements);
317
	this.match = refMatch;
318
309
319
	// Report match depending on reference type
310
	// Report match depending on reference type
320
	if (reference instanceof QualifiedNameReference)
311
	if (reference instanceof QualifiedNameReference)
Lines 332-394 Link Here
332
		locator.report(match);
323
		locator.report(match);
333
	}
324
	}
334
}
325
}
335
/**
336
 * Reports the match of the given reference. Also provide a scope to look for possible local and other elements.
337
 */
338
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, Scope scope, int accuracy, MatchLocator locator) throws CoreException {
339
	if (scope == null || (scope.kind != Scope.BLOCK_SCOPE && scope.kind != Scope.METHOD_SCOPE)) {
340
		matchReportReference(reference, element, elementBinding, accuracy, locator);
341
		return;
342
	}
343
	
344
	// Look if some block scope local variable declarations include reference start position
345
	BlockScope blockScope = (BlockScope) scope;
346
	LocalDeclaration[] localDeclarations = blockScope.findLocalVariableDeclarations(reference.sourceStart);
347
	IJavaElement localElement = null;
348
	IJavaElement[] otherElements = null;
349
350
	// Some local variable declaration are matching
351
	if (localDeclarations != null) {
352
		int length = localDeclarations.length;
353
354
		// Set local element to first matching local declaration
355
		int idx = 0;
356
		for (; idx<length; idx++) {
357
			if (localDeclarations[idx] == null) break;
358
			if (reference.sourceStart == localDeclarations[idx].declarationSourceStart) {
359
				localElement = locator.createHandle(localDeclarations[idx], element);
360
				break;
361
			}
362
			if (idx>0 && localDeclarations[idx].sourceStart > reference.sourceStart) {
363
				localElement = locator.createHandle(localDeclarations[idx-1], element);
364
				break;
365
			}
366
		}
367
		if (localElement == null && idx > 0) {
368
			if (reference.sourceEnd < localDeclarations[idx-1].declarationEnd) {
369
				localElement = locator.createHandle(localDeclarations[idx-1], element);
370
			}
371
		}
372
		
373
		// Store other local variable declarations in other elements
374
		int size = 0;
375
		for (int j=1; j<length; j++) {
376
			if (localDeclarations[j] == null) break;
377
			if (reference.sourceStart == localDeclarations[j].declarationSourceStart) {
378
				if (otherElements == null) {
379
					otherElements = new IJavaElement[length-j];
380
				}
381
				otherElements[size++] = locator.createHandle(localDeclarations[j], element);
382
			}
383
		}
384
		if (size > 0 && size != (length-1)) {
385
			System.arraycopy(otherElements, 0, otherElements = new IJavaElement[size], 0, size);
386
		}
387
	}
388
	
389
	// Report match with local and other elements if any
390
	matchReportReference(reference, element, localElement, otherElements, elementBinding, accuracy, locator);
391
}
392
protected void matchReportReference(QualifiedNameReference qNameRef, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
326
protected void matchReportReference(QualifiedNameReference qNameRef, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
393
	Binding binding = qNameRef.binding;
327
	Binding binding = qNameRef.binding;
394
	TypeBinding typeBinding = null;
328
	TypeBinding typeBinding = null;
(-)search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java (-5 / +5 lines)
Lines 178-184 Link Here
178
	}
178
	}
179
	return true;
179
	return true;
180
}
180
}
181
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
181
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
182
182
183
	MethodBinding constructorBinding = null;
183
	MethodBinding constructorBinding = null;
184
	boolean isSynthetic = false;
184
	boolean isSynthetic = false;
Lines 190-201 Link Here
190
		AllocationExpression alloc = (AllocationExpression) reference;
190
		AllocationExpression alloc = (AllocationExpression) reference;
191
		constructorBinding = alloc.binding;
191
		constructorBinding = alloc.binding;
192
	} else if (reference instanceof TypeDeclaration || reference instanceof FieldDeclaration) {
192
	} else if (reference instanceof TypeDeclaration || reference instanceof FieldDeclaration) {
193
		super.matchReportReference(reference, element, elementBinding, accuracy, locator);
193
		super.matchReportReference(reference, element, localElement, otherElements, elementBinding, accuracy, locator);
194
		if (match != null) return;
194
		if (match != null) return;
195
	}
195
	}
196
196
197
	// Create search match
197
	// Create search match
198
	match = locator.newMethodReferenceMatch(element, elementBinding, accuracy, -1, -1, true, isSynthetic, reference);
198
	match = locator.newMethodReferenceMatch(element, localElement, elementBinding, accuracy, -1, -1, true, isSynthetic, reference);
199
199
200
	// Look to refine accuracy
200
	// Look to refine accuracy
201
	if (constructorBinding instanceof ParameterizedGenericMethodBinding) { // parameterized generic method
201
	if (constructorBinding instanceof ParameterizedGenericMethodBinding) { // parameterized generic method
Lines 273-286 Link Here
273
				for (int i = 0, max = methods.length; i < max; i++) {
273
				for (int i = 0, max = methods.length; i < max; i++) {
274
					AbstractMethodDeclaration method = methods[i];
274
					AbstractMethodDeclaration method = methods[i];
275
					boolean synthetic = method.isDefaultConstructor() && method.sourceStart < type.bodyStart;
275
					boolean synthetic = method.isDefaultConstructor() && method.sourceStart < type.bodyStart;
276
					match = locator.newMethodReferenceMatch(element, binding, accuracy, offset, length, method.isConstructor(), synthetic, method);
276
					match = locator.newMethodReferenceMatch(element, null, binding, accuracy, offset, length, method.isConstructor(), synthetic, method);
277
				}
277
				}
278
			}
278
			}
279
		} else if (reference instanceof ConstructorDeclaration) {
279
		} else if (reference instanceof ConstructorDeclaration) {
280
			ConstructorDeclaration constructor = (ConstructorDeclaration) reference;
280
			ConstructorDeclaration constructor = (ConstructorDeclaration) reference;
281
			ExplicitConstructorCall call = constructor.constructorCall;
281
			ExplicitConstructorCall call = constructor.constructorCall;
282
			boolean synthetic = call != null && call.isImplicitSuper();
282
			boolean synthetic = call != null && call.isImplicitSuper();
283
			match = locator.newMethodReferenceMatch(element, binding, accuracy, offset, length, constructor.isConstructor(), synthetic, constructor);
283
			match = locator.newMethodReferenceMatch(element, null, binding, accuracy, offset, length, constructor.isConstructor(), synthetic, constructor);
284
		}
284
		}
285
	}
285
	}
286
	if (match != null) {
286
	if (match != null) {
(-)search/org/eclipse/jdt/internal/core/search/matching/PackageReferenceLocator.java (-4 / +4 lines)
Lines 164-170 Link Here
164
}
164
}
165
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaElement element, int accuracy, MatchLocator locator) throws CoreException {
165
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaElement element, int accuracy, MatchLocator locator) throws CoreException {
166
	if (binding == null) {
166
	if (binding == null) {
167
		this.matchReportReference(importRef, element, null/*no binding*/, accuracy, locator);
167
		matchReportReference(importRef, element, null, null, null/*no binding*/, accuracy, locator);
168
	} else {
168
	} else {
169
		if (locator.encloses(element)) {
169
		if (locator.encloses(element)) {
170
			long[] positions = importRef.sourcePositions;
170
			long[] positions = importRef.sourcePositions;
Lines 180-191 Link Here
180
				last = ((PackageBinding) binding).compoundName.length;
180
				last = ((PackageBinding) binding).compoundName.length;
181
			int start = (int) (positions[0] >>> 32);
181
			int start = (int) (positions[0] >>> 32);
182
			int end = (int) positions[last - 1];
182
			int end = (int) positions[last - 1];
183
			match = locator.newPackageReferenceMatch(element, accuracy, start, end-start+1, importRef);
183
			match = locator.newPackageReferenceMatch(element, null, accuracy, start, end-start+1, importRef);
184
			locator.report(match);
184
			locator.report(match);
185
		}
185
		}
186
	}
186
	}
187
}
187
}
188
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
188
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
189
	long[] positions = null;
189
	long[] positions = null;
190
	int last = -1;
190
	int last = -1;
191
	if (reference instanceof ImportReference) {
191
	if (reference instanceof ImportReference) {
Lines 259-265 Link Here
259
	if (last > positions.length) last = positions.length;
259
	if (last > positions.length) last = positions.length;
260
	int sourceStart = (int) (positions[0] >>> 32);
260
	int sourceStart = (int) (positions[0] >>> 32);
261
	int sourceEnd = ((int) positions[last - 1]);
261
	int sourceEnd = ((int) positions[last - 1]);
262
	match = locator.newPackageReferenceMatch(element, accuracy, sourceStart, sourceEnd-sourceStart+1, reference);
262
	match = locator.newPackageReferenceMatch(element, localElement, accuracy, sourceStart, sourceEnd-sourceStart+1, reference);
263
	locator.report(match);
263
	locator.report(match);
264
}
264
}
265
protected int referenceType() {
265
protected int referenceType() {
(-)search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java (-18 / +12 lines)
Lines 380-428 Link Here
380
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaElement element, int accuracy, MatchLocator locator) throws CoreException {
380
protected void matchReportImportRef(ImportReference importRef, Binding binding, IJavaElement element, int accuracy, MatchLocator locator) throws CoreException {
381
	if (locator.encloses(element)) {
381
	if (locator.encloses(element)) {
382
		// default is to report a match as a regular ref.
382
		// default is to report a match as a regular ref.
383
		this.matchReportReference(importRef, element, null/*no binding*/, accuracy, locator);
383
		this.matchReportReference(importRef, element, null, null, null/*no binding*/, accuracy, locator);
384
	}
384
	}
385
}
385
}
386
/**
386
/**
387
 * Reports the match of the given reference.
387
 * Reports the match of the given reference.
388
 */
388
 */
389
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
389
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
390
	matchReportReference(reference, element, null, null, elementBinding, accuracy, locator);
391
}
392
/**
393
 * Reports the match of the given reference. Also provide a local element to eventually report in match.
394
 */
395
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
390
	match = null;
396
	match = null;
391
	int referenceType = referenceType();
397
	int referenceType = referenceType();
392
	int offset = reference.sourceStart;
398
	int offset = reference.sourceStart;
393
	switch (referenceType) {
399
	switch (referenceType) {
394
		case IJavaElement.PACKAGE_FRAGMENT:
400
		case IJavaElement.PACKAGE_FRAGMENT:
395
			match = locator.newPackageReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
401
			match = locator.newPackageReferenceMatch(element, localElement, accuracy, offset, reference.sourceEnd-offset+1, reference);
396
			break;
402
			break;
397
		case IJavaElement.TYPE:
403
		case IJavaElement.TYPE:
398
			match = locator.newTypeReferenceMatch(element, elementBinding, accuracy, offset, reference.sourceEnd-offset+1, reference);
404
			match = locator.newTypeReferenceMatch(element, localElement, otherElements, elementBinding, accuracy, offset, reference.sourceEnd-offset+1, reference);
399
			break;
405
			break;
400
		case IJavaElement.FIELD:
406
		case IJavaElement.FIELD:
401
			match = locator.newFieldReferenceMatch(element, elementBinding, accuracy, offset, reference.sourceEnd-offset+1, reference);
407
			match = locator.newFieldReferenceMatch(element, localElement, elementBinding, accuracy, offset, reference.sourceEnd-offset+1, reference);
402
			break;
408
			break;
403
		case IJavaElement.LOCAL_VARIABLE:
409
		case IJavaElement.LOCAL_VARIABLE:
404
			match = locator.newLocalVariableReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
410
			match = locator.newLocalVariableReferenceMatch(element, localElement, accuracy, offset, reference.sourceEnd-offset+1, reference);
405
			break;
411
			break;
406
		case IJavaElement.TYPE_PARAMETER:
412
		case IJavaElement.TYPE_PARAMETER:
407
			match = locator.newTypeParameterReferenceMatch(element, accuracy, offset, reference.sourceEnd-offset+1, reference);
413
			match = locator.newTypeParameterReferenceMatch(element, localElement, accuracy, offset, reference.sourceEnd-offset+1, reference);
408
			break;
414
			break;
409
	}
415
	}
410
	if (match != null) {
416
	if (match != null) {
411
		locator.report(match);
417
		locator.report(match);
412
	}
418
	}
413
}
419
}
414
/**
415
 * Reports the match of the given reference. Also provide a local element to eventually report in match.
416
 */
417
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
418
	matchReportReference(reference, element, elementBinding, accuracy, locator);
419
}
420
/**
421
 * Reports the match of the given reference. Also provide a scope to look for potential other elements.
422
 */
423
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, Scope scope, int accuracy, MatchLocator locator) throws CoreException {
424
	matchReportReference(reference, element, elementBinding, accuracy, locator);
425
}
426
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, int length, MatchLocator locator) {
420
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, int length, MatchLocator locator) {
427
    return locator.newDeclarationMatch(element, elementBinding, accuracy, reference.sourceStart, length);
421
    return locator.newDeclarationMatch(element, elementBinding, accuracy, reference.sourceStart, length);
428
}
422
}
(-)search/org/eclipse/jdt/internal/core/search/matching/FieldLocator.java (-10 / +10 lines)
Lines 136-142 Link Here
136
	}
136
	}
137
	return super.matchReference(node, nodeSet, writeOnlyAccess);
137
	return super.matchReference(node, nodeSet, writeOnlyAccess);
138
}
138
}
139
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
139
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
140
	if (this.isDeclarationOfAccessedFieldsPattern) {
140
	if (this.isDeclarationOfAccessedFieldsPattern) {
141
		// need exact match to be able to open on type ref
141
		// need exact match to be able to open on type ref
142
		if (accuracy != SearchMatch.A_ACCURATE) return;
142
		if (accuracy != SearchMatch.A_ACCURATE) return;
Lines 166-183 Link Here
166
		int lastIndex = importRef.tokens.length - 1;
166
		int lastIndex = importRef.tokens.length - 1;
167
		int start = (int) ((positions[lastIndex]) >>> 32);
167
		int start = (int) ((positions[lastIndex]) >>> 32);
168
		int end = (int) positions[lastIndex];
168
		int end = (int) positions[lastIndex];
169
		match = locator.newFieldReferenceMatch(element, elementBinding, accuracy, start, end-start+1, importRef);
169
		match = locator.newFieldReferenceMatch(element, localElement, elementBinding, accuracy, start, end-start+1, importRef);
170
		locator.report(match);
170
		locator.report(match);
171
	} else if (reference instanceof FieldReference) {
171
	} else if (reference instanceof FieldReference) {
172
		FieldReference fieldReference = (FieldReference) reference;
172
		FieldReference fieldReference = (FieldReference) reference;
173
		long position = fieldReference.nameSourcePosition;
173
		long position = fieldReference.nameSourcePosition;
174
		int start = (int) (position >>> 32);
174
		int start = (int) (position >>> 32);
175
		int end = (int) position;
175
		int end = (int) position;
176
		match = locator.newFieldReferenceMatch(element, elementBinding, accuracy, start, end-start+1, fieldReference);
176
		match = locator.newFieldReferenceMatch(element, localElement, elementBinding, accuracy, start, end-start+1, fieldReference);
177
		locator.report(match);
177
		locator.report(match);
178
	} else if (reference instanceof SingleNameReference) {
178
	} else if (reference instanceof SingleNameReference) {
179
		int offset = reference.sourceStart;
179
		int offset = reference.sourceStart;
180
		match = locator.newFieldReferenceMatch(element, elementBinding, accuracy, offset, reference.sourceEnd-offset+1, reference);
180
		match = locator.newFieldReferenceMatch(element, localElement, elementBinding, accuracy, offset, reference.sourceEnd-offset+1, reference);
181
		locator.report(match);
181
		locator.report(match);
182
	} else if (reference instanceof QualifiedNameReference) {
182
	} else if (reference instanceof QualifiedNameReference) {
183
		QualifiedNameReference qNameRef = (QualifiedNameReference) reference;
183
		QualifiedNameReference qNameRef = (QualifiedNameReference) reference;
Lines 190-203 Link Here
190
		if (matchesName(this.pattern.name, qNameRef.tokens[indexOfFirstFieldBinding]) && !(nameBinding instanceof LocalVariableBinding)) {
190
		if (matchesName(this.pattern.name, qNameRef.tokens[indexOfFirstFieldBinding]) && !(nameBinding instanceof LocalVariableBinding)) {
191
			FieldBinding fieldBinding = nameBinding instanceof FieldBinding ? (FieldBinding) nameBinding : null;
191
			FieldBinding fieldBinding = nameBinding instanceof FieldBinding ? (FieldBinding) nameBinding : null;
192
			if (fieldBinding == null) {
192
			if (fieldBinding == null) {
193
				matches[indexOfFirstFieldBinding] = locator.newFieldReferenceMatch(element, elementBinding, accuracy, -1, -1, reference);
193
				matches[indexOfFirstFieldBinding] = locator.newFieldReferenceMatch(element, localElement, elementBinding, accuracy, -1, -1, reference);
194
			} else {
194
			} else {
195
				switch (matchField(fieldBinding, false)) {
195
				switch (matchField(fieldBinding, false)) {
196
					case ACCURATE_MATCH:
196
					case ACCURATE_MATCH:
197
						matches[indexOfFirstFieldBinding] = locator.newFieldReferenceMatch(element, elementBinding, SearchMatch.A_ACCURATE, -1, -1, reference);
197
						matches[indexOfFirstFieldBinding] = locator.newFieldReferenceMatch(element, localElement, elementBinding, SearchMatch.A_ACCURATE, -1, -1, reference);
198
						break;
198
						break;
199
					case INACCURATE_MATCH:
199
					case INACCURATE_MATCH:
200
						match = locator.newFieldReferenceMatch(element, elementBinding, SearchMatch.A_INACCURATE, -1, -1, reference);
200
						match = locator.newFieldReferenceMatch(element, localElement, elementBinding, SearchMatch.A_INACCURATE, -1, -1, reference);
201
						if (fieldBinding.type != null && fieldBinding.type.isParameterizedType() && this.pattern.hasTypeArguments()) {
201
						if (fieldBinding.type != null && fieldBinding.type.isParameterizedType() && this.pattern.hasTypeArguments()) {
202
							updateMatch((ParameterizedTypeBinding) fieldBinding.type, this.pattern.getTypeArguments(), locator);
202
							updateMatch((ParameterizedTypeBinding) fieldBinding.type, this.pattern.getTypeArguments(), locator);
203
						}
203
						}
Lines 213-226 Link Here
213
			if (matchesName(this.pattern.name, token)) {
213
			if (matchesName(this.pattern.name, token)) {
214
				FieldBinding otherBinding = qNameRef.otherBindings == null ? null : qNameRef.otherBindings[i-(indexOfFirstFieldBinding+1)];
214
				FieldBinding otherBinding = qNameRef.otherBindings == null ? null : qNameRef.otherBindings[i-(indexOfFirstFieldBinding+1)];
215
				if (otherBinding == null) {
215
				if (otherBinding == null) {
216
					matches[i] = locator.newFieldReferenceMatch(element, elementBinding, accuracy, -1, -1, reference);
216
					matches[i] = locator.newFieldReferenceMatch(element, localElement, elementBinding, accuracy, -1, -1, reference);
217
				} else {
217
				} else {
218
					switch (matchField(otherBinding, false)) {
218
					switch (matchField(otherBinding, false)) {
219
						case ACCURATE_MATCH:
219
						case ACCURATE_MATCH:
220
							matches[i] = locator.newFieldReferenceMatch(element, elementBinding, SearchMatch.A_ACCURATE, -1, -1, reference);
220
							matches[i] = locator.newFieldReferenceMatch(element, localElement, elementBinding, SearchMatch.A_ACCURATE, -1, -1, reference);
221
							break;
221
							break;
222
						case INACCURATE_MATCH:
222
						case INACCURATE_MATCH:
223
							match = locator.newFieldReferenceMatch(element, elementBinding, SearchMatch.A_INACCURATE, -1, -1, reference);
223
							match = locator.newFieldReferenceMatch(element, localElement, elementBinding, SearchMatch.A_INACCURATE, -1, -1, reference);
224
							if (otherBinding.type != null && otherBinding.type.isParameterizedType() && this.pattern.hasTypeArguments()) {
224
							if (otherBinding.type != null && otherBinding.type.isParameterizedType() && this.pattern.hasTypeArguments()) {
225
								updateMatch((ParameterizedTypeBinding) otherBinding.type, this.pattern.getTypeArguments(), locator);
225
								updateMatch((ParameterizedTypeBinding) otherBinding.type, this.pattern.getTypeArguments(), locator);
226
							}
226
							}
(-)search/org/eclipse/jdt/internal/core/search/matching/LocalVariableLocator.java (-2 / +2 lines)
Lines 41-47 Link Here
41
private LocalVariable getLocalVariable() {
41
private LocalVariable getLocalVariable() {
42
	return ((LocalVariablePattern) this.pattern).localVariable;
42
	return ((LocalVariablePattern) this.pattern).localVariable;
43
}
43
}
44
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
44
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
45
	int offset = -1;
45
	int offset = -1;
46
	int length = -1;
46
	int length = -1;
47
	if (reference instanceof SingleNameReference) {
47
	if (reference instanceof SingleNameReference) {
Lines 62-68 Link Here
62
		return;
62
		return;
63
	}
63
	}
64
	if (offset >= 0) {
64
	if (offset >= 0) {
65
		match = locator.newLocalVariableReferenceMatch(element, accuracy, offset, length, reference);
65
		match = locator.newLocalVariableReferenceMatch(element, localElement, accuracy, offset, length, reference);
66
		locator.report(match);
66
		locator.report(match);
67
	}
67
	}
68
}
68
}
(-)search/org/eclipse/jdt/internal/core/search/matching/AndLocator.java (-2 / +2 lines)
Lines 214-220 Link Here
214
	}
214
	}
215
	weakestPattern.matchReportImportRef(importRef, binding, element, accuracy, locator);
215
	weakestPattern.matchReportImportRef(importRef, binding, element, accuracy, locator);
216
}
216
}
217
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
217
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
218
	PatternLocator weakestPattern = null;
218
	PatternLocator weakestPattern = null;
219
	int level = IMPOSSIBLE_MATCH;
219
	int level = IMPOSSIBLE_MATCH;
220
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
220
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
Lines 226-232 Link Here
226
			level = newLevel;
226
			level = newLevel;
227
		}
227
		}
228
	}
228
	}
229
	weakestPattern.matchReportReference(reference, element, elementBinding, accuracy, locator);
229
	weakestPattern.matchReportReference(reference, element, localElement, otherElements, elementBinding, accuracy, locator);
230
}
230
}
231
public int resolveLevel(ASTNode node) {
231
public int resolveLevel(ASTNode node) {
232
	int level = ACCURATE_MATCH;
232
	int level = ACCURATE_MATCH;
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-78 / +124 lines)
Lines 21-26 Link Here
21
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.*;
22
import org.eclipse.core.runtime.*;
23
import org.eclipse.jdt.core.Flags;
23
import org.eclipse.jdt.core.Flags;
24
import org.eclipse.jdt.core.IAnnotatable;
25
import org.eclipse.jdt.core.IAnnotation;
24
import org.eclipse.jdt.core.IClassFile;
26
import org.eclipse.jdt.core.IClassFile;
25
import org.eclipse.jdt.core.IJavaElement;
27
import org.eclipse.jdt.core.IJavaElement;
26
import org.eclipse.jdt.core.IJavaModelStatusConstants;
28
import org.eclipse.jdt.core.IJavaModelStatusConstants;
Lines 35-41 Link Here
35
import org.eclipse.jdt.core.Signature;
37
import org.eclipse.jdt.core.Signature;
36
import org.eclipse.jdt.core.compiler.*;
38
import org.eclipse.jdt.core.compiler.*;
37
import org.eclipse.jdt.core.search.*;
39
import org.eclipse.jdt.core.search.*;
38
import org.eclipse.jdt.internal.compiler.ASTVisitor;
39
import org.eclipse.jdt.internal.compiler.CompilationResult;
40
import org.eclipse.jdt.internal.compiler.CompilationResult;
40
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
41
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
41
import org.eclipse.jdt.internal.compiler.ast.*;
42
import org.eclipse.jdt.internal.compiler.ast.*;
Lines 48-54 Link Here
48
import org.eclipse.jdt.internal.compiler.lookup.*;
49
import org.eclipse.jdt.internal.compiler.lookup.*;
49
import org.eclipse.jdt.internal.compiler.parser.*;
50
import org.eclipse.jdt.internal.compiler.parser.*;
50
import org.eclipse.jdt.internal.compiler.problem.*;
51
import org.eclipse.jdt.internal.compiler.problem.*;
51
import org.eclipse.jdt.internal.compiler.util.HashtableOfIntValues;
52
import org.eclipse.jdt.internal.compiler.util.Messages;
52
import org.eclipse.jdt.internal.compiler.util.Messages;
53
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
53
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
54
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
54
import org.eclipse.jdt.internal.compiler.util.SimpleSet;
Lines 146-191 Link Here
146
146
147
private final boolean searchPackageDeclaration;
147
private final boolean searchPackageDeclaration;
148
148
149
/**
150
 * An ast visitor that visits local type declarations.
151
 */
152
public class LocalDeclarationVisitor extends ASTVisitor {
153
	IJavaElement enclosingElement;
154
	Binding enclosingElementBinding;
155
	MatchingNodeSet nodeSet;
156
	HashtableOfIntValues occurrencesCounts = new HashtableOfIntValues(); // key = class name (char[]), value = occurrenceCount (int)
157
	public LocalDeclarationVisitor(IJavaElement enclosingElement, Binding enclosingElementBinding, MatchingNodeSet nodeSet) {
158
		this.enclosingElement = enclosingElement;
159
		this.enclosingElementBinding = enclosingElementBinding;
160
		this.nodeSet = nodeSet;
161
	}
162
	public boolean visit(TypeDeclaration typeDeclaration, BlockScope unused) {
163
		try {
164
			char[] simpleName;
165
			if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {				
166
				simpleName = CharOperation.NO_CHAR;
167
			} else {
168
				simpleName = typeDeclaration.name;
169
			}
170
			int occurrenceCount = occurrencesCounts.get(simpleName);
171
			if (occurrenceCount == HashtableOfIntValues.NO_VALUE) {
172
				occurrenceCount = 1;
173
			} else {
174
				occurrenceCount = occurrenceCount + 1;
175
			}
176
			occurrencesCounts.put(simpleName, occurrenceCount);
177
			if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {				
178
				reportMatching(typeDeclaration, this.enclosingElement, -1, nodeSet, occurrenceCount);
179
			} else {
180
				Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeDeclaration);
181
				reportMatching(typeDeclaration, this.enclosingElement, level != null ? level.intValue() : -1, nodeSet, occurrenceCount);
182
			}
183
			return false; // don't visit members as this was done during reportMatching(...)
184
		} catch (CoreException e) {
185
			throw new WrappedCoreException(e);
186
		}
187
	}
188
}
189
public static class WorkingCopyDocument extends JavaSearchDocument {
149
public static class WorkingCopyDocument extends JavaSearchDocument {
190
	public org.eclipse.jdt.core.ICompilationUnit workingCopy;
150
	public org.eclipse.jdt.core.ICompilationUnit workingCopy;
191
	WorkingCopyDocument(org.eclipse.jdt.core.ICompilationUnit workingCopy, SearchParticipant participant) {
151
	WorkingCopyDocument(org.eclipse.jdt.core.ICompilationUnit workingCopy, SearchParticipant participant) {
Lines 600-606 Link Here
600
	return ((IType) parent).getInitializer(occurrenceCount);
560
	return ((IType) parent).getInitializer(occurrenceCount);
601
}
561
}
602
/**
562
/**
603
 * Create an handle for a local variable declartion (may be a local variable or type parameter).
563
 * Create an handle for a local variable declaration (may be a local variable or type parameter).
604
 */
564
 */
605
protected IJavaElement createHandle(AbstractVariableDeclaration variableDeclaration, IJavaElement parent) {
565
protected IJavaElement createHandle(AbstractVariableDeclaration variableDeclaration, IJavaElement parent) {
606
	switch (variableDeclaration.getKind()) {
566
	switch (variableDeclaration.getKind()) {
Lines 629-634 Link Here
629
	}
589
	}
630
	return null;
590
	return null;
631
}
591
}
592
/**
593
 * Create an handle for a local variable declaration (may be a local variable or type parameter).
594
 */
595
protected IJavaElement createHandle(Annotation annotation, IAnnotatable parent) {
596
	if (parent == null) return null;
597
	TypeReference typeRef = annotation.type;
598
	char[][] typeName = typeRef.getTypeName();
599
	String name = new String(typeName[typeName.length-1]);
600
	try {
601
		IAnnotation[] annotations = parent.getAnnotations();
602
		int length = annotations == null ? 0 : annotations.length;
603
		for (int i=0; i<length; i++) {
604
			if (annotations[i].getElementName().equals(name)) {
605
				return annotations[i];
606
			}
607
		}
608
	}
609
	catch (JavaModelException jme) {
610
		// skip
611
	}
612
	return null;
613
}
632
/*
614
/*
633
 * Creates hierarchy resolver if needed. 
615
 * Creates hierarchy resolver if needed. 
634
 * Returns whether focus is visible.
616
 * Returns whether focus is visible.
Lines 1389-1394 Link Here
1389
1371
1390
public SearchMatch newFieldReferenceMatch(
1372
public SearchMatch newFieldReferenceMatch(
1391
		IJavaElement enclosingElement,
1373
		IJavaElement enclosingElement,
1374
		IJavaElement localElement,
1392
		Binding enclosingBinding,
1375
		Binding enclosingBinding,
1393
		int accuracy,
1376
		int accuracy,
1394
		int offset,  
1377
		int offset,  
Lines 1413-1423 Link Here
1413
	IResource resource = this.currentPossibleMatch.resource;
1396
	IResource resource = this.currentPossibleMatch.resource;
1414
	if (enclosingBinding != null)
1397
	if (enclosingBinding != null)
1415
		enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
1398
		enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
1416
	return new FieldReferenceMatch(enclosingElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource);
1399
	return new FieldReferenceMatch(enclosingElement, localElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource);
1417
}
1400
}
1418
1401
1419
public SearchMatch newLocalVariableReferenceMatch(
1402
public SearchMatch newLocalVariableReferenceMatch(
1420
		IJavaElement enclosingElement,
1403
		IJavaElement enclosingElement,
1404
		IJavaElement localElement,
1421
		int accuracy,
1405
		int accuracy,
1422
		int offset,  
1406
		int offset,  
1423
		int length,
1407
		int length,
Lines 1439-1449 Link Here
1439
	boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0;
1423
	boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0;
1440
	SearchParticipant participant = getParticipant(); 
1424
	SearchParticipant participant = getParticipant(); 
1441
	IResource resource = this.currentPossibleMatch.resource;
1425
	IResource resource = this.currentPossibleMatch.resource;
1442
	return new LocalVariableReferenceMatch(enclosingElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource);
1426
	return new LocalVariableReferenceMatch(enclosingElement, localElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource);
1443
}
1427
}
1444
1428
1445
public SearchMatch newMethodReferenceMatch(
1429
public SearchMatch newMethodReferenceMatch(
1446
		IJavaElement enclosingElement,
1430
		IJavaElement enclosingElement,
1431
		IJavaElement localElement,
1447
		Binding enclosingBinding,
1432
		Binding enclosingBinding,
1448
		int accuracy,
1433
		int accuracy,
1449
		int offset,  
1434
		int offset,  
Lines 1457-1467 Link Here
1457
	if (enclosingBinding != null)
1442
	if (enclosingBinding != null)
1458
		enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
1443
		enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
1459
	boolean isOverridden = (accuracy & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0;
1444
	boolean isOverridden = (accuracy & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0;
1460
	return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, isOverridden, insideDocComment, participant, resource);
1445
	return new MethodReferenceMatch(enclosingElement, localElement, accuracy, offset, length, isConstructor, isSynthetic, isOverridden, insideDocComment, participant, resource);
1461
}
1446
}
1462
1447
1463
public SearchMatch newPackageReferenceMatch(
1448
public SearchMatch newPackageReferenceMatch(
1464
		IJavaElement enclosingElement,
1449
		IJavaElement enclosingElement,
1450
		IJavaElement localElement,
1465
		int accuracy,
1451
		int accuracy,
1466
		int offset,  
1452
		int offset,  
1467
		int length,
1453
		int length,
Lines 1469-1479 Link Here
1469
	SearchParticipant participant = getParticipant(); 
1455
	SearchParticipant participant = getParticipant(); 
1470
	IResource resource = this.currentPossibleMatch.resource;
1456
	IResource resource = this.currentPossibleMatch.resource;
1471
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1457
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1472
	return new PackageReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource);
1458
	return new PackageReferenceMatch(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource);
1473
}
1459
}
1474
1460
1475
public SearchMatch newTypeParameterReferenceMatch(
1461
public SearchMatch newTypeParameterReferenceMatch(
1476
		IJavaElement enclosingElement,
1462
		IJavaElement enclosingElement,
1463
		IJavaElement localElement,
1477
		int accuracy,
1464
		int accuracy,
1478
		int offset,  
1465
		int offset,  
1479
		int length,
1466
		int length,
Lines 1482-1492 Link Here
1482
	boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0;
1469
	boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0;
1483
	SearchParticipant participant = getParticipant(); 
1470
	SearchParticipant participant = getParticipant(); 
1484
	IResource resource = this.currentPossibleMatch.resource;
1471
	IResource resource = this.currentPossibleMatch.resource;
1485
	return new TypeParameterReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource);
1472
	return new TypeParameterReferenceMatch(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource);
1486
}
1473
}
1487
1474
1488
public TypeReferenceMatch newTypeReferenceMatch(
1475
public TypeReferenceMatch newTypeReferenceMatch(
1489
		IJavaElement enclosingElement,
1476
		IJavaElement enclosingElement,
1477
		IJavaElement localElement,
1478
		IJavaElement[] otherElements,
1490
		Binding enclosingBinding,
1479
		Binding enclosingBinding,
1491
		int accuracy,
1480
		int accuracy,
1492
		int offset,  
1481
		int offset,  
Lines 1497-1503 Link Here
1497
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1486
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1498
	if (enclosingBinding != null)
1487
	if (enclosingBinding != null)
1499
		enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
1488
		enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
1500
	return new TypeReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource);
1489
	return new TypeReferenceMatch(enclosingElement, localElement, otherElements, accuracy, offset, length, insideDocComment, participant, resource);
1501
}
1490
}
1502
1491
1503
public TypeReferenceMatch newTypeReferenceMatch(
1492
public TypeReferenceMatch newTypeReferenceMatch(
Lines 1505-1511 Link Here
1505
		Binding enclosingBinding,
1494
		Binding enclosingBinding,
1506
		int accuracy,
1495
		int accuracy,
1507
		ASTNode reference) {
1496
		ASTNode reference) {
1508
	return newTypeReferenceMatch(enclosingElement, enclosingBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference);
1497
	return newTypeReferenceMatch(enclosingElement, null, null, enclosingBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference);
1509
}
1498
}
1510
1499
1511
/**
1500
/**
Lines 2073-2086 Link Here
2073
2062
2074
	// handle nodes for the local type first
2063
	// handle nodes for the local type first
2075
	if ((method.bits & ASTNode.HasLocalType) != 0) {
2064
	if ((method.bits & ASTNode.HasLocalType) != 0) {
2076
		if (enclosingElement == null)
2065
		if (enclosingElement == null) {
2077
			enclosingElement = createHandle(method, parent);
2066
			enclosingElement = createHandle(method, parent);
2078
		LocalDeclarationVisitor localDeclarationVisitor = new LocalDeclarationVisitor(enclosingElement, method.binding, nodeSet);
2067
		}
2068
		// Traverse method declaration to report matches both in local types declaration
2069
		// and in local variables declaration
2070
		ASTNode[] nodes = typeInHierarchy ? nodeSet.matchingNodes(method.declarationSourceStart, method.declarationSourceEnd) : null;
2071
		boolean report = (this.matchContainer & PatternLocator.METHOD_CONTAINER) != 0 && encloses(enclosingElement);
2072
		MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, report ? nodes : null, nodeSet, this);
2079
		try {
2073
		try {
2080
			method.traverse(localDeclarationVisitor, (ClassScope) null);
2074
			method.traverse(declarationVisitor, (ClassScope) null);
2081
		} catch (WrappedCoreException e) {
2075
		} catch (WrappedCoreException e) {
2082
			throw e.coreException;
2076
			throw e.coreException;
2083
		}
2077
		}
2078
		// Report all nodes and remove them
2079
		if (nodes != null) {
2080
			int length = nodes.length;
2081
			for (int i = 0; i < length; i++) {
2082
				Integer level = (Integer) nodeSet.matchingNodes.removeKey(nodes[i]);
2083
				if (report && level != null) {
2084
	    	        this.patternLocator.matchReportReference(nodes[i], enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), method.binding, level.intValue(), this);
2085
				}
2086
			}
2087
		}
2084
	}
2088
	}
2085
2089
2086
	// report the type parameters
2090
	// report the type parameters
Lines 2105-2117 Link Here
2105
		ASTNode[] nodes = nodeSet.matchingNodes(method.declarationSourceStart, method.declarationSourceEnd);
2109
		ASTNode[] nodes = nodeSet.matchingNodes(method.declarationSourceStart, method.declarationSourceEnd);
2106
		if (nodes != null) {
2110
		if (nodes != null) {
2107
			if ((this.matchContainer & PatternLocator.METHOD_CONTAINER) != 0) {
2111
			if ((this.matchContainer & PatternLocator.METHOD_CONTAINER) != 0) {
2108
				if (enclosingElement == null)
2112
				if (enclosingElement == null) {
2109
					enclosingElement = createHandle(method, parent);
2113
					enclosingElement = createHandle(method, parent);
2114
				}
2110
				if (encloses(enclosingElement)) {
2115
				if (encloses(enclosingElement)) {
2111
					for (int i = 0, l = nodes.length; i < l; i++) {
2116
					if (((InternalSearchPattern)this.pattern).mustResolve) {
2112
						ASTNode node = nodes[i];
2117
						// Visit only if the pattern must resolve
2113
						Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2118
						MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, nodes, nodeSet, this);
2114
						this.patternLocator.matchReportReference(node, enclosingElement, method.binding, method.scope, level.intValue(), this);
2119
						method.traverse(declarationVisitor, (ClassScope) null);
2120
						int length = nodes.length;
2121
						for (int i = 0; i < length; i++) {
2122
							Integer level = (Integer) nodeSet.matchingNodes.removeKey(nodes[i]);
2123
			    	        this.patternLocator.matchReportReference(nodes[i], enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), method.binding, level.intValue(), this);
2124
						}
2125
					} else {
2126
						for (int i = 0, l = nodes.length; i < l; i++) {
2127
							ASTNode node = nodes[i];
2128
							Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2129
							this.patternLocator.matchReportReference(node, enclosingElement, null, null, method.binding, level.intValue(), this);
2130
						}
2115
					}
2131
					}
2116
					return;
2132
					return;
2117
				}
2133
				}
Lines 2129-2140 Link Here
2129
protected void reportMatching(Annotation[] annotations, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedContainer, boolean enclosesElement) throws CoreException {
2145
protected void reportMatching(Annotation[] annotations, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedContainer, boolean enclosesElement) throws CoreException {
2130
	for (int i=0, al=annotations.length; i<al; i++) {
2146
	for (int i=0, al=annotations.length; i<al; i++) {
2131
		Annotation annotationType = annotations[i];
2147
		Annotation annotationType = annotations[i];
2148
		IJavaElement localElement = null;
2132
2149
2133
		// Look for annotation type ref
2150
		// Look for annotation type ref
2134
		TypeReference typeRef = annotationType.type;
2151
		TypeReference typeRef = annotationType.type;
2135
		Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef);
2152
		Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef);
2136
		if (level != null && matchedContainer) {
2153
		if (level != null && matchedContainer) {
2137
			this.patternLocator.matchReportReference(typeRef, enclosingElement, elementBinding, level.intValue(), this);
2154
			localElement = createHandle(annotationType, (IAnnotatable) enclosingElement);
2155
			this.patternLocator.matchReportReference(typeRef, enclosingElement, localElement, null, elementBinding, level.intValue(), this);
2138
		}
2156
		}
2139
		
2157
		
2140
		// Look for attribute ref
2158
		// Look for attribute ref
Lines 2144-2150 Link Here
2144
			level = (Integer) nodeSet.matchingNodes.removeKey(pair);
2162
			level = (Integer) nodeSet.matchingNodes.removeKey(pair);
2145
			if (level != null && enclosesElement) {
2163
			if (level != null && enclosesElement) {
2146
				ASTNode reference = (annotationType instanceof SingleMemberAnnotation) ? (ASTNode) annotationType: pair;
2164
				ASTNode reference = (annotationType instanceof SingleMemberAnnotation) ? (ASTNode) annotationType: pair;
2147
				this.patternLocator.matchReportReference(reference, enclosingElement, pair.binding, level.intValue(), this);
2165
				if (localElement == null) {
2166
					localElement = createHandle(annotationType, (IAnnotatable) enclosingElement);
2167
				}
2168
				this.patternLocator.matchReportReference(reference, enclosingElement, localElement, null, pair.binding, level.intValue(), this);
2148
			}
2169
			}
2149
		}
2170
		}
2150
		
2171
		
Lines 2160-2166 Link Here
2160
					ASTNode node = nodes[j];
2181
					ASTNode node = nodes[j];
2161
					level = (Integer) nodeSet.matchingNodes.removeKey(node);
2182
					level = (Integer) nodeSet.matchingNodes.removeKey(node);
2162
					if (enclosesElement) {
2183
					if (enclosesElement) {
2163
						this.patternLocator.matchReportReference(node, enclosingElement, elementBinding, level.intValue(), this);
2184
						if (localElement == null) {
2185
							localElement = createHandle(annotationType, (IAnnotatable) enclosingElement);
2186
						}
2187
						this.patternLocator.matchReportReference(node, enclosingElement, localElement, null, elementBinding, level.intValue(), this);
2164
					}
2188
					}
2165
				}
2189
				}
2166
			}
2190
			}
Lines 2235-2241 Link Here
2235
					ASTNode node = nodes[i];
2259
					ASTNode node = nodes[i];
2236
					Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2260
					Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2237
					if (encloses(element)) {
2261
					if (encloses(element)) {
2238
						this.patternLocator.matchReportReference(node, element, null/*no binding*/, level.intValue(), this);
2262
						this.patternLocator.matchReportReference(node, element, null, null, null/*no binding*/, level.intValue(), this);
2239
					}
2263
					}
2240
				}
2264
				}
2241
			}
2265
			}
Lines 2300-2313 Link Here
2300
2324
2301
	// handle the nodes for the local type first
2325
	// handle the nodes for the local type first
2302
	if ((field.bits & ASTNode.HasLocalType) != 0) {
2326
	if ((field.bits & ASTNode.HasLocalType) != 0) {
2303
		if (enclosingElement == null)
2327
		if (enclosingElement == null) {
2304
			enclosingElement = createHandle(field, type, parent);
2328
			enclosingElement = createHandle(field, type, parent);
2305
		LocalDeclarationVisitor localDeclarationVisitor = new LocalDeclarationVisitor(enclosingElement, field.binding, nodeSet);
2329
		}
2330
		// Traverse field declaration(s) to report matches both in local types declaration
2331
		// and in local variables declaration
2332
		int fieldEnd = field.endPart2Position == 0 ? field.declarationSourceEnd : field.endPart2Position;
2333
		ASTNode[] nodes = typeInHierarchy ? nodeSet.matchingNodes(field.sourceStart, fieldEnd) : null;
2334
		boolean report = (this.matchContainer & PatternLocator.FIELD_CONTAINER) != 0 && encloses(enclosingElement);
2335
		MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, report ? nodes : null, nodeSet, this);
2306
		try {
2336
		try {
2307
			field.traverse(localDeclarationVisitor, null);
2337
			field.traverse(declarationVisitor, (MethodScope) null);
2308
		} catch (WrappedCoreException e) {
2338
		} catch (WrappedCoreException e) {
2309
			throw e.coreException;
2339
			throw e.coreException;
2310
		}
2340
		}
2341
		// Report all nodes and remove them
2342
		if (nodes != null) {
2343
			int length = nodes.length;
2344
			for (int i = 0; i < length; i++) {
2345
				ASTNode node = nodes[i];
2346
				Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2347
				if (report && level != null) {
2348
					if (node instanceof TypeDeclaration) {
2349
						// use field declaration to report match (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88174)
2350
						AllocationExpression allocation = ((TypeDeclaration)node).allocation;
2351
						if (allocation != null && allocation.enumConstant != null) {
2352
							node = field;
2353
						}
2354
					}
2355
	    	        this.patternLocator.matchReportReference(node, enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), field.binding, level.intValue(), this);
2356
				}
2357
			}
2358
		}
2311
	}
2359
	}
2312
2360
2313
	// report annotations
2361
	// report annotations
Lines 2357-2370 Link Here
2357
		ASTNode[] nodes = nodeSet.matchingNodes(field.sourceStart, fieldEnd);
2405
		ASTNode[] nodes = nodeSet.matchingNodes(field.sourceStart, fieldEnd);
2358
		if (nodes != null) {
2406
		if (nodes != null) {
2359
			if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) {
2407
			if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) {
2360
				for (int i = 0, l = nodes.length; i < l; i++)
2408
				for (int i = 0, l = nodes.length; i < l; i++) {
2361
					nodeSet.matchingNodes.removeKey(nodes[i]);
2409
					nodeSet.matchingNodes.removeKey(nodes[i]);
2410
				}
2362
			} else {
2411
			} else {
2363
				if (enclosingElement == null) {
2412
				if (enclosingElement == null) {
2364
					enclosingElement = createHandle(field, type, parent);
2413
					enclosingElement = createHandle(field, type, parent);
2365
				}
2414
				}
2366
				if (encloses(enclosingElement)) {
2415
				if (encloses(enclosingElement)) {
2367
					for (int i = 0, l = nodes.length; i < l; i++) {
2416
					MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, nodes, nodeSet, this);
2417
					field.traverse(declarationVisitor, (MethodScope) null);
2418
					int length = nodes.length;
2419
					for (int i = 0; i < length; i++) {
2368
						ASTNode node = nodes[i];
2420
						ASTNode node = nodes[i];
2369
						Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2421
						Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2370
						if (node instanceof TypeDeclaration) {
2422
						if (node instanceof TypeDeclaration) {
Lines 2374-2386 Link Here
2374
								node = field;
2426
								node = field;
2375
							}
2427
							}
2376
						}
2428
						}
2377
						// Set block scope for initializer in case there would have other local and other elements to report
2429
		    	        this.patternLocator.matchReportReference(node, enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), field.binding, level.intValue(), this);
2378
						BlockScope blockScope = null;
2379
						if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) {
2380
							Block block = ((Initializer)field).block;
2381
							if (block != null) blockScope = block.scope;
2382
						}
2383
						this.patternLocator.matchReportReference(node, enclosingElement, field.binding, blockScope, level.intValue(), this);
2384
					}
2430
					}
2385
					return;
2431
					return;
2386
				}
2432
				}
Lines 2441-2447 Link Here
2441
					ASTNode node = nodes[i];
2487
					ASTNode node = nodes[i];
2442
					Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2488
					Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2443
					if (enclosesElement) {
2489
					if (enclosesElement) {
2444
						this.patternLocator.matchReportReference(node, enclosingElement, type.binding, level.intValue(), this);
2490
						this.patternLocator.matchReportReference(node, enclosingElement, null, null, type.binding, level.intValue(), this);
2445
					}
2491
					}
2446
				}
2492
				}
2447
			}
2493
			}
Lines 2454-2460 Link Here
2454
		if (superType != null) {
2500
		if (superType != null) {
2455
			Integer level = (Integer) nodeSet.matchingNodes.removeKey(superType);
2501
			Integer level = (Integer) nodeSet.matchingNodes.removeKey(superType);
2456
			if (level != null && matchedClassContainer)
2502
			if (level != null && matchedClassContainer)
2457
				this.patternLocator.matchReportReference(superType, enclosingElement, type.binding, level.intValue(), this);
2503
				this.patternLocator.matchReportReference(superType, enclosingElement, null, null, type.binding, level.intValue(), this);
2458
		}
2504
		}
2459
	} else {
2505
	} else {
2460
		TypeReference superClass = type.superclass;
2506
		TypeReference superClass = type.superclass;
Lines 2639-2651 Link Here
2639
				for (int i = 0, l = nodes.length; i < l; i++) {
2685
				for (int i = 0, l = nodes.length; i < l; i++) {
2640
					ASTNode node = nodes[i];
2686
					ASTNode node = nodes[i];
2641
					Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2687
					Integer level = (Integer) nodeSet.matchingNodes.removeKey(node);
2642
					this.patternLocator.matchReportReference(node, enclosingElement, elementBinding, level.intValue(), this);
2688
					this.patternLocator.matchReportReference(node, enclosingElement, null, null, elementBinding, level.intValue(), this);
2643
				}
2689
				}
2644
		}
2690
		}
2645
	} else if (encloses(enclosingElement)) {
2691
	} else if (encloses(enclosingElement)) {
2646
		Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference);
2692
		Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference);
2647
		if (level != null && matchedClassContainer)
2693
		if (level != null && matchedClassContainer)
2648
			this.patternLocator.matchReportReference(superReference, enclosingElement, elementBinding, level.intValue(), this);
2694
			this.patternLocator.matchReportReference(superReference, enclosingElement, null, null, elementBinding, level.intValue(), this);
2649
	}
2695
	}
2650
}
2696
}
2651
protected boolean typeInHierarchy(ReferenceBinding binding) {
2697
protected boolean typeInHierarchy(ReferenceBinding binding) {
(-)search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java (-2 / +2 lines)
Lines 56-62 Link Here
56
/* (non-Javadoc)
56
/* (non-Javadoc)
57
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchReportReference(org.eclipse.jdt.internal.compiler.ast.ASTNode, org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.internal.compiler.lookup.Binding, int, org.eclipse.jdt.internal.core.search.matching.MatchLocator)
57
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#matchReportReference(org.eclipse.jdt.internal.compiler.ast.ASTNode, org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.internal.compiler.lookup.Binding, int, org.eclipse.jdt.internal.core.search.matching.MatchLocator)
58
 */
58
 */
59
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
59
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
60
	if (elementBinding instanceof ReferenceBinding) {
60
	if (elementBinding instanceof ReferenceBinding) {
61
		ReferenceBinding referenceBinding = (ReferenceBinding) elementBinding;
61
		ReferenceBinding referenceBinding = (ReferenceBinding) elementBinding;
62
		if (referenceBinding.isClass() && this.pattern.typeSuffix == IIndexConstants.INTERFACE_SUFFIX) {
62
		if (referenceBinding.isClass() && this.pattern.typeSuffix == IIndexConstants.INTERFACE_SUFFIX) {
Lines 68-74 Link Here
68
			return;
68
			return;
69
		}
69
		}
70
	}
70
	}
71
	super.matchReportReference(reference, element, elementBinding, accuracy, locator);
71
	super.matchReportReference(reference, element, localElement, otherElements, elementBinding, accuracy, locator);
72
}
72
}
73
protected int referenceType() {
73
protected int referenceType() {
74
	return IJavaElement.TYPE;
74
	return IJavaElement.TYPE;
(-)search/org/eclipse/jdt/internal/core/search/matching/OrLocator.java (-2 / +2 lines)
Lines 249-255 Link Here
249
	if (closestPattern != null)
249
	if (closestPattern != null)
250
		closestPattern.matchReportImportRef(importRef, binding, element, accuracy, locator);
250
		closestPattern.matchReportImportRef(importRef, binding, element, accuracy, locator);
251
}
251
}
252
protected void matchReportReference(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
252
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException {
253
	PatternLocator closestPattern = null;
253
	PatternLocator closestPattern = null;
254
	int level = IMPOSSIBLE_MATCH;
254
	int level = IMPOSSIBLE_MATCH;
255
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
255
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
Lines 262-268 Link Here
262
		}
262
		}
263
	}
263
	}
264
	if (closestPattern != null)
264
	if (closestPattern != null)
265
		closestPattern.matchReportReference(reference, element, elementBinding, accuracy, locator);
265
		closestPattern.matchReportReference(reference, element, localElement, otherElements, elementBinding, accuracy, locator);
266
}
266
}
267
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, int length, MatchLocator locator) {
267
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, Binding elementBinding, int accuracy, int length, MatchLocator locator) {
268
	PatternLocator closestPattern = null;
268
	PatternLocator closestPattern = null;
(-)search/org/eclipse/jdt/internal/core/search/matching/MemberDeclarationVisitor.java (+269 lines)
Added 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 org.eclipse.core.runtime.CoreException;
14
import org.eclipse.jdt.core.IAnnotatable;
15
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.internal.compiler.ASTVisitor;
18
import org.eclipse.jdt.internal.compiler.ast.*;
19
import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
20
import org.eclipse.jdt.internal.compiler.util.HashtableOfIntValues;
21
import org.eclipse.jdt.internal.core.search.matching.MatchLocator.WrappedCoreException;
22
23
/**
24
 * Specific visitor of field or method declaration which can identify and store
25
 * the local and  other elements of one or several matching nodes.
26
 * <p>
27
 * This visitor can also peek up local or anonymous type declaration and restart
28
 * a new {@link MatchLocator} traverse on this type.
29
 * </p>
30
 */
31
class MemberDeclarationVisitor extends ASTVisitor {
32
	// Matches information
33
	private final MatchLocator locator;
34
	private final IJavaElement enclosingElement;
35
	private final MatchingNodeSet nodeSet;
36
	private final ASTNode[] matchingNodes;
37
	private final ASTNode matchingNode;
38
39
	// Local type storage
40
	HashtableOfIntValues occurrencesCounts = new HashtableOfIntValues(); // key = class name (char[]), value = occurrenceCount (int)
41
	int nodesCount = 0;
42
43
	// Local and other elements storage
44
	IJavaElement currentDeclaration;
45
	private Annotation annotation;
46
	private LocalDeclaration localDeclaration;
47
	IJavaElement localElement;
48
	IJavaElement[] localElements, otherElements;
49
	IJavaElement[][] allOtherElements;
50
	int ptr = -1;
51
	int[] ptrs;
52
53
public MemberDeclarationVisitor(IJavaElement element, ASTNode[] nodes, MatchingNodeSet set, MatchLocator locator) {
54
	this.enclosingElement = element;
55
	this.nodeSet = set;
56
	this.locator = locator;
57
	if (nodes == null) {
58
		this.matchingNode = null;
59
		this.matchingNodes = null;
60
	} else {
61
		this.nodesCount = nodes.length;
62
		if (nodes.length == 1) {
63
			this.matchingNode = nodes[0];
64
			this.matchingNodes = null;
65
		} else {
66
			this.matchingNode = null;
67
			this.matchingNodes = nodes;
68
			this.localElements = new IJavaElement[this.nodesCount];
69
			this.ptrs = new int[this.nodesCount];
70
			this.allOtherElements = new IJavaElement[this.nodesCount][];
71
		}
72
	}
73
}
74
public void endVisit(Argument argument, BlockScope scope) {
75
    this.localDeclaration = null;
76
}
77
public void endVisit(LocalDeclaration declaration, BlockScope scope) {
78
    this.localDeclaration = null;
79
}
80
public void endVisit(MarkerAnnotation markerAnnotation, BlockScope unused) {
81
	this.annotation = null;
82
}
83
public void endVisit(NormalAnnotation normalAnnotation, BlockScope unused) {
84
	this.annotation = null;
85
}
86
public void endVisit(SingleMemberAnnotation singleMemberAnnotation, BlockScope unused) {
87
	this.annotation = null;
88
}
89
IJavaElement getLocalElement(int idx) {
90
	if (this.nodesCount == 1) {
91
		return this.localElement;
92
	}
93
	if (this.localElements != null) {
94
		return this.localElements[idx];
95
	}
96
	return null;
97
}
98
IJavaElement[] getOtherElements(int idx) {
99
	if (this.nodesCount == 1) {
100
		if (this.otherElements != null) {
101
			int length = this.otherElements.length;
102
			if (this.ptr < (length-1)) {
103
				System.arraycopy(this.otherElements, 0, this.otherElements = new IJavaElement[this.ptr+1], 0, this.ptr+1);
104
			}
105
		}
106
		return this.otherElements;
107
	}
108
	IJavaElement[] elements = this.allOtherElements == null ? null : this.allOtherElements[idx];
109
	if (elements != null) {
110
		int length = elements.length;
111
		if (this.ptrs[idx] < (length-1)) {
112
			System.arraycopy(elements, 0, elements = this.allOtherElements[idx] = new IJavaElement[this.ptrs[idx]+1], 0, this.ptrs[idx]+1);
113
		}
114
	}
115
	return elements;
116
}
117
private int matchNode(ASTNode reference) {
118
	if (this.matchingNode != null) {
119
		if (this.matchingNode == reference) return 0;
120
	} else {
121
	    int length = this.matchingNodes.length;
122
		for (int i=0; i<length; i++) {
123
			if (this.matchingNodes[i] == reference)  { // == is intentional
124
				return i;
125
			}
126
		}
127
	}
128
	return -1;
129
}
130
/*
131
 * Store the handle for the reference of the given index (e.g. peek in #matchingNodes
132
 * or #matchingNode).
133
 * Note that for performance reason, matching node and associated handles are
134
 * not stored in array when there's only one reference to identify.
135
 */
136
private void storeHandle(int idx) {
137
	if (this.localDeclaration == null) return;
138
	IJavaElement handle = locator.createHandle(this.localDeclaration, this.enclosingElement);
139
    if (this.nodesCount == 1) {
140
    	if (this.localElement == null) {
141
    		if (this.annotation == null) {
142
		    	this.localElement =  handle;
143
    		} else {
144
		    	IJavaElement annotHandle = this.locator.createHandle(this.annotation, (IAnnotatable) handle);
145
		    	if (annotHandle == null) {
146
			    	annotHandle = this.locator.createHandle(this.annotation, (IAnnotatable) this.enclosingElement);
147
		    	}
148
		    	this.localElement = annotHandle == null ? handle : annotHandle;
149
    		}
150
    	} else {
151
	    	if (++this.ptr == 0) {
152
	    		this.otherElements = new IJavaElement[10];
153
	    	} else {
154
	            int length = this.otherElements.length;
155
	            if (this.ptr == length) {
156
	            	System.arraycopy(this.otherElements, 0, this.otherElements = new IJavaElement[length+10], 0, length);
157
	            }
158
            }
159
	    	this.otherElements[this.ptr] = handle;
160
    	}
161
    } else {
162
    	if (this.localElements[idx] == null) {
163
	    	if (this.annotation == null) {
164
		    	this.localElements[idx] =  handle;
165
    		} else {
166
		    	IJavaElement annotHandle = locator.createHandle(this.annotation, (IAnnotatable) handle);
167
		    	if (annotHandle == null) {
168
			    	annotHandle = locator.createHandle(this.annotation, (IAnnotatable) this.enclosingElement);
169
		    	}
170
		    	this.localElements[idx] = annotHandle == null ? handle : annotHandle;
171
    		}
172
			this.ptrs[idx] = -1;
173
	    } else {
174
	        int oPtr = ++this.ptrs[idx];
175
	    	if (oPtr== 0) {
176
    			this.allOtherElements[idx] = new IJavaElement[10];
177
    		} else {
178
            	int length = this.allOtherElements[idx].length;
179
	            if (oPtr == length) {
180
	            	System.arraycopy(this.allOtherElements[idx], 0, this.allOtherElements[idx] = new IJavaElement[length+10], 0, length);
181
        	    }
182
	        }
183
 		   	this.allOtherElements[idx][oPtr] = handle;
184
    	}
185
    }
186
}
187
public boolean visit(Argument argument, BlockScope scope) {
188
    this.localDeclaration = argument;
189
    return true;
190
}
191
public boolean visit(LocalDeclaration declaration, BlockScope scope) {
192
    this.localDeclaration = declaration;
193
    return true;
194
}
195
public boolean visit(MarkerAnnotation markerAnnotation, BlockScope unused) {
196
	this.annotation = markerAnnotation;
197
	return true;
198
}
199
public boolean visit(NormalAnnotation normalAnnotation, BlockScope unused) {
200
	this.annotation = normalAnnotation;
201
	return true;
202
}
203
public boolean visit(QualifiedNameReference nameReference, BlockScope unused) {
204
	if (this.nodesCount > 0){
205
		int idx = matchNode(nameReference);
206
		if (idx >= 0) {
207
			storeHandle(idx);
208
		}
209
	}
210
	return false;
211
}
212
public boolean visit(QualifiedTypeReference typeReference, BlockScope unused) {
213
	if (this.nodesCount > 0){
214
		int idx = matchNode(typeReference);
215
		if (idx >= 0) {
216
			storeHandle(idx);
217
		}
218
	}
219
	return false;
220
}
221
public boolean visit(SingleMemberAnnotation singleMemberAnnotation, BlockScope unused) {
222
	this.annotation = singleMemberAnnotation;
223
	return true;
224
}
225
public boolean visit(SingleNameReference nameReference, BlockScope unused) {
226
	if (this.nodesCount > 0){
227
		int idx = matchNode(nameReference);
228
		if (idx >= 0) {
229
			storeHandle(idx);
230
		}
231
	}
232
	return false;
233
}
234
public boolean visit(SingleTypeReference typeReference, BlockScope unused) {
235
	if (this.nodesCount > 0){
236
		int idx = matchNode(typeReference);
237
		if (idx >= 0) {
238
			storeHandle(idx);
239
		}
240
	}
241
	return false;
242
}
243
public boolean visit(TypeDeclaration typeDeclaration, BlockScope unused) {
244
	try {
245
		char[] simpleName;
246
		if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {				
247
			simpleName = CharOperation.NO_CHAR;
248
		} else {
249
			simpleName = typeDeclaration.name;
250
		}
251
		int occurrenceCount = occurrencesCounts.get(simpleName);
252
		if (occurrenceCount == HashtableOfIntValues.NO_VALUE) {
253
			occurrenceCount = 1;
254
		} else {
255
			occurrenceCount = occurrenceCount + 1;
256
		}
257
		occurrencesCounts.put(simpleName, occurrenceCount);
258
		if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) {				
259
			this.locator.reportMatching(typeDeclaration, this.enclosingElement, -1, nodeSet, occurrenceCount);
260
		} else {
261
			Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeDeclaration);
262
			this.locator.reportMatching(typeDeclaration, this.enclosingElement, level != null ? level.intValue() : -1, nodeSet, occurrenceCount);
263
		}
264
		return false; // don't visit members as this was done during reportMatching(...)
265
	} catch (CoreException e) {
266
		throw new WrappedCoreException(e);
267
	}
268
}
269
}
(-)search/org/eclipse/jdt/core/search/ReferenceMatch.java (+104 lines)
Added 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.core.search;
12
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.jdt.core.*;
15
16
/**
17
 * An abstract Java search match that represents a reference.
18
 * <p>
19
 * The element is the inner-most enclosing member that references this type.
20
 * </p><p>
21
 * Since version 3.2, a {@link TypeReferenceMatch} also can return a local element
22
 * which may be a {@link ILocalVariable} or a  {@link ITypeParameter}.
23
 * </p><p>
24
 * This local element has been enhanced since version 3.4:
25
 * <ul>
26
 * 	<li>it is accessible from all kind of reference match (e.g. all sub-classes of this
27
 * 			{@link ReferenceMatch} class).</li>
28
 * 	<li>it can also return an {@link IAnnotation} (see {@link #getLocalElement()}
29
 * 			for more details).</li>
30
 * </ul>
31
 * </p><p>
32
 * TODO (frederic) Add this paragraph only if we really want to prevent client to subclass this class...
33
 * This class is not intended to be subclassed by clients.
34
 * </p>
35
 * 
36
 * @since 3.4
37
 */
38
public abstract class ReferenceMatch extends SearchMatch {
39
40
	IJavaElement localElement;
41
42
/**
43
 * Creates a new type reference match.
44
 * 
45
 * @param enclosingElement the inner-most enclosing member that references this type
46
 * @param localElement the nearest local element enclosing this reference
47
 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
48
 * @param offset the offset the match starts at, or -1 if unknown
49
 * @param length the length of the match, or -1 if unknown
50
 * @param insideDocComment <code>true</code> if this search match is inside a doc
51
 * comment, and <code>false</code> otherwise
52
 * @param participant the search participant that created the match
53
 * @param resource the resource of the element
54
 */
55
ReferenceMatch(IJavaElement enclosingElement, IJavaElement localElement, int accuracy, int offset, int length, boolean insideDocComment, SearchParticipant participant, IResource resource) {
56
	super(enclosingElement, accuracy, offset, length, participant, resource);
57
	setInsideDocComment(insideDocComment);
58
	this.localElement = localElement;
59
}
60
61
/**
62
 * Returns the local element of this search match.
63
 * <p>
64
 * This may be a local variable whose declaring type is the referenced one
65
 * or a type parameter which extends it.
66
 * </p><p>
67
 * Since the version 3.4, clients can access to this method from all reference match
68
 * classes although it was only defined on {@link TypeReferenceMatch} before.
69
 * This was necessary as this local element may also be an {@link IAnnotation}.
70
 * </p><p>
71
 * For example,
72
 * <ul>
73
 * 	<li>in the following code snippet while searching the reference to the type <code>Test</code>:
74
 * 			<pre>
75
 *             public class Test {
76
 *                 void method() {
77
 *                     &#0064;Annot(Test.class) int x;
78
 *                 }
79
 *             }
80
 * 			</pre>
81
 * 			the local element of the returned {@link TypeReferenceMatch} will be
82
 * 			the {@link IAnnotation} <code>Annot</code>.
83
 * 	</li>
84
 *		<li>in the other code snippet while searching for the reference to the type
85
 * 			<code>Deprecated</code>:
86
 * 			<pre>
87
 *             public class Test {
88
 *                &#0064;Deprecated void method() {}
89
 *             }
90
 * 			</pre>
91
 * 			the local element of the returned {@link TypeReferenceMatch} will be
92
 * 			the {@link IAnnotation} <code>Annot</code>.
93
 * 	</li>
94
 * </ul>
95
 * </p>
96
 * 
97
 * @return the element of the search match, or <code>null</code> if none or there's
98
 * 	no more specific local element than the element itself ({@link SearchMatch#getElement()}).
99
 * @since 3.2
100
 */
101
public final IJavaElement getLocalElement() {
102
	return this.localElement;
103
}
104
}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+67 lines)
Lines 9210-9215 Link Here
9210
}
9210
}
9211
9211
9212
/**
9212
/**
9213
 * @bug 209778: [search] TypeReferenceMatch#getOtherElements() fails for match in annotation
9214
 * @test Ensure that the local element is no longer a local variable
9215
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=209778"
9216
 */
9217
public void testBug209778() throws CoreException {
9218
	workingCopies = new ICompilationUnit[1];
9219
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/xy/Try.java",
9220
		"package xy;\n" + 
9221
		"\n" + 
9222
		"public class Try {\n" + 
9223
		"        void tryB(int tryKind) {\n" + 
9224
		"                @Constants(Try.class) int tryCopy, tryCopy2= tryKind;\n" + 
9225
		"        }\n" + 
9226
		"        @Constants(value= Try.class) Object fTryA, fTryB;\n" + 
9227
		"}\n" + 
9228
		"\n" + 
9229
		"@interface Constants {\n" + 
9230
		"        Class<?> value();\n" + 
9231
		"}"
9232
	);
9233
	IType type = workingCopies[0].getType("Try");
9234
	TypeReferencesCollector collector = new TypeReferencesCollector();
9235
	search(type, REFERENCES, EXACT_RULE, getJavaSearchScope(), collector);
9236
	assertSearchResults(
9237
		"src/xy/Try.java @Constants(value=Try.class) [Try]\n" + 
9238
		"src/xy/Try.java @Constants(value=Try.class) [Try]",
9239
		collector
9240
	);
9241
}
9242
9243
/**
9244
 * @bug 209996: [search] Add a way to access the most local enclosing annotation for reference search matches
9245
 * @test Verify the behavior of the new Search API {@link ReferenceMatch#getLocalElement()}
9246
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=209996"
9247
 */
9248
public void testBug209996() throws CoreException {
9249
	workingCopies = new ICompilationUnit[1];
9250
	workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/comment5/Ref.java",
9251
		"package comment5;\n" + 
9252
		"public class Ref {\n" + 
9253
		"    void doA(Ref ref) {}\n" + 
9254
		"    void doB(List<Ref> ref) {}\n" + 
9255
		"    void doC(@Tag(Ref.class) Ref ref) {}\n" + 
9256
		"    void dontD(@Tag(Ref.class) Object ref) {}\n" + 
9257
		"}\n" + 
9258
		"\n" + 
9259
		"@interface Tag {\n" + 
9260
		"    Class value();\n" + 
9261
		"}\n" + 
9262
		"class List<T> {\n" + 
9263
		"}\n"
9264
	);
9265
	IType type = workingCopies[0].getType("Ref");
9266
	TypeReferencesCollector collector = new TypeReferencesCollector();
9267
	collector.showSelection = true;
9268
	search(type, REFERENCES, EXACT_RULE, getJavaSearchScope(), collector);
9269
	assertSearchResults(
9270
		"src/comment5/Ref.java void comment5.Ref.doA(Ref).ref [    void doA(§|Ref|§ ref) {}]\n" + 
9271
		"src/comment5/Ref.java void comment5.Ref.doB(List<Ref>).ref [    void doB(List<§|Ref|§> ref) {}]\n" + 
9272
		"src/comment5/Ref.java @Tag(value=Ref.class) [    void doC(@Tag(§|Ref|§.class) Ref ref) {}]\n" + 
9273
		"src/comment5/Ref.java void comment5.Ref.doC(Ref).ref [    void doC(@Tag(Ref.class) §|Ref|§ ref) {}]\n" + 
9274
		"src/comment5/Ref.java @Tag(value=Ref.class) [    void dontD(@Tag(§|Ref|§.class) Object ref) {}]",
9275
		collector
9276
	);
9277
}
9278
9279
/**
9213
 * @bug 210689: [search] Type references are not found in import declarations when JUnit tests only use working copies
9280
 * @bug 210689: [search] Type references are not found in import declarations when JUnit tests only use working copies
9214
 * @test Ensure that import references are found when searching on working copies not written on disk
9281
 * @test Ensure that import references are found when searching on working copies not written on disk
9215
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=210689"
9282
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=210689"
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchFineGrainTests.java (-8 / +8 lines)
Lines 1005-1019 Link Here
1005
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<§|String|§>>, Z<String>>();@257] EXACT_MATCH\n" + 
1005
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<§|String|§>>, Z<String>>();@257] EXACT_MATCH\n" + 
1006
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, §|Z|§<String>>();@267] EXACT_MATCH\n" + 
1006
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, §|Z|§<String>>();@267] EXACT_MATCH\n" + 
1007
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, Z<§|String|§>>();@269] EXACT_MATCH\n" + 
1007
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, Z<§|String|§>>();@269] EXACT_MATCH\n" + 
1008
		"src/test02/Test.java test02.Test.field [	§|Test|§<A, ? extends B, ? super C> field = new Test<A, Z<String>, X<String>> () {@47] EXACT_MATCH\n" + 
1009
		"src/test02/Test.java test02.Test.field [	Test<§|A|§, ? extends B, ? super C> field = new Test<A, Z<String>, X<String>> () {@52] EXACT_MATCH\n" + 
1010
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends §|B|§, ? super C> field = new Test<A, Z<String>, X<String>> () {@65] EXACT_MATCH\n" + 
1011
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super §|C|§> field = new Test<A, Z<String>, X<String>> () {@76] EXACT_MATCH\n" + 
1012
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<§|A|§, Z<String>, X<String>> () {@96] EXACT_MATCH\n" + 
1008
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<§|A|§, Z<String>, X<String>> () {@96] EXACT_MATCH\n" + 
1013
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, §|Z|§<String>, X<String>> () {@99] EXACT_MATCH\n" + 
1009
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, §|Z|§<String>, X<String>> () {@99] EXACT_MATCH\n" + 
1014
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<§|String|§>, X<String>> () {@101] EXACT_MATCH\n" + 
1010
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<§|String|§>, X<String>> () {@101] EXACT_MATCH\n" + 
1015
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, §|X|§<String>> () {@110] EXACT_MATCH\n" + 
1011
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, §|X|§<String>> () {@110] EXACT_MATCH\n" + 
1016
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, X<§|String|§>> () {@112] EXACT_MATCH\n" + 
1012
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, X<§|String|§>> () {@112] EXACT_MATCH\n" + 
1013
		"src/test02/Test.java test02.Test.field [	§|Test|§<A, ? extends B, ? super C> field = new Test<A, Z<String>, X<String>> () {@47] EXACT_MATCH\n" + 
1014
		"src/test02/Test.java test02.Test.field [	Test<§|A|§, ? extends B, ? super C> field = new Test<A, Z<String>, X<String>> () {@52] EXACT_MATCH\n" + 
1015
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends §|B|§, ? super C> field = new Test<A, Z<String>, X<String>> () {@65] EXACT_MATCH\n" + 
1016
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super §|C|§> field = new Test<A, Z<String>, X<String>> () {@76] EXACT_MATCH\n" + 
1017
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	§|Test|§<? super A, B, ? extends C> foo(Test<? extends A, ? super B, C> param) {@290] EXACT_MATCH\n" + 
1017
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	§|Test|§<? super A, B, ? extends C> foo(Test<? extends A, ? super B, C> param) {@290] EXACT_MATCH\n" + 
1018
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super §|A|§, B, ? extends C> foo(Test<? extends A, ? super B, C> param) {@303] EXACT_MATCH\n" + 
1018
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super §|A|§, B, ? extends C> foo(Test<? extends A, ? super B, C> param) {@303] EXACT_MATCH\n" + 
1019
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, §|B|§, ? extends C> foo(Test<? extends A, ? super B, C> param) {@306] EXACT_MATCH\n" + 
1019
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, §|B|§, ? extends C> foo(Test<? extends A, ? super B, C> param) {@306] EXACT_MATCH\n" + 
Lines 1054-1067 Link Here
1054
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<§|String|§>>, Z<String>>();@257] EXACT_MATCH\n" + 
1054
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<§|String|§>>, Z<String>>();@257] EXACT_MATCH\n" + 
1055
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, §|Z|§<String>>();@267] EXACT_MATCH\n" + 
1055
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, §|Z|§<String>>();@267] EXACT_MATCH\n" + 
1056
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, Z<§|String|§>>();@269] EXACT_MATCH\n" + 
1056
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, Z<§|String|§>>();@269] EXACT_MATCH\n" + 
1057
		"src/test02/Test.java test02.Test.field [	Test<§|A|§, ? extends B, ? super C> field = new Test<A, Z<String>, X<String>> () {@52] EXACT_MATCH\n" + 
1058
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends §|B|§, ? super C> field = new Test<A, Z<String>, X<String>> () {@65] EXACT_MATCH\n" + 
1059
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super §|C|§> field = new Test<A, Z<String>, X<String>> () {@76] EXACT_MATCH\n" + 
1060
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<§|A|§, Z<String>, X<String>> () {@96] EXACT_MATCH\n" + 
1057
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<§|A|§, Z<String>, X<String>> () {@96] EXACT_MATCH\n" + 
1061
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, §|Z|§<String>, X<String>> () {@99] EXACT_MATCH\n" + 
1058
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, §|Z|§<String>, X<String>> () {@99] EXACT_MATCH\n" + 
1062
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<§|String|§>, X<String>> () {@101] EXACT_MATCH\n" + 
1059
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<§|String|§>, X<String>> () {@101] EXACT_MATCH\n" + 
1063
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, §|X|§<String>> () {@110] EXACT_MATCH\n" + 
1060
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, §|X|§<String>> () {@110] EXACT_MATCH\n" + 
1064
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, X<§|String|§>> () {@112] EXACT_MATCH\n" + 
1061
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, X<§|String|§>> () {@112] EXACT_MATCH\n" + 
1062
		"src/test02/Test.java test02.Test.field [	Test<§|A|§, ? extends B, ? super C> field = new Test<A, Z<String>, X<String>> () {@52] EXACT_MATCH\n" + 
1063
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends §|B|§, ? super C> field = new Test<A, Z<String>, X<String>> () {@65] EXACT_MATCH\n" + 
1064
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super §|C|§> field = new Test<A, Z<String>, X<String>> () {@76] EXACT_MATCH\n" + 
1065
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super §|A|§, B, ? extends C> foo(Test<? extends A, ? super B, C> param) {@303] EXACT_MATCH\n" + 
1065
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super §|A|§, B, ? extends C> foo(Test<? extends A, ? super B, C> param) {@303] EXACT_MATCH\n" + 
1066
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, §|B|§, ? extends C> foo(Test<? extends A, ? super B, C> param) {@306] EXACT_MATCH\n" + 
1066
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, §|B|§, ? extends C> foo(Test<? extends A, ? super B, C> param) {@306] EXACT_MATCH\n" + 
1067
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, B, ? extends §|C|§> foo(Test<? extends A, ? super B, C> param) {@319] EXACT_MATCH\n" + 
1067
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, B, ? extends §|C|§> foo(Test<? extends A, ? super B, C> param) {@319] EXACT_MATCH\n" + 
Lines 1097-1108 Link Here
1097
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<§|String|§>>, Z<String>>();@257] EXACT_MATCH\n" + 
1097
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<§|String|§>>, Z<String>>();@257] EXACT_MATCH\n" + 
1098
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, §|Z|§<String>>();@267] EXACT_MATCH\n" + 
1098
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, §|Z|§<String>>();@267] EXACT_MATCH\n" + 
1099
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, Z<§|String|§>>();@269] EXACT_MATCH\n" + 
1099
		"src/test02/Test.java Test<X<Y<Z<String>>>,Y<Z<String>>,Z<String>> test02.Test.field:<anonymous>#1.bar() [			return new Test<X<Y<Z<String>>>, Y<Z<String>>, Z<§|String|§>>();@269] EXACT_MATCH\n" + 
1100
		"src/test02/Test.java test02.Test.field [	Test<§|A|§, ? extends B, ? super C> field = new Test<A, Z<String>, X<String>> () {@52] EXACT_MATCH\n" + 
1101
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<§|A|§, Z<String>, X<String>> () {@96] EXACT_MATCH\n" + 
1100
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<§|A|§, Z<String>, X<String>> () {@96] EXACT_MATCH\n" + 
1102
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, §|Z|§<String>, X<String>> () {@99] EXACT_MATCH\n" + 
1101
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, §|Z|§<String>, X<String>> () {@99] EXACT_MATCH\n" + 
1103
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<§|String|§>, X<String>> () {@101] EXACT_MATCH\n" + 
1102
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<§|String|§>, X<String>> () {@101] EXACT_MATCH\n" + 
1104
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, §|X|§<String>> () {@110] EXACT_MATCH\n" + 
1103
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, §|X|§<String>> () {@110] EXACT_MATCH\n" + 
1105
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, X<§|String|§>> () {@112] EXACT_MATCH\n" + 
1104
		"src/test02/Test.java test02.Test.field [	Test<A, ? extends B, ? super C> field = new Test<A, Z<String>, X<§|String|§>> () {@112] EXACT_MATCH\n" + 
1105
		"src/test02/Test.java test02.Test.field [	Test<§|A|§, ? extends B, ? super C> field = new Test<A, Z<String>, X<String>> () {@52] EXACT_MATCH\n" + 
1106
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, §|B|§, ? extends C> foo(Test<? extends A, ? super B, C> param) {@306] EXACT_MATCH\n" + 
1106
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, §|B|§, ? extends C> foo(Test<? extends A, ? super B, C> param) {@306] EXACT_MATCH\n" + 
1107
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, B, ? extends C> foo(Test<? extends A, ? super B, §|C|§> param) {@355] EXACT_MATCH\n" + 
1107
		"src/test02/Test.java Test<? super A,B,? extends C> test02.Test.foo(Test<? extends A,? super B,C>) [	Test<? super A, B, ? extends C> foo(Test<? extends A, ? super B, §|C|§> param) {@355] EXACT_MATCH\n" + 
1108
		"src/test02/Test.java test02.C [class C extends X<§|String|§> {}@428] EXACT_MATCH"
1108
		"src/test02/Test.java test02.C [class C extends X<§|String|§> {}@428] EXACT_MATCH"
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java (+26 lines)
Lines 162-167 Link Here
162
				} else if (element instanceof IPackageDeclaration) {
162
				} else if (element instanceof IPackageDeclaration) {
163
					IPackageDeclaration packageDeclaration = (IPackageDeclaration)element;
163
					IPackageDeclaration packageDeclaration = (IPackageDeclaration)element;
164
					unit = (ICompilationUnit)packageDeclaration.getAncestor(IJavaElement.COMPILATION_UNIT);
164
					unit = (ICompilationUnit)packageDeclaration.getAncestor(IJavaElement.COMPILATION_UNIT);
165
				} else if (element instanceof IAnnotation) {
166
					line.append(" ");
167
					append((IAnnotation)element);
168
					unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT);
165
				}
169
				}
166
				if (resource instanceof IFile) {
170
				if (resource instanceof IFile) {
167
					char[] contents = getSource(resource, element, unit);
171
					char[] contents = getSource(resource, element, unit);
Lines 273-278 Link Here
273
		private boolean showSuperInvocation() {
277
		private boolean showSuperInvocation() {
274
			return (this.showFlavors & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0;
278
			return (this.showFlavors & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0;
275
		}
279
		}
280
		protected void append(IAnnotation annotation) throws JavaModelException {
281
			line.append("@");
282
			line.append(annotation.getElementName());
283
			line.append('(');
284
			IMemberValuePair[] pairs = annotation.getMemberValuePairs();
285
			int length = pairs == null ? 0 : pairs.length;
286
			for (int i=0; i<length; i++) {
287
				line.append(pairs[i].getMemberName());
288
				line.append('=');
289
				Object value = pairs[i].getValue();
290
				switch (pairs[i].getValueKind()) {
291
					case IMemberValuePair.K_CLASS:
292
						line.append(value);
293
						line.append(".class");
294
						break;
295
					default:
296
						line.append(value);
297
					break;
298
				}
299
			}
300
			line.append(')');
301
		}
276
		protected void append(IField field) throws JavaModelException {
302
		protected void append(IField field) throws JavaModelException {
277
			append(field.getDeclaringType());
303
			append(field.getDeclaringType());
278
			line.append(".");
304
			line.append(".");

Return to bug 209996