### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v retrieving revision 1.144 diff -u -r1.144 Util.java --- model/org/eclipse/jdt/internal/core/util/Util.java 26 Oct 2010 17:24:15 -0000 1.144 +++ model/org/eclipse/jdt/internal/core/util/Util.java 11 Nov 2010 10:44:45 -0000 @@ -1788,6 +1788,17 @@ return binaryTypeName.substring(nameStart, end); } + public static char[] localTypeName(char[] binaryTypeName, int lastDollar, int end) { + // If local name starts with a dollar sign, don't touch the name + if(lastDollar > 0 && binaryTypeName[lastDollar-1] == '$') + return binaryTypeName; + + int nameStart = lastDollar+1; + while (nameStart < end && Character.isDigit(binaryTypeName[nameStart])) + nameStart++; + return CharOperation.subarray(binaryTypeName, nameStart, end); + } + /* * Add a log entry */ Index: search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java,v retrieving revision 1.43 diff -u -r1.43 ClassFileMatchLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java 18 Sep 2008 15:24:57 -0000 1.43 +++ search/org/eclipse/jdt/internal/core/search/matching/ClassFileMatchLocator.java 11 Nov 2010 10:44:45 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -21,6 +21,7 @@ import org.eclipse.jdt.internal.compiler.lookup.*; import org.eclipse.jdt.internal.core.*; import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; +import org.eclipse.jdt.internal.core.util.Util; public class ClassFileMatchLocator implements IIndexConstants { @@ -274,6 +275,10 @@ if (lastSlash != -1) { name = CharOperation.subarray(name, lastSlash+1, name.length); } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=329727 + // Remove the enclosing type name from the constructor name if applicable + int lastDollar = CharOperation.lastIndexOf('$', name); + name = lastDollar > -1 ? Util.localTypeName(name, lastDollar, name.length) : name; } else { name = method.getSelector(); } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java,v retrieving revision 1.187 diff -u -r1.187 JavaSearchTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 27 Oct 2010 02:55:20 -0000 1.187 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java 11 Nov 2010 10:44:48 -0000 @@ -4464,4 +4464,59 @@ // Should have same types with these 2 searches assertEquals("Found types sounds not to be correct", requestor.toString(), collector.toString()); } +/** + * @bug 329727 Invalid check in the isConstructor() method of the IMethod implementation. + * @test check that in a binary type, method's name doesn't contain the enclosing type name and + * that IMethod#isContructor returns correct value + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=329727" + * @throws CoreException + * @throws IOException + */ +public void testBug329727() throws CoreException, IOException { + + IJavaProject project = getJavaProject("JavaSearch"); + IClasspathEntry[] originalCP = project.getRawClasspath(); + try { + int cpLength = originalCP.length; + IClasspathEntry[] newCP = new IClasspathEntry[cpLength + 1]; + System.arraycopy(originalCP, 0, newCP, 0, cpLength); + createLibrary(project, "bug329727.jar", null, new String[] { + "p/OuterClass.java", + "package p;\n" + "public class OuterClass {\n" + + " public OuterClass(){}\n" + + " class InnerClass {\n" + + " public InnerClass(){}\n" + " }\n" + "}\n" }, + new String[0], JavaCore.VERSION_1_4); + newCP[cpLength] = JavaCore.newLibraryEntry( + new Path("/JavaSearch/bug329727.jar"), null, null); + project.setRawClasspath(newCP, null); + + final String txtPattern = "InnerClas*"; + SearchPattern pattern = SearchPattern.createPattern(txtPattern, + IJavaSearchConstants.CONSTRUCTOR, + IJavaSearchConstants.DECLARATIONS, + SearchPattern.R_CASE_SENSITIVE + | SearchPattern.R_PATTERN_MATCH); + + SearchParticipant[] participants = new SearchParticipant[1]; + participants[0] = SearchEngine.getDefaultSearchParticipant(); + + SearchRequestor requestor = new SearchRequestor() { + public void acceptSearchMatch(SearchMatch match) + throws CoreException { + assertTrue("Incorrect Element", match.getElement() instanceof IMethod); + assertTrue("Must be a constructor", ((IMethod) match.getElement()).isConstructor()); + assertEquals("Incorrect Constructor name", "InnerClass", ((IMethod)match.getElement()).getElementName()); + } + }; + + SearchEngine engine = new SearchEngine(); + IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); + engine.search(pattern, participants, scope, requestor, null); + } + finally{ + project.setRawClasspath(originalCP, null); + } + +} }