com.intellij.psi.util
Class TypeConversionUtil

java.lang.Object
  extended by com.intellij.psi.util.TypeConversionUtil

public class TypeConversionUtil
extends java.lang.Object


Field Summary
static int BYTE_RANK
           
static int CHAR_RANK
           
static int INT_RANK
           
static int SHORT_RANK
           
 
Constructor Summary
TypeConversionUtil()
           
 
Method Summary
static boolean areDistinctParameterTypes(PsiClassType type1, PsiClassType type2)
           
static boolean areTypesAssignmentCompatible(PsiType lType, PsiExpression rExpr)
          JLS 5.2
static boolean areTypesConvertible(PsiType fromType, PsiType toType)
           
static PsiType binaryNumericPromotion(PsiType type1, PsiType type2)
          see JLS 5.6.2
static boolean boxingConversionApplicable(PsiType left, PsiType right)
           
static java.lang.Object computeCastTo(java.lang.Object operand, PsiType castType)
           
static PsiType erasure(PsiType type)
           
static PsiSubstitutor getClassSubstitutor(PsiClass superClassCandidate, PsiClass derivedClassCandidate, PsiSubstitutor derivedSubstitutor)
           
static PsiSubstitutor getSuperClassSubstitutor(PsiClass superClass, PsiClass derivedClass, PsiSubstitutor derivedSubstitutor)
          Calculates substitutor that binds type parameters in superClass with values that they have in derivedClass, given that type parameters in derivedClass are bound by derivedSubstitutor.
static int getTypeRank(PsiType type)
           
static boolean isAssignable(PsiType left, PsiType right)
          Checks whether values of one type can be assigned to another
static boolean isAssignable(PsiType left, PsiType right, boolean allowUncheckedConversion)
           
static boolean isBinaryOperatorApplicable(IElementType tokenType, PsiExpression lOperand, PsiExpression rOperand, boolean strict)
           
static boolean isBooleanType(PsiType type)
           
static boolean isDoubleType(PsiType type)
           
static boolean isFloatType(PsiType type)
           
static boolean isIntegerNumber(java.lang.String typeName)
           
static boolean isLongType(PsiType type)
           
static boolean isLValue(PsiExpression element)
           
static boolean isNullType(PsiType type)
           
static boolean isNumericType(int typeRank)
           
static boolean isPrimitive(java.lang.String typeName)
           
static boolean isPrimitiveAndNotNull(PsiType type)
           
static boolean isPrimitiveAndNotNullOrWrapper(PsiType type)
           
static boolean isPrimitiveWrapper(java.lang.String typeName)
           
static boolean isUnaryOperatorApplicable(PsiJavaToken token, PsiExpression operand)
           
static boolean isVoidType(PsiType type)
           
static PsiClassType typeParameterErasure(PsiTypeParameter typeParameter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_RANK

public static final int BYTE_RANK
See Also:
Constant Field Values

SHORT_RANK

public static final int SHORT_RANK
See Also:
Constant Field Values

CHAR_RANK

public static final int CHAR_RANK
See Also:
Constant Field Values

INT_RANK

public static final int INT_RANK
See Also:
Constant Field Values
Constructor Detail

TypeConversionUtil

public TypeConversionUtil()
Method Detail

areTypesConvertible

public static boolean areTypesConvertible(PsiType fromType,
                                          PsiType toType)
Returns:
true iff fromType can be casted to toType

areDistinctParameterTypes

public static final boolean areDistinctParameterTypes(PsiClassType type1,
                                                      PsiClassType type2)

isPrimitiveAndNotNull

public static boolean isPrimitiveAndNotNull(PsiType type)

isNullType

public static boolean isNullType(PsiType type)

isDoubleType

public static boolean isDoubleType(PsiType type)

isFloatType

public static boolean isFloatType(PsiType type)

isLongType

public static boolean isLongType(PsiType type)

isVoidType

public static boolean isVoidType(PsiType type)

isBooleanType

public static boolean isBooleanType(PsiType type)

isNumericType

public static boolean isNumericType(int typeRank)

getTypeRank

public static int getTypeRank(PsiType type)
Returns:
1..MAX_NUMERIC_TYPE if type is primitive numeric type, BOOL_TYPE for boolean, STRING_TYPE for String, Integer.MAX_VALUE for other

isBinaryOperatorApplicable

public static boolean isBinaryOperatorApplicable(IElementType tokenType,
                                                 PsiExpression lOperand,
                                                 PsiExpression rOperand,
                                                 boolean strict)
Parameters:
tokenType - JavaTokenType enumeration
lOperand -
rOperand -
strict - true if operator result type should be convertible to the left operand
Returns:
true if lOperand operator rOperand expression is syntactically correct

isPrimitiveAndNotNullOrWrapper

public static boolean isPrimitiveAndNotNullOrWrapper(PsiType type)

isUnaryOperatorApplicable

public static boolean isUnaryOperatorApplicable(PsiJavaToken token,
                                                PsiExpression operand)

isLValue

public static boolean isLValue(PsiExpression element)
Returns:
true if expression can be the left part of assignment operator

areTypesAssignmentCompatible

public static boolean areTypesAssignmentCompatible(PsiType lType,
                                                   PsiExpression rExpr)
JLS 5.2


isAssignable

public static boolean isAssignable(PsiType left,
                                   PsiType right)
Checks whether values of one type can be assigned to another

Parameters:
left - type to assign to
right - type of value
Returns:
true if value of type right can be assigned to an l-value of type left

isAssignable

public static boolean isAssignable(PsiType left,
                                   PsiType right,
                                   boolean allowUncheckedConversion)

boxingConversionApplicable

public static boolean boxingConversionApplicable(PsiType left,
                                                 PsiType right)

getClassSubstitutor

public static PsiSubstitutor getClassSubstitutor(PsiClass superClassCandidate,
                                                 PsiClass derivedClassCandidate,
                                                 PsiSubstitutor derivedSubstitutor)

getSuperClassSubstitutor

public static PsiSubstitutor getSuperClassSubstitutor(PsiClass superClass,
                                                      PsiClass derivedClass,
                                                      PsiSubstitutor derivedSubstitutor)
Calculates substitutor that binds type parameters in superClass with values that they have in derivedClass, given that type parameters in derivedClass are bound by derivedSubstitutor. superClass must be a super class/interface of derivedClass (as in InheritanceUtil.isInheritor(derivedClass, superClass, true)

Parameters:
superClass -
derivedClass -
derivedSubstitutor -
Returns:
substitutor (never returns null)
See Also:
InheritanceUtil.isInheritor(PsiClass, PsiClass, boolean)

binaryNumericPromotion

public static PsiType binaryNumericPromotion(PsiType type1,
                                             PsiType type2)
see JLS 5.6.2


isIntegerNumber

public static boolean isIntegerNumber(java.lang.String typeName)

isPrimitive

public static boolean isPrimitive(java.lang.String typeName)

isPrimitiveWrapper

public static boolean isPrimitiveWrapper(java.lang.String typeName)

typeParameterErasure

public static PsiClassType typeParameterErasure(PsiTypeParameter typeParameter)

erasure

public static PsiType erasure(PsiType type)

computeCastTo

public static java.lang.Object computeCastTo(java.lang.Object operand,
                                             PsiType castType)