Search in sources :

Example 1 with RenameVariableFix

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

the class VariableShadowingInspection method buildVisitor.

@NotNull
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    if (!(holder.getFile() instanceof XmlFile))
        return PsiElementVisitor.EMPTY_VISITOR;
    return new XmlElementVisitor() {

        @Override
        public void visitXmlTag(final XmlTag tag) {
            final XmlAttribute nameAttr = tag.getAttribute("name", null);
            if (nameAttr == null || PsiTreeUtil.hasErrorElements(nameAttr))
                return;
            if (XsltSupport.isVariableOrParam(tag)) {
                final XmlTag shadowedVariable = DeclarationChecker.getInstance((XmlFile) tag.getContainingFile()).getShadowedVariable(tag);
                if (shadowedVariable != null) {
                    final String innerKind = XsltSupport.isParam(tag) ? "Parameter" : "Variable";
                    final String outerKind = XsltSupport.isParam(shadowedVariable) ? "parameter" : "variable";
                    final LocalQuickFix fix1 = new RenameVariableFix(tag, "local").createQuickFix(isOnTheFly);
                    final LocalQuickFix fix2 = new RenameVariableFix(shadowedVariable, "outer").createQuickFix(isOnTheFly);
                    final XmlAttribute name = tag.getAttribute("name");
                    assert name != null;
                    final PsiElement token = XsltSupport.getAttValueToken(name);
                    assert token != null;
                    holder.registerProblem(token, innerKind + " '" + name.getValue() + "' shadows " + outerKind, AbstractFix.createFixes(fix1, fix2));
                }
            }
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) RenameVariableFix(org.intellij.lang.xpath.xslt.quickfix.RenameVariableFix) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 PsiElement (com.intellij.psi.PsiElement)1 XmlElementVisitor (com.intellij.psi.XmlElementVisitor)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 RenameVariableFix (org.intellij.lang.xpath.xslt.quickfix.RenameVariableFix)1 NotNull (org.jetbrains.annotations.NotNull)1