public void test_childOperationsOnNull() throws Exception { this.addNodeById("8758390115029078425"); this.addNodeById("5815925154349132136"); this.addNodeById("2166349271756548530"); SNode nullNode = null; Assert.assertNull(SNodeOperations.getContainingLinkDeclaration(nullNode)); Assert.assertNull(SNodeOperations.getContainingLinkRole(nullNode)); }
private void collectGroupChangesWithOthersConflicts( Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> arrangedChanges, ChangeSet thisChangeSet, ChangeSet otherChangeSet) { Map<SNodeId, DeleteRootChange> deleteRootChanges = MergeConflictsBuilder.<SNodeId, DeleteRootChange>arrangeChanges( thisChangeSet, new _FunctionTypes._return_P1_E0<SNodeId, DeleteRootChange>() { public SNodeId invoke(DeleteRootChange drc) { return drc.getRootId(); } }, DeleteRootChange.class); for (ModelChange change : ListSequence.fromList(otherChangeSet.getModelChanges())) { if (MapSequence.fromMap(myConflictingChanges).containsKey(change)) { continue; } SNodeId nodeId = null; if (change instanceof NodeChange) { nodeId = ((NodeChange) change).getAffectedNodeId(); } else if (change instanceof NodeGroupChange) { nodeId = ((NodeGroupChange) change).getParentNodeId(); } if (nodeId == null) { continue; } SNode node = myBaseModel.getNode(nodeId); while (node != null) { if (SNodeOperations.getParent(node) == null) { DeleteRootChange conflicting = MapSequence.fromMap(deleteRootChanges).get(node.getNodeId()); if (conflicting != null) { addPossibleConflict(change, conflicting); } } else { Tuples._2<SNodeId, String> nodeRole = MultiTuple.<SNodeId, String>from( SNodeOperations.getParent(node).getNodeId(), SNodeOperations.getContainingLinkRole(node)); final int index = SNodeOperations.getIndexInParent(node); NodeGroupChange conflicting = ListSequence.fromList(MapSequence.fromMap(arrangedChanges).get(nodeRole)) .findFirst( new IWhereFilter<NodeGroupChange>() { public boolean accept(NodeGroupChange ch) { return ch.getBegin() <= index && index < ch.getEnd(); } }); if (conflicting != null) { addPossibleConflict(change, conflicting); break; } } node = SNodeOperations.getParent(node); } } }
public void test_unspecifiedChildren() throws Exception { this.addNodeById("8758390115029078425"); this.addNodeById("5815925154349132136"); this.addNodeById("2166349271756548530"); int initialSize = ListSequence.fromList( SNodeOperations.getChildren( SNodeOperations.cast( this.getNodeById("2166349271756548531"), "jetbrains.mps.lang.smodelTests.structure.Root"))) .count(); SNode unspecifiedChild = SConceptOperations.createNewNode( "jetbrains.mps.lang.smodelTests.structure.GrandChild", null); String unspecifiedChildRole = this.addUnspecifiedChild( SNodeOperations.cast( this.getNodeById("2166349271756548531"), "jetbrains.mps.lang.smodelTests.structure.Root"), unspecifiedChild); Assert.assertEquals( initialSize + 1, ListSequence.fromList( SNodeOperations.getChildren( SNodeOperations.cast( this.getNodeById("2166349271756548531"), "jetbrains.mps.lang.smodelTests.structure.Root"))) .count()); Iterable<SNode> unspecifiedChildren = ListSequence.fromList( SNodeOperations.getChildren( SNodeOperations.cast( this.getNodeById("2166349271756548531"), "jetbrains.mps.lang.smodelTests.structure.Root"))) .where( new IWhereFilter<SNode>() { public boolean accept(SNode it) { return (SNodeOperations.getContainingLinkDeclaration(it) == null); } }); Assert.assertEquals(1, Sequence.fromIterable(unspecifiedChildren).count()); SNode theChild = Sequence.fromIterable(unspecifiedChildren).first(); Assert.assertEquals(unspecifiedChildRole, SNodeOperations.getContainingLinkRole(theChild)); Assert.assertEquals(unspecifiedChild, theChild); }
public List<INodeSubstituteAction> createActions() { if (myLinkDeclaration == null) { return Collections.emptyList(); } EditorComponent editor = mySubstituteInfo.getEditorContext().getNodeEditorComponent(); EditorCell referenceCell = editor.findNodeCellWithRole( mySourceNode, ((String) BehaviorManager.getInstance() .invoke( Object.class, SNodeOperations.cast( myLinkDeclaration, "jetbrains.mps.lang.structure.structure.LinkDeclaration"), "call_getGenuineRole_1213877254542", new Class[] {SNode.class}))); if (referenceCell != null && referenceCell.getContainingBigCell().getFirstLeaf() == referenceCell && ReferenceConceptUtil.getCharacteristicReference( SNodeOperations.getConceptDeclaration(mySourceNode)) == myLinkDeclaration && SNodeOperations.getParent(mySourceNode) != null && ListSequence.fromList(SNodeOperations.getChildren(mySourceNode)).isEmpty()) { SNode parent = SNodeOperations.getParent(mySourceNode); String role = SNodeOperations.getContainingLinkRole(mySourceNode); SNode roleLink = SNodeOperations.cast( parent.getLinkDeclaration(role), "jetbrains.mps.lang.structure.structure.LinkDeclaration"); return ModelActions.createChildSubstituteActions( parent, mySourceNode, SLinkOperations.getTarget(roleLink, "target", false), new DefaultChildNodeSetter(roleLink), mySubstituteInfo.getOperationContext()); } return ModelActions.createReferentSubstituteActions( mySourceNode, myCurrentReferent, myLinkDeclaration, mySubstituteInfo.getOperationContext()); }