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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/index/DiskIndex.java (-1 / +1 lines)
Lines 35-41 Link Here
35
private HashtableOfObject categoryTables; // category name -> HashtableOfObject(words -> int[] of document #'s) or offset if not read yet
35
private HashtableOfObject categoryTables; // category name -> HashtableOfObject(words -> int[] of document #'s) or offset if not read yet
36
private char[] cachedCategoryName;
36
private char[] cachedCategoryName;
37
37
38
public static final String SIGNATURE= "INDEX VERSION 1.106"; //$NON-NLS-1$
38
public static final String SIGNATURE= "INDEX VERSION 1.107"; //$NON-NLS-1$
39
public static boolean DEBUG = false;
39
public static boolean DEBUG = false;
40
40
41
private static final int RE_INDEXED = -1;
41
private static final int RE_INDEXED = -1;
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-1 / +33 lines)
Lines 1109-1114 Link Here
1109
		// remove the position of the '@' token as we don't have modifiers
1109
		// remove the position of the '@' token as we don't have modifiers
1110
		annotationTypeDeclaration.declarationSourceStart = atPosition;
1110
		annotationTypeDeclaration.declarationSourceStart = atPosition;
1111
	}
1111
	}
1112
1113
	// Store secondary info
1114
	if ((annotationTypeDeclaration.bits & ASTNode.IsMemberType) == 0 && (annotationTypeDeclaration.bits & ASTNode.IsLocalType) == 0) {
1115
		if (this.compilationUnit != null && !CharOperation.equals(annotationTypeDeclaration.name, this.compilationUnit.getMainTypeName())) {
1116
			annotationTypeDeclaration.bits |= ASTNode.IsSecondaryType;
1117
		}
1118
	}
1119
1112
	// consume annotations
1120
	// consume annotations
1113
	int length;
1121
	int length;
1114
	if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
1122
	if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
Lines 1873-1878 Link Here
1873
	if (typeDecl.modifiersSourceStart >= 0) {
1881
	if (typeDecl.modifiersSourceStart >= 0) {
1874
		typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
1882
		typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
1875
	}
1883
	}
1884
1885
	// Store secondary info
1886
	if ((typeDecl.bits & ASTNode.IsMemberType) == 0 && (typeDecl.bits & ASTNode.IsLocalType) == 0) {
1887
		if (this.compilationUnit != null && !CharOperation.equals(typeDecl.name, this.compilationUnit.getMainTypeName())) {
1888
			typeDecl.bits |= ASTNode.IsSecondaryType;
1889
		}
1890
	}
1891
1876
	// consume annotations
1892
	// consume annotations
1877
	int length;
1893
	int length;
1878
	if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
1894
	if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
Lines 2745-2751 Link Here
2745
   enumConstant.modifiersSourceStart = this.intStack[this.intPtr--];
2761
   enumConstant.modifiersSourceStart = this.intStack[this.intPtr--];
2746
   enumConstant.modifiers = this.intStack[this.intPtr--];
2762
   enumConstant.modifiers = this.intStack[this.intPtr--];
2747
   enumConstant.declarationSourceStart = enumConstant.modifiersSourceStart;
2763
   enumConstant.declarationSourceStart = enumConstant.modifiersSourceStart;
2748
   // consume annotations
2764
2765
	// Store secondary info
2766
	if ((enumConstant.bits & ASTNode.IsMemberType) == 0 && (enumConstant.bits & ASTNode.IsLocalType) == 0) {
2767
		if (this.compilationUnit != null && !CharOperation.equals(enumConstant.name, this.compilationUnit.getMainTypeName())) {
2768
			enumConstant.bits |= ASTNode.IsSecondaryType;
2769
		}
2770
	}
2771
2772
	// consume annotations
2749
   int length;
2773
   int length;
2750
   if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2774
   if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
2751
      System.arraycopy(
2775
      System.arraycopy(
Lines 3456-3461 Link Here
3456
	if (typeDecl.modifiersSourceStart >= 0) {
3480
	if (typeDecl.modifiersSourceStart >= 0) {
3457
		typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
3481
		typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
3458
	}
3482
	}
3483
3484
	// Store secondary info
3485
	if ((typeDecl.bits & ASTNode.IsMemberType) == 0 && (typeDecl.bits & ASTNode.IsLocalType) == 0) {
3486
		if (this.compilationUnit != null && !CharOperation.equals(typeDecl.name, this.compilationUnit.getMainTypeName())) {
3487
			typeDecl.bits |= ASTNode.IsSecondaryType;
3488
		}
3489
	}
3490
3459
	// consume annotations
3491
	// consume annotations
3460
	int length;
3492
	int length;
3461
	if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
3493
	if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
(-)search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java (-4 / +4 lines)
Lines 137-143 Link Here
137
	} else {
137
	} else {
138
		typeNames = this.enclosingTypeNames();
138
		typeNames = this.enclosingTypeNames();
139
	}
139
	}
140
	this.indexer.addAnnotationTypeDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames);
140
	this.indexer.addAnnotationTypeDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.secondary);
141
	this.pushTypeName(typeInfo.name);	
141
	this.pushTypeName(typeInfo.name);	
142
}
142
}
143
143
Lines 170-176 Link Here
170
			typeParameterSignatures[i] = Signature.createTypeParameterSignature(typeParameterInfo.name, typeParameterInfo.bounds == null ? CharOperation.NO_CHAR_CHAR : typeParameterInfo.bounds);
170
			typeParameterSignatures[i] = Signature.createTypeParameterSignature(typeParameterInfo.name, typeParameterInfo.bounds == null ? CharOperation.NO_CHAR_CHAR : typeParameterInfo.bounds);
171
		}
171
		}
172
	}
172
	}
173
	this.indexer.addClassDeclaration(typeInfo.modifiers, this.packageName, typeInfo.name, typeNames, typeInfo.superclass, typeInfo.superinterfaces, typeParameterSignatures);
173
	this.indexer.addClassDeclaration(typeInfo.modifiers, this.packageName, typeInfo.name, typeNames, typeInfo.superclass, typeInfo.superinterfaces, typeParameterSignatures, typeInfo.secondary);
174
	this.pushTypeName(typeInfo.name);
174
	this.pushTypeName(typeInfo.name);
175
}
175
}
176
/**
176
/**
Lines 199-205 Link Here
199
	} else {
199
	} else {
200
		typeNames = this.enclosingTypeNames();
200
		typeNames = this.enclosingTypeNames();
201
	}
201
	}
202
	this.indexer.addEnumDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces);
202
	this.indexer.addEnumDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces, typeInfo.secondary);
203
	this.pushTypeName(typeInfo.name);	
203
	this.pushTypeName(typeInfo.name);	
204
}
204
}
205
/**
205
/**
Lines 237-243 Link Here
237
			typeParameterSignatures[i] = Signature.createTypeParameterSignature(typeParameterInfo.name, typeParameterInfo.bounds);
237
			typeParameterSignatures[i] = Signature.createTypeParameterSignature(typeParameterInfo.name, typeParameterInfo.bounds);
238
		}
238
		}
239
	}
239
	}
240
	this.indexer.addInterfaceDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces, typeParameterSignatures);
240
	this.indexer.addInterfaceDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces, typeParameterSignatures, typeInfo.secondary);
241
	this.pushTypeName(typeInfo.name);	
241
	this.pushTypeName(typeInfo.name);	
242
}
242
}
243
/**
243
/**
(-)search/org/eclipse/jdt/internal/core/search/indexing/IIndexConstants.java (+1 lines)
Lines 36-41 Link Here
36
	char CLASS_AND_ENUM_SUFFIX = IJavaSearchConstants.CLASS_AND_ENUM;
36
	char CLASS_AND_ENUM_SUFFIX = IJavaSearchConstants.CLASS_AND_ENUM;
37
	char CLASS_AND_INTERFACE_SUFFIX = IJavaSearchConstants.CLASS_AND_INTERFACE;
37
	char CLASS_AND_INTERFACE_SUFFIX = IJavaSearchConstants.CLASS_AND_INTERFACE;
38
	char SEPARATOR= '/';
38
	char SEPARATOR= '/';
39
	char SECONDARY_SUFFIX = 'S';
39
40
40
	char[] ONE_STAR = new char[] {'*'};
41
	char[] ONE_STAR = new char[] {'*'};
41
	char[][] ONE_STAR_CHAR = new char[][] {ONE_STAR};
42
	char[][] ONE_STAR_CHAR = new char[][] {ONE_STAR};
(-)search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java (-2 / +4 lines)
Lines 59-70 Link Here
59
			requestor, 
59
			requestor, 
60
			this.problemFactory, 
60
			this.problemFactory, 
61
			new CompilerOptions(options), 
61
			new CompilerOptions(options), 
62
			true/*index local declarations*/,
62
			true, // index local declarations
63
			true/*optimize string literals*/);
63
			true, // optimize string literals
64
			false); // do not use source javadoc parser to speed up parsing
64
		parser.reportOnlyOneSyntaxError = true;
65
		parser.reportOnlyOneSyntaxError = true;
65
	
66
	
66
		// Always check javadoc while indexing
67
		// Always check javadoc while indexing
67
		parser.javadocParser.checkDocComment = true;
68
		parser.javadocParser.checkDocComment = true;
69
		parser.javadocParser.reportProblems = false;
68
		
70
		
69
		// Launch the parser
71
		// Launch the parser
70
		char[] source = null;
72
		char[] source = null;
(-)search/org/eclipse/jdt/internal/core/search/indexing/InternalSearchDocument.java (-1 / +11 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core.search.indexing;
11
package org.eclipse.jdt.internal.core.search.indexing;
12
12
13
import org.eclipse.jdt.internal.core.JavaModelManager;
13
import org.eclipse.jdt.internal.core.index.Index;
14
import org.eclipse.jdt.internal.core.index.Index;
14
15
15
/**
16
/**
Lines 22-29 Link Here
22
	 * Hidden by API SearchDocument subclass
23
	 * Hidden by API SearchDocument subclass
23
	 */
24
	 */
24
	public void addIndexEntry(char[] category, char[] key) {
25
	public void addIndexEntry(char[] category, char[] key) {
25
		if (this.index != null)
26
		if (this.index != null) {
26
			index.addIndexEntry(category, key, getContainerRelativePath());
27
			index.addIndexEntry(category, key, getContainerRelativePath());
28
			if (category == IIndexConstants.TYPE_DECL && key != null) {
29
				int length = key.length;
30
				if (length > 1 && key[length-2] == IIndexConstants.SEPARATOR && key[length-1] == IIndexConstants.SECONDARY_SUFFIX ) {
31
					// This is a key of a secondary type => reset java model manager secondary types cache for document path project
32
					JavaModelManager manager = JavaModelManager.getJavaModelManager();
33
					manager.resetSecondaryTypesCache(getPath());
34
				}
35
			}
36
		}
27
	}
37
	}
28
	private String getContainerRelativePath() {
38
	private String getContainerRelativePath() {
29
		if (this.containerRelativePath == null)
39
		if (this.containerRelativePath == null)
(-)search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java (-9 / +14 lines)
Lines 23-30 Link Here
23
	public AbstractIndexer(SearchDocument document) {
23
	public AbstractIndexer(SearchDocument document) {
24
		this.document = document;
24
		this.document = document;
25
	}
25
	}
26
	public void addAnnotationTypeDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames) {
26
	public void addAnnotationTypeDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, boolean secondary) {
27
		addIndexEntry(TYPE_DECL, TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames));
27
		char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
28
		addIndexEntry(TYPE_DECL, indexKey);
28
		
29
		
29
		addIndexEntry(
30
		addIndexEntry(
30
			SUPER_REF, 
31
			SUPER_REF, 
Lines 38-45 Link Here
38
			char[][] enclosingTypeNames, 
39
			char[][] enclosingTypeNames, 
39
			char[] superclass, 
40
			char[] superclass, 
40
			char[][] superinterfaces,
41
			char[][] superinterfaces,
41
			char[][] typeParameterSignatures) {
42
			char[][] typeParameterSignatures,
42
		addIndexEntry(TYPE_DECL, TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames));
43
			boolean secondary) {
44
		char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
45
		addIndexEntry(TYPE_DECL, indexKey);
43
46
44
		if (superclass != null) {
47
		if (superclass != null) {
45
			superclass = erasure(superclass);
48
			superclass = erasure(superclass);
Lines 84-92 Link Here
84
		if (innermostTypeName != simpleTypeName)
87
		if (innermostTypeName != simpleTypeName)
85
			addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern.createIndexKey(innermostTypeName, argCount));
88
			addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern.createIndexKey(innermostTypeName, argCount));
86
	}
89
	}
87
	public void addEnumDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces) {
90
	public void addEnumDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces, boolean secondary) {
88
		addIndexEntry(TYPE_DECL, TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames));
91
		char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
89
		
92
		addIndexEntry(TYPE_DECL, indexKey);
