public CodeInsertionDialog(Shell shell, IType type) throws JavaModelException {
    super(shell);

    insertPositions = new ArrayList<IJavaElement>();
    fLabels = new ArrayList<String>();

    System.out.println(type.getElementName() + type.getElementType());

    IJavaElement[] members = type.getChildren();

    insertPositions.add(members.length > 0 ? members[0] : null); // first
    insertPositions.add(null); // last

    fLabels.add(CodeInsertionDialog.firstElement);
    fLabels.add(CodeInsertionDialog.secondElement);

    for (int i = 0; i < members.length; i++) {
      IJavaElement curr = members[i];
      String methodLabel =
          JavaElementLabels.getElementLabel(curr, JavaElementLabels.M_PARAMETER_TYPES);
      // System.out.println(MessageFormat.format(afterElement, methodLabel));
      fLabels.add(MessageFormat.format(afterElement, methodLabel));
      insertPositions.add(findSibling(curr, members));
    }
    insertPositions.add(null); // null indicate we want to insert into the last position
  }
 private static String getAddClasspathLabel(
     IClasspathEntry entry, IPackageFragmentRoot root, IJavaProject project) {
   switch (entry.getEntryKind()) {
     case IClasspathEntry.CPE_LIBRARY:
       if (root.isArchive()) {
         String[] args = {
           JavaElementLabels.getElementLabel(
               root, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED),
           BasicElementLabels.getJavaElementName(project.getElementName())
         };
         return Messages.format(
             CorrectionMessages.ReorgCorrectionsSubProcessor_addcp_archive_description, args);
       } else {
         String[] args = {
           JavaElementLabels.getElementLabel(
               root, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED),
           BasicElementLabels.getJavaElementName(project.getElementName())
         };
         return Messages.format(
             CorrectionMessages.ReorgCorrectionsSubProcessor_addcp_classfolder_description, args);
       }
     case IClasspathEntry.CPE_VARIABLE:
       {
         String[] args = {
           JavaElementLabels.getElementLabel(root, 0),
           BasicElementLabels.getJavaElementName(project.getElementName())
         };
         return Messages.format(
             CorrectionMessages.ReorgCorrectionsSubProcessor_addcp_variable_description, args);
       }
     case IClasspathEntry.CPE_CONTAINER:
       try {
         String[] args = {
           JavaElementLabels.getContainerEntryLabel(entry.getPath(), root.getJavaProject()),
           BasicElementLabels.getJavaElementName(project.getElementName())
         };
         return Messages.format(
             CorrectionMessages.ReorgCorrectionsSubProcessor_addcp_library_description, args);
       } catch (JavaModelException e) {
         // ignore
       }
       break;
   }
   return null;
 }
