Ejemplo n.º 1
0
  private static Map<String, String> getNestedClassifiers(SNode classifier) {
    // returns map from simpleName to fqName
    Map<String, String> nestedClassifiers = new HashMap<String, String>();

    // todo: classifiers with same names in different supertypes?
    for (SNode superClassifier :
        Classifier_Behavior.call_getAllExtendedClassifiers_2907982978864985482(
            SNodeOperations.cast(classifier, "jetbrains.mps.baseLanguage.structure.Classifier"))) {
      for (SNode nestedClassifier :
          Classifier_Behavior.call_nestedClassifiers_5292274854859193142(superClassifier)) {
        addClassifierToBindingMap(nestedClassifiers, nestedClassifier);
      }
    }

    return nestedClassifiers;
  }
 public void applyRule(
     final SNode classifier,
     final TypeCheckingContext typeCheckingContext,
     IsApplicableStatus status) {
   List<SNode> ownMethods = Classifier_Behavior.call_getOwnMethods_1906502351318572840(classifier);
   ClassifierAndSuperClassifiersScope scope =
       new ClassifierAndSuperClassifiersScope(
           classifier,
           IClassifiersSearchScope.INSTANCE_METHOD | IClassifiersSearchScope.STATIC_METHOD);
   for (SNode ownMethod : ownMethods) {
     List<SNode> namesakes =
         scope.getMethodsByName(SPropertyOperations.getString(ownMethod, "name"));
     if (namesakes.size() < 2) {
       continue;
     }
     RulesFunctions_BaseLanguage.checkDuplicates(
         typeCheckingContext, ownMethod, classifier, namesakes);
   }
 }
  private boolean isApplicableToNode(final SNode node, final EditorContext editorContext) {
    if (!(SNodeOperations.isInstanceOf(
        SLinkOperations.getTarget(node, "visibility", true),
        "jetbrains.mps.baseLanguage.structure.PublicVisibility"))) {
      return false;
    }
    SNode classifierType =
        SNodeOperations.as(
            SLinkOperations.getTarget(node, "type", true),
            "jetbrains.mps.baseLanguage.structure.ClassifierType");
    if (classifierType == null
        && SLinkOperations.getTarget(classifierType, "classifier", false) == null) {
      return false;
    }

    Set<SNode> allExtendedClassifiers =
        Classifier_Behavior.call_getAllExtendedClassifiers_2907982978864985482(
            SLinkOperations.getTarget(classifierType, "classifier", false));
    return SetSequence.fromSet(allExtendedClassifiers)
        .contains(
            SNodeOperations.getNode(
                "f:java_stub#67b3c41d-58b3-4756-b971-30bf8a9d63e6#jetbrains.jetpad.projectional.view(jetbrains.jetpad/jetbrains.jetpad.projectional.view@java_stub)",
                "~ViewPropertySpec"));
  }
  public void applyRule(
      final SNode classifier,
      final TypeCheckingContext typeCheckingContext,
      IsApplicableStatus status) {
    OverridingMethodsFinder finder = new OverridingMethodsFinder(classifier);
    for (SNode overridingMethod : SetSequence.fromSet(finder.getOverridingMethods())) {
      Set<Tuples._2<SNode, SNode>> overridenMethods = finder.getOverridenMethods(overridingMethod);
      for (Iterator<Tuples._2<SNode, SNode>> it = SetSequence.fromSet(overridenMethods).iterator();
          it.hasNext(); ) {
        SNode overridenMethod = it.next()._0();
        SNode returnType = SLinkOperations.getTarget(overridenMethod, "returnType", true);
        SNode ancestor =
            SNodeOperations.cast(
                SNodeOperations.getParent(overridenMethod),
                "jetbrains.mps.baseLanguage.structure.Classifier");
        SNode overridingMethodParent = SNodeOperations.getParent(overridingMethod);
        SNode resolvedReturnType;
        if (SNodeOperations.isInstanceOf(
            overridingMethodParent, "jetbrains.mps.baseLanguage.structure.Classifier")) {
          resolvedReturnType =
              Classifier_Behavior.call_getWithResolvedTypevars_3305065273710852527(
                  SNodeOperations.cast(
                      overridingMethodParent, "jetbrains.mps.baseLanguage.structure.Classifier"),
                  returnType,
                  ancestor,
                  overridingMethod,
                  overridenMethod);
        } else if (SNodeOperations.isInstanceOf(
            overridingMethodParent,
            "jetbrains.mps.baseLanguage.structure.EnumConstantDeclaration")) {
          SNode enumClass =
              SNodeOperations.cast(
                  SNodeOperations.getParent(
                      SNodeOperations.cast(
                          overridingMethodParent,
                          "jetbrains.mps.baseLanguage.structure.EnumConstantDeclaration")),
                  "jetbrains.mps.baseLanguage.structure.EnumClass");
          SNode dummy =
              SConceptOperations.createNewNode(
                  "jetbrains.mps.baseLanguage.structure.AnonymousClass", null);
          SLinkOperations.setTarget(dummy, "classifier", enumClass, false);
          resolvedReturnType =
              Classifier_Behavior.call_getWithResolvedTypevars_3305065273710852527(
                  dummy, returnType, ancestor, overridingMethod, overridenMethod);
        } else {
          {
            MessageTarget errorTarget = new NodeMessageTarget();
            IErrorReporter _reporter_2309309498 =
                typeCheckingContext.reportTypeError(
                    overridingMethodParent,
                    "This node is not supposed to override methods",
                    "r:00000000-0000-4000-0000-011c895902c5(jetbrains.mps.baseLanguage.typesystem)",
                    "6207253590661761584",
                    null,
                    errorTarget);
          }
          return;
        }

        if (!(TypeChecker.getInstance()
            .getSubtypingManager()
            .isSubtype(
                SLinkOperations.getTarget(overridingMethod, "returnType", true),
                resolvedReturnType))) {
          {
            MessageTarget errorTarget = new NodeMessageTarget();
            IErrorReporter _reporter_2309309498 =
                typeCheckingContext.reportTypeError(
                    SLinkOperations.getTarget(overridingMethod, "returnType", true),
                    "method's return type is incompatible with overridden method ",
                    "r:00000000-0000-4000-0000-011c895902c5(jetbrains.mps.baseLanguage.typesystem)",
                    "2792291462223216211",
                    null,
                    errorTarget);
          }
          break;
        }
      }
    }
  }
