当前位置: 首页>>代码示例>>Java>>正文


Java TypeConversionUtil.areTypesConvertible方法代码示例

本文整理汇总了Java中com.intellij.psi.util.TypeConversionUtil.areTypesConvertible方法的典型用法代码示例。如果您正苦于以下问题:Java TypeConversionUtil.areTypesConvertible方法的具体用法?Java TypeConversionUtil.areTypesConvertible怎么用?Java TypeConversionUtil.areTypesConvertible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.util.TypeConversionUtil的用法示例。


在下文中一共展示了TypeConversionUtil.areTypesConvertible方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitMethodCallExpression

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
  super.visitMethodCallExpression(expression);
  if (!MethodCallUtils.isEqualsCall(expression)) {
    return;
  }
  final PsiReferenceExpression methodExpression = expression.getMethodExpression();
  final PsiExpression qualifier = methodExpression.getQualifierExpression();
  if (qualifier == null || !TypeUtils.expressionHasTypeOrSubtype(qualifier, CommonClassNames.JAVA_LANG_ENUM)) {
    return;
  }
  final PsiExpressionList argumentList = expression.getArgumentList();
  final PsiExpression[] arguments = argumentList.getExpressions();
  if (arguments.length > 0) {
    final PsiType comparedTypeErasure = TypeConversionUtil.erasure(qualifier.getType());
    final PsiType comparisonTypeErasure = TypeConversionUtil.erasure(arguments[0].getType());
    if (comparedTypeErasure == null || comparisonTypeErasure == null ||
        !TypeConversionUtil.areTypesConvertible(comparedTypeErasure, comparisonTypeErasure)) {
      return;
    }
  }
  registerMethodCallError(expression, expression);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:EqualsCalledOnEnumConstantInspection.java

