### Eclipse Workspace Patch 1.0
#P org.eclipse.jdt.core
Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v
retrieving revision 1.285
diff -u -r1.285 MatchLocator.java
--- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 24 Nov 2006 01:32:04 -0000 1.285
+++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 29 Nov 2006 16:29:59 -0000
@@ -675,12 +675,17 @@
char[] importName = CharOperation.concatWith(importRef.getImportName(), '.');
if (importRef.onDemand)
importName = CharOperation.concat(importName, ".*" .toCharArray()); //$NON-NLS-1$
- Openable openable = this.currentPossibleMatch.openable;
- if (openable instanceof CompilationUnit)
- return ((CompilationUnit) openable).getImport(new String(importName));
+// Openable openable = this.currentPossibleMatch.openable;
+// if (openable instanceof CompilationUnit)
+// return ((CompilationUnit) openable).getImport(new String(importName));
+ CompilationUnit unit = this.currentPossibleMatch.getCompilationUnit();
+ if (unit != null) {
+ return unit.getImport(new String(importName));
+ }
// binary types do not contain import statements so just answer the top-level type as the element
- IType binaryType = ((ClassFile) openable).getType();
+// IType binaryType = ((ClassFile) this.currentPossibleMatch.openable).getType();
+ IType binaryType = this.currentPossibleMatch.getClassFile().getType();
String typeName = binaryType.getElementName();
int lastDollar = typeName.lastIndexOf('$');
if (lastDollar == -1) return binaryType;
@@ -692,9 +697,13 @@
protected IJavaElement createPackageDeclarationHandle(CompilationUnitDeclaration unit) {
if (unit.isPackageInfo()) {
char[] packName = CharOperation.concatWith(unit.currentPackage.getImportName(), '.');
- Openable openable = this.currentPossibleMatch.openable;
- if (openable instanceof CompilationUnit) {
- return ((CompilationUnit) openable).getPackageDeclaration(new String(packName));
+// Openable openable = this.currentPossibleMatch.openable;
+// if (openable instanceof CompilationUnit) {
+// return ((CompilationUnit) openable).getPackageDeclaration(new String(packName));
+// }
+ CompilationUnit cu = this.currentPossibleMatch.getCompilationUnit();
+ if (cu != null) {
+ return cu.getPackageDeclaration(new String(packName));
}
}
return createTypeHandle(new String(unit.getMainTypeName()));
@@ -703,11 +712,16 @@
* Creates an IType from the given simple top level type name.
*/
protected IType createTypeHandle(String simpleTypeName) {
- Openable openable = this.currentPossibleMatch.openable;
- if (openable instanceof CompilationUnit)
- return ((CompilationUnit) openable).getType(simpleTypeName);
+// Openable openable = this.currentPossibleMatch.openable;
+// if (openable instanceof CompilationUnit)
+// return ((CompilationUnit) openable).getType(simpleTypeName);
+ CompilationUnit unit = this.currentPossibleMatch.getCompilationUnit();
+ if (unit != null) {
+ return unit.getType(simpleTypeName);
+ }
- IType binaryType = ((ClassFile) openable).getType();
+// IType binaryType = ((ClassFile) openable).getType();
+ IType binaryType = this.currentPossibleMatch.getClassFile().getType();
String binaryTypeQualifiedName = binaryType.getTypeQualifiedName();
if (simpleTypeName.equals(binaryTypeQualifiedName))
return binaryType; // answer only top-level types, sometimes the classFile is for a member/local type
@@ -930,7 +944,7 @@
/**
* Create a new parser for the given project, as well as a lookup environment.
*/
-public void initialize(JavaProject project, int possibleMatchSize) throws JavaModelException {
+public void initialize(JavaProject project, int possibleMatchSize, long highestSourceLevel) throws JavaModelException {
// clean up name environment only if there are several possible match as it is reused
// when only one possible match (bug 58581)
if (this.nameEnvironment != null && possibleMatchSize != 1)
@@ -949,6 +963,15 @@
Map map = project.getOptions(true);
map.put(CompilerOptions.OPTION_TaskTags, ""); //$NON-NLS-1$
this.options = new CompilerOptions(map);
+ // force source level to highest one
+ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=166093
+ if (highestSourceLevel > this.options.sourceLevel) {
+ this.options.sourceLevel = highestSourceLevel;
+ if (highestSourceLevel > ClassFileConstants.JDK1_4) {
+ this.options.complianceLevel = highestSourceLevel;
+ this.options.targetJDK = highestSourceLevel;
+ }
+ }
ProblemReporter problemReporter =
new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
@@ -970,7 +993,15 @@
this.matchesToProcess = new PossibleMatch[possibleMatchSize];
}
protected void locateMatches(JavaProject javaProject, PossibleMatch[] possibleMatches, int start, int length) throws CoreException {
- initialize(javaProject, length);
+ long highestSourceLevel = 0;
+ for (int i = start, maxUnits = start + length; i < maxUnits; i++) {
+ PossibleMatch possibleMatch = possibleMatches[i];
+ long version = possibleMatch.getVersion();
+ if (version > highestSourceLevel) {
+ highestSourceLevel = version;
+ }
+ }
+ initialize(javaProject, length, highestSourceLevel);
// create and resolve binding (equivalent to beginCompilation() in Compiler)
boolean mustResolvePattern = ((InternalSearchPattern)this.pattern).mustResolve;
@@ -1515,8 +1546,10 @@
CompilationUnitDeclaration unit = possibleMatch.parsedUnit;
try {
if (unit.isEmpty()) {
- if (this.currentPossibleMatch.openable instanceof ClassFile) {
- ClassFile classFile = (ClassFile) this.currentPossibleMatch.openable;
+ ClassFile classFile = this.currentPossibleMatch.getClassFile();
+// if (this.currentPossibleMatch.openable instanceof ClassFile) {
+ if (classFile != null) {
+// ClassFile classFile = (ClassFile) this.currentPossibleMatch.openable;
IBinaryType info = getBinaryInfo(classFile, this.currentPossibleMatch.resource);
if (info != null) {
boolean mayBeGeneric = this.patternLocator.mayBeGeneric;
@@ -2339,7 +2372,8 @@
} else if (enclosingElement instanceof IMember) {
IMember member = (IMember) parent;
if (member.isBinary()) {
- enclosingElement = ((IClassFile)this.currentPossibleMatch.openable).getType();
+// enclosingElement = ((IClassFile)this.currentPossibleMatch.openable).getType();
+ enclosingElement = this.currentPossibleMatch.getClassFile().getType();
} else {
enclosingElement = member.getType(new String(type.name), occurrenceCount);
}
Index: search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java,v
retrieving revision 1.26
diff -u -r1.26 PossibleMatch.java
--- search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java 14 Nov 2006 16:38:47 -0000 1.26
+++ search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java 29 Nov 2006 16:29:59 -0000
@@ -15,6 +15,7 @@
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.search.SearchDocument;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.core.*;
@@ -32,6 +33,7 @@
public SearchDocument document;
private String sourceFileName;
private char[] source;
+private long version = -1;
public PossibleMatch(MatchLocator locator, IResource resource, Openable openable, SearchDocument document, boolean mustResolve) {
this.resource = resource;
@@ -39,8 +41,12 @@
this.document = document;
this.nodeSet = new MatchingNodeSet(mustResolve);
char[] qualifiedName = getQualifiedName();
- if (qualifiedName != null)
+ if (qualifiedName != null) {
this.compoundName = CharOperation.splitOn('.', qualifiedName);
+ }
+ if (openable instanceof CompilationUnit) {
+ this.version = 0;
+ }
}
public void cleanUp() {
this.source = null;
@@ -58,6 +64,23 @@
// Even .class files for secondary types and their nested types
return CharOperation.equals(this.compoundName, ((PossibleMatch) obj).compoundName);
}
+public ClassFile getClassFile() {
+ if (this.version >= ClassFileConstants.JDK1_1) {
+ return (ClassFile) this.openable;
+ }
+ if (this.version == -1) {
+ if (this.openable instanceof ClassFile) {
+ return (ClassFile) this.openable;
+ }
+ }
+ return null;
+}
+public CompilationUnit getCompilationUnit() {
+ if (this.version == 0) {
+ return (CompilationUnit) this.openable;
+ }
+ return null;
+}
public char[] getContents() {
if (this.source != null) return this.source;
@@ -128,10 +151,21 @@
if (reader != null) {
String fileName = type.sourceFileName(reader);
this.sourceFileName = fileName == null ? NO_SOURCE_FILE_NAME : fileName;
+ this.version = reader.getVersion();
}
}
return this.sourceFileName;
}
+/**
+ * Returns the version of the associated .class file, 0 for source file
+ * and -1 when the class file has not been opened yet
+ *
+ * @return the JDK level of the associated .class file. Returns 0 for
+ * compilation unit or -1 when the class file is not opened yet.
+ */
+public long getVersion() {
+ return this.version;
+}
public int hashCode() {
if (this.compoundName == null) return super.hashCode();
Index: search/org/eclipse/jdt/internal/core/search/matching/SuperTypeNamesCollector.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/SuperTypeNamesCollector.java,v
retrieving revision 1.56
diff -u -r1.56 SuperTypeNamesCollector.java
--- search/org/eclipse/jdt/internal/core/search/matching/SuperTypeNamesCollector.java 29 Mar 2006 03:13:59 -0000 1.56
+++ search/org/eclipse/jdt/internal/core/search/matching/SuperTypeNamesCollector.java 29 Nov 2006 16:29:59 -0000
@@ -135,7 +135,7 @@
this.result = new char[1][][];
this.resultIndex = 0;
JavaProject javaProject = (JavaProject) this.type.getJavaProject();
- this.locator.initialize(javaProject, 0);
+ this.locator.initialize(javaProject, 0, -1);
try {
if (this.type.isBinary()) {
BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null);
@@ -179,7 +179,7 @@
IJavaProject project = openable.getJavaProject();
if (!project.equals(previousProject)) {
previousProject = (JavaProject) project;
- this.locator.initialize(previousProject, 0);
+ this.locator.initialize(previousProject, 0, -1);
}
if (openable instanceof ICompilationUnit) {
ICompilationUnit unit = (ICompilationUnit) openable;
Index: search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java,v
retrieving revision 1.71
diff -u -r1.71 MethodLocator.java
--- search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java 10 Nov 2006 17:54:00 -0000 1.71
+++ search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java 29 Nov 2006 16:29:59 -0000
@@ -334,7 +334,7 @@
// verify closest match if pattern was bound
// (see bug 70827)
if (focus != null && focus.getElementType() == IJavaElement.METHOD) {
- if (methodBinding != null) {
+ if (methodBinding != null && methodBinding.isValidBinding()) {
boolean isPrivate = Flags.isPrivate(((IMethod) focus).getFlags());
if (isPrivate && !CharOperation.equals(methodBinding.declaringClass.sourceName, focus.getParent().getElementName().toCharArray())) {
return; // finally the match was not possible
Index: model/org/eclipse/jdt/core/IClasspathEntry.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IClasspathEntry.java,v
retrieving revision 1.59
diff -u -r1.59 IClasspathEntry.java
--- model/org/eclipse/jdt/core/IClasspathEntry.java 29 Sep 2006 17:13:57 -0000 1.59
+++ model/org/eclipse/jdt/core/IClasspathEntry.java 29 Nov 2006 16:29:58 -0000
@@ -15,7 +15,7 @@
/**
* An entry on a Java project classpath identifying one or more package fragment
* roots. A classpath entry has a content kind (either source,
- * K_SOURCE
, or binary, K_BINARY
), which is inherited
+ * {@link IPackageFragmentRoot#K_SOURCE}, or binary, {@link IPackageFragmentRoot#K_BINARY}), which is inherited
* by each package fragment root and package fragment associated with the entry.
*
* A classpath entry can refer to any of the following:
CPE_SOURCE
constant.
+ * associated with the {@link #CPE_SOURCE} constant.
* Source classpath entries can carry inclusion and exclusion patterns for
* selecting which source files appear as compilation
* units and get compiled when the project is built.
@@ -40,7 +40,7 @@
* package fragments and .class
files. The classpath entry
* must specify the absolute path to the JAR (or root folder), and in case it refers
* to an external JAR, then there is no associated resource in the workbench. Entries
- * of this kind are associated with the CPE_LIBRARY
constant.
+ * of this kind are associated with the {@link #CPE_LIBRARY} constant.
*
* CPE_PROJECT
+ * project. Entries of this kind are associated with the {@link #CPE_PROJECT}
* constant.
* Note: referencing a required project with a classpath entry refers to the source
* code or associated .class
files located in its output location.
* It will also automatically include any other libraries or projects that the required project's classpath
* refers to, iff the corresponding classpath entries are tagged as being exported
- * (IClasspathEntry#isExported
).
+ * ({@link IClasspathEntry#isExported}).
* Unless exporting some classpath entries, classpaths are not chained by default -
* each project must specify its own classpath in its entirety.CPE_VARIABLE
constant.
- * Classpath variables are created using JavaCore#setClasspathVariable
,
+ * Entries of this kind are associated with the {@link #CPE_VARIABLE} constant.
+ * Classpath variables are created using {@link JavaCore#setClasspathVariable(String, IPath, org.eclipse.core.runtime.IProgressMonitor)},
* and gets resolved, to either a project or library entry, using
- * JavaCore#getResolvedClasspathVariable
.
- * It is also possible to register an automatic initializer (ClasspathVariableInitializer
),
+ * {@link JavaCore#getResolvedClasspathEntry(IClasspathEntry)}.
+ * It is also possible to register an automatic initializer ({@link ClasspathVariableInitializer}),
* which will be invoked through the extension point "org.eclipse.jdt.core.classpathVariableInitializer".
* After resolution, a classpath variable entry may either correspond to a project or a library entry. CPE_CONTAINER
. Typically, a classpath container can
+ * a classpath entry of kind {@link #CPE_CONTAINER}. Typically, a classpath container can
* be used to describe a complex library composed of multiple JARs, projects or classpath variables,
* considering also that containers can be mapped differently on each project. Several projects can
* reference the same generic container path, but have each of them actually bound to a different
* container object.
* The container path is a formed by a first ID segment followed with extra segments,
* which can be used as additional hints for resolving this container reference. If no container was ever
- * recorded for this container path onto this project (using setClasspathContainer
,
- * then a ClasspathContainerInitializer
will be activated if any was registered for this
+ * recorded for this container path onto this project (using {@link JavaCore#setClasspathContainer},
+ * then a {@link ClasspathContainerInitializer} will be activated if any was registered for this
* container ID onto the extension point "org.eclipse.jdt.core.classpathContainerInitializer".
- * A classpath container entry can be resolved explicitly using JavaCore#getClasspathContainer
+ * A classpath container entry can be resolved explicitly using {@link JavaCore#getClasspathContainer}
* and the resulting container entries can contain any non-container entry. In particular, it may contain variable
* entries, which in turn needs to be resolved before being directly used.
* IJavaProject#getResolvedClasspath
will have all entries of type
- * CPE_VARIABLE
and CPE_CONTAINER
resolved to a set of
- * CPE_SOURCE
, CPE_LIBRARY
or CPE_PROJECT
+ * The result of {@link IJavaProject#getResolvedClasspath} will have all entries of type
+ * {@link #CPE_VARIABLE} and {@link #CPE_CONTAINER} resolved to a set of
+ * {@link #CPE_SOURCE}, {@link #CPE_LIBRARY} or {@link #CPE_PROJECT}
* classpath entries.
*
- * Any classpath entry other than a source folder (kind CPE_SOURCE
) can
+ * Any classpath entry other than a source folder (kind {@link #CPE_SOURCE}) can
* be marked as being exported. Exported entries are automatically contributed to
* dependent projects, along with the project's default output folder, which is
* implicitly exported, and any auxiliary output folders specified on source
@@ -102,7 +102,7 @@
* followed by the any exported entries.
*
* This interface is not intended to be implemented by clients.
- * Classpath entries can be created via methods on JavaCore
.
+ * Classpath entries can be created via methods on {@link JavaCore}.
*
IPackageFragmentRoot.K_SOURCE
for files containing
- * source code, and IPackageFragmentRoot.K_BINARY
for binary
+ * @return {@link IPackageFragmentRoot#K_SOURCE} for files containing
+ * source code, and {@link IPackageFragmentRoot#K_BINARY} for binary
* class files.
- * There is no specified value for an entry denoting a variable (CPE_VARIABLE
)
- * or a classpath container (CPE_CONTAINER
).
+ * There is no specified value for an entry denoting a variable ({@link #CPE_VARIABLE})
+ * or a classpath container ({@link #CPE_CONTAINER}).
*/
int getContentKind();
@@ -183,16 +183,16 @@
*
* @return one of:
* CPE_SOURCE
- this entry describes a source root in
+ * CPE_LIBRARY
- this entry describes a folder or JAR
+ * CPE_PROJECT
- this entry describes another project
+ * CPE_VARIABLE
- this entry describes a project or library
+ * CPE_CONTAINER
- this entry describes set of entries
+ * .class
files generated for this source entry
- * (entry kind CPE_SOURCE
).
+ * (entry kind {@link #CPE_SOURCE}).
*
* Source entries can optionally be associated with a specific output location.
* If none is provided, the source entry will be implicitly associated with its project
- * default output location (see IJavaProject#getOutputLocation
).
+ * default output location (see {@link IJavaProject#getOutputLocation}).
*
* NOTE: A specific output location cannot coincidate with another source/library entry. *
@@ -364,24 +364,24 @@ * Returns the path of this classpath entry. * * The meaning of the path of a classpath entry depends on its entry kind:CPE_SOURCE
) -
+ * CPE_LIBRARY
) - the path
+ * CPE_PROJECT
) - the path of the entry denotes the
+ * CPE_VARIABLE
) - the first segment of the path
+ * CPE_CONTAINER
) - the path of the entry
+ * IClasspathContainer
).
+ * reference (also see {@link IClasspathContainer}).
* null
value
- * if and only if getSourceAttachmentPath
returns
+ * if and only if {@link #getSourceAttachmentPath} returns
* a non-null
value.
*
* @return the path within the source archive or folder, or null
if
@@ -421,7 +421,7 @@
/**
* Returns whether this entry is exported to dependent projects.
* Always returns false
for source entries (kind
- * CPE_SOURCE
), which cannot be exported.
+ * {@link #CPE_SOURCE}), which cannot be exported.
*
* @return true
if exported, and false
otherwise
* @since 2.0