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


Java ExpectedTypesProvider.createInfo方法代码示例

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


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

示例1: equalsExpectedTypes

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
private static ExpectedTypeInfo[] equalsExpectedTypes(PsiMethodCallExpression methodCall) {
  final PsiType[] argumentTypes = methodCall.getArgumentList().getExpressionTypes();
  if (argumentTypes.length != 1) {
    return ExpectedTypeInfo.EMPTY_ARRAY;
  }
  PsiType type = argumentTypes[0];
  if (type instanceof PsiPrimitiveType) {
    type = ((PsiPrimitiveType)type).getBoxedType(methodCall);
  }
  if (type == null) return ExpectedTypeInfo.EMPTY_ARRAY;
  return new ExpectedTypeInfo[]{ExpectedTypesProvider.createInfo(type, ExpectedTypeInfo.TYPE_STRICTLY, type, TailType.NONE)};
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:13,代码来源:CreateFromUsageUtils.java

示例2: setupMethodParameters

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
public static void setupMethodParameters(final PsiMethod method, final TemplateBuilder builder, final PsiElement contextElement,
                                         final PsiSubstitutor substitutor, final List<Pair<PsiExpression, PsiType>> arguments)
  throws IncorrectOperationException {
  PsiManager psiManager = method.getManager();
  JVMElementFactory factory = JVMElementFactories.getFactory(method.getLanguage(), method.getProject());

  PsiParameterList parameterList = method.getParameterList();

  GlobalSearchScope resolveScope = method.getResolveScope();

  GuessTypeParameters guesser = new GuessTypeParameters(JavaPsiFacade.getElementFactory(method.getProject()));

  final PsiClass containingClass = method.getContainingClass();
  final boolean isInterface = containingClass != null && containingClass.isInterface();
  for (int i = 0; i < arguments.size(); i++) {
    Pair<PsiExpression, PsiType> arg = arguments.get(i);
    PsiExpression exp = arg.first;

    PsiType argType = exp == null ? arg.second : exp.getType();
    SuggestedNameInfo suggestedInfo = JavaCodeStyleManager.getInstance(psiManager.getProject()).suggestVariableName(
      VariableKind.PARAMETER, null, exp, argType);
    @NonNls String[] names = suggestedInfo.names; //TODO: callback about used name

    if (names.length == 0) {
      names = new String[]{"p" + i};
    }

    if (argType == null || PsiType.NULL.equals(argType) ||
        argType instanceof PsiLambdaExpressionType ||
        argType instanceof PsiLambdaParameterType ||
        argType instanceof PsiMethodReferenceType) {
      argType = PsiType.getJavaLangObject(psiManager, resolveScope);
    } else if (argType instanceof PsiDisjunctionType) {
      argType = ((PsiDisjunctionType)argType).getLeastUpperBound();
    } else if (argType instanceof PsiWildcardType) {
      argType = ((PsiWildcardType)argType).isBounded() ? ((PsiWildcardType)argType).getBound() : PsiType.getJavaLangObject(psiManager, resolveScope);
    }
    PsiParameter parameter;
    if (parameterList.getParametersCount() <= i) {
      parameter = factory.createParameter(names[0], argType);
      if (isInterface) {
        PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, false);
      }
      parameter = (PsiParameter) parameterList.add(parameter);
    } else {
      parameter = parameterList.getParameters()[i];
    }

    ExpectedTypeInfo info = ExpectedTypesProvider.createInfo(argType, ExpectedTypeInfo.TYPE_OR_SUPERTYPE, argType, TailType.NONE);

    PsiElement context = PsiTreeUtil.getParentOfType(contextElement, PsiClass.class, PsiMethod.class);
    guesser.setupTypeElement(parameter.getTypeElement(), new ExpectedTypeInfo[]{info},
                             substitutor, builder, context, containingClass);

    Expression expression = new ParameterNameExpression(names);
    builder.replaceElement(parameter.getNameIdentifier(), expression);
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:59,代码来源:CreateFromUsageUtils.java

示例3: guessExpectedTypes

import com.intellij.codeInsight.ExpectedTypesProvider; //导入方法依赖的package包/类
public static ExpectedTypeInfo[] guessExpectedTypes (PsiExpression expression, boolean allowVoidType) {
      PsiManager manager = expression.getManager();
  GlobalSearchScope resolveScope = expression.getResolveScope();

  List<ExpectedTypeInfo[]> typesList = new ArrayList<ExpectedTypeInfo[]>();
  List<String> expectedMethodNames = new ArrayList<String>();
  List<String> expectedFieldNames  = new ArrayList<String>();

  getExpectedInformation(expression, typesList, expectedMethodNames, expectedFieldNames);


  if (typesList.size() == 1 && (!expectedFieldNames.isEmpty() || !expectedMethodNames.isEmpty())) {
    ExpectedTypeInfo[] infos = typesList.get(0);
    if (infos.length == 1 && infos[0].getKind() == ExpectedTypeInfo.TYPE_OR_SUBTYPE &&
        infos[0].getType().equals(PsiType.getJavaLangObject(manager, resolveScope))) {
      typesList.clear();
    }
  }

  if (typesList.isEmpty()) {
    final JavaPsiFacade facade = JavaPsiFacade.getInstance(expression.getProject());
    final PsiShortNamesCache cache = PsiShortNamesCache.getInstance(expression.getProject());
    PsiElementFactory factory = facade.getElementFactory();
    for (String fieldName : expectedFieldNames) {
      PsiField[] fields = cache.getFieldsByName(fieldName, resolveScope);
      addMemberInfo(fields, expression, typesList, factory);
    }

    for (String methodName : expectedMethodNames) {
      PsiMethod[] methods = cache.getMethodsByName(methodName, resolveScope);
      addMemberInfo(methods, expression, typesList, factory);
    }
  }

  ExpectedTypeInfo[] expectedTypes = ExpectedTypeUtil.intersect(typesList);
  if (expectedTypes.length == 0 && !typesList.isEmpty()) {
    List<ExpectedTypeInfo> union = new ArrayList<ExpectedTypeInfo>();
    for (ExpectedTypeInfo[] aTypesList : typesList) {
      ContainerUtil.addAll(union, (ExpectedTypeInfo[])aTypesList);
    }
    expectedTypes = union.toArray(new ExpectedTypeInfo[union.size()]);
  }

  if (expectedTypes.length == 0) {
    PsiType t = allowVoidType ? PsiType.VOID : PsiType.getJavaLangObject(manager, resolveScope);
    expectedTypes = new ExpectedTypeInfo[] {ExpectedTypesProvider.createInfo(t, ExpectedTypeInfo.TYPE_OR_SUBTYPE, t, TailType.NONE)};
  }

  return expectedTypes;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:51,代码来源:CreateFromUsageUtils.java


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