Class JdtUtil

java.lang.Object
com.ibm.wala.ide.util.JdtUtil

public class JdtUtil extends Object
Convenience methods to get information from JDT IJavaElement model.
  • Constructor Details

    • JdtUtil

      public JdtUtil()
  • Method Details

    • getFilePath

      public static String getFilePath(org.eclipse.jdt.core.IJavaElement javaElt)
    • getPackageName

      public static String getPackageName(org.eclipse.jdt.core.ICompilationUnit cu)
    • getFullyQualifiedClassName

      public static String getFullyQualifiedClassName(org.eclipse.jdt.core.IType type)
    • getClassName

      public static String getClassName(org.eclipse.jdt.core.IType type)
    • getJdtHandleString

      public static 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<fooPackage.barPackage{FooClass.java[FooClass~fooMethod~I'

      Throws:
      IllegalArgumentException - if javaElt is null
    • createJavaElementFromJdtHandle

      @Deprecated public static org.eclipse.jdt.core.IJavaElement createJavaElementFromJdtHandle(String jdtHandle)
      Deprecated.
    • 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 String getProjectName(org.eclipse.jdt.core.IJavaProject javaProject)
    • getHumanReadableType

      public static String getHumanReadableType(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(String projectName)
    • getWorkspaceJavaProjects

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

      public static org.eclipse.jdt.core.IType findJavaClassInProjects(String fullyQualifiedName, Collection<org.eclipse.jdt.core.IJavaProject> projects) throws IllegalArgumentException
      Find the IType in the workspace corresponding to a class name.
      Returns:
      null if not found
      Throws:
      IllegalArgumentException - if projects == null
    • findJavaClassInResources

      public static org.eclipse.jdt.core.IType findJavaClassInResources(String className, Collection<org.eclipse.core.resources.IResource> resources)
    • findJavaMethodInProjects

      public static org.eclipse.jdt.core.IMethod findJavaMethodInProjects(String klass, String selector, 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 Collection<String> getTypeParameterNames(org.eclipse.jdt.core.IType type) throws IllegalArgumentException, org.eclipse.jdt.core.JavaModelException
      Throws:
      IllegalArgumentException
      org.eclipse.jdt.core.JavaModelException
    • parseForName

      public static String parseForName(String selector, org.eclipse.jdt.core.IType type)
    • parseForParameterTypes

      public static final String[] parseForParameterTypes(String selector) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • findJavaMethodInWorkspaceBrokenForInnerClasses

      @Deprecated public static org.eclipse.jdt.core.IMethod findJavaMethodInWorkspaceBrokenForInnerClasses(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 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
    • getStructuredSelectionForProjectNames

      public static org.eclipse.jface.viewers.StructuredSelection getStructuredSelectionForProjectNames(Collection<String> projectNames)
      get a StructuredSelection corresponding to the named projects
    • getNamedProject

      public static org.eclipse.jdt.core.IJavaProject getNamedProject(String projectName)
    • getAST

      public static org.eclipse.jdt.core.dom.ASTNode getAST(org.eclipse.core.resources.IFile javaSourceFile)
    • getOriginalNode

      public static org.eclipse.jdt.core.dom.ASTNode getOriginalNode(JdtPosition pos)
    • getOriginalNode

      public static org.eclipse.jdt.core.dom.ASTNode getOriginalNode(org.eclipse.jdt.core.dom.ASTNode root, JdtPosition pos)