### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java,v retrieving revision 1.40 diff -u -r1.40 CompletionTests2.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests2.java 27 Jun 2008 16:02:38 -0000 1.40 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests2.java 15 Jul 2008 11:03:10 -0000 @@ -33,6 +33,7 @@ import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.internal.codeassist.RelevanceConstants; import org.eclipse.jdt.internal.core.JavaModelManager; @@ -2338,4 +2339,213 @@ deleteResource(new File(jarName)); } } +public void testBug237469a() throws Exception { + String externalJar1 = Util.getOutputDirectory() + File.separator + "bug237469a.jar"; //$NON-NLS-1$ + String externalJar2 = Util.getOutputDirectory() + File.separator + "bug237469b.jar"; //$NON-NLS-1$ + + try { + // create variable +// JavaCore.setClasspathVariables( +// new String[] {"JCL_LIB", "JCL_SRC", "JCL_SRCROOT"}, +// new IPath[] {getExternalJCLPath(), getExternalJCLSourcePath(), getExternalJCLRootSourcePath()}, +// null); + + + // create external jar 1 + Util.createJar( + new String[] { + "test/IProject.java", //$NON-NLS-1$ + "package test;\n" + //$NON-NLS-1$ + "public class IProject {\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + }, + new HashMap(), + externalJar1); + + // create external jar 2 + Util.createJar( + new String[] { + "test/IJavaProject.java", //$NON-NLS-1$ + "package test;\n" + //$NON-NLS-1$ + "import test.IProject;\n" + //$NON-NLS-1$ + "public class IJavaProject {\n" + //$NON-NLS-1$ + " IProject project = null;\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + }, + null, + new HashMap(), + new String[]{externalJar1}, + externalJar2); + + // create P1 + this.createJavaProject( + "PS1", + new String[]{"src"}, + new String[]{"JCL_LIB", externalJar1, externalJar2}, + "bin"); + + this.createFolder("/PS1/src/test"); + this.createFile( + "/PS1/src/test/Y.java", + "package test;\n"+ + "import test.IProject;\n"+ + "import test.IJavaProject;\n"+ + "public class Y {\n"+ + " IProject project;\n"+ + " IJavaProject javaProject;\n"+ + "}"); + + // create P2 + this.createJavaProject( + "PS2", + new String[]{"src"}, + new String[]{"JCL_LIB", externalJar2}, + new String[]{"/PS1"}, + "bin"); + + this.createFolder("/PS2/src/test"); + this.createFile( + "/PS2/src/test/X.java", + "package test;\n"+ + "public class X extends test.Y {\n"+ + " private Object initializer;\n"+ + " public void foo() {\n"+ + " initializer\n"+ + " }\n"+ + "}"); + + waitUntilIndexesReady(); + + // do completion + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(); + ICompilationUnit cu= getCompilationUnit("PS2", "src", "test", "X.java"); + + String str = cu.getSource(); + String completeBehind = "initializer"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + cu.codeComplete(cursorLocation, requestor); + + assertResults( + "initializer[FIELD_REF]{initializer, Ltest.X;, Ljava.lang.Object;, initializer, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_EXACT_NAME + R_UNQUALIFIED + R_NON_RESTRICTED) + "}", + requestor.getResults()); + } finally { + this.deleteProject("PS1"); + this.deleteProject("PS2"); + this.deleteFile(externalJar1); + this.deleteFile(externalJar2); + } +} +public void testBug237469b() throws Exception { + String externalJar1 = Util.getOutputDirectory() + File.separator + "bug237469a.jar"; //$NON-NLS-1$ + String externalJar2 = Util.getOutputDirectory() + File.separator + "bug237469b.jar"; //$NON-NLS-1$ + + try { + // create variable +// JavaCore.setClasspathVariables( +// new String[] {"JCL_LIB", "JCL_SRC", "JCL_SRCROOT"}, +// new IPath[] {getExternalJCLPath(), getExternalJCLSourcePath(), getExternalJCLRootSourcePath()}, +// null); + + + // create external jar 1 + Util.createJar( + new String[] { + "test/IProject.java", //$NON-NLS-1$ + "package test;\n" + //$NON-NLS-1$ + "public class IProject {\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + }, + new HashMap(), + externalJar1); + + // create external jar 2 + Util.createJar( + new String[] { + "test/IJavaProject.java", //$NON-NLS-1$ + "package test;\n" + //$NON-NLS-1$ + "import test.IProject;\n" + //$NON-NLS-1$ + "public class IJavaProject {\n" + //$NON-NLS-1$ + " IProject project = null;\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + }, + null, + new HashMap(), + new String[]{externalJar1}, + externalJar2); + + // create P1 + this.createJavaProject( + "PS1", + new String[]{"src"}, + new String[]{"JCL_LIB", externalJar1, externalJar2}, + "bin"); + + this.createFolder("/PS1/src/test"); + this.createFile( + "/PS1/src/test/Y.java", + "package test;\n"+ + "import test.IProject;\n"+ + "import test.IJavaProject;\n"+ + "public class Y {\n"+ + " IProject project;\n"+ + " IJavaProject javaProject;\n"+ + "}"); + + // create P2 + this.createJavaProject( + "PS2", + new String[]{"src"}, + new String[]{"JCL_LIB", externalJar2}, + new String[]{"/PS1"}, + "bin"); + + this.createFolder("/PS2/src/test"); + this.createFile( + "/PS2/src/test/X.java", + "package test;\n"+ + "public class X extends test.Y {\n"+ + " private X initializer;\n"+ + " public void foo() {\n"+ + " Object o; o.equals\n"+ + " }\n"+ + "}"); + + waitUntilIndexesReady(); + + // do completion + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(false, false, false, false); + requestor.setRequireExtendedContext(true); + requestor.setComputeEnclosingElement(false); + requestor.setComputeVisibleElements(true); + requestor.setAssignableType("Ltest/X;"); + + ICompilationUnit cu= getCompilationUnit("PS2", "src", "test", "X.java"); + + String str = cu.getSource(); + String completeBehind = "equals"; + + int tokenStart = str.lastIndexOf(completeBehind); + int tokenEnd = tokenStart + completeBehind.length() - 1; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + cu.codeComplete(cursorLocation, requestor); + + assertResults( + "completion offset="+(cursorLocation)+"\n" + + "completion range=["+(tokenStart)+", "+(tokenEnd)+"]\n" + + "completion token=\"equals\"\n" + + "completion token kind=TOKEN_KIND_NAME\n" + + "expectedTypesSignatures=null\n" + + "expectedTypesKeys=null\n"+ + "completion token location=UNKNOWN\n"+ + "visibleElements={\n" + + " initializer {key=Ltest/X;.initializer)Ltest/X;} [in X [in X.java [in test [in src [in PS2]]]]],\n" + + "}", + requestor.getContext()); + } finally { + this.deleteProject("PS1"); + this.deleteProject("PS2"); + this.deleteFile(externalJar1); + this.deleteFile(externalJar2); + } +} } #P org.eclipse.jdt.core Index: codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java,v retrieving revision 1.7 diff -u -r1.7 InternalExtendedCompletionContext.java --- codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java 27 Jun 2008 16:04:05 -0000 1.7 +++ codeassist/org/eclipse/jdt/internal/codeassist/InternalExtendedCompletionContext.java 15 Jul 2008 11:03:11 -0000 @@ -155,46 +155,52 @@ } private void computeVisibleElementBindings() { - this.hasComputedVisibleElementBindings = true; - - Scope scope = this.assistScope; - ASTNode astNode = this.assistNode; - boolean notInJavadoc = this.completionContext.javadoc == 0; - - this.visibleLocalVariables = new ObjectVector(); - this.visibleFields = new ObjectVector(); - this.visibleMethods = new ObjectVector(); - this.bindingsToNodes = new HashMap(); - - ReferenceContext referenceContext = scope.referenceContext(); - if (referenceContext instanceof AbstractMethodDeclaration) { - // completion is inside a method body - searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc); - } else if (referenceContext instanceof TypeDeclaration) { - TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext; - FieldDeclaration[] fields = typeDeclaration.fields; - if (fields != null) { - done : for (int i = 0; i < fields.length; i++) { - if (fields[i] instanceof Initializer) { - Initializer initializer = (Initializer) fields[i]; - if (initializer.block.sourceStart <= astNode.sourceStart && - astNode.sourceStart < initializer.bodyEnd) { - // completion is inside an initializer - searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc); - break done; - } - } else { - FieldDeclaration fieldDeclaration = fields[i]; - if (fieldDeclaration.initialization != null && - fieldDeclaration.initialization.sourceStart <= astNode.sourceStart && - astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) { - // completion is inside a field initializer - searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc); - break done; + CompilationUnitDeclaration previousUnitBeingCompleted = this.lookupEnvironment.unitBeingCompleted; + this.lookupEnvironment.unitBeingCompleted = this.compilationUnitDeclaration; + try { + this.hasComputedVisibleElementBindings = true; + + Scope scope = this.assistScope; + ASTNode astNode = this.assistNode; + boolean notInJavadoc = this.completionContext.javadoc == 0; + + this.visibleLocalVariables = new ObjectVector(); + this.visibleFields = new ObjectVector(); + this.visibleMethods = new ObjectVector(); + this.bindingsToNodes = new HashMap(); + + ReferenceContext referenceContext = scope.referenceContext(); + if (referenceContext instanceof AbstractMethodDeclaration) { + // completion is inside a method body + searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc); + } else if (referenceContext instanceof TypeDeclaration) { + TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext; + FieldDeclaration[] fields = typeDeclaration.fields; + if (fields != null) { + done : for (int i = 0; i < fields.length; i++) { + if (fields[i] instanceof Initializer) { + Initializer initializer = (Initializer) fields[i]; + if (initializer.block.sourceStart <= astNode.sourceStart && + astNode.sourceStart < initializer.bodyEnd) { + // completion is inside an initializer + searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc); + break done; + } + } else { + FieldDeclaration fieldDeclaration = fields[i]; + if (fieldDeclaration.initialization != null && + fieldDeclaration.initialization.sourceStart <= astNode.sourceStart && + astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) { + // completion is inside a field initializer + searchVisibleVariablesAndMethods(scope, this.visibleLocalVariables, this.visibleFields, this.visibleMethods, notInJavadoc); + break done; + } } } } } + } finally { + this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted; } } #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java,v retrieving revision 1.65 diff -u -r1.65 Util.java --- src/org/eclipse/jdt/core/tests/util/Util.java 27 Jun 2008 16:04:46 -0000 1.65 +++ src/org/eclipse/jdt/core/tests/util/Util.java 15 Jul 2008 11:03:12 -0000 @@ -152,6 +152,9 @@ return result; } public static void compile(String[] pathsAndContents, Map options, String outputPath) { + compile(pathsAndContents, options, null, outputPath); +} +public static void compile(String[] pathsAndContents, Map options, String[] classpath, String outputPath) { IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); Requestor requestor = new Requestor( @@ -161,7 +164,17 @@ false /* show warning token*/); requestor.outputPath = outputPath.endsWith(File.separator) ? outputPath : outputPath + File.separator; - INameEnvironment nameEnvironment = new FileSystem(getJavaClassLibs(), new String[] {}, null); + String[] classLibs = getJavaClassLibs(); + if (classpath != null) { + int length = classpath.length; + int classLibsLength = classLibs.length; + System.arraycopy(classpath, 0, classpath = new String[classLibsLength + length], classLibsLength, length); + System.arraycopy(classLibs, 0, classpath, 0, classLibsLength); + } else { + classpath = classLibs; + } + + INameEnvironment nameEnvironment = new FileSystem(classpath, new String[] {}, null); IErrorHandlingPolicy errorHandlingPolicy = new IErrorHandlingPolicy() { public boolean proceedOnErrors() { @@ -317,14 +330,21 @@ compile(pathsAndContents, getCompileOptions(compliance), folderPath); } public static void createJar(String[] pathsAndContents, Map options, String jarPath) throws IOException { - createJar(pathsAndContents, null, options, jarPath); + createJar(pathsAndContents, null, options, null, jarPath); } public static void createJar(String[] pathsAndContents, String[] extraPathsAndContents, Map options, String jarPath) throws IOException { + createJar(pathsAndContents, extraPathsAndContents, options, null, jarPath); +} +public static void createJar(String[] pathsAndContents, String[] extraPathsAndContents, Map options, String jarPath, String[] classpath) throws IOException { + createJar(pathsAndContents, extraPathsAndContents, options, classpath, jarPath); +} + +public static void createJar(String[] pathsAndContents, String[] extraPathsAndContents, Map options, String[] classpath, String jarPath) throws IOException { String classesPath = getOutputDirectory() + File.separator + "classes"; File classesDir = new File(classesPath); flushDirectoryContent(classesDir); if (pathsAndContents != null) { - compile(pathsAndContents, options, classesPath); + compile(pathsAndContents, options, classpath, classesPath); } for (int i = 0, l = extraPathsAndContents == null ? 0 : extraPathsAndContents.length; i < l; /* inc in loop */) { File outputFile = new File(classesPath, extraPathsAndContents[i++]); @@ -337,7 +357,7 @@ createJar(javaPathsAndContents, null, jarPath, compliance); } public static void createJar(String[] javaPathsAndContents, String[] extraPathsAndContents, String jarPath, String compliance) throws IOException { - createJar(javaPathsAndContents, extraPathsAndContents, getCompileOptions(compliance), jarPath); + createJar(javaPathsAndContents, extraPathsAndContents, getCompileOptions(compliance), null, jarPath); } public static void createSourceZip(String[] pathsAndContents, String zipPath) throws IOException { String sourcesPath = getOutputDirectory() + File.separator + "sources";