/**
  * Sets the extra default values from the given 'compilationUnit' argument
  *
  * @param compilationUnit the selected {@link ICompilationUnit}.
  */
 private void setDefaultValues(final ICompilationUnit compilationUnit) {
   final IPackageFragment selectedPackageFragment =
       (IPackageFragment) compilationUnit.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
   final IPackageFragment suggestedPackage = getSuggestedPackage(selectedPackageFragment);
   setPackageFragment(suggestedPackage, true);
   setDefaultValues(selectedPackageFragment);
 }
Пример #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) {
    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();
    }
  }