Ejemplo n.º 1
0
 private static void checkHierarchyOfEnclosedTypes(
     IType destinationType, RefactoringStatus result, IType type) throws JavaModelException {
   IType[] enclosedTypes = getAllEnclosedTypes(type);
   for (int i = 0; i < enclosedTypes.length; i++) {
     IType enclosedType = enclosedTypes[i];
     if (destinationType.getElementName().equals(enclosedType.getElementName())) {
       String message =
           Messages.format(
               RefactoringCoreMessages.MemberCheckUtil_type_name_conflict3,
               new String[] {getQualifiedLabel(enclosedType), getQualifiedLabel(type)});
       RefactoringStatusContext context =
           JavaStatusContext.create(
               destinationType.getCompilationUnit(), destinationType.getNameRange());
       result.addError(message, context);
     }
     if (typeNameExistsInEnclosingTypeChain(destinationType, enclosedType.getElementName())) {
       String message =
           Messages.format(
               RefactoringCoreMessages.MemberCheckUtil_type_name_conflict4,
               new String[] {getQualifiedLabel(enclosedType), getQualifiedLabel(type)});
       RefactoringStatusContext context =
           JavaStatusContext.create(
               destinationType.getCompilationUnit(), destinationType.getNameRange());
       result.addError(message, context);
     }
   }
 }
Ejemplo n.º 2
0
 private static void checkMethodInType(
     IType destinationType, RefactoringStatus result, IMethod method) throws JavaModelException {
   IMethod[] destinationTypeMethods = destinationType.getMethods();
   IMethod found = findMethod(method, destinationTypeMethods);
   if (found != null) {
     RefactoringStatusContext context =
         JavaStatusContext.create(destinationType.getCompilationUnit(), found.getSourceRange());
     String message =
         Messages.format(
             RefactoringCoreMessages.MemberCheckUtil_signature_exists,
             new String[] {
               BasicElementLabels.getJavaElementName(method.getElementName()),
               getQualifiedLabel(destinationType)
             });
     result.addError(message, context);
   } else {
     IMethod similar = Checks.findMethod(method, destinationType);
     if (similar != null) {
       String message =
           Messages.format(
               RefactoringCoreMessages.MemberCheckUtil_same_param_count,
               new String[] {
                 BasicElementLabels.getJavaElementName(method.getElementName()),
                 getQualifiedLabel(destinationType)
               });
       RefactoringStatusContext context =
           JavaStatusContext.create(
               destinationType.getCompilationUnit(), similar.getSourceRange());
       result.addWarning(message, context);
     }
   }
 }
  private void validateFolders() {
    boolean useFolders = fFoldersAsSourceFolder.getSelection();

    fSrcFolderNameText.setEnabled(useFolders);
    fBinFolderNameText.setEnabled(useFolders);
    fSrcFolderNameLabel.setEnabled(useFolders);
    fBinFolderNameLabel.setEnabled(useFolders);
    if (useFolders) {
      String srcName = fSrcFolderNameText.getText();
      String binName = fBinFolderNameText.getText();
      if (srcName.length() + binName.length() == 0) {
        updateStatus(
            new StatusInfo(
                IStatus.ERROR,
                PreferencesMessages.NewJavaProjectPreferencePage_folders_error_namesempty));
        return;
      }
      IWorkspace workspace = JavaPlugin.getWorkspace();
      IProject dmy = workspace.getRoot().getProject("project"); // $NON-NLS-1$

      IStatus status;
      IPath srcPath = dmy.getFullPath().append(srcName);
      if (srcName.length() != 0) {
        status = workspace.validatePath(srcPath.toString(), IResource.FOLDER);
        if (!status.isOK()) {
          String message =
              Messages.format(
                  PreferencesMessages.NewJavaProjectPreferencePage_folders_error_invalidsrcname,
                  status.getMessage());
          updateStatus(new StatusInfo(IStatus.ERROR, message));
          return;
        }
      }
      IPath binPath = dmy.getFullPath().append(binName);
      if (binName.length() != 0) {
        status = workspace.validatePath(binPath.toString(), IResource.FOLDER);
        if (!status.isOK()) {
          String message =
              Messages.format(
                  PreferencesMessages.NewJavaProjectPreferencePage_folders_error_invalidbinname,
                  status.getMessage());
          updateStatus(new StatusInfo(IStatus.ERROR, message));
          return;
        }
      }
      IClasspathEntry entry = JavaCore.newSourceEntry(srcPath);
      status =
          JavaConventions.validateClasspath(
              JavaCore.create(dmy), new IClasspathEntry[] {entry}, binPath);
      if (!status.isOK()) {
        String message = PreferencesMessages.NewJavaProjectPreferencePage_folders_error_invalidcp;
        updateStatus(new StatusInfo(IStatus.ERROR, message));
        return;
      }
    }
    updateStatus(new StatusInfo()); // set to OK
  }
  public ImplementInterfaceProposal(
      ICompilationUnit targetCU,
      ITypeBinding binding,
      CompilationUnit astRoot,
      ITypeBinding newInterface,
      int relevance) {
    super(
        "",
        targetCU,
        null,
        relevance,
        JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE)); // $NON-NLS-1$

    Assert.isTrue(binding != null && Bindings.isDeclarationBinding(binding));

    fBinding = binding;
    fAstRoot = astRoot;
    fNewInterface = newInterface;

    String[] args = {
      BasicElementLabels.getJavaElementName(binding.getName()),
      BasicElementLabels.getJavaElementName(Bindings.getRawName(newInterface))
    };
    setDisplayName(Messages.format(CorrectionMessages.ImplementInterfaceProposal_name, args));
  }
