use of com.intellij.xml.XmlAttributeDescriptor in project intellij-plugins by JetBrains.
the class ActionScriptGenerateEventHandler method getEventType.
@Nullable
public static String getEventType(final XmlAttribute xmlAttribute) {
final XmlAttributeDescriptor descriptor = xmlAttribute == null ? null : xmlAttribute.getDescriptor();
final PsiElement declaration = descriptor instanceof AnnotationBackedDescriptor ? descriptor.getDeclaration() : null;
final PsiElement declarationParent = declaration == null ? null : declaration.getParent();
if (declaration instanceof JSAttributeNameValuePair && (((JSAttributeNameValuePair) declaration).getName() == null || "name".equals(((JSAttributeNameValuePair) declaration).getName())) && declarationParent instanceof JSAttribute && "Event".equals(((JSAttribute) declarationParent).getName())) {
return ((AnnotationBackedDescriptor) descriptor).getType();
}
return null;
}
use of com.intellij.xml.XmlAttributeDescriptor in project intellij-plugins by JetBrains.
the class MxmlWriter method processElements.
@SuppressWarnings("StatementWithEmptyBody")
private boolean processElements(final XmlTag tag, @Nullable final Context parentContext, final boolean allowIncludeInExcludeFrom, final int dataPosition, final int referencePosition, final boolean writeLocation, @Nullable final Condition<AnnotationBackedDescriptor> propertyFilter) {
boolean staticChild = true;
ByteRange dataRange = null;
// if state specific property before includeIn, state override data range wil be added before object data range, so,
// we keep current index and insert at the specified position
final Marker dataRangeAfterAnchor = writer.getBlockOut().getLastMarker();
if (writeLocation) {
out.writeUInt29(writer.P_FUD_RANGE_ID);
out.writeUInt29(rangeMarkers.size());
rangeMarkers.add(document.createRangeMarker(tag.getTextOffset(), tag.getTextOffset() + tag.getTextLength()));
}
assert !tagAttributeProcessContext.isCssRulesetDefined();
Context context = tagAttributeProcessContext;
if (parentContext != null && parentContext.getScope().staticObjectPointToScope) {
tagAttributeProcessContext.setTempParentScope(parentContext.getScope());
}
for (final XmlAttribute attribute : tag.getAttributes()) {
if (attribute.getValueElement() == null) {
// skip invalid - "<Button label/>"
continue;
}
final XmlAttributeDescriptor attributeDescriptor = attribute.getDescriptor();
final AnnotationBackedDescriptor descriptor;
if (attributeDescriptor instanceof AnnotationBackedDescriptor) {
descriptor = (AnnotationBackedDescriptor) attributeDescriptor;
// id and includeIn/excludeFrom only as attribute, not as tag
if (descriptor.isPredefined()) {
if (descriptor.hasIdType()) {
processObjectWithExplicitId(attribute.getValue(), context);
} else if (allowIncludeInExcludeFrom) {
String name = descriptor.getName();
boolean excludeFrom = false;
if (name.equals(FlexStateElementNames.INCLUDE_IN) || (excludeFrom = name.equals(FlexStateElementNames.EXCLUDE_FROM))) {
if (context == tagAttributeProcessContext) {
context = new DynamicObjectContext(tagAttributeProcessContext);
}
// must be before stateWriter.includeIn - start object data range before state data range
dataRange = writer.getBlockOut().startRange(dataPosition, dataRangeAfterAnchor);
((DynamicObjectContext) context).setDataRange(dataRange);
stateWriter.includeInOrExcludeFrom(attribute.getValueElement(), parentContext, (DynamicObjectContext) context, excludeFrom);
staticChild = false;
} else if (name.equals(FlexStateElementNames.ITEM_CREATION_POLICY)) {
if (attribute.getValue().charAt(0) == 'i') {
if (context == tagAttributeProcessContext) {
context = new DynamicObjectContext(tagAttributeProcessContext);
}
((DynamicObjectContext) context).setImmediateCreation(true);
}
} else if (name.equals(FlexStateElementNames.ITEM_DESTRUCTION_POLICY)) {
if (attribute.getValue().charAt(0) == 'a') {
stateWriter.applyItemAutoDestruction(context, parentContext);
}
}
}
} else if (propertyFilter != null && !propertyFilter.value(descriptor)) {
// skip
} else if (MxmlUtil.isIdLanguageAttribute(attribute, descriptor)) {
String explicitId = attribute.getValue();
writer.idMxmlProperty(explicitId);
processObjectWithExplicitId(explicitId, context);
} else if (descriptor.getTypeName() == null) {
//IDEA-73453
// skip
LOG.warn("Skip " + descriptor.getName() + " in " + tag.getText() + " due to IDEA-73453");
} else if (hasStates && stateWriter.checkStateSpecificPropertyValue(this, propertyProcessor, valueProviderFactory.create(attribute), descriptor, context)) {
// skip
} else {
writeAttributeBackedProperty(attribute, descriptor, context, context);
}
} else if (attributeDescriptor instanceof AnyXmlAttributeDescriptor) {
writeAttributeBackedProperty(attribute, new AnyXmlAttributeDescriptorWrapper(attributeDescriptor), context, context);
} else if (!attribute.isNamespaceDeclaration()) {
LOG.warn("unknown attribute (" + attribute.getText() + ") descriptor: " + (attributeDescriptor == null ? "null" : attributeDescriptor.toString()) + " of tag " + tag.getText());
}
}
if (!hasStates) {
assert context == tagAttributeProcessContext;
context = writer.createStaticContext(parentContext, referencePosition);
if (tagAttributeProcessContext.isCssRulesetDefined()) {
context.markCssRulesetDefined();
}
} else if (context == tagAttributeProcessContext) {
context = stateWriter.createContextForStaticBackSibling(allowIncludeInExcludeFrom, referencePosition, parentContext);
stateWriter.finalizeStateSpecificAttributesForStaticContext((StaticObjectContext) context, parentContext, this);
if (tagAttributeProcessContext.isCssRulesetDefined()) {
context.markCssRulesetDefined();
}
}
tagAttributeProcessContext.reset();
processTagChildren(tag, context, parentContext, true, null);
// width="150"><group>{cardtype} !!id (for binding target, RadioButton id="visa") allocation here!!</group></RadioButton>
if (dataPosition != -1) {
writer.endObject();
if (dataRange != null) {
writer.getBlockOut().endRange(dataRange);
}
}
return staticChild;
}
use of com.intellij.xml.XmlAttributeDescriptor 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.XmlAttributeDescriptor in project intellij-plugins by JetBrains.
the class ActionScriptAnnotatingVisitor method visitJSAttributeNameValuePair.
@Override
public void visitJSAttributeNameValuePair(@NotNull final JSAttributeNameValuePair attributeNameValuePair) {
final boolean ok = checkReferences(attributeNameValuePair);
if (!ok)
return;
// check if attribute value must be FQN of a class class inherited from some other class
if (attributeNameValuePair.getValueNode() == null)
return;
final PsiElement parent = attributeNameValuePair.getParent();
final XmlElementDescriptor descriptor = parent instanceof JSAttributeImpl ? ((JSAttributeImpl) parent).getBackedDescriptor() : null;
final String attributeName = StringUtil.notNullize(attributeNameValuePair.getName(), JSAttributeNameValuePair.DEFAULT);
final XmlAttributeDescriptor attributeDescriptor = descriptor == null ? null : descriptor.getAttributeDescriptor(attributeName, null);
final String baseClassFqns = attributeDescriptor == null ? null : attributeDescriptor.getDefaultValue();
if (baseClassFqns != null && !StringUtil.isEmptyOrSpaces(baseClassFqns)) {
final PsiReference[] references = attributeNameValuePair.getReferences();
PsiReference lastReference = references.length > 0 ? references[0] : null;
for (final PsiReference reference : references) {
if (reference.getRangeInElement().getEndOffset() > lastReference.getRangeInElement().getEndOffset()) {
lastReference = reference;
}
}
final PsiElement resolved = lastReference != null ? lastReference.resolve() : null;
if (resolved instanceof JSClass) {
boolean correctClass = false;
final Collection<String> resolvedBaseClasses = new ArrayList<>();
final GlobalSearchScope scope = JSResolveUtil.getResolveScope(attributeNameValuePair);
for (String baseClassFqn : StringUtil.split(baseClassFqns, ",")) {
if ("Object".equals(baseClassFqn)) {
correctClass = true;
break;
}
final PsiElement baseClass = ActionScriptClassResolver.findClassByQNameStatic(baseClassFqn, attributeNameValuePair);
if (baseClass instanceof JSClass) {
resolvedBaseClasses.add(baseClassFqn);
if (JSInheritanceUtil.isParentClass((JSClass) resolved, (JSClass) baseClass, false, scope)) {
correctClass = true;
break;
}
}
}
if (!correctClass) {
final String classesForMessage = resolvedBaseClasses.isEmpty() ? StringUtil.replace(baseClassFqns, ",", ", ") : StringUtil.join(resolvedBaseClasses, ", ");
myHolder.createErrorAnnotation(calcRangeForReferences(lastReference), JSBundle.message("javascript.expected.class.or.descendant", classesForMessage));
}
} else if (resolved != attributeNameValuePair) {
// for some reason int and uint are resolved to self-reference JSResolveUtil.MyResolveResult() instead of usual JSClass
myHolder.createErrorAnnotation(attributeNameValuePair.getValueNode(), JSBundle.message("javascript.qualified.class.name.expected"));
}
}
}
use of com.intellij.xml.XmlAttributeDescriptor in project android by JetBrains.
the class NlProperties method getPropertiesWithReadLock.
@NotNull
private Table<String, String, NlPropertyItem> getPropertiesWithReadLock(@NotNull AndroidFacet facet, @NotNull List<NlComponent> components, @NotNull GradleDependencyManager dependencyManager) {
ResourceManager localResourceManager = facet.getLocalResourceManager();
ResourceManager systemResourceManager = facet.getSystemResourceManager();
if (systemResourceManager == null) {
Logger.getInstance(NlProperties.class).error("No system resource manager for module: " + facet.getModule().getName());
return ImmutableTable.of();
}
AttributeDefinitions localAttrDefs = localResourceManager.getAttributeDefinitions();
AttributeDefinitions systemAttrDefs = systemResourceManager.getAttributeDefinitions();
Table<String, String, NlPropertyItem> combinedProperties = null;
for (NlComponent component : components) {
XmlTag tag = component.getTag();
if (!tag.isValid()) {
return ImmutableTable.of();
}
XmlElementDescriptor elementDescriptor = myDescriptorProvider.getDescriptor(tag);
if (elementDescriptor == null) {
return ImmutableTable.of();
}
XmlAttributeDescriptor[] descriptors = elementDescriptor.getAttributesDescriptors(tag);
Table<String, String, NlPropertyItem> properties = HashBasedTable.create(3, descriptors.length);
for (XmlAttributeDescriptor desc : descriptors) {
String namespace = getNamespace(desc, tag);
AttributeDefinitions attrDefs = NS_RESOURCES.equals(namespace) ? systemAttrDefs : localAttrDefs;
AttributeDefinition attrDef = attrDefs == null ? null : attrDefs.getAttrDefByName(desc.getName());
NlPropertyItem property = NlPropertyItem.create(components, desc, namespace, attrDef);
properties.put(StringUtil.notNullize(namespace), property.getName(), property);
}
// Exceptions:
switch(tag.getName()) {
case AUTO_COMPLETE_TEXT_VIEW:
// An AutoCompleteTextView has a popup that is created at runtime.
// Properties for this popup can be added to the AutoCompleteTextView tag.
properties.put(ANDROID_URI, ATTR_POPUP_BACKGROUND, NlPropertyItem.create(components, new AndroidAnyAttributeDescriptor(ATTR_POPUP_BACKGROUND), ANDROID_URI, systemAttrDefs != null ? systemAttrDefs.getAttrDefByName(ATTR_POPUP_BACKGROUND) : null));
break;
}
combinedProperties = combine(properties, combinedProperties);
}
// The following properties are deprecated in the support library and can be ignored by tools:
assert combinedProperties != null;
combinedProperties.remove(AUTO_URI, ATTR_PADDING_START);
combinedProperties.remove(AUTO_URI, ATTR_PADDING_END);
combinedProperties.remove(AUTO_URI, ATTR_THEME);
setUpDesignProperties(combinedProperties);
setUpSrcCompat(combinedProperties, facet, components, dependencyManager);
initStarState(combinedProperties);
//noinspection ConstantConditions
return combinedProperties;
}
Aggregations