|
23 | 23 | import junit.framework.Test; |
24 | 24 | import org.eclipse.core.resources.IFile; |
25 | 25 | import org.eclipse.core.resources.IFolder; |
| 26 | +import org.eclipse.core.resources.IProject; |
26 | 27 | import org.eclipse.core.resources.IWorkspace; |
27 | 28 | import org.eclipse.core.resources.ResourcesPlugin; |
28 | 29 | import org.eclipse.core.runtime.CoreException; |
| 30 | +import org.eclipse.core.runtime.IPath; |
29 | 31 | import org.eclipse.core.runtime.NullProgressMonitor; |
30 | 32 | import org.eclipse.core.runtime.Path; |
31 | 33 | 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; |
32 | 37 | import org.eclipse.jdt.core.search.IJavaSearchConstants; |
33 | 38 | import org.eclipse.jdt.core.search.IJavaSearchScope; |
34 | 39 | import org.eclipse.jdt.core.search.LocalVariableDeclarationMatch; |
|
42 | 47 | import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
43 | 48 | import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; |
44 | 49 | import org.eclipse.jdt.internal.core.JavaModelStatus; |
| 50 | +import org.eclipse.jdt.internal.core.util.HandleFactory; |
45 | 51 |
|
46 | 52 | /** |
47 | 53 | * Tests the Java search engine where results are JavaElements and source positions. |
@@ -4157,6 +4163,58 @@ public void testStaticImportPackage02() throws CoreException { |
4157 | 4163 | ); |
4158 | 4164 | } |
4159 | 4165 |
|
| 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 | + |
4160 | 4218 | /** |
4161 | 4219 | * test Bug 110060: [plan][search] Add support for Camel Case search pattern |
4162 | 4220 | * see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=110060" |
|
0 commit comments