Ejemplo n.º 5
0
 private void showUnexpectedError(CoreException e) {
   String message2 =
       Messages.format(
           ActionMessages.CleanUpAction_UnexpectedErrorMessage, e.getStatus().getMessage());
   IStatus status = new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, message2, null);
   ErrorDialog.openError(getShell(), getActionName(), null, status);
 }
Ejemplo n.º 6
0
  private void runOnMultiple(final ICompilationUnit[] cus) {
    ICleanUp[] cleanUps = getCleanUps(cus);
    if (cleanUps == null) return;

    MultiStatus status =
        new MultiStatus(
            JavaUI.ID_PLUGIN, IStatus.OK, ActionMessages.CleanUpAction_MultiStateErrorTitle, null);
    for (int i = 0; i < cus.length; i++) {
      ICompilationUnit cu = cus[i];

      if (!ActionUtil.isOnBuildPath(cu)) {
        String cuLocation = BasicElementLabels.getPathLabel(cu.getPath(), false);
        String message =
            Messages.format(ActionMessages.CleanUpAction_CUNotOnBuildpathMessage, cuLocation);
        status.add(new Status(IStatus.INFO, JavaUI.ID_PLUGIN, IStatus.ERROR, message, null));
      }
    }
    if (!status.isOK()) {
      ErrorDialog.openError(getShell(), getActionName(), null, status);
      return;
    }

    try {
      performRefactoring(cus, cleanUps);
    } catch (InvocationTargetException e) {
      JavaPlugin.log(e);
      if (e.getCause() instanceof CoreException) showUnexpectedError((CoreException) e.getCause());
    }
  }
Ejemplo n.º 7
0
 private static void checkTypeInType(IType destinationType, RefactoringStatus result, IType type)
     throws JavaModelException {
   String typeName = type.getElementName();
   IType destinationTypeType = destinationType.getType(typeName);
   if (destinationTypeType.exists()) {
     String message =
         Messages.format(
             RefactoringCoreMessages.MemberCheckUtil_type_name_conflict0,
             new String[] {
               BasicElementLabels.getJavaElementName(typeName), getQualifiedLabel(destinationType)
             });
     RefactoringStatusContext context =
         JavaStatusContext.create(
             destinationType.getCompilationUnit(), destinationTypeType.getNameRange());
     result.addError(message, context);
   } else {
     // need to check the hierarchy of enclosing and enclosed types
     if (destinationType.getElementName().equals(typeName)) {
       String message =
           Messages.format(
               RefactoringCoreMessages.MemberCheckUtil_type_name_conflict1,
               getQualifiedLabel(type));
       RefactoringStatusContext context =
           JavaStatusContext.create(
               destinationType.getCompilationUnit(), destinationType.getNameRange());
       result.addError(message, context);
     }
     if (typeNameExistsInEnclosingTypeChain(destinationType, typeName)) {
       String message =
           Messages.format(
               RefactoringCoreMessages.MemberCheckUtil_type_name_conflict2,
               getQualifiedLabel(type));
       RefactoringStatusContext context =
           JavaStatusContext.create(
               destinationType.getCompilationUnit(), destinationType.getNameRange());
       result.addError(message, context);
     }
     checkHierarchyOfEnclosedTypes(destinationType, result, type);
   }
 }
  private void updateStatus(HoverConfig hoverConfig) {
    if (hoverConfig != null && hoverConfig.fIsEnabled && hoverConfig.fStateMask == -1)
      fStatus =
          new StatusInfo(
              IStatus.ERROR,
              Messages.format(
                  PreferencesMessages.JavaEditorHoverConfigurationBlock_modifierIsNotValid,
                  hoverConfig.fModifierString));
    else fStatus = new StatusInfo();

    int i = 0;
    HashMap<Integer, String> stateMasks = new HashMap<Integer, String>(fHoverConfigs.length);
    while (fStatus.isOK() && i < fHoverConfigs.length) {
      if (fHoverConfigs[i].fIsEnabled) {
        String label = getContributedHovers()[i].getLabel();
        Integer stateMask = new Integer(fHoverConfigs[i].fStateMask);
        if (fHoverConfigs[i].fStateMask == -1)
          fStatus =
              new StatusInfo(
                  IStatus.ERROR,
                  Messages.format(
                      PreferencesMessages
                          .JavaEditorHoverConfigurationBlock_modifierIsNotValidForHover,
                      new String[] {fHoverConfigs[i].fModifierString, label}));
        else if (stateMasks.containsKey(stateMask))
          fStatus =
              new StatusInfo(
                  IStatus.ERROR,
                  Messages.format(
                      PreferencesMessages.JavaEditorHoverConfigurationBlock_duplicateModifier,
                      new String[] {label, stateMasks.get(stateMask)}));
        else stateMasks.put(stateMask, label);
      }
      i++;
    }

    fMainPreferencePage.setValid(fStatus.isOK());
    StatusUtil.applyToStatusLine(fMainPreferencePage, fStatus);
  }