Ejemplo n.º 5
0
 public void doGenerateText(SNode node) {
   if (getBuffer().hasPositionsSupport()) {
     TraceInfoGenerationUtil.createUnitInfo(this, node);
   }
   if ((AttributeOperations.getAttribute(
           node,
           new IAttributeDescriptor.NodeAttribute(
               "jetbrains.mps.baseLanguage.javadoc.structure.ClassifierDocComment"))
       != null)) {
     appendNode(
         AttributeOperations.getAttribute(
             node,
             new IAttributeDescriptor.NodeAttribute(
                 "jetbrains.mps.baseLanguage.javadoc.structure.ClassifierDocComment")));
   }
   BaseLanguageTextGen.fileHeader(node, this);
   BaseLanguageTextGen.annotations(node, this);
   BaseLanguageTextGen.visibilityWithIndent(
       SLinkOperations.getTarget(node, "visibility", true), this);
   if (Classifier_Behavior.call_isInner_521412098689998677(node)
       && BehaviorReflection.invokeVirtual(
           Boolean.TYPE, node, "virtual_isStatic_7405920559687241224", new Object[] {})) {
     this.append("static ");
   }
   if (SPropertyOperations.getBoolean(node, "abstractClass")) {
     this.append("abstract ");
   }
   if (SPropertyOperations.getBoolean(node, "isFinal")) {
     this.append("final ");
   }
   this.append("class ");
   this.append(SPropertyOperations.getString(node, "name"));
   GenericDeclarationTextGen2.typeDeclarations(node, this);
   if ((SLinkOperations.getTarget(node, "superclass", true) != null)) {
     this.append(" extends ");
     appendNode(SLinkOperations.getTarget(node, "superclass", true));
   }
   if (ListSequence.fromList(SLinkOperations.getTargets(node, "implementedInterface", true))
       .isNotEmpty()) {
     this.append(" implements ");
     {
       Iterable<SNode> collection = SLinkOperations.getTargets(node, "implementedInterface", true);
       final SNode lastItem = Sequence.fromIterable(collection).last();
       for (SNode item : collection) {
         appendNode(item);
         if (item != lastItem) {
           append(", ");
         }
       }
     }
   }
   this.append(" ");
   BaseClassConceptTextGen.membersWithBrackets(node, true, this);
   this.appendNewLine();
   if (getBuffer().hasPositionsSupport()) {
     {
       String unitName = null;
       try {
         unitName =
             BehaviorReflection.invokeVirtual(
                 String.class,
                 SNodeOperations.cast(node, "jetbrains.mps.lang.traceable.structure.UnitConcept"),
                 "virtual_getUnitName_5067982036267369911",
                 new Object[] {});
       } catch (Throwable t) {
         if (LOG.isEnabledFor(Level.ERROR)) {
           LOG.error("Can't calculate unit name for a node " + node + ".", t);
         }
       }
       TraceInfoGenerationUtil.fillUnitInfo(this, node, unitName);
     }
   }
 }
