### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/MethodBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java,v retrieving revision 1.65 diff -u -r1.65 MethodBinding.java --- dom/org/eclipse/jdt/core/dom/MethodBinding.java 20 Oct 2005 13:26:47 -0000 1.65 +++ dom/org/eclipse/jdt/core/dom/MethodBinding.java 16 Dec 2005 13:51:58 -0000 @@ -200,14 +200,20 @@ // case of method not in the created AST, or a binary method org.eclipse.jdt.internal.compiler.lookup.MethodBinding original = this.binding.original(); String selector = original.isConstructor() ? declaringType.getElementName() : new String(original.selector); + boolean isBinary = declaringType.isBinary(); + ReferenceBinding enclosingType = original.declaringClass.enclosingType(); + boolean isInnerBinaryTypeConstructor = isBinary && original.isConstructor() && enclosingType != null; TypeBinding[] parameters = original.parameters; int length = parameters == null ? 0 : parameters.length; - String[] parameterSignatures = new String[length]; + int declaringIndex = isInnerBinaryTypeConstructor ? 1 : 0; + String[] parameterSignatures = new String[declaringIndex + length]; + if (isInnerBinaryTypeConstructor) + parameterSignatures[0] = new String(enclosingType.genericTypeSignature()).replace('/', '.'); for (int i = 0; i < length; i++) { - parameterSignatures[i] = new String(parameters[i].genericTypeSignature()).replace('/', '.'); + parameterSignatures[declaringIndex + i] = new String(parameters[i].genericTypeSignature()).replace('/', '.'); } IMethod result = declaringType.getMethod(selector, parameterSignatures); - if (declaringType.isBinary()) + if (isBinary) return (JavaElement) result; IMethod[] methods = null; try { Index: model/org/eclipse/jdt/internal/core/SourceMapper.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SourceMapper.java,v retrieving revision 1.115 diff -u -r1.115 SourceMapper.java --- model/org/eclipse/jdt/internal/core/SourceMapper.java 17 Oct 2005 18:18:05 -0000 1.115 +++ model/org/eclipse/jdt/internal/core/SourceMapper.java 16 Dec 2005 13:51:59 -0000 @@ -687,10 +687,19 @@ this.memberNameRange[typeDepth] = new SourceRange(methodInfo.nameSourceStart, methodInfo.nameSourceEnd - methodInfo.nameSourceStart + 1); this.memberDeclarationStart[typeDepth] = methodInfo.declarationStart; - this.methodParameterTypes[typeDepth] = methodInfo.parameterTypes; - this.methodParameterNames[typeDepth] = methodInfo. parameterNames; - IType currentType = this.types[typeDepth]; + char[][] parameterTypes = methodInfo.parameterTypes; + if (parameterTypes != null && methodInfo.isConstructor && currentType.getDeclaringType() != null) { + int length = parameterTypes.length; + char[][] newParameterTypes = new char[length+1][]; + newParameterTypes[0] = currentType.getDeclaringType().getElementName().toCharArray(); + System.arraycopy(parameterTypes, 0, newParameterTypes, 1, length); + this.methodParameterTypes[typeDepth] = newParameterTypes; + } else { + this.methodParameterTypes[typeDepth] = parameterTypes; + } + this.methodParameterNames[typeDepth] = methodInfo.parameterNames; + IMethod method = currentType.getMethod( this.memberName[typeDepth], convertTypeNamesToSigs(this.methodParameterTypes[typeDepth])); #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java,v retrieving revision 1.38 diff -u -r1.38 AttachSourceTests.java --- src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 10 Nov 2005 21:29:07 -0000 1.38 +++ src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 16 Dec 2005 13:52:03 -0000 @@ -33,7 +33,7 @@ */ public class AttachSourceTests extends ModifyingResourceTests { static { -// TESTS_NAMES = new String[] { "testRootPath13" }; +// TESTS_NAMES = new String[] { "testClassFileGetElementAt04" }; // TESTS_NUMBERS = new int[] { 5 }; // TESTS_RANGE = new int[] { 169, 180 }; } @@ -109,6 +109,8 @@ " }\n" + " }\n" + " class V {\n" + + " V(String s) {\n" + + " }\n" + " }\n" + "}" }; @@ -218,29 +220,52 @@ /** * Ensure that a class file with an attached source can retrieve its children given a source index. */ -public void testClassFileGetElementAt() throws JavaModelException { - IClassFile cf = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class"); - IJavaElement elt = null; - - elt = cf.getElementAt(15); - assertTrue("should have found \"A\"", - elt != null && - elt.getElementType() == IJavaElement.TYPE && - elt.getElementName().equals("A")); - - elt = cf.getElementAt(53); - assertTrue("should have found \"public A()\"", - elt != null && - elt.getElementType() == IJavaElement.METHOD && - elt.getElementName().equals("A")); - - elt = cf.getElementAt(72); - assertTrue("should have found \"public void foo()\"", - elt != null && - elt.getElementType() == IJavaElement.METHOD && - elt.getElementName().equals("foo")); +public void testClassFileGetElementAt01() throws JavaModelException { + IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class"); + String source = classFile.getSource(); + IJavaElement element = classFile.getElementAt(source.indexOf("class A")); + assertElementEquals( + "Unexpected element", + "A [in A.class [in x.y [in attach.jar [in AttachSourceTests]]]]", + element); +} +/** + * Ensure that a class file with an attached source can retrieve its children given a source index. + */ +public void testClassFileGetElementAt02() throws JavaModelException { + IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class"); + String source = classFile.getSource(); + IJavaElement element = classFile.getElementAt(source.indexOf("public A")); + assertElementEquals( + "Unexpected element", + "A() [in A [in A.class [in x.y [in attach.jar [in AttachSourceTests]]]]]", + element); +} +/** + * Ensure that a class file with an attached source can retrieve its children given a source index. + */ +public void testClassFileGetElementAt03() throws JavaModelException { + IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class"); + String source = classFile.getSource(); + IJavaElement element = classFile.getElementAt(source.indexOf("void foo")); + assertElementEquals( + "Unexpected element", + "foo() [in A [in A.class [in x.y [in attach.jar [in AttachSourceTests]]]]]", + element); } /* + * Ensure that a constructor of a binary member type can be retrieved with its source position. + * (regression test for bug 119249 codeResolve, search, etc. don't work on constructor of binary inner class) + */ +public void testClassFileGetElementAt04() throws JavaModelException { + IClassFile classFile = this.innerClasses.getClassFile("X$V.class"); + String source = classFile.getSource(); + IJavaElement element = classFile.getElementAt(source.indexOf("V(String s)")); + assertElementEquals( + "Unexpected element", + "V(inner.X, java.lang.String) [in V [in X$V.class [in inner [in innerClasses.jar [in AttachSourceTests]]]]]", + element); +}/* * Ensures that the source of a .class file is implicetely attached when prj=src=bin * (regression test for bug 41444 [navigation] error dialog on opening class file) */ @@ -300,20 +325,27 @@ * Ensures that name ranges exists for BinaryMembers that have * mapped source. */ -public void testGetNameRange() throws JavaModelException { - IClassFile cf = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class"); - IMethod method = cf.getType().getMethod("foo", null); - assertTrue("method name range not correct", method.getNameRange().getOffset() != -1 && method.getNameRange().getLength() != 0); - - IClassFile objectCF = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class"); - ISourceRange range= objectCF.getType().getNameRange(); - int start, end; - start= range.getOffset(); - end= start + range.getLength() - 1; - - assertTrue("source code does not exist for the entire attached compilation unit", start != -1 && end != -1); - String source= objectCF.getSource().substring(start, end + 1); - assertSourceEquals("name should be 'A'", "A", source); +public void testGetNameRange01() throws JavaModelException { + IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class"); + IMethod method = classFile.getType().getMethod("foo", null); + assertSourceEquals("Unexpected name source", "foo", getNameSource(classFile.getSource(), method)); +} +/** + * Ensures that name ranges exists for BinaryMembers that have + * mapped source. + */ +public void testGetNameRange02() throws JavaModelException { + IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class"); + assertSourceEquals("Unexpected name source", "A", getNameSource(classFile.getSource(), classFile.getType())); +} +/* + * Ensure that the name range for a constructor of a binary member type is correct. + * (regression test for bug 119249 codeResolve, search, etc. don't work on constructor of binary inner class) + */ +public void testGetNameRange03() throws JavaModelException { + IClassFile classFile = this.innerClasses.getClassFile("X$V.class"); + IMethod constructor = classFile.getType().getMethod("V", new String[] {"Linner.X;", "Ljava.lang.String;"}); + assertSourceEquals("Unexpected name source", "V", getNameSource(classFile.getSource(), constructor)); } /** * Retrieves the source attachment paths for jar root. @@ -366,6 +398,8 @@ " }\n" + " }\n" + " class V {\n" + + " V(String s) {\n" + + " }\n" + " }\n" + "}", type.getSource()); @@ -444,6 +478,8 @@ assertSourceEquals( "Unexpected source", "class V {\n" + + " V(String s) {\n" + + " }\n" + " }", type.getSource()); } Index: src/org/eclipse/jdt/core/tests/model/GetSourceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/GetSourceTests.java,v retrieving revision 1.14 diff -u -r1.14 GetSourceTests.java --- src/org/eclipse/jdt/core/tests/model/GetSourceTests.java 12 Apr 2005 18:00:21 -0000 1.14 +++ src/org/eclipse/jdt/core/tests/model/GetSourceTests.java 16 Dec 2005 13:52:03 -0000 @@ -209,14 +209,6 @@ } } - private String getNameSource(String cuSource, IJavaElement element) throws JavaModelException { - ISourceRange nameRange = element instanceof ITypeParameter ? ((ITypeParameter) element).getNameRange() : ((IMember) element).getNameRange(); - int start = nameRange.getOffset(); - int end = start+nameRange.getLength(); - String actualSource = start >= 0 && end >= start ? cuSource.substring(start, end) : ""; - return actualSource; - } - /* * Ensures the name range for a type parameter is correct. */ Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v retrieving revision 1.154 diff -u -r1.154 AbstractJavaModelTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 5 Dec 2005 15:52:04 -0000 1.154 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 16 Dec 2005 13:52:02 -0000 @@ -1395,6 +1395,13 @@ ISourceReference cu = getCompilationUnit(cuPath); return getLocalVariable(cu, selectAt, selection); } + protected String getNameSource(String cuSource, IJavaElement element) throws JavaModelException { + ISourceRange nameRange = element instanceof ITypeParameter ? ((ITypeParameter) element).getNameRange() : ((IMember) element).getNameRange(); + int start = nameRange.getOffset(); + int end = start+nameRange.getLength(); + String actualSource = start >= 0 && end >= start ? cuSource.substring(start, end) : ""; + return actualSource; + } /** * Returns the specified package fragment in the given project and root, or * null if it does not exist. Index: src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java,v retrieving revision 1.36 diff -u -r1.36 ASTModelBridgeTests.java --- src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java 2 Sep 2005 10:14:31 -0000 1.36 +++ src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java 16 Dec 2005 13:52:00 -0000 @@ -36,7 +36,7 @@ // All specified tests which do not belong to the class are skipped... static { // TESTS_PREFIX = "testBug86380"; -// TESTS_NAMES = new String[] { "testLocalType2" }; + TESTS_NAMES = new String[] { "testBinaryMemberTypeConstructor" }; // TESTS_NUMBERS = new int[] { 83230 }; // TESTS_RANGE = new int[] { 83304, -1 }; } @@ -95,6 +95,14 @@ " new Member() {};\n" + " }\n" + "}", + "p/W.java", + "package p;\n" + + "public class W {\n" + + " class Member {\n" + + " /*start*/Member(String s) {\n" + + " }/*end*/\n" + + " }\n" + + "}", "Z.java", "public class Z {\n" + " /*start*/class Member {\n" + @@ -239,6 +247,28 @@ } /* + * Ensures that the IJavaElement of an IBinding representing a constructor of a binary member type is correct. + * (regression test for bug 119249 codeResolve, search, etc. don't work on constructor of binary inner class) + */ + public void testBinaryMemberTypeConstructor() throws JavaModelException { + IClassFile classFile = getClassFile("P", "/P/lib.jar", "p", "W$Member.class"); + String source = classFile.getSource(); + MarkerInfo markerInfo = new MarkerInfo(source); + markerInfo.astStarts = new int[] {source.indexOf("/*start*/") + "/*start*/".length()}; + markerInfo.astEnds = new int[] {source.indexOf("/*end*/")}; + ASTNode node = buildAST(markerInfo, classFile); + IBinding binding = ((MethodDeclaration) node).resolveBinding(); + assertNotNull("No binding", binding); + IJavaElement element = binding.getJavaElement(); + assertElementEquals( + "Unexpected Java element", + "Member(p.W, java.lang.String) [in Member [in W$Member.class [in p [in lib.jar [in P]]]]]", + element + ); + assertTrue("Element should exist", element.exists()); + } + + /* * Ensures that the IJavaElement of an IBinding representing a type coming from a class file is correct. */ public void testBinaryType() throws JavaModelException {