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


Java PsiUtil.substituteTypeParameter方法代码示例

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


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

示例1: getEntryForMap

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType getEntryForMap(@Nullable PsiType map, @NotNull final Project project, @NotNull final GlobalSearchScope scope) {
  PsiType key = PsiUtil.substituteTypeParameter(map, JAVA_UTIL_MAP, 0, true);
  PsiType value = PsiUtil.substituteTypeParameter(map, JAVA_UTIL_MAP, 1, true);

  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
  final PsiClass entryClass = JavaPsiFacade.getInstance(project).findClass(JAVA_UTIL_MAP_ENTRY, scope);
  if (entryClass == null) {
    if (key != null && key != PsiType.NULL && value != null && value != PsiType.NULL) {
      final String text = String.format("%s<%s,%s>", JAVA_UTIL_MAP_ENTRY, key.getCanonicalText(), value.getCanonicalText());
      return factory.createTypeFromText(text, null);
    }
    else {
      return factory.createTypeByFQClassName(JAVA_UTIL_MAP_ENTRY, scope);
    }
  }
  else {
    return factory.createType(entryClass, key, value);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ClosureParameterEnhancer.java

示例2: addCollectConversion

import com.intellij.psi.util.PsiUtil; //导入方法依赖的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

示例3: addCompletions

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static void addCompletions(@NotNull final JavaSmartCompletionParameters parameters,
                                  @NotNull Consumer<LookupElement> result, final PrefixMatcher matcher) {
  PsiType expectedType = parameters.getDefaultType();
  if (!InheritanceUtil.isInheritor(expectedType, CommonClassNames.JAVA_LANG_CLASS)) {
    expectedType = parameters.getExpectedType();
    if (!InheritanceUtil.isInheritor(expectedType, CommonClassNames.JAVA_LANG_CLASS)) {
      return;
    }
  }

  PsiType classParameter = PsiUtil.substituteTypeParameter(expectedType, CommonClassNames.JAVA_LANG_CLASS, 0, false);

  boolean addInheritors = false;
  PsiElement position = parameters.getPosition();
  if (classParameter instanceof PsiWildcardType) {
    final PsiWildcardType wildcardType = (PsiWildcardType)classParameter;
    classParameter = wildcardType.isSuper() ? wildcardType.getSuperBound() : wildcardType.getExtendsBound();
    addInheritors = wildcardType.isExtends() && classParameter instanceof PsiClassType;
  } else if (!matcher.getPrefix().isEmpty()) {
    addInheritors = true;
    classParameter = PsiType.getJavaLangObject(position.getManager(), position.getResolveScope());
  }
  if (classParameter != null) {
    PsiFile file = position.getContainingFile();
    addClassLiteralLookupElement(classParameter, result, file);
    if (addInheritors) {
      addInheritorClassLiterals(file, classParameter, result, matcher);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:ClassLiteralGetter.java

示例4: resolveExtensionPointClass

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static PsiClass resolveExtensionPointClass(PsiField psiField) {
  final PsiType typeParameter = PsiUtil.substituteTypeParameter(psiField.getType(),
                                                                ExtensionPointName.class.getName(),
                                                                0, false);
  return PsiUtil.resolveClassInClassTypeOnly(typeParameter);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:ExtensionPointDeclarationRelatedItemLineMarkerProvider.java

示例5: visitBinaryExpression

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void visitBinaryExpression(GrBinaryExpression expression) {
  super.visitBinaryExpression(expression);

  if (expression.getOperationTokenType() != GroovyTokenTypes.kIN) return;

  GrExpression leftOperand = expression.getLeftOperand();
  GrExpression rightOperand = expression.getRightOperand();
  if (rightOperand == null) return;

  PsiType ltype = leftOperand.getType();
  PsiType rtype = rightOperand.getType();
  if (ltype == null || rtype == null) return;

  PsiType component;

  if (rtype instanceof PsiArrayType) {
    component = ((PsiArrayType)rtype).getComponentType();
  }
  else if (InheritanceUtil.isInheritor(rtype, CommonClassNames.JAVA_UTIL_COLLECTION)) {
    component = PsiUtil.substituteTypeParameter(rtype, CommonClassNames.JAVA_UTIL_COLLECTION, 0, false);
  }
  else {
    checkSimpleClasses(ltype, rtype, expression);
    return;
  }

  if (component == null) return;
  
  if (TypesUtil.isAssignableWithoutConversions(component, ltype, expression)) return;

  registerError(expression, ltype, rtype);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:GroovyInArgumentCheckInspection.java

示例6: inferExpectedSignatures

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@NotNull
@Override
public List<PsiType[]> inferExpectedSignatures(@NotNull PsiMethod method,
                                               @NotNull PsiSubstitutor substitutor,
                                               @NotNull String[] options) {
  int argNum = extractArgNum(options);
  boolean index = extractIndex(options);

  PsiParameter[] parameters = method.getParameterList().getParameters();

  if (argNum >= parameters.length) return ContainerUtil.emptyList();

  PsiParameter parameter = parameters[argNum];
  PsiType type = parameter.getType();
  PsiType substituted = substitutor.substitute(type);

  if (!InheritanceUtil.isInheritor(substituted, CommonClassNames.JAVA_UTIL_MAP)) return ContainerUtil.emptyList();

  PsiType key = PsiUtil.substituteTypeParameter(substituted, CommonClassNames.JAVA_UTIL_MAP, 0, true);
  PsiType value = PsiUtil.substituteTypeParameter(substituted, CommonClassNames.JAVA_UTIL_MAP, 1, true);

  PsiClass mapEntry = JavaPsiFacade.getInstance(method.getProject()).findClass(CommonClassNames.JAVA_UTIL_MAP_ENTRY, method.getResolveScope());
  if (mapEntry == null) return ContainerUtil.emptyList();

  PsiClassType mapEntryType = JavaPsiFacade.getElementFactory(method.getProject()).createType(mapEntry, key, value);

  PsiType[] keyValueSignature = index ? new PsiType[]{key, value, PsiType.INT} : new PsiType[]{key, value};
  PsiType[] mapEntrySignature = index ? new PsiType[]{mapEntryType, PsiType.INT} : new PsiType[]{mapEntryType};

  return ContainerUtil.newArrayList(keyValueSignature, mapEntrySignature);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:MapEntryOrKeyValueHintProcessor.java

示例7: findTypeFromIteratorMethod

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType findTypeFromIteratorMethod(@Nullable PsiType type, PsiElement context) {
  if (!(type instanceof PsiClassType)) return null;

  final GroovyResolveResult[] candidates = ResolveUtil.getMethodCandidates(type, "iterator", context, PsiType.EMPTY_ARRAY);
  final GroovyResolveResult candidate = PsiImplUtil.extractUniqueResult(candidates);
  final PsiElement element = candidate.getElement();
  if (!(element instanceof PsiMethod)) return null;

  final PsiType returnType = org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil.getSmartReturnType((PsiMethod)element);
  final PsiType iteratorType = candidate.getSubstitutor().substitute(returnType);

  return PsiUtil.substituteTypeParameter(iteratorType, JAVA_UTIL_ITERATOR, 0, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:ClosureParameterEnhancer.java

示例8: processTypesFromTuple

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static boolean processTypesFromTuple(@NotNull GrTupleType type,
                                             @NotNull PsiScopeProcessor processor,
                                             @NotNull ResolveState state,
                                             @NotNull GrClosableBlock place) {
  for (PsiType component : type.getComponentTypes()) {
    PsiType clazz = PsiUtil.substituteTypeParameter(component, CommonClassNames.JAVA_LANG_CLASS, 0, false);
    PsiClass aClass = PsiTypesUtil.getPsiClass(clazz);
    if (aClass != null) {
      if (!processCategoryMethods(place, processor, state, aClass)) return false;
    }
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:GdkMethodUtil.java

示例9: genNewMapBy

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static PsiType genNewMapBy(PsiType genericOwner, PsiManager manager) {
  PsiClass map = JavaPsiFacade.getInstance(manager.getProject()).findClass(CommonClassNames.JAVA_UTIL_MAP, genericOwner.getResolveScope());
  PsiElementFactory factory = JavaPsiFacade.getElementFactory(manager.getProject());
  if (map == null) return factory.createTypeFromText(CommonClassNames.JAVA_UTIL_MAP, null);

  final PsiType key = PsiUtil.substituteTypeParameter(genericOwner, CommonClassNames.JAVA_UTIL_MAP, 0, false);
  final PsiType value = PsiUtil.substituteTypeParameter(genericOwner, CommonClassNames.JAVA_UTIL_MAP, 1, false);
  return factory.createType(map, key, value);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:TypesUtil.java

示例10: calculateReturnType

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
@Override
protected PsiType calculateReturnType(@NotNull GrMethodCall callExpression, @NotNull PsiMethod resolvedMethod) {
  if (!"withTraits".equals(resolvedMethod.getName())) return null;

  if (resolvedMethod instanceof GrGdkMethod) {
    resolvedMethod = ((GrGdkMethod)resolvedMethod).getStaticMethod();
  }

  GrExpression invokedExpression = callExpression.getInvokedExpression();
  if (!(invokedExpression instanceof GrReferenceExpression)) return null;
  GrExpression originalObject = ((GrReferenceExpression)invokedExpression).getQualifierExpression();
  if (originalObject == null) return null;

  PsiType invokedType = originalObject.getType();
  if (!(invokedType instanceof PsiClassType)) return null;

  PsiClass containingClass = resolvedMethod.getContainingClass();
  if (containingClass == null || !GroovyCommonClassNames.DEFAULT_GROOVY_METHODS.equals(containingClass.getQualifiedName())) return null;

  List<PsiClassType> traits = ContainerUtil.newArrayList();
  GrExpression[] args = callExpression.getArgumentList().getExpressionArguments();
  for (GrExpression arg : args) {
    PsiType type = arg.getType();
    PsiType classItem = PsiUtil.substituteTypeParameter(type, CommonClassNames.JAVA_LANG_CLASS, 0, false);
    PsiClass psiClass = PsiTypesUtil.getPsiClass(classItem);
    if (GrTraitUtil.isTrait(psiClass)) {
      traits.add((PsiClassType)classItem);
    }
  }

  return GrTraitType.createTraitClassType(callExpression, (PsiClassType)invokedType, traits, callExpression.getResolveScope());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:34,代码来源:GrWithTraitTypeCalculator.java

示例11: getStreamComponentType

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static PsiType getStreamComponentType(PsiType expectedType) {
  return PsiUtil.substituteTypeParameter(expectedType, CommonClassNames.JAVA_UTIL_STREAM_BASE_STREAM, 0, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:ReferenceExpressionCompletionContributor.java

示例12: extractComponentType

import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType extractComponentType(PsiType type) {
  if (type instanceof PsiArrayType) return ((PsiArrayType)type).getComponentType();
  return PsiUtil.substituteTypeParameter(type, CommonClassNames.JAVA_UTIL_COLLECTION, 0, false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:GrContainerTypeConverter.java


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