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