Esempio n. 1
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();
        }
      }
    }
  }
Esempio n. 2
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));
    }
  }
Esempio n. 3
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());
        }
      }
    }
  }
Esempio n. 4
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();
    }
  }
Esempio n. 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) {
    FieldModel fieldModel = (FieldModel) root.getModelFromElement(element);

    // remove only stored copy
    if (fieldModel != null) {
      fieldModel.removeFromParent();
    }
  }
Esempio n. 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) {
    if (element.equals(element.getPrimaryElement())) {
      TypeModel type = (TypeModel) root.getModelFromElement(element.getAncestor(TYPE));

      if (type != null) {
        type.addChild(new FieldModel(element));
      }
    }
  }
Esempio n. 7
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();
          }
        }
      }
    }
  }
Esempio n. 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) {
   REMOVED_TYPE = (TypeModel) root.getModelFromElement(element);
 }