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));
}
}
}
};
}
Aggregations