@NotNull private static List<PsiClassType> getExceptionsByMethod(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor, @NotNull PsiElement place) { PsiClassType[] referenceTypes = method.getThrowsList().getReferencedTypes(); if (referenceTypes.length == 0) return Collections.emptyList(); GlobalSearchScope scope = place.getResolveScope(); List<PsiClassType> result = ContainerUtil.newArrayList(); for (PsiType type : referenceTypes) { type = PsiClassImplUtil.correctType(substitutor.substitute(type), scope); if (type instanceof PsiClassType) { result.add((PsiClassType)type); } } return result; }
private static List<PsiClassType> getUnhandledExceptions(PsiElement element, PsiElement topElement, PsiSubstitutor substitutor, PsiClassType[] referencedTypes) { if (referencedTypes.length > 0) { List<PsiClassType> result = ContainerUtil.newArrayList(); for (PsiClassType referencedType : referencedTypes) { final PsiType type = PsiClassImplUtil.correctType(GenericsUtil.eliminateWildcards(substitutor.substitute(referencedType), false), element.getResolveScope()); if (!(type instanceof PsiClassType)) continue; PsiClassType classType = (PsiClassType)type; PsiClass exceptionClass = ((PsiClassType)type).resolve(); if (exceptionClass == null) continue; if (isUncheckedException(classType)) continue; if (isHandled(element, classType, topElement)) continue; result.add((PsiClassType)type); } return result; } return Collections.emptyList(); }
@Override @Nullable public PsiType fun(final PsiMethodCallExpression call) { PsiReferenceExpression methodExpression = call.getMethodExpression(); PsiType theOnly = null; final JavaResolveResult[] results = methodExpression.multiResolve(false); LanguageLevel languageLevel = PsiUtil.getLanguageLevel(call); for (int i = 0; i < results.length; i++) { final PsiType type = getResultType(call, methodExpression, results[i], languageLevel); if (type == null) { return null; } if (i == 0) { theOnly = type; } else if (!theOnly.equals(type)) { return null; } } return PsiClassImplUtil.correctType(theOnly, call.getResolveScope()); }
private static boolean processField(@NotNull GrTypeDefinition grType, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place, boolean processInstanceMethods, @NotNull PsiSubstitutor substitutor, @NotNull PsiElementFactory factory, @NotNull LanguageLevel level, CandidateInfo fieldInfo) { final PsiField field = (PsiField)fieldInfo.getElement(); if (!processInstanceMember(processInstanceMethods, field) || isSameDeclaration(place, field)) { return true; } LOG.assertTrue(field.getContainingClass() != null); final PsiSubstitutor finalSubstitutor = PsiClassImplUtil.obtainFinalSubstitutor(field.getContainingClass(), fieldInfo.getSubstitutor(), grType, substitutor, factory, level); return processor.execute(field, state.put(PsiSubstitutor.KEY, finalSubstitutor)); }
private static boolean processMethod(@NotNull GrTypeDefinition grType, @NotNull PsiScopeProcessor processor, @NotNull ResolveState state, @NotNull PsiElement place, boolean processInstanceMethods, @NotNull PsiSubstitutor substitutor, @NotNull PsiElementFactory factory, @NotNull LanguageLevel level, boolean placeGroovy, @NotNull CandidateInfo info) { PsiMethod method = (PsiMethod)info.getElement(); if (!processInstanceMember(processInstanceMethods, method) || isSameDeclaration(place, method) || !isMethodVisible(placeGroovy, method)) { return true; } LOG.assertTrue(method.getContainingClass() != null); final PsiSubstitutor finalSubstitutor = PsiClassImplUtil.obtainFinalSubstitutor(method.getContainingClass(), info.getSubstitutor(), grType, substitutor, factory, level); return processor.execute(method, state.put(PsiSubstitutor.KEY, finalSubstitutor)); }
public static List<PsiClassType> collectSubstituted(PsiSubstitutor substitutor, PsiClassType[] thrownExceptions, GlobalSearchScope scope) { final List<PsiClassType> ex = new ArrayList<PsiClassType>(); for (PsiClassType thrownException : thrownExceptions) { final PsiType psiType = PsiClassImplUtil.correctType(substitutor.substitute(thrownException), scope); if (psiType instanceof PsiClassType) { ex.add((PsiClassType)psiType); } } return ex; }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { return PsiClassImplUtil.processDeclarationsInClass(this, processor, state, null, lastParent, place, PsiUtil.getLanguageLevel(place), false); }
@Override @NotNull public PsiClass[] getSupers() { if (CommonClassNames.JAVA_LANG_OBJECT.equals(getQualifiedName())) { return PsiClass.EMPTY_ARRAY; } return PsiClassImplUtil.getSupers(this); }
@Override @NotNull public PsiClassType[] getSuperTypes() { if (CommonClassNames.JAVA_LANG_OBJECT.equals(getQualifiedName())) { return PsiClassType.EMPTY_ARRAY; } return PsiClassImplUtil.getSuperTypes(this); }
@Override public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) { if (isEnum()) { if (!PsiClassImplUtil.processDeclarationsInEnum(processor, state, myInnersCache)) return false; } LanguageLevel level = processor instanceof MethodsProcessor ? ((MethodsProcessor)processor).getLanguageLevel() : PsiUtil.getLanguageLevel(place); return PsiClassImplUtil.processDeclarationsInClass(this, processor, state, null, lastParent, place, level, false); }
@Nullable public PsiField findFieldByName(String name, boolean checkBases) { if (checkBases) { return PsiClassImplUtil.findFieldByName(myClass, name, true); } return CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<Map<String, PsiField>>() { @Nullable @Override public Result<Map<String, PsiField>> compute() { return Result.create(getFieldsMap(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker); } }).get(name); }
@NotNull public PsiMethod[] findMethodsByName(String name, boolean checkBases) { if (checkBases) { return PsiClassImplUtil.findMethodsByName(myClass, name, true); } PsiMethod[] methods = CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<Map<String, PsiMethod[]>>() { @Nullable @Override public Result<Map<String, PsiMethod[]>> compute() { return Result.create(getMethodsMap(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker); } }).get(name); return methods == null ? PsiMethod.EMPTY_ARRAY : methods; }
@Nullable public PsiClass findInnerClassByName(final String name, final boolean checkBases) { if (checkBases) { return PsiClassImplUtil.findInnerByName(myClass, name, true); } else { return CachedValuesManager.getCachedValue(myClass, new CachedValueProvider<Map<String, PsiClass>>() { @Nullable @Override public Result<Map<String, PsiClass>> compute() { return Result.create(getInnerClassesMap(), OUT_OF_CODE_BLOCK_MODIFICATION_COUNT, myTracker); } }).get(name); } }
public boolean isEntryPoint(@NotNull PsiElement element) { final Project project = element.getProject(); final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); if (element instanceof PsiMethod && isAddMainsEnabled() && PsiClassImplUtil.isMainOrPremainMethod((PsiMethod)element)) { return true; } if (element instanceof PsiClass) { PsiClass aClass = (PsiClass)element; final PsiClass applet = psiFacade.findClass("java.applet.Applet", GlobalSearchScope.allScope(project)); if (isAddAppletEnabled() && applet != null && aClass.isInheritor(applet, true)) { return true; } final PsiClass servlet = psiFacade.findClass("javax.servlet.Servlet", GlobalSearchScope.allScope(project)); if (isAddServletEnabled() && servlet != null && aClass.isInheritor(servlet, true)) { return true; } if (isAddMainsEnabled() && PsiMethodUtil.hasMainMethod(aClass)) return true; } if (element instanceof PsiModifierListOwner) { final EntryPointsManager entryPointsManager = EntryPointsManager.getInstance(project); if (entryPointsManager.isEntryPoint(element)) return true; } for (EntryPoint extension : myExtensions) { if (extension.isEntryPoint(element)) { return true; } } final ImplicitUsageProvider[] implicitUsageProviders = Extensions.getExtensions(ImplicitUsageProvider.EP_NAME); for (ImplicitUsageProvider provider : implicitUsageProviders) { if (provider.isImplicitUsage(element)) return true; } return false; }
@Override public boolean processDeclarations(@NotNull final PsiScopeProcessor processor, @NotNull final ResolveState state, final PsiElement lastParent, @NotNull final PsiElement place) { return PsiClassImplUtil.processDeclarationsInClass(this, processor, state, null, lastParent, place, PsiUtil.getLanguageLevel(place), false); }
private static boolean methodMayHaveUnusedParameters(GrMethod method) { return (method.isConstructor() || method.hasModifierProperty(PsiModifier.PRIVATE) || method.hasModifierProperty(PsiModifier.STATIC) || !method.hasModifierProperty(PsiModifier.ABSTRACT) && !isOverriddenOrOverrides(method)) && !method.hasModifierProperty(PsiModifier.NATIVE) && !JavaHighlightUtil.isSerializationRelatedMethod(method, method.getContainingClass()) && !PsiClassImplUtil.isMainOrPremainMethod(method); }
@Override public boolean isEquivalentTo(final PsiElement another) { return PsiClassImplUtil.isMethodEquivalentTo(this, another); }
@Override @NotNull public PsiClassType[] getExtendsListTypes() { return PsiClassImplUtil.getExtendsListTypes(this); }
@Override public boolean isEquivalentTo(PsiElement another) { return PsiClassImplUtil.isMethodEquivalentTo(this, another); }
@Override @Nullable public PsiField findFieldByName(@NonNls String name, boolean checkBases) { return PsiClassImplUtil.findFieldByName(this, name, checkBases); }
@Override @Nullable public PsiMethod findMethodBySignature(PsiMethod patternMethod, boolean checkBases) { return PsiClassImplUtil.findMethodBySignature(this, patternMethod, checkBases); }
@Override @NotNull public PsiMethod[] findMethodsBySignature(PsiMethod patternMethod, boolean checkBases) { return PsiClassImplUtil.findMethodsBySignature(this, patternMethod, checkBases); }
@Override @NotNull public PsiMethod[] findMethodsByName(@NonNls String name, boolean checkBases) { return PsiClassImplUtil.findMethodsByName(this, name, checkBases); }
@Override @NotNull public List<Pair<PsiMethod, PsiSubstitutor>> findMethodsAndTheirSubstitutorsByName(@NonNls String name, boolean checkBases) { return PsiClassImplUtil.findMethodsAndTheirSubstitutorsByName(this, name, checkBases); }
@Override @NotNull public List<Pair<PsiMethod, PsiSubstitutor>> getAllMethodsAndTheirSubstitutors() { return PsiClassImplUtil.getAllWithSubstitutorsByMap(this, PsiClassImplUtil.MemberType.METHOD); }
@Override public boolean isEquivalentTo(PsiElement another) { return PsiClassImplUtil.isClassEquivalentTo(this, another); }
@Override @NotNull public PsiClassType[] getImplementsListTypes() { return PsiClassImplUtil.getImplementsListTypes(this); }
@Nullable @Override public PsiClass getSuperClass() { return PsiClassImplUtil.getSuperClass(this); }
@Override public PsiClass[] getInterfaces() { return PsiClassImplUtil.getInterfaces(this); }
@NotNull @Override public PsiClass[] getSupers() { return PsiClassImplUtil.getSupers(this); }
@NotNull @Override public PsiClassType[] getSuperTypes() { return PsiClassImplUtil.getSuperTypes(this); }
@NotNull @Override public PsiField[] getAllFields() { return PsiClassImplUtil.getAllFields(this); }
@NotNull @Override public PsiMethod[] getAllMethods() { return PsiClassImplUtil.getAllMethods(this); }
@NotNull @Override public PsiClass[] getAllInnerClasses() { return PsiClassImplUtil.getAllInnerClasses(this); }
public static boolean isClassEquivalentTo(GrTypeDefinitionImpl definition, PsiElement another) { return PsiClassImplUtil.isClassEquivalentTo(definition, another); }
@Nullable @Override public PsiMethod findMethodBySignature(PsiMethod patternMethod, boolean checkBases) { return PsiClassImplUtil.findMethodBySignature(this, patternMethod, checkBases); }
@NotNull @Override public PsiMethod[] findMethodsBySignature(PsiMethod patternMethod, boolean checkBases) { return PsiClassImplUtil.findMethodsBySignature(this, patternMethod, checkBases); }