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


Java TypeConversionUtil.getSuperClassSubstitutor方法代码示例

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


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

示例1: getExpectedArgumentsTypesForNewExpression

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private void getExpectedArgumentsTypesForNewExpression(@NotNull final PsiNewExpression newExpr,
                                                       @NotNull final PsiExpressionList list) {
  PsiType newType = newExpr.getType();
  if (newType instanceof PsiClassType) {
    JavaResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(newType);
    PsiClass newClass = (PsiClass)resolveResult.getElement();
    final PsiSubstitutor substitutor;
    if (newClass instanceof PsiAnonymousClass) {
      final PsiAnonymousClass anonymous = (PsiAnonymousClass)newClass;
      newClass = anonymous.getBaseClassType().resolve();
      if (newClass == null) return;

      substitutor = TypeConversionUtil.getSuperClassSubstitutor(newClass, anonymous, PsiSubstitutor.EMPTY);
    } else if (newClass != null) {
      substitutor = resolveResult.getSubstitutor();
    }
    else {
      return;
    }
    getExpectedTypesForConstructorCall(newClass, list, substitutor);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ExpectedTypesProvider.java

示例2: chooseAndImplement

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
protected static void chooseAndImplement(PsiClass psiClass, Project project, @NotNull PsiClass targetClass, Editor editor) {
  boolean hasNonTrivialConstructor = false;
  final PsiMethod[] constructors = psiClass.getConstructors();
  for (PsiMethod constructor : constructors) {
    if (constructor.getParameterList().getParametersCount() > 0) {
      hasNonTrivialConstructor = true;
      break;
    }
  }
  if (hasNonTrivialConstructor) {
    final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(psiClass, targetClass, PsiSubstitutor.EMPTY);
    final List<PsiMethodMember> baseConstructors = new ArrayList<PsiMethodMember>();
    for (PsiMethod baseConstr : constructors) {
      if (PsiUtil.isAccessible(project, baseConstr, targetClass, targetClass)) {
        baseConstructors.add(new PsiMethodMember(baseConstr, substitutor));
      }
    }
    final int offset = editor.getCaretModel().getOffset();
    CreateConstructorMatchingSuperFix.chooseConstructor2Delegate(project, editor,
                                                                 substitutor,
                                                                 baseConstructors, constructors, targetClass);
    editor.getCaretModel().moveToOffset(offset);
  }

  OverrideImplementUtil.chooseAndImplementMethods(project, editor, targetClass);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:CreateSubclassAction.java

示例3: findSubmemberHidesMemberCollisions

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static void findSubmemberHidesMemberCollisions(final PsiMethod method, final String newName, final List<UsageInfo> result) {
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) return;
  if (method.hasModifierProperty(PsiModifier.PRIVATE)) return;
  Collection<PsiClass> inheritors = ClassInheritorsSearch.search(containingClass, true).findAll();

  MethodSignature oldSignature = method.getSignature(PsiSubstitutor.EMPTY);
  MethodSignature newSignature = MethodSignatureUtil.createMethodSignature(newName, oldSignature.getParameterTypes(),
                                                                           oldSignature.getTypeParameters(),
                                                                           oldSignature.getSubstitutor(),
                                                                           method.isConstructor());
  for (PsiClass inheritor : inheritors) {
    PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(containingClass, inheritor, PsiSubstitutor.EMPTY);
    final PsiMethod[] methodsByName = inheritor.findMethodsByName(newName, false);
    for (PsiMethod conflictingMethod : methodsByName) {
      if (newSignature.equals(conflictingMethod.getSignature(superSubstitutor))) {
        result.add(new SubmemberHidesMemberUsageInfo(conflictingMethod, method));
        break;
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:RenameJavaMethodProcessor.java

示例4: isMemberEnabled

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public boolean isMemberEnabled(MemberInfo member) {
  final PsiClass currentSuperClass = getSuperClass();
  if(currentSuperClass == null) return true;
  if (myMemberInfoStorage.getDuplicatedMemberInfos(currentSuperClass).contains(member)) return false;
  if (myMemberInfoStorage.getExtending(currentSuperClass).contains(member.getMember())) return false;
  final boolean isInterface = currentSuperClass.isInterface();
  if (!isInterface) return true;

  PsiElement element = member.getMember();
  if (element instanceof PsiClass && ((PsiClass) element).isInterface()) return true;
  if (element instanceof PsiField) {
    return ((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  if (element instanceof PsiMethod) {
    final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(currentSuperClass, myClass, PsiSubstitutor.EMPTY);
    final MethodSignature signature = ((PsiMethod) element).getSignature(superSubstitutor);
    final PsiMethod superClassMethod = MethodSignatureUtil.findMethodBySignature(currentSuperClass, signature, false);
    if (superClassMethod != null && !PsiUtil.isLanguageLevel8OrHigher(currentSuperClass)) return false;
    return !((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC) || PsiUtil.isLanguageLevel8OrHigher(currentSuperClass);
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:PullUpDialog.java

示例5: testEnum

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public void testEnum() throws Exception {
  setupLoadingFilter();
  final PsiClass enumClass = findClass("enums.OurEnum");
  assertTrue(enumClass.isEnum());
  final PsiClass superClass = enumClass.getSuperClass();
  assertNotNull(superClass);
  assertEquals("java.lang.Enum", superClass.getQualifiedName());
  assertTrue(enumClass.isInheritor(superClass, false));
  final PsiClassType[] superTypes = enumClass.getSuperTypes();
  assertEquals(1, superTypes.length);
  assertEquals("java.lang.Enum<enums.OurEnum>", superTypes[0].getCanonicalText());
  final PsiClass[] supers = enumClass.getSupers();
  assertEquals(1, supers.length);
  assertEquals("java.lang.Enum", supers[0].getQualifiedName());
  final PsiClassType[] extendsListTypes = enumClass.getExtendsListTypes();
  assertEquals(1, extendsListTypes.length);
  assertEquals("java.lang.Enum<enums.OurEnum>", extendsListTypes[0].getCanonicalText());
  final PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, enumClass, PsiSubstitutor.EMPTY);
  assertEquals("java.lang.Enum<enums.OurEnum>", myJavaFacade.getElementFactory().createType(superClass, superClassSubstitutor).getCanonicalText());
  tearDownLoadingFilter();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:Src15RepositoryUseTest.java

示例6: inferGenericArgType

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType inferGenericArgType(@NotNull GrClosureSignature signature,
                                           @NotNull PsiType targetType,
                                           int genericIndex,
                                           int param) {
  if (targetType instanceof PsiClassType) {
    final PsiClassType.ClassResolveResult result = ((PsiClassType)targetType).resolveGenerics();
    final PsiClass psiClass = result.getElement();
    if (psiClass != null) {
      final PsiSubstitutor substitutor = result.getSubstitutor();

      final PsiType baseType = signature.getParameters()[param].getType();
      final PsiClass baseClass = PsiUtil.resolveClassInClassTypeOnly(baseType);

      if (baseClass != null && InheritanceUtil.isInheritorOrSelf(psiClass, baseClass, true)) {
        final PsiTypeParameter[] typeParameters = baseClass.getTypeParameters();
        if (genericIndex < typeParameters.length) {
          final PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(baseClass, psiClass, substitutor);
          return superClassSubstitutor.substitute(typeParameters[genericIndex]);
        }
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GrDelegatesToUtil.java

示例7: isMemberEnabled

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public boolean isMemberEnabled(GrMemberInfo member) {
  PsiClass currentSuperClass = getSuperClass();
  if(currentSuperClass == null) return true;
  if (myMemberInfoStorage.getDuplicatedMemberInfos(currentSuperClass).contains(member)) return false;
  if (myMemberInfoStorage.getExtending(currentSuperClass).contains(member.getMember())) return false;
  if (!currentSuperClass.isInterface()) return true;

  PsiElement element = member.getMember();
  if (element instanceof PsiClass && ((PsiClass) element).isInterface()) return true;
  if (element instanceof PsiField) {
    return ((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  if (element instanceof PsiMethod) {
    if (currentSuperClass.isInterface()) {
      final PsiSubstitutor superSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(currentSuperClass, myClass, PsiSubstitutor.EMPTY);
      final MethodSignature signature = ((PsiMethod)element).getSignature(superSubstitutor);
      final PsiMethod superClassMethod = MethodSignatureUtil.findMethodBySignature(currentSuperClass, signature, false);
      if (superClassMethod != null) return false;
    }
    return !((PsiModifierListOwner) element).hasModifierProperty(PsiModifier.STATIC);
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:GrPullUpDialog.java

示例8: getHandlerSignature

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private static String getHandlerSignature(JavaFxEventHandlerReference ref) {
  final XmlAttributeValue element = ref.getElement();
  String canonicalText = JavaFxCommonClassNames.JAVAFX_EVENT;
  final PsiElement parent = element.getParent();
  if (parent instanceof XmlAttribute) {
    final XmlAttribute xmlAttribute = (XmlAttribute)parent;
    final Project project = element.getProject();
    final PsiField handlerField = ref.myCurrentTagClass.findFieldByName(xmlAttribute.getName(), true);
    if (handlerField != null) {
      final PsiClassType classType = JavaFxPsiUtil.getPropertyClassType(handlerField);
      if (classType != null) {
        final PsiClass eventHandlerClass = JavaPsiFacade.getInstance(project).findClass(JavaFxCommonClassNames.JAVAFX_EVENT_EVENT_HANDLER, GlobalSearchScope.allScope(project));
        final PsiTypeParameter[] typeParameters = eventHandlerClass != null ? eventHandlerClass.getTypeParameters() : null;
        if (typeParameters != null && typeParameters.length == 1) {
          final PsiTypeParameter typeParameter = typeParameters[0];
          final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(eventHandlerClass, classType);
          final PsiType eventType = substitutor.substitute(typeParameter);
          if (eventType != null) {
            canonicalText = eventType.getCanonicalText();
          }
        }
      }
    }
  }
  return "public void " + element.getValue().substring(1) + "(" + canonicalText + " e)";
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:JavaFxEventHandlerReference.java

示例9: substituteGenericMethod

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
public static PsiMethod substituteGenericMethod(@NotNull PsiMethod sourceMethod,
                                                @NotNull PsiSubstitutor substitutor,
                                                @Nullable PsiElement target) {
  final Project project = sourceMethod.getProject();
  final JVMElementFactory factory = getFactory(sourceMethod.getProject(), target);
  final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);

  try {
    final PsiMethod resultMethod = createMethod(factory, sourceMethod, target);
    copyModifiers(sourceMethod.getModifierList(), resultMethod.getModifierList());
    final PsiSubstitutor collisionResolvedSubstitutor =
      substituteTypeParameters(factory, target, sourceMethod.getTypeParameterList(), resultMethod.getTypeParameterList(), substitutor, sourceMethod);
    substituteReturnType(PsiManager.getInstance(project), resultMethod, sourceMethod.getReturnType(), collisionResolvedSubstitutor);
    substituteParameters(factory, codeStyleManager, sourceMethod.getParameterList(), resultMethod.getParameterList(), collisionResolvedSubstitutor, target);
    copyDocComment(sourceMethod, resultMethod, factory);
    GlobalSearchScope scope = sourceMethod.getResolveScope();
    final List<PsiClassType> thrownTypes = ExceptionUtil.collectSubstituted(collisionResolvedSubstitutor, sourceMethod.getThrowsList().getReferencedTypes(),
                                                                            scope);
    if (target instanceof PsiClass) {
      final PsiMethod[] methods = ((PsiClass)target).findMethodsBySignature(sourceMethod, true);
      for (PsiMethod psiMethod : methods) {
        if (psiMethod != null && psiMethod != sourceMethod) {
          PsiClass aSuper = psiMethod.getContainingClass();
          if (aSuper != null && aSuper != target) {
            PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(aSuper, (PsiClass)target, PsiSubstitutor.EMPTY);
            ExceptionUtil.retainExceptions(thrownTypes, ExceptionUtil.collectSubstituted(superClassSubstitutor, psiMethod.getThrowsList().getReferencedTypes(), scope));
          }
        }
      }
    }
    substituteThrows(factory, resultMethod.getThrowsList(), collisionResolvedSubstitutor, sourceMethod, thrownTypes);
    return resultMethod;
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
    return sourceMethod;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:39,代码来源:GenerateMembersUtil.java

示例10: createImplementationPrototypes

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiMethod[] createImplementationPrototypes(PsiClass inClass, PsiMethod method) throws IncorrectOperationException {
  if (!(inClass instanceof GrTypeDefinition)) return PsiMethod.EMPTY_ARRAY;
  if (method instanceof GrTraitMethod) return PsiMethod.EMPTY_ARRAY;

  final PsiClass containingClass = method.getContainingClass();
  PsiSubstitutor substitutor = inClass.isInheritor(containingClass, true)
                               ? TypeConversionUtil.getSuperClassSubstitutor(containingClass, inClass, PsiSubstitutor.EMPTY)
                               : PsiSubstitutor.EMPTY;
  return new PsiMethod[]{GroovyOverrideImplementUtil.generateMethodPrototype((GrTypeDefinition)inClass, method, substitutor)};
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:GroovyMethodImplementor.java

示例11: createImplementationPrototypes

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiMethod[] createImplementationPrototypes(PsiClass inClass, PsiMethod method) throws IncorrectOperationException {
  if (!(inClass instanceof GrTypeDefinition && method instanceof GrTraitMethod)) return PsiMethod.EMPTY_ARRAY;

  final PsiClass containingClass = method.getContainingClass();
  PsiSubstitutor substitutor = inClass.isInheritor(containingClass, true) ? TypeConversionUtil.getSuperClassSubstitutor(containingClass, inClass, PsiSubstitutor.EMPTY)
                                                                          : PsiSubstitutor.EMPTY;
  return new GrMethod[]{GroovyOverrideImplementUtil.generateTraitMethodPrototype((GrTypeDefinition)inClass, (GrTraitMethod)method, substitutor)};
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:TraitMethodImplementor.java

示例12: getTargetTypeParameter

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private PsiType getTargetTypeParameter(PsiClass iterableClass, PsiExpression value, TypeView typeView) {
  final Project project = iterableClass.getProject();
  final PsiClass itClass =
    JavaPsiFacade.getInstance(project).findClass("java.lang.Iterable", GlobalSearchScope.allScope(project));
  if (itClass == null) return null;

  if (!InheritanceUtil.isInheritorOrSelf(iterableClass, itClass, true)) {
    findConversionOrFail(value, value, typeView.getTypePair());
    return null;
  }

  final PsiSubstitutor aSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(itClass, iterableClass, PsiSubstitutor.EMPTY);

  return aSubstitutor.substitute(itClass.getTypeParameters()[0]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:TypeMigrationStatementProcessor.java

示例13: findOverridingMethod

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
/**
 * @param method the method of which to find an override.
 * @param aClass subclass to find the method in.
 * @return the overriding method.
 */
@Nullable
private static PsiMethod findOverridingMethod(PsiClass aClass, @NotNull PsiMethod method) {
  final PsiClass superClass = method.getContainingClass();
  if (aClass.equals(superClass)) {
    return null;
  }
  final PsiSubstitutor substitutor =
    TypeConversionUtil.getSuperClassSubstitutor(superClass, aClass, PsiSubstitutor.EMPTY);
  final MethodSignature signature = method.getSignature(substitutor);
  final List<Pair<PsiMethod, PsiSubstitutor>> pairs =
    aClass.findMethodsAndTheirSubstitutorsByName(signature.getName(), true);
  for (Pair<PsiMethod, PsiSubstitutor> pair : pairs) {
    final PsiMethod overridingMethod = pair.first;
    if (overridingMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
      continue;
    }
    final PsiClass containingClass = overridingMethod.getContainingClass();
    if (containingClass != null && containingClass.isInterface() && !overridingMethod.hasModifierProperty(PsiModifier.DEFAULT)) {
      continue;
    }
    final PsiSubstitutor overridingSubstitutor = pair.second;
    final MethodSignature foundMethodSignature =
      overridingMethod.getSignature(overridingSubstitutor);
    if (MethodSignatureUtil.isSubsignature(signature,
                                           foundMethodSignature) && overridingMethod != method) {
      return overridingMethod;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:AbstractMethodWithMissingImplementationsInspection.java

示例14: methodsHaveSameReturnTypes

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
private boolean methodsHaveSameReturnTypes(PsiMethod method1, PsiMethod method2) {
  final PsiType type1 = method1.getReturnType();
  if (type1 == null) {
    return false;
  }
  final PsiClass superClass = method2.getContainingClass();
  final PsiClass aClass = method1.getContainingClass();
  if (aClass == null || superClass == null) return false;
  final PsiSubstitutor substitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, aClass, PsiSubstitutor.EMPTY);
  final PsiType type2 = method2.getReturnType();
  return Comparing.equal(type1, substitutor.substitute(type2));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:AbstractMethodOverridesAbstractMethodInspection.java

示例15: collectMethods

import com.intellij.psi.util.TypeConversionUtil; //导入方法依赖的package包/类
@Override
public void collectMethods(@NotNull GrTypeDefinition psiClass, @NotNull Collection<PsiMethod> collector) {
  if (psiClass.isAnonymous() || psiClass.isInterface() || psiClass.isEnum()) {
    return;
  }

  if (!hasInheritConstructorsAnnotation(psiClass)) return;

  final PsiClass superClass = psiClass.getSuperClass();
  if (superClass == null) return;

  final PsiSubstitutor superClassSubstitutor = TypeConversionUtil.getSuperClassSubstitutor(superClass, psiClass, PsiSubstitutor.EMPTY);
  for (PsiMethod constructor : superClass.getConstructors()) {
    if (constructor.hasModifierProperty(PsiModifier.PRIVATE)) continue;

    final GrLightMethodBuilder inheritedConstructor = new GrLightMethodBuilder(psiClass.getManager(), psiClass.getName());
    inheritedConstructor.setContainingClass(psiClass);
    inheritedConstructor.setConstructor(true);
    inheritedConstructor.setNavigationElement(psiClass);
    inheritedConstructor.addModifier(VisibilityUtil.getVisibilityModifier(constructor.getModifierList()));
    inheritedConstructor.setOriginInfo("created by @InheritConstructors");

    for (PsiParameter parameter : constructor.getParameterList().getParameters()) {
      String name = StringUtil.notNullize(parameter.getName());
      PsiType type = superClassSubstitutor.substitute(parameter.getType());
      inheritedConstructor.addParameter(name, type, false);
    }
    if (psiClass.findCodeMethodsBySignature(inheritedConstructor, false).length == 0) {
      collector.add(inheritedConstructor);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:GrInheritConstructorContributor.java


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