93
90
		addIndexEntry(
94
		addIndexEntry(
91
			SUPER_REF, 
95
			SUPER_REF, 
92
			SuperTypeReferencePattern.createIndexKey(
96
			SuperTypeReferencePattern.createIndexKey(
Lines 112-119 Link Here
112
	protected void addIndexEntry(char[] category, char[] key) {
116
	protected void addIndexEntry(char[] category, char[] key) {
113
		this.document.addIndexEntry(category, key);
117
		this.document.addIndexEntry(category, key);
114
	}
118
	}
115
	public void addInterfaceDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces, char[][] typeParameterSignatures) {
119
	public void addInterfaceDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces, char[][] typeParameterSignatures, boolean secondary) {
116
		addIndexEntry(TYPE_DECL, TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames));
120
		char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
121
		addIndexEntry(TYPE_DECL, indexKey);
117
122
118
		if (superinterfaces != null) {
123
		if (superinterfaces != null) {
119
			for (int i = 0, max = superinterfaces.length; i < max; i++) {
124
			for (int i = 0, max = superinterfaces.length; i < max; i++) {
(-)search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java (-4 / +4 lines)
Lines 496-511 Link Here
496
			switch (TypeDeclaration.kind(modifiers)) {
496
			switch (TypeDeclaration.kind(modifiers)) {
497
				case TypeDeclaration.CLASS_DECL :
497
				case TypeDeclaration.CLASS_DECL :
498
					char[] superclass = replace('/', '.', reader.getSuperclassName());
498
					char[] superclass = replace('/', '.', reader.getSuperclassName());
499
					addClassDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, typeParameterSignatures);
499
					addClassDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, typeParameterSignatures, false);
500
					break;
500
					break;
501
				case TypeDeclaration.INTERFACE_DECL :
501
				case TypeDeclaration.INTERFACE_DECL :
502
					addInterfaceDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, typeParameterSignatures);
502
					addInterfaceDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, typeParameterSignatures, false);
503
					break;
503
					break;
504
				case TypeDeclaration.ENUM_DECL :
504
				case TypeDeclaration.ENUM_DECL :
505
					addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces);
505
					addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, false);
506
					break;
506
					break;
507
				case TypeDeclaration.ANNOTATION_TYPE_DECL :
507
				case TypeDeclaration.ANNOTATION_TYPE_DECL :
508
					addAnnotationTypeDeclaration(modifiers, packageName, name, enclosingTypeNames);
508
					addAnnotationTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, false);
509
					break;
509
					break;
510
			}			
510
			}			
511
	
511
	
(-)model/org/eclipse/jdt/core/IJavaProject.java (-20 / +4 lines)
Lines 185-195 Link Here
185
	 * a class B defined as a member type of a class A in package x.y should have a 
185
	 * a class B defined as a member type of a class A in package x.y should have a 
186
	 * the fully qualified name "x.y.A.B".
186
	 * the fully qualified name "x.y.A.B".
187
	 * 
187
	 * 
188
	 * Note that in order to be found, a type name (or its toplevel enclosing
188
	 * Secondary types are found since 3.2 version.
189
	 * type name) must match its corresponding compilation unit name. As a 
190
	 * consequence, secondary types cannot be found using this functionality.
191
	 * Secondary types can however be explicitely accessed through their enclosing
192
	 * unit or found by the <code>SearchEngine</code>.
193
	 * 
189
	 * 
194
	 * @param fullyQualifiedName the given fully qualified name
190
	 * @param fullyQualifiedName the given fully qualified name
195
	 * @exception JavaModelException if this project does not exist or if an
191
	 * @exception JavaModelException if this project does not exist or if an
Lines 209-219 Link Here
209
	 * If the returned type is part of a compilation unit, its owner is the given
205
	 * If the returned type is part of a compilation unit, its owner is the given
210
	 * owner.
206
	 * owner.
211
	 * 
207
	 * 
212
	 * Note that in order to be found, a type name (or its toplevel enclosing
208
	 * Secondary types are found since 3.2 version.
213
	 * type name) must match its corresponding compilation unit name. As a 
214
	 * consequence, secondary types cannot be found using this functionality.
215
	 * Secondary types can however be explicitely accessed through their enclosing
216
	 * unit or found by the <code>SearchEngine</code>.
217
	 * 
209
	 * 
218
	 * @param fullyQualifiedName the given fully qualified name
210
	 * @param fullyQualifiedName the given fully qualified name
219
	 * @param owner the owner of the returned type's compilation unit
211
	 * @param owner the owner of the returned type's compilation unit
Lines 234-244 Link Here
234
	 * a class B defined as a member type of a class A should have the 
226
	 * a class B defined as a member type of a class A should have the 
235
	 * type qualified name "A.B".
227
	 * type qualified name "A.B".
236
	 * 
228
	 * 
237
	 * Note that in order to be found, a type name (or its toplevel enclosing
229
	 * Secondary types are found since 3.2 version.
238
	 * type name) must match its corresponding compilation unit name. As a 
239
	 * consequence, secondary types cannot be found using this functionality.
240
	 * Secondary types can however be explicitely accessed through their enclosing
241
	 * unit or found by the <code>SearchEngine</code>.
242
	 * 
230
	 * 
243
	 * @param packageName the given package name
231
	 * @param packageName the given package name
244
	 * @param typeQualifiedName the given type qualified name
232
	 * @param typeQualifiedName the given type qualified name
Lines 262-272 Link Here
262
	 * If the returned type is part of a compilation unit, its owner is the given
250
	 * If the returned type is part of a compilation unit, its owner is the given
263
	 * owner.
251
	 * owner.
264
	 * 
252
	 * 
265
	 * Note that in order to be found, a type name (or its toplevel enclosing
253
	 * Secondary types are found since 3.2 version.
266
	 * type name) must match its corresponding compilation unit name. As a 
267
	 * consequence, secondary types cannot be found using this functionality.
268
	 * Secondary types can however be explicitely accessed through their enclosing
269
	 * unit or found by the <code>SearchEngine</code>.
270
	 * 
254
	 * 
271
	 * @param packageName the given package name
255
	 * @param packageName the given package name
272
	 * @param typeQualifiedName the given type qualified name
256
	 * @param typeQualifiedName the given type qualified name
(-)model/org/eclipse/jdt/internal/core/NameLookup.java (-90 / +117 lines)
Lines 15-36 Link Here
15
15
16
import org.eclipse.core.resources.*;
16
import org.eclipse.core.resources.*;
17
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.Path;
19
import org.eclipse.core.runtime.OperationCanceledException;
20
import org.eclipse.jdt.core.IClassFile;
18
import org.eclipse.jdt.core.IClassFile;
21
import org.eclipse.jdt.core.IClasspathEntry;
19
import org.eclipse.jdt.core.IClasspathEntry;
22
import org.eclipse.jdt.core.ICompilationUnit;
20
import org.eclipse.jdt.core.ICompilationUnit;
23
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.IPackageFragment;
23
import org.eclipse.jdt.core.IPackageFragment;
25
import org.eclipse.jdt.core.IPackageFragmentRoot;
24
import org.eclipse.jdt.core.IPackageFragmentRoot;
26
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.IType;
27
import org.eclipse.jdt.core.JavaCore;
26
import org.eclipse.jdt.core.JavaCore;
28
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.core.JavaModelException;
29
import org.eclipse.jdt.core.compiler.CharOperation;
28
import org.eclipse.jdt.core.compiler.CharOperation;
30
import org.eclipse.jdt.core.search.*;
31
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
29
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
32
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
30
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
33
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
34
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
31
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
35
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
32
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
36
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
33
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
Lines 114-129 Link Here
114
	 */
111
	 */
115
	protected HashMap typesInWorkingCopies;
112
	protected HashMap typesInWorkingCopies;
116
	
113
	
114
//	/**
115
//	 * Flag to prevent secondary types search
116
//	 */
117
//	public boolean findSecondaryTypes = true;
118
117
	public long timeSpentInSeekTypesInSourcePackage = 0;
119
	public long timeSpentInSeekTypesInSourcePackage = 0;
118
	public long timeSpentInSeekTypesInBinaryPackage = 0;
120
	public long timeSpentInSeekTypesInBinaryPackage = 0;
119
121
120
	public NameLookup(IPackageFragmentRoot[] packageFragmentRoots, HashtableOfArrayToObject packageFragments, ICompilationUnit[] workingCopies, Map rootToResolvedEntries) {
122
	public NameLookup(IPackageFragmentRoot[] packageFragmentRoots, HashtableOfArrayToObject packageFragments, ICompilationUnit[] workingCopies, Map rootToResolvedEntries) {
121
		long start = -1;
123
		long start = -1;
122
		if (VERBOSE) {
124
		if (VERBOSE) {
123
			System.out.println(Thread.currentThread() + " BUILDING NameLoopkup");  //$NON-NLS-1$
125
			Util.verbose(" BUILDING NameLoopkup");  //$NON-NLS-1$
124
			System.out.println(Thread.currentThread() + " -> pkg roots size: " + (packageFragmentRoots == null ? 0 : packageFragmentRoots.length));  //$NON-NLS-1$
126
			Util.verbose(" -> pkg roots size: " + (packageFragmentRoots == null ? 0 : packageFragmentRoots.length));  //$NON-NLS-1$
125
			System.out.println(Thread.currentThread() + " -> pkgs size: " + (packageFragments == null ? 0 : packageFragments.size()));  //$NON-NLS-1$
127
			Util.verbose(" -> pkgs size: " + (packageFragments == null ? 0 : packageFragments.size()));  //$NON-NLS-1$
126
			System.out.println(Thread.currentThread() + " -> working copy size: " + (workingCopies == null ? 0 : workingCopies.length));  //$NON-NLS-1$
128
			Util.verbose(" -> working copy size: " + (workingCopies == null ? 0 : workingCopies.length));  //$NON-NLS-1$
127
			start = System.currentTimeMillis();
129
			start = System.currentTimeMillis();
128
		}
130
		}
129
		this.packageFragmentRoots = packageFragmentRoots;
131
		this.packageFragmentRoots = packageFragmentRoots;
Lines 201-207 Link Here
201
		}
203
		}
202
		this.rootToResolvedEntries = rootToResolvedEntries;
204
		this.rootToResolvedEntries = rootToResolvedEntries;
203
        if (VERBOSE) {
205
        if (VERBOSE) {
204
            System.out.println(Thread.currentThread() + " -> spent: " + (start - System.currentTimeMillis()) + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
206
            Util.verbose(" -> spent: " + (start - System.currentTimeMillis()) + "ms");  //$NON-NLS-1$ //$NON-NLS-2$
205
        }
207
        }
206
	}
208
	}
207
209
Lines 483-488 Link Here
483
		return null;
485
		return null;
484
	}
486
	}
485
487
488
	/*
489
	 * Find secondary type for a source folders.
490
	 */
491
	private IType findSecondaryType(String packageName, String typeName, IJavaProject project) { //IJavaProject[] projects) {
492
//		int length = projects.length;
493
		if (VERBOSE) {
494
			Util.verbose("NameLookup FIND SECONDARY TYPES:"); //$NON-NLS-1$
495
			Util.verbose(" -> pkg name: " + packageName);  //$NON-NLS-1$
496
			Util.verbose(" -> type name: " + typeName);  //$NON-NLS-1$
497
//			StringBuffer buffer = new StringBuffer(" -> projects: "); //$NON-NLS-1$
498
//			for (int i=0; i<length; i++) {
499
//				if (i==0) {
500
//					buffer.append('[');
501
//				} else {
502
//					buffer.append(',');
503
//				}
504
//				buffer.append(projects[i].getElementName());
505
//			}
506
//			buffer.append(']');
507
//			Util.verbose(buffer.toString());
508
			Util.verbose(" -> projects: "+project.getElementName()); //$NON-NLS-1$
509
		}
510
//		for (int i=0; i<length; i++) {
511
//			IType type = ((JavaProject)projects[i]).findSecondaryType(packageName, typeName);
512
//			if (type != null) {
513
//				return type;
514
//			}
515
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
516
			try {
517
				IJavaProject javaProject = project; // projects[i];
518
				HashMap secondaryTypePaths = manager.getSecondaryTypes(javaProject);
519
				if (secondaryTypePaths.size() > 0) {
520
//					String searchedName = packageName.length()==0 ? typeName : packageName + '.' + typeName;
521
//					Object cachedType = secondaryTypePaths.get(searchedName);
522
					HashMap types = (HashMap) secondaryTypePaths.get(packageName==null?"":packageName); //$NON-NLS-1$
523
					if (types != null && types.size() > 0) {
524
//						Object cachedType = types.get(typeName);
525
						IType type = (IType) types.get(typeName);
526
						if (type != null) return type;
527
//						if (cachedType instanceof IType) return (IType) cachedType; // we already found this secondary type and stored it in cache
528
//						String pathName = (String) cachedType;
529
//						if (JavaModelManager.VERBOSE) {
530
//							Util.verbose(" -> path name: " + pathName);  //$NON-NLS-1$
531
//						}
532
//						if (pathName != null && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(pathName)) {
533
//							IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(pathName));
534
//							ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null);
535
//							IType type = unit.getType(typeName);
536
//							if (JavaModelManager.VERBOSE) {
537
//								Util.verbose(" -> type: " + type.getElementName());  //$NON-NLS-1$
538
//							}
539
//							types.put(typeName, type); // replace stored path with type itself
540
//							return type;
541
//						}
542
					}
543
				}
544
			}
545
			catch (JavaModelException jme) {
546
				// give up
547
			}
548
//		}
549
		return null;
550
	}
551
486
	/**
552
	/**
487
	 * 
553
	 * 
488
	 */
554
	 */
Lines 493-516 Link Here
493
			// see if this is a known package and not a type
559
			// see if this is a known package and not a type
494
			if (findPackageFragments(packageName + "." + typeName, false) != null) return null; //$NON-NLS-1$
560
			if (findPackageFragments(packageName + "." + typeName, false) != null) return null; //$NON-NLS-1$
495
		}
561
		}
562
		
563
		// Look for concerned package fragments
496
		JavaElementRequestor elementRequestor = new JavaElementRequestor();
564
		JavaElementRequestor elementRequestor = new JavaElementRequestor();
497
		seekPackageFragments(packageName, false, elementRequestor);
565
		seekPackageFragments(packageName, false, elementRequestor);
498
		IPackageFragment[] packages= elementRequestor.getPackageFragments();
566
		IPackageFragment[] packages= elementRequestor.getPackageFragments();