Ejemplo n.º 9
0
 private static void checkFieldInType(
     IType destinationType, RefactoringStatus result, IField field) throws JavaModelException {
   IField destinationTypeField = destinationType.getField(field.getElementName());
   if (!destinationTypeField.exists()) return;
   String message =
       Messages.format(
           RefactoringCoreMessages.MemberCheckUtil_field_exists,
           new String[] {
             BasicElementLabels.getJavaElementName(field.getElementName()),
             getQualifiedLabel(destinationType)
           });
   RefactoringStatusContext context =
       JavaStatusContext.create(
           destinationType.getCompilationUnit(), destinationTypeField.getSourceRange());
   result.addError(message, context);
 }
Ejemplo n.º 10
0
 private IPackageFragment[] getPackages(NodeList list) throws IOException {
   if (list.getLength() > 1)
     throw new IOException(
         Messages.format(
             JarPackagerMessages.JarPackageReader_error_duplicateTag, list.item(0).getNodeName()));
   if (list.getLength() == 0) return null; // optional entry is not present
   NodeList packageNodes = list.item(0).getChildNodes();
   List<IJavaElement> packages = new ArrayList<IJavaElement>(packageNodes.getLength());
   for (int i = 0; i < packageNodes.getLength(); i++) {
     Node packageNode = packageNodes.item(i);
     if (packageNode.getNodeType() == Node.ELEMENT_NODE
         && packageNode.getNodeName().equals("package")) { // $NON-NLS-1$
       String handleId = ((Element) packageNode).getAttribute("handleIdentifier"); // $NON-NLS-1$
       if (handleId.equals("")) // $NON-NLS-1$
       throw new IOException(
             JarPackagerMessages.JarPackageReader_error_tagHandleIdentifierNotFoundOrEmpty);
       IJavaElement je = JavaCore.create(handleId);
       if (je != null && je.getElementType() == IJavaElement.PACKAGE_FRAGMENT) packages.add(je);
       else addWarning(JarPackagerMessages.JarPackageReader_warning_javaElementDoesNotExist, null);
     }
   }
   return packages.toArray(new IPackageFragment[packages.size()]);
 }
  private void createMessage(final Composite composite) {
    // TODO create a link with an argument, so the formatter preference page can open the
    // current profile automatically.
    String linkTooltip = PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tooltip;
    String text;
    String indentMode =
        JavaPlugin.getDefault()
            .getCombinedPreferenceStore()
            .getString(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
    if (JavaCore.TAB.equals(indentMode))
      text =
          Messages.format(
              PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_tab_text,
              new String[] {Integer.toString(getTabDisplaySize())});
    else
      text =
          Messages.format(
              PreferencesMessages.SmartTypingConfigurationBlock_tabs_message_others_text,
              new String[] {
                Integer.toString(getTabDisplaySize()),
                Integer.toString(getIndentSize()),
                getIndentMode()
              });

    final Link link = new Link(composite, SWT.NONE);
    link.setText(text);
    link.setToolTipText(linkTooltip);
    GridData gd = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    gd.widthHint = 300; // don't get wider initially
    link.setLayoutData(gd);
    link.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            PreferencesUtil.createPreferenceDialogOn(
                link.getShell(),
                "org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage",
                null,
                null); //$NON-NLS-1$
          }
        });

    final IPreferenceStore combinedStore = JavaPlugin.getDefault().getCombinedPreferenceStore();
    final IPropertyChangeListener propertyChangeListener =
        new IPropertyChangeListener() {
          private boolean fHasRun = false;

          public void propertyChange(PropertyChangeEvent event) {
            if (fHasRun) return;
            if (composite.isDisposed()) return;
            String property = event.getProperty();
            if (DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR.equals(property)
                || DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE.equals(property)) {
              fHasRun = true;
              link.dispose();
              createMessage(composite);
              Dialog.applyDialogFont(composite);
              composite.redraw();
              composite.layout();
            }
          }
        };
    combinedStore.addPropertyChangeListener(propertyChangeListener);
    link.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
            combinedStore.removePropertyChangeListener(propertyChangeListener);
          }
        });
  }