private static void assertDeepChildrenEquals(SNode expectedNode, SNode actualNode) { Set<String> roles = new HashSet<String>(); for (SNode child : expectedNode.getChildren()) { roles.add(child.getRoleInParent()); } for (SNode child : actualNode.getChildren()) { roles.add(child.getRoleInParent()); } for (String role : roles) { Iterable<? extends SNode> expectedChildren = expectedNode.getChildren(role); Iterable<? extends SNode> actualChildren = actualNode.getChildren(role); int esize = IterableUtil.asCollection(expectedChildren).size(); int asize = IterableUtil.asCollection(actualChildren).size(); assertEquals( getErrorString("child count in role " + role, expectedNode, actualNode), esize, asize); Iterator<? extends SNode> actualIterator = actualChildren.iterator(); for (SNode expectedChild : expectedChildren) { SNode actualChild = actualIterator.next(); assertEquals( getErrorString("children in role " + role, expectedNode, actualNode), expectedChild.getNodeId(), actualChild.getNodeId()); assertDeepNodeEquals(expectedChild, actualChild); } } }
public SNode coerceSubTypingNew( final SNode subtype, final IMatchingPattern pattern, final boolean isWeak, final TypeCheckingContext context) { if (subtype == null) return null; if (pattern.match(subtype)) return subtype; if (!CoerceUtil.canBeCoerced(subtype, pattern.getConceptFQName())) return null; if ("jetbrains.mps.lang.typesystem.structure.MeetType" .equals(subtype.getConcept().getQualifiedName())) { List<SNode> children = new ArrayList(IterableUtil.asCollection(subtype.getChildren("argument"))); for (SNode child : children) { SNode result = coerceSubTypingNew(child, pattern, isWeak, context); if (result != null) return result; } return null; } final TypeCheckingContext typeCheckingContext = context; if ("jetbrains.mps.lang.typesystem.structure.JoinType" .equals(subtype.getConcept().getQualifiedName())) { List<SNode> children = new ArrayList(IterableUtil.asCollection(subtype.getChildren("argument"))); SNode lcs = SubtypingUtil.createLeastCommonSupertype(children, typeCheckingContext); return coerceSubTypingNew(lcs, pattern, isWeak, context); } // asking the cache return NodeReadAccessCasterInEditor.runReadTransparentAction( new Computable<SNode>() { @Override public SNode compute() { Pair<Boolean, SNode> answer = getCoerceCacheAnswer(subtype, pattern, isWeak); if (answer != null && answer.o1) { return answer.o2; } CoercionMatcher coercionMatcher = new CoercionMatcher(pattern); SNode result = searchInSuperTypes(subtype, coercionMatcher, isWeak); // writing to the cache SubtypingCache subtypingCache = myTypeChecker.getSubtypingCache(); if (subtypingCache != null) { subtypingCache.cacheCoerce(subtype, pattern, result, isWeak); } return result; } }); }
private static void checkModelNodes(@NotNull SModel model, @NotNull final List<String> result) { for (final SNode node : SNodeUtil.getDescendants(model)) { final SConcept concept = node.getConcept(); if (concept == null) { result.add("unknown concept of node: " + SNodeUtil.getDebugText(node)); continue; } for (String name : node.getPropertyNames()) { if (concept.getProperty(name) == null) { result.add("unknown property: `" + name + "' in node " + SNodeUtil.getDebugText(node)); } } for (SReference ref : node.getReferences()) { SAbstractLink link = concept.getLink(ref.getRole()); if (link == null || !(link.isReference())) { result.add( "unknown link role: `" + ref.getRole() + "' in node " + SNodeUtil.getDebugText(node)); } } for (SNode child : node.getChildren()) { String role = child.getRoleInParent(); SAbstractLink link = concept.getLink(role); if (link == null || link.isReference()) { result.add("unknown child role: `" + role + "' in node " + SNodeUtil.getDebugText(node)); } } } }
public boolean match(SNode nodeToMatch) { { SNode nodeToMatch_nlist_subtypeOf_list_of_nodes_3tjcdg_a0a_0; nodeToMatch_nlist_subtypeOf_list_of_nodes_3tjcdg_a0a_0 = nodeToMatch; if (!("jetbrains.mps.baseLanguage.collections.structure.ListType" .equals( nodeToMatch_nlist_subtypeOf_list_of_nodes_3tjcdg_a0a_0 .getConcept() .getConceptId()))) { return false; } { String childRole_nlist_subtypeOf_list_of_nodes_3tjcdg_ = "elementType"; if (!(PatternUtil.hasNChildren( nodeToMatch_nlist_subtypeOf_list_of_nodes_3tjcdg_a0a_0, childRole_nlist_subtypeOf_list_of_nodes_3tjcdg_, 1))) { return false; } { SNode childVar_nlist_subtypeOf_list_of_nodes_3tjcdg_a0a0 = IterableUtil.get( nodeToMatch_nlist_subtypeOf_list_of_nodes_3tjcdg_a0a_0.getChildren( childRole_nlist_subtypeOf_list_of_nodes_3tjcdg_), 0); this.patternVar_ELEMENT = childVar_nlist_subtypeOf_list_of_nodes_3tjcdg_a0a0; } } } return true; }
// doesn't trigger property/reference reads /*package*/ static int countTreeNodes( Iterable<? extends org.jetbrains.mps.openapi.model.SNode> nodes) { int rv = 0; for (org.jetbrains.mps.openapi.model.SNode n : nodes) { rv++; rv += countTreeNodes(n.getChildren()); } return rv; }
public static SNode getTarget(SNode node, String role, boolean child) { if (node != null) { if (child) { Iterator<SNode> it = ((Iterator) node.getChildren(role).iterator()); return (it.hasNext() ? it.next() : null); } return node.getReferenceTarget(role); } return null; }
public static List<SNode> removeAllChildren(SNode parent, String role) { if (parent == null) { return jetbrains.mps.lang.smodel.generator.smodelAdapter.SNodeOperations.EMPTY_LIST; } Iterable<? extends SNode> children = parent.getChildren(role); for (SNode child : children) { parent.removeChild(child); } return IterableUtil.asList(children); }
public TemplateSwitchMappingInterpreted(SNode aSwitch) { mySwitch = aSwitch; rules = new ArrayList<TemplateReductionRule>(); for (SNode child : mySwitch.getChildren()) { String conceptName = child.getConcept().getQualifiedName(); if (conceptName.equals(RuleUtil.concept_Reduction_MappingRule)) { rules.add(new TemplateReductionRuleInterpreted(child)); } } }
public boolean match(SNode nodeToMatch) { { SNode nodeToMatch_7fbm30_a1a0a0 = nodeToMatch; if (!("jetbrains.mps.baseLanguage.structure.NotEqualsExpression" .equals(nodeToMatch_7fbm30_a1a0a0.getConcept().getQualifiedName()))) { return false; } { String childRole_7fbm30__2 = "leftExpression"; if (!(PatternUtil.hasNChildren(nodeToMatch_7fbm30_a1a0a0, childRole_7fbm30__2, 1))) { return false; } { SNode childVar_7fbm30_a0b0a0a = IterableUtil.get(nodeToMatch_7fbm30_a1a0a0.getChildren(childRole_7fbm30__2), 0); { SNode nodeToMatch_7fbm30_a0b0a0a = childVar_7fbm30_a0b0a0a; if (!("jetbrains.mps.baseLanguage.structure.NullLiteral" .equals(nodeToMatch_7fbm30_a0b0a0a.getConcept().getQualifiedName()))) { return false; } } } } { String childRole_7fbm30__3 = "rightExpression"; if (!(PatternUtil.hasNChildren(nodeToMatch_7fbm30_a1a0a0, childRole_7fbm30__3, 1))) { return false; } { SNode childVar_7fbm30_a0b0a0a_0 = IterableUtil.get(nodeToMatch_7fbm30_a1a0a0.getChildren(childRole_7fbm30__3), 0); { SNode nodeToMatch_7fbm30_a0b0a0a_0 = childVar_7fbm30_a0b0a0a_0; patternVar_p = nodeToMatch_7fbm30_a0b0a0a_0; } } } } return true; }
private void removeDescendantChanges(SNodeId parentId, String role) { SNode oldNode = getOldNode(parentId); assert oldNode != null; List<? extends SNode> children = IterableUtil.asList(oldNode.getChildren(role)); ListSequence.fromList(children) .visitAll( new IVisitor<SNode>() { public void visit(SNode c) { removeDescendantChanges(c.getNodeId()); } }); }
/** * Create a model with a tree of nodes. * * <p>It's an instance method as I envision model to be owned by this class, which would keep * extra info about created model (e.g. number of initial nodes to get rid of constants like * (3*5*2 + 3*5 + 3) from the tests code * * @param nodesAtLevel number of child elements for each parent (i.e. of previous level) element. * Each node at level i has nodesAtLevel[i] children */ public SModel createModel(@Nullable int... nodesAtLevel) { final SNode top = createNode(nodesAtLevel); final jetbrains.mps.smodel.SModel modelData = new jetbrains.mps.smodel.SModel( new SModelReference( new ModuleReference("M", ModuleId.regular()), SModelId.generate(), "m")); for (SNode c : top.getChildren(ourRole)) { modelData.addRootNode(c); } assert myNeedEditableModel; return myModel = new TestModelBase(modelData); }
private void findPrefixReferences(String prefix, SNode node, Consumer<SReference> consumer) { LinkedList<SNode> queue = new LinkedList<SNode>(); queue.add(node); while (!queue.isEmpty()) { SNode n = queue.pop(); for (SReference ref : n.getReferences()) { processReference(prefix, ref, consumer); } for (SNode child : n.getChildren()) { queue.add(child); } } }
@Deprecated public static SNode removeChild(SNode parent, String role) { // use SNodeOperations.detachNode if (parent == null) { return null; } Iterator<SNode> it = ((Iterator) parent.getChildren(role).iterator()); SNode child = (it.hasNext() ? it.next() : null); if (child != null) { parent.removeChild(child); return child; } return null; }
public void applyNonTypeSystemRulesToRoot( TypeCheckingContext typeCheckingContext, SNode rootNode) { if (rootNode == null) return; doInvalidate(); try { Queue<SNode> frontier = new LinkedList<SNode>(); frontier.add(rootNode); while (!(frontier.isEmpty())) { SNode sNode = frontier.remove(); applyNonTypesystemRulesToNode(sNode, typeCheckingContext); frontier.addAll(IterableUtil.asCollection(sNode.getChildren())); } // all error reporters must be simple reporters, no error expansion needed } finally { setInvalidationWasPerformed(false); } }
public boolean match(SNode nodeToMatch) { { SNode nodeToMatch_7fbm30_a0a = nodeToMatch; if (!("jetbrains.mps.baseLanguage.structure.AssertStatement" .equals(nodeToMatch_7fbm30_a0a.getConcept().getQualifiedName()))) { return false; } { String childRole_7fbm30_ = "condition"; if (!(PatternUtil.hasNChildren(nodeToMatch_7fbm30_a0a, childRole_7fbm30_, 1))) { return false; } { SNode childVar_7fbm30_a0a0 = IterableUtil.get(nodeToMatch_7fbm30_a0a.getChildren(childRole_7fbm30_), 0); { SNode nodeToMatch_7fbm30_a0a0 = childVar_7fbm30_a0a0; { boolean orMatches = false; GeneratedMatchingPattern orPattern; orPattern = new RuleAssertNotNull.Pattern_7fbm30_a0a .Pattern_7fbm30_a0a0a2a1a1a1a1a0a1a1a0a0a0a(); if (orPattern.match(nodeToMatch_7fbm30_a0a0)) { orMatches = true; myOrPattern_7fbm30_a0a0 = orPattern; } orPattern = new RuleAssertNotNull.Pattern_7fbm30_a0a .Pattern_7fbm30_a0a0a3a1a1a1a1a0a1a1a0a0a0a(); if (orPattern.match(nodeToMatch_7fbm30_a0a0)) { orMatches = true; myOrPattern_7fbm30_a0a0 = orPattern; } if (!(orMatches)) { return false; } } } this.patternVar_action_var_5730083271929373007 = childVar_7fbm30_a0a0; } } } return true; }
public boolean match(SNode nodeToMatch) { { SNode nodeToMatch_6isygg_a0a0a0 = nodeToMatch; if (!(MetaAdapterFactory.getConcept( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, "jetbrains.mps.baseLanguage.structure.ClassifierType") .equals(nodeToMatch_6isygg_a0a0a0.getConcept()))) { return false; } { SNodeReference pointer = SNODE_POINTER_w1n2qe_a0a0a0a0b0b0a0b0a0a0a0c7; if (!(PatternUtil.matchReferentWithNode( pointer, nodeToMatch_6isygg_a0a0a0.getReferenceTarget( MetaAdapterFactory.getReferenceLink( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x101de490babL, "classifier"))))) { return false; } } { SContainmentLink childRole_6isygg_ = MetaAdapterFactory.getContainmentLink( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x101de48bf9eL, 0x102419671abL, "parameter"); if (!(PatternUtil.hasNChildren(nodeToMatch_6isygg_a0a0a0, childRole_6isygg_, 1))) { return false; } { SNode childVar_6isygg_a0a0a0a = IterableUtil.get(nodeToMatch_6isygg_a0a0a0.getChildren(childRole_6isygg_), 0); this.patternVar_elem = childVar_6isygg_a0a0a0a; } } } return true; }
public boolean match(SNode nodeToMatch) { { SNode nodeToMatch_twopzc_a0a = nodeToMatch; if (!("jetbrains.mps.baseLanguage.collections.structure.SetType" .equals(nodeToMatch_twopzc_a0a.getConcept().getQualifiedName()))) { return false; } { String childRole_twopzc_ = "elementType"; if (!(PatternUtil.hasNChildren(nodeToMatch_twopzc_a0a, childRole_twopzc_, 1))) { return false; } { SNode childVar_twopzc_a0a0 = IterableUtil.get(nodeToMatch_twopzc_a0a.getChildren(childRole_twopzc_), 0); this.patternVar_elementType = childVar_twopzc_a0a0; } } } return true; }
private void processChild(SModelChildEvent event, Map<SNode, Set<String>> childChanged) { SNode parent = event.getParent(); if (parent.getModel() == null) { return; } final String childRole = event.getChildRole(); // tyring to avoid update task execution for the same child role twice Set<String> childRoles = MapSequence.fromMap(childChanged).get(parent); if (childRoles == null) { childRoles = SetSequence.fromSet(new HashSet<String>()); MapSequence.fromMap(childChanged).put(parent, childRoles); } if (SetSequence.fromSet(childRoles).contains(childRole)) { return; } else { SetSequence.fromSet(childRoles).addElement(childRole); } final SNodeId parentId = parent.getNodeId(); final Wrappers._T<List<? extends SNode>> childrenRightAfterEvent = new Wrappers._T<List<? extends SNode>>( IterableUtil.asList(parent.getChildren(childRole))); childrenRightAfterEvent.value = ListSequence.fromList(childrenRightAfterEvent.value) .select( new ISelector<SNode, SNode>() { public SNode select(SNode n) { return CopyUtil.copyAndPreserveId(n, false); } }) .toListSequence(); runUpdateTask( new _FunctionTypes._void_P0_E0() { public void invoke() { removeChanges( parentId, NodeGroupChange.class, new _FunctionTypes._return_P1_E0<Boolean, NodeGroupChange>() { public Boolean invoke(NodeGroupChange ch) { return childRole.equals(ch.getRole()); } }); removeDescendantChanges(parentId, childRole); myLastParentAndNewChildrenIds = MultiTuple.<SNodeId, List<SNodeId>>from( parentId, ListSequence.fromList(childrenRightAfterEvent.value) .select( new ISelector<SNode, SNodeId>() { public SNodeId select(SNode n) { return n.getNodeId(); } }) .toListSequence()); buildAndAddChanges( new _FunctionTypes._void_P1_E0<ChangeSetBuilder>() { public void invoke(ChangeSetBuilder b) { b.buildForNodeRole( IterableUtil.asList(getOldNode(parentId).getChildren(childRole)), childrenRightAfterEvent.value, parentId, childRole); } }); } }, parent, event); }
private void fillMap(Iterable<? extends SNode> roots) { for (SNode root : roots) { myMap.add(root); fillMap(root.getChildren()); } }
public boolean match(SNode nodeToMatch) { { SNode nodeToMatch_xihehy_a0a1a2c = nodeToMatch; if (!(MetaAdapterFactory.getConcept( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, "jetbrains.mps.baseLanguage.structure.DotExpression") .equals(nodeToMatch_xihehy_a0a1a2c.getConcept()))) { return false; } { SContainmentLink childRole_xihehy_ = MetaAdapterFactory.getContainmentLink( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, 0x116b46a4416L, "operand"); if (!(PatternUtil.hasNChildren(nodeToMatch_xihehy_a0a1a2c, childRole_xihehy_, 1))) { return false; } { SNode childVar_xihehy_a0a0b0c2 = IterableUtil.get(nodeToMatch_xihehy_a0a1a2c.getChildren(childRole_xihehy_), 0); { SNode nodeToMatch_xihehy_a0a0b0c2 = childVar_xihehy_a0a0b0c2; if (!(MetaAdapterFactory.getConcept( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940c80846L, "jetbrains.mps.baseLanguage.structure.StaticFieldReference") .equals(nodeToMatch_xihehy_a0a0b0c2.getConcept()))) { return false; } patternVar_className = nodeToMatch_xihehy_a0a0b0c2.getReferenceTarget( MetaAdapterFactory.getReferenceLink( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf940c80846L, 0x10a75869f9bL, "classifier")); patternVar_field = nodeToMatch_xihehy_a0a0b0c2.getReferenceTarget( MetaAdapterFactory.getReferenceLink( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8c77f1e98L, 0xf8cc6bf960L, "variableDeclaration")); } } } { SContainmentLink childRole_xihehy__0 = MetaAdapterFactory.getContainmentLink( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x116b46a08c4L, 0x116b46b36c4L, "operation"); if (!(PatternUtil.hasNChildren(nodeToMatch_xihehy_a0a1a2c, childRole_xihehy__0, 1))) { return false; } { SNode childVar_xihehy_a0a0b0c2_0 = IterableUtil.get(nodeToMatch_xihehy_a0a1a2c.getChildren(childRole_xihehy__0), 0); { SNode nodeToMatch_xihehy_a0a0b0c2_0 = childVar_xihehy_a0a0b0c2_0; if (!(MetaAdapterFactory.getConcept( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x118154a6332L, "jetbrains.mps.baseLanguage.structure.InstanceMethodCallOperation") .equals(nodeToMatch_xihehy_a0a0b0c2_0.getConcept()))) { return false; } patternVar_method = nodeToMatch_xihehy_a0a0b0c2_0.getReferenceTarget( MetaAdapterFactory.getReferenceLink( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11857355952L, 0xf8c78301adL, "baseMethodDeclaration")); { SContainmentLink childRole_xihehy__1 = MetaAdapterFactory.getContainmentLink( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x11857355952L, 0xf8c78301aeL, "actualArgument"); if (!(PatternUtil.hasNChildren( nodeToMatch_xihehy_a0a0b0c2_0, childRole_xihehy__1, 1))) { return false; } { SNode childVar_xihehy_a0a0a1a2c = IterableUtil.get( nodeToMatch_xihehy_a0a0b0c2_0.getChildren(childRole_xihehy__1), 0); { SNode nodeToMatch_xihehy_a0a0a1a2c = childVar_xihehy_a0a0a1a2c; if (!(MetaAdapterFactory.getConcept( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, "jetbrains.mps.baseLanguage.structure.StringLiteral") .equals(nodeToMatch_xihehy_a0a0a1a2c.getConcept()))) { return false; } patternVar_printed = SNodeAccessUtil.getProperty( nodeToMatch_xihehy_a0a0a1a2c, MetaAdapterFactory.getProperty( 0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf93d565d10L, 0xf93d565d11L, "value")); } } } } } } } return true; }
public boolean match(SNode nodeToMatch) { { SNode nodeToMatch_x583g4_a0a0a78 = nodeToMatch; if (!("jetbrains.mps.core.xml.structure.XmlElement" .equals(nodeToMatch_x583g4_a0a0a78.getConcept().getQualifiedName()))) { return false; } if (!("classpath" .equals(SNodeAccessUtil.getProperty(nodeToMatch_x583g4_a0a0a78, "tagName")))) { return false; } { String childRole_x583g4__5 = "content"; if (!(PatternUtil.hasNChildren(nodeToMatch_x583g4_a0a0a78, childRole_x583g4__5, 1))) { return false; } { SNode childVar_x583g4_a0a0a0jd = IterableUtil.get(nodeToMatch_x583g4_a0a0a78.getChildren(childRole_x583g4__5), 0); { SNode nodeToMatch_x583g4_a0a0a0jd = childVar_x583g4_a0a0a0jd; if (!("jetbrains.mps.core.xml.structure.XmlElement" .equals(nodeToMatch_x583g4_a0a0a0jd.getConcept().getQualifiedName()))) { return false; } if (!("true" .equals( SNodeAccessUtil.getProperty( nodeToMatch_x583g4_a0a0a0jd, "shortEmptyNotation")))) { return false; } if (!("pathelement" .equals(SNodeAccessUtil.getProperty(nodeToMatch_x583g4_a0a0a0jd, "tagName")))) { return false; } { String childRole_x583g4__6 = "attributes"; if (!(PatternUtil.hasNChildren( nodeToMatch_x583g4_a0a0a0jd, childRole_x583g4__6, 1))) { return false; } { SNode childVar_x583g4_a0a0a0a78 = IterableUtil.get( nodeToMatch_x583g4_a0a0a0jd.getChildren(childRole_x583g4__6), 0); { SNode nodeToMatch_x583g4_a0a0a0a78 = childVar_x583g4_a0a0a0a78; if (!("jetbrains.mps.core.xml.structure.XmlAttribute" .equals(nodeToMatch_x583g4_a0a0a0a78.getConcept().getQualifiedName()))) { return false; } if (!("path" .equals( SNodeAccessUtil.getProperty( nodeToMatch_x583g4_a0a0a0a78, "attrName")))) { return false; } { String childRole_x583g4__7 = "value"; if (!(PatternUtil.hasNChildren( nodeToMatch_x583g4_a0a0a0a78, childRole_x583g4__7, 1))) { return false; } { SNode childVar_x583g4_a0a0a0a0jd = IterableUtil.get( nodeToMatch_x583g4_a0a0a0a78.getChildren(childRole_x583g4__7), 0); this.patternVar_pathvalue = childVar_x583g4_a0a0a0a0jd; } } } } } } } } } return true; }