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


Java TypeConversionUtil.isAssignable方法代码示例

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


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

示例1: isAssignable

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean isAssignable( boolean structural, boolean covariant, PsiType to, PsiType from )
{
  if( to.equals( from ) )
  {
    return true;
  }

  if( structural )
  {
    return TypeConversionUtil.isAssignable( to, from ) ||
           arePrimitiveTypesAssignable( to, from ) ||
           isStructurallyAssignable( to, from, structural ) ||
           TypeConversionUtil.boxingConversionApplicable( to, from );
  }

  if( covariant )
  {
    TypeConversionUtil.isAssignable( to, from );
  }

  return false;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:23,代码来源:TypeUtil.java

示例2: findRedundantArgument

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiExpression[] findRedundantArgument(@NotNull PsiExpression[] arguments,
                                                     @NotNull PsiParameter[] parameters,
                                                     @NotNull PsiSubstitutor substitutor) {
  if (arguments.length <= parameters.length) return null;

  for (int i = 0; i < parameters.length; i++) {
    final PsiExpression argument = arguments[i];
    final PsiParameter parameter = parameters[i];

    final PsiType argumentType = argument.getType();
    if (argumentType == null) return null;
    final PsiType parameterType = substitutor.substitute(parameter.getType());

    if (!TypeConversionUtil.isAssignable(parameterType, argumentType)) {
      return null;
    }
  }

  return Arrays.copyOfRange(arguments, parameters.length, arguments.length);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:RemoveRedundantArgumentsFix.java

示例3: findVariablesOfType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
static VariablesProcessor findVariablesOfType(final PsiDeclarationStatement declaration, final PsiType type) {
  VariablesProcessor proc = new VariablesProcessor(false) {
    @Override
    protected boolean check(PsiVariable var, ResolveState state) {
      for (PsiElement element : declaration.getDeclaredElements()) {
        if (element == var) return false;
      }
      return TypeConversionUtil.isAssignable(var.getType(), type);
    }
  };
  PsiElement scope = declaration;
  while (scope != null) {
    if (scope instanceof PsiFile || 
        scope instanceof PsiMethod || 
        scope instanceof PsiLambdaExpression ||
        scope instanceof PsiClassInitializer) break;
    scope = scope.getParent();
  }
  if (scope == null) return proc;
  PsiScopesUtil.treeWalkUp(proc, declaration, scope);
  return proc;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ReassignVariableUtil.java

示例4: getBroaderType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType getBroaderType(PsiType currentType, PsiType castType) {
  if (currentType != null) {
    if (castType != null) {
      if (TypeConversionUtil.isAssignable(castType, currentType)) {
        return castType;
      } else if (!TypeConversionUtil.isAssignable(currentType, castType)) {
        for (PsiType superType : castType.getSuperTypes()) {
          if (TypeConversionUtil.isAssignable(superType, currentType)) {
            return superType;
          }
        }
        return null;
      }
    }
  }
  else {
    return castType;
  }
  return currentType;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:InputVariables.java

示例5: getConflictMessage

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public String getConflictMessage() {
  if (!TypeConversionUtil.isAssignable(myOriginalType, myTargetClassType)) {
    final String conflict = "No consistent substitution found for " +
                            getElement().getText() +
                            ". Expected \'" +
                            myOriginalType.getPresentableText() +
                            "\' but found \'" +
                            myTargetClassType.getPresentableText() +
                            "\'.";
    if (myConflict == null) {
      myConflict = conflict;
    } else {
      myConflict += "\n" + conflict;
    }
  }
  return myConflict;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ReplaceWithSubtypeUsageInfo.java

示例6: shouldInlineParameterName

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private boolean shouldInlineParameterName(int paramIndex) {
  PsiExpression argument = myCallArguments[paramIndex];
  if (isLiteralExpression(argument) && argument.getType() != null) {
    PsiParameter parameter = myParameters[paramIndex];
    String paramName = parameter.getName();
    if (paramName != null && paramName.length() >= MIN_NAME_LENGTH_THRESHOLD) {
      return TypeConversionUtil.isAssignable(parameter.getType(), argument.getType());
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ParameterNameFoldingManager.java

示例7: isAddressed

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean isAddressed(List<PsiType> expectedThrownTypes, PsiType thrownType) {
  for (PsiType expectedThrownType : expectedThrownTypes) {
    if (TypeConversionUtil.isAssignable(TypeConversionUtil.erasure(thrownType), expectedThrownType)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:CheckedExceptionCompatibilityConstraint.java

示例8: canCollapse

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean canCollapse(PsiParameter[] parameters, int index1, int index2) {
  if (index2 <= index1) throw new IllegalArgumentException();
  final PsiType type = parameters[index2].getType();
  for (int i = index1 + 1; i < index2; i++) {
    final PsiType otherType = parameters[i].getType();
    if (TypeConversionUtil.isAssignable(type, otherType)) {
      return false;
    }
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:TryWithIdenticalCatchesInspection.java

示例9: changeCollectionCallsToArray

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static TypeConversionDescriptor changeCollectionCallsToArray(final PsiMethod method,
                                                                     final PsiElement context,
                                                                     PsiType collectionType,
                                                                     PsiArrayType arrayType) {
  @NonNls final String methodName = method.getName();
  if (methodName.equals("toArray")) {
    if (method.getParameterList().getParameters().length == 0) {
      return new TypeConversionDescriptor("$qualifier$.toArray()", "$qualifier$");
    }
    return new TypeConversionDescriptor("$qualifier$.toArray($expr$)", "$qualifier$");
  }
  else if (methodName.equals("size")) {
    return new TypeConversionDescriptor("$qualifier$.size()", "$qualifier$.length");
  }
  else if (methodName.equals("get")) {
    if (TypeConversionUtil.isAssignable(collectionType, arrayType.getComponentType())) {
      return new TypeConversionDescriptor("$qualifier$.get($i$)", "$qualifier$[$i$]", PsiTreeUtil.getParentOfType(context, PsiMethodCallExpression.class));
    }
  }
  else if (methodName.equals("set")) {
    if (TypeConversionUtil.isAssignable(arrayType.getComponentType(), collectionType)) {
      return new TypeConversionDescriptor("$qualifier$.set($i$, $val$)", "$qualifier$[$i$] = $val$");
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:ListArrayConversionRule.java

示例10: checkParametersCompatible

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
static HighlightInfo checkParametersCompatible(PsiLambdaExpression expression,
                                               PsiParameter[] methodParameters,
                                               PsiSubstitutor substitutor) {
  final PsiParameter[] lambdaParameters = expression.getParameterList().getParameters();
  String incompatibleTypesMessage = "Incompatible parameter types in lambda expression: ";
  if (lambdaParameters.length != methodParameters.length) {
    incompatibleTypesMessage += "wrong number of parameters: expected " + methodParameters.length + " but found " + lambdaParameters.length;
    return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
      .range(expression.getParameterList())
      .descriptionAndTooltip(incompatibleTypesMessage)
      .create();
  }
  boolean hasFormalParameterTypes = expression.hasFormalParameterTypes();
  for (int i = 0; i < lambdaParameters.length; i++) {
    PsiParameter lambdaParameter = lambdaParameters[i];
    PsiType lambdaParameterType = lambdaParameter.getType();
    PsiType substitutedParamType = substitutor.substitute(methodParameters[i].getType());
    if (hasFormalParameterTypes &&!PsiTypesUtil.compareTypes(lambdaParameterType, substitutedParamType, true) ||
        !TypeConversionUtil.isAssignable(substitutedParamType, lambdaParameterType)) {
      final String expectedType = substitutedParamType != null ? substitutedParamType.getPresentableText() : null;
      final String actualType = lambdaParameterType.getPresentableText();
      return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
        .range(expression.getParameterList())
        .descriptionAndTooltip(incompatibleTypesMessage + "expected " + expectedType + " but found " + actualType)
        .create();
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:LambdaHighlightingUtil.java

示例11: appendCallArguments

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public void appendCallArguments(VariableData data, StringBuilder buffer) {
  if (myFoldingAvailable) {
    buffer.append(myFolding.getGeneratedCallArgument(data));
  } else {
    if (!TypeConversionUtil.isAssignable(data.type, data.variable.getType())) {
      buffer.append("(").append(data.type.getCanonicalText()).append(")");
    }
    buffer.append(data.variable.getName());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:InputVariables.java

示例12: weakerType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean weakerType(final PsiMethod psiMethod, final PsiType returnType, @NotNull final PsiType currentType) {
  final PsiTypeParameter[] typeParameters = psiMethod.getTypeParameters();
  final PsiSubstitutor substitutor =
      JavaPsiFacade.getInstance(psiMethod.getProject()).getResolveHelper().inferTypeArguments(typeParameters, new PsiType[]{returnType}, new PsiType[]{currentType}, PsiUtil.getLanguageLevel(psiMethod));

  return !TypeConversionUtil.isAssignable(currentType, substitutor.substitute(returnType));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:Match.java

示例13: areInferredTypesApplicable

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static boolean areInferredTypesApplicable(@NotNull PsiType[] types, PsiElement position) {
  final PsiMethodCallExpression methodCallExpression = PsiTreeUtil.getParentOfType(position, PsiMethodCallExpression.class);
  if (methodCallExpression != null) {
    if (PsiUtil.isLanguageLevel8OrHigher(methodCallExpression)) {
      final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(position, PsiNewExpression.class, false);
      if (newExpression != null) {
        PsiElement parent = newExpression;
        while (parent.getParent() instanceof PsiParenthesizedExpression) {
          parent = parent.getParent();
        }
        final int idx = ArrayUtil.find(methodCallExpression.getArgumentList().getExpressions(), parent);
        if (idx > -1) {
          final JavaResolveResult resolveResult = methodCallExpression.resolveMethodGenerics();
          final PsiMethod method = (PsiMethod)resolveResult.getElement();
          if (method != null) {
            final PsiParameter[] parameters = method.getParameterList().getParameters();
            if (idx < parameters.length) {
              final PsiType expectedType = resolveResult.getSubstitutor().substitute(parameters[idx].getType());
              final PsiClass aClass = PsiUtil.resolveClassInType(expectedType);
              if (aClass != null) {
                final PsiClassType inferredArg = JavaPsiFacade.getElementFactory(method.getProject()).createType(aClass, types);
                LOG.assertTrue(expectedType != null);
                return TypeConversionUtil.isAssignable(expectedType, inferredArg);
              }
            }
          }
        }
      }
    }
    return false;
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:JavaInheritorsGetter.java

示例14: visitInstanceOfExpression

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

示例15: addCollectConversion

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
static void addCollectConversion(PsiReferenceExpression ref, Collection<ExpectedTypeInfo> expectedTypes, Consumer<LookupElement> consumer) {
  final PsiExpression qualifier = ref.getQualifierExpression();
  PsiType component = qualifier == null ? null : PsiUtil.substituteTypeParameter(qualifier.getType(), JAVA_UTIL_STREAM_STREAM, 0, true);
  if (component == null) return;

  JavaPsiFacade facade = JavaPsiFacade.getInstance(ref.getProject());
  GlobalSearchScope scope = ref.getResolveScope();
  PsiClass list = facade.findClass(JAVA_UTIL_LIST, scope);
  PsiClass set = facade.findClass(JAVA_UTIL_SET, scope);
  if (facade.findClass(JAVA_UTIL_STREAM_COLLECTORS, scope) == null || list == null || set == null) return;

  boolean hasList = false;
  boolean hasSet = false;
  for (ExpectedTypeInfo info : expectedTypes) {
    PsiType type = info.getDefaultType();
    PsiClass expectedClass = PsiUtil.resolveClassInClassTypeOnly(type);
    PsiType expectedComponent = PsiUtil.extractIterableTypeParameter(type, true);
    if (expectedClass == null || expectedComponent == null || !TypeConversionUtil.isAssignable(expectedComponent, component)) continue;

    if (!hasList && InheritanceUtil.isInheritorOrSelf(list, expectedClass, true)) {
      hasList = true;
      consumer.consume(new MyLookupElement("toList", type));
    }

    if (!hasSet && InheritanceUtil.isInheritorOrSelf(set, expectedClass, true)) {
      hasSet = true;
      consumer.consume(new MyLookupElement("toSet", type));
    }

  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:CollectConversion.java


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