public DefaultReferenceSubstituteInfoActionsFactory(
     SNode sourceNode, SNode linkDeclaration, DefaultReferenceSubstituteInfo substituteInfo) {
   mySourceNode = sourceNode;
   myLinkDeclaration = linkDeclaration;
   SNode genuineLinkDeclaration =
       BehaviorReflection.invokeNonVirtual(
           (Class<SNode>) ((Class) Object.class),
           myLinkDeclaration,
           "jetbrains.mps.lang.structure.structure.LinkDeclaration",
           "call_getGenuineLink_1213877254523",
           new Object[] {});
   if (genuineLinkDeclaration == null) {
     return;
   }
   if (SPropertyOperations.hasValue(
       genuineLinkDeclaration, "metaClass", "aggregation", "reference")) {
     DefaultReferenceSubstituteInfoActionsFactory.LOG.error(
         "only reference links are allowed here", myLinkDeclaration);
   }
   if (!(BehaviorReflection.invokeNonVirtual(
       Boolean.TYPE,
       genuineLinkDeclaration,
       "jetbrains.mps.lang.structure.structure.LinkDeclaration",
       "call_isSingular_1213877254557",
       new Object[] {}))) {
     DefaultReferenceSubstituteInfoActionsFactory.LOG.error(
         "cardinalities 1 or 0..1 are allowed here", myLinkDeclaration);
   }
   myCurrentReferent =
       SLinkOperations.getTargetNode(SNodeOperations.getReference(sourceNode, myLinkDeclaration));
   mySubstituteInfo = substituteInfo;
 }
 private static SReference getCheckingReference_id4IvydoGvimX(@NotNull SNode __thisNode__) {
   if (SLinkOperations.getTarget(
           __thisNode__,
           MetaAdapterFactory.getReferenceLink(
               0x8585453e6bfb4d80L,
               0x98deb16074f1d86cL,
               0x7181d929c720809L,
               0x4b9f88d62c795596L,
               "checkingReference"))
       == null) {
     return ((SNode) SNodeOperations.getParent(__thisNode__)).getReferences().iterator().next();
   }
   for (SReference reference :
       Sequence.fromIterable(
           SNodeOperations.getReferences(SNodeOperations.getParent(__thisNode__)))) {
     if (SLinkOperations.getTargetNode(reference)
         == SLinkOperations.getTarget(
             __thisNode__,
             MetaAdapterFactory.getReferenceLink(
                 0x8585453e6bfb4d80L,
                 0x98deb16074f1d86cL,
                 0x7181d929c720809L,
                 0x4b9f88d62c795596L,
                 "checkingReference"))) {
       return (jetbrains.mps.smodel.SReference) reference;
     }
   }
   return null;
 }
Beispiel #3
0
 public static SReference call_getCheckingReference_5449224527592367549(SNode thisNode) {
   if (SLinkOperations.getTarget(
           thisNode,
           MetaAdapterFactory.getReferenceLink(
               0x8585453e6bfb4d80L,
               0x98deb16074f1d86cL,
               0x7181d929c720809L,
               0x4b9f88d62c795596L,
               "checkingReference"))
       == null) {
     return ((SNode) SNodeOperations.getParent(thisNode)).getReferences().iterator().next();
   }
   for (SReference reference :
       ListSequence.fromList(SNodeOperations.getReferences(SNodeOperations.getParent(thisNode)))) {
     if (SLinkOperations.getTargetNode(reference)
         == SLinkOperations.getTarget(
             thisNode,
             MetaAdapterFactory.getReferenceLink(
                 0x8585453e6bfb4d80L,
                 0x98deb16074f1d86cL,
                 0x7181d929c720809L,
                 0x4b9f88d62c795596L,
                 "checkingReference"))) {
       return (jetbrains.mps.smodel.SReference) reference;
     }
   }
   return null;
 }
 public static void fixImportsFromNode(SNode node) {
   for (SNode descendant :
       ListSequence.fromList(
           SNodeOperations.getDescendants(
               node, "jetbrains.mps.lang.core.structure.BaseConcept", false, new String[] {}))) {
     for (SReference reference :
         Sequence.fromIterable(SNodeOperations.getReferences(descendant))) {
       addNodeModelImportIfNeed(node, SLinkOperations.getTargetNode(reference));
     }
   }
 }
 public void test_unspecifiedReferences() throws Exception {
   this.addNodeById("2906110183022219846");
   this.addNodeById("2906110183022219807");
   this.addNodeById("2906110183022219843");
   this.addNodeById("2906110183022354865");
   this.addNodeById("2906110183022432276");
   // Adding one unspecified reference and checking if it was added properly
   int initialSize =
       Sequence.fromIterable(
               SNodeOperations.getReferences(
                   SNodeOperations.cast(
                       this.getNodeById("2906110183022432277"),
                       "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer")))
           .count();
   String unspecifiedReferenceName =
       this.addUnspecifiedReference(
           SNodeOperations.cast(
               this.getNodeById("2906110183022432277"),
               "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer"),
           SNodeOperations.cast(
               this.getNodeById("2906110183022219849"),
               "jetbrains.mps.lang.smodelTests.structure.GrandChild"));
   Assert.assertEquals(
       initialSize + 1,
       Sequence.fromIterable(
               SNodeOperations.getReferences(
                   SNodeOperations.cast(
                       this.getNodeById("2906110183022432277"),
                       "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer")))
           .count());
   // Checking if unspecified reference is working properly
   Iterable<SReference> unspecifiedReferences =
       Sequence.fromIterable(
               SNodeOperations.getReferences(
                   SNodeOperations.cast(
                       this.getNodeById("2906110183022432277"),
                       "jetbrains.mps.lang.smodelTests.structure.ReferenceContainer")))
           .where(
               new IWhereFilter<SReference>() {
                 public boolean accept(SReference it) {
                   return (SLinkOperations.findLinkDeclaration(it) == null);
                 }
               });
   Assert.assertEquals(1, Sequence.fromIterable(unspecifiedReferences).count());
   SReference theReference = Sequence.fromIterable(unspecifiedReferences).first();
   Assert.assertEquals(unspecifiedReferenceName, SLinkOperations.getRole(theReference));
   Assert.assertEquals(
       SNodeOperations.cast(
           this.getNodeById("2906110183022219849"),
           "jetbrains.mps.lang.smodelTests.structure.GrandChild"),
       SLinkOperations.getTargetNode(theReference));
 }
 public void test_forNull() throws Exception {
   this.addNodeById("2906110183022219846");
   this.addNodeById("2906110183022219807");
   this.addNodeById("2906110183022219843");
   this.addNodeById("2906110183022354865");
   this.addNodeById("2906110183022432276");
   SNode nullNode = null;
   Assert.assertTrue(Sequence.fromIterable(SNodeOperations.getReferences(nullNode)).isEmpty());
   SReference nullReference = null;
   Assert.assertNull(SLinkOperations.findLinkDeclaration(nullReference));
   Assert.assertNull(SLinkOperations.getRole(nullReference));
   Assert.assertNull(SLinkOperations.getTargetNode(nullReference));
   Assert.assertNull(SLinkOperations.getResolveInfo(nullReference));
 }
