Skip to content

Commit

Permalink
Fix testCamelCaseTypePattern01_CamelCase and many others
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 Dec 2, 2024
1 parent 95178a7 commit c43fb2e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IBuffer;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaModelStatusConstants;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.WorkingCopyOwner;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.core.util.IClassFileReader;
import org.eclipse.jdt.internal.compiler.env.IDependent;
import org.eclipse.jdt.internal.compiler.env.IElementInfo;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.core.util.Disassembler;
Expand Down Expand Up @@ -79,6 +83,30 @@ public IPath getPath() {
return this.classFile.getPath();
}

@Override
public char[] getFileName(){
// BIG PROBLEM HERE!!!
// IJavaElement#getPath() has different specs than
// org.eclipse.jdt.internal.compiler.env.IDependent#getFileName()
//return getPath().toString().toCharArray();
char[] ret = null;
PackageFragmentRoot root = getPackageFragmentRoot();
if (root == null)
// working copy not in workspace
ret = new Path(getElementName()).toString().toCharArray();
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 goal = parentPath + IDependent.JAR_FILE_ENTRY_SEPARATOR + packReplaced + clazzFileName;
ret = goal.toCharArray();
} else {
ret = getParent().getPath().append(getElementName()).toString().toCharArray();
}
return ret;
}
@Override
public JavaElement getPrimaryElement(boolean checkOwner) {
if (checkOwner && isPrimary()) return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ public char[] getContents() {
public CompilationUnit originalFromClone() {
return CompilationUnit.this;
}
@Override
public char[] getFileName(){
return originalFromClone().getFileName();
}

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
import org.eclipse.jdt.internal.core.Annotation;
import org.eclipse.jdt.internal.core.ClassFile;
import org.eclipse.jdt.internal.core.JavaElement;
import org.eclipse.jdt.internal.core.JavaModel;
import org.eclipse.jdt.internal.core.JavaModelManager;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.jdt.internal.core.Member;
import org.eclipse.jdt.internal.core.MemberValuePair;
import org.eclipse.jdt.internal.core.PackageFragment;
Expand Down Expand Up @@ -808,7 +810,8 @@ private static IClassFile getClassFile(char[] fileName) {
IPackageFragment pkg = getPackageFragment(fileName, pkgEnd, jarSeparator);
if (pkg == null) return null;
int start;
return pkg.getClassFile(new String(fileName, start = pkgEnd + 1, fileName.length - start));
IClassFile cz = pkg.getClassFile(new String(fileName, start = pkgEnd + 1, fileName.length - start));
return cz;
}

private static ICompilationUnit getCompilationUnit(char[] fileName, WorkingCopyOwner workingCopyOwner) {
Expand Down Expand Up @@ -1000,7 +1003,11 @@ private static String getLineSeparator(char[] text, char[] buffer) {
public static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) {
if (jarSeparator != -1) {
String jarMemento = new String(fileName, 0, jarSeparator);
// TODO this is where shit is blowing up,
PackageFragmentRoot root = (PackageFragmentRoot) JavaCore.create(jarMemento);
if( root == null ) {
root = getJarPkgFragmentRoot(new String(fileName), jarSeparator, jarMemento);
}
if (pkgEnd == jarSeparator)
return root.getPackageFragment(CharOperation.NO_STRINGS);
char[] pkgName = CharOperation.subarray(fileName, jarSeparator+1, pkgEnd);
Expand All @@ -1026,6 +1033,41 @@ public static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, i
}
}

// Copied from org.eclipse.jdt.internal.core.util.HandleFactory
private static PackageFragmentRoot getJarPkgFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPathString) {
IPath jarPath= new Path(jarPathString);
Object target = JavaModel.getTarget(jarPath, false);
if (target instanceof IFile jarFile) {
// internal jar: is it on the classpath of its project?
// e.g. org.eclipse.swt.win32/ws/win32/swt.jar
// is NOT on the classpath of org.eclipse.swt.win32
JavaProject javaProject = (JavaProject) JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject(jarFile);
try {
IClasspathEntry entry = javaProject.getClasspathEntryFor(jarPath);
if (entry != null) {
return (PackageFragmentRoot) javaProject.getPackageFragmentRoot(jarFile);
}
} catch (JavaModelException e) {
// ignore and try to find another project
}
} else if( target instanceof File) {
try {
// Have to search, I guess.
IJavaProject[] javaProjects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
for( int i = 0; i < javaProjects.length; i++ ) {
IClasspathEntry entry = javaProjects[i].getClasspathEntryFor(jarPath);
if (entry != null) {
return (PackageFragmentRoot) javaProjects[i].getPackageFragmentRoot(jarPathString);
}
}
} catch(JavaModelException jme) {
// TODO ignore
}

}
return null;
}

/**
* Returns the number of parameter types in a method signature.
*/
Expand Down

0 comments on commit c43fb2e

Please sign in to comment.