com.ibm.wala.eclipse.util
Class JdtUtil

java.lang.Object
  extended by com.ibm.wala.eclipse.util.JdtUtil

public class JdtUtil
extends java.lang.Object

Convenience methods to get information from JDT IJavaElement model.


Constructor Summary
JdtUtil()
           
 
Method Summary
static org.eclipse.jdt.core.IJavaElement createJavaElementFromJdtHandle(java.lang.String jdtHandle)
           
static org.eclipse.jdt.core.IType findJavaClassInProjects(java.lang.String fullyQualifiedName, java.util.Collection<org.eclipse.jdt.core.IJavaProject> projects)
          Find the IType in the workspace corresponding to a class name.
static org.eclipse.jdt.core.IType findJavaClassInResources(java.lang.String className, java.util.Collection<org.eclipse.core.resources.IResource> resources)
           
static org.eclipse.jdt.core.IMethod findJavaMethodInProjects(java.lang.String klass, java.lang.String selector, java.util.Collection<org.eclipse.jdt.core.IJavaProject> projects)
          Find the IMethod in the workspace corresponding to a method selector.
static org.eclipse.jdt.core.IMethod findJavaMethodInWorkspaceBrokenForInnerClasses(java.lang.String methodSig)
          Deprecated. 
static java.util.Collection<org.eclipse.jdt.core.IMethod> findMethods(org.eclipse.jdt.core.IJavaElement elt)
          Use the search engine to find all methods in a java element
static org.eclipse.jdt.core.IType[] getClasses(org.eclipse.jdt.core.ICompilationUnit cu)
           
static java.lang.String getClassName(org.eclipse.jdt.core.IType type)
           
static java.lang.String getFilePath(org.eclipse.jdt.core.IJavaElement javaElt)
           
static java.lang.String getFullyQualifiedClassName(org.eclipse.jdt.core.IType type)
           
static java.lang.String getHumanReadableType(java.lang.String typeSignature)
           
static org.eclipse.jdt.core.IJavaProject getJavaProject(org.eclipse.core.resources.IFile appJar)
           
static org.eclipse.jdt.core.IJavaProject getJavaProject(java.lang.String projectName)
           
static java.lang.String getJdtHandleString(org.eclipse.jdt.core.IJavaElement javaElt)
          Return a unique string representing the specified Java element across projects in the workspace.
static java.lang.String getPackageName(org.eclipse.jdt.core.ICompilationUnit cu)
           
static org.eclipse.jdt.core.IJavaProject getProject(org.eclipse.jdt.core.IJavaElement javaElt)
           
static java.lang.String getProjectName(org.eclipse.jdt.core.IJavaProject javaProject)
           
static java.util.Collection<java.lang.String> getTypeParameterNames(org.eclipse.jdt.core.IType type)
           
static java.util.Collection<org.eclipse.jdt.core.IJavaProject> getWorkspaceJavaProjects()
          compute the java projects in the active workspace
static java.lang.String parseForName(java.lang.String selector, org.eclipse.jdt.core.IType type)
           
static java.lang.String[] parseForParameterTypes(java.lang.String selector)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdtUtil

public JdtUtil()
Method Detail

getFilePath

public static java.lang.String getFilePath(org.eclipse.jdt.core.IJavaElement javaElt)

getPackageName

public static java.lang.String getPackageName(org.eclipse.jdt.core.ICompilationUnit cu)

getFullyQualifiedClassName

public static java.lang.String getFullyQualifiedClassName(org.eclipse.jdt.core.IType type)

getClassName

public static java.lang.String getClassName(org.eclipse.jdt.core.IType type)

getJdtHandleString

public static java.lang.String getJdtHandleString(org.eclipse.jdt.core.IJavaElement javaElt)
Return a unique string representing the specified Java element across projects in the workspace. The returned string can be used as a handle to create JavaElement by 'JavaCore.create(String)' For example, suppose we have the method 'fooPackage.barPackage.FooClass.fooMethod(int)' which is in the 'FooProject' and source folder 'src' the handle would be '=FooProject/src
Parameters:
javaElt -
Throws:
java.lang.IllegalArgumentException - if javaElt is null

createJavaElementFromJdtHandle

public static org.eclipse.jdt.core.IJavaElement createJavaElementFromJdtHandle(java.lang.String jdtHandle)

getClasses

public static org.eclipse.jdt.core.IType[] getClasses(org.eclipse.jdt.core.ICompilationUnit cu)

getProject

public static org.eclipse.jdt.core.IJavaProject getProject(org.eclipse.jdt.core.IJavaElement javaElt)

getProjectName

public static java.lang.String getProjectName(org.eclipse.jdt.core.IJavaProject javaProject)

getHumanReadableType

public static java.lang.String getHumanReadableType(java.lang.String typeSignature)
Parameters:
typeSignature - Some of the type signatures examples are "QString;" (String) and "I" (int) The type signatures may be either unresolved (for source types) or resolved (for binary types), and either basic (for basic types) or rich (for parameterized types). See Signature for details.

getJavaProject

public static org.eclipse.jdt.core.IJavaProject getJavaProject(org.eclipse.core.resources.IFile appJar)

getJavaProject

public static org.eclipse.jdt.core.IJavaProject getJavaProject(java.lang.String projectName)

getWorkspaceJavaProjects

public static java.util.Collection<org.eclipse.jdt.core.IJavaProject> getWorkspaceJavaProjects()
compute the java projects in the active workspace


findJavaClassInProjects

public static org.eclipse.jdt.core.IType findJavaClassInProjects(java.lang.String fullyQualifiedName,
                                                                 java.util.Collection<org.eclipse.jdt.core.IJavaProject> projects)
                                                          throws java.lang.IllegalArgumentException
Find the IType in the workspace corresponding to a class name.

Returns:
null if not found
Throws:
java.lang.IllegalArgumentException - if projects == null

findJavaClassInResources

public static org.eclipse.jdt.core.IType findJavaClassInResources(java.lang.String className,
                                                                  java.util.Collection<org.eclipse.core.resources.IResource> resources)

findJavaMethodInProjects

public static org.eclipse.jdt.core.IMethod findJavaMethodInProjects(java.lang.String klass,
                                                                    java.lang.String selector,
                                                                    java.util.Collection<org.eclipse.jdt.core.IJavaProject> projects)
Find the IMethod in the workspace corresponding to a method selector. TODO: this is way too slow. figure out something better.

Returns:
null if not found

getTypeParameterNames

public static java.util.Collection<java.lang.String> getTypeParameterNames(org.eclipse.jdt.core.IType type)
                                                                    throws java.lang.IllegalArgumentException,
                                                                           org.eclipse.jdt.core.JavaModelException
Throws:
java.lang.IllegalArgumentException
org.eclipse.jdt.core.JavaModelException

parseForName

public static java.lang.String parseForName(java.lang.String selector,
                                            org.eclipse.jdt.core.IType type)

parseForParameterTypes

public static final java.lang.String[] parseForParameterTypes(java.lang.String selector)
                                                       throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

findJavaMethodInWorkspaceBrokenForInnerClasses

@Deprecated
public static org.eclipse.jdt.core.IMethod findJavaMethodInWorkspaceBrokenForInnerClasses(java.lang.String methodSig)
Deprecated. 

Find the IMethod in the workspace corresponding to a method signature. This doesn't work for elements declared in inner classes. It's possible this is a 3.2 bug fixed in 3.3

Returns:
null if not found

findMethods

public static java.util.Collection<org.eclipse.jdt.core.IMethod> findMethods(org.eclipse.jdt.core.IJavaElement elt)
Use the search engine to find all methods in a java element