public static void visitRefInDocTag( final PsiDocTag tag, final JavadocManager manager, final PsiElement context, final ArrayList<ProblemDescriptor> problems, final InspectionManager inspectionManager, final boolean onTheFly) { final String tagName = tag.getName(); final PsiDocTagValue value = tag.getValueElement(); if (value == null) return; final JavadocTagInfo info = manager.getTagInfo(tagName); if (info != null && !info.isValidInContext(context)) return; final String message = info == null || !info.isInline() ? null : info.checkTagValue(value); if (message != null) { problems.add(createDescriptor(value, message, inspectionManager, onTheFly)); } final PsiReference reference = value.getReference(); if (reference == null) return; final PsiElement element = reference.resolve(); if (element != null) return; final int textOffset = value.getTextOffset(); if (textOffset == value.getTextRange().getEndOffset()) return; final PsiDocTagValue valueElement = tag.getValueElement(); if (valueElement == null) return; final CharSequence paramName = value .getContainingFile() .getViewProvider() .getContents() .subSequence(textOffset, value.getTextRange().getEndOffset()); final String params = "<code>" + paramName + "</code>"; final List<LocalQuickFix> fixes = new ArrayList<LocalQuickFix>(); if (onTheFly && "param".equals(tagName)) { final PsiDocCommentOwner commentOwner = PsiTreeUtil.getParentOfType(tag, PsiDocCommentOwner.class); if (commentOwner instanceof PsiMethod) { final PsiMethod method = (PsiMethod) commentOwner; final PsiParameter[] parameters = method.getParameterList().getParameters(); final PsiDocTag[] tags = tag.getContainingComment().getTags(); final Set<String> unboundParams = new HashSet<String>(); for (PsiParameter parameter : parameters) { if (!JavaDocLocalInspection.isFound(tags, parameter)) { unboundParams.add(parameter.getName()); } } if (!unboundParams.isEmpty()) { fixes.add(new RenameReferenceQuickFix(unboundParams)); } } } fixes.add(new RemoveTagFix(tagName, paramName)); problems.add( inspectionManager.createProblemDescriptor( valueElement, reference.getRangeInElement(), cannotResolveSymbolMessage(params), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, onTheFly, fixes.toArray(new LocalQuickFix[fixes.size()]))); }
@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); } } }