private static List<INodeSubstituteAction> createPrimaryChildSubstituteActions(
      SNode parentNode,
      SNode currentChild,
      SNode childConcept,
      IChildNodeSetter childSetter,
      IOperationContext context) {

    if (childConcept == null) {
      return Collections.emptyList();
    }
    final IScope scope = context.getScope();

    String childConceptFqName = NameUtil.nodeFQName(childConcept);
    Set<String> concepts = new HashSet<String>();
    for (Language l : SModelOperations.getLanguages(parentNode.getModel(), scope)) {
      concepts.addAll(
          LanguageHierarchyCache.getInstance()
              .getDefaultSubstitutableDescendantsOf(childConceptFqName, l));
    }

    List<INodeSubstituteAction> actions = new ArrayList<INodeSubstituteAction>();
    for (String fqName : concepts) {
      SNode applicableConcept = SModelUtil.findConceptDeclaration(fqName, scope);
      assert applicableConcept != null : "No concept " + fqName;
      actions.addAll(
          createDefaultActions(applicableConcept, parentNode, currentChild, childSetter, context));
    }

    return actions;
  }
 @Override
 @NotNull
 protected List<MenuPart<TransformationMenuItem, TransformationMenuContext>> getParts(
     TransformationMenuContext _context) {
   List<MenuPart<TransformationMenuItem, TransformationMenuContext>> result =
       new ArrayList<MenuPart<TransformationMenuItem, TransformationMenuContext>>();
   if (ListSequence.fromListAndArray(
           new ArrayList<String>(),
           MenuLocations.LEFT_SIDE_TRANSFORM,
           MenuLocations.RIGHT_SIDE_TRANSFORM)
       .contains(_context.getMenuLocation())) {
     result.add(
         new DefaultConceptMenusTransformationMenuPart(
             SModelUtil.getDirectSuperConcepts(
                 MetaAdapterFactory.getConcept(
                     0x7866978ea0f04cc7L,
                     0x81bc4d213d9375e1L,
                     0x58ea5217b045b9abL,
                     "jetbrains.mps.lang.smodel.structure.AttributeQualifier"))));
   }
   if (ListSequence.fromListAndArray(new ArrayList<String>(), MenuLocations.RIGHT_SIDE_TRANSFORM)
       .contains(_context.getMenuLocation())) {
     result.add(
         new AttributeQualifier_TransformationMenu.TransformationMenuPart_IncludeMenu_5hmkak_a1());
   }
   return result;
 }
 @Override
 @NotNull
 protected List<MenuPart<TransformationMenuItem, TransformationMenuContext>> getParts(
     TransformationMenuContext _context) {
   List<MenuPart<TransformationMenuItem, TransformationMenuContext>> result =
       new ArrayList<MenuPart<TransformationMenuItem, TransformationMenuContext>>();
   if (ListSequence.fromListAndArray(
           new ArrayList<String>(),
           MenuLocations.LEFT_SIDE_TRANSFORM,
           MenuLocations.RIGHT_SIDE_TRANSFORM)
       .contains(_context.getMenuLocation())) {
     result.add(
         new DefaultConceptMenusTransformationMenuPart(
             SModelUtil.getDirectSuperConcepts(
                 MetaAdapterFactory.getConcept(
                     0xf3061a5392264cc5L,
                     0xa443f952ceaf5816L,
                     0xfbdeb6fecfL,
                     "jetbrains.mps.baseLanguage.structure.BinaryOperation"))));
   }
   if (ListSequence.fromListAndArray(new ArrayList<String>(), MenuLocations.LEFT_SIDE_TRANSFORM)
       .contains(_context.getMenuLocation())) {
     result.add(
         new BinaryOperation_TransformationMenu
             .TransformationMenuPart_WrapSubstituteMenu_kltahs_a1());
   }
   if (ListSequence.fromListAndArray(new ArrayList<String>(), MenuLocations.RIGHT_SIDE_TRANSFORM)
       .contains(_context.getMenuLocation())) {
     result.add(
         new BinaryOperation_TransformationMenu
             .TransformationMenuPart_WrapSubstituteMenu_kltahs_a2());
   }
   return result;
 }
 @Override
 @NotNull
 protected List<MenuPart<TransformationMenuItem, TransformationMenuContext>> getParts(
     TransformationMenuContext _context) {
   List<MenuPart<TransformationMenuItem, TransformationMenuContext>> result =
       new ArrayList<MenuPart<TransformationMenuItem, TransformationMenuContext>>();
   if (ListSequence.fromListAndArray(
           new ArrayList<String>(),
           MenuLocations.LEFT_SIDE_TRANSFORM,
           MenuLocations.RIGHT_SIDE_TRANSFORM)
       .contains(_context.getMenuLocation())) {
     result.add(
         new DefaultConceptMenusTransformationMenuPart(
             SModelUtil.getDirectSuperConcepts(
                 MetaAdapterFactory.getConcept(
                     0xf3347d8a0e794f35L,
                     0x8ac91574f25c986fL,
                     0xbe3a0d5ba1a2c12L,
                     "jetbrains.mps.execution.commands.structure.ProcessType"))));
   }
   if (ListSequence.fromListAndArray(new ArrayList<String>(), MenuLocations.RIGHT_SIDE_TRANSFORM)
       .contains(_context.getMenuLocation())) {
     result.add(
         new ConstraintsFilteringTransformationMenuPartDecorator(
             new ProcessType_TransformationMenu.TransformationMenuPart_Action_fvqin_a1(),
             MetaAdapterFactory.getConcept(
                 0xf3347d8a0e794f35L,
                 0x8ac91574f25c986fL,
                 0x87f99370d7e1ea3L,
                 "jetbrains.mps.execution.commands.structure.CommandProcessType")));
   }
   return result;
 }
