Search in sources :

Example 21 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue 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 22 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.

the class LinkedToHtmlFilesContributor method fillRelatedFiles.

@Override
public void fillRelatedFiles(@NotNull final XmlFile xmlFile, @NotNull final Set<PsiFile> resultSet) {
    HtmlLinkUtil.processLinks(xmlFile, tag -> {
        final XmlAttribute attribute = tag.getAttribute("href");
        if (attribute == null) {
            return true;
        }
        final XmlAttributeValue link = attribute.getValueElement();
        if (link == null) {
            return true;
        }
        for (PsiReference reference : link.getReferences()) {
            if (reference instanceof PsiPolyVariantReference) {
                final ResolveResult[] results = ((PsiPolyVariantReference) reference).multiResolve(false);
                for (ResolveResult result : results) {
                    final PsiElement resolvedElement = result.getElement();
                    if (resolvedElement instanceof PsiFile) {
                        resultSet.add((PsiFile) resolvedElement);
                    }
                }
            } else {
                final PsiElement resolvedElement = reference.resolve();
                if (resolvedElement instanceof PsiFile) {
                    resultSet.add((PsiFile) resolvedElement);
                }
            }
        }
        return true;
    });
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Example 23 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.

the class XmlDuplicatedIdInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new XmlElementVisitor() {

        @Override
        public void visitXmlAttributeValue(final XmlAttributeValue value) {
            if (value.getTextRange().isEmpty()) {
                return;
            }
            final PsiFile file = value.getContainingFile();
            if (!(file instanceof XmlFile)) {
                return;
            }
            PsiFile baseFile = PsiUtilCore.getTemplateLanguageFile(file);
            if (baseFile != file && !(baseFile instanceof XmlFile)) {
                return;
            }
            final XmlRefCountHolder refHolder = XmlRefCountHolder.getRefCountHolder((XmlFile) file);
            if (refHolder == null)
                return;
            final PsiElement parent = value.getParent();
            if (!(parent instanceof XmlAttribute))
                return;
            final XmlTag tag = (XmlTag) parent.getParent();
            if (tag == null)
                return;
            checkValue(value, (XmlFile) file, refHolder, tag, holder);
        }
    };
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.

the class RngRefImpl method getPattern.

@Override
public Define getPattern() {
    final XmlAttributeValue value = getName().getXmlAttributeValue();
    if (value == null)
        return null;
    final String name = getReferencedName();
    if (name == null) {
        return null;
    }
    final RngGrammar scope = getScope();
    if (scope == null) {
        return null;
    }
    final Set<Define> defines = DefinitionResolver.resolve(scope, name);
    // TODO: honor combine & return virtual element if defines.size() > 1
    return defines != null && defines.size() > 0 ? defines.iterator().next() : null;
}
Also used : Define(org.intellij.plugins.relaxNG.model.Define) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) RngGrammar(org.intellij.plugins.relaxNG.xml.dom.RngGrammar)

Example 25 with XmlAttributeValue

use of com.intellij.psi.xml.XmlAttributeValue in project intellij-community by JetBrains.

the class SpellcheckingStrategy method getTokenizer.

@NotNull
public Tokenizer getTokenizer(PsiElement element) {
    if (element instanceof PsiWhiteSpace) {
        return EMPTY_TOKENIZER;
    }
    if (element instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost) element)) {
        return EMPTY_TOKENIZER;
    }
    if (element instanceof PsiNameIdentifierOwner)
        return new PsiIdentifierOwnerTokenizer();
    if (element instanceof PsiComment) {
        if (SuppressionUtil.isSuppressionComment(element)) {
            return EMPTY_TOKENIZER;
        }
        return myCommentTokenizer;
    }
    if (element instanceof XmlAttributeValue)
        return myXmlAttributeTokenizer;
    if (element instanceof PsiPlainText) {
        PsiFile file = element.getContainingFile();
        FileType fileType = file == null ? null : file.getFileType();
        if (fileType instanceof CustomSyntaxTableFileType) {
            return new CustomFileTypeTokenizer(((CustomSyntaxTableFileType) fileType).getSyntaxTable());
        }
        return TEXT_TOKENIZER;
    }
    if (element instanceof XmlToken) {
        if (((XmlToken) element).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
            PsiElement injection = InjectedLanguageManager.getInstance(element.getProject()).findInjectedElementAt(element.getContainingFile(), element.getTextOffset());
            if (injection == null) {
                return TEXT_TOKENIZER;
            }
        }
    }
    return EMPTY_TOKENIZER;
}
Also used : XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlToken(com.intellij.psi.xml.XmlToken) FileType(com.intellij.openapi.fileTypes.FileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)127 XmlAttribute (com.intellij.psi.xml.XmlAttribute)57 XmlTag (com.intellij.psi.xml.XmlTag)50 NotNull (org.jetbrains.annotations.NotNull)38 PsiElement (com.intellij.psi.PsiElement)31 Nullable (org.jetbrains.annotations.Nullable)24 PsiReference (com.intellij.psi.PsiReference)20 XmlFile (com.intellij.psi.xml.XmlFile)19 TextRange (com.intellij.openapi.util.TextRange)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)15 ArrayList (java.util.ArrayList)13 Project (com.intellij.openapi.project.Project)12 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 DomElement (com.intellij.util.xml.DomElement)9 PsiFile (com.intellij.psi.PsiFile)8 LazyValueResourceElementWrapper (org.jetbrains.android.dom.wrappers.LazyValueResourceElementWrapper)7 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 Module (com.intellij.openapi.module.Module)5 ValueResourceElementWrapper (org.jetbrains.android.dom.wrappers.ValueResourceElementWrapper)5