499
567
500
		for (int i= 0, length= packages.length; i < length; i++) {
568
		// Try to find type in package fragments list
501
			IType type= findType(typeName, packages[i], partialMatch, acceptFlags);
569
		IType type = null;
502
			if (type != null)
570
		int length= packages.length;
571
//		Set projectsSet = this.findSecondaryTypes ? new HashSet() : null;
572
		IJavaProject project = null;
573
		for (int i= 0; i < length; i++) {
574
			type = findType(typeName, packages[i], partialMatch, acceptFlags);
575
			if (type != null) {
503
				return type;
576
				return type;
577
			}
578
			if (/*this.findSecondaryTypes &&*/ project == null) {
579
//				projectsSet.add(packages[i].getJavaProject());
580
				project = packages[i].getJavaProject();
581
			}
504
		}
582
		}
505
		return null;
583
506
	}
584
		// If type was not found, try to find it as secondary in source folders
507
	
585
		if (/*this.findSecondaryTypes && */project != null) {
508
	private IType getMemberType(IType type, String name, int dot) {
586
//			int size = projectsSet.size();
509
		while (dot != -1) {
587
//			if (size > 0) {
510
			int start = dot+1;
588
//				IJavaProject[] projects = new IJavaProject[size];
511
			dot = name.indexOf('.', start);
589
//				projectsSet.toArray(projects);
512
			String typeName = name.substring(start, dot == -1 ? name.length() : dot);
590
				type = findSecondaryType(packageName, typeName, project); //projects);
513
			type = type.getType(typeName);
591
//			}
514
		}
592
		}
515
		return type;
593
		return type;
516
	}
594
	}
Lines 540-607 Link Here
540
		// Return first found (ignore duplicates).
618
		// Return first found (ignore duplicates).
541
		SingleTypeRequestor typeRequestor = new SingleTypeRequestor();
619
		SingleTypeRequestor typeRequestor = new SingleTypeRequestor();
542
		seekTypes(name, pkg, partialMatch, acceptFlags, typeRequestor);
620
		seekTypes(name, pkg, partialMatch, acceptFlags, typeRequestor);
543
		IType type = typeRequestor.getType();
621
		return typeRequestor.getType();
544
//		if (type == null)
545
//			type = findSecondaryType(name, pkg, partialMatch, acceptFlags);
546
		return type;
547
	}
548
549
	// TODO (kent) enable once index support is in
550
	IType findSecondaryType(String typeName, IPackageFragment pkg, boolean partialMatch, final int acceptFlags) {
551
		try {
552
			final ArrayList paths = new ArrayList();
553
			TypeNameRequestor nameRequestor = new TypeNameRequestor() {
554
				public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
555
					if (enclosingTypeNames == null || enclosingTypeNames.length == 0) { // accept only top level types
556
						int kind = modifiers & (ClassFileConstants.AccInterface|ClassFileConstants.AccEnum|ClassFileConstants.AccAnnotation);
557
						switch (kind) {
558
							case ClassFileConstants.AccAnnotation:
559
							case ClassFileConstants.AccAnnotation|ClassFileConstants.AccInterface:
560
								if ((acceptFlags & ACCEPT_ANNOTATIONS) != 0) paths.add(path);
561
								break;
562
							case ClassFileConstants.AccEnum:
563
								if ((acceptFlags & ACCEPT_ENUMS) != 0) paths.add(path);
564
								break;
565
							case ClassFileConstants.AccInterface:
566
								if ((acceptFlags & ACCEPT_INTERFACES) != 0) paths.add(path);
567
								break;
568
							default:
569
								if ((acceptFlags & ACCEPT_CLASSES) != 0) paths.add(path);
570
								break;
571
						}
572
					}
573
				}
574
			};
575
576
			int matchMode = partialMatch ? SearchPattern.R_PREFIX_MATCH : SearchPattern.R_EXACT_MATCH;
577
			int matchRule = !partialMatch ? matchMode | SearchPattern.R_CASE_SENSITIVE : matchMode;
578
			new SearchEngine().searchAllTypeNames(
579
				pkg.getElementName().toCharArray(),
580
				typeName.toCharArray(),
581
				matchRule,
582
				IJavaSearchConstants.TYPE,
583
				SearchEngine.createJavaSearchScope(new IJavaElement[] {pkg}, false),
584
				nameRequestor,
585
				IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH,
586
				null);
587
588
			if (!paths.isEmpty()) {
589
				IWorkspace workspace = ResourcesPlugin.getWorkspace();
590
				for (int i = 0, l = paths.size(); i < l; i++) {
591
					String pathname = (String) paths.get(i);
592
					if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(pathname)) {
593
						IFile file = workspace.getRoot().getFile(new Path(pathname));
594
						ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
595
						return unit.getType(typeName);
596
					}
597
				}
598
			}
599
		} catch (JavaModelException e) {
600
			// ignore
601
		} catch (OperationCanceledException ignore) {
602
			// ignore
603
		}
604
		return null;
605
	}
622
	}
606
623
607
	/**
624
	/**
Lines 633-638 Link Here
633
		return findType(className, packageName, partialMatch, acceptFlags);
650
		return findType(className, packageName, partialMatch, acceptFlags);
634
	}
651
	}
635
652
653
	private IType getMemberType(IType type, String name, int dot) {
654
		while (dot != -1) {
655
			int start = dot+1;
656
			dot = name.indexOf('.', start);
657
			String typeName = name.substring(start, dot == -1 ? name.length() : dot);
658
			type = type.getType(typeName);
659
		}
660
		return type;
661
	}
662
636
	/**
663
	/**
637
	 * Returns true if the given element's name matches the
664
	 * Returns true if the given element's name matches the
638
	 * specified <code>searchName</code>, otherwise false.
665
	 * specified <code>searchName</code>, otherwise false.
Lines 681-689 Link Here
681
	 */
708
	 */
682
	public void seekPackageFragments(String name, boolean partialMatch, IJavaElementRequestor requestor) {
709
	public void seekPackageFragments(String name, boolean partialMatch, IJavaElementRequestor requestor) {
683
/*		if (VERBOSE) {
710
/*		if (VERBOSE) {
684
			System.out.println(Thread.currentThread() + " SEEKING PACKAGE FRAGMENTS");  //$NON-NLS-1$
711
			Util.verbose(" SEEKING PACKAGE FRAGMENTS");  //$NON-NLS-1$
685
			System.out.println(Thread.currentThread() + " -> name: " + name);  //$NON-NLS-1$
712
			Util.verbose(" -> name: " + name);  //$NON-NLS-1$
686
			System.out.println(Thread.currentThread() + " -> partial match:" + partialMatch);  //$NON-NLS-1$
713
			Util.verbose(" -> partial match:" + partialMatch);  //$NON-NLS-1$
687
		}
714
		}
688
*/		if (partialMatch) {
715
*/		if (partialMatch) {
689
			String[] splittedName = Util.splitOn('.', name, 0, name.length());
716
			String[] splittedName = Util.splitOn('.', name, 0, name.length());
Lines 749-758 Link Here
749
	 */
776
	 */
750
	public void seekTypes(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor) {
777
	public void seekTypes(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor) {
751
/*		if (VERBOSE) {
778
/*		if (VERBOSE) {
752
			System.out.println(Thread.currentThread() + " SEEKING TYPES");  //$NON-NLS-1$
779
			Util.verbose(" SEEKING TYPES");  //$NON-NLS-1$
753
			System.out.println(Thread.currentThread() + " -> name: " + name);  //$NON-NLS-1$
780
			Util.verbose(" -> name: " + name);  //$NON-NLS-1$
754
			System.out.println(Thread.currentThread() + " -> pkg: " + ((JavaElement) pkg).toStringWithAncestors());  //$NON-NLS-1$
781
			Util.verbose(" -> pkg: " + ((JavaElement) pkg).toStringWithAncestors());  //$NON-NLS-1$
755
			System.out.println(Thread.currentThread() + " -> partial match:" + partialMatch);  //$NON-NLS-1$
782
			Util.verbose(" -> partial match:" + partialMatch);  //$NON-NLS-1$
756
		}
783
		}
757
*/
784
*/
758
		String matchName= partialMatch ? name.toLowerCase() : name;
785
		String matchName= partialMatch ? name.toLowerCase() : name;
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (+1 lines)
Lines 2401-2406 Link Here
2401
						break;
2401
						break;
2402
					case IResourceDelta.REMOVED :
2402
					case IResourceDelta.REMOVED :
2403
						indexManager.remove(Util.relativePath(file.getFullPath(), 1/*remove project segment*/), file.getProject().getFullPath());
2403
						indexManager.remove(Util.relativePath(file.getFullPath(), 1/*remove project segment*/), file.getProject().getFullPath());
2404
						this.manager.removeFromSecondaryTypesCache(file);
2404
						break;
2405
						break;
2405
				}
2406
				}
2406
		}
2407
		}
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-2 / +51 lines)
Lines 1151-1157 Link Here
1151
		}
1151
		}
1152
		return new IPackageFragmentRoot[] {};
1152
		return new IPackageFragmentRoot[] {};
1153
	}
1153
	}
1154
	
1154
1155
	/*
1156
	 * Find secondary type for a project.
1157
	 * 
1158
	 * @param packageName Package name of secondary type to be found
1159
	 * @param typeName Type name to be found
1160
	 *
1161
	public IType findSecondaryType(String packageName, String typeName) {
1162
		if (JavaModelManager.VERBOSE) {
1163
			StringBuffer buffer = new StringBuffer("JavaProject.findSecondaryType("); //$NON-NLS-1$
1164
			buffer.append(packageName);
1165
			buffer.append(',');
1166
			buffer.append(typeName);
1167
			buffer.append(')');
1168
			Util.verbose(buffer.toString());
1169
		}
1170
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
1171
		try {
1172
			HashMap secondaryTypePaths = manager.getSecondaryTypes(this);
1173
			if (secondaryTypePaths.size() > 0) {
1174
				String searchedName = packageName.length()==0 ? typeName : packageName + '.' + typeName;
1175
				String pathName = (String) secondaryTypePaths.get(searchedName);
1176
				if (JavaModelManager.VERBOSE) {
1177
					Util.verbose(" -> path name: " + pathName);  //$NON-NLS-1$
1178
				}
1179
				if (pathName != null && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(pathName)) {
1180
					IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(pathName));
1181
					ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, this);
1182
					IType type = unit.getType(typeName);
1183
					if (JavaModelManager.VERBOSE) {
1184
						Util.verbose(" -> type: " + type.getElementName());  //$NON-NLS-1$
1185
					}
1186
					return type;
1187
				}
1188
			}
1189
		}
1190
		catch (JavaModelException jme) {
1191
			// give up
1192
		}
1193
		return null;
1194
	}
1195
	*/
1196
1155
	/**
1197
	/**
1156
	 * @see IJavaProject#findType(String)
1198
	 * @see IJavaProject#findType(String)
1157
	 */
1199
	 */
