Пример #1
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleMove(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.IJavaElement)
   */
  public void handleMove(RootModel root, E sourceElement, E targetElement) {
    root.changeProjectElement(sourceElement, targetElement);

    try {
      List<IJavaElement> packages = root.getElementsOfKind(PACKAGE_FRAGMENT);

      // look through packages to match up source and destination elements
      for (IJavaElement packElement : packages) {
        IPackageFragment packFrag = (IPackageFragment) packElement;

        if (JavaModelListener.sameElements(
            packFrag.getAncestor(JAVA_PROJECT), sourceElement.getPrimaryElement())) {
          for (IPackageFragment packFrags : targetElement.getPackageFragments()) {
            // check for the same name of the two packages
            if (packFrag.getElementName().equals(packFrags.getElementName())) {
              PackageRefactorHandler.instance().handleMove(root, packFrag, packFrags);
            }
          }
        }
      }

      root.dispose();
    } catch (JavaModelException e) {
      e.printStackTrace();
    }
  }
Пример #2
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleMove(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.IJavaElement)
   */
  public void handleMove(RootModel root, E sourceElement, E targetElement) {
    // get all types represented in the diagram
    String scuId = sourceElement.getHandleIdentifier();
    String tcuId = targetElement.getHandleIdentifier();

    String scuName = scuId.substring(scuId.indexOf('{') + 1, scuId.indexOf(".java"));
    String tcuName = tcuId.substring(tcuId.indexOf('{') + 1, tcuId.indexOf(".java"));

    List<IJavaElement> cuTypes = root.getElementsOfKind(TYPE);

    // see if any types belong to the compilation unit
    // that is undergoing the move event
    for (IJavaElement oType : cuTypes) {
      if (JavaModelListener.sameElements(sourceElement, oType.getAncestor(COMPILATION_UNIT))) {
        String oId = oType.getHandleIdentifier();
        String oName = oId.substring(oId.indexOf('['));

        oName = oName.replaceAll("\\[" + scuName, "[" + tcuName);

        IJavaElement nType = JavaCore.create(tcuId + oName);
        TypeModel oModel = (TypeModel) root.getModelFromElement(oType);

        TypeModel nModel = root.createTypeModel((IType) nType);
        if (oModel != null) {
          // TODO We tried to catch a ResourceException,
          // but it is caught in MemberModel
          oModel.removeFromParent();
          nModel.setLocation(oModel.getLocation());
          nModel.setSize(oModel.getSize());
        }
      }
    }
  }
Пример #3
0
  /** @see edu.buffalo.cse.green.editor.model.commands.DeleteCommand#doDelete() */
  public void doDelete() {
    RootModel root = _typeModel.getRootModel();

    // Remove relationships first
    List<RelationshipModel> rels = root.getRelationships();

    // No iterators here due to CME's (ConcurrentModificationException)
    // Removal of relationships causes modifications to the rels list.
    for (int i = 0; i < rels.size(); i++) {
      IType t = _typeModel.getType();
      RelationshipModel r = rels.get(i);
      if (r.getSourceType() == t || r.getTargetType() == t) {
        DeleteCommand drc = r.getDeleteCommand(DiagramEditor.findProjectEditor(root.getProject()));
        drc.suppressMessage(true);
        drc.execute();
      }
    }

    _typeModel.removeChildren(); // remove fields/methods
    _typeModel.removeFromParent();
    try {
      IType type = _typeModel.getType();
      ICompilationUnit cu = (ICompilationUnit) type.getAncestor(IJavaElement.COMPILATION_UNIT);

      if (type.equals(cu.findPrimaryType())) {
        cu.delete(true, PlugIn.getEmptyProgressMonitor());
      } else {
        type.delete(true, PlugIn.getEmptyProgressMonitor());
      }
    } catch (JavaModelException e) {
      e.printStackTrace();
    }
    root.updateRelationships();
  }
Пример #4
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleAdd(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement)
   */
  public void handleAdd(RootModel root, E element) {
    // if the compilation unit exists in the editor, add the type
    if (root.ancestorInEditor(element.getAncestor(COMPILATION_UNIT))) {
      TypeModel addedType = root.createTypeModel(element);

      if (REMOVED_TYPE != null) {
        addedType.setLocation(REMOVED_TYPE.getLocation());
        addedType.setSize(REMOVED_TYPE.getSize());
      }
    }
  }
Пример #5
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleRemove(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement)
   */
  public void handleRemove(RootModel root, E element) {
    // ignore this if the CU removed is a working copy (not actual removal)
    if (element.isWorkingCopy()) return;

    List<IJavaElement> types = new ArrayList<IJavaElement>(root.getElementsOfKind(TYPE));

    // remove any types that belong to the compilation unit
    for (IJavaElement type : types) {
      if (JavaModelListener.sameElements(element, type.getAncestor(COMPILATION_UNIT))) {
        if (root.getModelFromElement(type) != null) {
          root.getModelFromElement(type).removeFromParent();
        }
      }
    }
  }
