private static Iterable<CommandPart> getMacroValues() { final PathMacros pathMacros = PathMacros.getInstance(); List<CommandPart> macroValues = ListSequence.fromListAndArray( new ArrayList<CommandPart>(), new PropertyCommandPart("mps_home", jetbrains.mps.util.PathManager.getHomePath())); return ListSequence.fromList(macroValues) .union( Sequence.fromIterable( Sequence.fromClosure( new ISequenceClosure<String>() { public Iterable<String> iterable() { return pathMacros.getUserMacroNames(); } })) .select( new ISelector<String, CommandPart>() { public CommandPart select(String it) { return (CommandPart) new PropertyCommandPart(it, pathMacros.getValue(it)); } })); }
public Iterable<Node> sequence() { final Node _node = this.thisNode; return Sequence.fromClosure( new ISequenceClosure<Node>() { public Iterable<Node> iterable() { return new Iterable<Node>() { public Iterator<Node> iterator() { return new YieldingIterator<Node>() { private int __CP__ = 0; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 8: this._8_idx = 0; case 9: if (!(_8_idx < _7_count)) { this.__CP__ = 1; break; } this.__CP__ = 10; break; case 11: _8_idx++; this.__CP__ = 9; break; case 4: if (_3_attributes != null) { this.__CP__ = 5; break; } this.__CP__ = 1; break; case 12: this.__CP__ = 11; this.yield(_node.getAttributes().item(_8_idx)); return true; case 0: this._3_attributes = _node.getAttributes(); this.__CP__ = 4; break; case 5: this._7_count = _3_attributes.getLength(); this.__CP__ = 8; break; case 10: this.__CP__ = 12; break; default: break __loop__; } } while (true); return false; } private NamedNodeMap _3_attributes; private int _7_count; private int _8_idx; }; } }; } }); }
public static void main(String[] args) { final SNode foo = null; ListSequence.fromList((SLinkOperations.getTargets(foo, "implements", true))) .translate( new ITranslator2<SNode, SNode>() { public Iterable<SNode> translate(final SNode it) { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 2: this.__CP__ = 1; this.yield(SLinkOperations.getTarget(it, "intfc", false)); return true; case 0: this.__CP__ = 2; break; default: break __loop__; } } while (true); return false; } }; } }; } }) .translate( new ITranslator2<SNode, SNode>() { public Iterable<SNode> translate(final SNode it) { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; private SNode _2__zzz_; private Iterator<SNode> _2__zzz__it; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 2: this._2__zzz__it = ListSequence.fromList( SLinkOperations.getTargets(it, "extends", true)) .iterator(); case 3: if (!(this._2__zzz__it.hasNext())) { this.__CP__ = 1; break; } this._2__zzz_ = this._2__zzz__it.next(); this.__CP__ = 4; break; case 5: this.__CP__ = 3; this.yield(_2__zzz_); return true; case 0: this.__CP__ = 2; break; case 4: this.__CP__ = 5; break; default: break __loop__; } } while (true); return false; } }; } }; } }); // The following ypath construct should result in the same expression as above Sequence.fromIterable( Sequence.fromClosure( new ISequenceClosure<SNode>() { public Iterable<SNode> iterable() { SNode _zzz_ = foo; return SLinkOperations.getTargets(_zzz_, "implements", true); } })) .translate( new ITranslator2<SNode, SNode>() { public Iterable<SNode> translate(final SNode it) { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 2: this.__CP__ = 1; this.yield(SLinkOperations.getTarget(it, "intfc", false)); return true; case 0: this.__CP__ = 2; break; default: break __loop__; } } while (true); return false; } }; } }; } }) .translate( new ITranslator2<SNode, SNode>() { public Iterable<SNode> translate(final SNode it) { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; private SNode _2__yyy_; private Iterator<SNode> _2__yyy__it; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 2: this._2__yyy__it = ListSequence.fromList( SLinkOperations.getTargets(it, "extends", true)) .iterator(); case 3: if (!(this._2__yyy__it.hasNext())) { this.__CP__ = 1; break; } this._2__yyy_ = this._2__yyy__it.next(); this.__CP__ = 4; break; case 5: this.__CP__ = 3; this.yield(_2__yyy_); return true; case 0: this.__CP__ = 2; break; case 4: this.__CP__ = 5; break; default: break __loop__; } } while (true); return false; } }; } }; } }); // Another pair of tests ListSequence.fromList( ListSequence.fromListAndArray( new ArrayList<SNode>(), SLinkOperations.getTarget(foo, "extends", false))) .translate( new ITranslator2<SNode, SNode>() { public Iterable<SNode> translate(final SNode it) { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; private SNode _2_p; private Iterator<SNode> _2_p_it; private SNode _5_c; private Iterator<SNode> _5_c_it; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 2: this._2_p_it = ListSequence.fromListAndArray( new ArrayList<SNode>(), SNodeOperations.getParent(it)) .iterator(); case 3: if (!(this._2_p_it.hasNext())) { this.__CP__ = 1; break; } this._2_p = this._2_p_it.next(); this.__CP__ = 4; break; case 5: this._5_c_it = ListSequence.fromList(SNodeOperations.getChildren(_2_p)) .iterator(); case 6: if (!(this._5_c_it.hasNext())) { this.__CP__ = 3; break; } this._5_c = this._5_c_it.next(); this.__CP__ = 7; break; case 8: if (it == _5_c) { this.__CP__ = 9; break; } this.__CP__ = 10; break; case 10: this.__CP__ = 6; this.yield(_5_c); return true; case 0: this.__CP__ = 2; break; case 4: this.__CP__ = 5; break; case 7: this.__CP__ = 8; break; case 9: this.__CP__ = 1; break; default: break __loop__; } } while (true); return false; } }; } }; } }); ListSequence.fromList( ListSequence.fromListAndArray( new ArrayList<SNode>(), SLinkOperations.getTarget(foo, "extends", false))) .translate( new ITranslator2<SNode, SNode>() { public Iterable<SNode> translate(final SNode it) { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; private SNode _5__yyy_; private Iterator<SNode> _5__yyy__it; private SNode _2__zzz_; private Iterator<SNode> _2__zzz__it; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 2: this._2__zzz__it = ListSequence.fromListAndArray( new ArrayList<SNode>(), SNodeOperations.getParent(it)) .iterator(); case 3: if (!(this._2__zzz__it.hasNext())) { this.__CP__ = 1; break; } this._2__zzz_ = this._2__zzz__it.next(); this.__CP__ = 4; break; case 5: this._5__yyy__it = SNodeOperations.getChildren(_2__zzz_).iterator(); case 6: if (!(this._5__yyy__it.hasNext())) { this.__CP__ = 3; break; } this._5__yyy_ = this._5__yyy__it.next(); this.__CP__ = 7; break; case 8: if (it == _5__yyy_) { this.__CP__ = 9; break; } this.__CP__ = 10; break; case 10: this.__CP__ = 6; this.yield(_5__yyy_); return true; case 0: this.__CP__ = 2; break; case 4: this.__CP__ = 5; break; case 7: this.__CP__ = 8; break; case 9: this.__CP__ = 1; break; default: break __loop__; } } while (true); return false; } }; } }; } }); // And another one /* // way too complicated ListSequence.fromList(ListSequence.fromListAndArray(new ArrayList<SNode>(), foo)).translate(new ITranslator2<SNode, SNode>() { public Iterable<SNode> translate(SNode it) { return new _FunctionTypes._return_P1_E0<Iterable<SNode>, SNode>() { public Iterable<SNode> invoke(final SNode _zzz_) { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; private SNode _2__yyy_; private Iterator<SNode> _2__yyy__it; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 2: this._2__yyy__it = ListSequence.fromList(SNodeOperations.getChildren(_zzz_)).iterator(); case 3: if (!(this._2__yyy__it.hasNext())) { this.__CP__ = 1; break; } this._2__yyy_ = this._2__yyy__it.next(); this.__CP__ = 4; break; case 5: this.__CP__ = 6; this.yield(_2__yyy_); return true; case 0: this.__CP__ = 2; break; case 4: this.__CP__ = 5; break; case 6: invoke(_2__yyy_); this.__CP__ = 3; break; default: break __loop__; } } while (true); return false; } }; } }; } }.invoke(it); } }); */ Sequence.fromClosure( new ISequenceClosure<SNode>() { public Iterable<SNode> iterable() { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; private SNode _3__zzz_; private List<SNode> _5__yyy_; private SNode _9__xxx_; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 6: if (ListSequence.fromList(_5__yyy_).isNotEmpty()) { this.__CP__ = 7; break; } this.__CP__ = 1; break; case 10: this.__CP__ = 11; this.yield(_9__xxx_); return true; case 0: this._3__zzz_ = foo; this.__CP__ = 1; break; case 3: this._5__yyy_ = ListSequence.fromList(new ArrayList<SNode>()); ListSequence.fromList(_5__yyy_) .addSequence( ListSequence.fromList(SNodeOperations.getChildren(_3__zzz_))); this.__CP__ = 6; break; case 7: this._9__xxx_ = ListSequence.fromList(_5__yyy_).first(); ListSequence.fromList(_5__yyy_).removeElement(_9__xxx_); this.__CP__ = 10; break; case 11: ListSequence.fromList(_5__yyy_) .addSequence( ListSequence.fromList(SNodeOperations.getChildren(_9__xxx_))); this.__CP__ = 6; break; default: break __loop__; } } while (true); return false; } }; } }; } }); // Following is just a test Sequence.fromIterable( Sequence.fromClosure( new ISequenceClosure<SNode>() { public Iterable<SNode> iterable() { SNode _zzz_ = foo; return SLinkOperations.getTargets(_zzz_, "implements", true); } })) .translate( new ITranslator2<SNode, SNode>() { public Iterable<SNode> translate(final SNode it) { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 2: this.__CP__ = 1; this.yield(SLinkOperations.getTarget(it, "intfc", false)); return true; case 0: this.__CP__ = 2; break; default: break __loop__; } } while (true); return false; } }; } }; } }); TreeTraversalFactory.Traverse( new SNODE().startTraversal(foo), TreeTraversalFactory.Axis("CHILDREN"), SNODE.child("implements")); TreeTraversalFactory.Traverse( new SNODE().startTraversal(foo), TreeTraversalFactory.Axis("ANCESTORS")); Sequence.fromClosure( new ISequenceClosure<SNode>() { public Iterable<SNode> iterable() { return new Iterable<SNode>() { public Iterator<SNode> iterator() { return new YieldingIterator<SNode>() { private int __CP__ = 0; private SNode _3__zzz_; private List<SNode> _7__yyy_; private SNode _11__xxx_; protected boolean moveToNext() { __loop__: do { __switch__: switch (this.__CP__) { case -1: assert false : "Internal error"; return false; case 8: if (ListSequence.fromList(_7__yyy_).isNotEmpty()) { this.__CP__ = 9; break; } this.__CP__ = 1; break; case 4: this.__CP__ = 5; this.yield(_3__zzz_); return true; case 12: this.__CP__ = 13; this.yield(_11__xxx_); return true; case 0: this._3__zzz_ = foo; this.__CP__ = 4; break; case 5: this._7__yyy_ = ListSequence.fromList(new ArrayList<SNode>()); ListSequence.fromList(_7__yyy_) .addSequence( ListSequence.fromList(SNodeOperations.getChildren(_3__zzz_))); this.__CP__ = 8; break; case 9: this._11__xxx_ = ListSequence.fromList(_7__yyy_).first(); ListSequence.fromList(_7__yyy_).removeElement(_11__xxx_); this.__CP__ = 12; break; case 13: ListSequence.fromList(_7__yyy_) .addSequence( ListSequence.fromList(SNodeOperations.getChildren(_11__xxx_))); this.__CP__ = 8; break; default: break __loop__; } } while (true); return false; } }; } }; } }); TreeTraversalFactory.Traverse( new SNODE().startTraversal(foo), TreeTraversalFactory.Axis("SELF_FOLLOWING_SIBLINGS")); TreeTraversalFactory.Traverse( new SNODE().startTraversal(foo), TreeTraversalFactory.Axis("CHILDREN")); TreeTraversalFactory.Traverse( new SNODE().startTraversal(foo), TreeTraversalFactory.Axis("CHILDREN")); Sequence.fromClosure( new ISequenceClosure<SNode>() { public Iterable<SNode> iterable() { SNode _zzz_ = foo; return SNodeOperations.getChildren(_zzz_); } }); // !@#$& }