Lines 1184-1189 Link Here
1184
	public IType findType(String fullyQualifiedName, WorkingCopyOwner owner) throws JavaModelException {
1226
	public IType findType(String fullyQualifiedName, WorkingCopyOwner owner) throws JavaModelException {
1185
		
1227
		
1186
		NameLookup lookup = newNameLookup(owner);
1228
		NameLookup lookup = newNameLookup(owner);
1229
		return findType(fullyQualifiedName, lookup);
1230
	}
1231
	
1232
	/*
1233
	 * Internal findType with instanciated name lookup
1234
	 */
1235
	IType findType(String fullyQualifiedName, NameLookup lookup) throws JavaModelException {
1187
		IType type = lookup.findType(
1236
		IType type = lookup.findType(
1188
			fullyQualifiedName,
1237
			fullyQualifiedName,
1189
			false,
1238
			false,
Lines 1192-1198 Link Here
1192
			// try to find enclosing type
1241
			// try to find enclosing type
1193
			int lastDot = fullyQualifiedName.lastIndexOf('.');
1242
			int lastDot = fullyQualifiedName.lastIndexOf('.');
1194
			if (lastDot == -1) return null;
1243
			if (lastDot == -1) return null;
1195
			type = this.findType(fullyQualifiedName.substring(0, lastDot));
1244
			type = findType(fullyQualifiedName.substring(0, lastDot), lookup);
1196
			if (type != null) {
1245
			if (type != null) {
1197
				type = type.getType(fullyQualifiedName.substring(lastDot+1));
1246
				type = type.getType(fullyQualifiedName.substring(lastDot+1));
1198
				if (!type.exists()) {
1247
				if (!type.exists()) {
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-2 / +159 lines)
Lines 34-43 Link Here
34
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
34
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
35
import org.eclipse.jdt.internal.codeassist.SelectionEngine;
35
import org.eclipse.jdt.internal.codeassist.SelectionEngine;
36
import org.eclipse.jdt.internal.compiler.Compiler;
36
import org.eclipse.jdt.internal.compiler.Compiler;
37
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
37
import org.eclipse.jdt.internal.core.builder.JavaBuilder;
38
import org.eclipse.jdt.internal.core.builder.JavaBuilder;
38
import org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy;
39
import org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy;
39
import org.eclipse.jdt.internal.core.search.AbstractSearchScope;
40
import org.eclipse.jdt.internal.core.search.AbstractSearchScope;
40
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
41
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
42
import org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor;
41
import org.eclipse.jdt.internal.core.search.JavaWorkspaceScope;
43
import org.eclipse.jdt.internal.core.search.JavaWorkspaceScope;
42
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
44
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
43
import org.eclipse.jdt.internal.core.search.processing.JobManager;
45
import org.eclipse.jdt.internal.core.search.processing.JobManager;
Lines 799-804 Link Here
799
		
801
		
800
		public IEclipsePreferences preferences;
802
		public IEclipsePreferences preferences;
801
		public Hashtable options;
803
		public Hashtable options;
804
		public HashMap secondaryTypes;
802
		
805
		
803
		public PerProjectInfo(IProject project) {
806
		public PerProjectInfo(IProject project) {
804
807
Lines 1408-1414 Link Here
1408
		}
1411
		}
1409
	    return null; // break cycle
1412
	    return null; // break cycle
1410
	}
1413
	}
1411
	
1414
1415
	/**
1416
	 * Get all secondary types for a project and store result in per project info cache.
1417
	 * 
1418
	 * @param project Project we want get secondary types from
1419
	 * @return HashMap Table of secondary type names->path for given project
1420
	 */
1421
	public HashMap getSecondaryTypes(IJavaProject project) throws JavaModelException {
1422
		if (VERBOSE) {
1423
			StringBuffer buffer = new StringBuffer("JavaModelManager.getSecondaryTypesPaths("); //$NON-NLS-1$
1424
			buffer.append(project.getElementName());
1425
			buffer.append(')');
1426
			Util.verbose(buffer.toString());
1427
		}
1428
1429
		PerProjectInfo projectInfo = getPerProjectInfoCheckExistence(project.getProject());
1430
		if (projectInfo.secondaryTypes != null) return projectInfo.secondaryTypes;
1431
		final HashMap secondaryTypePaths = new HashMap();
1432
1433
		IRestrictedAccessTypeRequestor nameRequestor = new IRestrictedAccessTypeRequestor() {
1434
			public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
1435
//				String key = new String(CharOperation.concat(packageName, simpleTypeName, '.'));
1436
				String key = packageName==null ? "" : new String(packageName); //$NON-NLS-1$
1437
				HashMap types = (HashMap) secondaryTypePaths.get(key);
1438
				if (types == null) {
1439
					types = new HashMap();
1440
				}
1441
				types.put(new String(simpleTypeName), path);
1442
				secondaryTypePaths.put(key, types);
1443
//				secondaryTypePaths.put(key, path);
1444
			}
1445
		};
1446
1447
		// Build scope using prereq projects but only source folders
1448
		IPackageFragmentRoot[] allRoots = project.getAllPackageFragmentRoots();
1449
		int length = allRoots.length, size = 0;
1450
		IPackageFragmentRoot[] allSourceFolders = new IPackageFragmentRoot[length];
1451
		for (int i=0; i<length; i++) {
1452
			if (allRoots[i].getKind() == IPackageFragmentRoot.K_SOURCE) {
1453
				allSourceFolders[size++] = allRoots[i];
1454
			}
1455
		}
1456
		if (size < length) {
1457
			System.arraycopy(allSourceFolders, 0, allSourceFolders = new IPackageFragmentRoot[size], 0, size);
1458
		}
1459
			
1460
		// Search all secondary types on scope
1461
		new BasicSearchEngine().searchAllSecondaryTypeNames(allSourceFolders, nameRequestor);
1462
		if (VERBOSE) {
1463
			System.out.print(Thread.currentThread() + " -> secondary paths: ");  //$NON-NLS-1$
1464
			if (secondaryTypePaths == null) {
1465
				System.out.println(" NONE"); //$NON-NLS-1$
1466
			} else {
1467
				System.out.println();
1468
				Iterator keys = secondaryTypePaths.keySet().iterator();
1469
				while (keys.hasNext()) {
1470
					String qualifiedName = (String) keys.next();
1471
					Util.verbose("		- "+qualifiedName+'-'+secondaryTypePaths.get(qualifiedName) ); //$NON-NLS-1$
1472
				}
1473
			}
1474
		}
1475
		
1476
		// Build types from paths
1477
		Iterator packages = secondaryTypePaths.keySet().iterator();
1478
		while (packages.hasNext()) {
1479
			String packName = (String) packages.next();
1480
			HashMap types = (HashMap) secondaryTypePaths.get(packName);
1481
			Iterator names = types.keySet().iterator();
1482
			while (names.hasNext()) {
1483
				String typeName = (String) names.next();
1484
				String path = (String) types.get(typeName);
1485
				if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(path)) {
1486
					IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
1487
					ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null);
1488
					IType type = unit.getType(typeName);
1489
					types.put(typeName, type); // replace stored path with type itself
1490
				}
1491
			}
1492
		}
1493
		
1494
		// Store result in per project info cache
1495
		return (projectInfo.secondaryTypes = secondaryTypePaths);
1496
	}
1497
1412
	/**
1498
	/**
1413
	 * Returns the temporary cache for newly opened elements for the current thread.
1499
	 * Returns the temporary cache for newly opened elements for the current thread.
1414
	 * Creates it if not already created.
1500
	 * Creates it if not already created.
Lines 2266-2272 Link Here
2266
		// used by tests to simulate a startup
2352
		// used by tests to simulate a startup
2267
		MANAGER = new JavaModelManager();
2353
		MANAGER = new JavaModelManager();
2268
	}
2354
	}
2269
	
2355
2356
	/**
2357
	 * Remove a file from its project secondary types cache.
2358
	 * 
2359
	 * @param file File to remove
2360
	 */
2361
	public void removeFromSecondaryTypesCache(IFile file) {
2362
		if (VERBOSE) {
2363
			StringBuffer buffer = new StringBuffer("JavaModelManager.removeSecondaryTypePaths("); //$NON-NLS-1$
2364
			buffer.append(file.getName());
2365
			buffer.append(')');
2366
			Util.verbose(buffer.toString());
2367
		}
2368
		if (file != null) {
2369
			PerProjectInfo projectInfo = getPerProjectInfo(file.getProject(), false);
2370
			if (projectInfo != null && projectInfo.secondaryTypes != null) {
2371
				if (VERBOSE) {
2372
					Util.verbose("-> remove file from cache of project: "+file.getProject().getName()); //$NON-NLS-1$
2373
				}
2374
				Iterator packages = projectInfo.secondaryTypes.keySet().iterator();
2375
				while (packages.hasNext()) {
2376
					String packName = (String) packages.next();
2377
					HashMap types = (HashMap) projectInfo.secondaryTypes.get(packName);
2378
					Iterator names = types.keySet().iterator();
2379
					while (names.hasNext()) {
2380
						String typeName = (String) names.next();
2381
						Object obj = types.get(typeName);
2382
						boolean remove = false;
2383
						if (obj instanceof String) {
2384
							String path = (String) obj;
2385
							remove = path.equals(file.getFullPath().toString());
2386
						} else if (obj instanceof IType) {
2387
							remove = file == ((IType)obj).getResource();
2388
						}
2389
						if (remove) {
2390
							types.remove(typeName);
2391
							if (types.size() == 0) {
2392
								projectInfo.secondaryTypes.remove(packName);
2393
							}
2394
							return;
2395
						}
2396
					}
2397
				}
2398
			}
2399
		}
2400
	}
2401
2402
	/**
2403
	 * Reset secondary types cache for a project got from given path.
2404
	 * 
2405
	 * @param path Path of file containing a secondary type
2406
	 */
2407
	public void resetSecondaryTypesCache(String path) {
2408
		if (VERBOSE) {
2409
			StringBuffer buffer = new StringBuffer("JavaModelManager.resetSecondaryTypePaths("); //$NON-NLS-1$
2410
			buffer.append(path);
2411
			buffer.append(')');
2412
			Util.verbose(buffer.toString());
2413
		}
2414
		IWorkspaceRoot wRoot = ResourcesPlugin.getWorkspace().getRoot();
2415
		IResource resource = wRoot.findMember(path);
2416
		if (resource != null) {
2417
			PerProjectInfo projectInfo = getPerProjectInfo(resource.getProject(), false);
2418
			if (projectInfo != null) {
2419
				if (VERBOSE) {
2420
					Util.verbose("-> reset cache for project: "+resource.getProject().getName()); //$NON-NLS-1$
2421
				}
2422
				projectInfo.secondaryTypes = null;
2423
			}
2424
		}
2425
	}
2426
2270
	/*
2427
	/*
2271
	 * Resets the temporary cache for newly created elements to null.
2428
	 * Resets the temporary cache for newly created elements to null.
2272
	 */
2429
	 */
(-)compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java (+7 lines)
Lines 1326-1329 Link Here
1326
			maxFieldCount = outerMostType.maxFieldCount; // down
1326
			maxFieldCount = outerMostType.maxFieldCount; // down
1327
		}
1327
		}
1328
	}	
1328
	}	
1329
1330
	/**
1331
	 * Returns whether the type is a secondary one or not.
1332
	 */
1333
	public boolean isSecondary() {
1334
		return (this.bits & IsSecondaryType) != 0;
1335
	}
1329
}
1336
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java (-2 / +3 lines)
Lines 32-38 Link Here
32
	public final static int Bit10= 0x200; 					// depth (name ref, msg) | operator (operator) | is anonymous type (type decl)
32
	public final static int Bit10= 0x200; 					// depth (name ref, msg) | operator (operator) | is anonymous type (type decl)
33
	public final static int Bit11 = 0x400; 					// depth (name ref, msg) | operator (operator) | is member type (type decl)
33
	public final static int Bit11 = 0x400; 					// depth (name ref, msg) | operator (operator) | is member type (type decl)
34
	public final static int Bit12 = 0x800; 					// depth (name ref, msg) | operator (operator) | has abstract methods (type decl)
34
	public final static int Bit12 = 0x800; 					// depth (name ref, msg) | operator (operator) | has abstract methods (type decl)
35
	public final static int Bit13 = 0x1000; 				// depth (name ref, msg) 
35
	public final static int Bit13 = 0x1000; 				// depth (name ref, msg) | is secondary type (type decl)
36
	public final static int Bit14 = 0x2000; 				// strictly assigned (reference lhs)
36
	public final static int Bit14 = 0x2000; 				// strictly assigned (reference lhs)
37
	public final static int Bit15 = 0x4000; 				// is unnecessary cast (expression) | is varargs (type ref)
37
	public final static int Bit15 = 0x4000; 				// is unnecessary cast (expression) | is varargs (type ref)
38
	public final static int Bit16 = 0x8000; 				// in javadoc comment (name ref, type ref, msg)
38
	public final static int Bit16 = 0x8000; 				// in javadoc comment (name ref, type ref, msg)
Lines 118-124 Link Here
118
	public static final int IsAnonymousType = Bit10; // used to test for anonymous 
118
	public static final int IsAnonymousType = Bit10; // used to test for anonymous 
119
	public static final int IsMemberType = Bit11; // local member do not know it is local at parse time (need to look at binding)
119
	public static final int IsMemberType = Bit11; // local member do not know it is local at parse time (need to look at binding)
120
	public static final int HasAbstractMethods = Bit12; // used to promote abstract enums
120
	public static final int HasAbstractMethods = Bit12; // used to promote abstract enums
121
	
121
	public static final int IsSecondaryType = Bit13; // used to test for secondary
122
122
	// for type, method and field declarations 
123
	// for type, method and field declarations 
123
	public static final int HasLocalType = Bit2; // cannot conflict with AddAssertionMASK
124
	public static final int HasLocalType = Bit2; // cannot conflict with AddAssertionMASK
