use of com.intellij.psi.impl.source.xml.XmlAttributeImpl in project intellij-plugins by JetBrains.
the class MxmlLanguageTagsUtil method addErrorMessage.
private static void addErrorMessage(final XmlElement element, final String message, final Validator.ValidationHost host, @NotNull IntentionAction... intentionActions) {
PsiElement target = element;
PsiElement secondaryTarget = null;
if (element instanceof XmlAttributeValue) {
final ASTNode node = element.getNode();
final ASTNode value = node == null ? null : XmlChildRole.ATTRIBUTE_VALUE_VALUE_FINDER.findChild(node);
if (value instanceof PsiElement) {
target = (PsiElement) value;
}
} else if (element instanceof XmlAttributeImpl) {
target = ((XmlAttributeImpl) element).getNameElement();
} else if (element instanceof XmlTag) {
target = XmlTagUtil.getStartTagNameElement((XmlTag) element);
secondaryTarget = XmlTagUtil.getEndTagNameElement((XmlTag) element);
}
if (host instanceof IdeValidationHost) {
if (target != null) {
((IdeValidationHost) host).addMessageWithFixes(target, message, Validator.ValidationHost.ErrorType.ERROR, intentionActions);
}
if (secondaryTarget != null) {
((IdeValidationHost) host).addMessageWithFixes(secondaryTarget, message, Validator.ValidationHost.ErrorType.ERROR, intentionActions);
}
} else {
if (target != null) {
host.addMessage(target, message, Validator.ValidationHost.ErrorType.ERROR);
}
if (secondaryTarget != null) {
host.addMessage(secondaryTarget, message, Validator.ValidationHost.ErrorType.ERROR);
}
}
}
use of com.intellij.psi.impl.source.xml.XmlAttributeImpl in project intellij-community by JetBrains.
the class NSDeclTracker method queryCount.
@SuppressWarnings({ "AutoUnboxing" })
private synchronized long queryCount() {
for (XmlAttribute decl : myNSDecls) {
if (!decl.isValid()) {
return update();
}
final Integer modCount = decl.getUserData(MOD_COUNT);
if (modCount != null && ((XmlAttributeImpl) decl).getModificationCount() != modCount) {
return update();
}
}
final ArrayList<XmlAttribute> list = getNSDecls(false);
if (!list.equals(myNSDecls)) {
return update();
}
myRootCount = myRootTag.getModificationCount();
return myCount;
}
use of com.intellij.psi.impl.source.xml.XmlAttributeImpl in project intellij-community by JetBrains.
the class XmlAttributeReferenceCompletionProvider method addVariants.
private static void addVariants(final CompletionResultSet result, final XmlAttribute[] attributes, final XmlAttributeDescriptor[] descriptors, XmlAttribute attribute, @Nullable InsertHandler<LookupElement> replacementInsertHandler) {
final XmlTag tag = attribute.getParent();
final PsiFile file = tag.getContainingFile();
final XmlExtension extension = XmlExtension.getExtension(file);
final String prefix = attribute.getName().contains(":") && ((XmlAttributeImpl) attribute).getRealLocalName().length() > 0 ? attribute.getNamespacePrefix() + ":" : null;
for (XmlAttributeDescriptor descriptor : descriptors) {
if (isValidVariant(attribute, descriptor, attributes, extension)) {
String name = descriptor.getName(tag);
InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE;
if (tag instanceof HtmlTag && HtmlUtil.isShortNotationOfBooleanAttributePreferred() && HtmlUtil.isBooleanAttribute(descriptor, tag)) {
insertHandler = null;
}
if (replacementInsertHandler != null) {
insertHandler = replacementInsertHandler;
} else if (descriptor instanceof NamespaceAwareXmlAttributeDescriptor) {
final String namespace = ((NamespaceAwareXmlAttributeDescriptor) descriptor).getNamespace(tag);
if (file instanceof XmlFile && namespace != null && namespace.length() > 0 && !name.contains(":") && tag.getPrefixByNamespace(namespace) == null) {
insertHandler = new XmlAttributeInsertHandler(namespace);
}
}
if (prefix == null || name.startsWith(prefix)) {
if (prefix != null && name.length() > prefix.length()) {
name = descriptor.getName(tag).substring(prefix.length());
}
LookupElementBuilder element = LookupElementBuilder.create(name);
if (descriptor instanceof PsiPresentableMetaData) {
element = element.withIcon(((PsiPresentableMetaData) descriptor).getIcon());
}
final int separator = name.indexOf(':');
if (separator > 0) {
element = element.withLookupString(name.substring(separator + 1));
}
element = element.withCaseSensitivity(!(descriptor instanceof HtmlAttributeDescriptorImpl)).withInsertHandler(insertHandler);
result.addElement(descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) : HtmlUtil.isOwnHtmlAttribute(descriptor) ? PrioritizedLookupElement.withPriority(element, 50) : element);
}
}
}
}
Aggregations