use of com.intellij.flex.uiDesigner.mxml.PrimitiveWriter in project intellij-plugins by JetBrains.
the class IncrementalDocumentSynchronizer method incrementalSync.
private boolean incrementalSync(final DocumentInfo info) {
final XmlElementValueProvider valueProvider = findSupportedTarget();
if (valueProvider == null) {
return false;
}
XmlTag tag = (XmlTag) valueProvider.getElement().getParent();
if (!(tag.getDescriptor() instanceof ClassBackedElementDescriptor)) {
return false;
}
int componentId = info.rangeMarkerIndexOf(tag);
if (componentId == -1) {
return false;
}
final AnnotationBackedDescriptor descriptor = (AnnotationBackedDescriptor) valueProvider.getPsiMetaData();
assert descriptor != null;
final String typeName = descriptor.getTypeName();
final String type = descriptor.getType();
if (type == null) {
return !typeName.equals(FlexAnnotationNames.EFFECT);
} else if (type.equals(JSCommonTypeNames.FUNCTION_CLASS_NAME) || typeName.equals(FlexAnnotationNames.EVENT)) {
return true;
}
final StringRegistry.StringWriter stringWriter = new StringRegistry.StringWriter();
//noinspection IOResourceOpenedButNotSafelyClosed
final PrimitiveAmfOutputStream dataOut = new PrimitiveAmfOutputStream(new ByteArrayOutputStreamEx(16));
PrimitiveWriter writer = new PrimitiveWriter(dataOut, stringWriter);
boolean needRollbackStringWriter = true;
try {
if (descriptor.isAllowsPercentage()) {
String value = valueProvider.getTrimmed();
final boolean hasPercent;
if (value.isEmpty() || ((hasPercent = value.endsWith("%")) && value.length() == 1)) {
return true;
}
final String name;
if (hasPercent) {
name = descriptor.getPercentProxy();
value = value.substring(0, value.length() - 1);
} else {
name = descriptor.getName();
}
stringWriter.write(name, dataOut);
dataOut.writeAmfDouble(value);
} else {
stringWriter.write(descriptor.getName(), dataOut);
if (!writer.writeIfApplicable(valueProvider, dataOut, descriptor)) {
needRollbackStringWriter = false;
stringWriter.rollback();
return false;
}
}
needRollbackStringWriter = false;
} catch (InvalidPropertyException ignored) {
return true;
} catch (NumberFormatException ignored) {
return true;
} finally {
if (needRollbackStringWriter) {
stringWriter.rollback();
}
}
Client.getInstance().updatePropertyOrStyle(info.getId(), componentId, stream -> {
stringWriter.writeTo(stream);
stream.write(descriptor.isStyle());
dataOut.writeTo(stream);
}).doWhenDone(() -> DesignerApplicationManager.createDocumentRenderedNotificationDoneHandler(true).consume(info));
return true;
}
Aggregations