124
125
(-)model/org/eclipse/jdt/internal/compiler/SourceJavadocParser.java (-1 / +1 lines)
Lines 22-28 Link Here
22
22
23
public SourceJavadocParser(Parser sourceParser) {
23
public SourceJavadocParser(Parser sourceParser) {
24
	super(sourceParser);
24
	super(sourceParser);
25
	this.kind = SOURCE_PARSER | TEXT_PARSE | TEXT_VERIF;
25
	this.kind = SOURCE_PARSER | TEXT_VERIF;
26
}
26
}
27
27
28
public boolean checkDeprecation(int commentPtr) {
28
public boolean checkDeprecation(int commentPtr) {
(-)model/org/eclipse/jdt/internal/compiler/SourceElementParser.java (-6 / +23 lines)
Lines 57-62 Link Here
57
	CompilerOptions options;
57
	CompilerOptions options;
58
	HashtableOfObjectToInt sourceEnds = new HashtableOfObjectToInt();
58
	HashtableOfObjectToInt sourceEnds = new HashtableOfObjectToInt();
59
	HashMap nodesToCategories = new HashMap(); // a map from ASTNode to char[][]
59
	HashMap nodesToCategories = new HashMap(); // a map from ASTNode to char[][]
60
	boolean useSourceJavadocParser = true;
60
	
61
	
61
/**
62
/**
62
 * An ast visitor that visits local type declarations.
63
 * An ast visitor that visits local type declarations.
Lines 94-99 Link Here
94
		CompilerOptions options,
95
		CompilerOptions options,
95
		boolean reportLocalDeclarations,
96
		boolean reportLocalDeclarations,
96
		boolean optimizeStringLiterals) {
97
		boolean optimizeStringLiterals) {
98
	this(requestor, problemFactory, options, reportLocalDeclarations, optimizeStringLiterals, true/* use SourceJavadocParser */);
99
}
100
101
public SourceElementParser(
102
		final ISourceElementRequestor requestor, 
103
		IProblemFactory problemFactory,
104
		CompilerOptions options,
105
		boolean reportLocalDeclarations,
106
		boolean optimizeStringLiterals,
107
		boolean useSourceJavadocParser) {
97
	// we want to notify all syntax error with the acceptProblem API
108
	// we want to notify all syntax error with the acceptProblem API
98
	// To do so, we define the record method of the ProblemReporter
109
	// To do so, we define the record method of the ProblemReporter
99
	super(new ProblemReporter(
110
	super(new ProblemReporter(
Lines 115-121 Link Here
115
		this.localDeclarationVisitor = new LocalDeclarationVisitor();
126
		this.localDeclarationVisitor = new LocalDeclarationVisitor();
116
	}
127
	}
117
	// set specific javadoc parser
128
	// set specific javadoc parser
118
	this.javadocParser = new SourceJavadocParser(this);
129
	this.useSourceJavadocParser = useSourceJavadocParser;
130
	if (useSourceJavadocParser) {
131
		this.javadocParser = new SourceJavadocParser(this);
132
	}
119
}
133
}
120
134
121
public void checkComment() {
135
public void checkComment() {
Lines 1246-1251 Link Here
1246
			typeInfo.typeParameters = getTypeParameterInfos(typeDeclaration.typeParameters);
1260
			typeInfo.typeParameters = getTypeParameterInfos(typeDeclaration.typeParameters);
1247
			typeInfo.annotationPositions = collectAnnotationPositions(typeDeclaration.annotations);
1261
			typeInfo.annotationPositions = collectAnnotationPositions(typeDeclaration.annotations);
1248
			typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration);
1262
			typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration);
1263
			typeInfo.secondary = typeDeclaration.isSecondary();
1249
			requestor.enterType(typeInfo);
1264
			requestor.enterType(typeInfo);
1250
			switch (kind) {
1265
			switch (kind) {
1251
				case TypeDeclaration.CLASS_DECL :
1266
				case TypeDeclaration.CLASS_DECL :
Lines 1323-1333 Link Here
1323
	}
1338
	}
1324
}
1339
}
1325
private void rememberCategories() {
1340
private void rememberCategories() {
1326
	SourceJavadocParser sourceJavadocParser = (SourceJavadocParser) this.javadocParser;
1341
	if (this.useSourceJavadocParser) {
1327
	char[][] categories =  sourceJavadocParser.categories;
1342
		SourceJavadocParser sourceJavadocParser = (SourceJavadocParser) this.javadocParser;
1328
	if (categories.length > 0) {
1343
		char[][] categories =  sourceJavadocParser.categories;
1329
		this.nodesToCategories.put(this.astStack[this.astPtr], categories);
1344
		if (categories.length > 0) {
1330
		sourceJavadocParser.categories = CharOperation.NO_CHAR_CHAR;
1345
			this.nodesToCategories.put(this.astStack[this.astPtr], categories);
1346
			sourceJavadocParser.categories = CharOperation.NO_CHAR_CHAR;
1347
		}
1331
	}
1348
	}
1332
}
1349
}
1333
private int sourceEnd(TypeDeclaration typeDeclaration) {
1350
private int sourceEnd(TypeDeclaration typeDeclaration) {
(-)model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java (+1 lines)
Lines 49-54 Link Here
49
		public TypeParameterInfo[] typeParameters;
49
		public TypeParameterInfo[] typeParameters;
50
		public long[] annotationPositions;
50
		public long[] annotationPositions;
51
		public char[][] categories;
51
		public char[][] categories;
52
		public boolean secondary;
52
	}
53
	}
53
	
54
	
54
	public static class TypeParameterInfo {
55
	public static class TypeParameterInfo {
(-)search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java (-18 / +127 lines)
Lines 71-77 Link Here
71
	}
71
	}
72
	
72
	
73
	/**
73
	/**
74
	 * @see org.eclipse.jdt.core.search.SearchEngine#SearchEngine(ICompilationUnit[]) for detailed comment.
74
	 * @see SearchEngine#SearchEngine(ICompilationUnit[]) for detailed comment.
75
	 */
75
	 */
76
	public BasicSearchEngine(ICompilationUnit[] workingCopies) {
76
	public BasicSearchEngine(ICompilationUnit[] workingCopies) {
77
		this.workingCopies = workingCopies;
77
		this.workingCopies = workingCopies;
Lines 87-121 Link Here
87
		}
87
		}
88
	}
88
	}
89
	/**
89
	/**
90
	 * @see org.eclipse.jdt.core.search.SearchEngine#SearchEngine(WorkingCopyOwner) for detailed comment.
90
	 * @see SearchEngine#SearchEngine(WorkingCopyOwner) for detailed comment.
91
	 */
91
	 */
92
	public BasicSearchEngine(WorkingCopyOwner workingCopyOwner) {
92
	public BasicSearchEngine(WorkingCopyOwner workingCopyOwner) {
93
		this.workingCopyOwner = workingCopyOwner;
93
		this.workingCopyOwner = workingCopyOwner;
94
	}
94
	}
95
95
96
	/**
96
	/**
97
	 * @see org.eclipse.jdt.core.search.SearchEngine#createHierarchyScope(IType) for detailed comment.
97
	 * @see SearchEngine#createHierarchyScope(IType) for detailed comment.
98
	 */
98
	 */
99
	public static IJavaSearchScope createHierarchyScope(IType type) throws JavaModelException {
99
	public static IJavaSearchScope createHierarchyScope(IType type) throws JavaModelException {
100
		return createHierarchyScope(type, DefaultWorkingCopyOwner.PRIMARY);
100
		return createHierarchyScope(type, DefaultWorkingCopyOwner.PRIMARY);
101
	}
101
	}
102
	
102
	
103
	/**
103
	/**
104
	 * @see org.eclipse.jdt.core.search.SearchEngine#createHierarchyScope(IType,WorkingCopyOwner) for detailed comment.
104
	 * @see SearchEngine#createHierarchyScope(IType,WorkingCopyOwner) for detailed comment.
105
	 */
105
	 */
106
	public static IJavaSearchScope createHierarchyScope(IType type, WorkingCopyOwner owner) throws JavaModelException {
106
	public static IJavaSearchScope createHierarchyScope(IType type, WorkingCopyOwner owner) throws JavaModelException {
107
		return new HierarchyScope(type, owner);
107
		return new HierarchyScope(type, owner);
108
	}
108
	}
109
109
110
	/**
110
	/**
111
	 * @see org.eclipse.jdt.core.search.SearchEngine#createJavaSearchScope(IJavaElement[]) for detailed comment.
111
	 * @see SearchEngine#createJavaSearchScope(IJavaElement[]) for detailed comment.
112
	 */
112
	 */
113
	public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements) {
113
	public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements) {
114
		return createJavaSearchScope(elements, true);
114
		return createJavaSearchScope(elements, true);
115
	}
115
	}
116
116
117
	/**
117
	/**
118
	 * @see org.eclipse.jdt.core.search.SearchEngine#createJavaSearchScope(IJavaElement[], boolean) for detailed comment.
118
	 * @see SearchEngine#createJavaSearchScope(IJavaElement[], boolean) for detailed comment.
119
	 */
119
	 */
120
	public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements, boolean includeReferencedProjects) {
120
	public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements, boolean includeReferencedProjects) {
121
		int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES;
121
		int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES;
Lines 126-132 Link Here
126
	}
126
	}
127
127
128
	/**
128
	/**
129
	 * @see org.eclipse.jdt.core.search.SearchEngine#createJavaSearchScope(IJavaElement[], int) for detailed comment.
129
	 * @see SearchEngine#createJavaSearchScope(IJavaElement[], int) for detailed comment.
130
	 */
130
	 */
131
	public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements, int includeMask) {
131
	public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements, int includeMask) {
132
		JavaSearchScope scope = new JavaSearchScope();
132
		JavaSearchScope scope = new JavaSearchScope();
Lines 149-157 Link Here
149
	}
149
	}
150
	
150
	
151
	/**
151
	/**
152
	 * Returns a Java search scope with the workspace as the only limit.
152
	 * @see SearchEngine#createWorkspaceScope() for detailed comment.
153
	 *
154
	 * @return a new workspace scope
155
	 */
153
	 */
