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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/ConstructorLocator.java (+28 lines)
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.core.search.matching;
11
package org.eclipse.jdt.internal.core.search.matching;
12
12
13
import org.eclipse.jdt.core.IJavaElement;
13
import org.eclipse.jdt.core.IJavaElement;
14
import org.eclipse.jdt.core.search.SearchMatch;
14
import org.eclipse.jdt.internal.compiler.ast.*;
15
import org.eclipse.jdt.internal.compiler.ast.*;
15
import org.eclipse.jdt.internal.compiler.lookup.Binding;
16
import org.eclipse.jdt.internal.compiler.lookup.Binding;
16
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
17
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
Lines 114-119 Link Here
114
	}
115
	}
115
116
116
	return ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
117
	return ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;
118
}
119
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, int accuracy, int length, MatchLocator locator) {
120
	SearchMatch match = null;
121
	int offset = reference.sourceStart;
122
	if (this.pattern.findReferences) {
123
		if (reference instanceof TypeDeclaration) {
124
			TypeDeclaration type = (TypeDeclaration) reference;
125
			AbstractMethodDeclaration[] methods = type.methods;
126
			if (methods != null) {
127
				for (int i = 0, max = methods.length; i < max; i++) {
128
					AbstractMethodDeclaration method = methods[i];
129
					boolean synthetic = method.isDefaultConstructor() && method.sourceStart < type.bodyStart;
130
					match = locator.newConstructorReferenceMatch(element, accuracy, offset, length, type, synthetic);
131
				}
132
			}
133
		} else if (reference instanceof ConstructorDeclaration) {
134
			ConstructorDeclaration constructor = (ConstructorDeclaration) reference;
135
			ExplicitConstructorCall call = constructor.constructorCall;
136
			boolean synthetic = call != null && call.isSuperAccess();
137
			match = locator.newConstructorReferenceMatch(element, accuracy, offset, length, constructor, synthetic);
138
		}
139
	}
140
	if (match != null) {
141
		return match;
142
	}
143
	// super implementation...
144
    return locator.newDeclarationMatch(element, accuracy, reference.sourceStart, length);
117
}
145
}
118
public int resolveLevel(ASTNode node) {
146
public int resolveLevel(ASTNode node) {
119
	if (this.pattern.findReferences) {
147
	if (this.pattern.findReferences) {
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-2 / +16 lines)
Lines 994-999 Link Here
994
	if (type.exists()) return type;
994
	if (type.exists()) return type;
995
	return null;
995
	return null;
996
}
996
}
997
public SearchMatch newConstructorReferenceMatch(
998
		IJavaElement enclosingElement,
999
		int accuracy,
1000
		int offset,  
1001
		int length,
1002
		ASTNode reference,
1003
		boolean synthetic) {
1004
	SearchParticipant participant = getParticipant(); 
1005
	IResource resource = this.currentPossibleMatch.resource;
1006
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1007
	return new ConstructorReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, synthetic, participant, resource);
1008
}
997
public SearchMatch newDeclarationMatch(
1009
public SearchMatch newDeclarationMatch(
998
		IJavaElement element,
1010
		IJavaElement element,
999
		int accuracy,
1011
		int accuracy,
Lines 1342-1348 Link Here
1342
			}
1354
			}
1343
			if (encloses(enclosingElement)) {
1355
			if (encloses(enclosingElement)) {
1344
				int length = scanner.currentPosition - nameSourceStart;
1356
				int length = scanner.currentPosition - nameSourceStart;
1345
				SearchMatch match = newDeclarationMatch(enclosingElement, accuracy, nameSourceStart, length);
1357
//				SearchMatch match = newDeclarationMatch(enclosingElement, accuracy, nameSourceStart, length);
1358
				SearchMatch match = this.patternLocator.newDeclarationMatch(method, enclosingElement, accuracy, length, this);
1346
				report(match);
1359
				report(match);
1347
			}
1360
			}
1348
		}
1361
		}
Lines 1534-1540 Link Here
1534
	// report the type declaration
1547
	// report the type declaration
1535
	if (accuracy > -1 && encloses(enclosingElement)) {
1548
	if (accuracy > -1 && encloses(enclosingElement)) {
1536
		int offset = type.sourceStart;
1549
		int offset = type.sourceStart;
1537
		SearchMatch match = newDeclarationMatch(enclosingElement, accuracy, offset, type.sourceEnd-offset+1);
1550
//		SearchMatch match = newDeclarationMatch(enclosingElement, accuracy, offset, type.sourceEnd-offset+1);
1551
		SearchMatch match = this.patternLocator.newDeclarationMatch(type, enclosingElement, accuracy, type.sourceEnd-offset+1, this);
1538
		report(match);
1552
		report(match);
1539
	}
1553
	}
