Search in sources :

Example 1 with DeleteUnusedElementBase

use of org.intellij.lang.xpath.xslt.quickfix.DeleteUnusedElementBase in project intellij-community by JetBrains.

the class XsltValidator method checkUnusedVariable.

public static void checkUnusedVariable(XsltVariable variable, ProblemsHolder holder) {
    if (variable instanceof XsltParameter) {
        if (((XsltParameter) variable).isAbstract()) {
            return;
        }
    } else {
        if (variable.isVoid()) {
            return;
        }
    }
    final XmlTag tag = variable.getTag();
    final XmlTag templateTag = XsltCodeInsightUtil.getTemplateTag(tag, false);
    if (templateTag == null) {
        return;
    }
    final XmlAttribute attribute = tag.getAttribute("name");
    if (attribute == null) {
        return;
    }
    final PsiElement token = XsltSupport.getAttValueToken(attribute);
    if (token == null) {
        return;
    }
    final SearchScope scope = new LocalSearchScope(templateTag);
    final Query<PsiReference> refs = ReferencesSearch.search(variable, scope, false);
    if (isUnused(variable, refs)) {
        final String name = variable.getName();
        assert name != null;
        final LocalQuickFix[] fixes;
        if (variable instanceof XsltParameter) {
            fixes = new LocalQuickFix[] { new DeleteUnusedParameterFix(name, (XsltParameter) variable) };
        } else {
            fixes = new LocalQuickFix[] { new DeleteUnusedVariableFix(name, variable) };
        }
        holder.registerProblem(token, ((DeleteUnusedElementBase) fixes[0]).getType() + " '" + name + "' is never used", ProblemHighlightType.LIKE_UNUSED_SYMBOL, fixes);
    }
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) XmlAttribute(com.intellij.psi.xml.XmlAttribute) DeleteUnusedVariableFix(org.intellij.lang.xpath.xslt.quickfix.DeleteUnusedVariableFix) PsiReference(com.intellij.psi.PsiReference) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) XsltParameter(org.intellij.lang.xpath.xslt.psi.XsltParameter) DeleteUnusedParameterFix(org.intellij.lang.xpath.xslt.quickfix.DeleteUnusedParameterFix) SearchScope(com.intellij.psi.search.SearchScope) LocalSearchScope(com.intellij.psi.search.LocalSearchScope) PsiElement(com.intellij.psi.PsiElement) DeleteUnusedElementBase(org.intellij.lang.xpath.xslt.quickfix.DeleteUnusedElementBase) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1 SearchScope (com.intellij.psi.search.SearchScope)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlTag (com.intellij.psi.xml.XmlTag)1 XsltParameter (org.intellij.lang.xpath.xslt.psi.XsltParameter)1 DeleteUnusedElementBase (org.intellij.lang.xpath.xslt.quickfix.DeleteUnusedElementBase)1 DeleteUnusedParameterFix (org.intellij.lang.xpath.xslt.quickfix.DeleteUnusedParameterFix)1 DeleteUnusedVariableFix (org.intellij.lang.xpath.xslt.quickfix.DeleteUnusedVariableFix)1