156
	public static IJavaSearchScope createWorkspaceScope() {
154
	public static IJavaSearchScope createWorkspaceScope() {
157
		return JavaModelManager.getJavaModelManager().getWorkspaceScope();
155
		return JavaModelManager.getJavaModelManager().getWorkspaceScope();
Lines 165-171 Link Here
165
	 * @param scope the search result has to be limited to the given scope
163
	 * @param scope the search result has to be limited to the given scope
166
	 * @param requestor a callback object to which each match is reported
164
	 * @param requestor a callback object to which each match is reported
167
	 */
165
	 */
168
	public void findMatches(SearchPattern pattern, SearchParticipant[] participants, IJavaSearchScope scope, SearchRequestor requestor, IProgressMonitor monitor) throws CoreException {
166
	void findMatches(SearchPattern pattern, SearchParticipant[] participants, IJavaSearchScope scope, SearchRequestor requestor, IProgressMonitor monitor) throws CoreException {
169
		if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
167
		if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
170
	
168
	
171
		/* initialize progress monitor */
169
		/* initialize progress monitor */
Lines 231-237 Link Here
231
	/**
229
	/**
232
	 * @param matchRule
230
	 * @param matchRule
233
	 */
231
	 */
234
	private String getMatchRuleString(final int matchRule) {
232
	public static String getMatchRuleString(final int matchRule) {
235
		StringBuffer buffer = new StringBuffer();
233
		StringBuffer buffer = new StringBuffer();
236
		for (int i=1; i<=8; i++) {
234
		for (int i=1; i<=8; i++) {
237
			int bit = matchRule & (1<<(i-1));
235
			int bit = matchRule & (1<<(i-1));
Lines 266-271 Link Here
266
		return buffer.toString();
264
		return buffer.toString();
267
	}
265
	}
268
266
267
	/**
268
	 * Return kind of search corresponding to given value.
269
	 * 
270
	 * @param searchFor
271
	 */
272
	public static String getSearchForString(final int searchFor) {
273
		switch (searchFor) {
274
			case IJavaSearchConstants.TYPE:
275
				return ("TYPE"); //$NON-NLS-1$
276
			case IJavaSearchConstants.METHOD:
277
				return ("METHOD"); //$NON-NLS-1$
278
			case IJavaSearchConstants.PACKAGE:
279
				return ("PACKAGE"); //$NON-NLS-1$
280
			case IJavaSearchConstants.CONSTRUCTOR:
281
				return ("CONSTRUCTOR"); //$NON-NLS-1$
282
			case IJavaSearchConstants.FIELD:
283
				return ("FIELD"); //$NON-NLS-1$
284
			case IJavaSearchConstants.CLASS:
285
				return ("CLASS"); //$NON-NLS-1$
286
			case IJavaSearchConstants.INTERFACE:
287
				return ("INTERFACE"); //$NON-NLS-1$
288
			case IJavaSearchConstants.ENUM:
289
				return ("ENUM"); //$NON-NLS-1$
290
			case IJavaSearchConstants.ANNOTATION_TYPE:
291
				return ("ANNOTATION_TYPE"); //$NON-NLS-1$
292
			case IJavaSearchConstants.CLASS_AND_ENUM:
293
				return ("CLASS_AND_ENUM"); //$NON-NLS-1$
294
			case IJavaSearchConstants.CLASS_AND_INTERFACE:
295
				return ("CLASS_AND_INTERFACE"); //$NON-NLS-1$
296
		}
297
		return "UNKNOWN"; //$NON-NLS-1$
298
	}
299
269
	private Parser getParser() {
300
	private Parser getParser() {
270
		if (this.parser == null) {
301
		if (this.parser == null) {
271
			this.compilerOptions = new CompilerOptions(JavaCore.getOptions());
302
			this.compilerOptions = new CompilerOptions(JavaCore.getOptions());
Lines 279-288 Link Here
279
		return this.parser;
310
		return this.parser;
280
	}
311
	}
281
	
312
	
282
	/**
313
	/*
283
	 * Returns the underlying resource of the given element.
314
	 * Returns the underlying resource of the given element.
284
	 * @param element an IJavaElement
285
	 * @return an IResource
286
	 */
315
	 */
287
	private IResource getResource(IJavaElement element) {
316
	private IResource getResource(IJavaElement element) {
288
		if (element instanceof IMember) {
317
		if (element instanceof IMember) {
Lines 354-363 Link Here
354
		return result;
383
		return result;
355
	}
384
	}
356
	
385
	
357
	/**
386
	/*
358
	 * Returns the list of working copies used to do the search on the given Java element.
387
	 * Returns the list of working copies used to do the search on the given Java element.
359
	 * @param element an IJavaElement
360
	 * @return an array of ICompilationUnit
361
	 */
388
	 */
362
	private ICompilationUnit[] getWorkingCopies(IJavaElement element) {
389
	private ICompilationUnit[] getWorkingCopies(IJavaElement element) {
363
		if (element instanceof IMember) {
390
		if (element instanceof IMember) {
Lines 688-693 Link Here
688
	}
715
	}
689
716
690
	/**
717
	/**
718
	 * Searches for all top-level types and member types in the given scope.
719
	 * The search can be selecting specific types (given a package or a type name
720
	 * prefix and match modes). 
721
	 * 
722
	 */
723
	public void searchAllSecondaryTypeNames(IPackageFragmentRoot[] sourceFolders, final IRestrictedAccessTypeRequestor nameRequestor)  throws JavaModelException {
724
725
		if (VERBOSE) {
726
			Util.verbose("BasicSearchEngine.searchAllSecondaryTypeNames(char[], char[], int, int, IJavaSearchScope, IRestrictedAccessTypeRequestor, int, IProgressMonitor)"); //$NON-NLS-1$
727
			StringBuffer buffer = new StringBuffer(" -> source folders: "); //$NON-NLS-1$
728
			int length = sourceFolders.length;
729
			for (int i=0; i<length; i++) {
730
				if (i==0) {
731
					buffer.append('[');
732
				} else {
733
					buffer.append(',');
734
				}
735
				buffer.append(sourceFolders[i].getElementName());
736
			}
737
			buffer.append(']');
738
			Util.verbose(buffer.toString());
739
		}
740
741
		IndexManager indexManager = JavaModelManager.getJavaModelManager().getIndexManager();
742
		final TypeDeclarationPattern pattern = new SecondaryTypeDeclarationPattern();
743
		
744
		final HashSet workingCopyPaths = new HashSet();
745
		ICompilationUnit[] copies = getWorkingCopies();
746
		if (copies != null) {
747
			for (int i = 0, length = copies.length; i < length; i++) {
748
				ICompilationUnit workingCopy = copies[i];
749
				workingCopyPaths.add(workingCopy.getPath().toString());
750
			}
751
		}
752
753
		IndexQueryRequestor searchRequestor = new IndexQueryRequestor(){
754
			public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) {
755
				TypeDeclarationPattern record = (TypeDeclarationPattern)indexRecord;
756
				if (record.secondary) {
757
					AccessRestriction accessRestriction = null;
758
					if (record.enclosingTypeNames != IIndexConstants.ONE_ZERO_CHAR  // filter out local and anonymous classes
759
							&& !workingCopyPaths.contains(documentPath)) { // filter out working copies
760
						if (access != null) {
761
							// Compute document relative path
762
							int pkgLength = (record.pkg==null || record.pkg.length==0) ? 0 : record.pkg.length+1;
763
							int nameLength = record.simpleName==null ? 0 : record.simpleName.length;
764
							char[] path = new char[pkgLength+nameLength];
765
							int pos = 0;
766
							if (pkgLength > 0) {
767
								System.arraycopy(record.pkg, 0, path, pos, pkgLength-1);
768
								CharOperation.replace(path, '.', '/');
769
								path[pkgLength-1] = '/';
770
								pos += pkgLength;
771
							}
772
							if (nameLength > 0) {
773
								System.arraycopy(record.simpleName, 0, path, pos, nameLength);
774
								pos += nameLength;
775
							}
776
							// Update access restriction if path is not empty
777
							if (pos > 0) {
778
								accessRestriction = access.getViolatedRestriction(path);
779
							}
780
						}
781
						nameRequestor.acceptType(record.modifiers, record.pkg, record.simpleName, record.enclosingTypeNames, documentPath, accessRestriction);
782
					}
783
				}
784
				return true;
785
			}
786
		};
787
	
788
		// add type names from indexes
789
		indexManager.performConcurrentJob(
790
			new PatternSearchJob(
791
				pattern, 
792
				getDefaultSearchParticipant(), // Java search only
793
				createJavaSearchScope(sourceFolders), 
794
				searchRequestor),
795
			IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
796
			null);	
797
	}
798
799
	/**
691
	 * Searches for all top-level types and member types in the given scope using  a case sensitive exact match
800
	 * Searches for all top-level types and member types in the given scope using  a case sensitive exact match
692
	 * with the given qualified names and type names.
801
	 * with the given qualified names and type names.
693
	 * 
802
	 * 
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationPattern.java (-4 / +16 lines)
Lines 31-36 Link Here
31
// set to TYPE_SUFFIX for matching both classes and interfaces
31
// set to TYPE_SUFFIX for matching both classes and interfaces
32
public char typeSuffix; 
32
public char typeSuffix; 
33
public int modifiers;
33
public int modifiers;
34
public boolean secondary = false;
34
35
35
protected static char[][] CATEGORIES = { TYPE_DECL };
36
protected static char[][] CATEGORIES = { TYPE_DECL };
36
37
Lines 81-89 Link Here
81
82
82
/*
83
/*
83
 * Create index key for type declaration pattern:
84
 * Create index key for type declaration pattern:
84
 *		key = typeName / packageName / enclosingTypeName / typeSuffix modifiers
85
 *		key = typeName / packageName / enclosingTypeName / modifiers
86
 * or for secondary types
87
 *		key = typeName / packageName / enclosingTypeName / modifiers / 'S'
85
 */
88
 */
86
public static char[] createIndexKey(int modifiers, char[] typeName, char[] packageName, char[][] enclosingTypeNames) { //, char typeSuffix) {
89
public static char[] createIndexKey(int modifiers, char[] typeName, char[] packageName, char[][] enclosingTypeNames, boolean secondary) { //, char typeSuffix) {
87
	int typeNameLength = typeName == null ? 0 : typeName.length;
90
	int typeNameLength = typeName == null ? 0 : typeName.length;
88
	int packageLength = packageName == null ? 0 : packageName.length;
91
	int packageLength = packageName == null ? 0 : packageName.length;
89
	int enclosingNamesLength = 0;
92
	int enclosingNamesLength = 0;
Lines 95-101 Link Here
95
		}
98
		}
96
	}
99
	}
97
100
98
	char[] result = new char[typeNameLength + packageLength + enclosingNamesLength + 4];
101
	int resultLength = typeNameLength + packageLength + enclosingNamesLength + 4;
102
	if (secondary) resultLength += 2;
103
	char[] result = new char[resultLength];
99
	int pos = 0;
104
	int pos = 0;
100
	if (typeNameLength > 0) {
105
	if (typeNameLength > 0) {
101
		System.arraycopy(typeName, 0, result, pos, typeNameLength);
106
		System.arraycopy(typeName, 0, result, pos, typeNameLength);
Lines 119-124 Link Here
119
	}
124
	}
120
	result[pos++] = SEPARATOR;
125
	result[pos++] = SEPARATOR;
121
	result[pos] = (char) modifiers;
126
	result[pos] = (char) modifiers;
127
	if (secondary) {
128
		result[++pos] = SEPARATOR;
129
		result[++pos] = 'S';
130
	}
122
	return result;
131
	return result;
123
}
132
}
124
133
Lines 170-176 Link Here
170
		this.enclosingTypeNames = CharOperation.equals(ONE_ZERO, names) ? ONE_ZERO_CHAR : CharOperation.splitOn('.', names);
179
		this.enclosingTypeNames = CharOperation.equals(ONE_ZERO, names) ? ONE_ZERO_CHAR : CharOperation.splitOn('.', names);
171
	}
180
	}
172
181
173
	decodeModifiers(key[key.length - 1]);
182
	slash = CharOperation.indexOf(SEPARATOR, key, start = slash + 1);
183
	this.secondary = slash > 0;
184
	int last = this.secondary ? slash : key.length;
185
	decodeModifiers(key[last-1]);
174
}
186
}
175
protected void decodeModifiers(char value) {
187
protected void decodeModifiers(char value) {
176
	this.modifiers = value; // implicit cast to int type
188
	this.modifiers = value; // implicit cast to int type
(-)search/org/eclipse/jdt/internal/core/search/matching/SecondaryTypeDeclarationPattern.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 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 java.io.IOException;
14
15
import org.eclipse.jdt.core.search.SearchPattern;
16
import org.eclipse.jdt.internal.core.index.EntryResult;
17
import org.eclipse.jdt.internal.core.index.Index;
18
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
19
20
public class SecondaryTypeDeclarationPattern extends TypeDeclarationPattern {
21
	
22
	private final static char[] SECONDARY_PATTERN_KEY = "*/S".toCharArray(); //$NON-NLS-1$
23
24
public SecondaryTypeDeclarationPattern() {
25
	super(null, null, null, IIndexConstants.SECONDARY_SUFFIX, R_EXACT_MATCH | R_CASE_SENSITIVE);
26
}
27
28
public SecondaryTypeDeclarationPattern(int matchRule) {
29
	super(matchRule);
30
}
31
32
public SearchPattern getBlankPattern() {
33
	return new SecondaryTypeDeclarationPattern(R_EXACT_MATCH | R_CASE_SENSITIVE);
34
}
35
protected StringBuffer print(StringBuffer output) {
36
	output.append("Secondary"); //$NON-NLS-1$
37
	return super.print(output);
38
}
39
40
/* (non-Javadoc)
41
 * @see org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern#queryIn(org.eclipse.jdt.internal.core.index.Index)
42
 */
43
EntryResult[] queryIn(Index index) throws IOException {
44
	return index.query(CATEGORIES, SECONDARY_PATTERN_KEY, R_PATTERN_MATCH | R_CASE_SENSITIVE);
45
}
46
	
47
}
(-)src/org/eclipse/jdt/core/tests/model/NameLookupTests2.java (-66 / +1 lines)
Lines 11-22 Link Here
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import java.io.IOException;
13
import java.io.IOException;
14
import java.util.ArrayList;
15
14
16
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.Path;
16
import org.eclipse.core.runtime.Path;
18
import org.eclipse.jdt.core.*;
17
import org.eclipse.jdt.core.*;
19
import org.eclipse.jdt.internal.core.IJavaElementRequestor;
20
import org.eclipse.jdt.internal.core.JavaProject;
18
import org.eclipse.jdt.internal.core.JavaProject;
21
import org.eclipse.jdt.internal.core.NameLookup;
19
import org.eclipse.jdt.internal.core.NameLookup;
22
20
Lines 37-43 Link Here
37
	static {
35
	static {
38
//		org.eclipse.jdt.internal.core.search.matching.MatchLocator.PRINT_BUFFER = false;
36
//		org.eclipse.jdt.internal.core.search.matching.MatchLocator.PRINT_BUFFER = false;
39
//		TESTS_PREFIX =  "testArray";
37
//		TESTS_PREFIX =  "testArray";
40
//		TESTS_NAMES = new String[] { "testFindBinaryTypeWithSameNameAsMember" };
38
//		TESTS_NAMES = new String[] { "testFindBinaryTypeWithDollarName" };
41
//		TESTS_NUMBERS = new int[] { 8 };
39
//		TESTS_NUMBERS = new int[] { 8 };
42
//		TESTS_RANGE = new int[] { 6, -1 };
40
//		TESTS_RANGE = new int[] { 6, -1 };
43
	}
41
	}
Lines 267-334 Link Here
267
		deleteProject("P");
265
		deleteProject("P");
268
	}
266
	}
269
}
267
}
270
/*
271
 * Performance test for looking up package fragments
272
 * (see bug 72683 Slow code assist in Display view)
273
 */
274
public void testPerfSeekPackageFragments() throws CoreException {
275
	try {
276
		// setup projects with 100 source folders and 10 packages per source folder
277
		final int rootLength = 100;
278
		final String[] sourceFolders = new String[rootLength];
279
		for (int i = 0; i < rootLength; i++) {
280
			sourceFolders[i] = "src" + i;
281
		}
282
		String path = getWorkspaceRoot().getLocation().toString() + "/P/src";
283
		for (int i = 0; i < rootLength; i++) {
284
			for (int j = 0; j < 10; j++) {
285
				new java.io.File(path + i + "/org/eclipse/jdt/core/tests" + i + "/performance" + j).mkdirs();
286
			}
287
		}
288
		JavaProject project = (JavaProject)createJavaProject("P", sourceFolders, "bin");
289
		
290
		class PackageRequestor implements IJavaElementRequestor {
291
			ArrayList pkgs = new ArrayList();
292
			public void acceptField(IField field) {}
293
			public void acceptInitializer(IInitializer initializer) {}
294
			public void acceptMemberType(IType type) {}
295
			public void acceptMethod(IMethod method) {}
296
			public void acceptPackageFragment(IPackageFragment packageFragment) {
297
				if (pkgs != null)
298
					pkgs.add(packageFragment);
299
			}
300
			public void acceptType(IType type) {}
301
			public boolean isCanceled() {
302
				return false;
303
			}
304
		}
305
		
306
		// first pass: ensure all class are loaded, and ensure that the test works as expected
307
		PackageRequestor requestor = new PackageRequestor();
308
		getNameLookup(project).seekPackageFragments("org.eclipse.jdt.core.tests78.performance5", false/*not partial match*/, requestor);
309
		int size = requestor.pkgs.size();
310
		IJavaElement[] result = new IJavaElement[size];
311
		requestor.pkgs.toArray(result);
312
		assertElementsEqual(
313
			"Unexpected packages",
314
			"org.eclipse.jdt.core.tests78.performance5 [in src78 [in P]]",
315
			result
316
		);
317
		
318
		// measure performance
319
		requestor.pkgs = null;
320
		for (int i = 0; i < 100; i++) {
321
			startMeasuring();
322
			for (int j = 0; j < 40; j++) {
323
				getNameLookup(project).seekPackageFragments("org.eclipse.jdt.core.tests" + j + "0.performance" + j, false/*not partial match*/, requestor);
324
			}
325
			stopMeasuring();
326
		}
327
		commitMeasurements();
328
		assertPerformance();
329
	} finally {
330
		deleteProject("P");
331
	}
332
}
333
}
268
}
334
269
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+28 lines)
Lines 2816-2821 Link Here
2816
		"Unexpected all type names",
2816
		"Unexpected all type names",
2817
		"Test\n" + 
2817
		"Test\n" + 
2818
		"Test$Inner\n" + 
2818
		"Test$Inner\n" + 
2819
		"b108088.A108088\n" + 
2820
		"b108088.B108088\n" + 
2821
		"b108088.Test108088\n" + 
2819
		"b81556.a.A81556\n" + 
2822
		"b81556.a.A81556\n" + 
2820
		"b81556.a.B81556\n" + 
2823
		"b81556.a.B81556\n" + 
2821
		"b81556.a.X81556\n" + 
2824
		"b81556.a.X81556\n" + 
Lines 2878-2883 Link Here
2878
		"Unexpected all type names",
2881
		"Unexpected all type names",
2879
		"Test\n" + 
2882
		"Test\n" + 
2880
		"Test$Inner\n" + 
2883
		"Test$Inner\n" + 
2884
		"b108088.A108088\n" + 
2885
		"b108088.B108088\n" + 
2886
		"b108088.Test108088\n" + 
2881
		"b81556.a.A81556\n" + 
2887
		"b81556.a.A81556\n" + 
2882
		"b81556.a.B81556\n" + 
2888
		"b81556.a.B81556\n" + 
2883
		"b81556.a.X81556\n" + 
