示例#1
0
  private void addSavedUserCreatedNodes(
      ArtifactFragment parent,
      Resource instanceRes,
      Resource modelRes,
      Map<Resource, ArtifactFragment> instanceRes2AFMap,
      ReloRdfRepository repo) {
    ArtifactFragment childToAdd =
        SeqUtil.createAFForSavedResources(
            repo, modelRes, instanceRes, parent, (DiagramModel) getModel());
    if (childToAdd == null)
      logger.error("Could not create model for " + instanceRes + "in parent " + parent);

    // Add AF to parent and call same method with child
    int indexWhenSaved = findSavedIndex(repo, instanceRes);
    List<ArtifactFragment> childrenAddedToParent = parent.getShownChildren();
    if (parent instanceof DiagramModel)
      childrenAddedToParent = ((DiagramModel) parent).getChildren();
    else if (parent instanceof UserCreatedInstanceModel)
      childrenAddedToParent = ((NodeModel) parent).getChildren();

    int indexToAddAt = getCurrentIndex(indexWhenSaved, repo, childrenAddedToParent);
    parent.appendShownChild(childToAdd, indexToAddAt);
    instanceRes2AFMap.put(instanceRes, childToAdd);

    for (DiagramPolicy pol : childToAdd.getDiagramPolicies()) pol.readRDF(repo);

    addSavedContainee(childToAdd, instanceRes, instanceRes2AFMap, repo);
  }
