From 3c3dce9f21dcfc2b910679e5b777ce626252c3bd Mon Sep 17 00:00:00 2001 From: Rob Stryker Date: Tue, 5 Nov 2024 11:35:54 -0500 Subject: [PATCH] Add test, fix nls warnings Signed-off-by: Rob Stryker --- .../jdt/core/tests/model/JavaSearchTests.java | 50 +++++++++++++++++++ .../internal/core/ClassFileWorkingCopy.java | 4 +- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java index 5d0ccb28fec..3e4f5a84af4 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java @@ -23,12 +23,16 @@ import junit.framework.Test; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.*; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.ASTRequestor; import org.eclipse.jdt.core.search.IJavaSearchConstants; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.core.search.LocalVariableDeclarationMatch; @@ -42,6 +46,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; import org.eclipse.jdt.internal.core.JavaModelStatus; +import org.eclipse.jdt.internal.core.util.HandleFactory; /** * Tests the Java search engine where results are JavaElements and source positions. @@ -4157,6 +4162,51 @@ public void testStaticImportPackage02() throws CoreException { ); } +public void testCamelCaseTypePattern_ClassFileWorkingCopy_Prereq() throws CoreException { + IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject("JavaSearch"); + IJavaProject jp = JavaCore.create(p); + + String runtimeExceptionPath = "/home/rob/apps/eclipse/workspaces/jclMin1.8.jar|java/lang/RuntimeException.class"; + ITypeRoot typeRootRuntimeException = (ITypeRoot)new HandleFactory().createOpenable(runtimeExceptionPath, getJavaSearchScope()); + org.eclipse.jdt.core.ICompilationUnit cuRuntimeException = typeRootRuntimeException.getWorkingCopy(null, new NullProgressMonitor()); + + + String retentionPath = "/home/rob/apps/eclipse/workspaces/jclMin1.8.jar|java/lang/annotation/Retention.class"; + ITypeRoot typeRootRetention = (ITypeRoot)new HandleFactory().createOpenable(retentionPath, getJavaSearchScope()); + org.eclipse.jdt.core.ICompilationUnit cuRetention = typeRootRetention.getWorkingCopy(null, new NullProgressMonitor()); + + String retentionPolicyPath = "/home/rob/apps/eclipse/workspaces/jclMin1.8.jar|java/lang/annotation/RetentionPolicy.class"; + ITypeRoot typeRootRetentionPolicy = (ITypeRoot)new HandleFactory().createOpenable(retentionPolicyPath, getJavaSearchScope()); + org.eclipse.jdt.core.ICompilationUnit cuRetentionPolicy = typeRootRetentionPolicy.getWorkingCopy(null, new NullProgressMonitor()); + + org.eclipse.jdt.core.ICompilationUnit[] cuArr = new org.eclipse.jdt.core.ICompilationUnit[] { + cuRuntimeException, cuRetention, cuRetentionPolicy + }; + + ASTParser astParser = ASTParser.newParser(AST.getJLSLatest()); + astParser.setCompilerOptions(jp.getOptions(true)); + astParser.setProject(jp); + astParser.setResolveBindings(true); + astParser.setBindingsRecovery(true); + astParser.createASTs(cuArr, new String[0], new ASTRequestor() { + @Override + public void acceptAST(org.eclipse.jdt.core.ICompilationUnit source, org.eclipse.jdt.core.dom.CompilationUnit ast) { + String srcString = source.toString(); + String astString = ast.toString(); + if( srcString.contains("RetentionPolicy.class") && !astString.contains("RetentionPolicy")) { + fail(); + } + if( srcString.contains("Retention.class") && !astString.contains("Retention")) { + fail(); + } + if( srcString.contains("RuntimeException.class") && !astString.contains("RuntimeException")) { + fail(); + } + } + // todo, use a subprogressmonitor or slice it + }, new NullProgressMonitor()); +} + /** * test Bug 110060: [plan][search] Add support for Camel Case search pattern * see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=110060" diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java index ff239568d5a..bb727ea58f4 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFileWorkingCopy.java @@ -94,8 +94,8 @@ else if (root.isArchive()) { String clazzFileName = this.classFile.getElementName(); String parentPath = this.classFile.getParent().getPath().toString(); IPackageFragment enclosingPackage = (IPackageFragment)getAncestor(IJavaElement.PACKAGE_FRAGMENT); - String pack = enclosingPackage == null ? "" : enclosingPackage.getElementName(); - String packReplaced = pack.length() > 0 ? pack.replaceAll("\\.", "/") + "/" : ""; + String pack = enclosingPackage == null ? "" : enclosingPackage.getElementName(); //$NON-NLS-1$ + String packReplaced = pack.length() > 0 ? pack.replaceAll("\\.", "/") + "/" : ""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ String goal = parentPath + IDependent.JAR_FILE_ENTRY_SEPARATOR + packReplaced + clazzFileName; ret = goal.toCharArray(); } else {