示例#5
0
 public static void addVariablePattern(EditorContext context) {
   EditorCell contextCell = context.getSelectedCell();
   SNode node = contextCell.getSNode();
   SNode linkDeclaration =
       SNodeOperations.cast(
           contextCell.getLinkDeclaration(),
           "jetbrains.mps.lang.structure.structure.LinkDeclaration");
   SNode genuineLinkDeclaration = SModelUtil.getGenuineLinkDeclaration(linkDeclaration);
   if (linkDeclaration != null
       && SPropertyOperations.hasValue(
           genuineLinkDeclaration, "metaClass", "reference", "reference")) {
     String role = SPropertyOperations.getString(genuineLinkDeclaration, "role");
     AttributeOperations.createAndSetAttrbiute(
         node,
         new IAttributeDescriptor.LinkAttribute(
             SConceptOperations.findConceptDeclaration(
                 "jetbrains.mps.lang.pattern.structure.LinkPatternVariableDeclaration"),
             role),
         "jetbrains.mps.lang.pattern.structure.LinkPatternVariableDeclaration");
   } else {
     AttributeOperations.createAndSetAttrbiute(
         node,
         new IAttributeDescriptor.NodeAttribute(
             SConceptOperations.findConceptDeclaration(
                 "jetbrains.mps.lang.pattern.structure.Pattern")),
         "jetbrains.mps.lang.pattern.structure.PatternVariableDeclaration");
   }
 }
 public SNodePointer getConcept() {
   if (myConcept == null) {
     myConcept =
         new SNodePointer(
             SModelUtil.findConceptDeclaration(myConceptName, GlobalScope.getInstance()));
   }
   return myConcept;
 }
  @Override
  public boolean isSubConceptOf(SAbstractConcept concept) {
    if (!(concept instanceof SConceptNodeAdapterBase)) {
      throw new IllegalArgumentException("not supported");
    }

    return SModelUtil.isAssignableConcept(
        myConceptName, ((SConceptNodeAdapterBase) concept).myConceptName);
  }
 public SNode createChildNode(Object parameterObject, SModel model, String pattern) {
   SNode childNode =
       SModelUtil_new.instantiateConceptDeclaration(
           NameUtil.nodeFQName(mySmartConcept), model, GlobalScope.getInstance());
   String referentRole = SModelUtil.getGenuineLinkRole(mySmartReference);
   childNode.setReferenceTarget(referentRole, myReferentNode);
   NodeFactoryManager.setupNode(
       mySmartConcept, childNode, myCurrentChild, myParentNode, model, getScope());
   return childNode;
 }
  private void collectAncestorNames(String conceptFqName, Set<String> result) {
    if (result.contains(conceptFqName)) return;

    result.add(conceptFqName);

    SNode declaration = SModelUtil.findConceptDeclaration(conceptFqName, GlobalScope.getInstance());
    if (declaration == null) {
      return;
    }

    if (SNodeUtil.isInstanceOfConceptDeclaration(declaration)) {
      SNode extendedConcept = SNodeUtil.getConceptDeclaration_Extends(declaration);
      if (extendedConcept != null) {
        Language declaringLanguage = SModelUtil.getDeclaringLanguage(extendedConcept);
        if (declaringLanguage != null) {
          collectAncestorNames(NameUtil.nodeFQName(extendedConcept), result);
        }
      } else if (!SNodeUtil.concept_BaseConcept.equals(NameUtil.nodeFQName(declaration))) {
        collectAncestorNames(SNodeUtil.concept_BaseConcept, result);
      }

      for (SNode interfaceConcept : SNodeUtil.getConceptDeclaration_Implements(declaration)) {
        if (interfaceConcept == null) continue;
        Language declaringLanguage = SModelUtil.getDeclaringLanguage(interfaceConcept);
        if (declaringLanguage == null) continue;
        collectAncestorNames(NameUtil.nodeFQName(interfaceConcept), result);
      }
    } else if (SNodeUtil.isInstanceOfInterfaceConceptDeclaration(declaration)) {
      for (SNode interfaceConcept : SNodeUtil.getInterfaceConceptDeclaration_Extends(declaration)) {
        if (interfaceConcept == null) continue;
        Language declaringLanguage = SModelUtil.getDeclaringLanguage(interfaceConcept);
        if (declaringLanguage == null) continue;
        collectAncestorNames(NameUtil.nodeFQName(interfaceConcept), result);
      }
    }
  }