示例#2
0
  private void addSavedCodeRes(
      ArtifactFragment parent,
      Resource codeRes,
      Map<Resource, ArtifactFragment> instanceRes2AFMap,
      ReloRdfRepository repo)
      throws Exception {
    ArtifactFragment childToAdd = SeqUtil.createChronoModelForResource(codeRes, parent, repo, this);
    if (childToAdd == null)
      throw new Exception("Could not create model for resource: " + codeRes.toString());

    if (parent instanceof DiagramModel) instanceResToAF.put(codeRes, childToAdd);

    //		Statement indexWhenSavedStmt = repo.getStatement(codeRes, RJCore.index, null);
    //		int indexWhenSaved = (indexWhenSavedStmt == null || indexWhenSavedStmt.getObject() == null)
    // ? -1 : Integer.parseInt(indexWhenSavedStmt.getObject().toString());
    int indexWhenSaved = findSavedIndex(repo, codeRes);
    //		int indexToAddAt = -1;

    List<ArtifactFragment> childrenAddedToParent = parent.getShownChildren();
    if (parent instanceof DiagramModel)
      childrenAddedToParent = ((DiagramModel) parent).getChildren();
    else if (parent instanceof NodeModel)
      childrenAddedToParent = ((NodeModel) parent).getChildren();
    //		for(ArtifactFragment addedChild : childrenAddedToParent) {
    //
    //			Resource addedChildSaveRes = addedChild.getInstanceRes();
    //			Statement addedChildIndexWhenSavedStmt = repo.getStatement(addedChildSaveRes, RJCore.index,
    // null);
    //			int addedChildIndexWhenSaved = -1;
    //			if(addedChildIndexWhenSavedStmt.getObject()!=null)
    //				addedChildIndexWhenSaved =
    // Integer.parseInt(addedChildIndexWhenSavedStmt.getObject().toString());
    //
    //			if(indexWhenSaved>-1 && indexWhenSaved<addedChildIndexWhenSaved)
    //				indexToAddAt = childrenAddedToParent.indexOf(addedChild);
    //		}
    int indexToAddAt = getCurrentIndex(indexWhenSaved, repo, childrenAddedToParent);
    parent.appendShownChild(childToAdd, indexToAddAt);
    instanceRes2AFMap.put(codeRes, childToAdd);

    for (DiagramPolicy pol : childToAdd.getDiagramPolicies()) {
      pol.readRDF(repo);
    }

    addSavedContainee(childToAdd, codeRes, instanceRes2AFMap, repo);
  }
  private static void generate(IRSEDiagramEngine diagramEngine) {
    if (diagramEngine == null) return;

    LinkedHashMap<IType, List<Invocation>> history =
        SeqUtil.getNavigationHistory(numNavigationsToInclude);
    List<CodeUnit> classUnits = new ArrayList<CodeUnit>();
    List<CodeUnit> methodUnits = new ArrayList<CodeUnit>();
    List<ArtifactFragment> toAddToDiagram = new ArrayList<ArtifactFragment>();

    for (IType type : history.keySet()) {
      if (!openTabs.contains(type)) continue;

      Resource classOfNavigationRes =
          RJCore.jdtElementToResource(StoreUtil.getDefaultStoreRepository(), type);
      CodeUnit classOfNavigationCU =
          GenerateUtil.getCodeUnitForRes(classOfNavigationRes, null, classUnits, null);

      // Add method calls
      for (Invocation invocation : history.get(type)) {

        IType container = null;
        if (invocation.getMethodElement() != null) {
          IMethod method = invocation.getMethodElement();
          container = method.getDeclaringType();
        }
        if (container == null) continue;

        boolean containerIsAnOpenTab = false;
        for (IType navigatedType : openTabs) {
          if (navigatedType.equals(container)) {
            containerIsAnOpenTab = true;
            break;
          }
        }
        if (!containerIsAnOpenTab) continue;

        // Find the method declaration in which the invocation is made
        CompilationUnit cu = ASTUtil.getAst(IJEUtils.ije_getTypeRoot(type));
        MethodDeclarationFinder finder = new MethodDeclarationFinder(cu);
        MethodDeclaration declaration = finder.findDeclaration(invocation.getStartPosition());
        if (declaration == null
            || declaration.resolveBinding() == null
            || declaration.resolveBinding().getJavaElement() == null) continue;

        Resource declarationRes =
            RJCore.jdtElementToResource(
                StoreUtil.getDefaultStoreRepository(),
                declaration.resolveBinding().getJavaElement());
        CodeUnit declarationThatMakesInvocation =
            GenerateUtil.getCodeUnitForRes(declarationRes, null, methodUnits, classOfNavigationCU);

        String instanceName =
            (invocation.getInvocation() instanceof SuperMethodInvocation)
                ? null
                : MethodUtil.getInstanceCalledOn(invocation);
        CodeUnit containerOfDeclOfInvokedMethod =
            GenerateUtil.getCodeUnitForRes(
                RJCore.jdtElementToResource(StoreUtil.getDefaultStoreRepository(), container),
                instanceName,
                classUnits,
                null);
        Resource declOfInvokedMethodRes =
            RJCore.jdtElementToResource(
                StoreUtil.getDefaultStoreRepository(), invocation.getMethodElement());
        CodeUnit declOfInvokedMethodCU =
            GenerateUtil.getCodeUnitForRes(
                declOfInvokedMethodRes, null, methodUnits, containerOfDeclOfInvokedMethod);

        ArtifactRel rel =
            new ArtifactRel(declarationThatMakesInvocation, declOfInvokedMethodCU, RJCore.calls);

        declarationThatMakesInvocation.addSourceConnection(rel);
        declOfInvokedMethodCU.addTargetConnection(rel);
      }

      // Add inheritance relationships among classes
      for (Resource superClassRes : InstanceUtil.getSuperClasses(classOfNavigationRes)) {
        CodeUnit superClassCU =
            GenerateUtil.getCodeUnitForRes(superClassRes, null, classUnits, null);

        IJavaElement superClassElt =
            RJCore.resourceToJDTElement(StoreUtil.getDefaultStoreRepository(), superClassRes);
        if (!history.keySet().contains(superClassElt))
          continue; // superclass has not been recently navigated
        if (!openTabs.contains(superClassElt)) continue; // superclass is not an open tab

        ArtifactRel inheritanceRel =
            new ArtifactRel(classOfNavigationCU, superClassCU, RJCore.inherits);
        classOfNavigationCU.addSourceConnection(inheritanceRel);
        superClassCU.addTargetConnection(inheritanceRel);
      }
    }

    for (CodeUnit classUnit : classUnits) {
      if (classUnit.getShownChildren().size() > 0) toAddToDiagram.add(classUnit);
    }

    int numBeingAdded = toAddToDiagram.size();
    if (numBeingAdded < numNavigationsToInclude) {
      // Diagram going to be small, so add a reasonable number
      // of the open tabs that were most recently activated
      // (openTabs list is ordered with most recently activated first)
      for (int i = 0; i < openTabs.size() && numBeingAdded < numNavigationsToInclude; i++) {
        IType type = openTabs.get(i);

        // only adding top level tabs here, not any nested classes
        if (!(type instanceof SourceType)
            || ((SourceType) type).getParent().getElementType() == IJavaElement.TYPE) continue;

        Resource classOfNavigationRes =
            RJCore.jdtElementToResource(StoreUtil.getDefaultStoreRepository(), type);
        CodeUnit classOfNavigationCU =
            GenerateUtil.getCodeUnitForRes(classOfNavigationRes, null, classUnits, null);
        if (!toAddToDiagram.contains(classOfNavigationCU)) {
          toAddToDiagram.add(classOfNavigationCU);
          numBeingAdded++;
        }
      }
    }
    diagramEngine.openDiagramFromNavigatedTabs(
        toAddToDiagram, new ArrayList<ArtifactFragment>(classUnits));
  }