public void appendDerivedMethods(StringBuffer buf, RefMethod refMethod) { if (refMethod.getDerivedMethods().size() > 0) { HTMLComposer.appendHeading( buf, InspectionsBundle.message("inspection.export.results.derived.methods")); myComposer.startList(buf); for (RefMethod refDerived : refMethod.getDerivedMethods()) { myComposer.appendListItem(buf, refDerived); } myComposer.doneList(buf); } }
private boolean isAccessible( RefJavaElement to, @PsiModifier.ModifierConstant String accessModifier) { for (RefElement refElement : to.getInReferences()) { if (!isAccessibleFrom(refElement, to, accessModifier)) return false; } if (to instanceof RefMethod) { RefMethod refMethod = (RefMethod) to; if (refMethod.isAbstract() && (refMethod.getDerivedMethods().isEmpty() || refMethod.getAccessModifier() == PsiModifier.PRIVATE)) return false; for (RefMethod refOverride : refMethod.getDerivedMethods()) { if (!isAccessibleFrom(refOverride, to, accessModifier)) return false; } for (RefMethod refSuper : refMethod.getSuperMethods()) { if (RefJavaUtil.getInstance().compareAccess(refSuper.getAccessModifier(), accessModifier) > 0) return false; } } if (to instanceof RefClass) { RefClass refClass = (RefClass) to; for (RefClass subClass : refClass.getSubClasses()) { if (!isAccessibleFrom(subClass, to, accessModifier)) return false; } List children = refClass.getChildren(); if (children != null) { for (Object refElement : children) { if (!isAccessible((RefJavaElement) refElement, accessModifier)) return false; } } for (final RefElement refElement : refClass.getInTypeReferences()) { if (!isAccessibleFrom(refElement, refClass, accessModifier)) return false; } List<RefJavaElement> classExporters = ((RefClassImpl) refClass).getClassExporters(); if (classExporters != null) { for (RefJavaElement refExporter : classExporters) { if (getAccessLevel(accessModifier) < getAccessLevel(refExporter.getAccessModifier())) return false; } } } return true; }
private static void clearUsedParameters( @NotNull RefMethod refMethod, RefParameter[] params, boolean checkDeep) { RefParameter[] methodParms = refMethod.getParameters(); for (int i = 0; i < methodParms.length; i++) { if (methodParms[i].isUsedForReading()) params[i] = null; } if (checkDeep) { for (RefMethod refOverride : refMethod.getDerivedMethods()) { clearUsedParameters(refOverride, params, checkDeep); } } }
@Nullable public CommonProblemDescriptor[] checkElement( final RefEntity refEntity, final AnalysisScope scope, final InspectionManager manager, final GlobalInspectionContext globalContext, final ProblemDescriptionsProcessor processor) { if (refEntity instanceof RefMethod) { final RefMethod refMethod = (RefMethod) refEntity; if (refMethod.isSyntheticJSP()) return null; if (refMethod.isExternalOverride()) return null; if (!(refMethod.isStatic() || refMethod.isConstructor()) && !refMethod.getSuperMethods().isEmpty()) return null; if ((refMethod.isAbstract() || refMethod.getOwnerClass().isInterface()) && refMethod.getDerivedMethods().isEmpty()) return null; if (RefUtil.isEntryPoint(refMethod)) return null; if (refMethod.isAppMain()) return null; final ArrayList<RefParameter> unusedParameters = getUnusedParameters(refMethod); if (unusedParameters.isEmpty()) return null; final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>(); for (RefParameter refParameter : unusedParameters) { final PsiIdentifier psiIdentifier = refParameter.getElement().getNameIdentifier(); if (psiIdentifier != null) { result.add( manager.createProblemDescriptor( psiIdentifier, refMethod.isAbstract() ? InspectionsBundle.message("inspection.unused.parameter.composer") : InspectionsBundle.message("inspection.unused.parameter.composer1"), new AcceptSuggested( globalContext.getRefManager(), processor, refParameter.toString()), ProblemHighlightType.LIKE_UNUSED_SYMBOL, false)); } } return result.toArray(new CommonProblemDescriptor[result.size()]); } return null; }
@Override public void referenceRemoved() { if (getOwnerClass() != null) { ((RefClassImpl) getOwnerClass()).methodRemoved(this); } super.referenceRemoved(); for (RefMethod superMethod : getSuperMethods()) { superMethod.getDerivedMethods().remove(this); } for (RefMethod subMethod : getDerivedMethods()) { subMethod.getSuperMethods().remove(this); } ArrayList<RefElement> deletedRefs = new ArrayList<RefElement>(); for (RefParameter parameter : getParameters()) { getRefManager().removeRefElement(parameter, deletedRefs); } }