2889
		"b81556.a.X81556\n" + 
Lines 2935-2940 Link Here
2935
		"Unexpected all type names",
2941
		"Unexpected all type names",
2936
		"Test\n" + 
2942
		"Test\n" + 
2937
		"Test$Inner\n" + 
2943
		"Test$Inner\n" + 
2944
		"b108088.A108088\n" + 
2945
		"b108088.B108088\n" + 
2946
		"b108088.Test108088\n" + 
2938
		"b81556.a.A81556\n" + 
2947
		"b81556.a.A81556\n" + 
2939
		"b81556.a.B81556\n" + 
2948
		"b81556.a.B81556\n" + 
2940
		"b81556.a.X81556\n" + 
2949
		"b81556.a.X81556\n" + 
Lines 2995-3000 Link Here
2995
		"Unexpected all type names",
3004
		"Unexpected all type names",
2996
		"Test\n" + 
3005
		"Test\n" + 
2997
		"Test$Inner\n" + 
3006
		"Test$Inner\n" + 
3007
		"b108088.A108088\n" + 
3008
		"b108088.B108088\n" + 
3009
		"b108088.Test108088\n" + 
2998
		"b81556.a.A81556\n" + 
3010
		"b81556.a.A81556\n" + 
2999
		"b81556.a.B81556\n" + 
3011
		"b81556.a.B81556\n" + 
3000
		"b81556.a.X81556\n" + 
3012
		"b81556.a.X81556\n" + 
Lines 4458-4463 Link Here
4458
}
4470
}
4459
4471
4460
/**
4472
/**
4473
 * Bug 108088: [search] Inaccurate search match for method invocations with literal arguments
4474
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=108088"
4475
 */
4476
public void testBug108088() throws CoreException {
4477
	ICompilationUnit unit = getCompilationUnit("JavaSearchBugs", "src", "b108088", "Test108088.java");
4478
	IType type = unit.getType("A108088");
4479
	IMethod method = type.getMethod("subroutine", new String[] { "F" });
4480
	SearchPattern pattern = SearchPattern.createPattern(method, REFERENCES, EXACT_RULE);
4481
	assertNotNull("Pattern should not be null", pattern);
4482
	search(pattern, getJavaSearchScopeBugs(), resultCollector);
4483
	assertSearchResults(
4484
		"src/b108088/B108088.java void b108088.B108088.doit(A108088, String) [subroutine(1.2f)] EXACT_MATCH"
4485
	);
4486
}
4487
4488
/**
4461
 * @test Bug 110060: [plan][search] Add support for Camel Case search pattern
4489
 * @test Bug 110060: [plan][search] Add support for Camel Case search pattern
4462
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=110060"
4490
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=110060"
4463
 */
4491
 */
(-)src/org/eclipse/jdt/core/tests/model/ClassNameTests.java (-13 / +398 lines)
Lines 11-36 Link Here
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import junit.framework.Test;
13
import junit.framework.Test;
14
import junit.framework.TestSuite;
15
14
16
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.NullProgressMonitor;
17
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.jdt.core.IClasspathEntry;
18
import org.eclipse.jdt.core.*;
20
import org.eclipse.jdt.core.IJavaProject;
19
import org.eclipse.jdt.core.dom.AST;
21
import org.eclipse.jdt.core.IType;
20
import org.eclipse.jdt.internal.core.SourceType;
22
import org.eclipse.jdt.core.JavaCore;
21
23
import org.eclipse.jdt.core.JavaModelException;
22
24
/**
23
/**
25
 * Test retrieving types by their name.
24
 * Test retrieving types by their name.
26
 */
25
 */
27
public class ClassNameTests extends ModifyingResourceTests {
26
public class ClassNameTests extends ModifyingResourceTests {
28
27
28
	static IJavaProject TEST_PROJECT;
29
	final static int SF_LENGTH = 5;
30
	static int TESTS_COUNT;
29
31
30
	public ClassNameTests(String name) {
32
	public ClassNameTests(String name) {
31
		super(name);
33
		super(name);
32
	}
34
	}
33
	
35
36
	static {
37
//		org.eclipse.jdt.internal.core.NameLookup.VERBOSE = true;
38
//		TESTS_NAMES = new String[] { "testReconcileMultipleProject" };
39
//		TESTS_PREFIX = "testReconcile";
40
	}
41
	public static Test suite() {
42
		Test suite = buildTestSuite(ClassNameTests.class);
43
		TESTS_COUNT = suite.countTestCases();
44
		return suite;
45
	}
46
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#setUp()
49
	 */
50
	protected void setUp() throws Exception {
51
		if (org.eclipse.jdt.internal.core.NameLookup.VERBOSE || org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE) {
52
			System.out.println("--------------------------------------------------------------------------------");
53
			System.out.println("Running test "+getName()+"...");
54
		}
55
		super.setUp();
56
		if (TEST_PROJECT == null) {
57
			String[] sourceFolders = new String[SF_LENGTH];
58
			for (int i=0; i<SF_LENGTH; i++) {
59
				sourceFolders[i] = "src" + i;
60
			}
61
			TEST_PROJECT = createJavaProject("TestProject", sourceFolders, new String[] {"JCL_LIB"}, "bin");
62
			createFolder("/TestProject/src0/org/eclipse/jdt/core/test0");
63
			createFile(
64
				"/TestProject/src0/org/eclipse/jdt/core/test0/Foo.java", 
65
				"package org.eclipse.jdt.core.test0;\n" +
66
				"public class Foo {\n" +
67
				"	class InFoo {}\n" +
68
				"}\n" +
69
				"class Secondary {\n" +
70
				"	class InSecondary {}\n" +
71
				"}\n"
72
			);
73
			createFile(
74
				"/TestProject/src1/Foo.java", 
75
				"public class Foo {\n" +
76
				"	class InFoo {}\n" +
77
				"}\n" +
78
				"class Secondary {\n" +
79
				"	class InSecondary {}\n" +
80
				"}\n"
81
			);
82
			int length = SF_LENGTH - 1;
83
			createFolder("/TestProject/src"+length+"/org/eclipse/jdt/core/test"+length);
84
			createFile(
85
				"/TestProject/src"+length+"/org/eclipse/jdt/core/test"+length+"/Foo.java", 
86
				"package org.eclipse.jdt.core.test"+length+";\n" +
87
				"public class Foo {\n" +
88
				"}\n" +
89
				"class Secondary {\n" +
90
				"}\n"
91
			);
92
			createFile(
93
				"/TestProject/src"+length+"/org/eclipse/jdt/core/test"+length+"/Test.java", 
94
				"package org.eclipse.jdt.core.test"+length+";\n" +
95
				"public class Test {\n" +
96
				"	public static void main(String[] args) {\n" +
97
				"		Secondary s = new Secondary();\n" +
98
				"	}\n" +
99
				"}\n"
100
			);
101
		}
102
	}
103
104
	/* (non-Javadoc)
105
	 * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#tearDown()
106
	 */
107
	protected void tearDown() throws Exception {
108
		TESTS_COUNT--;
109
		if (TEST_PROJECT != null && TESTS_COUNT == 0) {
110
			deleteResource(TEST_PROJECT.getProject());
111
		}
112
		super.tearDown();
113
	}
114
115
	protected void assertTypeFound(String typeName, String expectedResult) throws JavaModelException {
116
		assertNotNull("TEST_PROJECT should not be null!!!", TEST_PROJECT);
117
		IType type = TEST_PROJECT.findType(typeName);
118
		assertTrue("type "+typeName+" should exist!", type != null && type.exists());
119
		assertEquals("Expected type "+typeName+" NOT found!",
120
			expectedResult,
121
			((SourceType)type).toStringWithAncestors()
122
		);
123
	}
124
	protected void assertTypeFound(String packageName, String typeName, String expectedResult) throws JavaModelException {
125
		assertNotNull("TEST_PROJECT should not be null!!!", TEST_PROJECT);
126
		IType type = TEST_PROJECT.findType(packageName, typeName);
127
		assertTrue("type "+typeName+" should exist!", type != null && type.exists());
128
		assertEquals("Expected type "+typeName+" NOT found!",
129
			expectedResult,
130
			((SourceType)type).toStringWithAncestors()
131
		);
132
	}
133
134
	protected void assertTypeNotFound(String typeName) throws JavaModelException {
135
		assertNotNull("TEST_PROJECT should not be null!!!", TEST_PROJECT);
136
		IType type = TEST_PROJECT.findType(typeName);
137
		assertNotNull("type "+typeName+" should NOT be null!", type);
138
		assertFalse("type "+typeName+" should NOT exist!", type.exists());
139
	}
140
	protected void assertTypeNotFound(String packageName, String typeName) throws JavaModelException {
141
		assertNotNull("TEST_PROJECT should not be null!!!", TEST_PROJECT);
142
		IType type = TEST_PROJECT.findType(packageName, typeName);
143
		assertNotNull("type "+typeName+" should NOT be null!", type);
144
		assertFalse("type "+typeName+" should NOT exist!", type.exists());
145
	}
146
147
	protected void assertTypeUnknown(String typeName) throws JavaModelException {
148
		assertNotNull("TEST_PROJECT should not be null!!!", TEST_PROJECT);
149
		IType type = TEST_PROJECT.findType(typeName);
150
		assertNull("type "+typeName+" should NOT be found!", type);
151
	}
152
	protected void assertTypeUnknown(String packageName, String typeName) throws JavaModelException {
153
		assertNotNull("TEST_PROJECT should not be null!!!", TEST_PROJECT);
154
		IType type = TEST_PROJECT.findType(packageName, typeName);
155
		assertNull("type "+typeName+" should NOT be found!", type);
156
	}
157
34
	/**
158
	/**
35
	 * Tests that a type in a jar with a name ending with $ can be retrieved.
159
	 * Tests that a type in a jar with a name ending with $ can be retrieved.
36
	 */
160
	 */
Lines 945-957 Link Here
945
		}
1069
		}
946
	}
1070
	}
947
1071
948
	public static Test suite() {
1072
	/**
949
		TestSuite suite = new Suite(ClassNameTests.class.getName());
1073
	 * Bug 36032: JavaProject.findType() fails to find second type in source file
950
		suite.addTest(new ClassNameTests("testClassNameWithDollar"));
1074
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=36032"
951
		suite.addTest(new ClassNameTests("testFindTypeWithDot"));
1075
	 */
952
		suite.addTest(new ClassNameTests("testSearchTypeNameInJars"));
1076
	public void testFindSecondaryType_Exist01() throws JavaModelException, CoreException {
953
		return suite;
1077
		int length = SF_LENGTH - 1;
1078
		assertTypeFound(
1079
			"org.eclipse.jdt.core.test"+length+".Foo",
1080
			"Foo [in Foo.java [in org.eclipse.jdt.core.test"+length+" [in src"+length+" [in TestProject]]]]"
1081
		);
1082
	}
1083
	public void testFindSecondaryType_Exist02() throws JavaModelException, CoreException {
1084
		int length = SF_LENGTH - 1;
1085
		assertTypeFound(
1086
			"org.eclipse.jdt.core.test"+length+".Secondary",
1087
			"Secondary [in Foo.java [in org.eclipse.jdt.core.test"+length+" [in src"+length+" [in TestProject]]]]"
1088
		);
1089
	}
1090
	public void testFindSecondaryType_Exist03() throws JavaModelException, CoreException {
1091
		assertTypeFound(
1092
			"org.eclipse.jdt.core.test0.Foo.InFoo",
1093
			"InFoo [in Foo [in Foo.java [in org.eclipse.jdt.core.test0 [in src0 [in TestProject]]]]]"
1094
		);
1095
	}
1096
	public void testFindSecondaryType_Exist04() throws JavaModelException, CoreException {
1097
		assertTypeFound(
1098
			"org.eclipse.jdt.core.test0.Secondary.InSecondary",
1099
			"InSecondary [in Secondary [in Foo.java [in org.eclipse.jdt.core.test0 [in src0 [in TestProject]]]]]"
1100
		);
1101
	}
1102
	public void testFindSecondaryType_Exist05() throws JavaModelException, CoreException {
1103
		assertTypeFound(
1104
			"Foo",
1105
			"Foo [in Foo.java [in <default> [in src1 [in TestProject]]]]"
1106
		);
1107
	}
1108
	public void testFindSecondaryType_Exist06() throws JavaModelException, CoreException {
1109
		assertTypeFound(
1110
			"Secondary",
1111
			"Secondary [in Foo.java [in <default> [in src1 [in TestProject]]]]"
1112
		);
954
	}
1113
	}
1114
	// duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=72179
1115
	public void testFindSecondaryType_Bug72179() throws JavaModelException, CoreException {
1116
		try {
1117
			IJavaProject javaProject = createJavaProject("P", new String[] {""}, "");
1118
			createFolder("/P/p1");
1119
			createFile(
1120
				"/P/p1/jc.java", 
1121
				"package p1;\n" +
1122
				"class jc008{}\n" +
1123
				"class jc009{}\n" +
1124
				"class jc010 extends jc009 {\n" +
1125
				"	jc008 a;\n" +
1126
				"}\n"
1127
			);
1128
			IType type = javaProject.findType("p1", "jc008");
1129
			assertTrue("type 'jc008' should exist!", type != null && type.exists());
1130
			assertEquals("Expected type 'jc008' NOT found!",
1131
				"class jc008 [in jc.java [in p1 [in <project root> [in P]]]]",
1132
				type.toString()
1133
			);
1134
			type = javaProject.findType("p1", "jc009");
1135
			assertTrue("type 'jc009' should exist!", type != null && type.exists());
1136
			assertEquals("Expected type 'jc009' NOT found!",
1137
				"class jc009 [in jc.java [in p1 [in <project root> [in P]]]]",
1138
				type.toString()
1139
			);
1140
			type = javaProject.findType("p1", "jc010");
1141
			assertTrue("type 'jc010' should exist!", type != null && type.exists());
1142
			assertEquals("Expected type 'jc010' NOT found!",
1143
				"class jc010 [in jc.java [in p1 [in <project root> [in P]]]]\n" +
1144
				"  jc008 a",
1145
				type.toString()
1146
			);
1147
		} finally {
1148
			deleteProject("P");
1149
		}
1150
	}
