org.eclipse.jst.jsf.common.util
Class TypeUtil

java.lang.Object
  extended by org.eclipse.jst.jsf.common.util.TypeUtil

public final class TypeUtil
extends java.lang.Object

Utility for handling IType's and type signatures Class is static and cannot be extended or instantiated.


Method Summary
static boolean canNeverBeEqual(java.lang.String typeSig1, java.lang.String typeSig2)
           
static java.lang.String getFullyQualifiedName(java.lang.String typeSignature)
           
static java.lang.String getSignature(org.eclipse.jdt.core.IType type)
           
static boolean isEnumMember(org.eclipse.jdt.core.IType type, java.lang.String fieldName)
           
static boolean isEnumsCompareCompatible(java.lang.String typeSig1, java.lang.String typeSig2)
           
static java.lang.String matchTypeParameterToArgument(org.eclipse.jdt.core.IType type, java.lang.String typeParamSignature, java.util.List<java.lang.String> typeArguments)
           
static java.lang.String resolveMethodSignature(org.eclipse.jdt.core.IType owner, java.lang.String unresolvedSignature)
           
static org.eclipse.jdt.core.IType resolveType(org.eclipse.jdt.core.IJavaProject javaProject, java.lang.String fullyResolvedTypeSignature)
          Attempts to get a Java IType for a fully qualified signature.
static java.lang.String resolveTypeSignature(org.eclipse.jdt.core.IType owningType, java.lang.String typeSignature)
          Fully equivalent to: #resolveTypeSignature(owningType, typeSignature, true) If resolved, type signature has generic type parameters erased (absent).
static java.lang.String resolveTypeSignature(org.eclipse.jdt.core.IType owningType, java.lang.String typeSignature, boolean eraseTypeParameters)
          Resolve typeSignature in the context of owningType.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

resolveTypeSignature

public static java.lang.String resolveTypeSignature(org.eclipse.jdt.core.IType owningType,
                                                    java.lang.String typeSignature)
Fully equivalent to: #resolveTypeSignature(owningType, typeSignature, true) If resolved, type signature has generic type parameters erased (absent).

Parameters:
owningType -
typeSignature -
Returns:
the resolved type signature for typeSignature in owningType or typeSignature unchanged if cannot resolve.

resolveTypeSignature

public static java.lang.String resolveTypeSignature(org.eclipse.jdt.core.IType owningType,
                                                    java.lang.String typeSignature,
                                                    boolean eraseTypeParameters)
Resolve typeSignature in the context of owningType. This method will return a type erased signture if eraseTypeParameters == true and will attempt to resolve and include parameters if eraseTypeParamters == false NOTE: special rules apply to the way unresolved type parameters and wildcards are resolved: 1) If a fully unresolved type parameter is found, then it will be replaced with Ljava.lang.Object; i.e. List -> Ljava.util.List; for any unresolved T. 2) Any bounded wildcard will be replaced by the bound: i.e. List -> Ljava.util.List; i.e. List -> Ljava.util.List; Note limitation here: bounds that use 'super' will take the "best case" scenario that the list type is of that type. 3) The unbounded wildcard will be replaced by Ljava.lang.Object; i.e. List -> Ljava.util.List; The reason for this substition is to return the most accurate reasonable approximation of the type within what is known by owningType

Parameters:
owningType -
typeSignature -
eraseTypeParameters - if set to false, type parameters are resolved included in the signature
Returns:
the resolved type signature for typeSignature in owningType or typeSignature unchanged if cannot resolve.

getSignature

public static java.lang.String getSignature(org.eclipse.jdt.core.IType type)
Parameters:
type -
Returns:
a type signature for a type

resolveMethodSignature

public static java.lang.String resolveMethodSignature(org.eclipse.jdt.core.IType owner,
                                                      java.lang.String unresolvedSignature)
Parameters:
owner -
unresolvedSignature -
Returns:
the resolved method signature for unresolvedSignature in owner

getFullyQualifiedName

public static java.lang.String getFullyQualifiedName(java.lang.String typeSignature)
Parameters:
typeSignature -
Returns:
a fully qualified Java class name from a type signature i.e. Ljava.lang.String; -> java.lang.String

resolveType

public static org.eclipse.jdt.core.IType resolveType(org.eclipse.jdt.core.IJavaProject javaProject,
                                                     java.lang.String fullyResolvedTypeSignature)
Attempts to get a Java IType for a fully qualified signature. Note that generic type arguments are generally ignored by JDT when doing such look ups.

Parameters:
javaProject - the project context inside which to resolve the type
fullyResolvedTypeSignature - a fully resolved type signature
Returns:
the IType if resolved, null otherwise

matchTypeParameterToArgument

public static java.lang.String matchTypeParameterToArgument(org.eclipse.jdt.core.IType type,
                                                            java.lang.String typeParamSignature,
                                                            java.util.List<java.lang.String> typeArguments)
Parameters:
type -
typeParamSignature -
typeArguments -
Returns:
the signature for the type argument in typeArguments that matches the named typeParamSignature in type. For example, given type for java.util.Map, typeParamSignature == "V" and typeArguments = {Ljava.util.String;, Lcom.test.Blah;}, the result would be the typeArgument that matches "V", which is "Lcom.test.Blah;} returns null if the match cannot be found.

isEnumMember

public static boolean isEnumMember(org.eclipse.jdt.core.IType type,
                                   java.lang.String fieldName)
Parameters:
type -
fieldName -
Returns:
true if fieldName is a member of type. Note that if type is java.lang.Enum then this will always return true since we cannot know what fields the instance has (it could be any enum)

isEnumsCompareCompatible

public static boolean isEnumsCompareCompatible(java.lang.String typeSig1,
                                               java.lang.String typeSig2)
Parameters:
typeSig1 - the type signature of the first enum. Must be non-null, fully resolved enum type.
typeSig2 - the type signature of the second enum. Must be non-null, fully resolved enum type.
Returns:
true if typeSig1.compareTo(typeSig2) is a legal operation (won't throw a CCE)

canNeverBeEqual

public static boolean canNeverBeEqual(java.lang.String typeSig1,
                                      java.lang.String typeSig2)
Parameters:
typeSig1 - the type signature of the first enum. Must be non-null, fully resolved enum type.
typeSig2 - the type signature of the second enum. Must be non-null, fully resolved enum type.
Returns:
true if instances typeSig1 and typeSig2 can never be equal due their being definitively different enum types