Пример #6
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleAdd(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement)
   */
  public void handleAdd(RootModel root, E element) {
    TypeModel type = (TypeModel) root.getModelFromElement(element.getAncestor(TYPE));

    if (type != null) {
      type.addChild(new MethodModel((IMethod) element));
    }
  }
Пример #7
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleRemove(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement)
   */
  public void handleRemove(RootModel root, E element) {
    MethodModel methodModel = (MethodModel) root.getModelFromElement(element);

    // remove only stored copy
    if (methodModel != null) {
      methodModel.removeFromParent();
    }
  }
Пример #8
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleRemove(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement)
   */
  public void handleRemove(RootModel root, E element) {
    FieldModel fieldModel = (FieldModel) root.getModelFromElement(element);

    // remove only stored copy
    if (fieldModel != null) {
      fieldModel.removeFromParent();
    }
  }
Пример #9
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleAdd(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement)
   */
  public void handleAdd(RootModel root, E element) {
    if (element.equals(element.getPrimaryElement())) {
      TypeModel type = (TypeModel) root.getModelFromElement(element.getAncestor(TYPE));

      if (type != null) {
        type.addChild(new FieldModel(element));
      }
    }
  }
Пример #10
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleRemove(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement)
   */
  public void handleRemove(RootModel root, E element) {
    List<IJavaElement> cus = root.getElementsOfKind(COMPILATION_UNIT);

    for (IJavaElement cu : cus) {
      if (JavaModelListener.sameElements(cu.getAncestor(PACKAGE_FRAGMENT), element)) {
        CompilationUnitRefactorHandler.instance().handleRemove(root, (ICompilationUnit) cu);
      }
    }
  }
Пример #11
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleRemove(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement)
   */
  public void handleRemove(RootModel root, E element) {
    List<IJavaElement> packages = root.getElementsOfKind(PACKAGE_FRAGMENT);

    for (IJavaElement pack : packages) {
      // get the project that contains the package
      IJavaElement proj = pack.getAncestor(JAVA_PROJECT);

      // if the package belongs to the project, remove it
      if (JavaModelListener.sameElements(proj, element)) {
        PackageRefactorHandler.instance().handleRemove(root, (IPackageFragment) pack);
      }
    }
  }
Пример #12
0
  /**
   * Updates the display when some change occurs to a Java element that doesn't involve removal,
   * addition, or movement.
   *
   * @param elementDelta - The delta of the element that changed.
   */
  private void handleElementChange(IJavaElementDelta elementDelta) {
    IJavaElement element = elementDelta.getElement();

    // update the modifiers of the element (if they changed)
    if ((elementDelta.getFlags() & IJavaElementDelta.F_MODIFIERS) != 0) {
      for (DiagramEditor editor : DiagramEditor.getEditors()) {
        RootPart rootEditPart = editor.getRootPart();
        RootModel root = (RootModel) rootEditPart.getModel();
        AbstractModel abstractModel = root.getModelFromElement(element);

        if (abstractModel != null) {
          if (abstractModel instanceof FieldModel) {
            FieldModel fModel = (FieldModel) abstractModel;
            FieldPart fEditPart = (FieldPart) rootEditPart.getPartFromModel(fModel);
            fEditPart.updateIcon();
          } else if (abstractModel instanceof MethodModel) {
            MethodModel mModel = (MethodModel) abstractModel;
            MethodPart mEditPart = (MethodPart) rootEditPart.getPartFromModel(mModel);
            mEditPart.updateIcon();
          }
        }
      }
    }
  }
Пример #13
0
  /**
   * @see
   *     edu.buffalo.cse.green.RefactorHandler#handleMove(edu.buffalo.cse.green.editor.model.RootModel,
   *     org.eclipse.jdt.core.IJavaElement, org.eclipse.jdt.core.IJavaElement)
   */
  public void handleMove(RootModel root, E sourceElement, E targetElement) {
    try {
      List<IJavaElement> cus = root.getElementsOfKind(COMPILATION_UNIT);
      ICompilationUnit[] newCUs = targetElement.getCompilationUnits();

      for (IJavaElement cuElement : cus) {
        ICompilationUnit iCU = (ICompilationUnit) cuElement;
        if (JavaModelListener.sameElements(iCU.getAncestor(PACKAGE_FRAGMENT), sourceElement)) {
          for (ICompilationUnit cu : newCUs) {
            if (cu.getElementName().equals(iCU.getElementName())) {
              CompilationUnitRefactorHandler.instance().handleMove(root, iCU, cu);
            }
          }
        }
      }
    } catch (JavaModelException e) {
      e.printStackTrace();
    }
  }
Пример #14
0
 /**
  * @see
  *     edu.buffalo.cse.green.RefactorHandler#handleRemove(edu.buffalo.cse.green.editor.model.RootModel,
  *     org.eclipse.jdt.core.IJavaElement)
  */
 public void handleRemove(RootModel root, E element) {
   REMOVED_TYPE = (TypeModel) root.getModelFromElement(element);
 }