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


Java TypeConversionUtil.areTypesAssignmentCompatible方法代码示例

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


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

示例1: isAvailable

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  if (!myArrayAccessExpression.isValid()) return false;
  if (!TypeConversionUtil.areTypesAssignmentCompatible(PsiType.INT, myArrayAccessExpression.getIndexExpression())) {
    return false;
  }
  final PsiElement parent = myArrayAccessExpression.getParent();
  if (parent instanceof PsiAssignmentExpression) {
    final PsiExpression lExpression = ((PsiAssignmentExpression)parent).getLExpression();
    if (lExpression.equals(myArrayAccessExpression) && !(parent.getParent() instanceof PsiExpressionStatement)) {
      return false;
    }
  }

  final PsiExpression arrayExpression = myArrayAccessExpression.getArrayExpression();
  final PsiType type = arrayExpression.getType();
  final PsiType listType = createUtilListType(project);

  if (type == null || listType == null) return false;


  return listType.isAssignableFrom(type);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:ReplaceWithListAccessFix.java

示例2: visitAssignmentExpression

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public void visitAssignmentExpression(PsiAssignmentExpression expression) {
  final PsiExpression rExpression = expression.getRExpression();
  if(rExpression == null) {
    throwExpressionInvalid(expression);
  }

  rExpression.accept(this);
  Evaluator rEvaluator = myResult;

  final PsiExpression lExpression = expression.getLExpression();
  final PsiType lType = lExpression.getType();
  if(lType == null) {
    throwEvaluateException(DebuggerBundle.message("evaluation.error.unknown.expression.type", lExpression.getText()));
  }

  IElementType assignmentType = expression.getOperationTokenType();
  PsiType rType = rExpression.getType();
  if(!TypeConversionUtil.areTypesAssignmentCompatible(lType, rExpression) && rType != null) {
    throwEvaluateException(DebuggerBundle.message("evaluation.error.incompatible.types", expression.getOperationSign().getText()));
  }
  lExpression.accept(this);
  Evaluator lEvaluator = myResult;

  rEvaluator = handleAssignmentBoxingAndPrimitiveTypeConversions(lType, rType, rEvaluator);

  if (assignmentType != JavaTokenType.EQ) {
    IElementType opType = TypeConversionUtil.convertEQtoOperation(assignmentType);
    final PsiType typeForBinOp = TypeConversionUtil.calcTypeForBinaryExpression(lType, rType, opType, true);
    if (typeForBinOp == null || rType == null) {
      throwEvaluateException(DebuggerBundle.message("evaluation.error.unknown.expression.type", expression.getText()));
    }
    rEvaluator = createBinaryEvaluator(lEvaluator, lType, rEvaluator, rType, opType, typeForBinOp);
  }
  myResult = new AssignmentEvaluator(lEvaluator, rEvaluator);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:EvaluatorBuilderImpl.java

示例3: registerFix

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public static void registerFix(HighlightInfo info, PsiCall callExpression, final CandidateInfo[] candidates, final TextRange fixRange) {
  PsiExpression[] expressions = callExpression.getArgumentList().getExpressions();
  if (expressions.length < 2) return;
  List<PsiCall> permutations = new ArrayList<PsiCall>();

  for (CandidateInfo candidate : candidates) {
    if (candidate instanceof MethodCandidateInfo) {
      MethodCandidateInfo methodCandidate = (MethodCandidateInfo)candidate;
      PsiMethod method = methodCandidate.getElement();
      PsiSubstitutor substitutor = methodCandidate.getSubstitutor();

      PsiParameter[] parameters = method.getParameterList().getParameters();
      if (expressions.length != parameters.length || parameters.length ==0) continue;
      int minIncompatibleIndex = parameters.length;
      int maxIncompatibleIndex = 0;
      int incompatibilitiesCount = 0;
      for (int i = 0; i < parameters.length; i++) {
        PsiParameter parameter = parameters[i];
        PsiType type = substitutor.substitute(parameter.getType());
        if (TypeConversionUtil.areTypesAssignmentCompatible(type, expressions[i])) continue;
        if (minIncompatibleIndex == parameters.length) minIncompatibleIndex = i;
        maxIncompatibleIndex = i;
        incompatibilitiesCount++;
      }

      try {
        registerSwapFixes(expressions, callExpression, permutations, methodCandidate, incompatibilitiesCount, minIncompatibleIndex, maxIncompatibleIndex);
        registerShiftFixes(expressions, callExpression, permutations, methodCandidate, minIncompatibleIndex, maxIncompatibleIndex);
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  }
  if (permutations.size() == 1) {
    PermuteArgumentsFix fix = new PermuteArgumentsFix(callExpression, permutations.get(0));
    QuickFixAction.registerQuickFixAction(info, fixRange, fix);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:PermuteArgumentsFix.java

示例4: isArgumentInVarargPosition

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
static boolean isArgumentInVarargPosition(PsiExpression[] expressions, int ei, PsiParameter varargParam, PsiSubstitutor substitutor) {
  if (varargParam == null) return false;
  final PsiExpression expression = expressions[ei];
  if (expression == null || TypeConversionUtil.areTypesAssignmentCompatible(substitutor.substitute(((PsiEllipsisType)varargParam.getType()).getComponentType()), expression)) {
    final int lastExprIdx = expressions.length - 1;
    if (ei == lastExprIdx) return true;
    return expressions[lastExprIdx].getType() != PsiType.NULL;
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:ChangeMethodSignatureFromUsageFix.java

示例5: 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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:PsiConditionalExpressionImpl.java


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