예제 #1
0
  private static String asString(MappingConfig_AbstractRef mappingRef, boolean moreDetails) {
    if (mappingRef instanceof MappingConfig_RefAllLocal) {
      return "*";
    }
    if (mappingRef instanceof MappingConfig_RefAllGlobal) {
      return "[*:*]";
    }

    if (mappingRef instanceof MappingConfig_RefSet) {
      String s = "{";
      int count = ((MappingConfig_RefSet) mappingRef).getMappingConfigs().size();
      for (MappingConfig_AbstractRef mappingSimpleRef :
          ((MappingConfig_RefSet) mappingRef).getMappingConfigs()) {
        count--;
        s = s + asString(mappingSimpleRef, moreDetails);
        if (count > 0) s += ", ";
      }
      return s + "}";
    }

    if (mappingRef instanceof MappingConfig_SimpleRef) {
      final String modelUID = ((MappingConfig_SimpleRef) mappingRef).getModelUID();
      final String nodeID = ((MappingConfig_SimpleRef) mappingRef).getNodeID();
      final SModelReference modelReference =
          PersistenceFacade.getInstance().createModelReference(modelUID);
      String modelName =
          moreDetails
              ? SModelStereotype.withoutStereotype(modelReference.getModelName())
              : NameUtil.shortNameFromLongName(
                  SModelStereotype.withoutStereotype(modelReference.getModelName()));
      StringBuilder sb = new StringBuilder();
      sb.append(modelName);
      sb.append('.');
      if (nodeID.equals("*")) {
        return sb.append('*').toString();
      } else {
        SModel refModel = SModelRepository.getInstance().getModelDescriptor(modelReference);
        if (refModel != null) {
          SNodeId nodeId = PersistenceFacade.getInstance().createNodeId(nodeID);
          assert nodeId != null : "wrong node id string";
          SNode mappingConfig = refModel.getNode(nodeId);
          if (mappingConfig != null) {
            return sb.append(mappingConfig.getName()).toString();
          }
        }
      }
      return sb.append(nodeID).append("!unresolved!").toString();
    }

    if (mappingRef instanceof MappingConfig_ExternalRef) {
      SModuleReference generatorRef = ((MappingConfig_ExternalRef) mappingRef).getGenerator();
      MappingConfig_AbstractRef extMappingRef =
          ((MappingConfig_ExternalRef) mappingRef).getMappingConfig();
      return "[" + asString(generatorRef) + ":" + asString(extMappingRef, moreDetails) + "]";
    }

    return "???";
  }
예제 #2
0
  private void collectGroupChangesWithOthersConflicts(
      Map<Tuples._2<SNodeId, String>, List<NodeGroupChange>> arrangedChanges,
      ChangeSet thisChangeSet,
      ChangeSet otherChangeSet) {
    Map<SNodeId, DeleteRootChange> deleteRootChanges =
        MergeConflictsBuilder.<SNodeId, DeleteRootChange>arrangeChanges(
            thisChangeSet,
            new _FunctionTypes._return_P1_E0<SNodeId, DeleteRootChange>() {
              public SNodeId invoke(DeleteRootChange drc) {
                return drc.getRootId();
              }
            },
            DeleteRootChange.class);
    for (ModelChange change : ListSequence.fromList(otherChangeSet.getModelChanges())) {
      if (MapSequence.fromMap(myConflictingChanges).containsKey(change)) {
        continue;
      }

      SNodeId nodeId = null;
      if (change instanceof NodeChange) {
        nodeId = ((NodeChange) change).getAffectedNodeId();
      } else if (change instanceof NodeGroupChange) {
        nodeId = ((NodeGroupChange) change).getParentNodeId();
      }
      if (nodeId == null) {
        continue;
      }
      SNode node = myBaseModel.getNode(nodeId);
      while (node != null) {
        if (SNodeOperations.getParent(node) == null) {
          DeleteRootChange conflicting =
              MapSequence.fromMap(deleteRootChanges).get(node.getNodeId());
          if (conflicting != null) {
            addPossibleConflict(change, conflicting);
          }
        } else {
          Tuples._2<SNodeId, String> nodeRole =
              MultiTuple.<SNodeId, String>from(
                  SNodeOperations.getParent(node).getNodeId(),
                  SNodeOperations.getContainingLinkRole(node));
          final int index = SNodeOperations.getIndexInParent(node);
          NodeGroupChange conflicting =
              ListSequence.fromList(MapSequence.fromMap(arrangedChanges).get(nodeRole))
                  .findFirst(
                      new IWhereFilter<NodeGroupChange>() {
                        public boolean accept(NodeGroupChange ch) {
                          return ch.getBegin() <= index && index < ch.getEnd();
                        }
                      });
          if (conflicting != null) {
            addPossibleConflict(change, conflicting);
            break;
          }
        }
        node = SNodeOperations.getParent(node);
      }
    }
  }
