public class TypeConversionUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
BYTE_RANK |
static int |
CHAR_RANK |
static int |
DOUBLE_RANK |
static int |
FLOAT_RANK |
static int |
INT_RANK |
static int |
LONG_RANK |
static PsiType |
NULL_TYPE |
static int |
SHORT_RANK |
Modifier and Type | Method and Description |
---|---|
static boolean |
areSameFreshVariables(PsiTypeParameter p1,
PsiTypeParameter p2) |
static boolean |
areTypesAssignmentCompatible(PsiType lType,
PsiExpression rExpr)
JLS 5.2
|
static boolean |
areTypesConvertible(PsiType fromType,
PsiType toType) |
static boolean |
areTypesConvertible(PsiType fromType,
PsiType toType,
LanguageLevel languageLevel) |
static PsiType |
binaryNumericPromotion(PsiType type1,
PsiType type2)
see JLS 5.6.2
|
static boolean |
boxingConversionApplicable(PsiType left,
PsiType right) |
static PsiType |
calcTypeForBinaryExpression(PsiType lType,
PsiType rType,
IElementType sign,
boolean accessLType) |
static java.lang.Object |
computeCastTo(java.lang.Object operand,
PsiType castType) |
static IElementType |
convertEQtoOperation(IElementType eqOpSign) |
static PsiType |
erasure(PsiType type) |
static PsiType |
erasure(PsiType type,
PsiSubstitutor beforeSubstitutor) |
static PsiSubstitutor |
getClassSubstitutor(PsiClass superClassCandidate,
PsiClass derivedClassCandidate,
PsiSubstitutor derivedSubstitutor) |
static PsiType |
getInferredLowerBoundForSynthetic(PsiTypeParameter psiClass)
the lower bound for the non-physical (and may be non-denotable) type parameter temporarily created during type inference
|
static PsiType |
getInferredUpperBoundForSynthetic(PsiTypeParameter psiClass)
the upper bound for the non-physical (and may be non-denotable) type parameter temporarily created during type inference
|
static PsiSubstitutor |
getMaybeSuperClassSubstitutor(PsiClass superClass,
PsiClass derivedClass,
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 PsiSubstitutor |
getSuperClassSubstitutor(PsiClass superClass,
PsiClassType classType) |
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 |
isAssignableFromPrimitiveWrapper(PsiType type) |
static boolean |
isBinaryOperatorApplicable(IElementType tokenType,
PsiExpression lOperand,
PsiExpression rOperand,
boolean strict) |
static boolean |
isBinaryOperatorApplicable(IElementType tokenType,
PsiType ltype,
PsiType rtype,
boolean strict) |
static boolean |
isBooleanType(PsiType type) |
static boolean |
isComposite(PsiType type) |
static boolean |
isDoubleType(PsiType type) |
static boolean |
isEnumType(PsiType type) |
static boolean |
isFloatOrDoubleType(PsiType type) |
static boolean |
isFloatType(PsiType type) |
static boolean |
isFPZero(java.lang.String text)
See JLS 3.10.2.
|
static boolean |
isFreshVariable(PsiTypeParameter typeParameter) |
static boolean |
isIntegerNumber(java.lang.String typeName) |
static boolean |
isIntegralNumberType(PsiType type) |
static boolean |
isLongType(PsiType type) |
static boolean |
isLValue(PsiExpression element) |
static boolean |
isNullType(PsiType type) |
static boolean |
isNumericType(int typeRank) |
static boolean |
isNumericType(PsiType type) |
static boolean |
isPrimitive(java.lang.String typeName) |
static boolean |
isPrimitiveAndNotNull(PsiType type) |
static boolean |
isPrimitiveAndNotNullOrWrapper(PsiType type) |
static boolean |
isPrimitiveWrapper(PsiType type) |
static boolean |
isPrimitiveWrapper(java.lang.String fullyQualifiedName) |
static boolean |
isSafeConversion(PsiType target,
PsiType source)
Returns true if numeric conversion (widening or narrowing) does not lose the information.
|
static boolean |
isUnaryOperatorApplicable(PsiJavaToken token,
PsiExpression operand) |
static boolean |
isUnaryOperatorApplicable(PsiJavaToken token,
PsiType type) |
static boolean |
isVoidType(PsiType type) |
static void |
markAsFreshVariable(PsiTypeParameter parameter,
PsiElement context) |
static void |
setInferredBoundsForSynthetic(PsiTypeParameter parameter,
PsiType lowerBound,
PsiType upperBound) |
static PsiType |
typeParameterErasure(PsiTypeParameter typeParameter) |
static boolean |
typesAgree(PsiType typeLeft,
PsiType typeRight,
boolean allowUncheckedConversion) |
static PsiType |
unboxAndBalanceTypes(PsiType type1,
PsiType type2) |
public static final int BYTE_RANK
public static final int SHORT_RANK
public static final int CHAR_RANK
public static final int INT_RANK
public static final int LONG_RANK
public static final int FLOAT_RANK
public static final int DOUBLE_RANK
public static final PsiType NULL_TYPE
public static boolean areTypesConvertible(PsiType fromType, PsiType toType)
public static boolean areTypesConvertible(PsiType fromType, PsiType toType, LanguageLevel languageLevel)
public static boolean isPrimitiveAndNotNull(PsiType type)
public static boolean isEnumType(PsiType type)
public static boolean isNullType(PsiType type)
public static boolean isFloatOrDoubleType(PsiType type)
public static boolean isDoubleType(PsiType type)
public static boolean isFloatType(PsiType type)
public static boolean isLongType(PsiType type)
public static boolean isVoidType(PsiType type)
public static boolean isBooleanType(PsiType type)
public static boolean isNumericType(int typeRank)
public static boolean isNumericType(PsiType type)
public static boolean isIntegralNumberType(PsiType type)
public static int getTypeRank(PsiType type)
public static boolean isBinaryOperatorApplicable(IElementType tokenType, PsiExpression lOperand, PsiExpression rOperand, boolean strict)
tokenType
- JavaTokenType enumerationstrict
- true if operator result type should be convertible to the left operandpublic static boolean isBinaryOperatorApplicable(IElementType tokenType, PsiType ltype, PsiType rtype, boolean strict)
public static boolean isPrimitiveAndNotNullOrWrapper(PsiType type)
public static boolean isUnaryOperatorApplicable(PsiJavaToken token, PsiExpression operand)
public static boolean isUnaryOperatorApplicable(PsiJavaToken token, PsiType type)
public static boolean isLValue(PsiExpression element)
public static boolean areTypesAssignmentCompatible(PsiType lType, PsiExpression rExpr)
public static boolean isAssignable(PsiType left, PsiType right)
left
- type to assign toright
- type of valueright
can be assigned to an l-value of
type left
public static boolean isAssignable(PsiType left, PsiType right, boolean allowUncheckedConversion)
public static boolean boxingConversionApplicable(PsiType left, PsiType right)
public static boolean typesAgree(PsiType typeLeft, PsiType typeRight, boolean allowUncheckedConversion)
public static PsiSubstitutor getClassSubstitutor(PsiClass superClassCandidate, PsiClass derivedClassCandidate, PsiSubstitutor derivedSubstitutor)
public static PsiSubstitutor getSuperClassSubstitutor(PsiClass superClass, PsiClass derivedClass, PsiSubstitutor derivedSubstitutor)
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.isInheritorOrSelf(derivedClass, superClass, true)
null
)PsiClass.isInheritor(PsiClass, boolean)
,
InheritanceUtil.isInheritorOrSelf(PsiClass, PsiClass, boolean)
public static PsiSubstitutor getMaybeSuperClassSubstitutor(PsiClass superClass, PsiClass derivedClass, PsiSubstitutor derivedSubstitutor)
public static PsiSubstitutor getSuperClassSubstitutor(PsiClass superClass, PsiClassType classType)
public static PsiType binaryNumericPromotion(PsiType type1, PsiType type2)
public static boolean isIntegerNumber(java.lang.String typeName)
public static boolean isPrimitive(java.lang.String typeName)
public static boolean isPrimitiveWrapper(java.lang.String fullyQualifiedName)
public static boolean isAssignableFromPrimitiveWrapper(PsiType type)
public static boolean isPrimitiveWrapper(PsiType type)
public static boolean isComposite(PsiType type)
public static PsiType typeParameterErasure(PsiTypeParameter typeParameter)
public static PsiType erasure(PsiType type, PsiSubstitutor beforeSubstitutor)
public static java.lang.Object computeCastTo(java.lang.Object operand, PsiType castType)
public static IElementType convertEQtoOperation(IElementType eqOpSign)
public static PsiType calcTypeForBinaryExpression(PsiType lType, PsiType rType, IElementType sign, boolean accessLType)
public static boolean isFPZero(java.lang.String text)
public static boolean areSameFreshVariables(PsiTypeParameter p1, PsiTypeParameter p2)
public static boolean isFreshVariable(PsiTypeParameter typeParameter)
public static void markAsFreshVariable(PsiTypeParameter parameter, PsiElement context)
public static PsiType getInferredUpperBoundForSynthetic(PsiTypeParameter psiClass)
InferenceSession
public static PsiType getInferredLowerBoundForSynthetic(PsiTypeParameter psiClass)
InferenceSession
public static void setInferredBoundsForSynthetic(PsiTypeParameter parameter, PsiType lowerBound, PsiType upperBound)
public static boolean isSafeConversion(PsiType target, PsiType source)
isAssignable(PsiType, PsiType)
result as some assignable types
still may lose the information. E.g. double doubleVar = longVar
may lose round the long value.target
- target typesource
- source type