/**
   * Returns the tool tip text for the given element.
   *
   * @param element the element
   * @return the tooltip for the element
   */
  String getToolTipText(Object element) {
    String result;
    if (!(element instanceof IResource)) {
      result =
          JavaElementLabels.getTextLabel(element, AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS);
    } else {
      IPath path = ((IResource) element).getFullPath();
      if (path.isRoot()) {
        result = getConfigurationElement().getAttribute("name"); // $NON-NLS-1$
      } else {
        result = path.makeRelative().toString();
      }
    }

    if (fWorkingSetFilterActionGroup == null
        || fWorkingSetFilterActionGroup.getWorkingSet() == null) return result;

    IWorkingSet ws = fWorkingSetFilterActionGroup.getWorkingSet();
    String wsstr =
        Messages.format(
            JavaBrowsingMessages.JavaBrowsingPart_toolTip,
            new String[] {BasicElementLabels.getWorkingSetLabel(ws)});
    if (result.length() == 0) return wsstr;
    return Messages.format(
        JavaBrowsingMessages.JavaBrowsingPart_toolTip2,
        new String[] {result, BasicElementLabels.getWorkingSetLabel(ws)});
  }
  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;
 }
 @Override
 public Change createChange(IProgressMonitor monitor) throws CoreException {
   try {
     final TextChange[] changes = fChangeManager.getAllChanges();
     final List<TextChange> list = new ArrayList<>(changes.length);
     list.addAll(Arrays.asList(changes));
     String project = null;
     IJavaProject javaProject = fMethod.getJavaProject();
     if (javaProject != null) project = javaProject.getElementName();
     int flags =
         JavaRefactoringDescriptor.JAR_MIGRATION
             | JavaRefactoringDescriptor.JAR_REFACTORING
             | RefactoringDescriptor.STRUCTURAL_CHANGE;
     try {
       if (!Flags.isPrivate(fMethod.getFlags())) flags |= RefactoringDescriptor.MULTI_CHANGE;
     } catch (JavaModelException exception) {
       JavaPlugin.log(exception);
     }
     final IType declaring = fMethod.getDeclaringType();
     try {
       if (declaring.isAnonymous() || declaring.isLocal())
         flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
     } catch (JavaModelException exception) {
       JavaPlugin.log(exception);
     }
     final String description =
         Messages.format(
             RefactoringCoreMessages.RenameMethodProcessor_descriptor_description_short,
             BasicElementLabels.getJavaElementName(fMethod.getElementName()));
     final String header =
         Messages.format(
             RefactoringCoreMessages.RenameMethodProcessor_descriptor_description,
             new String[] {
               JavaElementLabels.getTextLabel(fMethod, JavaElementLabels.ALL_FULLY_QUALIFIED),
               BasicElementLabels.getJavaElementName(getNewElementName())
             });
     final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
     final RenameJavaElementDescriptor descriptor =
         RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
             IJavaRefactorings.RENAME_METHOD);
     descriptor.setProject(project);
     descriptor.setDescription(description);
     descriptor.setComment(comment);
     descriptor.setFlags(flags);
     descriptor.setJavaElement(fMethod);
     descriptor.setNewName(getNewElementName());
     descriptor.setUpdateReferences(fUpdateReferences);
     descriptor.setKeepOriginal(fDelegateUpdating);
     descriptor.setDeprecateDelegate(fDelegateDeprecation);
     return new DynamicValidationRefactoringChange(
         descriptor,
         RefactoringCoreMessages.RenameMethodProcessor_change_name,
         list.toArray(new Change[list.size()]));
   } finally {
     monitor.done();
   }
 }
