@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; }
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; }
@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); }
@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; }
@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; }
@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; }
@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; }