Skip to content

Commit

Permalink
Add test, fix nls warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <stryker@redhat.com>
  • Loading branch information
Rob Stryker committed Nov 7, 2024
1 parent 727ca20 commit 2db37c4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -4162,6 +4167,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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,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 {
Expand Down

0 comments on commit 2db37c4

Please sign in to comment.