示例2: areConvertible

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public static boolean areConvertible(PsiType type1, PsiType type2) {
  if (TypeConversionUtil.areTypesConvertible(type1, type2)) {
    return true;
  }
  final PsiType comparedTypeErasure = TypeConversionUtil.erasure(type1);
  final PsiType comparisonTypeErasure = TypeConversionUtil.erasure(type2);
  if (comparedTypeErasure == null || comparisonTypeErasure == null ||
      TypeConversionUtil.areTypesConvertible(comparedTypeErasure, comparisonTypeErasure)) {
    if (type1 instanceof PsiClassType && type2 instanceof PsiClassType) {
      final PsiClassType classType1 = (PsiClassType)type1;
      final PsiClassType classType2 = (PsiClassType)type2;
      final PsiType[] parameters1 = classType1.getParameters();
      final PsiType[] parameters2 = classType2.getParameters();
      if (parameters1.length != parameters2.length) {
        return ((PsiClassType)type1).isRaw() || ((PsiClassType)type2).isRaw();
      }
      for (int i = 0; i < parameters1.length; i++) {
        if (!areConvertible(parameters1[i], parameters2[i])) {
          return false;
        }
      }
    }
    return true;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:TypeUtils.java

示例3: visitTypeCastExpression

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public void visitTypeCastExpression(final PsiTypeCastExpression expression) {
  super.visitTypeCastExpression(expression);
  final PsiTypeElement typeElement = expression.getCastType();
  if (typeElement != null) {
    final PsiType fixedType = typeElement.getType();
    final PsiType migrationType = myTypeEvaluator.evaluateType(expression.getOperand());
    if (migrationType != null && !TypeConversionUtil.areTypesConvertible(migrationType, fixedType)) {
      myLabeler.markFailedConversion(Pair.create(fixedType, migrationType), expression);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:TypeMigrationStatementProcessor.java

示例4: isThreadLocalTypeMigration

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean isThreadLocalTypeMigration(PsiType from, PsiClassType to, PsiExpression context) {
  final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(to);
  final PsiClass threadLocalClass = resolveResult.getElement();

  if (threadLocalClass != null) {
    final String typeQualifiedName = threadLocalClass.getQualifiedName();
    if (!Comparing.strEqual(typeQualifiedName, ThreadLocal.class.getName())) {
      return false;
    }
    final PsiTypeParameter[] typeParameters = threadLocalClass.getTypeParameters();
    if (typeParameters.length != 1) return !PsiUtil.isLanguageLevel5OrHigher(context);
    final PsiType toTypeParameterValue = resolveResult.getSubstitutor().substitute(typeParameters[0]);
    if (toTypeParameterValue != null) {
      if (from instanceof PsiPrimitiveType) {
        final PsiPrimitiveType unboxedInitialType = PsiPrimitiveType.getUnboxedType(toTypeParameterValue);
        if (unboxedInitialType != null) {
          return TypeConversionUtil.areTypesConvertible(from, unboxedInitialType);
        }
      }
      else {
        return TypeConversionUtil.isAssignable(from, PsiUtil.captureToplevelWildcards(toTypeParameterValue, context));
      }
    }
    return !PsiUtil.isLanguageLevel5OrHigher(context);
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:ThreadLocalConversionRule.java

示例5: 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

示例6: isConvertibleFrom

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
/**
 * Checks whether values of type <code>type</code> can be casted to this type.
 */
public boolean isConvertibleFrom(@NotNull PsiType type) {
  return TypeConversionUtil.areTypesConvertible(type, this);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PsiType.java

示例7: createBinaryEvaluator

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static BinaryExpressionEvaluator createBinaryEvaluator(Evaluator lResult,
                                                               PsiType lType,
                                                               Evaluator rResult,
                                                               @NotNull PsiType rType,
                                                               @NotNull IElementType operation,
                                                               @NotNull PsiType expressionExpectedType) {
  // handle unboxing if necessary
  if (isUnboxingInBinaryExpressionApplicable(lType, rType, operation)) {
    if (rType instanceof PsiClassType && UnBoxingEvaluator.isTypeUnboxable(rType.getCanonicalText())) {
      rResult = new UnBoxingEvaluator(rResult);
    }
    if (lType instanceof PsiClassType && UnBoxingEvaluator.isTypeUnboxable(lType.getCanonicalText())) {
      lResult = new UnBoxingEvaluator(lResult);
    }
  }
  if (isBinaryNumericPromotionApplicable(lType, rType, operation)) {
    PsiType _lType = lType;
    final PsiPrimitiveType unboxedLType = PsiPrimitiveType.getUnboxedType(lType);
    if (unboxedLType != null) {
      _lType = unboxedLType;
    }

    PsiType _rType = rType;
    final PsiPrimitiveType unboxedRType = PsiPrimitiveType.getUnboxedType(rType);
    if (unboxedRType != null) {
      _rType = unboxedRType;
    }

    // handle numeric promotion
    if (PsiType.DOUBLE.equals(_lType)) {
      if (TypeConversionUtil.areTypesConvertible(_rType, PsiType.DOUBLE)) {
        rResult = new TypeCastEvaluator(rResult, PsiType.DOUBLE.getCanonicalText(), true);
      }
    }
    else if (PsiType.DOUBLE.equals(_rType)) {
      if (TypeConversionUtil.areTypesConvertible(_lType, PsiType.DOUBLE)) {
        lResult = new TypeCastEvaluator(lResult, PsiType.DOUBLE.getCanonicalText(), true);
      }
    }
    else if (PsiType.FLOAT.equals(_lType)) {
      if (TypeConversionUtil.areTypesConvertible(_rType, PsiType.FLOAT)) {
        rResult = new TypeCastEvaluator(rResult, PsiType.FLOAT.getCanonicalText(), true);
      }
    }
    else if (PsiType.FLOAT.equals(_rType)) {
      if (TypeConversionUtil.areTypesConvertible(_lType, PsiType.FLOAT)) {
        lResult = new TypeCastEvaluator(lResult, PsiType.FLOAT.getCanonicalText(), true);
      }
    }
    else if (PsiType.LONG.equals(_lType)) {
      if (TypeConversionUtil.areTypesConvertible(_rType, PsiType.LONG)) {
        rResult = new TypeCastEvaluator(rResult, PsiType.LONG.getCanonicalText(), true);
      }
    }
    else if (PsiType.LONG.equals(_rType)) {
      if (TypeConversionUtil.areTypesConvertible(_lType, PsiType.LONG)) {
        lResult = new TypeCastEvaluator(lResult, PsiType.LONG.getCanonicalText(), true);
      }
    }
    else {
      if (!PsiType.INT.equals(_lType) && TypeConversionUtil.areTypesConvertible(_lType, PsiType.INT)) {
        lResult = new TypeCastEvaluator(lResult, PsiType.INT.getCanonicalText(), true);
      }
      if (!PsiType.INT.equals(_rType) && TypeConversionUtil.areTypesConvertible(_rType, PsiType.INT)) {
        rResult = new TypeCastEvaluator(rResult, PsiType.INT.getCanonicalText(), true);
      }
    }
  }

  return new BinaryExpressionEvaluator(lResult, rResult, operation, expressionExpectedType.getCanonicalText());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:72,代码来源:EvaluatorBuilderImpl.java

示例8: visitTypeCastExpression

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public void visitTypeCastExpression(PsiTypeCastExpression expression) {
  PsiExpression operandExpr = expression.getOperand();
  if (operandExpr == null) {
    throwExpressionInvalid(expression);
  }
  operandExpr.accept(this);
  Evaluator operandEvaluator = myResult;
  PsiTypeElement castTypeElem = expression.getCastType();
  if (castTypeElem == null) {
    throwExpressionInvalid(expression);
  }
  PsiType castType = castTypeElem.getType();
  PsiType operandType = operandExpr.getType();

  // if operand type can not be resolved in current context - leave it for runtime checks
  if (operandType != null &&
      !TypeConversionUtil.areTypesConvertible(operandType, castType) &&
      PsiUtil.resolveClassInType(operandType) != null) {
    throw new EvaluateRuntimeException(
      new EvaluateException(JavaErrorMessages.message("inconvertible.type.cast", JavaHighlightUtil.formatType(operandType), JavaHighlightUtil
        .formatType(castType)))
    );
  }

  boolean shouldPerformBoxingConversion = operandType != null && TypeConversionUtil.boxingConversionApplicable(castType, operandType);
  final boolean castingToPrimitive = castType instanceof PsiPrimitiveType;
  if (shouldPerformBoxingConversion && castingToPrimitive) {
    operandEvaluator = new UnBoxingEvaluator(operandEvaluator);
  }

  final boolean performCastToWrapperClass = shouldPerformBoxingConversion && !castingToPrimitive;

  if (!(PsiUtil.resolveClassInClassTypeOnly(castType) instanceof PsiTypeParameter)) {
    String castTypeName = castType.getCanonicalText();
    if (performCastToWrapperClass) {
      final PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(castType);
      if (unboxedType != null) {
        castTypeName = unboxedType.getCanonicalText();
      }
    }

    myResult = new TypeCastEvaluator(operandEvaluator, castTypeName, castingToPrimitive);
  }

  if (performCastToWrapperClass) {
    myResult = new BoxingEvaluator(myResult);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:50,代码来源:EvaluatorBuilderImpl.java

示例9: isAtomicTypeMigration

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean isAtomicTypeMigration(PsiType from, PsiClassType to, PsiExpression context) {
  if (from == PsiType.INT && to.getCanonicalText().equals(AtomicInteger.class.getName())) {
    return true;
  }
  if (from.equals(PsiType.INT.createArrayType()) && to.getCanonicalText().equals(AtomicIntegerArray.class.getName())) {
    return true;
  }
  if (from == PsiType.LONG && to.getCanonicalText().equals(AtomicLong.class.getName())) {
    return true;
  }
  if (from.equals(PsiType.LONG.createArrayType()) && to.getCanonicalText().equals(AtomicLongArray.class.getName())) {
    return true;
  }
  if (from == PsiType.BOOLEAN && to.getCanonicalText().equals(AtomicBoolean.class.getName())) {
    return true;
  }
  final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(to);
  final PsiClass atomicClass = resolveResult.getElement();

  if (atomicClass != null) {
    final String typeQualifiedName = atomicClass.getQualifiedName();
    if (!Comparing.strEqual(typeQualifiedName, AtomicReference.class.getName()) &&
        !Comparing.strEqual(typeQualifiedName, AtomicReferenceArray.class.getName())) {
      return false;
    }
    final PsiTypeParameter[] typeParameters = atomicClass.getTypeParameters();
    if (typeParameters.length != 1) return false;
    final PsiType toTypeParameterValue = resolveResult.getSubstitutor().substitute(typeParameters[0]);
    if (toTypeParameterValue != null) {
      if (from.getDeepComponentType() instanceof PsiPrimitiveType) {
        final PsiPrimitiveType unboxedInitialType = PsiPrimitiveType.getUnboxedType(toTypeParameterValue);
        if (unboxedInitialType != null) {
          return TypeConversionUtil.areTypesConvertible(from.getDeepComponentType(), unboxedInitialType);
        }
      }
      else {
        return TypeConversionUtil.isAssignable(from.getDeepComponentType(), PsiUtil.captureToplevelWildcards(toTypeParameterValue, context));
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:43,代码来源:AtomicConversionRule.java

示例10: canCast

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@NotNull
public static ConversionResult canCast(@NotNull PsiType targetType, @NotNull PsiType actualType, @NotNull PsiElement context) {
  final ConversionResult result = areTypesConvertible(targetType, actualType, context, ApplicableTo.EXPLICIT_CAST);
  if (result != null) return result;
  return TypeConversionUtil.areTypesConvertible(targetType, actualType) ? ConversionResult.OK : ConversionResult.ERROR;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:TypesUtil.java


注:本文中的com.intellij.psi.util.TypeConversionUtil.areTypesConvertible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。