use of com.intellij.xml.util.XmlRefCountHolder in project intellij-community by JetBrains.
the class XmlUnusedNamespaceInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
return new XmlElementVisitor() {
@Override
public void visitXmlAttribute(XmlAttribute attribute) {
PsiFile file = holder.getFile();
if (!(file instanceof XmlFile))
return;
XmlRefCountHolder refCountHolder = XmlRefCountHolder.getRefCountHolder((XmlFile) file);
if (refCountHolder == null)
return;
if (!attribute.isNamespaceDeclaration()) {
checkUnusedLocations(attribute, holder, refCountHolder);
return;
}
String namespace = attribute.getValue();
String declaredPrefix = getDeclaredPrefix(attribute);
if (namespace != null && !refCountHolder.isInUse(declaredPrefix)) {
ImplicitUsageProvider[] implicitUsageProviders = Extensions.getExtensions(ImplicitUsageProvider.EP_NAME);
for (ImplicitUsageProvider provider : implicitUsageProviders) {
if (provider.isImplicitUsage(attribute))
return;
}
XmlAttributeValue value = attribute.getValueElement();
assert value != null;
holder.registerProblem(attribute, XmlBundle.message("xml.inspections.unused.schema.declaration"), ProblemHighlightType.LIKE_UNUSED_SYMBOL, new RemoveNamespaceDeclarationFix(declaredPrefix, false, !refCountHolder.isUsedNamespace(namespace)));
XmlTag parent = attribute.getParent();
if (declaredPrefix.isEmpty()) {
XmlAttribute location = getDefaultLocation(parent);
if (location != null) {
holder.registerProblem(location, XmlBundle.message("xml.inspections.unused.schema.location"), ProblemHighlightType.LIKE_UNUSED_SYMBOL, new RemoveNamespaceDeclarationFix(declaredPrefix, true, true));
}
} else if (!refCountHolder.isUsedNamespace(namespace)) {
for (PsiReference reference : getLocationReferences(namespace, parent)) {
if (!XmlHighlightVisitor.hasBadResolve(reference, false))
holder.registerProblemForReference(reference, ProblemHighlightType.LIKE_UNUSED_SYMBOL, XmlBundle.message("xml.inspections.unused.schema.location"), new RemoveNamespaceDeclarationFix(declaredPrefix, true, true));
}
}
}
}
};
}
Aggregations