public static boolean hasBadResolve(final PsiReference reference, boolean checkSoft) { if (!checkSoft && reference.isSoft()) return false; if (reference instanceof PsiPolyVariantReference) { return ((PsiPolyVariantReference) reference).multiResolve(false).length == 0; } return reference.resolve() == null; }
private void doCheckRefs(final PsiElement value, final PsiReference[] references, int start) { for (int i = start; i < references.length; ++i) { PsiReference reference = references[i]; ProgressManager.checkCanceled(); if (reference == null) { continue; } if (!hasBadResolve(reference, false)) { continue; } String description = getErrorDescription(reference); final int startOffset = reference.getElement().getTextRange().getStartOffset(); final TextRange referenceRange = reference.getRangeInElement(); // logging for IDEADEV-29655 if (referenceRange.getStartOffset() > referenceRange.getEndOffset()) { LOG.error( "Reference range start offset > end offset: " + reference + ", start offset: " + referenceRange.getStartOffset() + ", end offset: " + referenceRange.getEndOffset()); } HighlightInfoType type = getTagProblemInfoType(PsiTreeUtil.getParentOfType(value, XmlTag.class)); if (value instanceof XmlAttributeValue) { PsiElement parent = value.getParent(); if (parent instanceof XmlAttribute) { String name = ((XmlAttribute) parent).getName().toLowerCase(); if (type.getSeverity(null).compareTo(HighlightInfoType.WARNING.getSeverity(null)) > 0 && name.endsWith("stylename")) { type = HighlightInfoType.WARNING; } else if (name.equals("href") && type.getSeverity(null) == HighlightInfoType.WARNING.getSeverity(null)) { continue; } } } HighlightInfo info = HighlightInfo.createHighlightInfo( type, startOffset + referenceRange.getStartOffset(), startOffset + referenceRange.getEndOffset(), description); addToResults(info); if (reference instanceof QuickFixProvider) ((QuickFixProvider) reference).registerQuickfix(info, reference); UnresolvedReferenceQuickFixProvider.registerReferenceFixes( reference, new QuickFixActionRegistrarImpl(info)); } }
public static String getErrorDescription(final PsiReference reference) { String message; if (reference instanceof EmptyResolveMessageProvider) { message = ((EmptyResolveMessageProvider) reference).getUnresolvedMessagePattern(); } else { //noinspection UnresolvedPropertyKey message = PsiBundle.message("cannot.resolve.symbol"); } String description; try { description = MessageFormat.format(message, reference.getCanonicalText()); } catch (IllegalArgumentException ex) { // unresolvedMessage provided by third-party reference contains wrong format string (e.g. {}), // tolerate it description = message; LOG.warn( XmlErrorMessages.message( "plugin.reference.message.problem", reference.getClass().getName(), message)); } return description; }