Search in sources :

Example 1 with XsltTemplate

use of org.intellij.lang.xpath.xslt.psi.XsltTemplate 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;
}
Also used : XPathVariable(org.intellij.lang.xpath.psi.XPathVariable) PsiReference(com.intellij.psi.PsiReference) XsltParameter(org.intellij.lang.xpath.xslt.psi.XsltParameter) XsltTemplate(org.intellij.lang.xpath.xslt.psi.XsltTemplate)

Example 2 with XsltTemplate

use of org.intellij.lang.xpath.xslt.psi.XsltTemplate in project intellij-community by JetBrains.

the class XsltParameterImpl method getLocalUseScope.

@NotNull
@Override
public SearchScope getLocalUseScope() {
    final XmlTag tag = getTag();
    if (!tag.isValid()) {
        return getDefaultUseScope();
    }
    final XsltTemplate template = getTemplate();
    if (template == null) {
        return getDefaultUseScope();
    }
    if (template.getName() == null) {
        return getDefaultUseScope();
    }
    final XmlFile file = (XmlFile) tag.getContainingFile();
    if (!XsltIncludeIndex.processBackwardDependencies(file, new CommonProcessors.FindFirstProcessor<>())) {
        // processor found something
        return getDefaultUseScope();
    }
    return new LocalSearchScope(file);
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) XmlFile(com.intellij.psi.xml.XmlFile) XsltTemplate(org.intellij.lang.xpath.xslt.psi.XsltTemplate) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with XsltTemplate

use of org.intellij.lang.xpath.xslt.psi.XsltTemplate in project intellij-community by JetBrains.

the class DeleteUnusedParameterFix method deleteElement.

protected void deleteElement(@NotNull XsltParameter obj) throws IncorrectOperationException {
    final XsltTemplate template = XsltCodeInsightUtil.getTemplate(obj.getTag(), false);
    if (template == null || template.getMatchExpression() == null) {
        final SearchScope searchScope = obj.getResolveScope();
        for (PsiReference reference : ReferencesSearch.search(obj, searchScope, false)) {
            final XmlTag t = PsiTreeUtil.getContextOfType(reference.getElement(), XmlTag.class, true);
            if (t != null && XsltSupport.XSLT_NS.equals(t.getNamespace())) {
                assert "with-param".equals(t.getLocalName());
                t.delete();
            }
        }
    }
    super.deleteElement(obj);
}
Also used : SearchScope(com.intellij.psi.search.SearchScope) PsiReference(com.intellij.psi.PsiReference) XsltTemplate(org.intellij.lang.xpath.xslt.psi.XsltTemplate) XmlTag(com.intellij.psi.xml.XmlTag)

Example 4 with XsltTemplate

use of org.intellij.lang.xpath.xslt.psi.XsltTemplate in project intellij-community by JetBrains.

the class XsltDeclarationInspection 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 XsltNamedElement instance = getXsltElementFactory().wrapElement(tag, XsltNamedElement.class);
                checkDeclaration(instance, nameAttr.getValue(), holder);
            } else if (XsltSupport.isTemplate(tag)) {
                final XsltTemplate tmpl = getXsltElementFactory().wrapElement(tag, XsltTemplate.class);
                checkDeclaration(tmpl, nameAttr.getValue(), holder);
            }
        }

        private void checkDeclaration(final XsltNamedElement element, final String name, ProblemsHolder holder) {
            final XmlTag tag = element.getTag();
            final PsiElement token = element.getNameIdentifier();
            if (name == null || name.length() == 0) {
                if (token != null) {
                    holder.registerProblem(token, "Empty name not permitted");
                } else {
                    final XmlAttribute attribute = element.getNameAttribute();
                    if (attribute != null) {
                        final XmlAttributeValue e = attribute.getValueElement();
                        if (e != null) {
                            holder.registerProblem(e, "Empty name not permitted");
                        }
                    }
                }
            } else if (!isLegalName(name, holder.getManager().getProject())) {
                assert token != null;
                holder.registerProblem(token, "Illegal name");
            } else {
                assert token != null;
                final XmlFile file = (XmlFile) tag.getContainingFile();
                final XmlTag duplicatedSymbol = DeclarationChecker.getInstance(file).getDuplicatedSymbol(tag);
                if (duplicatedSymbol != null) {
                    if (duplicatedSymbol.getContainingFile() == file) {
                        holder.registerProblem(token, "Duplicate declaration");
                    } else {
                        holder.registerProblem(token, "Duplicates declaration from '" + duplicatedSymbol.getContainingFile().getName() + "'");
                    }
                }
            }
        }

        private boolean isLegalName(String value, Project project) {
            return getNamesValidator().isIdentifier(value, project);
        }
    };
}
Also used : XmlElementVisitor(com.intellij.psi.XmlElementVisitor) Project(com.intellij.openapi.project.Project) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XsltNamedElement(org.intellij.lang.xpath.xslt.psi.XsltNamedElement) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XsltTemplate(org.intellij.lang.xpath.xslt.psi.XsltTemplate) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with XsltTemplate

use of org.intellij.lang.xpath.xslt.psi.XsltTemplate in project intellij-community by JetBrains.

the class MatchTemplateMatcher method matches.

public boolean matches(XmlTag element) {
    if (super.matches(element) && element.getAttribute("match", null) != null) {
        final XsltTemplate t = XsltElementFactory.getInstance().wrapElement(element, XsltTemplate.class);
        final QName mode = t.getMode();
        if (mode != null) {
            if (QNameUtil.equal(myMode, mode)) {
                return true;
            }
        } else {
            return myMode == null;
        }
    }
    return false;
}
Also used : QName(javax.xml.namespace.QName) XsltTemplate(org.intellij.lang.xpath.xslt.psi.XsltTemplate)

Aggregations

XsltTemplate (org.intellij.lang.xpath.xslt.psi.XsltTemplate)5 XmlTag (com.intellij.psi.xml.XmlTag)3 PsiReference (com.intellij.psi.PsiReference)2 XmlFile (com.intellij.psi.xml.XmlFile)2 NotNull (org.jetbrains.annotations.NotNull)2 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 XmlElementVisitor (com.intellij.psi.XmlElementVisitor)1 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1 SearchScope (com.intellij.psi.search.SearchScope)1 XmlAttribute (com.intellij.psi.xml.XmlAttribute)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1 QName (javax.xml.namespace.QName)1 XPathVariable (org.intellij.lang.xpath.psi.XPathVariable)1 XsltNamedElement (org.intellij.lang.xpath.xslt.psi.XsltNamedElement)1 XsltParameter (org.intellij.lang.xpath.xslt.psi.XsltParameter)1