package jetbrains.mps.core.xml.actions;
/*Generated by MPS */
import jetbrains.mps.openapi.editor.EditorContext;
import org.jetbrains.mps.openapi.model.SNode;
import java.util.List;
import java.util.ArrayList;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.internal.collections.runtime.ListSequence;
public class AttributeUtil {
public AttributeUtil() {
}
public static void setIndexSelection(EditorContext editorContext) {
}
public static void updateValue(SNode attr, EditorContext editorContext) {
if (attr == null) {
return;
}
List<SNode> valuesToDelete = new ArrayList<SNode>();
SNode lastValue = null;
for (SNode part : SLinkOperations.getChildren(attr, MetaAdapterFactory.getContainmentLink(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x5c842a42c54b8df3L, 0x5c842a42c54cfd1eL, "value"))) {
if (SNodeOperations.isInstanceOf(part, MetaAdapterFactory.getConcept(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x5c842a42c54cfd1fL, "jetbrains.mps.core.xml.structure.XmlTextValue"))) {
if (isEmptyString(SPropertyOperations.getString(SNodeOperations.cast(part, MetaAdapterFactory.getConcept(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x5c842a42c54cfd1fL, "jetbrains.mps.core.xml.structure.XmlTextValue")), MetaAdapterFactory.getProperty(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x5c842a42c54cfd1fL, 0x5c842a42c54cfd20L, "text")))) {
ListSequence.fromList(valuesToDelete).addElement(part);
} else if (lastValue != null) {
SPropertyOperations.set(lastValue, MetaAdapterFactory.getProperty(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x5c842a42c54cfd1fL, 0x5c842a42c54cfd20L, "text"), SPropertyOperations.getString_def(lastValue, MetaAdapterFactory.getProperty(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x5c842a42c54cfd1fL, 0x5c842a42c54cfd20L, "text"), "") + SPropertyOperations.getString(SNodeOperations.cast(part, MetaAdapterFactory.getConcept(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x5c842a42c54cfd1fL, "jetbrains.mps.core.xml.structure.XmlTextValue")), MetaAdapterFactory.getProperty(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x5c842a42c54cfd1fL, 0x5c842a42c54cfd20L, "text")));
ListSequence.fromList(valuesToDelete).addElement(part);
} else {
lastValue = SNodeOperations.cast(part, MetaAdapterFactory.getConcept(0x479c7a8c02f943b5L, 0x9139d910cb22f298L, 0x5c842a42c54cfd1fL, "jetbrains.mps.core.xml.structure.XmlTextValue"));
}
} else {
lastValue = null;
}
}
for (SNode d : valuesToDelete) {
SNodeOperations.deleteNode(d);
}
}
private static boolean isEmptyString(String str) {
return str == null || str.length() == 0;
}
}