### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: search/org/eclipse/jdt/internal/core/index/DiskIndex.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java,v
retrieving revision 1.40
diff -u -r1.40 DiskIndex.java
--- search/org/eclipse/jdt/internal/core/index/DiskIndex.java 17 Nov 2005 11:10:02 -0000 1.40
+++ search/org/eclipse/jdt/internal/core/index/DiskIndex.java 22 Nov 2005 18:44:50 -0000
@@ -35,7 +35,7 @@
private HashtableOfObject categoryTables; // category name -> HashtableOfObject(words -> int[] of document #'s) or offset if not read yet
private char[] cachedCategoryName;
-public static final String SIGNATURE= "INDEX VERSION 1.106"; //$NON-NLS-1$
+public static final String SIGNATURE= "INDEX VERSION 1.107"; //$NON-NLS-1$
public static boolean DEBUG = false;
private static final int RE_INDEXED = -1;
Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v
retrieving revision 1.329
diff -u -r1.329 Parser.java
--- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 11 Nov 2005 23:44:39 -0000 1.329
+++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 22 Nov 2005 18:44:41 -0000
@@ -1109,6 +1109,14 @@
// remove the position of the '@' token as we don't have modifiers
annotationTypeDeclaration.declarationSourceStart = atPosition;
}
+
+ // Store secondary info
+ if ((annotationTypeDeclaration.bits & ASTNode.IsMemberType) == 0 && (annotationTypeDeclaration.bits & ASTNode.IsLocalType) == 0) {
+ if (this.compilationUnit != null && !CharOperation.equals(annotationTypeDeclaration.name, this.compilationUnit.getMainTypeName())) {
+ annotationTypeDeclaration.bits |= ASTNode.IsSecondaryType;
+ }
+ }
+
// consume annotations
int length;
if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
@@ -1873,6 +1881,14 @@
if (typeDecl.modifiersSourceStart >= 0) {
typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
}
+
+ // Store secondary info
+ if ((typeDecl.bits & ASTNode.IsMemberType) == 0 && (typeDecl.bits & ASTNode.IsLocalType) == 0) {
+ if (this.compilationUnit != null && !CharOperation.equals(typeDecl.name, this.compilationUnit.getMainTypeName())) {
+ typeDecl.bits |= ASTNode.IsSecondaryType;
+ }
+ }
+
// consume annotations
int length;
if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
@@ -2745,7 +2761,15 @@
enumConstant.modifiersSourceStart = this.intStack[this.intPtr--];
enumConstant.modifiers = this.intStack[this.intPtr--];
enumConstant.declarationSourceStart = enumConstant.modifiersSourceStart;
- // consume annotations
+
+ // Store secondary info
+ if ((enumConstant.bits & ASTNode.IsMemberType) == 0 && (enumConstant.bits & ASTNode.IsLocalType) == 0) {
+ if (this.compilationUnit != null && !CharOperation.equals(enumConstant.name, this.compilationUnit.getMainTypeName())) {
+ enumConstant.bits |= ASTNode.IsSecondaryType;
+ }
+ }
+
+ // consume annotations
int length;
if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
System.arraycopy(
@@ -3456,6 +3480,14 @@
if (typeDecl.modifiersSourceStart >= 0) {
typeDecl.declarationSourceStart = typeDecl.modifiersSourceStart;
}
+
+ // Store secondary info
+ if ((typeDecl.bits & ASTNode.IsMemberType) == 0 && (typeDecl.bits & ASTNode.IsLocalType) == 0) {
+ if (this.compilationUnit != null && !CharOperation.equals(typeDecl.name, this.compilationUnit.getMainTypeName())) {
+ typeDecl.bits |= ASTNode.IsSecondaryType;
+ }
+ }
+
// consume annotations
int length;
if ((length = this.expressionLengthStack[this.expressionLengthPtr--]) != 0) {
Index: search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java,v
retrieving revision 1.34
diff -u -r1.34 SourceIndexerRequestor.java
--- search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java 7 Sep 2005 07:45:57 -0000 1.34
+++ search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java 22 Nov 2005 18:44:51 -0000
@@ -137,7 +137,7 @@
} else {
typeNames = this.enclosingTypeNames();
}
- this.indexer.addAnnotationTypeDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames);
+ this.indexer.addAnnotationTypeDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.secondary);
this.pushTypeName(typeInfo.name);
}
@@ -170,7 +170,7 @@
typeParameterSignatures[i] = Signature.createTypeParameterSignature(typeParameterInfo.name, typeParameterInfo.bounds == null ? CharOperation.NO_CHAR_CHAR : typeParameterInfo.bounds);
}
}
- this.indexer.addClassDeclaration(typeInfo.modifiers, this.packageName, typeInfo.name, typeNames, typeInfo.superclass, typeInfo.superinterfaces, typeParameterSignatures);
+ this.indexer.addClassDeclaration(typeInfo.modifiers, this.packageName, typeInfo.name, typeNames, typeInfo.superclass, typeInfo.superinterfaces, typeParameterSignatures, typeInfo.secondary);
this.pushTypeName(typeInfo.name);
}
/**
@@ -199,7 +199,7 @@
} else {
typeNames = this.enclosingTypeNames();
}
- this.indexer.addEnumDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces);
+ this.indexer.addEnumDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces, typeInfo.secondary);
this.pushTypeName(typeInfo.name);
}
/**
@@ -237,7 +237,7 @@
typeParameterSignatures[i] = Signature.createTypeParameterSignature(typeParameterInfo.name, typeParameterInfo.bounds);
}
}
- this.indexer.addInterfaceDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces, typeParameterSignatures);
+ this.indexer.addInterfaceDeclaration(typeInfo.modifiers, packageName, typeInfo.name, typeNames, typeInfo.superinterfaces, typeParameterSignatures, typeInfo.secondary);
this.pushTypeName(typeInfo.name);
}
/**
Index: search/org/eclipse/jdt/internal/core/search/indexing/IIndexConstants.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IIndexConstants.java,v
retrieving revision 1.29
diff -u -r1.29 IIndexConstants.java
--- search/org/eclipse/jdt/internal/core/search/indexing/IIndexConstants.java 26 Apr 2005 18:55:07 -0000 1.29
+++ search/org/eclipse/jdt/internal/core/search/indexing/IIndexConstants.java 22 Nov 2005 18:44:51 -0000
@@ -36,6 +36,7 @@
char CLASS_AND_ENUM_SUFFIX = IJavaSearchConstants.CLASS_AND_ENUM;
char CLASS_AND_INTERFACE_SUFFIX = IJavaSearchConstants.CLASS_AND_INTERFACE;
char SEPARATOR= '/';
+ char SECONDARY_SUFFIX = 'S';
char[] ONE_STAR = new char[] {'*'};
char[][] ONE_STAR_CHAR = new char[][] {ONE_STAR};
Index: search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java,v
retrieving revision 1.34
diff -u -r1.34 SourceIndexer.java
--- search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java 9 Mar 2005 15:34:51 -0000 1.34
+++ search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexer.java 22 Nov 2005 18:44:51 -0000
@@ -59,12 +59,14 @@
requestor,
this.problemFactory,
new CompilerOptions(options),
- true/*index local declarations*/,
- true/*optimize string literals*/);
+ true, // index local declarations
+ true, // optimize string literals
+ false); // do not use source javadoc parser to speed up parsing
parser.reportOnlyOneSyntaxError = true;
// Always check javadoc while indexing
parser.javadocParser.checkDocComment = true;
+ parser.javadocParser.reportProblems = false;
// Launch the parser
char[] source = null;
Index: search/org/eclipse/jdt/internal/core/search/indexing/InternalSearchDocument.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/InternalSearchDocument.java,v
retrieving revision 1.3
diff -u -r1.3 InternalSearchDocument.java
--- search/org/eclipse/jdt/internal/core/search/indexing/InternalSearchDocument.java 7 Apr 2005 10:37:29 -0000 1.3
+++ search/org/eclipse/jdt/internal/core/search/indexing/InternalSearchDocument.java 22 Nov 2005 18:44:51 -0000
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.jdt.internal.core.search.indexing;
+import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.core.index.Index;
/**
@@ -22,8 +23,17 @@
* Hidden by API SearchDocument subclass
*/
public void addIndexEntry(char[] category, char[] key) {
- if (this.index != null)
+ if (this.index != null) {
index.addIndexEntry(category, key, getContainerRelativePath());
+ if (category == IIndexConstants.TYPE_DECL && key != null) {
+ int length = key.length;
+ if (length > 1 && key[length-2] == IIndexConstants.SEPARATOR && key[length-1] == IIndexConstants.SECONDARY_SUFFIX ) {
+ // This is a key of a secondary type => reset java model manager secondary types cache for document path project
+ JavaModelManager manager = JavaModelManager.getJavaModelManager();
+ manager.resetSecondaryTypesCache(getPath());
+ }
+ }
+ }
}
private String getContainerRelativePath() {
if (this.containerRelativePath == null)
Index: search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java,v
retrieving revision 1.32
diff -u -r1.32 AbstractIndexer.java
--- search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java 25 May 2005 11:09:39 -0000 1.32
+++ search/org/eclipse/jdt/internal/core/search/indexing/AbstractIndexer.java 22 Nov 2005 18:44:51 -0000
@@ -23,8 +23,9 @@
public AbstractIndexer(SearchDocument document) {
this.document = document;
}
- public void addAnnotationTypeDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames) {
- addIndexEntry(TYPE_DECL, TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames));
+ public void addAnnotationTypeDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, boolean secondary) {
+ char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
+ addIndexEntry(TYPE_DECL, indexKey);
addIndexEntry(
SUPER_REF,
@@ -38,8 +39,10 @@
char[][] enclosingTypeNames,
char[] superclass,
char[][] superinterfaces,
- char[][] typeParameterSignatures) {
- addIndexEntry(TYPE_DECL, TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames));
+ char[][] typeParameterSignatures,
+ boolean secondary) {
+ char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
+ addIndexEntry(TYPE_DECL, indexKey);
if (superclass != null) {
superclass = erasure(superclass);
@@ -84,9 +87,10 @@
if (innermostTypeName != simpleTypeName)
addIndexEntry(CONSTRUCTOR_REF, ConstructorPattern.createIndexKey(innermostTypeName, argCount));
}
- public void addEnumDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces) {
- addIndexEntry(TYPE_DECL, TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames));
-
+ public void addEnumDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces, boolean secondary) {
+ char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
+ addIndexEntry(TYPE_DECL, indexKey);
+
addIndexEntry(
SUPER_REF,
SuperTypeReferencePattern.createIndexKey(
@@ -112,8 +116,9 @@
protected void addIndexEntry(char[] category, char[] key) {
this.document.addIndexEntry(category, key);
}
- public void addInterfaceDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces, char[][] typeParameterSignatures) {
- addIndexEntry(TYPE_DECL, TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames));
+ public void addInterfaceDeclaration(int modifiers, char[] packageName, char[] name, char[][] enclosingTypeNames, char[][] superinterfaces, char[][] typeParameterSignatures, boolean secondary) {
+ char[] indexKey = TypeDeclarationPattern.createIndexKey(modifiers, name, packageName, enclosingTypeNames, secondary);
+ addIndexEntry(TYPE_DECL, indexKey);
if (superinterfaces != null) {
for (int i = 0, max = superinterfaces.length; i < max; i++) {
Index: search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java,v
retrieving revision 1.49
diff -u -r1.49 BinaryIndexer.java
--- search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java 7 Sep 2005 07:45:57 -0000 1.49
+++ search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java 22 Nov 2005 18:44:51 -0000
@@ -496,16 +496,16 @@
switch (TypeDeclaration.kind(modifiers)) {
case TypeDeclaration.CLASS_DECL :
char[] superclass = replace('/', '.', reader.getSuperclassName());
- addClassDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, typeParameterSignatures);
+ addClassDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, typeParameterSignatures, false);
break;
case TypeDeclaration.INTERFACE_DECL :
- addInterfaceDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, typeParameterSignatures);
+ addInterfaceDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, typeParameterSignatures, false);
break;
case TypeDeclaration.ENUM_DECL :
- addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces);
+ addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, false);
break;
case TypeDeclaration.ANNOTATION_TYPE_DECL :
- addAnnotationTypeDeclaration(modifiers, packageName, name, enclosingTypeNames);
+ addAnnotationTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, false);
break;
}
Index: model/org/eclipse/jdt/core/IJavaProject.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaProject.java,v
retrieving revision 1.76
diff -u -r1.76 IJavaProject.java
--- model/org/eclipse/jdt/core/IJavaProject.java 5 Oct 2005 09:20:16 -0000 1.76
+++ model/org/eclipse/jdt/core/IJavaProject.java 22 Nov 2005 18:44:42 -0000
@@ -185,11 +185,7 @@
* a class B defined as a member type of a class A in package x.y should have a
* the fully qualified name "x.y.A.B".
*
- * Note that in order to be found, a type name (or its toplevel enclosing
- * type name) must match its corresponding compilation unit name. As a
- * consequence, secondary types cannot be found using this functionality.
- * Secondary types can however be explicitely accessed through their enclosing
- * unit or found by the SearchEngine
.
+ * Secondary types are found since 3.2 version.
*
* @param fullyQualifiedName the given fully qualified name
* @exception JavaModelException if this project does not exist or if an
@@ -209,11 +205,7 @@
* If the returned type is part of a compilation unit, its owner is the given
* owner.
*
- * Note that in order to be found, a type name (or its toplevel enclosing
- * type name) must match its corresponding compilation unit name. As a
- * consequence, secondary types cannot be found using this functionality.
- * Secondary types can however be explicitely accessed through their enclosing
- * unit or found by the SearchEngine
.
+ * Secondary types are found since 3.2 version.
*
* @param fullyQualifiedName the given fully qualified name
* @param owner the owner of the returned type's compilation unit
@@ -234,11 +226,7 @@
* a class B defined as a member type of a class A should have the
* type qualified name "A.B".
*
- * Note that in order to be found, a type name (or its toplevel enclosing
- * type name) must match its corresponding compilation unit name. As a
- * consequence, secondary types cannot be found using this functionality.
- * Secondary types can however be explicitely accessed through their enclosing
- * unit or found by the SearchEngine
.
+ * Secondary types are found since 3.2 version.
*
* @param packageName the given package name
* @param typeQualifiedName the given type qualified name
@@ -262,11 +250,7 @@
* If the returned type is part of a compilation unit, its owner is the given
* owner.
*
- * Note that in order to be found, a type name (or its toplevel enclosing
- * type name) must match its corresponding compilation unit name. As a
- * consequence, secondary types cannot be found using this functionality.
- * Secondary types can however be explicitely accessed through their enclosing
- * unit or found by the SearchEngine
.
+ * Secondary types are found since 3.2 version.
*
* @param packageName the given package name
* @param typeQualifiedName the given type qualified name
Index: model/org/eclipse/jdt/internal/core/NameLookup.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java,v
retrieving revision 1.93
diff -u -r1.93 NameLookup.java
--- model/org/eclipse/jdt/internal/core/NameLookup.java 4 Nov 2005 15:52:51 -0000 1.93
+++ model/org/eclipse/jdt/internal/core/NameLookup.java 22 Nov 2005 18:44:49 -0000
@@ -15,22 +15,19 @@
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.compiler.CharOperation;
-import org.eclipse.jdt.core.search.*;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
-import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject;
@@ -114,16 +111,21 @@
*/
protected HashMap typesInWorkingCopies;
+// /**
+// * Flag to prevent secondary types search
+// */
+// public boolean findSecondaryTypes = true;
+
public long timeSpentInSeekTypesInSourcePackage = 0;
public long timeSpentInSeekTypesInBinaryPackage = 0;
public NameLookup(IPackageFragmentRoot[] packageFragmentRoots, HashtableOfArrayToObject packageFragments, ICompilationUnit[] workingCopies, Map rootToResolvedEntries) {
long start = -1;
if (VERBOSE) {
- System.out.println(Thread.currentThread() + " BUILDING NameLoopkup"); //$NON-NLS-1$
- System.out.println(Thread.currentThread() + " -> pkg roots size: " + (packageFragmentRoots == null ? 0 : packageFragmentRoots.length)); //$NON-NLS-1$
- System.out.println(Thread.currentThread() + " -> pkgs size: " + (packageFragments == null ? 0 : packageFragments.size())); //$NON-NLS-1$
- System.out.println(Thread.currentThread() + " -> working copy size: " + (workingCopies == null ? 0 : workingCopies.length)); //$NON-NLS-1$
+ Util.verbose(" BUILDING NameLoopkup"); //$NON-NLS-1$
+ Util.verbose(" -> pkg roots size: " + (packageFragmentRoots == null ? 0 : packageFragmentRoots.length)); //$NON-NLS-1$
+ Util.verbose(" -> pkgs size: " + (packageFragments == null ? 0 : packageFragments.size())); //$NON-NLS-1$
+ Util.verbose(" -> working copy size: " + (workingCopies == null ? 0 : workingCopies.length)); //$NON-NLS-1$
start = System.currentTimeMillis();
}
this.packageFragmentRoots = packageFragmentRoots;
@@ -201,7 +203,7 @@
}
this.rootToResolvedEntries = rootToResolvedEntries;
if (VERBOSE) {
- System.out.println(Thread.currentThread() + " -> spent: " + (start - System.currentTimeMillis()) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
+ Util.verbose(" -> spent: " + (start - System.currentTimeMillis()) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@@ -483,6 +485,70 @@
return null;
}
+ /*
+ * Find secondary type for a source folders.
+ */
+ private IType findSecondaryType(String packageName, String typeName, IJavaProject project) { //IJavaProject[] projects) {
+// int length = projects.length;
+ if (VERBOSE) {
+ Util.verbose("NameLookup FIND SECONDARY TYPES:"); //$NON-NLS-1$
+ Util.verbose(" -> pkg name: " + packageName); //$NON-NLS-1$
+ Util.verbose(" -> type name: " + typeName); //$NON-NLS-1$
+// StringBuffer buffer = new StringBuffer(" -> projects: "); //$NON-NLS-1$
+// for (int i=0; i projects: "+project.getElementName()); //$NON-NLS-1$
+ }
+// for (int i=0; i 0) {
+// String searchedName = packageName.length()==0 ? typeName : packageName + '.' + typeName;
+// Object cachedType = secondaryTypePaths.get(searchedName);
+ HashMap types = (HashMap) secondaryTypePaths.get(packageName==null?"":packageName); //$NON-NLS-1$
+ if (types != null && types.size() > 0) {
+// Object cachedType = types.get(typeName);
+ IType type = (IType) types.get(typeName);
+ if (type != null) return type;
+// if (cachedType instanceof IType) return (IType) cachedType; // we already found this secondary type and stored it in cache
+// String pathName = (String) cachedType;
+// if (JavaModelManager.VERBOSE) {
+// Util.verbose(" -> path name: " + pathName); //$NON-NLS-1$
+// }
+// if (pathName != null && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(pathName)) {
+// IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(pathName));
+// ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null);
+// IType type = unit.getType(typeName);
+// if (JavaModelManager.VERBOSE) {
+// Util.verbose(" -> type: " + type.getElementName()); //$NON-NLS-1$
+// }
+// types.put(typeName, type); // replace stored path with type itself
+// return type;
+// }
+ }
+ }
+ }
+ catch (JavaModelException jme) {
+ // give up
+ }
+// }
+ return null;
+ }
+
/**
*
*/
@@ -493,24 +559,36 @@
// see if this is a known package and not a type
if (findPackageFragments(packageName + "." + typeName, false) != null) return null; //$NON-NLS-1$
}
+
+ // Look for concerned package fragments
JavaElementRequestor elementRequestor = new JavaElementRequestor();
seekPackageFragments(packageName, false, elementRequestor);
IPackageFragment[] packages= elementRequestor.getPackageFragments();
- for (int i= 0, length= packages.length; i < length; i++) {
- IType type= findType(typeName, packages[i], partialMatch, acceptFlags);
- if (type != null)
+ // Try to find type in package fragments list
+ IType type = null;
+ int length= packages.length;
+// Set projectsSet = this.findSecondaryTypes ? new HashSet() : null;
+ IJavaProject project = null;
+ for (int i= 0; i < length; i++) {
+ type = findType(typeName, packages[i], partialMatch, acceptFlags);
+ if (type != null) {
return type;
+ }
+ if (/*this.findSecondaryTypes &&*/ project == null) {
+// projectsSet.add(packages[i].getJavaProject());
+ project = packages[i].getJavaProject();
+ }
}
- return null;
- }
-
- private IType getMemberType(IType type, String name, int dot) {
- while (dot != -1) {
- int start = dot+1;
- dot = name.indexOf('.', start);
- String typeName = name.substring(start, dot == -1 ? name.length() : dot);
- type = type.getType(typeName);
+
+ // If type was not found, try to find it as secondary in source folders
+ if (/*this.findSecondaryTypes && */project != null) {
+// int size = projectsSet.size();
+// if (size > 0) {
+// IJavaProject[] projects = new IJavaProject[size];
+// projectsSet.toArray(projects);
+ type = findSecondaryType(packageName, typeName, project); //projects);
+// }
}
return type;
}
@@ -540,68 +618,7 @@
// Return first found (ignore duplicates).
SingleTypeRequestor typeRequestor = new SingleTypeRequestor();
seekTypes(name, pkg, partialMatch, acceptFlags, typeRequestor);
- IType type = typeRequestor.getType();
-// if (type == null)
-// type = findSecondaryType(name, pkg, partialMatch, acceptFlags);
- return type;
- }
-
- // TODO (kent) enable once index support is in
- IType findSecondaryType(String typeName, IPackageFragment pkg, boolean partialMatch, final int acceptFlags) {
- try {
- final ArrayList paths = new ArrayList();
- TypeNameRequestor nameRequestor = new TypeNameRequestor() {
- public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
- if (enclosingTypeNames == null || enclosingTypeNames.length == 0) { // accept only top level types
- int kind = modifiers & (ClassFileConstants.AccInterface|ClassFileConstants.AccEnum|ClassFileConstants.AccAnnotation);
- switch (kind) {
- case ClassFileConstants.AccAnnotation:
- case ClassFileConstants.AccAnnotation|ClassFileConstants.AccInterface:
- if ((acceptFlags & ACCEPT_ANNOTATIONS) != 0) paths.add(path);
- break;
- case ClassFileConstants.AccEnum:
- if ((acceptFlags & ACCEPT_ENUMS) != 0) paths.add(path);
- break;
- case ClassFileConstants.AccInterface:
- if ((acceptFlags & ACCEPT_INTERFACES) != 0) paths.add(path);
- break;
- default:
- if ((acceptFlags & ACCEPT_CLASSES) != 0) paths.add(path);
- break;
- }
- }
- }
- };
-
- int matchMode = partialMatch ? SearchPattern.R_PREFIX_MATCH : SearchPattern.R_EXACT_MATCH;
- int matchRule = !partialMatch ? matchMode | SearchPattern.R_CASE_SENSITIVE : matchMode;
- new SearchEngine().searchAllTypeNames(
- pkg.getElementName().toCharArray(),
- typeName.toCharArray(),
- matchRule,
- IJavaSearchConstants.TYPE,
- SearchEngine.createJavaSearchScope(new IJavaElement[] {pkg}, false),
- nameRequestor,
- IJavaSearchConstants.CANCEL_IF_NOT_READY_TO_SEARCH,
- null);
-
- if (!paths.isEmpty()) {
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- for (int i = 0, l = paths.size(); i < l; i++) {
- String pathname = (String) paths.get(i);
- if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(pathname)) {
- IFile file = workspace.getRoot().getFile(new Path(pathname));
- ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
- return unit.getType(typeName);
- }
- }
- }
- } catch (JavaModelException e) {
- // ignore
- } catch (OperationCanceledException ignore) {
- // ignore
- }
- return null;
+ return typeRequestor.getType();
}
/**
@@ -633,6 +650,16 @@
return findType(className, packageName, partialMatch, acceptFlags);
}
+ private IType getMemberType(IType type, String name, int dot) {
+ while (dot != -1) {
+ int start = dot+1;
+ dot = name.indexOf('.', start);
+ String typeName = name.substring(start, dot == -1 ? name.length() : dot);
+ type = type.getType(typeName);
+ }
+ return type;
+ }
+
/**
* Returns true if the given element's name matches the
* specified searchName
, otherwise false.
@@ -681,9 +708,9 @@
*/
public void seekPackageFragments(String name, boolean partialMatch, IJavaElementRequestor requestor) {
/* if (VERBOSE) {
- System.out.println(Thread.currentThread() + " SEEKING PACKAGE FRAGMENTS"); //$NON-NLS-1$
- System.out.println(Thread.currentThread() + " -> name: " + name); //$NON-NLS-1$
- System.out.println(Thread.currentThread() + " -> partial match:" + partialMatch); //$NON-NLS-1$
+ Util.verbose(" SEEKING PACKAGE FRAGMENTS"); //$NON-NLS-1$
+ Util.verbose(" -> name: " + name); //$NON-NLS-1$
+ Util.verbose(" -> partial match:" + partialMatch); //$NON-NLS-1$
}
*/ if (partialMatch) {
String[] splittedName = Util.splitOn('.', name, 0, name.length());
@@ -749,10 +776,10 @@
*/
public void seekTypes(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor) {
/* if (VERBOSE) {
- System.out.println(Thread.currentThread() + " SEEKING TYPES"); //$NON-NLS-1$
- System.out.println(Thread.currentThread() + " -> name: " + name); //$NON-NLS-1$
- System.out.println(Thread.currentThread() + " -> pkg: " + ((JavaElement) pkg).toStringWithAncestors()); //$NON-NLS-1$
- System.out.println(Thread.currentThread() + " -> partial match:" + partialMatch); //$NON-NLS-1$
+ Util.verbose(" SEEKING TYPES"); //$NON-NLS-1$
+ Util.verbose(" -> name: " + name); //$NON-NLS-1$
+ Util.verbose(" -> pkg: " + ((JavaElement) pkg).toStringWithAncestors()); //$NON-NLS-1$
+ Util.verbose(" -> partial match:" + partialMatch); //$NON-NLS-1$
}
*/
String matchName= partialMatch ? name.toLowerCase() : name;
Index: model/org/eclipse/jdt/internal/core/DeltaProcessor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java,v
retrieving revision 1.270
diff -u -r1.270 DeltaProcessor.java
--- model/org/eclipse/jdt/internal/core/DeltaProcessor.java 20 Oct 2005 10:19:58 -0000 1.270
+++ model/org/eclipse/jdt/internal/core/DeltaProcessor.java 22 Nov 2005 18:44:44 -0000
@@ -2401,6 +2401,7 @@
break;
case IResourceDelta.REMOVED :
indexManager.remove(Util.relativePath(file.getFullPath(), 1/*remove project segment*/), file.getProject().getFullPath());
+ this.manager.removeFromSecondaryTypesCache(file);
break;
}
}
Index: model/org/eclipse/jdt/internal/core/JavaProject.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v
retrieving revision 1.351
diff -u -r1.351 JavaProject.java
--- model/org/eclipse/jdt/internal/core/JavaProject.java 5 Oct 2005 09:20:16 -0000 1.351
+++ model/org/eclipse/jdt/internal/core/JavaProject.java 22 Nov 2005 18:44:48 -0000
@@ -1151,7 +1151,49 @@
}
return new IPackageFragmentRoot[] {};
}
-
+
+ /*
+ * Find secondary type for a project.
+ *
+ * @param packageName Package name of secondary type to be found
+ * @param typeName Type name to be found
+ *
+ public IType findSecondaryType(String packageName, String typeName) {
+ if (JavaModelManager.VERBOSE) {
+ StringBuffer buffer = new StringBuffer("JavaProject.findSecondaryType("); //$NON-NLS-1$
+ buffer.append(packageName);
+ buffer.append(',');
+ buffer.append(typeName);
+ buffer.append(')');
+ Util.verbose(buffer.toString());
+ }
+ JavaModelManager manager = JavaModelManager.getJavaModelManager();
+ try {
+ HashMap secondaryTypePaths = manager.getSecondaryTypes(this);
+ if (secondaryTypePaths.size() > 0) {
+ String searchedName = packageName.length()==0 ? typeName : packageName + '.' + typeName;
+ String pathName = (String) secondaryTypePaths.get(searchedName);
+ if (JavaModelManager.VERBOSE) {
+ Util.verbose(" -> path name: " + pathName); //$NON-NLS-1$
+ }
+ if (pathName != null && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(pathName)) {
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(pathName));
+ ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, this);
+ IType type = unit.getType(typeName);
+ if (JavaModelManager.VERBOSE) {
+ Util.verbose(" -> type: " + type.getElementName()); //$NON-NLS-1$
+ }
+ return type;
+ }
+ }
+ }
+ catch (JavaModelException jme) {
+ // give up
+ }
+ return null;
+ }
+ */
+
/**
* @see IJavaProject#findType(String)
*/
@@ -1184,6 +1226,13 @@
public IType findType(String fullyQualifiedName, WorkingCopyOwner owner) throws JavaModelException {
NameLookup lookup = newNameLookup(owner);
+ return findType(fullyQualifiedName, lookup);
+ }
+
+ /*
+ * Internal findType with instanciated name lookup
+ */
+ IType findType(String fullyQualifiedName, NameLookup lookup) throws JavaModelException {
IType type = lookup.findType(
fullyQualifiedName,
false,
@@ -1192,7 +1241,7 @@
// try to find enclosing type
int lastDot = fullyQualifiedName.lastIndexOf('.');
if (lastDot == -1) return null;
- type = this.findType(fullyQualifiedName.substring(0, lastDot));
+ type = findType(fullyQualifiedName.substring(0, lastDot), lookup);
if (type != null) {
type = type.getType(fullyQualifiedName.substring(lastDot+1));
if (!type.exists()) {
Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v
retrieving revision 1.301
diff -u -r1.301 JavaModelManager.java
--- model/org/eclipse/jdt/internal/core/JavaModelManager.java 22 Nov 2005 14:57:44 -0000 1.301
+++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 22 Nov 2005 18:44:47 -0000
@@ -34,10 +34,12 @@
import org.eclipse.jdt.internal.codeassist.CompletionEngine;
import org.eclipse.jdt.internal.codeassist.SelectionEngine;
import org.eclipse.jdt.internal.compiler.Compiler;
+import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
import org.eclipse.jdt.internal.core.builder.JavaBuilder;
import org.eclipse.jdt.internal.core.hierarchy.TypeHierarchy;
import org.eclipse.jdt.internal.core.search.AbstractSearchScope;
import org.eclipse.jdt.internal.core.search.BasicSearchEngine;
+import org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor;
import org.eclipse.jdt.internal.core.search.JavaWorkspaceScope;
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
import org.eclipse.jdt.internal.core.search.processing.JobManager;
@@ -799,6 +801,7 @@
public IEclipsePreferences preferences;
public Hashtable options;
+ public HashMap secondaryTypes;
public PerProjectInfo(IProject project) {
@@ -1408,7 +1411,90 @@
}
return null; // break cycle
}
-
+
+ /**
+ * Get all secondary types for a project and store result in per project info cache.
+ *
+ * @param project Project we want get secondary types from
+ * @return HashMap Table of secondary type names->path for given project
+ */
+ public HashMap getSecondaryTypes(IJavaProject project) throws JavaModelException {
+ if (VERBOSE) {
+ StringBuffer buffer = new StringBuffer("JavaModelManager.getSecondaryTypesPaths("); //$NON-NLS-1$
+ buffer.append(project.getElementName());
+ buffer.append(')');
+ Util.verbose(buffer.toString());
+ }
+
+ PerProjectInfo projectInfo = getPerProjectInfoCheckExistence(project.getProject());
+ if (projectInfo.secondaryTypes != null) return projectInfo.secondaryTypes;
+ final HashMap secondaryTypePaths = new HashMap();
+
+ IRestrictedAccessTypeRequestor nameRequestor = new IRestrictedAccessTypeRequestor() {
+ public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) {
+// String key = new String(CharOperation.concat(packageName, simpleTypeName, '.'));
+ String key = packageName==null ? "" : new String(packageName); //$NON-NLS-1$
+ HashMap types = (HashMap) secondaryTypePaths.get(key);
+ if (types == null) {
+ types = new HashMap();
+ }
+ types.put(new String(simpleTypeName), path);
+ secondaryTypePaths.put(key, types);
+// secondaryTypePaths.put(key, path);
+ }
+ };
+
+ // Build scope using prereq projects but only source folders
+ IPackageFragmentRoot[] allRoots = project.getAllPackageFragmentRoots();
+ int length = allRoots.length, size = 0;
+ IPackageFragmentRoot[] allSourceFolders = new IPackageFragmentRoot[length];
+ for (int i=0; i secondary paths: "); //$NON-NLS-1$
+ if (secondaryTypePaths == null) {
+ System.out.println(" NONE"); //$NON-NLS-1$
+ } else {
+ System.out.println();
+ Iterator keys = secondaryTypePaths.keySet().iterator();
+ while (keys.hasNext()) {
+ String qualifiedName = (String) keys.next();
+ Util.verbose(" - "+qualifiedName+'-'+secondaryTypePaths.get(qualifiedName) ); //$NON-NLS-1$
+ }
+ }
+ }
+
+ // Build types from paths
+ Iterator packages = secondaryTypePaths.keySet().iterator();
+ while (packages.hasNext()) {
+ String packName = (String) packages.next();
+ HashMap types = (HashMap) secondaryTypePaths.get(packName);
+ Iterator names = types.keySet().iterator();
+ while (names.hasNext()) {
+ String typeName = (String) names.next();
+ String path = (String) types.get(typeName);
+ if (org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(path)) {
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
+ ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null);
+ IType type = unit.getType(typeName);
+ types.put(typeName, type); // replace stored path with type itself
+ }
+ }
+ }
+
+ // Store result in per project info cache
+ return (projectInfo.secondaryTypes = secondaryTypePaths);
+ }
+
/**
* Returns the temporary cache for newly opened elements for the current thread.
* Creates it if not already created.
@@ -2266,7 +2352,78 @@
// used by tests to simulate a startup
MANAGER = new JavaModelManager();
}
-
+
+ /**
+ * Remove a file from its project secondary types cache.
+ *
+ * @param file File to remove
+ */
+ public void removeFromSecondaryTypesCache(IFile file) {
+ if (VERBOSE) {
+ StringBuffer buffer = new StringBuffer("JavaModelManager.removeSecondaryTypePaths("); //$NON-NLS-1$
+ buffer.append(file.getName());
+ buffer.append(')');
+ Util.verbose(buffer.toString());
+ }
+ if (file != null) {
+ PerProjectInfo projectInfo = getPerProjectInfo(file.getProject(), false);
+ if (projectInfo != null && projectInfo.secondaryTypes != null) {
+ if (VERBOSE) {
+ Util.verbose("-> remove file from cache of project: "+file.getProject().getName()); //$NON-NLS-1$
+ }
+ Iterator packages = projectInfo.secondaryTypes.keySet().iterator();
+ while (packages.hasNext()) {
+ String packName = (String) packages.next();
+ HashMap types = (HashMap) projectInfo.secondaryTypes.get(packName);
+ Iterator names = types.keySet().iterator();
+ while (names.hasNext()) {
+ String typeName = (String) names.next();
+ Object obj = types.get(typeName);
+ boolean remove = false;
+ if (obj instanceof String) {
+ String path = (String) obj;
+ remove = path.equals(file.getFullPath().toString());
+ } else if (obj instanceof IType) {
+ remove = file == ((IType)obj).getResource();
+ }
+ if (remove) {
+ types.remove(typeName);
+ if (types.size() == 0) {
+ projectInfo.secondaryTypes.remove(packName);
+ }
+ return;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Reset secondary types cache for a project got from given path.
+ *
+ * @param path Path of file containing a secondary type
+ */
+ public void resetSecondaryTypesCache(String path) {
+ if (VERBOSE) {
+ StringBuffer buffer = new StringBuffer("JavaModelManager.resetSecondaryTypePaths("); //$NON-NLS-1$
+ buffer.append(path);
+ buffer.append(')');
+ Util.verbose(buffer.toString());
+ }
+ IWorkspaceRoot wRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IResource resource = wRoot.findMember(path);
+ if (resource != null) {
+ PerProjectInfo projectInfo = getPerProjectInfo(resource.getProject(), false);
+ if (projectInfo != null) {
+ if (VERBOSE) {
+ Util.verbose("-> reset cache for project: "+resource.getProject().getName()); //$NON-NLS-1$
+ }
+ projectInfo.secondaryTypes = null;
+ }
+ }
+ }
+
/*
* Resets the temporary cache for newly created elements to null.
*/
Index: compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java,v
retrieving revision 1.109
diff -u -r1.109 TypeDeclaration.java
--- compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 20 Oct 2005 13:26:45 -0000 1.109
+++ compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 22 Nov 2005 18:44:34 -0000
@@ -1326,4 +1326,11 @@
maxFieldCount = outerMostType.maxFieldCount; // down
}
}
+
+ /**
+ * Returns whether the type is a secondary one or not.
+ */
+ public boolean isSecondary() {
+ return (this.bits & IsSecondaryType) != 0;
+ }
}
Index: compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java,v
retrieving revision 1.53
diff -u -r1.53 ASTNode.java
--- compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 18 Nov 2005 16:46:23 -0000 1.53
+++ compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 22 Nov 2005 18:44:34 -0000
@@ -32,7 +32,7 @@
public final static int Bit10= 0x200; // depth (name ref, msg) | operator (operator) | is anonymous type (type decl)
public final static int Bit11 = 0x400; // depth (name ref, msg) | operator (operator) | is member type (type decl)
public final static int Bit12 = 0x800; // depth (name ref, msg) | operator (operator) | has abstract methods (type decl)
- public final static int Bit13 = 0x1000; // depth (name ref, msg)
+ public final static int Bit13 = 0x1000; // depth (name ref, msg) | is secondary type (type decl)
public final static int Bit14 = 0x2000; // strictly assigned (reference lhs)
public final static int Bit15 = 0x4000; // is unnecessary cast (expression) | is varargs (type ref)
public final static int Bit16 = 0x8000; // in javadoc comment (name ref, type ref, msg)
@@ -118,7 +118,8 @@
public static final int IsAnonymousType = Bit10; // used to test for anonymous
public static final int IsMemberType = Bit11; // local member do not know it is local at parse time (need to look at binding)
public static final int HasAbstractMethods = Bit12; // used to promote abstract enums
-
+ public static final int IsSecondaryType = Bit13; // used to test for secondary
+
// for type, method and field declarations
public static final int HasLocalType = Bit2; // cannot conflict with AddAssertionMASK
Index: model/org/eclipse/jdt/internal/compiler/SourceJavadocParser.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceJavadocParser.java,v
retrieving revision 1.3
diff -u -r1.3 SourceJavadocParser.java
--- model/org/eclipse/jdt/internal/compiler/SourceJavadocParser.java 4 Nov 2005 15:59:32 -0000 1.3
+++ model/org/eclipse/jdt/internal/compiler/SourceJavadocParser.java 22 Nov 2005 18:44:43 -0000
@@ -22,7 +22,7 @@
public SourceJavadocParser(Parser sourceParser) {
super(sourceParser);
- this.kind = SOURCE_PARSER | TEXT_PARSE | TEXT_VERIF;
+ this.kind = SOURCE_PARSER | TEXT_VERIF;
}
public boolean checkDeprecation(int commentPtr) {
Index: model/org/eclipse/jdt/internal/compiler/SourceElementParser.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/SourceElementParser.java,v
retrieving revision 1.54
diff -u -r1.54 SourceElementParser.java
--- model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 20 Oct 2005 13:26:47 -0000 1.54
+++ model/org/eclipse/jdt/internal/compiler/SourceElementParser.java 22 Nov 2005 18:44:43 -0000
@@ -57,6 +57,7 @@
CompilerOptions options;
HashtableOfObjectToInt sourceEnds = new HashtableOfObjectToInt();
HashMap nodesToCategories = new HashMap(); // a map from ASTNode to char[][]
+ boolean useSourceJavadocParser = true;
/**
* An ast visitor that visits local type declarations.
@@ -94,6 +95,16 @@
CompilerOptions options,
boolean reportLocalDeclarations,
boolean optimizeStringLiterals) {
+ this(requestor, problemFactory, options, reportLocalDeclarations, optimizeStringLiterals, true/* use SourceJavadocParser */);
+}
+
+public SourceElementParser(
+ final ISourceElementRequestor requestor,
+ IProblemFactory problemFactory,
+ CompilerOptions options,
+ boolean reportLocalDeclarations,
+ boolean optimizeStringLiterals,
+ boolean useSourceJavadocParser) {
// we want to notify all syntax error with the acceptProblem API
// To do so, we define the record method of the ProblemReporter
super(new ProblemReporter(
@@ -115,7 +126,10 @@
this.localDeclarationVisitor = new LocalDeclarationVisitor();
}
// set specific javadoc parser
- this.javadocParser = new SourceJavadocParser(this);
+ this.useSourceJavadocParser = useSourceJavadocParser;
+ if (useSourceJavadocParser) {
+ this.javadocParser = new SourceJavadocParser(this);
+ }
}
public void checkComment() {
@@ -1246,6 +1260,7 @@
typeInfo.typeParameters = getTypeParameterInfos(typeDeclaration.typeParameters);
typeInfo.annotationPositions = collectAnnotationPositions(typeDeclaration.annotations);
typeInfo.categories = (char[][]) this.nodesToCategories.get(typeDeclaration);
+ typeInfo.secondary = typeDeclaration.isSecondary();
requestor.enterType(typeInfo);
switch (kind) {
case TypeDeclaration.CLASS_DECL :
@@ -1323,11 +1338,13 @@
}
}
private void rememberCategories() {
- SourceJavadocParser sourceJavadocParser = (SourceJavadocParser) this.javadocParser;
- char[][] categories = sourceJavadocParser.categories;
- if (categories.length > 0) {
- this.nodesToCategories.put(this.astStack[this.astPtr], categories);
- sourceJavadocParser.categories = CharOperation.NO_CHAR_CHAR;
+ if (this.useSourceJavadocParser) {
+ SourceJavadocParser sourceJavadocParser = (SourceJavadocParser) this.javadocParser;
+ char[][] categories = sourceJavadocParser.categories;
+ if (categories.length > 0) {
+ this.nodesToCategories.put(this.astStack[this.astPtr], categories);
+ sourceJavadocParser.categories = CharOperation.NO_CHAR_CHAR;
+ }
}
}
private int sourceEnd(TypeDeclaration typeDeclaration) {
Index: model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java,v
retrieving revision 1.12
diff -u -r1.12 ISourceElementRequestor.java
--- model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java 13 Oct 2005 09:09:52 -0000 1.12
+++ model/org/eclipse/jdt/internal/compiler/ISourceElementRequestor.java 22 Nov 2005 18:44:42 -0000
@@ -49,6 +49,7 @@
public TypeParameterInfo[] typeParameters;
public long[] annotationPositions;
public char[][] categories;
+ public boolean secondary;
}
public static class TypeParameterInfo {
Index: search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java,v
retrieving revision 1.24
diff -u -r1.24 BasicSearchEngine.java
--- search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 27 Oct 2005 15:43:48 -0000 1.24
+++ search/org/eclipse/jdt/internal/core/search/BasicSearchEngine.java 22 Nov 2005 18:44:50 -0000
@@ -71,7 +71,7 @@
}
/**
- * @see org.eclipse.jdt.core.search.SearchEngine#SearchEngine(ICompilationUnit[]) for detailed comment.
+ * @see SearchEngine#SearchEngine(ICompilationUnit[]) for detailed comment.
*/
public BasicSearchEngine(ICompilationUnit[] workingCopies) {
this.workingCopies = workingCopies;
@@ -87,35 +87,35 @@
}
}
/**
- * @see org.eclipse.jdt.core.search.SearchEngine#SearchEngine(WorkingCopyOwner) for detailed comment.
+ * @see SearchEngine#SearchEngine(WorkingCopyOwner) for detailed comment.
*/
public BasicSearchEngine(WorkingCopyOwner workingCopyOwner) {
this.workingCopyOwner = workingCopyOwner;
}
/**
- * @see org.eclipse.jdt.core.search.SearchEngine#createHierarchyScope(IType) for detailed comment.
+ * @see SearchEngine#createHierarchyScope(IType) for detailed comment.
*/
public static IJavaSearchScope createHierarchyScope(IType type) throws JavaModelException {
return createHierarchyScope(type, DefaultWorkingCopyOwner.PRIMARY);
}
/**
- * @see org.eclipse.jdt.core.search.SearchEngine#createHierarchyScope(IType,WorkingCopyOwner) for detailed comment.
+ * @see SearchEngine#createHierarchyScope(IType,WorkingCopyOwner) for detailed comment.
*/
public static IJavaSearchScope createHierarchyScope(IType type, WorkingCopyOwner owner) throws JavaModelException {
return new HierarchyScope(type, owner);
}
/**
- * @see org.eclipse.jdt.core.search.SearchEngine#createJavaSearchScope(IJavaElement[]) for detailed comment.
+ * @see SearchEngine#createJavaSearchScope(IJavaElement[]) for detailed comment.
*/
public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements) {
return createJavaSearchScope(elements, true);
}
/**
- * @see org.eclipse.jdt.core.search.SearchEngine#createJavaSearchScope(IJavaElement[], boolean) for detailed comment.
+ * @see SearchEngine#createJavaSearchScope(IJavaElement[], boolean) for detailed comment.
*/
public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements, boolean includeReferencedProjects) {
int includeMask = IJavaSearchScope.SOURCES | IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SYSTEM_LIBRARIES;
@@ -126,7 +126,7 @@
}
/**
- * @see org.eclipse.jdt.core.search.SearchEngine#createJavaSearchScope(IJavaElement[], int) for detailed comment.
+ * @see SearchEngine#createJavaSearchScope(IJavaElement[], int) for detailed comment.
*/
public static IJavaSearchScope createJavaSearchScope(IJavaElement[] elements, int includeMask) {
JavaSearchScope scope = new JavaSearchScope();
@@ -149,9 +149,7 @@
}
/**
- * Returns a Java search scope with the workspace as the only limit.
- *
- * @return a new workspace scope
+ * @see SearchEngine#createWorkspaceScope() for detailed comment.
*/
public static IJavaSearchScope createWorkspaceScope() {
return JavaModelManager.getJavaModelManager().getWorkspaceScope();
@@ -165,7 +163,7 @@
* @param scope the search result has to be limited to the given scope
* @param requestor a callback object to which each match is reported
*/
- public void findMatches(SearchPattern pattern, SearchParticipant[] participants, IJavaSearchScope scope, SearchRequestor requestor, IProgressMonitor monitor) throws CoreException {
+ void findMatches(SearchPattern pattern, SearchParticipant[] participants, IJavaSearchScope scope, SearchRequestor requestor, IProgressMonitor monitor) throws CoreException {
if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
/* initialize progress monitor */
@@ -231,7 +229,7 @@
/**
* @param matchRule
*/
- private String getMatchRuleString(final int matchRule) {
+ public static String getMatchRuleString(final int matchRule) {
StringBuffer buffer = new StringBuffer();
for (int i=1; i<=8; i++) {
int bit = matchRule & (1<<(i-1));
@@ -266,6 +264,39 @@
return buffer.toString();
}
+ /**
+ * Return kind of search corresponding to given value.
+ *
+ * @param searchFor
+ */
+ public static String getSearchForString(final int searchFor) {
+ switch (searchFor) {
+ case IJavaSearchConstants.TYPE:
+ return ("TYPE"); //$NON-NLS-1$
+ case IJavaSearchConstants.METHOD:
+ return ("METHOD"); //$NON-NLS-1$
+ case IJavaSearchConstants.PACKAGE:
+ return ("PACKAGE"); //$NON-NLS-1$
+ case IJavaSearchConstants.CONSTRUCTOR:
+ return ("CONSTRUCTOR"); //$NON-NLS-1$
+ case IJavaSearchConstants.FIELD:
+ return ("FIELD"); //$NON-NLS-1$
+ case IJavaSearchConstants.CLASS:
+ return ("CLASS"); //$NON-NLS-1$
+ case IJavaSearchConstants.INTERFACE:
+ return ("INTERFACE"); //$NON-NLS-1$
+ case IJavaSearchConstants.ENUM:
+ return ("ENUM"); //$NON-NLS-1$
+ case IJavaSearchConstants.ANNOTATION_TYPE:
+ return ("ANNOTATION_TYPE"); //$NON-NLS-1$
+ case IJavaSearchConstants.CLASS_AND_ENUM:
+ return ("CLASS_AND_ENUM"); //$NON-NLS-1$
+ case IJavaSearchConstants.CLASS_AND_INTERFACE:
+ return ("CLASS_AND_INTERFACE"); //$NON-NLS-1$
+ }
+ return "UNKNOWN"; //$NON-NLS-1$
+ }
+
private Parser getParser() {
if (this.parser == null) {
this.compilerOptions = new CompilerOptions(JavaCore.getOptions());
@@ -279,10 +310,8 @@
return this.parser;
}
- /**
+ /*
* Returns the underlying resource of the given element.
- * @param element an IJavaElement
- * @return an IResource
*/
private IResource getResource(IJavaElement element) {
if (element instanceof IMember) {
@@ -354,10 +383,8 @@
return result;
}
- /**
+ /*
* Returns the list of working copies used to do the search on the given Java element.
- * @param element an IJavaElement
- * @return an array of ICompilationUnit
*/
private ICompilationUnit[] getWorkingCopies(IJavaElement element) {
if (element instanceof IMember) {
@@ -688,6 +715,88 @@
}
/**
+ * Searches for all top-level types and member types in the given scope.
+ * The search can be selecting specific types (given a package or a type name
+ * prefix and match modes).
+ *
+ */
+ public void searchAllSecondaryTypeNames(IPackageFragmentRoot[] sourceFolders, final IRestrictedAccessTypeRequestor nameRequestor) throws JavaModelException {
+
+ if (VERBOSE) {
+ Util.verbose("BasicSearchEngine.searchAllSecondaryTypeNames(char[], char[], int, int, IJavaSearchScope, IRestrictedAccessTypeRequestor, int, IProgressMonitor)"); //$NON-NLS-1$
+ StringBuffer buffer = new StringBuffer(" -> source folders: "); //$NON-NLS-1$
+ int length = sourceFolders.length;
+ for (int i=0; i 0) {
+ System.arraycopy(record.pkg, 0, path, pos, pkgLength-1);
+ CharOperation.replace(path, '.', '/');
+ path[pkgLength-1] = '/';
+ pos += pkgLength;
+ }
+ if (nameLength > 0) {
+ System.arraycopy(record.simpleName, 0, path, pos, nameLength);
+ pos += nameLength;
+ }
+ // Update access restriction if path is not empty
+ if (pos > 0) {
+ accessRestriction = access.getViolatedRestriction(path);
+ }
+ }
+ nameRequestor.acceptType(record.modifiers, record.pkg, record.simpleName, record.enclosingTypeNames, documentPath, accessRestriction);
+ }
+ }
+ return true;
+ }
+ };
+
+ // add type names from indexes
+ indexManager.performConcurrentJob(
+ new PatternSearchJob(
+ pattern,
+ getDefaultSearchParticipant(), // Java search only
+ createJavaSearchScope(sourceFolders),
+ searchRequestor),
+ IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
+ null);
+ }
+
+ /**
* Searches for all top-level types and member types in the given scope using a case sensitive exact match
* with the given qualified names and type names.
*
Index: search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationPattern.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationPattern.java,v
retrieving revision 1.55
diff -u -r1.55 TypeDeclarationPattern.java
--- search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationPattern.java 26 Oct 2005 18:00:40 -0000 1.55
+++ search/org/eclipse/jdt/internal/core/search/matching/TypeDeclarationPattern.java 22 Nov 2005 18:44:51 -0000
@@ -31,6 +31,7 @@
// set to TYPE_SUFFIX for matching both classes and interfaces
public char typeSuffix;
public int modifiers;
+public boolean secondary = false;
protected static char[][] CATEGORIES = { TYPE_DECL };
@@ -81,9 +82,11 @@
/*
* Create index key for type declaration pattern:
- * key = typeName / packageName / enclosingTypeName / typeSuffix modifiers
+ * key = typeName / packageName / enclosingTypeName / modifiers
+ * or for secondary types
+ * key = typeName / packageName / enclosingTypeName / modifiers / 'S'
*/
-public static char[] createIndexKey(int modifiers, char[] typeName, char[] packageName, char[][] enclosingTypeNames) { //, char typeSuffix) {
+public static char[] createIndexKey(int modifiers, char[] typeName, char[] packageName, char[][] enclosingTypeNames, boolean secondary) { //, char typeSuffix) {
int typeNameLength = typeName == null ? 0 : typeName.length;
int packageLength = packageName == null ? 0 : packageName.length;
int enclosingNamesLength = 0;
@@ -95,7 +98,9 @@
}
}
- char[] result = new char[typeNameLength + packageLength + enclosingNamesLength + 4];
+ int resultLength = typeNameLength + packageLength + enclosingNamesLength + 4;
+ if (secondary) resultLength += 2;
+ char[] result = new char[resultLength];
int pos = 0;
if (typeNameLength > 0) {
System.arraycopy(typeName, 0, result, pos, typeNameLength);
@@ -119,6 +124,10 @@
}
result[pos++] = SEPARATOR;
result[pos] = (char) modifiers;
+ if (secondary) {
+ result[++pos] = SEPARATOR;
+ result[++pos] = 'S';
+ }
return result;
}
@@ -170,7 +179,10 @@
this.enclosingTypeNames = CharOperation.equals(ONE_ZERO, names) ? ONE_ZERO_CHAR : CharOperation.splitOn('.', names);
}
- decodeModifiers(key[key.length - 1]);
+ slash = CharOperation.indexOf(SEPARATOR, key, start = slash + 1);
+ this.secondary = slash > 0;
+ int last = this.secondary ? slash : key.length;
+ decodeModifiers(key[last-1]);
}
protected void decodeModifiers(char value) {
this.modifiers = value; // implicit cast to int type
Index: search/org/eclipse/jdt/internal/core/search/matching/SecondaryTypeDeclarationPattern.java
===================================================================
RCS file: search/org/eclipse/jdt/internal/core/search/matching/SecondaryTypeDeclarationPattern.java
diff -N search/org/eclipse/jdt/internal/core/search/matching/SecondaryTypeDeclarationPattern.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ search/org/eclipse/jdt/internal/core/search/matching/SecondaryTypeDeclarationPattern.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.internal.core.search.matching;
+
+import java.io.IOException;
+
+import org.eclipse.jdt.core.search.SearchPattern;
+import org.eclipse.jdt.internal.core.index.EntryResult;
+import org.eclipse.jdt.internal.core.index.Index;
+import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
+
+public class SecondaryTypeDeclarationPattern extends TypeDeclarationPattern {
+
+ private final static char[] SECONDARY_PATTERN_KEY = "*/S".toCharArray(); //$NON-NLS-1$
+
+public SecondaryTypeDeclarationPattern() {
+ super(null, null, null, IIndexConstants.SECONDARY_SUFFIX, R_EXACT_MATCH | R_CASE_SENSITIVE);
+}
+
+public SecondaryTypeDeclarationPattern(int matchRule) {
+ super(matchRule);
+}
+
+public SearchPattern getBlankPattern() {
+ return new SecondaryTypeDeclarationPattern(R_EXACT_MATCH | R_CASE_SENSITIVE);
+}
+protected StringBuffer print(StringBuffer output) {
+ output.append("Secondary"); //$NON-NLS-1$
+ return super.print(output);
+}
+
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern#queryIn(org.eclipse.jdt.internal.core.index.Index)
+ */
+EntryResult[] queryIn(Index index) throws IOException {
+ return index.query(CATEGORIES, SECONDARY_PATTERN_KEY, R_PATTERN_MATCH | R_CASE_SENSITIVE);
+}
+
+}
#P org.eclipse.jdt.core.tests.model
Index: src/org/eclipse/jdt/core/tests/model/NameLookupTests2.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NameLookupTests2.java,v
retrieving revision 1.19
diff -u -r1.19 NameLookupTests2.java
--- src/org/eclipse/jdt/core/tests/model/NameLookupTests2.java 4 Nov 2005 15:52:52 -0000 1.19
+++ src/org/eclipse/jdt/core/tests/model/NameLookupTests2.java 22 Nov 2005 18:45:21 -0000
@@ -11,12 +11,10 @@
package org.eclipse.jdt.core.tests.model;
import java.io.IOException;
-import java.util.ArrayList;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.*;
-import org.eclipse.jdt.internal.core.IJavaElementRequestor;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jdt.internal.core.NameLookup;
@@ -37,7 +35,7 @@
static {
// org.eclipse.jdt.internal.core.search.matching.MatchLocator.PRINT_BUFFER = false;
// TESTS_PREFIX = "testArray";
-// TESTS_NAMES = new String[] { "testFindBinaryTypeWithSameNameAsMember" };
+// TESTS_NAMES = new String[] { "testFindBinaryTypeWithDollarName" };
// TESTS_NUMBERS = new int[] { 8 };
// TESTS_RANGE = new int[] { 6, -1 };
}
@@ -267,68 +265,5 @@
deleteProject("P");
}
}
-/*
- * Performance test for looking up package fragments
- * (see bug 72683 Slow code assist in Display view)
- */
-public void testPerfSeekPackageFragments() throws CoreException {
- try {
- // setup projects with 100 source folders and 10 packages per source folder
- final int rootLength = 100;
- final String[] sourceFolders = new String[rootLength];
- for (int i = 0; i < rootLength; i++) {
- sourceFolders[i] = "src" + i;
- }
- String path = getWorkspaceRoot().getLocation().toString() + "/P/src";
- for (int i = 0; i < rootLength; i++) {
- for (int j = 0; j < 10; j++) {
- new java.io.File(path + i + "/org/eclipse/jdt/core/tests" + i + "/performance" + j).mkdirs();
- }
- }
- JavaProject project = (JavaProject)createJavaProject("P", sourceFolders, "bin");
-
- class PackageRequestor implements IJavaElementRequestor {
- ArrayList pkgs = new ArrayList();
- public void acceptField(IField field) {}
- public void acceptInitializer(IInitializer initializer) {}
- public void acceptMemberType(IType type) {}
- public void acceptMethod(IMethod method) {}
- public void acceptPackageFragment(IPackageFragment packageFragment) {
- if (pkgs != null)
- pkgs.add(packageFragment);
- }
- public void acceptType(IType type) {}
- public boolean isCanceled() {
- return false;
- }
- }
-
- // first pass: ensure all class are loaded, and ensure that the test works as expected
- PackageRequestor requestor = new PackageRequestor();
- getNameLookup(project).seekPackageFragments("org.eclipse.jdt.core.tests78.performance5", false/*not partial match*/, requestor);
- int size = requestor.pkgs.size();
- IJavaElement[] result = new IJavaElement[size];
- requestor.pkgs.toArray(result);
- assertElementsEqual(
- "Unexpected packages",
- "org.eclipse.jdt.core.tests78.performance5 [in src78 [in P]]",
- result
- );
-
- // measure performance
- requestor.pkgs = null;
- for (int i = 0; i < 100; i++) {
- startMeasuring();
- for (int j = 0; j < 40; j++) {
- getNameLookup(project).seekPackageFragments("org.eclipse.jdt.core.tests" + j + "0.performance" + j, false/*not partial match*/, requestor);
- }
- stopMeasuring();
- }
- commitMeasurements();
- assertPerformance();
- } finally {
- deleteProject("P");
- }
-}
}
Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v
retrieving revision 1.53
diff -u -r1.53 JavaSearchBugsTests.java
--- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 4 Nov 2005 15:21:02 -0000 1.53
+++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 22 Nov 2005 18:45:20 -0000
@@ -2816,6 +2816,9 @@
"Unexpected all type names",
"Test\n" +
"Test$Inner\n" +
+ "b108088.A108088\n" +
+ "b108088.B108088\n" +
+ "b108088.Test108088\n" +
"b81556.a.A81556\n" +
"b81556.a.B81556\n" +
"b81556.a.X81556\n" +
@@ -2878,6 +2881,9 @@
"Unexpected all type names",
"Test\n" +
"Test$Inner\n" +
+ "b108088.A108088\n" +
+ "b108088.B108088\n" +
+ "b108088.Test108088\n" +
"b81556.a.A81556\n" +
"b81556.a.B81556\n" +
"b81556.a.X81556\n" +
@@ -2935,6 +2941,9 @@
"Unexpected all type names",
"Test\n" +
"Test$Inner\n" +
+ "b108088.A108088\n" +
+ "b108088.B108088\n" +
+ "b108088.Test108088\n" +
"b81556.a.A81556\n" +
"b81556.a.B81556\n" +
"b81556.a.X81556\n" +
@@ -2995,6 +3004,9 @@
"Unexpected all type names",
"Test\n" +
"Test$Inner\n" +
+ "b108088.A108088\n" +
+ "b108088.B108088\n" +
+ "b108088.Test108088\n" +
"b81556.a.A81556\n" +
"b81556.a.B81556\n" +
"b81556.a.X81556\n" +
@@ -4458,6 +4470,22 @@
}
/**
+ * Bug 108088: [search] Inaccurate search match for method invocations with literal arguments
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=108088"
+ */
+public void testBug108088() throws CoreException {
+ ICompilationUnit unit = getCompilationUnit("JavaSearchBugs", "src", "b108088", "Test108088.java");
+ IType type = unit.getType("A108088");
+ IMethod method = type.getMethod("subroutine", new String[] { "F" });
+ SearchPattern pattern = SearchPattern.createPattern(method, REFERENCES, EXACT_RULE);
+ assertNotNull("Pattern should not be null", pattern);
+ search(pattern, getJavaSearchScopeBugs(), resultCollector);
+ assertSearchResults(
+ "src/b108088/B108088.java void b108088.B108088.doit(A108088, String) [subroutine(1.2f)] EXACT_MATCH"
+ );
+}
+
+/**
* @test Bug 110060: [plan][search] Add support for Camel Case search pattern
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=110060"
*/
Index: src/org/eclipse/jdt/core/tests/model/ClassNameTests.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java,v
retrieving revision 1.8
diff -u -r1.8 ClassNameTests.java
--- src/org/eclipse/jdt/core/tests/model/ClassNameTests.java 23 Feb 2005 02:58:37 -0000 1.8
+++ src/org/eclipse/jdt/core/tests/model/ClassNameTests.java 22 Nov 2005 18:45:17 -0000
@@ -11,26 +11,150 @@
package org.eclipse.jdt.core.tests.model;
import junit.framework.Test;
-import junit.framework.TestSuite;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.internal.core.SourceType;
+
+
/**
* Test retrieving types by their name.
*/
public class ClassNameTests extends ModifyingResourceTests {
+ static IJavaProject TEST_PROJECT;
+ final static int SF_LENGTH = 5;
+ static int TESTS_COUNT;
public ClassNameTests(String name) {
super(name);
}
-
+
+ static {
+// org.eclipse.jdt.internal.core.NameLookup.VERBOSE = true;
+// TESTS_NAMES = new String[] { "testReconcileMultipleProject" };
+// TESTS_PREFIX = "testReconcile";
+ }
+ public static Test suite() {
+ Test suite = buildTestSuite(ClassNameTests.class);
+ TESTS_COUNT = suite.countTestCases();
+ return suite;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#setUp()
+ */
+ protected void setUp() throws Exception {
+ if (org.eclipse.jdt.internal.core.NameLookup.VERBOSE || org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE) {
+ System.out.println("--------------------------------------------------------------------------------");
+ System.out.println("Running test "+getName()+"...");
+ }
+ super.setUp();
+ if (TEST_PROJECT == null) {
+ String[] sourceFolders = new String[SF_LENGTH];
+ for (int i=0; i [in src1 [in TestProject]]]]"
+ );
+ }
+ public void testFindSecondaryType_Exist06() throws JavaModelException, CoreException {
+ assertTypeFound(
+ "Secondary",
+ "Secondary [in Foo.java [in [in src1 [in TestProject]]]]"
+ );
}
+ // duplicate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=72179
+ public void testFindSecondaryType_Bug72179() throws JavaModelException, CoreException {
+ try {
+ IJavaProject javaProject = createJavaProject("P", new String[] {""}, "");
+ createFolder("/P/p1");
+ createFile(
+ "/P/p1/jc.java",
+ "package p1;\n" +
+ "class jc008{}\n" +
+ "class jc009{}\n" +
+ "class jc010 extends jc009 {\n" +
+ " jc008 a;\n" +
+ "}\n"
+ );
+ IType type = javaProject.findType("p1", "jc008");
+ assertTrue("type 'jc008' should exist!", type != null && type.exists());
+ assertEquals("Expected type 'jc008' NOT found!",
+ "class jc008 [in jc.java [in p1 [in [in P]]]]",
+ type.toString()
+ );
+ type = javaProject.findType("p1", "jc009");
+ assertTrue("type 'jc009' should exist!", type != null && type.exists());
+ assertEquals("Expected type 'jc009' NOT found!",
+ "class jc009 [in jc.java [in p1 [in [in P]]]]",
+ type.toString()
+ );
+ type = javaProject.findType("p1", "jc010");
+ assertTrue("type 'jc010' should exist!", type != null && type.exists());
+ assertEquals("Expected type 'jc010' NOT found!",
+ "class jc010 [in jc.java [in p1 [in [in P]]]]\n" +
+ " jc008 a",
+ type.toString()
+ );
+ } finally {
+ deleteProject("P");
+ }
+ }
+ public void testFindSecondaryType_NotFound01() throws JavaModelException, CoreException {
+ assertTypeUnknown("test.Foo");
+ }
+ public void testFindSecondaryType_NotFound02() throws JavaModelException, CoreException {
+ assertTypeUnknown("InFoo");
+ }
+ public void testFindSecondaryType_NotFound03() throws JavaModelException, CoreException {
+ assertTypeUnknown("InSecondary");
+ }
+ public void testFindSecondaryType_NotFound04() throws JavaModelException, CoreException {
+ assertTypeUnknown("Foo.inFoo");
+ }
+ public void testFindSecondaryType_NotFound05() throws JavaModelException, CoreException {
+ assertTypeUnknown("Secondary.inBar");
+ }
+ public void testFindSecondaryType_Unknown01() throws JavaModelException, CoreException {
+ assertTypeUnknown("Unknown");
+ }
+ public void testFindSecondaryType_Unknown02() throws JavaModelException, CoreException {
+ assertTypeUnknown("Foo.Unknown");
+ }
+ public void testFindSecondaryType_Unknown03() throws JavaModelException, CoreException {
+ assertTypeUnknown("org.eclipse.jdt.core.test.Unknown");
+ }
+ public void testReconcileSingleProject01() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ createJavaProject("P", new String[] {""}, new String[] {"JCL_LIB"}, "bin");
+ String source =
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " new SFoo().foo();\n" +
+ " }\n" +
+ "}\n";
+ this.createFile(
+ "/P/Foo.java",
+ "class SFoo { void foo() {} }\n"
+ );
+ this.createFile(
+ "/P/Test.java",
+ source
+ );
+ ProblemRequestor problemRequestor = new ProblemRequestor();
+ workingCopy = getCompilationUnit("/P/Test.java").getWorkingCopy(new WorkingCopyOwner() {}, problemRequestor, null);
+ problemRequestor.initialize(source.toCharArray());
+ workingCopy.getBuffer().setContents(source);
+ workingCopy.reconcile(AST.JLS3, true, null, null);
+ if (problemRequestor.problemCount > 0) {
+ assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
+ }
+ // Add new secondary type
+ this.createFile(
+ "/P/Bar.java",
+ "class SBar{ void bar() {} }\n"
+ );
+ waitUntilIndexesReady();
+ source =
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " new SFoo().foo();\n" +
+ " new SBar().bar();\n" +
+ " }\n" +
+ "}\n";
+ problemRequestor.initialize(source.toCharArray());
+ workingCopy.getBuffer().setContents(source);
+ workingCopy.reconcile(AST.JLS3, true, null, null);
+ if (problemRequestor.problemCount > 0) {
+ assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
+ }
+ } finally {
+ if (workingCopy != null) workingCopy.discardWorkingCopy();
+ deleteProject("P");
+ }
+ }
+ public void testReconcileSingleProject02() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ createJavaProject("P", new String[] {""}, new String[] {"JCL_LIB"}, "bin");
+ String source =
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " new SFoo().foo();\n" +
+ " new SBar().bar();\n" +
+ " }\n" +
+ "}\n";
+ createFile(
+ "/P/Foo.java",
+ "class SFoo { void foo() {} }\n"
+ );
+ createFile(
+ "/P/Test.java",
+ source
+ );
+ createFile(
+ "/P/Bar.java",
+ "class SBar{ void bar() {} }\n"
+ );
+ ProblemRequestor problemRequestor = new ProblemRequestor();
+ workingCopy = getCompilationUnit("/P/Test.java").getWorkingCopy(new WorkingCopyOwner() {}, problemRequestor, null);
+ problemRequestor.initialize(source.toCharArray());
+ workingCopy.getBuffer().setContents(source);
+ workingCopy.reconcile(AST.JLS3, true, null, null);
+ if (problemRequestor.problemCount > 0) {
+ assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
+ }
+ // Delete secondary type => should get a problem
+ waitUntilIndexesReady();
+ deleteFile("/P/Bar.java");
+ workingCopy.reconcile(AST.JLS3, true, null, null);
+ assertEquals("Working copy should not find secondary type 'Bar'!", 1, problemRequestor.problemCount);
+ assertEquals("Working copy should have problem!",
+ "----------\n" +
+ "----------\n" +
+ "----------\n" +
+ "1. ERROR in /P/Test.java (at line 4)\r\n" +
+ " new SBar().bar();\r\n" +
+ " ^^^^\n" +
+ "SBar cannot be resolved to a type\n" +
+ "----------\n",
+ problemRequestor.problems.toString()
+ );
+
+ // Fix the problem
+ source =
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " new SFoo().foo();\n" +
+ " }\n" +
+ "}\n";
+ problemRequestor.initialize(source.toCharArray());
+ workingCopy.getBuffer().setContents(source);
+ workingCopy.reconcile(AST.JLS3, true, null, null);
+ if (problemRequestor.problemCount > 0) {
+ assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
+ }
+ } finally {
+ if (workingCopy != null) workingCopy.discardWorkingCopy();
+ deleteProject("P");
+ }
+ }
+ public void testReconcileMultipleProject() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ // Create first project
+ createJavaProject("P1", new String[] {""}, new String[] {"JCL_LIB"}, "bin");
+ createFolder("/P1/test");
+ createFile(
+ "/P1/test/Foo.java",
+ "package test;\n" +
+ "class Secondary{ void foo() {} }\n"
+ );
+ createFile(
+ "/P1/test/Test1.java",
+ "package test;\n" +
+ "public class Test1 {\n" +
+ " public static void main(String[] args) {\n" +
+ " new Secondary().foo();\n" +
+ " }\n" +
+ "}\n"
+ );
+
+ // Create second project
+ createJavaProject("P2", new String[] {""}, new String[] {"JCL_LIB"}, new String[] { "/P1" }, "bin");
+ String source2 =
+ "package test;\n" +
+ "public class Test2 {\n" +
+ " public static void main(String[] args) {\n" +
+ " new Secondary().foo();\n" +
+ " }\n" +
+ "}\n";
+ createFolder("/P2/test");
+ createFile(
+ "/P2/test/Test2.java",
+ source2
+ );
+ ProblemRequestor problemRequestor = new ProblemRequestor();
+ workingCopy = getCompilationUnit("/P2/test/Test2.java").getWorkingCopy(new WorkingCopyOwner() {}, problemRequestor, null);
+ problemRequestor.initialize(source2.toCharArray());
+ workingCopy.getBuffer().setContents(source2);
+ workingCopy.reconcile(AST.JLS3, true, null, null);
+ if (problemRequestor.problemCount > 0) {
+ assertEquals("Working copy should NOT have any problem!", "", problemRequestor.problems.toString());
+ }
+ } finally {
+ if (workingCopy != null) workingCopy.discardWorkingCopy();
+ deleteProject("P1");
+ deleteProject("P2");
+ }
+ }
}
Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java,v
retrieving revision 1.16
diff -u -r1.16 ASTConverterAST3Test.java
--- src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java 17 Nov 2005 16:07:40 -0000 1.16
+++ src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java 22 Nov 2005 18:45:07 -0000
@@ -32,8 +32,7 @@
}
static {
-// TESTS_NAMES = new String[] {"test0602"};
-// TESTS_NUMBERS = new int[] { 368, 369 };
+// TESTS_NUMBERS = new int[] { 356 };
}
public static Test suite() {
return buildTestSuite(ASTConverterAST3Test.class);
@@ -8699,14 +8698,27 @@
assertNotNull("No compilation unit", result); //$NON-NLS-1$
assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
CompilationUnit compilationUnit = (CompilationUnit) result;
- assertEquals("errors found", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
assertNotNull(node);
assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
Type type = variableDeclarationStatement.getType();
ITypeBinding binding = type.resolveBinding();
- assertNull(binding);
+ assertNotNull("Binding should NOT be null for type: "+type, binding);
+
+ // Verify that class instance creation has a null binding
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Expect only one fragment for VariableDeclarationStatement: "+variableDeclarationStatement, 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Not a variable declaration fragment", ASTNode.VARIABLE_DECLARATION_FRAGMENT, node.getNodeType()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ assertEquals("Expect a class instance creation for initializer: "+initializer, ASTNode.CLASS_INSTANCE_CREATION, initializer.getNodeType()); //$NON-NLS-1$
+ ClassInstanceCreation instanceCreation = (ClassInstanceCreation) initializer;
+ type = instanceCreation.getType();
+ binding = type.resolveBinding();
+ assertNull("Binding should BE null for type: "+type, binding);
}
/**
Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java,v
retrieving revision 1.72
diff -u -r1.72 ASTConverterTest.java
--- src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java 17 Nov 2005 16:07:40 -0000 1.72
+++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java 22 Nov 2005 18:45:16 -0000
@@ -32,9 +32,9 @@
public ASTConverterTest(String name) {
super(name);
}
+
static {
-// TESTS_NAMES = new String[] {"test0602"};
-// TESTS_NUMBERS = new int[] { 618 };
+// TESTS_NUMBERS = new int[] { 356 };
}
public static Test suite() {
return buildTestSuite(ASTConverterTest.class);
@@ -8868,14 +8868,14 @@
assertNotNull("No compilation unit", result); //$NON-NLS-1$
assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
CompilationUnit compilationUnit = (CompilationUnit) result;
- assertEquals("errors found", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
assertNotNull(node);
assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
Type type = variableDeclarationStatement.getType();
ITypeBinding binding = type.resolveBinding();
- assertNull(binding);
+ assertNotNull("Binding should NOT be null for type: "+type, binding);
}
/**
Index: workspace/JavaSearchBugs/src/b108088/B108088.java
===================================================================
RCS file: workspace/JavaSearchBugs/src/b108088/B108088.java
diff -N workspace/JavaSearchBugs/src/b108088/B108088.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ workspace/JavaSearchBugs/src/b108088/B108088.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,7 @@
+package b108088;
+class B108088 {
+ public void doit(A108088 pApp, String doitArg) {
+ pApp.subroutine(1.2f);
+ }
+
+}
Index: workspace/JavaSearchBugs/src/b108088/Test108088.java
===================================================================
RCS file: workspace/JavaSearchBugs/src/b108088/Test108088.java
diff -N workspace/JavaSearchBugs/src/b108088/Test108088.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ workspace/JavaSearchBugs/src/b108088/Test108088.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,12 @@
+package b108088;
+class A108088 {
+ B108088 fB;
+ public void subroutine(float subArg) {
+ subsub();
+ }
+ public void subsub() {
+ }
+
+}
+public class Test108088 {
+}