示例#10
0
 private static StringBuilder checkModel(final SModel sm) {
   StringBuilder errorMessages = new StringBuilder();
   List<String> validationResult =
       ModelAccess.instance()
           .runReadAction(
               new Computable<List<String>>() {
                 public List<String> compute() {
                   return new ModelValidator(sm).validate();
                 }
               });
   if (!(validationResult.isEmpty())) {
     errorMessages.append("errors in model: ").append(sm.getReference().toString()).append("\n");
     for (String item : validationResult) {
       errorMessages.append("\t");
       errorMessages.append(item);
       errorMessages.append("\n");
     }
   }
   for (SNode node : SNodeUtil.getDescendants(sm)) {
     // Testbench.LOG.debug("Checking node " + node);
     if (SModelUtil.findConceptDeclaration(node.getConcept().getQualifiedName()) == null) {
       errorMessages.append("Unknown concept ");
       errorMessages.append(node.getConcept().getQualifiedName());
       errorMessages.append("\n");
     }
   }
   for (SNode node : SNodeUtil.getDescendants(sm)) {
     for (SReference ref : node.getReferences()) {
       if (jetbrains.mps.smodel.SNodeUtil.hasReferenceMacro(node, ref.getRole())) {
         continue;
       }
       if (SNodeOperations.getTargetNodeSilently(ref) == null) {
         errorMessages
             .append("Broken reference in model {")
             .append(SNodeOperations.getModelLongName(node.getModel()))
             .append("}")
             .append(" node ")
             .append(node.getNodeId().toString())
             .append("(")
             .append(node)
             .append(")\n");
       }
     }
   }
   return errorMessages;
 }
 public IReferenceInfoResolver getReferenceInfoResolver(SNode referenceNode, SNode targetConcept) {
   if (SModelUtil.isAssignableConcept(
       NameUtil.nodeFQName(targetConcept),
       "jetbrains.mps.baseLanguage.structure.ConstructorDeclaration")) {
     if (SNodeOperations.isInstanceOf(
         referenceNode, "jetbrains.mps.baseLanguage.structure.ClassCreator")) {
       SNode classCreator =
           SNodeOperations.cast(
               referenceNode, "jetbrains.mps.baseLanguage.structure.ClassCreator");
       return new VisibleClassConstructorsScope.ConstructorDeclarationReferenceInfoResolver(
           SLinkOperations.getTargets(classCreator, "actualArgument", true),
           SLinkOperations.getTargets(classCreator, "typeParameter", true),
           getModel(),
           getScope());
     }
   }
   return super.getReferenceInfoResolver(referenceNode, targetConcept);
 }
