예제 #1
0
 /**
  * Uncomments the node which is under the comment node specified in constructor
  *
  * <p>Also if containment link of the commented node is singular and non optional comments or
  * deletes the existing child whether it is instance of abstract concept or not respectively
  *
  * @throws IllegalStateException if node to uncomment does not have parent
  * @return node which was under the comment
  */
 public SNode uncomment() {
   if (!(isValid())) {
     throw new IllegalStateException(
         "Node uncommenter has invalid state. Comment attribute has no parent. Attribute "
             + myComment.getPresentation()
             + " Attribute id: "
             + myComment.getNodeId());
   }
   SNode commentedNode =
       SLinkOperations.getTarget(
           myComment,
           MetaAdapterFactory.getContainmentLink(
               0xceab519525ea4f22L,
               0x9b92103b95ca8c0cL,
               0x3dcc194340c24debL,
               0x2ab99f0d2248e89dL,
               "commentedNode"));
   if (getContainmentLink() != null && commentedNode != null) {
     removeOrCommentChildInSingleRole();
     myComment.removeChild(commentedNode);
     getParent().insertChildAfter(getContainmentLink(), commentedNode, myComment);
   }
   SNodeOperations.deleteNode(myComment);
   return commentedNode;
 }
예제 #2
0
 public void apply() {
   if (myNodesToApply.isEmpty()) {
     return;
   }
   SNode first = myNodesToApply.iterator().next();
   SModel model = first.getModel();
   if (model == null) {
     LOG.warning(
         "Checking node which is not attached to the model: "
             + first.getPresentation()
             + " "
             + first.getNodeId());
     return;
   }
   // XXX could I demand here that model has to be attached to a repository, so that I can use one
   // to obtain LanguageRegistry?
   for (SLanguage language : SModelOperations.getAllLanguageImports(model)) {
     LanguageRuntime languageRuntime = LanguageRegistry.getInstance().getLanguage(language);
     if (languageRuntime == null) {
       continue;
     }
     DataFlowAspectDescriptor aspect = languageRuntime.getAspect(DataFlowAspectDescriptor.class);
     if (aspect == null) {
       continue;
     }
     for (DataFlowConstructor rule : aspect.getConstructors(myAnalyzerId)) {
       myRules.add(rule);
     }
   }
   Set<SNode> descendants = new LinkedHashSet<SNode>();
   for (SNode myNodeToApply : myNodesToApply) {
     descendants.addAll(
         SNodeOperations.getNodeDescendants(
             myNodeToApply, null, false, new SAbstractConcept[] {}));
   }
   for (SNode descendant : descendants) {
     getRules(descendant).forEach(rule -> rule.performActions(myProgram, descendant));
   }
 }
예제 #3
0
  private TypeCheckingContext getOrCreateContext(
      SNode node, ITypeContextOwner owner, boolean createIfAbsent) {
    ModelAccess.assertLegalRead();
    if (node == null) return null;
    final SNode rootNode = node.getContainingRoot();
    synchronized (myLock) {
      SNodeReference rootNodePointer = new jetbrains.mps.smodel.SNodePointer(rootNode);

      List<TypecheckingContextHolder> contextWithOwners =
          myTypeCheckingContexts.get(rootNodePointer);
      if (contextWithOwners == null && !createIfAbsent) return null;
      if (contextWithOwners == null) {
        contextWithOwners = new ArrayList<TypecheckingContextHolder>(4);
        myTypeCheckingContexts.put(rootNodePointer, contextWithOwners);
      }

      for (ListIterator<TypecheckingContextHolder> it = contextWithOwners.listIterator();
          it.hasNext(); ) {
        TypecheckingContextHolder contextHolder = it.next();
        if (contextHolder.getOwner() == owner) {

          if (!owner.reuseTypecheckingContext()) {
            assert createIfAbsent;
            return contextHolder.acquire(node);
          } else {
            // reuse the typechecking context
            if (!createIfAbsent) {
              return contextHolder.get(node);
            }

            final TypeCheckingContext ctx = contextHolder.acquire(node);

            // Dirty hack
            if (jetbrains.mps.util.SNodeOperations.isDisposed(ctx.getNode())) {
              removeContextForNode(rootNodePointer);
              LOG.error(
                  "Type Checking Context had a disposed node inside. Node: "
                      + node
                      + " model: "
                      + node.getModel());
              return getOrCreateContext(node, owner, createIfAbsent);
            }

            return ctx;
          }
        }
      }

      // not found, create new
      if (!owner.reuseTypecheckingContext()) {
        assert createIfAbsent;

        final NonReusableTypecheckingContextHolder contextHolder =
            new NonReusableTypecheckingContextHolder(owner);
        contextWithOwners.add(contextHolder);

        return contextHolder.acquire(node);
      } else if (!createIfAbsent) {
        return null;
      } else {
        if (contextWithOwners.size() > 100) {
          if (!myReported) {
            myReported = true;
            LOG.warn(
                "Type checking context for node "
                    + node.getPresentation()
                    + " has too much owners");
          }
        }

        final CountingTypecheckingContextHolder contextHolder =
            new CountingTypecheckingContextHolder(owner);
        contextWithOwners.add(contextHolder);
        return contextHolder.acquire(node);
      }
    }
  }