예제 #3
0
 private void collectConflictingRootAdds() {
   Tuples._2<Map<SNodeId, AddRootChange>, Map<SNodeId, AddRootChange>> arranged;
   arranged =
       this.<SNodeId, AddRootChange>arrangeChanges(
           new _FunctionTypes._return_P1_E0<SNodeId, AddRootChange>() {
             public SNodeId invoke(AddRootChange drc) {
               return drc.getRootId();
             }
           },
           AddRootChange.class);
   for (SNodeId addedRoot :
       SetSequence.fromSet(MapSequence.fromMap(arranged._0()).keySet())
           .intersect(SetSequence.fromSet(MapSequence.fromMap(arranged._1()).keySet()))) {
     AddRootChange mine = MapSequence.fromMap(arranged._0()).get(addedRoot);
     AddRootChange repository = MapSequence.fromMap(arranged._1()).get(addedRoot);
     if (SNodeCompare.nodeEquals(
         myMyModel.getNode(mine.getRootId()), myRepositoryModel.getNode(repository.getRootId()))) {
       addSymmetric(mine, repository);
     } else {
       addPossibleConflict(mine, repository);
     }
   }
 }
예제 #4
0
 private boolean nodeGroupChangesSymmetric(NodeGroupChange mine, NodeGroupChange repository) {
   if (mine.getBegin() == repository.getBegin() && mine.getEnd() == repository.getEnd()) {
     if (mine.getResultEnd() - mine.getResultBegin()
         == repository.getResultEnd() - repository.getResultBegin()) {
       List<? extends SNode> myChildren =
           IterableUtil.asList(
               myMyModel.getNode(mine.getParentNodeId()).getChildren(mine.getRole()));
       List<? extends SNode> repositoryChildren =
           IterableUtil.asList(
               myRepositoryModel
                   .getNode(repository.getParentNodeId())
                   .getChildren(repository.getRole()));
       for (int o = 0; o < mine.getResultEnd() - mine.getResultBegin(); o++) {
         if (!(SNodeCompare.nodeEquals(
             myChildren.get(mine.getResultBegin() + o),
             repositoryChildren.get(repository.getResultBegin() + o)))) {
           return false;
         }
       }
       return true;
     }
   }
   return false;
 }
예제 #5
0
  public synchronized Set<SModelReference> resolveModel(
      SModule module, String name, @Nullable SNodeId nodeId) {
    Pair<SModuleReference, String> key =
        new Pair<SModuleReference, String>(module.getModuleReference(), name);
    ensureInitialized(key);

    Set<SModelReference> models = myStubModulesCache.get(key);
    if (nodeId == null) return new HashSet<SModelReference>(models);

    Set<SModelReference> result = new HashSet<SModelReference>();
    for (SModelReference ref : models) {
      SModel m = SModelRepository.getInstance().getModelDescriptor(ref);
      if (m.getNode(nodeId) != null) {
        result.add(ref);
      }
    }

    return result;
  }
예제 #6
0
 @Override
 protected SNode findInConcept(SNode cnode) {
   SModel model = cnode.getModel();
   return model.getNode(new SNodeId.Regular(myRoleId.getIdValue()));
 }
예제 #7
0
  // Maybe will go to MPS2PsiMapper
  @Nullable
  public static SNode getNodeForElement(PsiElement element) {
    // baseLanguage specific check
    if (!(element instanceof PsiClass
        || element instanceof PsiMethod
        || element instanceof PsiField)) {
      return null;
    }

    PsiFile psiFile = element.getContainingFile();
    if (!(psiFile instanceof PsiJavaFile)) {
      return null;
    }

    if (PsiManager.getInstance(element.getProject()).isInProject(element)) {
      // It must be sources, try psi stubs
      // There might be psi stubs for this element, but there also might not (e.g. if it's inside a
      // module
      // with no MPS facet)

      NodePtr nodePtr = JavaForeignIdBuilder.computeNodePtr(element);
      if (nodePtr == null) {
        return null;
      }
      SNode node =
          nodePtr
              .toSNodeReference()
              .resolve(ProjectHelper.getProjectRepository(element.getProject()));

      return node;

    } else {
      // It must be from a library or SDK or something like that
      // Trying to find a suitable node in a class stub model
      SNodeId nodeId = null;
      if (element instanceof PsiClass) {
        nodeId = ASMNodeId.createId(((PsiClass) element).getQualifiedName());

      } else if (element instanceof PsiField) {
        PsiClass clas = ((PsiField) element).getContainingClass();
        String clasFqName = clas.getQualifiedName();
        nodeId = ASMNodeId.createFieldId(clasFqName, ((PsiField) element).getName());

      } else if (element instanceof PsiMethod) {
        // TODO argument types must be handled like they are in ASMNodeId (via asm classes)
      }

      if (nodeId == null) {
        // can't do anything about it
        return null;
      }

      String packageName = ((PsiJavaFile) psiFile).getPackageName();
      for (SModel model :
          new ModuleRepositoryFacade(ProjectHelper.getProjectRepository(element.getProject()))
              .getAllModels()) {
        if (!(model instanceof JavaClassStubModelDescriptor)) continue;
        if (!packageName.equals(model.getName().getLongName())) {
          continue;
        }
        SNode node = model.getNode(nodeId);
        if (node == null) continue;
        return node;
      }
    }

    return null;
  }