示例#12
0
 @Override
 public IReferenceInfoResolver getReferenceInfoResolver(SNode referenceNode, SNode targetConcept) {
   if (SModelUtil.isAssignableConcept(
       targetConcept,
       SConceptOperations.findConceptDeclaration(
           "jetbrains.mps.baseLanguage.structure.LocalVariableDeclaration"))) {
     return new IReferenceInfoResolver() {
       @Override
       public SNode resolve(String referenceInfo, SModelReference targetModelReference) {
         if (referenceInfo == null) {
           return null;
         }
         for (SNode node : LocalVariablesScope.this.getNodes(AbstractSearchScope.TRUE_CONDITION)) {
           if (referenceInfo.equals(node.getName())) {
             return node;
           }
         }
         return null;
       }
     };
   }
   return super.getReferenceInfoResolver(referenceNode, targetConcept);
 }
示例#13
0
 public void checkNode(
     final SNode node,
     LanguageErrorsComponent component,
     final IOperationContext operationContext,
     IScope scope) {
   if (operationContext == null) {
     return;
   }
   if (SNodeUtil.getMetaLevel(node) != 0) {
     return;
   }
   SNode concept = SNodeOperations.getConceptDeclaration(node);
   for (SReference ref : SNodeOperations.getReferences(node)) {
     SNode target = SLinkOperations.getTargetNode(ref);
     SNode ld = SLinkOperations.findLinkDeclaration(ref);
     // don't check unresolved and broken references, they should already have an error message
     if ((target == null) || ld == null) {
       continue;
     }
     component.addDependency(target);
     component.addDependency(ld);
     component.addDependency(node);
     component.addDependency(SNodeOperations.getParent(node));
     for (SNode c : SNodeOperations.getChildren(node)) {
       component.addDependency(c);
     }
     String linkRole = SModelUtil.getGenuineLinkRole(ld);
     final SNode linkTarget = SLinkOperations.getTarget(ld, "target", false);
     final INodeReferentSearchScopeProvider scopeProvider =
         ModelConstraintsUtil.getSearchScopeProvider(concept, linkRole);
     SearchScopeStatus searchScopeStatus =
         component.runCheckingAction(
             new _FunctionTypes._return_P0_E0<SearchScopeStatus>() {
               public SearchScopeStatus invoke() {
                 return ModelConstraintsUtil.createSearchScope(
                     scopeProvider,
                     SNodeOperations.getModel(node),
                     SNodeOperations.getParent(node),
                     node,
                     linkTarget,
                     operationContext);
               }
             });
     if (searchScopeStatus.isError()) {
       component.addError(
           node,
           searchScopeStatus.getMessage(),
           (SNode) null,
           new ReferenceMessageTarget(SLinkOperations.getRole(ref)));
     } else if (!(searchScopeStatus.isDefault()
         || searchScopeStatus.getSearchScope().isInScope(target))) {
       String name = target.getName();
       component.addError(
           node,
           "reference"
               + ((name == null ? "" : " " + name))
               + " ("
               + SLinkOperations.getRole(ref)
               + ") is out of search scope",
           searchScopeStatus.getReferenceValidatorNode(),
           new ReferenceMessageTarget(SLinkOperations.getRole(ref)));
     }
   }
 }
