package jetbrains.mps.editor.runtime.impl.cellActions;
/*Generated by MPS */
import org.jetbrains.annotations.NotNull;
import org.jetbrains.mps.openapi.model.SNode;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations;
import jetbrains.mps.smodel.behaviour.BHReflection;
import jetbrains.mps.core.aspects.behaviour.SMethodTrimmedId;
import org.jetbrains.mps.openapi.language.SContainmentLink;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import java.util.List;
import jetbrains.mps.internal.collections.runtime.ListSequence;
import java.util.ArrayList;
import jetbrains.mps.internal.collections.runtime.Sequence;
import jetbrains.mps.internal.collections.runtime.IWhereFilter;
import jetbrains.mps.internal.collections.runtime.ISelector;
import jetbrains.mps.internal.collections.runtime.IVisitor;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
public class CommentUtil {
private CommentUtil() {
}
/**
*
* @param node node to comment. This node must have parent
* @throws IllegalArgumentException if node does not have parent
*/
@NotNull
public static SNode commentOut(@NotNull SNode node) {
SNode parent = SNodeOperations.getParent(node);
if (parent == null) {
throw new IllegalArgumentException("Node to comment has no parent. Node: " + ((String) BHReflection.invoke(node, SMethodTrimmedId.create("getPresentation", null, "hEwIMiw"))) + " Node id: " + node.getNodeId());
}
SContainmentLink containmentLink = node.getContainmentLink();
assert containmentLink != null;
return new NodeCommenter(node).commentOut();
}
public static boolean isCommentedOut(@NotNull SNode node) {
return (SNodeOperations.getNodeAncestor(node, MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x3dcc194340c24debL, "jetbrains.mps.lang.core.structure.BaseCommentAttribute"), false, false) != null);
}
/**
*
*
* @param attribute attribute containing commented node. This node must have parent
* @throws IllegalArgumentException if attribute has no parent
*/
public static SNode uncomment(@NotNull SNode attribute) {
SNode parent = SNodeOperations.getParent(attribute);
if (parent == null) {
throw new IllegalArgumentException("Node to uncomment has no parent. Node: " + ((String) BHReflection.invoke(attribute, SMethodTrimmedId.create("getPresentation", null, "hEwIMiw"))) + " Node id: " + attribute.getNodeId());
}
return new NodeUncommenter(attribute).uncomment();
}
public static Iterable<SNode> uncommentAll(SNode container) {
List<SNode> uncommented = ListSequence.fromList(new ArrayList<SNode>());
ListSequence.fromList(uncommented).addSequence(Sequence.fromIterable(SNodeOperations.ofConcept(ListSequence.fromList(SNodeOperations.getChildren(container)).where(new IWhereFilter<SNode>() {
public boolean accept(SNode it) {
return SNodeOperations.isInstanceOf(it, MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x3dcc194340c24debL, "jetbrains.mps.lang.core.structure.BaseCommentAttribute"));
}
}), MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x3dcc194340c24debL, "jetbrains.mps.lang.core.structure.BaseCommentAttribute"))).select(new ISelector<SNode, SNode>() {
public SNode select(SNode it) {
return uncomment(it);
}
}));
return uncommented;
}
public static void commentOutAll(Iterable<SNode> nodes) {
Sequence.fromIterable(nodes).visitAll(new IVisitor<SNode>() {
public void visit(SNode it) {
commentOut(it);
}
});
}
public static boolean isComment(SNode node) {
return SNodeOperations.isInstanceOf(node, MetaAdapterFactory.getConcept(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x3dcc194340c24debL, "jetbrains.mps.lang.core.structure.BaseCommentAttribute"));
}
public static SNode getCommentedNode(SNode comment) {
return SLinkOperations.getTarget(comment, MetaAdapterFactory.getContainmentLink(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x3dcc194340c24debL, 0x2ab99f0d2248e89dL, "commentedNode"));
}
}