Exemple #3
0
 /**
  * Overridden by subclasses.
  *
  * @return return the refactoring descriptor for this refactoring
  */
 protected RenameJavaElementDescriptor createRefactoringDescriptor() {
   String project = null;
   IJavaProject javaProject = fField.getJavaProject();
   if (javaProject != null) project = javaProject.getElementName();
   int flags =
       JavaRefactoringDescriptor.JAR_MIGRATION
           | JavaRefactoringDescriptor.JAR_REFACTORING
           | RefactoringDescriptor.STRUCTURAL_CHANGE;
   try {
     if (!Flags.isPrivate(fField.getFlags())) flags |= RefactoringDescriptor.MULTI_CHANGE;
   } catch (JavaModelException exception) {
     JavaPlugin.log(exception);
   }
   final IType declaring = fField.getDeclaringType();
   try {
     if (declaring.isAnonymous() || declaring.isLocal())
       flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
   } catch (JavaModelException exception) {
     JavaPlugin.log(exception);
   }
   final String description =
       Messages.format(
           RefactoringCoreMessages.RenameFieldRefactoring_descriptor_description_short,
           BasicElementLabels.getJavaElementName(fField.getElementName()));
   final String header =
       Messages.format(
           RefactoringCoreMessages.RenameFieldProcessor_descriptor_description,
           new String[] {
             BasicElementLabels.getJavaElementName(fField.getElementName()),
             JavaElementLabels.getElementLabel(
                 fField.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED),
             getNewElementName()
           });
   final JDTRefactoringDescriptorComment comment =
       new JDTRefactoringDescriptorComment(project, this, header);
   if (fRenameGetter)
     comment.addSetting(RefactoringCoreMessages.RenameFieldRefactoring_setting_rename_getter);
   if (fRenameSetter)
     comment.addSetting(RefactoringCoreMessages.RenameFieldRefactoring_setting_rename_settter);
   final RenameJavaElementDescriptor descriptor =
       RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
           IJavaRefactorings.RENAME_FIELD);
   descriptor.setProject(project);
   descriptor.setDescription(description);
   descriptor.setComment(comment.asString());
   descriptor.setFlags(flags);
   descriptor.setJavaElement(fField);
   descriptor.setNewName(getNewElementName());
   descriptor.setUpdateReferences(fUpdateReferences);
   descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
   descriptor.setRenameGetters(fRenameGetter);
   descriptor.setRenameSetters(fRenameSetter);
   descriptor.setKeepOriginal(fDelegateUpdating);
   descriptor.setDeprecateDelegate(fDelegateDeprecation);
   return descriptor;
 }
 private void checkTypes(
     RefactoringStatus result, IMethod method, IType[] types, String key, IProgressMonitor pm) {
   pm.beginTask("", types.length); // $NON-NLS-1$
   for (int i = 0; i < types.length; i++) {
     pm.worked(1);
     IMethod[] overridden = types[i].findMethods(method);
     if (overridden != null && overridden.length > 0) {
       result.addError(
           Messages.format(
               key, JavaElementLabels.getElementLabel(types[i], JavaElementLabels.ALL_DEFAULT)),
           JavaStatusContext.create(overridden[0]));
     }
   }
 }
 private void isValid(RefactoringStatus result, IPackageFragment pack, IProgressMonitor pm)
     throws JavaModelException {
   ICompilationUnit[] units = pack.getCompilationUnits();
   pm.beginTask("", units.length); // $NON-NLS-1$
   for (int i = 0; i < units.length; i++) {
     pm.subTask(
         Messages.format(
             RefactoringCoreMessages.RenamePackageChange_checking_change,
             JavaElementLabels.getElementLabel(pack, JavaElementLabels.ALL_DEFAULT)));
     checkIfModifiable(
         result, units[i].getResource(), VALIDATE_NOT_READ_ONLY | VALIDATE_NOT_DIRTY);
     pm.worked(1);
   }
   pm.done();
 }
 private void addLabel(Composite parent) {
   Label label = new Label(parent, SWT.NONE);
   IMember[] members = getMoveProcessor().getMembersToMove();
   if (members.length == 1) {
     label.setText(
         Messages.format(
             RefactoringMessages.MoveMembersInputPage_destination_single,
             JavaElementLabels.getElementLabel(members[0], LABEL_FLAGS)));
   } else {
     label.setText(
         Messages.format(
             RefactoringMessages.MoveMembersInputPage_destination_multi,
             String.valueOf(members.length)));
   }
   GridData gd = new GridData();
   gd.horizontalSpan = 2;
   label.setLayoutData(gd);
 }
 public void setVisible(boolean visible) {
   if (visible) {
     IMember[] membersToMove = getMoveProcessor().getMembersToMove();
     int membersToMoveCount = membersToMove.length;
     String label =
         JavaElementLabels.getElementLabel(
             getMoveProcessor().getDeclaringType(), JavaElementLabels.ALL_FULLY_QUALIFIED);
     String message =
         membersToMoveCount == 1
             ? Messages.format(
                 RefactoringMessages.MoveMembersInputPage_descriptionKey_singular,
                 new String[] {
                   JavaElementLabels.getTextLabel(
                       membersToMove[0], JavaElementLabels.ALL_FULLY_QUALIFIED),
                   label
                 })
             : Messages.format(
                 RefactoringMessages.MoveMembersInputPage_descriptionKey_plural,
                 new String[] {new Integer(membersToMoveCount).toString(), label});
     setDescription(message);
   }
   super.setVisible(visible);
 }
    private void addUpdateReferenceComponent(Composite result) {
      final JavaMoveProcessor processor = getJavaMoveProcessor();
      if (!processor.canUpdateJavaReferences()) return;

      String text;
      int resources = getResources().length;
      int javaElements = getJavaElements().length;
      if (resources == 0 && javaElements == 1) {
        text =
            Messages.format(
                ReorgMessages.JdtMoveAction_update_references_singular,
                JavaElementLabels.getElementLabel(getJavaElements()[0], LABEL_FLAGS));
      } else if (resources == 1 && javaElements == 0) {
        text =
            Messages.format(
                ReorgMessages.JdtMoveAction_update_references_singular,
                BasicElementLabels.getResourceName(getResources()[0]));
      } else {
        text =
            Messages.format(
                ReorgMessages.JdtMoveAction_update_references_plural,
                String.valueOf(resources + javaElements));
      }

      fReferenceCheckbox = new Button(result, SWT.CHECK);
      fReferenceCheckbox.setText(text);
      fReferenceCheckbox.setSelection(processor.getUpdateReferences());

      fReferenceCheckbox.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              processor.setUpdateReferences(((Button) e.widget).getSelection());
              updateUIStatus();
            }
          });
    }
    /* (non-Javadoc)
     * @see org.eclipse.jface.action.Action#run()
     */
    public void run() {
      boolean showPropertyPage;

      Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

      if (!hasProjectSpecificOptions()) {
        String message =
            Messages.format(
                JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_message,
                new Object[] {
                  JavaElementLabels.getElementLabel(fProject, JavaElementLabels.ALL_DEFAULT)
                });

        String[] buttons =
            new String[] {
              JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_button_project,
              JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_button_workspace,
              JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_button_cancel
            };

        int result =
            OptionalMessageDialog.open(
                CONFIGURE_PROBLEM_SEVERITY_DIALOG_ID,
                shell,
                JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_title,
                null,
                message,
                MessageDialog.QUESTION,
                buttons,
                0,
                JavaHoverMessages.ProblemHover_chooseSettingsTypeDialog_checkBox_dontShowAgain);

        if (result == OptionalMessageDialog.NOT_SHOWN) {
          showPropertyPage = false;
        } else if (result == 2 || result == SWT.DEFAULT) {
          return;
        } else if (result == 0) {
          showPropertyPage = true;
        } else {
          showPropertyPage = false;
        }
      } else {
        showPropertyPage = true;
      }

      Map data = new HashMap();
      String pageId;
      if (fIsJavadocOption) {
        if (showPropertyPage) {
          pageId = JavadocProblemsPreferencePage.PROP_ID;
          data.put(JavadocProblemsPreferencePage.DATA_USE_PROJECT_SPECIFIC_OPTIONS, Boolean.TRUE);
        } else {
          pageId = JavadocProblemsPreferencePage.PREF_ID;
        }
        data.put(JavadocProblemsPreferencePage.DATA_SELECT_OPTION_KEY, fOptionId);
        data.put(JavadocProblemsPreferencePage.DATA_SELECT_OPTION_QUALIFIER, JavaCore.PLUGIN_ID);
      } else {
        if (showPropertyPage) {
          pageId = ProblemSeveritiesPreferencePage.PROP_ID;
          data.put(ProblemSeveritiesPreferencePage.USE_PROJECT_SPECIFIC_OPTIONS, Boolean.TRUE);
        } else {
          pageId = ProblemSeveritiesPreferencePage.PREF_ID;
        }
        data.put(ProblemSeveritiesPreferencePage.DATA_SELECT_OPTION_KEY, fOptionId);
        data.put(ProblemSeveritiesPreferencePage.DATA_SELECT_OPTION_QUALIFIER, JavaCore.PLUGIN_ID);
      }

      fInfoControl.dispose(); // FIXME: should have protocol to hide, rather than dispose

      if (showPropertyPage) {
        PreferencesUtil.createPropertyDialogOn(shell, fProject, pageId, null, data).open();
      } else {
        PreferencesUtil.createPreferenceDialogOn(shell, pageId, null, data).open();
      }
    }
Exemple #10
0
 private String getDeclaringTypeLabel() {
   return JavaElementLabels.getElementLabel(
       fField.getDeclaringType(), JavaElementLabels.ALL_DEFAULT);
 }