Skip to content

Commit ac38dcf

Browse files
author
Rob Stryker
committed
Add test, fix nls warnings
Signed-off-by: Rob Stryker <stryker@redhat.com> Fix test case Signed-off-by: Rob Stryker <stryker@redhat.com>
1 parent 021dfb7 commit ac38dcf

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@
2323
import junit.framework.Test;
2424
import org.eclipse.core.resources.IFile;
2525
import org.eclipse.core.resources.IFolder;
26+
import org.eclipse.core.resources.IProject;
2627
import org.eclipse.core.resources.IWorkspace;
2728
import org.eclipse.core.resources.ResourcesPlugin;
2829
import org.eclipse.core.runtime.CoreException;
30+
import org.eclipse.core.runtime.IPath;
2931
import org.eclipse.core.runtime.NullProgressMonitor;
3032
import org.eclipse.core.runtime.Path;
3133
import org.eclipse.jdt.core.*;
34+
import org.eclipse.jdt.core.dom.AST;
35+
import org.eclipse.jdt.core.dom.ASTParser;
36+
import org.eclipse.jdt.core.dom.ASTRequestor;
3237
import org.eclipse.jdt.core.search.IJavaSearchConstants;
3338
import org.eclipse.jdt.core.search.IJavaSearchScope;
3439
import org.eclipse.jdt.core.search.LocalVariableDeclarationMatch;
@@ -42,6 +47,7 @@
4247
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
4348
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
4449
import org.eclipse.jdt.internal.core.JavaModelStatus;
50+
import org.eclipse.jdt.internal.core.util.HandleFactory;
4551

4652
/**
4753
* Tests the Java search engine where results are JavaElements and source positions.
@@ -4157,6 +4163,58 @@ public void testStaticImportPackage02() throws CoreException {
41574163
);
41584164
}
41594165

4166+
public void testCamelCaseTypePattern_ClassFileWorkingCopy_Prereq() throws CoreException {
4167+
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("JavaSearch");
4168+
IJavaProject jp = JavaCore.create(p);
4169+
IClasspathEntry[] entr2 = jp.getResolvedClasspath(true);
4170+
String jclMinPath = null;
4171+
for( int i = 0; i < entr2.length && jclMinPath == null; i++ ) {
4172+
IPath path = entr2[i].getPath();
4173+
if( path.toString().contains("jclMin1.8.jar")) {
4174+
jclMinPath = path.toString();
4175+
}
4176+
}
4177+
String runtimeExceptionPath = jclMinPath + "|java/lang/RuntimeException.class";
4178+
ITypeRoot typeRootRuntimeException = (ITypeRoot)new HandleFactory().createOpenable(runtimeExceptionPath, getJavaSearchScope());
4179+
org.eclipse.jdt.core.ICompilationUnit cuRuntimeException = typeRootRuntimeException.getWorkingCopy(null, new NullProgressMonitor());
4180+
4181+
4182+
String retentionPath = jclMinPath + "|java/lang/annotation/Retention.class";
4183+
ITypeRoot typeRootRetention = (ITypeRoot)new HandleFactory().createOpenable(retentionPath, getJavaSearchScope());
4184+
org.eclipse.jdt.core.ICompilationUnit cuRetention = typeRootRetention.getWorkingCopy(null, new NullProgressMonitor());
4185+
4186+
String retentionPolicyPath = jclMinPath + "|java/lang/annotation/RetentionPolicy.class";
4187+
ITypeRoot typeRootRetentionPolicy = (ITypeRoot)new HandleFactory().createOpenable(retentionPolicyPath, getJavaSearchScope());
4188+
org.eclipse.jdt.core.ICompilationUnit cuRetentionPolicy = typeRootRetentionPolicy.getWorkingCopy(null, new NullProgressMonitor());
4189+
4190+
org.eclipse.jdt.core.ICompilationUnit[] cuArr = new org.eclipse.jdt.core.ICompilationUnit[] {
4191+
cuRuntimeException, cuRetention, cuRetentionPolicy
4192+
};
4193+
4194+
ASTParser astParser = ASTParser.newParser(AST.getJLSLatest());
4195+
astParser.setCompilerOptions(jp.getOptions(true));
4196+
astParser.setProject(jp);
4197+
astParser.setResolveBindings(true);
4198+
astParser.setBindingsRecovery(true);
4199+
astParser.createASTs(cuArr, new String[0], new ASTRequestor() {
4200+
@Override
4201+
public void acceptAST(org.eclipse.jdt.core.ICompilationUnit source, org.eclipse.jdt.core.dom.CompilationUnit ast) {
4202+
String srcString = source.toString();
4203+
String astString = ast.toString();
4204+
if( srcString.contains("RetentionPolicy.class") && !astString.contains("RetentionPolicy")) {
4205+
fail();
4206+
}
4207+
if( srcString.contains("Retention.class") && !astString.contains("Retention")) {
4208+
fail();
4209+
}
4210+
if( srcString.contains("RuntimeException.class") && !astString.contains("RuntimeException")) {
4211+
fail();
4212+
}
4213+
}
4214+
// todo, use a subprogressmonitor or slice it
4215+
}, new NullProgressMonitor());
4216+
}
4217+
41604218
/**
41614219
* test Bug 110060: [plan][search] Add support for Camel Case search pattern
41624220
* see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=110060"

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ else if (root.isArchive()) {
9494
String clazzFileName = this.classFile.getElementName();
9595
String parentPath = this.classFile.getParent().getPath().toString();
9696
IPackageFragment enclosingPackage = (IPackageFragment)getAncestor(IJavaElement.PACKAGE_FRAGMENT);
97-
String pack = enclosingPackage == null ? "" : enclosingPackage.getElementName();
98-
String packReplaced = pack.length() > 0 ? pack.replaceAll("\\.", "/") + "/" : "";
97+
String pack = enclosingPackage == null ? "" : enclosingPackage.getElementName(); //$NON-NLS-1$
98+
String packReplaced = pack.length() > 0 ? pack.replaceAll("\\.", "/") + "/" : ""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
9999
String goal = parentPath + IDependent.JAR_FILE_ENTRY_SEPARATOR + packReplaced + clazzFileName;
100100
ret = goal.toCharArray();
101101
} else {

0 commit comments

Comments
 (0)