Ejemplo n.º 6
0
 @Override
 protected void doFind(
     SNode node, SearchScope scope, List<SNode> _results, ProgressMonitor monitor) {
   monitor.start(getDescription(), 1);
   try {
     for (SNode classNode :
         ListSequence.fromList(
             FindUtils.executeFinder(
                 "jetbrains.mps.baseLanguage.findUsages.DerivedClasses_Finder",
                 SNodeOperations.getParent(node),
                 scope,
                 monitor.subTask(1)))) {
       Iterable<SNode> fieldsOfSameKind;
       if (SNodeOperations.isInstanceOf(
           node,
           MetaAdapterFactory.getConcept(
               0xf3061a5392264cc5L,
               0xa443f952ceaf5816L,
               0xf8c108ca68L,
               "jetbrains.mps.baseLanguage.structure.FieldDeclaration"))) {
         fieldsOfSameKind =
             ClassConcept_Behavior.call_fields_5292274854859383272(
                 SNodeOperations.cast(
                     classNode,
                     MetaAdapterFactory.getConcept(
                         0xf3061a5392264cc5L,
                         0xa443f952ceaf5816L,
                         0xf8c108ca66L,
                         "jetbrains.mps.baseLanguage.structure.ClassConcept")));
       } else {
         fieldsOfSameKind =
             Classifier_Behavior.call_staticFields_5292274854859223538(
                 SNodeOperations.cast(
                     classNode,
                     MetaAdapterFactory.getConcept(
                         0xf3061a5392264cc5L,
                         0xa443f952ceaf5816L,
                         0xf8c108ca66L,
                         "jetbrains.mps.baseLanguage.structure.ClassConcept")));
       }
       for (SNode field : Sequence.fromIterable(fieldsOfSameKind)) {
         if (SPropertyOperations.getString(
                     field,
                     MetaAdapterFactory.getProperty(
                         0xceab519525ea4f22L,
                         0x9b92103b95ca8c0cL,
                         0x110396eaaa4L,
                         0x110396ec041L,
                         "name"))
                 .equals(
                     SPropertyOperations.getString(
                         node,
                         MetaAdapterFactory.getProperty(
                             0xceab519525ea4f22L,
                             0x9b92103b95ca8c0cL,
                             0x110396eaaa4L,
                             0x110396ec041L,
                             "name")))
             && BehaviorReflection.invokeVirtual(
                     String.class,
                     SLinkOperations.getTarget(
                         field,
                         MetaAdapterFactory.getContainmentLink(
                             0xf3061a5392264cc5L,
                             0xa443f952ceaf5816L,
                             0x450368d90ce15bc3L,
                             0x4ed4d318133c80ceL,
                             "type")),
                     "virtual_getErasureSignature_1213877337313",
                     new Object[] {})
                 .equals(
                     BehaviorReflection.invokeVirtual(
                         String.class,
                         SLinkOperations.getTarget(
                             node,
                             MetaAdapterFactory.getContainmentLink(
                                 0xf3061a5392264cc5L,
                                 0xa443f952ceaf5816L,
                                 0x450368d90ce15bc3L,
                                 0x4ed4d318133c80ceL,
                                 "type")),
                         "virtual_getErasureSignature_1213877337313",
                         new Object[] {}))) {
           ListSequence.fromList(_results).addElement(field);
         }
       }
     }
   } finally {
     monitor.done();
   }
 }
Ejemplo n.º 7
0
 private static boolean renderingCondition_y68cfu_a4d7a(SNode node, EditorContext editorContext) {
   return !(Classifier_Behavior.call_isInner_521412098689998677(node))
       || Classifier_Behavior.call_isStatic_521412098689998668(node)
       || (SLinkOperations.getTarget(node, "classInitializer", true) != null);
 }
Ejemplo n.º 8
0
 private static boolean renderingCondition_y68cfu_a3h0(SNode node, EditorContext editorContext) {
   return Sequence.fromIterable(Classifier_Behavior.call_members_1465982738252129704(node))
       .subtract(ListSequence.fromList(SLinkOperations.getTargets(node, "member", true)))
       .isNotEmpty();
 }