示例#14
0
 public static SNode findLinkDeclaration(String conceptFqName, String linkRole) {
   SNode concept = SModelUtil.findConceptDeclaration(conceptFqName);
   SNode linkDeclaration = SModelSearchUtil.findLinkDeclaration(concept, linkRole);
   return linkDeclaration;
 }
  private static List<INodeSubstituteAction> createSmartReferenceActions(
      final SNode smartConcept,
      final SNode smartReference,
      final SNode parentNode,
      final SNode currentChild,
      final IChildNodeSetter childSetter,
      final IOperationContext context) {

    if (parentNode == null) {
      return null;
    }

    // try to create referent-search-scope
    SNode linkDeclaration = null;
    int index = 0;
    if (currentChild != null) {
      linkDeclaration = currentChild.getRoleLink();
      index = parentNode.getChildren(currentChild.getRoleInParent()).indexOf(currentChild);
    }
    //    TODO generate wrapping setter to have access to original link
    //    if(childSetter instanceof WrappingSetter) {
    //      childSetter = ((WrappingSetter)childSetter).unwrap();
    //    }
    if (linkDeclaration == null && childSetter instanceof DefaultChildNodeSetter) {
      linkDeclaration = ((DefaultChildNodeSetter) childSetter).getLinkDeclaration();
    }

    //    TODO restore (when wrapping setter is created)
    //    if (linkDeclaration == null) {
    //      return null;
    //    }

    ReferenceDescriptor refDescriptor =
        ModelConstraintsUtil.getSmartReferenceDescriptor(
            parentNode,
            linkDeclaration == null ? null : SModelUtil.getLinkDeclarationRole(linkDeclaration),
            index,
            smartConcept);
    if (refDescriptor == null) return null;

    Scope searchScope = refDescriptor.getScope();
    if (searchScope == null) return null;

    // create smart actions
    final String targetConcept =
        NameUtil.nodeFQName(SModelUtil.getLinkDeclarationTarget(smartReference));
    List<INodeSubstituteAction> actions = new ArrayList<INodeSubstituteAction>();
    IReferencePresentation presentation = refDescriptor.getReferencePresentation();
    Iterable<SNode> referentNodes = searchScope.getAvailableElements(null);
    for (SNode referentNode : referentNodes) {
      if (referentNode == null
          || !referentNode
              .getConcept()
              .isSubConceptOf(SConceptRepository.getInstance().getConcept(targetConcept))) continue;
      actions.add(
          new SmartRefChildNodeSubstituteAction(
              referentNode,
              parentNode,
              currentChild,
              childSetter,
              context.getScope(),
              smartConcept,
              smartReference,
              presentation));
    }

    return actions;
  }
