use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class PropertyProcessor method processClass.
// see ClassProperty test
private void processClass(XmlElementValueProvider valueProvider) throws InvalidPropertyException {
JSClass jsClass = valueProvider.getJsClass();
// IDEA-73537, cannot use only valueProvider.getJsClass()
if (jsClass == null) {
String trimmed = valueProvider.getTrimmed();
XmlElement exceptionElement = valueProvider.getElement();
if (trimmed.isEmpty() && valueProvider.getElement() instanceof XmlTag) {
// case 1, fx:Class
final XmlTag propertyTag = (XmlTag) valueProvider.getElement();
final XmlTag[] propertyTagSubTags = propertyTag.getSubTags();
if (propertyTagSubTags.length == 1) {
final XmlTag contentTag = propertyTagSubTags[0];
exceptionElement = contentTag;
final XmlElementDescriptor contentTagDescriptor = contentTag.getDescriptor();
if (contentTagDescriptor instanceof ClassBackedElementDescriptor && AsCommonTypeNames.CLASS.equals(contentTagDescriptor.getQualifiedName())) {
trimmed = contentTag.getValue().getTrimmedText();
}
}
}
if (trimmed.isEmpty()) {
throw new InvalidPropertyException(exceptionElement, "invalid.class.value");
}
final Module module = ModuleUtilCore.findModuleForPsiElement(valueProvider.getElement());
if (module != null) {
jsClass = (JSClass) ActionScriptClassResolver.findClassByQNameStatic(trimmed, module.getModuleWithDependenciesAndLibrariesScope(false));
}
if (jsClass == null) {
throw new InvalidPropertyException(exceptionElement, "unresolved.class", trimmed);
}
}
if (InjectionUtil.isProjectComponent(jsClass)) {
if (ActionScriptClassResolver.isParentClass(jsClass, "spark.components.View")) {
int projectComponentFactoryId = getProjectComponentFactoryId(jsClass);
assert projectComponentFactoryId != -1;
writer.projectClassReference(projectComponentFactoryId);
} else {
throw new InvalidPropertyException(valueProvider.getElement(), "class.reference.support.only.skin.class.or.view", jsClass.getQualifiedName());
}
} else {
writer.classReference(jsClass.getQualifiedName());
}
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class CssWriter method writeSelectors.
private void writeSelectors(@NotNull CssRuleset ruleset, @NotNull PrimitiveAmfOutputStream out, @NotNull Module module) {
CssSelector[] selectors = ruleset.getSelectors();
out.write(selectors.length);
for (CssSelector selector : selectors) {
CssSimpleSelector[] simpleSelectors = selector.getSimpleSelectors();
out.write(simpleSelectors.length);
for (CssSimpleSelector simpleSelector : simpleSelectors) {
// subject
if (simpleSelector.isUniversalSelector()) {
out.write(0);
} else {
XmlElementDescriptor typeSelectorDescriptor = FlexCssElementDescriptorProvider.getTypeSelectorDescriptor(simpleSelector, module);
String subject = simpleSelector.getElementName();
if (typeSelectorDescriptor == null) {
if (!subject.equals("global")) {
LOG.warn("unqualified type selector " + simpleSelector.getText());
}
stringWriter.write(subject, out);
out.write(0);
} else {
stringWriter.write(typeSelectorDescriptor.getQualifiedName(), out);
stringWriter.write(subject, out);
stringWriter.writeNullable(simpleSelector.getNamespaceName(), out);
}
}
// conditions
CssSelectorSuffix[] selectorSuffixes = simpleSelector.getSelectorSuffixes();
out.write(selectorSuffixes.length);
for (CssSelectorSuffix selectorSuffix : selectorSuffixes) {
if (selectorSuffix instanceof CssClass) {
out.write(FlexCssConditionKind.CLASS);
} else if (selectorSuffix instanceof CssIdSelector) {
out.write(FlexCssConditionKind.ID);
} else if (selectorSuffix instanceof CssPseudoClass) {
out.write(FlexCssConditionKind.PSEUDO);
} else {
LOG.error("unknown selector suffix " + selectorSuffix.getText());
}
stringWriter.write(selectorSuffix.getName(), out);
}
}
}
}
use of com.intellij.xml.XmlElementDescriptor in project intellij-plugins by JetBrains.
the class IncrementalDocumentSynchronizer method findSupportedTarget.
@Nullable
private XmlElementValueProvider findSupportedTarget() {
PsiElement element = event.getParent();
// if we change attribute value via line marker, so, event.getParent() will be XmlAttribute instead of XmlAttributeValue
while (!(element instanceof XmlAttribute)) {
element = element.getParent();
if (element instanceof XmlTag) {
XmlTag tag = (XmlTag) element;
XmlElementDescriptor descriptor = tag.getDescriptor();
if (descriptor instanceof ClassBackedElementDescriptor) {
ClassBackedElementDescriptor classBackedElementDescriptor = (ClassBackedElementDescriptor) descriptor;
if (classBackedElementDescriptor.isPredefined()) {
isStyleDataChanged = descriptor.getQualifiedName().equals(FlexPredefinedTagNames.STYLE);
isSkippedXml = isStyleDataChanged || (!MxmlUtil.isObjectLanguageTag(tag) && !descriptor.getQualifiedName().equals(FlexPredefinedTagNames.DECLARATIONS));
}
}
return null;
} else if (element instanceof PsiFile || element == null) {
return null;
}
}
XmlAttribute attribute = (XmlAttribute) element;
if (JavaScriptSupportLoader.MXML_URI3.equals(attribute.getNamespace()) || attribute.getValueElement() == null) {
return null;
}
XmlAttributeDescriptor xmlDescriptor = attribute.getDescriptor();
if (!(xmlDescriptor instanceof AnnotationBackedDescriptor)) {
return null;
}
AnnotationBackedDescriptor descriptor = (AnnotationBackedDescriptor) xmlDescriptor;
if (descriptor.isPredefined() || MxmlUtil.isIdLanguageAttribute(attribute, descriptor)) {
return null;
}
// todo incremental sync for state-specific attributes
PsiReference[] references = attribute.getReferences();
if (references.length > 1) {
for (int i = references.length - 1; i > -1; i--) {
PsiReference psiReference = references[i];
if (psiReference instanceof FlexReferenceContributor.StateReference) {
return null;
}
}
} else {
String prefix = attribute.getName() + '.';
for (XmlAttribute anotherAttribute : attribute.getParent().getAttributes()) {
if (anotherAttribute != attribute && anotherAttribute.getName().startsWith(prefix)) {
return null;
}
}
}
XmlAttributeValueProvider valueProvider = new XmlAttributeValueProvider(attribute);
// skip binding
PsiLanguageInjectionHost injectedHost = valueProvider.getInjectedHost();
if (injectedHost != null && InjectedLanguageUtil.hasInjections(injectedHost)) {
return null;
}
return valueProvider;
}
use of com.intellij.xml.XmlElementDescriptor in project android by JetBrains.
the class AndroidLayoutXmlTagNameProvider method addTagNameVariants.
@Override
public void addTagNameVariants(List<LookupElement> elements, @NotNull XmlTag tag, String prefix) {
final PsiFile file = tag.getContainingFile();
if (!(file instanceof XmlFile && LayoutDomFileDescription.isLayoutFile((XmlFile) file))) {
// Only use this provider for Android layout files
return;
}
XmlExtension xmlExtension = XmlExtension.getExtension(file);
List<XmlElementDescriptor> variants = TagNameVariantCollector.getTagDescriptors(tag, NAMESPACES, null);
// Find the framework widgets that have a support library alternative
Set<String> supportAlternatives = Sets.newHashSet();
for (XmlElementDescriptor descriptor : variants) {
String qualifiedName = descriptor.getName(tag);
if (qualifiedName.startsWith(ANDROID_SUPPORT_PKG_PREFIX)) {
supportAlternatives.add(AndroidUtils.getUnqualifiedName(qualifiedName));
}
}
final Set<String> addedNames = Sets.newHashSet();
for (XmlElementDescriptor descriptor : variants) {
String qualifiedName = descriptor.getName(tag);
if (!addedNames.add(qualifiedName)) {
continue;
}
final String simpleName = AndroidUtils.getUnqualifiedName(qualifiedName);
// Creating LookupElementBuilder with PsiElement gives an ability to show documentation during completion time
PsiElement declaration = descriptor.getDeclaration();
LookupElementBuilder lookupElement = declaration == null ? LookupElementBuilder.create(qualifiedName) : LookupElementBuilder.create(declaration, qualifiedName);
final boolean isDeprecated = isDeclarationDeprecated(declaration);
if (isDeprecated) {
lookupElement = lookupElement.withStrikeoutness(true);
}
if (simpleName != null) {
lookupElement = lookupElement.withLookupString(simpleName);
}
// This statement preserves them in autocompletion.
if (descriptor instanceof PsiPresentableMetaData) {
lookupElement = lookupElement.withIcon(((PsiPresentableMetaData) descriptor).getIcon());
}
// Using insert handler is required for, e.g. automatic insertion of required fields in Android layout XMLs
if (xmlExtension.useXmlTagInsertHandler()) {
lookupElement = lookupElement.withInsertHandler(XmlTagInsertHandler.INSTANCE);
}
// Deprecated tag names are supposed to be shown below non-deprecated tags
int priority = isDeprecated ? 10 : 100;
if (simpleName == null) {
if (supportAlternatives.contains(qualifiedName)) {
// This component has a support library alternative so lower the priority so the support component is shown at the top.
priority -= 1;
} else {
// The component doesn't have an alternative in the support library so push it to the top.
priority += 10;
}
}
elements.add(PrioritizedLookupElement.withPriority(lookupElement, priority));
}
}
use of com.intellij.xml.XmlElementDescriptor in project android by JetBrains.
the class AndroidXmlTagDescriptor method getElementDescriptor.
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
final XmlElementDescriptor descriptor = myParentDescriptor.getElementDescriptor(childTag, contextTag);
if (descriptor != null) {
return descriptor;
}
final XmlNSDescriptor nsDescriptor = getNSDescriptor();
return nsDescriptor != null ? new AndroidAnyTagDescriptor(nsDescriptor) : null;
}
Aggregations