use of com.intellij.flex.uiDesigner.mxml.PropertyProcessor.PropertyKind in project intellij-plugins by JetBrains.
the class StateWriter method checkStateSpecificPropertyValue.
public boolean checkStateSpecificPropertyValue(MxmlWriter mxmlWriter, PropertyProcessor propertyProcessor, XmlElementValueProvider valueProvider, AnnotationBackedDescriptor descriptor, @NotNull Context context) {
PsiReference[] references = valueProvider.getElement().getReferences();
if (references.length < 2) {
return false;
}
List<State> states = null;
for (int i = references.length - 1; i > -1; i--) {
PsiReference psiReference = references[i];
if (psiReference instanceof StateReference) {
// resolve is expensive for StateReference, so, we use string key (states name) instead of object key (states tag)
states = nameToState.get(psiReference.getCanonicalText());
break;
}
}
if (states == null) {
return false;
}
final List<State> filteredStates;
if (context instanceof DynamicObjectContext) {
final ArrayList<State> includeInStates = ((DynamicObjectContext) context).includeInStates;
filteredStates = new ArrayList<>(states.size());
for (State state : states) {
if (includeInStates.contains(state)) {
filteredStates.add(state);
} else {
MxmlWriter.LOG.warn("Skip " + valueProvider.getElement().getText() + " from " + state.name + " " + "due to element parent object included only in " + includeInStates);
}
}
if (filteredStates.isEmpty()) {
return true;
}
} else {
filteredStates = states;
}
ValueWriter valueWriter = null;
try {
valueWriter = propertyProcessor.process(valueProvider.getElement(), valueProvider, descriptor, context);
} catch (InvalidPropertyException ignored) {
}
if (valueWriter == null) {
// binding is not yet supported for state specific
return true;
}
final PrimitiveAmfOutputStream out = writer.getOut();
SetPropertyOrStyle override = new SetPropertyOrStyle(writer.getBlockOut().startRange());
writer.classOrPropertyName(propertyProcessor.isStyle() ? "com.intellij.flex.uiDesigner.flex.states.SetStyle" : "com.intellij.flex.uiDesigner.flex.states.SetProperty");
writer.property(NAME).stringReference(propertyProcessor.getName());
writer.property(VALUE);
PropertyKind propertyKind;
try {
propertyKind = valueWriter.write(descriptor, valueProvider, out, writer, false, context);
} catch (InvalidPropertyException ignored) {
// todo handle invalidProperty for state
throw new UnsupportedOperationException("");
}
if (propertyKind.isComplex()) {
mxmlWriter.processPropertyTagValue(descriptor, (XmlTag) valueProvider.getElement(), context, propertyKind);
}
override.targetId = context.getOrAllocateId();
if (pendingFirstSetProperty == null && context instanceof NullContext) {
pendingFirstSetProperty = override;
}
writer.getBlockOut().endRange(override.dataRange);
for (State state : filteredStates) {
state.overrides.add(override);
}
return true;
}
Aggregations