示例#16
0
    @Override
    public List<SearchResult<ModelCheckerIssue>> checkModel(
        SModel model, ProgressMonitor monitor, SRepository repository) {
      List<SearchResult<ModelCheckerIssue>> results =
          ListSequence.fromList(new ArrayList<SearchResult<ModelCheckerIssue>>());

      monitor.start("adapter usages", 1);
      for (SNode node : ListSequence.fromList(SModelOperations.getNodes(model, null))) {
        if (monitor.isCanceled()) {
          break;
        }
        // Check for adapter references
        for (SReference ref : Sequence.fromIterable(SNodeOperations.getReferences(node))) {
          SModelReference targetSModelReference = ref.getTargetSModelReference();
          if (targetSModelReference != null
              && SModelStereotype.getStereotype(targetSModelReference.getModelName())
                  .equals("java_stub")) {
            SNode target = SLinkOperations.getTargetNode(ref);
            if ((target != null)
                && SNodeOperations.isInstanceOf(
                    target, "jetbrains.mps.baseLanguage.structure.ClassConcept")) {
              String qualifiedName =
                  BehaviorReflection.invokeVirtual(
                      String.class,
                      SNodeOperations.cast(
                          target, "jetbrains.mps.baseLanguage.structure.ClassConcept"),
                      "virtual_getFqName_1213877404258",
                      new Object[] {});
              if ("jetbrains.mps.smodel.INodeAdapter".equals(qualifiedName)
                  || "jetbrains.mps.smodel.BaseAdapter".equals(qualifiedName)) {
                SpecificChecker.addIssue(
                    results,
                    node,
                    "Reference to "
                        + qualifiedName
                        + " in role `"
                        + SLinkOperations.getRole(ref)
                        + "'",
                    ModelChecker.SEVERITY_ERROR,
                    "adapter class usage",
                    null);
              }

              if (SModelStereotype.withoutStereotype(targetSModelReference.getModelName())
                      .endsWith(".structure")
                  && SModelUtil.findConceptDeclaration(qualifiedName) != null) {
                SpecificChecker.addIssue(
                    results,
                    node,
                    "Using adapter of "
                        + qualifiedName
                        + " concept in role `"
                        + SLinkOperations.getRole(ref)
                        + "'",
                    ModelChecker.SEVERITY_ERROR,
                    "adapter class usage",
                    null);
              }
            }
          }
        }
      }
      monitor.done();
      return results;
    }
  private static List<INodeSubstituteAction> createActions_internal(
      SNode parentNode,
      SNode currentChild,
      SNode childConcept,
      IChildNodeSetter childSetter,
      IOperationContext context) {
    List<INodeSubstituteAction> resultActions = new ArrayList<INodeSubstituteAction>();
    if (childConcept == null) {
      return resultActions;
    }

    // special case
    if (childConcept == SModelUtil.getBaseConcept()) {
      if ((currentChild == null
          || currentChild.getConcept().getId().equals(SNodeUtil.concept_BaseConcept))) {
        resultActions = new ArrayList<INodeSubstituteAction>();
        ISearchScope conceptsSearchScope =
            SModelSearchUtil.createConceptsFromModelLanguagesScope(
                parentNode.getModel(), true, context.getScope());
        List<SNode> allVisibleConcepts = conceptsSearchScope.getNodes();
        for (final SNode visibleConcept : allVisibleConcepts) {
          resultActions.add(
              new DefaultChildNodeSubstituteAction(
                  visibleConcept, parentNode, currentChild, childSetter, context.getScope()) {
                public String getMatchingText(String pattern) {
                  return getMatchingText(pattern, true, true);
                }

                public String getVisibleMatchingText(String pattern) {
                  return getMatchingText(pattern);
                }

                public String getDescriptionText(String pattern) {
                  String fqName = NameUtil.nodeFQName(visibleConcept);
                  return "lang: "
                      + NameUtil.compactNamespace(NameUtil.namespaceFromConceptFQName(fqName));
                }

                public Icon getIconFor(String pattern) {
                  return getIconFor(pattern, true);
                }
              });
        }
        return resultActions;
      }

      // pretend we are going to substitute more concrete concept
      childConcept = ChildSubstituteActionsUtil.getRefinedChildConcept(currentChild);
    }

    Language primaryLanguage = SModelUtil.getDeclaringLanguage(childConcept);
    if (primaryLanguage == null) {
      LOG.error(
          "Couldn't build actions : couldn't get declaring language for concept "
              + org.jetbrains.mps.openapi.model.SNodeUtil.getDebugText(childConcept));
      return resultActions;
    }

    List<SNode> allBuilders =
        ChildSubstituteActionsUtil.getActionsBuilders(
            parentNode, currentChild, childConcept, childSetter, context);
    if (!ChildSubstituteActionsUtil.containsRemoveDefaults(allBuilders)) {
      resultActions.addAll(
          createPrimaryChildSubstituteActions(
              parentNode, currentChild, childConcept, childSetter, context));
    }

    for (SNode builder : allBuilders) {
      List<INodeSubstituteAction> addActions =
          ChildSubstituteActionsUtil.invokeActionFactory(
              builder, parentNode, currentChild, childConcept, childSetter, context);
      resultActions.addAll(addActions);
    }

    for (SNode builder : allBuilders) {
      resultActions =
          ChildSubstituteActionsUtil.applyActionFilter(
              builder, resultActions, parentNode, currentChild, childConcept, context);
    }

    if (childSetter instanceof DefaultChildNodeSetter
        || childSetter instanceof AbstractCellMenuPart_ReplaceNode_CustomNodeConcept
            && currentChild != null) {
      SNode linkDeclaration;
      if (childSetter instanceof DefaultChildNodeSetter) {
        linkDeclaration = ((DefaultChildNodeSetter) childSetter).myLinkDeclaration;
      } else {
        linkDeclaration = currentChild.getRoleLink();
      }

      Iterator<INodeSubstituteAction> it = resultActions.iterator();
      while (it.hasNext()) {
        INodeSubstituteAction action = it.next();

        SNode conceptNode = action.getOutputConcept();
        if (conceptNode == null) {
          continue;
        }

        if (!ModelConstraintsManager.canBeParent(parentNode, conceptNode, linkDeclaration, context)
            || !ModelConstraintsManager.canBeAncestor(parentNode, conceptNode, context)) {
          it.remove();
        }
      }
    }

    return resultActions;
  }