1151
	public void testFindSecondaryType_NotFound01() throws JavaModelException, CoreException {
1152
		assertTypeUnknown("test.Foo");
1153
	}
1154
	public void testFindSecondaryType_NotFound02() throws JavaModelException, CoreException {
1155
		assertTypeUnknown("InFoo");
1156
	}
1157
	public void testFindSecondaryType_NotFound03() throws JavaModelException, CoreException {
1158
		assertTypeUnknown("InSecondary");
1159
	}
1160
	public void testFindSecondaryType_NotFound04() throws JavaModelException, CoreException {
1161
		assertTypeUnknown("Foo.inFoo");
1162
	}
1163
	public void testFindSecondaryType_NotFound05() throws JavaModelException, CoreException {
1164
		assertTypeUnknown("Secondary.inBar");
1165
	}
1166
	public void testFindSecondaryType_Unknown01() throws JavaModelException, CoreException {
1167
		assertTypeUnknown("Unknown");
1168
	}
1169
	public void testFindSecondaryType_Unknown02() throws JavaModelException, CoreException {
1170
		assertTypeUnknown("Foo.Unknown");
1171
	}
1172
	public void testFindSecondaryType_Unknown03() throws JavaModelException, CoreException {
1173
		assertTypeUnknown("org.eclipse.jdt.core.test.Unknown");
1174
	}
1175
	public void testReconcileSingleProject01() throws CoreException {
1176
		ICompilationUnit workingCopy = null;
1177
		try {
1178
			createJavaProject("P", new String[] {""}, new String[] {"JCL_LIB"}, "bin");
1179
			String source = 
1180
				"public class Test {\n" + 
1181
				"	public static void main(String[] args) {\n" + 
1182
				"		new SFoo().foo();\n" + 
1183
				"	}\n" + 
1184
				"}\n";
1185
			this.createFile(
1186
				"/P/Foo.java", 
1187
				"class SFoo { void foo() {} }\n"
1188
			);
1189
			this.createFile(
1190
				"/P/Test.java", 
1191
				source
1192
			);
1193
			ProblemRequestor problemRequestor =  new ProblemRequestor();
1194
			workingCopy = getCompilationUnit("/P/Test.java").getWorkingCopy(new WorkingCopyOwner() {}, problemRequestor, null);
1195
			problemRequestor.initialize(source.toCharArray());
1196
			workingCopy.getBuffer().setContents(source);
1197
			workingCopy.reconcile(AST.JLS3, true, null, null);
1198
			if (problemRequestor.problemCount > 0) {
1199
				assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
1200
			}
955
1201
1202
			// Add new secondary type
1203
			this.createFile(
1204
				"/P/Bar.java", 
1205
				"class SBar{ void bar() {} }\n"
1206
			);
1207
			waitUntilIndexesReady();
1208
			source = 
1209
				"public class Test {\n" + 
1210
				"	public static void main(String[] args) {\n" + 
1211
				"		new SFoo().foo();\n" + 
1212
				"		new SBar().bar();\n" + 
1213
				"	}\n" + 
1214
				"}\n";
1215
			problemRequestor.initialize(source.toCharArray());
1216
			workingCopy.getBuffer().setContents(source);
1217
			workingCopy.reconcile(AST.JLS3, true, null, null);
1218
			if (problemRequestor.problemCount > 0) {
1219
				assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
1220
			}
1221
		} finally {
1222
			if (workingCopy != null) workingCopy.discardWorkingCopy();
1223
			deleteProject("P");
1224
		}
1225
	}
1226
	public void testReconcileSingleProject02() throws CoreException {
1227
		ICompilationUnit workingCopy = null;
1228
		try {
1229
			createJavaProject("P", new String[] {""}, new String[] {"JCL_LIB"}, "bin");
1230
			String source = 
1231
				"public class Test {\n" + 
1232
				"	public static void main(String[] args) {\n" + 
1233
				"		new SFoo().foo();\n" + 
1234
				"		new SBar().bar();\n" + 
1235
				"	}\n" + 
1236
				"}\n";
1237
			createFile(
1238
				"/P/Foo.java", 
1239
				"class SFoo { void foo() {} }\n"
1240
			);
1241
			createFile(
1242
				"/P/Test.java", 
1243
				source
1244
			);
1245
			createFile(
1246
				"/P/Bar.java", 
1247
				"class SBar{ void bar() {} }\n"
1248
			);
1249
			ProblemRequestor problemRequestor =  new ProblemRequestor();
1250
			workingCopy = getCompilationUnit("/P/Test.java").getWorkingCopy(new WorkingCopyOwner() {}, problemRequestor, null);
1251
			problemRequestor.initialize(source.toCharArray());
1252
			workingCopy.getBuffer().setContents(source);
1253
			workingCopy.reconcile(AST.JLS3, true, null, null);
1254
			if (problemRequestor.problemCount > 0) {
1255
				assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
1256
			}
956
1257
1258
			// Delete secondary type => should get a problem
1259
			waitUntilIndexesReady();
1260
			deleteFile("/P/Bar.java");
1261
			workingCopy.reconcile(AST.JLS3, true, null, null);
1262
			assertEquals("Working copy should not find secondary type 'Bar'!", 1, problemRequestor.problemCount);
1263
			assertEquals("Working copy should have problem!",
1264
				"----------\n" +
1265
				"----------\n" +
1266
				"----------\n" +
1267
				"1. ERROR in /P/Test.java (at line 4)\r\n" +
1268
				"	new SBar().bar();\r\n" +
1269
				"	    ^^^^\n" +
1270
				"SBar cannot be resolved to a type\n" +
1271
				"----------\n",
1272
				problemRequestor.problems.toString()
1273
			);
1274
1275
			// Fix the problem
1276
			source = 
1277
				"public class Test {\n" + 
1278
				"	public static void main(String[] args) {\n" + 
1279
				"		new SFoo().foo();\n" + 
1280
				"	}\n" + 
1281
				"}\n";
1282
			problemRequestor.initialize(source.toCharArray());
1283
			workingCopy.getBuffer().setContents(source);
1284
			workingCopy.reconcile(AST.JLS3, true, null, null);
1285
			if (problemRequestor.problemCount > 0) {
1286
				assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
1287
			}
1288
		} finally {
1289
			if (workingCopy != null) workingCopy.discardWorkingCopy();
1290
			deleteProject("P");
1291
		}
1292
	}
1293
	public void testReconcileMultipleProject() throws CoreException {
1294
		ICompilationUnit workingCopy = null;
1295
		try {
1296
			// Create first project
1297
			createJavaProject("P1", new String[] {""}, new String[] {"JCL_LIB"}, "bin");
1298
			createFolder("/P1/test");
1299
			createFile(
1300
				"/P1/test/Foo.java", 
1301
				"package test;\n" +
1302
				"class Secondary{ void foo() {} }\n"
1303
			);
1304
			createFile(
1305
				"/P1/test/Test1.java", 
1306
				"package test;\n" +
1307
				"public class Test1 {\n" + 
1308
				"	public static void main(String[] args) {\n" + 
1309
				"		new Secondary().foo();\n" + 
1310
				"	}\n" + 
1311
				"}\n"
1312
			);
1313
1314
			// Create second project
1315
			createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] { "/P1" }, "bin");
1316
			String source2 = 
1317
				"package test;\n" +
1318
				"public class Test2 {\n" + 
1319
				"	public static void main(String[] args) {\n" + 
1320
				"		new Secondary().foo();\n" + 
1321
				"	}\n" + 
1322
				"}\n";
1323
			createFolder("/P2/test");
1324
			createFile(
1325
				"/P2/test/Test2.java", 
1326
				source2
1327
			);
1328
			ProblemRequestor problemRequestor =  new ProblemRequestor();
1329
			workingCopy = getCompilationUnit("/P2/test/Test2.java").getWorkingCopy(new WorkingCopyOwner() {}, problemRequestor, null);
1330
			problemRequestor.initialize(source2.toCharArray());
1331
			workingCopy.getBuffer().setContents(source2);
1332
			workingCopy.reconcile(AST.JLS3, true, null, null);
1333
			if (problemRequestor.problemCount > 0) {
1334
				assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
1335
			}
1336
		} finally {
1337
			if (workingCopy != null) workingCopy.discardWorkingCopy();
1338
			deleteProject("P1");
1339
			deleteProject("P2");
1340
		}
1341
	}
957
}
1342
}
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java (-4 / +16 lines)
Lines 32-39 Link Here
32
	}
32
	}
33
33
34
	static {
34
	static {
35
//		TESTS_NAMES = new String[] {"test0602"};
35
//		TESTS_NUMBERS = new int[] { 356 };
36
//		TESTS_NUMBERS =  new int[] { 368, 369 };
37
	}
36
	}
38
	public static Test suite() {
37
	public static Test suite() {
39
		return buildTestSuite(ASTConverterAST3Test.class);
38
		return buildTestSuite(ASTConverterAST3Test.class);
Lines 8699-8712 Link Here
8699
		assertNotNull("No compilation unit", result); //$NON-NLS-1$
8698
		assertNotNull("No compilation unit", result); //$NON-NLS-1$
8700
		assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
8699
		assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
8701
		CompilationUnit compilationUnit = (CompilationUnit) result;
8700
		CompilationUnit compilationUnit = (CompilationUnit) result;
8702
		assertEquals("errors found", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
8701
		assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
8703
		ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
8702
		ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
8704
		assertNotNull(node);
8703
		assertNotNull(node);
8705
		assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
8704
		assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
8706
		VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
8705
		VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
8707
		Type type = variableDeclarationStatement.getType();
8706
		Type type = variableDeclarationStatement.getType();
8708
		ITypeBinding binding = type.resolveBinding();
8707
		ITypeBinding binding = type.resolveBinding();
8709
		assertNull(binding);
8708
		assertNotNull("Binding should NOT be null for type: "+type, binding);
8709
8710
		// Verify that class instance creation has a null binding
8711
		List fragments = variableDeclarationStatement.fragments();
8712
		assertEquals("Expect only one fragment for VariableDeclarationStatement: "+variableDeclarationStatement, 1, fragments.size());
8713
		node = (ASTNode) fragments.get(0);
8714
		assertEquals("Not a variable declaration fragment", ASTNode.VARIABLE_DECLARATION_FRAGMENT, node.getNodeType()); //$NON-NLS-1$
8715
		VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
8716
		Expression initializer = fragment.getInitializer();
8717
		assertEquals("Expect a class instance creation for initializer: "+initializer, ASTNode.CLASS_INSTANCE_CREATION, initializer.getNodeType()); //$NON-NLS-1$
8718
		ClassInstanceCreation instanceCreation = (ClassInstanceCreation) initializer;
8719
		type = instanceCreation.getType();
8720
		binding = type.resolveBinding();
8721
		assertNull("Binding should BE null for type: "+type, binding);
8710
	}
8722
	}
8711
	
8723
	
8712
	/**
8724
	/**
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java (-4 / +4 lines)
Lines 32-40 Link Here
32
	public ASTConverterTest(String name) {
32
	public ASTConverterTest(String name) {
33
		super(name);
33
		super(name);
34
	}
34
	}
35
35
	static {
36
	static {
36
//		TESTS_NAMES = new String[] {"test0602"};
37
//		TESTS_NUMBERS = new int[] { 356 };
37
//		TESTS_NUMBERS =  new int[] { 618 };
38
	}
38
	}
39
	public static Test suite() {
39
	public static Test suite() {
40
		return buildTestSuite(ASTConverterTest.class);
40
		return buildTestSuite(ASTConverterTest.class);
Lines 8868-8881 Link Here
8868
		assertNotNull("No compilation unit", result); //$NON-NLS-1$
8868
		assertNotNull("No compilation unit", result); //$NON-NLS-1$
8869
		assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
8869
		assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
8870
		CompilationUnit compilationUnit = (CompilationUnit) result;
8870
		CompilationUnit compilationUnit = (CompilationUnit) result;
8871
		assertEquals("errors found", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
8871
		assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
8872
		ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
8872
		ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
8873
		assertNotNull(node);
8873
		assertNotNull(node);
8874
		assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
8874
		assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
8875
		VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
8875
		VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
8876
		Type type = variableDeclarationStatement.getType();
8876
		Type type = variableDeclarationStatement.getType();
8877
		ITypeBinding binding = type.resolveBinding();
8877
		ITypeBinding binding = type.resolveBinding();
8878
		assertNull(binding);
8878
		assertNotNull("Binding should NOT be null for type: "+type, binding);
8879
	}
8879
	}
8880
	
8880
	
8881
	/**
8881
	/**
(-)workspace/JavaSearchBugs/src/b108088/B108088.java (+7 lines)
Added Link Here
1
package b108088;
2
class B108088 {
3
	public void doit(A108088 pApp, String doitArg) {
4
	    pApp.subroutine(1.2f);
5
	}
6
    
7
}
(-)workspace/JavaSearchBugs/src/b108088/Test108088.java (+12 lines)
Added Link Here
1
package b108088;
2
class A108088 {
3
    B108088 fB;
4
    public void subroutine(float subArg) {
5
        subsub();
6
    }
7
    public void subsub() {
8
    }
9
    
10
}
11
public class Test108088 {
12
}

Return to bug 36032