Search in sources :

Example 26 with XmlAttribute

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

the class XsltVariableImpl method getType.

@NotNull
public XPathType getType() {
    final XPathType declaredType = XsltCodeInsightUtil.getDeclaredType(getTag());
    if (declaredType != null) {
        return declaredType;
    }
    final XmlAttribute attr = getTag().getAttribute("type", XsltSupport.PLUGIN_EXTENSIONS_NS);
    if (attr != null) {
        return XPathType.fromString(attr.getValue());
    }
    final XPathExpression value = getValue();
    if (value instanceof XPathVariableReference) {
        // recursive reference <xsl:variable name="foo" select="$foo" />
        final XPathVariableReference reference = (XPathVariableReference) value;
        if (reference.resolve() == this) {
            return XPathType.UNKNOWN;
        }
    }
    return value != null ? value.getType() : XPathType.UNKNOWN;
}
Also used : XPathExpression(org.intellij.lang.xpath.psi.XPathExpression) XPathType(org.intellij.lang.xpath.psi.XPathType) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XPathVariableReference(org.intellij.lang.xpath.psi.XPathVariableReference) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with XmlAttribute

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

the class XmlEqTypedHandler method beforeCharTyped.

@Override
public Result beforeCharTyped(char c, Project project, Editor editor, PsiFile file, FileType fileType) {
    if (c == '=' && WebEditorOptions.getInstance().isInsertQuotesForAttributeValue()) {
        if (XmlGtTypedHandler.fileContainsXmlLanguage(file)) {
            PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
            PsiElement at = file.findElementAt(editor.getCaretModel().getOffset() - 1);
            PsiElement atParent = at != null ? at.getParent() : null;
            if (atParent instanceof XmlAttribute && ((XmlAttribute) atParent).getValueElement() == null) {
                needToInsertQuotes = ((XmlAttribute) atParent).getValueElement() == null;
            }
        }
    }
    return super.beforeCharTyped(c, project, editor, file, fileType);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) PsiElement(com.intellij.psi.PsiElement)

Example 28 with XmlAttribute

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

the class EmmetUpdateTagAction method doUpdateTag.

public void doUpdateTag(@NotNull final String abbreviation, @NotNull final XmlTag tag, @NotNull PsiFile file, @NotNull Editor editor) throws EmmetException {
    if (tag.isValid()) {
        String templateText = expandTemplate(abbreviation, file, editor);
        final Collection<String> classNames = ContainerUtil.newLinkedHashSet();
        ContainerUtil.addAll(classNames, HtmlUtil.splitClassNames(tag.getAttributeValue(HtmlUtil.CLASS_ATTRIBUTE_NAME)));
        final Map<String, String> attributes = ContainerUtil.newLinkedHashMap();
        final Ref<String> newTagName = Ref.create();
        processTags(file.getProject(), templateText, (tag1, firstTag) -> {
            if (firstTag && !abbreviation.isEmpty() && StringUtil.isJavaIdentifierPart(abbreviation.charAt(0))) {
                newTagName.set(tag1.getName());
            }
            for (String clazz : HtmlUtil.splitClassNames(tag1.getAttributeValue(HtmlUtil.CLASS_ATTRIBUTE_NAME))) {
                if (StringUtil.startsWithChar(clazz, '+')) {
                    classNames.add(clazz.substring(1));
                } else if (StringUtil.startsWithChar(clazz, '-')) {
                    classNames.remove(clazz.substring(1));
                } else {
                    classNames.clear();
                    classNames.add(clazz);
                }
            }
            if (!firstTag) {
                classNames.add(tag1.getName());
            }
            for (XmlAttribute xmlAttribute : tag1.getAttributes()) {
                if (!HtmlUtil.CLASS_ATTRIBUTE_NAME.equalsIgnoreCase(xmlAttribute.getName())) {
                    attributes.put(xmlAttribute.getName(), StringUtil.notNullize(xmlAttribute.getValue()));
                }
            }
            return true;
        });
        doUpdateTagAttributes(tag, file, newTagName.get(), classNames, attributes).execute();
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute)

Example 29 with XmlAttribute

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

the class XmlEmmetParser method parseAttributeName.

@Nullable
private String parseAttributeName() {
    String name = "";
    ZenCodingToken token = getToken();
    while (token != null) {
        if ((token instanceof IdentifierToken)) {
            name += ((IdentifierToken) token).getText();
        } else if (token instanceof OperationToken && (((OperationToken) token).getSign() == '+' || ((OperationToken) token).getSign() == '-')) {
            name += ((OperationToken) token).getSign();
        } else {
            break;
        }
        advance();
        token = getToken();
    }
    if (name.isEmpty()) {
        return null;
    }
    final XmlTag tag = XmlElementFactory.getInstance(myCallback.getProject()).createTagFromText("<tag " + name + "=''/>", StdLanguages.HTML);
    XmlAttribute[] attributes = tag.getAttributes();
    if (attributes.length == 1) {
        return attributes[0].getName();
    } else {
        return null;
    }
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with XmlAttribute

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

the class XslZenCodingFilter method filterNode.

@NotNull
@Override
public GenerationNode filterNode(@NotNull final GenerationNode node) {
    TemplateToken token = node.getTemplateToken();
    final XmlTag tag = token != null ? token.getXmlTag() : null;
    if (tag != null) {
        if (token.getAttributes().containsKey(SELECT_ATTR_NAME)) {
            return node;
        }
        ApplicationManager.getApplication().runWriteAction(() -> {
            if (isOurTag(tag, node.getChildren().size() > 0)) {
                XmlAttribute attribute = tag.getAttribute(SELECT_ATTR_NAME);
                if (attribute != null) {
                    attribute.delete();
                }
            }
        });
        return node;
    }
    return node;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) TemplateToken(com.intellij.codeInsight.template.emmet.tokens.TemplateToken) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

XmlAttribute (com.intellij.psi.xml.XmlAttribute)220 XmlTag (com.intellij.psi.xml.XmlTag)116 PsiElement (com.intellij.psi.PsiElement)60 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)57 NotNull (org.jetbrains.annotations.NotNull)44 XmlFile (com.intellij.psi.xml.XmlFile)37 Nullable (org.jetbrains.annotations.Nullable)27 Project (com.intellij.openapi.project.Project)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)20 TextRange (com.intellij.openapi.util.TextRange)18 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)18 ArrayList (java.util.ArrayList)18 PsiFile (com.intellij.psi.PsiFile)17 PsiReference (com.intellij.psi.PsiReference)17 IncorrectOperationException (com.intellij.util.IncorrectOperationException)10 DomElement (com.intellij.util.xml.DomElement)10 Result (com.intellij.openapi.application.Result)9 XmlElementDescriptor (com.intellij.xml.XmlElementDescriptor)9 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)8 XmlElement (com.intellij.psi.xml.XmlElement)6