Java 类com.intellij.psi.util.PsiSuperMethodUtil 实例源码

项目:tools-idea    文件:FindSuperElementsHelper.java   
@Nullable
public static PsiElement[] findSuperElements(@NotNull PsiElement element) {
  if (element instanceof PsiClass) {
    PsiClass aClass = (PsiClass) element;
    List<PsiClass> allSupers = new ArrayList<PsiClass>(Arrays.asList(aClass.getSupers()));
    for (Iterator<PsiClass> iterator = allSupers.iterator(); iterator.hasNext();) {
      PsiClass superClass = iterator.next();
      if (CommonClassNames.JAVA_LANG_OBJECT.equals(superClass.getQualifiedName())) iterator.remove();
    }
    return allSupers.toArray(new PsiClass[allSupers.size()]);
  } else if (element instanceof PsiMethod) {
    PsiMethod method = (PsiMethod) element;
    if (method.isConstructor()) {
      PsiMethod constructorInSuper = PsiSuperMethodUtil.findConstructorInSuper(method);
      if (constructorInSuper != null) {
        return new PsiMethod[]{constructorInSuper};
      }
    } else {
      return method.findSuperMethods(false);
    }
  }
  return null;
}
项目:guards    文件:PsiTestMethod.java   
public static boolean isTestMethod(@Nullable PsiMethod method, @Nullable Set<PsiMethod> seenMethods) {
    if ( method == null ) {
        return false;
    }
    if ( !method.hasModifierProperty(PsiModifier.PUBLIC) ) {
        return false;
    }
    if ( !PsiType.BOOLEAN.equals(method.getReturnType()) ) {
        return false;
    }
    if ( !"test".equals(method.getName()) && !AnnotationUtil.isAnnotated(method, Psi.C_TEST, false) ) {
        return false;
    }
    if ( method.getParameterList().getParameters().length != 1 ) {
        return false;
    }
    if ( seenMethods != null ) {
        for( PsiMethod s : seenMethods ) {
            if ( PsiSuperMethodUtil.isSuperMethod(s, method) ) {
                return false;
            }
        }
        seenMethods.add(method);
    }
    return true;
}
项目:consulo-java    文件:TypeCorrector.java   
@Nullable
public <T extends PsiType> T correctType(@NotNull T type)
{
    if(type instanceof PsiClassType)
    {
        PsiClassType classType = (PsiClassType) type;
        if(classType.getParameterCount() == 0)
        {
            final PsiClassType.ClassResolveResult classResolveResult = classType.resolveGenerics();
            final PsiClass psiClass = classResolveResult.getElement();
            if(psiClass != null && classResolveResult.getSubstitutor() == PsiSubstitutor.EMPTY)
            {
                final PsiClass mappedClass = PsiSuperMethodUtil.correctClassByScope(psiClass, myResolveScope);
                if(mappedClass == null || mappedClass == psiClass)
                {
                    return (T) classType;
                }
            }
        }
    }

    return (T) type.accept(this);
}
项目:intellij-ce-playground    文件:FindSuperElementsHelper.java   
@NotNull
public static PsiElement[] findSuperElements(@NotNull PsiElement element) {
  if (element instanceof PsiClass) {
    PsiClass aClass = (PsiClass) element;
    List<PsiClass> allSupers = new ArrayList<PsiClass>(Arrays.asList(aClass.getSupers()));
    for (Iterator<PsiClass> iterator = allSupers.iterator(); iterator.hasNext();) {
      PsiClass superClass = iterator.next();
      if (CommonClassNames.JAVA_LANG_OBJECT.equals(superClass.getQualifiedName())) iterator.remove();
    }
    return allSupers.toArray(new PsiClass[allSupers.size()]);
  }
  if (element instanceof PsiMethod) {
    PsiMethod method = (PsiMethod) element;
    if (method.isConstructor()) {
      PsiMethod constructorInSuper = PsiSuperMethodUtil.findConstructorInSuper(method);
      if (constructorInSuper != null) {
        return new PsiMethod[]{constructorInSuper};
      }
    }
    else {
      PsiMethod[] superMethods = method.findSuperMethods(false);
      if (superMethods.length == 0) {
        PsiMethod superMethod = getSiblingInheritedViaSubClass(method);
        if (superMethod != null) {
          superMethods = new PsiMethod[]{superMethod};
        }
      }
      return superMethods;
    }
  }
  return PsiElement.EMPTY_ARRAY;
}
项目:intellij-ce-playground    文件:GroovyGotoSuperHandler.java   
@NotNull
private static PsiMethod[] getSupers(PsiMethod method) {
  if (method.isConstructor()) {
    PsiMethod constructorInSuper = PsiSuperMethodUtil.findConstructorInSuper(method);
    if (constructorInSuper != null) {
      return new PsiMethod[]{constructorInSuper};
    }
  }
  else {
    return method.findSuperMethods(false);
  }

  return PsiMethod.EMPTY_ARRAY;
}
项目:tools-idea    文件:GroovyGotoSuperHandler.java   
@NotNull
private static PsiMethod[] getSupers(PsiMethod method) {
  if (method.isConstructor()) {
    PsiMethod constructorInSuper = PsiSuperMethodUtil.findConstructorInSuper(method);
    if (constructorInSuper != null) {
      return new PsiMethod[]{constructorInSuper};
    }
  }
  else {
    return method.findSuperMethods(false);
  }

  return PsiMethod.EMPTY_ARRAY;
}
项目:consulo-java    文件:TypeCorrector.java   
@Override
public PsiType visitClassType(final PsiClassType classType)
{
    PsiClassType alreadyComputed = myResultMap.get(classType);
    if(alreadyComputed != null)
    {
        return alreadyComputed;
    }

    final PsiClassType.ClassResolveResult classResolveResult = classType.resolveGenerics();
    final PsiClass psiClass = classResolveResult.getElement();
    final PsiSubstitutor substitutor = classResolveResult.getSubstitutor();
    if(psiClass == null)
    {
        return classType;
    }

    PsiUtilCore.ensureValid(psiClass);

    final PsiClass mappedClass = PsiSuperMethodUtil.correctClassByScope(psiClass, myResolveScope);
    if(mappedClass == null)
    {
        return classType;
    }

    PsiClassType mappedType = new PsiCorrectedClassType(classType.getLanguageLevel(), classType, new CorrectedResolveResult(psiClass, mappedClass, substitutor, classResolveResult));
    myResultMap.put(classType, mappedType);
    return mappedType;
}
项目:consulo-java    文件:FindSuperElementsHelper.java   
@NotNull
public static PsiElement[] findSuperElements(@NotNull PsiElement element)
{
    if(element instanceof PsiClass)
    {
        PsiClass aClass = (PsiClass) element;
        List<PsiClass> allSupers = new ArrayList<>(Arrays.asList(aClass.getSupers()));
        for(Iterator<PsiClass> iterator = allSupers.iterator(); iterator.hasNext(); )
        {
            PsiClass superClass = iterator.next();
            if(CommonClassNames.JAVA_LANG_OBJECT.equals(superClass.getQualifiedName()))
            {
                iterator.remove();
            }
        }
        return allSupers.toArray(new PsiClass[allSupers.size()]);
    }
    if(element instanceof PsiMethod)
    {
        PsiMethod method = (PsiMethod) element;
        if(method.isConstructor())
        {
            PsiMethod constructorInSuper = PsiSuperMethodUtil.findConstructorInSuper(method);
            if(constructorInSuper != null)
            {
                return new PsiMethod[]{constructorInSuper};
            }
        }
        else
        {
            PsiMethod[] superMethods = method.findSuperMethods(false);
            if(superMethods.length == 0)
            {
                PsiMethod superMethod = getSiblingInheritedViaSubClass(method);
                if(superMethod != null)
                {
                    superMethods = new PsiMethod[]{superMethod};
                }
            }
            return superMethods;
        }
    }
    return PsiElement.EMPTY_ARRAY;
}