1540
1554
(-)search/org/eclipse/jdt/internal/core/search/matching/OrLocator.java (+18 lines)
Lines 193-198 Link Here
193
	if (closestPattern != null)
193
	if (closestPattern != null)
194
		closestPattern.matchReportReference(reference, element, accuracy, locator);
194
		closestPattern.matchReportReference(reference, element, accuracy, locator);
195
}
195
}
196
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, int accuracy, int length, MatchLocator locator) {
197
	PatternLocator closestPattern = null;
198
	int level = IMPOSSIBLE_MATCH;
199
	for (int i = 0, pl = this.patternLocators.length; i < pl; i++) {
200
		PatternLocator patternLocator = this.patternLocators[i];
201
		int newLevel = patternLocator.referenceType() == 0 ? IMPOSSIBLE_MATCH : patternLocator.resolveLevel(reference);
202
		if (newLevel > level) {
203
			closestPattern = patternLocator;
204
			if (newLevel == ACCURATE_MATCH) break;
205
			level = newLevel;
206
		}
207
	}
208
	if (closestPattern != null) {
209
	    return closestPattern.newDeclarationMatch(reference, element, accuracy, length, locator);
210
	}
211
	// super implementation...
212
    return locator.newDeclarationMatch(element, accuracy, reference.sourceStart, length);
213
}
196
public int resolveLevel(ASTNode node) {
214
public int resolveLevel(ASTNode node) {
197
	int level = IMPOSSIBLE_MATCH;
215
	int level = IMPOSSIBLE_MATCH;
198
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
216
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
(-)search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java (+3 lines)
Lines 251-256 Link Here
251
		locator.report(match);
251
		locator.report(match);
252
	}
252
	}
253
}
253
}
254
public SearchMatch newDeclarationMatch(ASTNode reference, IJavaElement element, int accuracy, int length, MatchLocator locator) {
255
    return locator.newDeclarationMatch(element, accuracy, reference.sourceStart, length);
256
}
254
protected int referenceType() {
257
protected int referenceType() {
255
	return 0; // defaults to unknown (a generic JavaSearchMatch will be created)
258
	return 0; // defaults to unknown (a generic JavaSearchMatch will be created)
256
}
259
}
(-)search/org/eclipse/jdt/core/search/ConstructorReferenceMatch.java (+59 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-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.IJavaElement;
15
16
/**
17
 * A Java search match that represents a constructor reference.
18
 * The element is the inner-most enclosing member that references this method.
19
 * <p>
20
 * This class is intended to be instantiated and subclassed by clients.
21
 * </p>
22
 * 
23
 * @since 3.1
24
 */
25
public class ConstructorReferenceMatch extends SearchMatch {
26
	
27
	private boolean synthetic;
28
29
	/**
30
	 * Creates a new method reference match.
31
	 * 
32
	 * @param enclosingElement the inner-most enclosing member that references this method
33
	 * @param accuracy one of {@link #A_ACCURATE} or {@link #A_INACCURATE}
34
	 * @param offset the offset the match starts at, or -1 if unknown
35
	 * @param length the length of the match, or -1 if unknown
36
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
37
	 * comment, and <code>false</code> otherwise
38
	 * @param synthetic <code>true</code> if this search match is a synthetic constructor
39
	 * <code>false</code> otherwise
40
	 * @param participant the search participant that created the match
41
	 * @param resource the resource of the element
42
	 */
43
	public ConstructorReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean insideDocComment, boolean synthetic, SearchParticipant participant, IResource resource) {
44
		super(enclosingElement, accuracy, offset, length, participant, resource);
45
		setInsideDocComment(insideDocComment);
46
		this.synthetic = synthetic;
47
	}
48
	
49
	/**
50
	 * Returns whether the constructor reference is synthetic or not.
51
	 * Note that a constructor reference can be synthetic when default constructor declaration is used
52
	 * or imlicit super constructor is called.
53
	 * 
54
	 * @return whether the constructor reference is synthetic or not.
55
	 */
56
	public final boolean isSynthetic() {
57
		return this.synthetic;
58
	}
59
}

Return to bug 43587