use of org.intellij.lang.xpath.xslt.psi.XsltParameter 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);
}
}
use of org.intellij.lang.xpath.xslt.psi.XsltParameter in project intellij-community by JetBrains.
the class XsltValidator method isUnused.
private static boolean isUnused(PsiElement obj, Query<PsiReference> query) {
if (obj instanceof XsltParameter) {
final Collection<PsiReference> references = query.findAll();
int n = references.size();
for (PsiReference reference : references) {
final PsiElement element = reference.getElement();
if (element instanceof XmlAttributeValue) {
final XmlAttribute parent = (XmlAttribute) element.getParent();
if ("name".equals(parent.getName())) {
final XmlTag tag = parent.getParent();
if (tag != null && "with-param".equals(tag.getLocalName())) {
n--;
}
}
}
}
return n == 0;
} else {
return query.findFirst() == null;
}
}
use of org.intellij.lang.xpath.xslt.psi.XsltParameter in project intellij-community by JetBrains.
the class XsltVariableContext method isReferenceTo.
public boolean isReferenceTo(PsiElement element, XPathVariableReference reference) {
if (element instanceof XsltParameter) {
final XsltTemplate template = XsltCodeInsightUtil.getTemplate(element, false);
if (template == null || template.getMatchExpression() == null)
return false;
final XPathVariable t = reference.resolve();
final PsiReference[] references = element.getReferences();
for (PsiReference r : references) {
if (r.isReferenceTo(t))
return true;
}
}
return false;
}
use of org.intellij.lang.xpath.xslt.psi.XsltParameter in project intellij-community by JetBrains.
the class XsltTemplateImpl method getParameters.
@NotNull
public XsltParameter[] getParameters() {
final PsiElement[] elements = ResolveUtil.collect(new ParamMatcher(getTag(), null));
final XsltParameter[] xsltParameters = new XsltParameter[elements.length];
//noinspection SuspiciousSystemArraycopy
System.arraycopy(elements, 0, xsltParameters, 0, elements.length);
return xsltParameters;
}
Aggregations