本文整理汇总了Java中com.intellij.psi.util.TypeConversionUtil.isNumericType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeConversionUtil.isNumericType方法的具体用法?Java TypeConversionUtil.isNumericType怎么用?Java TypeConversionUtil.isNumericType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.TypeConversionUtil
的用法示例。
在下文中一共展示了TypeConversionUtil.isNumericType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isBooleanOrNumeric
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static ConditionalKind isBooleanOrNumeric(PsiExpression expr) {
if (expr instanceof PsiParenthesizedExpression) {
return isBooleanOrNumeric(((PsiParenthesizedExpression)expr).getExpression());
}
if (expr == null) return null;
PsiType type = null;
if (expr instanceof PsiNewExpression || hasStandaloneForm(expr)) {
type = expr.getType();
} else if (expr instanceof PsiMethodCallExpression) {
final PsiMethod method = ((PsiMethodCallExpression)expr).resolveMethod();
if (method != null) {
type = method.getReturnType();
}
}
if (TypeConversionUtil.isNumericType(type)) return ConditionalKind.NUMERIC;
if (TypeConversionUtil.isBooleanType(type)) return ConditionalKind.BOOLEAN;
if (expr instanceof PsiConditionalExpression) {
final PsiExpression thenExpression = ((PsiConditionalExpression)expr).getThenExpression();
final PsiExpression elseExpression = ((PsiConditionalExpression)expr).getElseExpression();
final ConditionalKind thenKind = isBooleanOrNumeric(thenExpression);
final ConditionalKind elseKind = isBooleanOrNumeric(elseExpression);
if (thenKind == elseKind || elseKind == null) return thenKind;
if (thenKind == null) return elseKind;
}
return null;
}
示例2: hasOverflow
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean hasOverflow(PsiExpression expr, @NotNull Project project) {
if (!TypeConversionUtil.isNumericType(expr.getType())) return false;
boolean overflow = false;
try {
if (expr.getUserData(HAS_OVERFLOW_IN_CHILD) == null) {
JavaPsiFacade.getInstance(project).getConstantEvaluationHelper().computeConstantExpression(expr, true);
}
else {
overflow = true;
}
}
catch (ConstantEvaluationOverflowException e) {
overflow = true;
}
finally {
PsiElement parent = expr.getParent();
if (overflow && parent instanceof PsiExpression) {
parent.putUserData(HAS_OVERFLOW_IN_CHILD, "");
}
}
return overflow;
}
示例3: createFromValue
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@NotNull
public DfaConstValue createFromValue(Object value, final PsiType type, @Nullable PsiVariable constant) {
if (value == Boolean.TRUE) return dfaTrue;
if (value == Boolean.FALSE) return dfaFalse;
if (TypeConversionUtil.isNumericType(type) && !TypeConversionUtil.isFloatOrDoubleType(type)) {
value = TypeConversionUtil.computeCastTo(value, PsiType.LONG);
}
if (value instanceof Double || value instanceof Float) {
double doubleValue = ((Number)value).doubleValue();
if (doubleValue == -0.0) doubleValue = +0.0;
value = new Double(doubleValue);
}
DfaConstValue instance = myValues.get(value);
if (instance == null) {
instance = new DfaConstValue(value, myFactory, constant);
myValues.put(value, instance);
}
return instance;
}
示例4: isBinaryNumericPromotionApplicable
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean isBinaryNumericPromotionApplicable(PsiType lType, PsiType rType, IElementType opType) {
if (lType == null || rType == null) {
return false;
}
if (!TypeConversionUtil.isNumericType(lType) || !TypeConversionUtil.isNumericType(rType)) {
return false;
}
if (opType == JavaTokenType.EQEQ || opType == JavaTokenType.NE) {
if (PsiType.NULL.equals(lType) || PsiType.NULL.equals(rType)) {
return false;
}
if (lType instanceof PsiClassType && rType instanceof PsiClassType) {
return false;
}
if (lType instanceof PsiClassType) {
return PsiPrimitiveType.getUnboxedType(lType) != null; // should be unboxable
}
if (rType instanceof PsiClassType) {
return PsiPrimitiveType.getUnboxedType(rType) != null; // should be unboxable
}
return true;
}
return opType == JavaTokenType.ASTERISK ||
opType == JavaTokenType.DIV ||
opType == JavaTokenType.PERC ||
opType == JavaTokenType.PLUS ||
opType == JavaTokenType.MINUS ||
opType == JavaTokenType.LT ||
opType == JavaTokenType.LE ||
opType == JavaTokenType.GT ||
opType == JavaTokenType.GE ||
opType == JavaTokenType.AND ||
opType == JavaTokenType.XOR ||
opType == JavaTokenType.OR;
}
示例5: expectedPrimitiveType
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private PsiType expectedPrimitiveType(PsiPrimitiveType type1, PsiType type2) {
if (TypeConversionUtil.isNumericType(type1)) {
// JLS 15.21.1. Numerical Equality Operators == and !=
return TypeConversionUtil.isNumericType(type2) ? TypeConversionUtil.binaryNumericPromotion(type1, type2) : null;
}
else if (PsiType.BOOLEAN.equals(type1)) {
// JLS 15.21.2. Boolean Equality Operators == and !=
return TypeConversionUtil.isBooleanType(type2) ? PsiType.BOOLEAN : null;
}
else if (PsiType.NULL.equals(type1)) {
return TypeUtils.getObjectType(wrappedExpression);
}
// void
return null;
}
示例6: isNumericType
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public static boolean isNumericType(@Nullable PsiType type) {
if (type instanceof PsiClassType) {
return TYPE_TO_RANK.contains(getQualifiedName(type));
}
return type instanceof PsiPrimitiveType && TypeConversionUtil.isNumericType(type);
}
示例7: getCastString
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static String getCastString(PsiExpression lhs, PsiExpression rhs) {
if (lhs == null || rhs == null) {
return "";
}
final PsiType lType = lhs.getType();
PsiType rType = rhs.getType();
if (TypeConversionUtil.isNumericType(rType)) {
rType = TypeConversionUtil.binaryNumericPromotion(lType, rType);
}
if (lType == null || rType == null ||
TypeConversionUtil.isAssignable(lType, rType) || !TypeConversionUtil.areTypesConvertible(lType, rType)) {
return "";
}
return '(' + lType.getCanonicalText() + ')';
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:ReplaceOperatorAssignmentWithAssignmentIntention.java
示例8: getType
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
/**
* JLS 15.25
*/
@Override
public PsiType getType() {
PsiExpression expr1 = getThenExpression();
PsiExpression expr2 = getElseExpression();
PsiType type1 = expr1 == null ? null : expr1.getType();
PsiType type2 = expr2 == null ? null : expr2.getType();
if (type1 == null) return type2;
if (type2 == null) return type1;
if (type1.equals(type2)) return type1;
final int typeRank1 = TypeConversionUtil.getTypeRank(type1);
final int typeRank2 = TypeConversionUtil.getTypeRank(type2);
// bug in JLS3, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6888770
if (type1 instanceof PsiClassType && type2.equals(PsiPrimitiveType.getUnboxedType(type1))) return type2;
if (type2 instanceof PsiClassType && type1.equals(PsiPrimitiveType.getUnboxedType(type2))) return type1;
if (TypeConversionUtil.isNumericType(typeRank1) && TypeConversionUtil.isNumericType(typeRank2)){
if (typeRank1 == TypeConversionUtil.BYTE_RANK && typeRank2 == TypeConversionUtil.SHORT_RANK) {
return type2 instanceof PsiPrimitiveType ? type2 : PsiPrimitiveType.getUnboxedType(type2);
}
if (typeRank1 == TypeConversionUtil.SHORT_RANK && typeRank2 == TypeConversionUtil.BYTE_RANK) {
return type1 instanceof PsiPrimitiveType ? type1 : PsiPrimitiveType.getUnboxedType(type1);
}
if (typeRank2 == TypeConversionUtil.INT_RANK && (typeRank1 == TypeConversionUtil.BYTE_RANK || typeRank1 == TypeConversionUtil.SHORT_RANK || typeRank1 == TypeConversionUtil.CHAR_RANK)){
if (TypeConversionUtil.areTypesAssignmentCompatible(type1, expr2)) return type1;
}
if (typeRank1 == TypeConversionUtil.INT_RANK && (typeRank2 == TypeConversionUtil.BYTE_RANK || typeRank2 == TypeConversionUtil.SHORT_RANK || typeRank2 == TypeConversionUtil.CHAR_RANK)){
if (TypeConversionUtil.areTypesAssignmentCompatible(type2, expr1)) return type2;
}
return TypeConversionUtil.binaryNumericPromotion(type1, type2);
}
if (TypeConversionUtil.isNullType(type1) && !(type2 instanceof PsiPrimitiveType)) return type2;
if (TypeConversionUtil.isNullType(type2) && !(type1 instanceof PsiPrimitiveType)) return type1;
if (PsiUtil.isLanguageLevel8OrHigher(this) &&
PsiPolyExpressionUtil.isPolyExpression(this) &&
!MethodCandidateInfo.ourOverloadGuard.currentStack().contains(PsiUtil.skipParenthesizedExprUp(this.getParent()))) {
//15.25.3 Reference Conditional Expressions
// The type of a poly reference conditional expression is the same as its target type.
return InferenceSession.getTargetType(this);
}
if (TypeConversionUtil.isAssignable(type1, type2, false)) return type1;
if (TypeConversionUtil.isAssignable(type2, type1, false)) return type2;
if (!PsiUtil.isLanguageLevel5OrHigher(this)) {
return null;
}
if (TypeConversionUtil.isPrimitiveAndNotNull(type1)) {
type1 = ((PsiPrimitiveType)type1).getBoxedType(this);
if (type1 == null) return null;
}
if (TypeConversionUtil.isPrimitiveAndNotNull(type2)) {
type2 = ((PsiPrimitiveType)type2).getBoxedType(this);
if (type2 == null) return null;
}
if (type1 instanceof PsiLambdaParameterType || type2 instanceof PsiLambdaParameterType) return null;
final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(type1, type2, getManager());
return leastUpperBound != null ? PsiUtil.captureToplevelWildcards(leastUpperBound, this) : null;
}
示例9: VariableAssignedVisitor
import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public VariableAssignedVisitor(@NotNull PsiVariable variable, boolean recurseIntoClasses) {
variables = Collections.singleton(variable);
final PsiType type = variable.getType();
checkUnaryExpressions = TypeConversionUtil.isNumericType(type);
this.recurseIntoClasses = recurseIntoClasses;
}