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


Java TypeConversionUtil.getClassSubstitutor方法代码示例

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


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

示例1: isUncheckedConversion

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public static boolean isUncheckedConversion(final PsiType t, final PsiType s) {
  if (t instanceof PsiClassType && !((PsiClassType)t).isRaw() && s instanceof PsiClassType) {
    final PsiClassType.ClassResolveResult tResult = ((PsiClassType)t).resolveGenerics();
    final PsiClassType.ClassResolveResult sResult = ((PsiClassType)s).resolveGenerics();
    final PsiClass tClass = tResult.getElement();
    final PsiClass sClass = sResult.getElement();
    if (tClass != null && sClass != null) {
      final PsiSubstitutor sSubstitutor = TypeConversionUtil.getClassSubstitutor(tClass, sClass, sResult.getSubstitutor());
      if (sSubstitutor != null) {
        if (PsiUtil.isRawSubstitutor(tClass, sSubstitutor)) {
          return true;
        }
      }
      else if (tClass instanceof InferenceVariable && ((PsiClassType)s).isRaw() && tClass.isInheritor(sClass, true)) {
        return true;
      }
    }
  } 
  else if (t instanceof PsiArrayType && t.getArrayDimensions() == s.getArrayDimensions()) {
    return isUncheckedConversion(t.getDeepComponentType(), s.getDeepComponentType());
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:TypeCompatibilityConstraint.java

示例2: getTypeFromMapAccess

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType getTypeFromMapAccess(@NotNull GrReferenceExpressionImpl ref) {
  //map access
  GrExpression qualifier = ref.getQualifierExpression();
  if (qualifier != null) {
    PsiType qType = qualifier.getNominalType();
    if (qType instanceof PsiClassType) {
      PsiClassType.ClassResolveResult qResult = ((PsiClassType)qType).resolveGenerics();
      PsiClass clazz = qResult.getElement();
      if (clazz != null) {
        PsiClass mapClass = JavaPsiFacade.getInstance(ref.getProject()).findClass(CommonClassNames.JAVA_UTIL_MAP, ref.getResolveScope());
        if (mapClass != null && mapClass.getTypeParameters().length == 2) {
          PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(mapClass, clazz, qResult.getSubstitutor());
          if (substitutor != null) {
            PsiType substituted = substitutor.substitute(mapClass.getTypeParameters()[1]);
            if (substituted != null) {
              return PsiImplUtil.normalizeWildcardTypeByPosition(substituted, ref);
            }
          }
        }
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GrReferenceExpressionImpl.java

示例3: getCollectionComponentType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType getCollectionComponentType(PsiType type, Project project) {
  if (!(type instanceof PsiClassType)) return null;
  PsiClassType classType = (PsiClassType) type;
  PsiClassType.ClassResolveResult result = classType.resolveGenerics();
  PsiClass clazz = result.getElement();
  if (clazz == null) return null;
  JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  @SuppressWarnings({"ConstantConditions"}) PsiClass collectionClass = facade.findClass("java.util.Collection", type.getResolveScope());
  if (collectionClass == null || collectionClass.getTypeParameters().length != 1) return null;
  PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(collectionClass, clazz, result.getSubstitutor());

  if (substitutor == null) return null;
  PsiType componentType = substitutor.substitute(collectionClass.getTypeParameters()[0]);
  return componentType instanceof PsiIntersectionType ? null : componentType;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:GroovyNameSuggestionUtil.java

示例4: processInexactReference

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
protected boolean processInexactReference(PsiReference ref, PsiElement refElement, PsiMethod method, Processor<PsiReference> consumer) {
  if (refElement instanceof PsiMethod) {
    PsiMethod refMethod = (PsiMethod)refElement;
    PsiClass refMethodClass = refMethod.getContainingClass();
    if (refMethodClass == null) return true;

    if (!refMethod.hasModifierProperty(PsiModifier.STATIC)) {
      PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(myContainingClass, refMethodClass, PsiSubstitutor.EMPTY);
      if (substitutor != null) {
        MethodSignature superSignature = method.getSignature(substitutor);
        MethodSignature refSignature = refMethod.getSignature(PsiSubstitutor.EMPTY);

        if (MethodSignatureUtil.isSubsignature(superSignature, refSignature)) {
          if (!consumer.process(ref)) return false;
        }
      }
    }

    if (!myStrictSignatureSearch) {
      PsiManager manager = method.getManager();
      if (manager.areElementsEquivalent(refMethodClass, myContainingClass)) {
        if (!consumer.process(ref)) return false;
      }
    }
  }

  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:MethodTextOccurrenceProcessor.java

示例5: advancedResolveImpl

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private JavaResolveResult advancedResolveImpl(@NotNull PsiFile containingFile) {
  PsiTypeElement[] typeElements = myRefParameterList == null ? PsiTypeElement.EMPTY_ARRAY : myRefParameterList.getTypeParameterElements();
  PsiElement resolve = resolveElement(containingFile);
  if (resolve == null) return null;
  if (resolve instanceof PsiClass) {
    Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<PsiTypeParameter, PsiType>();
    int index = 0;
    for (PsiTypeParameter parameter : PsiUtil.typeParametersIterable((PsiClass)resolve)) {
      if (index >= typeElements.length) {
        PsiTypeParameterListOwner parameterOwner = parameter.getOwner();
        if (parameterOwner == resolve) {
          substitutionMap.put(parameter, null);
        }
        else if (parameterOwner instanceof PsiClass) {
          PsiElement containingClass = myParent;
          while ((containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class, true)) != null) {
            PsiSubstitutor superClassSubstitutor =
              TypeConversionUtil.getClassSubstitutor((PsiClass)parameterOwner, (PsiClass)containingClass, PsiSubstitutor.EMPTY);
            if (superClassSubstitutor != null) {
              substitutionMap.put(parameter, superClassSubstitutor.substitute(parameter));
              break;
            }
          }
        }
      }
      else {
        substitutionMap.put(parameter, typeElements[index].getType());
      }
      index++;
    }
    collectOuterClassTypeArgs((PsiClass)resolve, myCanonicalText, substitutionMap);
    return new CandidateInfo(resolve, PsiSubstitutorImpl.createSubstitutor(substitutionMap));
  }
  else {
    return new CandidateInfo(resolve, PsiSubstitutor.EMPTY);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:ClsJavaCodeReferenceElementImpl.java

示例6: getInheritorSubstitutorForNewExpression

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiSubstitutor getInheritorSubstitutorForNewExpression(final PsiClass baseClass, final PsiClass inheritor,
                                                                     final PsiSubstitutor baseSubstitutor, final PsiElement context) {
  final Project project = baseClass.getProject();
  JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
  final PsiResolveHelper resolveHelper = facade.getResolveHelper();
  PsiSubstitutor superSubstitutor = TypeConversionUtil.getClassSubstitutor(baseClass, inheritor, PsiSubstitutor.EMPTY);
  if (superSubstitutor == null) return null;
  PsiSubstitutor inheritorSubstitutor = PsiSubstitutor.EMPTY;
  for (PsiTypeParameter inheritorParameter : PsiUtil.typeParametersIterable(inheritor)) {
    for (PsiTypeParameter baseParameter : PsiUtil.typeParametersIterable(baseClass)) {
      final PsiType substituted = superSubstitutor.substitute(baseParameter);
      PsiType arg = baseSubstitutor.substitute(baseParameter);
      if (arg instanceof PsiWildcardType) arg = ((PsiWildcardType)arg).getBound();
      PsiType substitution =
        resolveHelper.getSubstitutionForTypeParameter(inheritorParameter, substituted, arg, true, PsiUtil.getLanguageLevel(context));
      if (PsiType.NULL.equals(substitution)) continue;
      if (substitution == null) {
        return facade.getElementFactory().createRawSubstitutor(inheritor);
      }
      inheritorSubstitutor = inheritorSubstitutor.put(inheritorParameter, substitution);
      break;
    }
  }

  return inheritorSubstitutor;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:ChangeNewOperatorTypeFix.java

示例7: getTypeParameterValue

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType getTypeParameterValue(@NotNull PsiClass rootClass, @NotNull PsiClass derivedClass, PsiSubstitutor substitutor, int index) {
  final PsiTypeParameter[] typeParameters = rootClass.getTypeParameters();
  if (typeParameters.length > index) {
    final PsiSubstitutor psiSubstitutor = TypeConversionUtil.getClassSubstitutor(rootClass, derivedClass, substitutor);
    if (psiSubstitutor != null) {
      PsiType type = psiSubstitutor.substitute(typeParameters[index]);
      if (type != null) return type;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:ExpectedTypesProvider.java

示例8: findVariable

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private Pair<PsiVariable,PsiType> findVariable(final PsiElement element) {
  PsiVariable variable = null;
  PsiElement elementParent = element.getParent();
  if (element instanceof PsiIdentifier) {
    if (elementParent instanceof PsiVariable) {
      variable = (PsiVariable)elementParent;
    }
  }
  else if (element instanceof PsiJavaToken) {
    final PsiJavaToken token = (PsiJavaToken)element;
    if (token.getTokenType() != JavaTokenType.EQ) return null;
    if (elementParent instanceof PsiVariable) {
      variable = (PsiVariable)elementParent;
    }
  }
  if (variable == null) return null;
  variableName = variable.getName();
  final PsiExpression initializer = variable.getInitializer();
  if (initializer == null) return null;
  final PsiType variableType = variable.getType();
  final PsiType initializerType = initializer.getType();
  if (!(variableType instanceof PsiClassType)) return null;
  final PsiClassType variableClassType = (PsiClassType) variableType;
  if (!variableClassType.isRaw()) return null;
  if (!(initializerType instanceof PsiClassType)) return null;
  final PsiClassType initializerClassType = (PsiClassType) initializerType;
  if (initializerClassType.isRaw()) return null;
  final PsiClassType.ClassResolveResult variableResolveResult = variableClassType.resolveGenerics();
  final PsiClassType.ClassResolveResult initializerResolveResult = initializerClassType.resolveGenerics();
  if (initializerResolveResult.getElement() == null) return null;
  PsiClass variableResolved = variableResolveResult.getElement();
  PsiSubstitutor targetSubstitutor = TypeConversionUtil.getClassSubstitutor(variableResolved, initializerResolveResult.getElement(), initializerResolveResult.getSubstitutor());
  if (targetSubstitutor == null) return null;
  PsiType type = JavaPsiFacade.getInstance(variable.getProject()).getElementFactory().createType(variableResolved, targetSubstitutor);
  if (variableType.equals(type)) return null;
  newTypeName = type.getCanonicalText();
  return Pair.create(variable, type);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:MakeTypeGenericAction.java

示例9: getClassImplementations

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private PsiClass[] getClassImplementations(final PsiClass psiClass) {
  ArrayList<PsiClass> list = new ArrayList<PsiClass>();
  for (PsiClass inheritor : ClassInheritorsSearch.search(psiClass, true)) {
    if (!inheritor.isInterface()) {
      final PsiSubstitutor classSubstitutor = TypeConversionUtil.getClassSubstitutor(psiClass, inheritor, PsiSubstitutor.EMPTY);
      PsiMethod method = classSubstitutor != null ? MethodSignatureUtil.findMethodBySignature(inheritor, myMethod.getSignature(classSubstitutor), true)
                                                  : inheritor.findMethodBySignature(myMethod, true);;
      if (method == null || !psiClass.equals(method.getContainingClass())) continue;
      list.add(inheritor);
    }
  }

  return list.toArray(new PsiClass[list.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:ImplementAbstractMethodHandler.java

示例10: fillTypeRange

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private void fillTypeRange(final PsiType lowerBound,
                           final PsiType upperBound,
                           final Set<PsiType> holder) {
  if (lowerBound instanceof PsiClassType && upperBound instanceof PsiClassType) {
    final PsiClassType.ClassResolveResult resultLower = ((PsiClassType)lowerBound).resolveGenerics();
    final PsiClassType.ClassResolveResult resultUpper = ((PsiClassType)upperBound).resolveGenerics();

    final PsiClass lowerClass = resultLower.getElement();
    final PsiClass upperClass = resultUpper.getElement();

    if (lowerClass != null && upperClass != null && !lowerClass.equals(upperClass)) {
      final PsiSubstitutor upperSubst = resultUpper.getSubstitutor();
      final PsiClass[] parents = upperClass.getSupers();
      final PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory();

      for (final PsiClass parent : parents) {
        final PsiSubstitutor superSubstitutor = TypeConversionUtil.getClassSubstitutor(parent, upperClass, upperSubst);
        if (superSubstitutor != null) {
          final PsiClassType type = factory.createType(parent, superSubstitutor);
          holder.add(type);
          fillTypeRange(lowerBound, type, holder);
        }
      }
    }
  }
  else if (lowerBound instanceof PsiArrayType && upperBound instanceof PsiArrayType) {
    fillTypeRange(((PsiArrayType)lowerBound).getComponentType(), ((PsiArrayType)upperBound).getComponentType(), holder);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:ResolverTree.java

示例11: addForEachConstraint

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private void addForEachConstraint(final ReductionSystem system, final PsiForeachStatement statement) {
  final PsiType paramType = getType(statement.getIterationParameter());
  final PsiExpression value = statement.getIteratedValue();
  if (value != null) {
    final PsiType type = evaluateType(value, system);
    if (type instanceof PsiClassType) {
      final PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)type).resolveGenerics();
      final PsiClass clazz = resolveResult.getElement();
      if (clazz != null) {
        final PsiClass iterableClass =
          JavaPsiFacade.getInstance(clazz.getProject()).findClass("java.lang.Iterable", clazz.getResolveScope());
        if (iterableClass != null) {
          final PsiTypeParameter[] typeParameters = iterableClass.getTypeParameters();
          if (typeParameters.length == 1) {
            final PsiSubstitutor substitutor =
              TypeConversionUtil.getClassSubstitutor(iterableClass, clazz, resolveResult.getSubstitutor());
            if (substitutor != null) {
              final PsiType componentType = substitutor.substitute(typeParameters[0]);
              system.addSubtypeConstraint(componentType, paramType);
            }
          }
        }
      }
    }
    else if (type instanceof PsiArrayType) {
      system.addSubtypeConstraint(((PsiArrayType)type).getComponentType(), paramType);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:SystemBuilder.java

示例12: getElementType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
public static PsiType getElementType(final PsiElement resolved) {
  if (resolved instanceof PsiVariable) {
    return ((PsiVariable)resolved).getType();
  }
  else {
    if (resolved instanceof PsiMethod) {
      return (((PsiMethod)resolved).getReturnType());
    }
    else if (resolved instanceof PsiExpression){
      return (((PsiExpression)resolved).getType());
    } else if (resolved instanceof PsiReferenceParameterList) {
      PsiElement parent = resolved.getParent();
      while (parent != null) {
        LOG.assertTrue(parent instanceof PsiJavaCodeReferenceElement);
        final PsiClass psiClass = (PsiClass)((PsiJavaCodeReferenceElement)parent).resolve();
        final PsiClass containingClass = PsiTreeUtil.getParentOfType(parent, PsiClass.class);
        if (psiClass != null && containingClass != null) {
         final PsiSubstitutor classSubstitutor = TypeConversionUtil.getClassSubstitutor(psiClass, containingClass, PsiSubstitutor.EMPTY);
         if (classSubstitutor != null) {
           return JavaPsiFacade.getElementFactory(parent.getProject()).createType(psiClass, classSubstitutor);
         }
        }
        parent = PsiTreeUtil.getParentOfType(parent, PsiJavaCodeReferenceElement.class, true);
      }
    } else if (resolved instanceof PsiClass) {
      return JavaPsiFacade.getElementFactory(resolved.getProject()).createType((PsiClass)resolved, PsiSubstitutor.EMPTY);
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:TypeMigrationLabeler.java

示例13: getContentType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType getContentType(PsiType type, String containerClassName, PsiElement context) {
  if (!(type instanceof PsiClassType)) {
    return null;
  }
  final PsiClassType classType = (PsiClassType)type;
  final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
  final PsiClass aClass = resolveResult.getElement();
  final Project project = context.getProject();

  if (aClass == null) {
    return null;
  }
  final PsiClass iterableClass = JavaPsiFacade.getInstance(project).findClass(containerClassName, aClass.getResolveScope());
  if (iterableClass == null) {
    return null;
  }
  final PsiSubstitutor substitutor1 = resolveResult.getSubstitutor();
  final PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(iterableClass, aClass, substitutor1);
  if (substitutor == null) {
    return null;
  }
  PsiType parameterType = substitutor.substitute(iterableClass.getTypeParameters()[0]);
  if (parameterType instanceof PsiCapturedWildcardType) {
    parameterType = ((PsiCapturedWildcardType)parameterType).getWildcard();
  }
  if (parameterType != null) {
    if (parameterType instanceof PsiWildcardType) {
      if (((PsiWildcardType)parameterType).isExtends()) {
        return ((PsiWildcardType)parameterType).getBound();
      }
      else {
        return null;
      }
    }
    return parameterType;
  }
  return TypeUtils.getObjectType(context);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:WhileCanBeForeachInspection.java

示例14: calculateResult

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
  if (params.length != 1) return null;
  final Result result = params[0].calculateResult(context);
  if (result == null) return null;

  Project project = context.getProject();

  PsiExpression expr = MacroUtil.resultToPsiExpression(result, context);
  if (expr == null) return null;
  PsiType type = expr.getType();


  if (type instanceof PsiArrayType) {
    return new PsiTypeResult(((PsiArrayType)type).getComponentType(), project);
  }

  if (type instanceof PsiClassType) {
    PsiClassType.ClassResolveResult resolveResult = ((PsiClassType)type).resolveGenerics();
    PsiClass aClass = resolveResult.getElement();

    if (aClass != null) {
      PsiClass iterableClass = JavaPsiFacade.getInstance(project).findClass("java.lang.Iterable", aClass.getResolveScope());
      if (iterableClass != null) {
        PsiSubstitutor substitutor = TypeConversionUtil.getClassSubstitutor(iterableClass, aClass, resolveResult.getSubstitutor());
        if (substitutor != null) {
          PsiType parameterType = substitutor.substitute(iterableClass.getTypeParameters()[0]);
          if (parameterType instanceof PsiCapturedWildcardType) {
            return new PsiTypeResult(((PsiCapturedWildcardType)parameterType).getUpperBound(), project);
          }
          if (parameterType != null) {
            if (parameterType instanceof PsiWildcardType) {
              if (((PsiWildcardType)parameterType).isExtends()) {
                return new PsiTypeResult(((PsiWildcardType)parameterType).getBound(), project);
              }
              else return null;
            }
            return new PsiTypeResult(parameterType, project);
          }
        }
      }
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:IterableComponentTypeMacro.java

示例15: SafeDeleteExtendsClassUsageInfo

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public SafeDeleteExtendsClassUsageInfo(final PsiJavaCodeReferenceElement reference, PsiClass refClass, PsiClass extendingClass) {
  super(reference, refClass, true);
  myExtendingClass = extendingClass;
  mySubstitutor = TypeConversionUtil.getClassSubstitutor(refClass, myExtendingClass, PsiSubstitutor.EMPTY);
  LOG.assertTrue(mySubstitutor != null);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:SafeDeleteExtendsClassUsageInfo.java


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