private void reportMissingOnClickProblem( OnClickConverter.MyReference reference, PsiClass activity, String methodName, boolean incorrectSignature) { String activityName = activity.getName(); if (activityName == null) { activityName = ""; } final String message = incorrectSignature ? AndroidBundle.message( "android.inspections.on.click.missing.incorrect.signature", methodName, activityName) : AndroidBundle.message( "android.inspections.on.click.missing.problem", methodName, activityName); final LocalQuickFix[] fixes = StringUtil.isJavaIdentifier(methodName) ? new LocalQuickFix[] {new MyQuickFix(methodName, reference.getConverter(), activity)} : LocalQuickFix.EMPTY_ARRAY; myResult.add( myInspectionManager.createProblemDescriptor( reference.getElement(), reference.getRangeInElement(), message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myOnTheFly, fixes)); }
@Override public void visitXmlAttributeValue(XmlAttributeValue value) { for (PsiReference reference : value.getReferences()) { if (!(reference instanceof OnClickConverter.MyReference)) { continue; } final OnClickConverter.MyReference ref = (OnClickConverter.MyReference) reference; final String methodName = ref.getValue(); if (methodName.isEmpty()) { continue; } final ResolveResult[] results = ref.multiResolve(false); final Set<PsiClass> resolvedClasses = new HashSet<PsiClass>(); final Set<PsiClass> resolvedClassesWithMistake = new HashSet<PsiClass>(); for (ResolveResult result : results) { if (result instanceof OnClickConverter.MyResolveResult) { final PsiElement element = result.getElement(); if (element != null) { final PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class); if (aClass != null) { resolvedClasses.add(aClass); if (!((OnClickConverter.MyResolveResult) result).hasCorrectSignature()) { resolvedClassesWithMistake.add(aClass); } } } } } PsiClass activity = null; for (PsiClass relatedActivity : myRelatedActivities) { if (!containsOrExtends(resolvedClasses, relatedActivity)) { activity = relatedActivity; break; } else if (activity == null && containsOrExtends(resolvedClassesWithMistake, relatedActivity)) { activity = relatedActivity; } } if (activity != null) { reportMissingOnClickProblem( ref, activity, methodName, resolvedClassesWithMistake.contains(activity)); } else if (results.length == 0) { myResult.add( myInspectionManager.createProblemDescriptor( value, reference.getRangeInElement(), ProblemsHolder.unresolvedReferenceMessage(reference), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myOnTheFly)); } else if (resolvedClassesWithMistake.size() > 0) { reportMissingOnClickProblem( ref, resolvedClassesWithMistake.iterator().next(), methodName, true); } } }