Beispiel #5
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;
 }
 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 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);
 }
 private static SourceProvider resolveSourceProvider(
     RefactoringStatus status, ITypeRoot typeRoot, ASTNode invocation) {
   CompilationUnit root = (CompilationUnit) invocation.getRoot();
   IMethodBinding methodBinding = Invocations.resolveBinding(invocation);
   if (methodBinding == null) {
     status.addFatalError(
         RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
     return null;
   }
   MethodDeclaration declaration = (MethodDeclaration) root.findDeclaringNode(methodBinding);
   if (declaration != null) {
     return new SourceProvider(typeRoot, declaration);
   }
   IMethod method = (IMethod) methodBinding.getJavaElement();
   if (method != null) {
     CompilationUnit methodDeclarationAstRoot;
     ICompilationUnit methodCu = method.getCompilationUnit();
     if (methodCu != null) {
       methodDeclarationAstRoot = new RefactoringASTParser(AST.JLS3).parse(methodCu, true);
     } else {
       IClassFile classFile = method.getClassFile();
       if (!JavaElementUtil.isSourceAvailable(classFile)) {
         String methodLabel =
             JavaElementLabels.getTextLabel(
                 method,
                 JavaElementLabels.M_FULLY_QUALIFIED | JavaElementLabels.M_PARAMETER_TYPES);
         status.addFatalError(
             Messages.format(
                 RefactoringCoreMessages.InlineMethodRefactoring_error_classFile, methodLabel));
         return null;
       }
       methodDeclarationAstRoot = new RefactoringASTParser(AST.JLS3).parse(classFile, true);
     }
     ASTNode node =
         methodDeclarationAstRoot.findDeclaringNode(methodBinding.getMethodDeclaration().getKey());
     if (node instanceof MethodDeclaration) {
       return new SourceProvider(methodDeclarationAstRoot.getTypeRoot(), (MethodDeclaration) node);
     }
   }
   status.addFatalError(RefactoringCoreMessages.InlineMethodRefactoring_error_noMethodDeclaration);
   return null;
 }
    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();
            }
          });
    }
  public JavadocHelpContext(IContext context, Object[] elements) throws JavaModelException {
    Assert.isNotNull(elements);
    if (context instanceof IContext2) fTitle = ((IContext2) context).getTitle();

    List helpResources = new ArrayList();

    String javadocSummary = null;
    for (int i = 0; i < elements.length; i++) {
      if (elements[i] instanceof IJavaElement) {
        IJavaElement element = (IJavaElement) elements[i];
        // if element isn't on the build path skip it
        if (!ActionUtil.isOnBuildPath(element)) continue;

        // Create Javadoc summary
        if (BUG_85721_FIXED) {
          if (javadocSummary == null) {
            javadocSummary = retrieveText(element);
            if (javadocSummary != null) {
              String elementLabel =
                  JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_DEFAULT);

              // FIXME: needs to be NLSed once the code becomes active
              javadocSummary =
                  "<b>Javadoc for "
                      + elementLabel
                      + ":</b><br>"
                      + javadocSummary; //$NON-NLS-1$//$NON-NLS-2$
            }
          } else {
            javadocSummary = ""; // no Javadoc summary for multiple selection //$NON-NLS-1$
          }
        }

        URL url = JavaUI.getJavadocLocation(element, true);
        if (url == null || doesNotExist(url)) {
          IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element);
          if (root != null) {
            url = JavaUI.getJavadocBaseLocation(element);
            if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
              element = element.getJavaProject();
            } else {
              element = root;
            }
            url = JavaUI.getJavadocLocation(element, false);
          }
        }
        if (url != null) {
          IHelpResource javaResource = new JavaUIHelpResource(element, getURLString(url));
          helpResources.add(javaResource);
        }
      }
    }

    // Add static help topics
    if (context != null) {
      IHelpResource[] resources = context.getRelatedTopics();
      if (resources != null) {
        for (int j = 0; j < resources.length; j++) {
          helpResources.add(resources[j]);
        }
      }
    }

    fHelpResources =
        (IHelpResource[]) helpResources.toArray(new IHelpResource[helpResources.size()]);

    if (context != null) fText = context.getText();

    if (BUG_85721_FIXED) {
      if (javadocSummary != null && javadocSummary.length() > 0) {
        if (fText != null) fText = context.getText() + "<br><br>" + javadocSummary; // $NON-NLS-1$
        else fText = javadocSummary;
      }
    }

    if (fText == null) fText = ""; // $NON-NLS-1$
  }
 public String getLabel() {
   String label =
       JavaElementLabels.getTextLabel(
           fElement, JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_FULLY_QUALIFIED);
   return Messages.format(JavaUIMessages.JavaUIHelp_link_label, label);
 }
    /* (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();
      }
    }
Beispiel #15
0
 private String getDeclaringTypeLabel() {
   return JavaElementLabels.getElementLabel(
       fField.getDeclaringType(), JavaElementLabels.ALL_DEFAULT);
 }