Beispiel #7
0
 protected void addNodeImports(SNode node) {
   final SModelInternal modelInternal = (SModelInternal) myModel;
   final AbstractModule module = ((AbstractModule) myModel.getModule());
   final Collection<SLanguage> importedLanguages = modelInternal.importedLanguageIds();
   for (SNode subNode :
       ListSequence.fromList(
           SNodeOperations.getNodeDescendants(node, null, true, new SAbstractConcept[] {}))) {
     SLanguage usedLanguage = subNode.getConcept().getLanguage();
     if (!(importedLanguages.contains(usedLanguage))) {
       modelInternal.addLanguage(usedLanguage);
     }
     for (SReference ref : ListSequence.fromList(SNodeOperations.getReferences(subNode))) {
       SModel usedModel = SNodeOperations.getModel(SLinkOperations.getTargetNode(ref));
       if (usedModel != null && !(modelInternal.importedModels().contains(usedModel))) {
         modelInternal.addModelImport(usedModel.getReference(), false);
         module.addDependency(
             SNodeOperations.getModel(SLinkOperations.getTargetNode(ref))
                 .getModule()
                 .getModuleReference(),
             false);
       }
     }
   }
 }
Beispiel #8
0
 public ModelLinkMap build() {
   // build map based on already loaded model
   for (SNode node : myModel.nodes()) {
     addRoleLocation(ptr(node.getRoleLink()), node);
     addTypeLocation(ptr(SNodeOperations.getConceptDeclaration(node)), node);
     for (String prop : SetSequence.fromSet(node.getPropertyNames())) {
       addNameLocation(ptr(node.getPropertyDeclaration(prop)), node, prop);
     }
     for (SReference ref : Sequence.fromIterable(SNodeOperations.getReferences(node))) {
       addRoleLocation(ptr(SLinkOperations.findLinkDeclaration(ref)), ref);
       if ((SReference) ref instanceof StaticReference) {
         addTargetLocation(
             ptr(SLinkOperations.getTargetNode(ref)), (StaticReference) (SReference) ref);
       } else {
         addDynamicReference(ref.getTargetSModelReference(), (DynamicReference) (SReference) ref);
       }
     }
   }
   return this;
 }
Beispiel #9
0
 public DefaultReferenceSubstituteInfoActionsFactory(
     SNode sourceNode, SNode linkDeclaration, DefaultReferenceSubstituteInfo substituteInfo) {
   mySourceNode = sourceNode;
   myLinkDeclaration = linkDeclaration;
   SNode genuineLinkDeclaration =
       ((SNode)
           BehaviorManager.getInstance()
               .invoke(
                   Object.class,
                   SNodeOperations.cast(
                       myLinkDeclaration,
                       "jetbrains.mps.lang.structure.structure.LinkDeclaration"),
                   "call_getGenuineLink_1213877254523",
                   new Class[] {SNode.class}));
   if (genuineLinkDeclaration == null) {
     return;
   }
   if (SPropertyOperations.hasValue(
       genuineLinkDeclaration, "metaClass", "aggregation", "reference")) {
     DefaultReferenceSubstituteInfoActionsFactory.LOG.error(
         "only reference links are allowed here", myLinkDeclaration);
   }
   if (!(((Boolean)
       BehaviorManager.getInstance()
           .invoke(
               Boolean.class,
               SNodeOperations.cast(
                   genuineLinkDeclaration,
                   "jetbrains.mps.lang.structure.structure.LinkDeclaration"),
               "call_isSingular_1213877254557",
               new Class[] {SNode.class})))) {
     DefaultReferenceSubstituteInfoActionsFactory.LOG.error(
         "cardinalities 1 or 0..1 are allowed here", myLinkDeclaration);
   }
   myCurrentReferent =
       SLinkOperations.getTargetNode(SNodeOperations.getReference(sourceNode, myLinkDeclaration));
   mySubstituteInfo = substituteInfo;
 }
    @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;
    }
Beispiel #11
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)));
     }
   }
 }