public void run(IStructuredSelection selection) { ICompilationUnit[] cus= getCompilationUnits(selection); if (cus.length == 0) { MessageDialog.openInformation(getShell(), getActionName(), ActionMessages.CleanUpAction_EmptySelection_description); } else if (cus.length == 1) { run(cus[0]); } else { runOnMultiple(cus); } }
@Override public void selectionChanged(ITextSelection selection) { setEnabled(getCompilationUnit(fEditor) != null); }
public void selectionChanged(IStructuredSelection selection) { setEnabled(isEnabled(selection)); }
public void run(ITextSelection selection) { ICompilationUnit cu= getCompilationUnit(fEditor); if (cu != null) { run(cu); } }
private void run(ICompilationUnit cu) { if (!ActionUtil.isEditable(fEditor, getShell(), cu)) return; ICleanUp[] cleanUps= getCleanUps(new ICompilationUnit[] { cu }); if (cleanUps == null) return; if (!ElementValidator.check(cu, getShell(), getActionName(), fEditor != null)) return; try { performRefactoring(new ICompilationUnit[] { cu }, cleanUps); } catch (InvocationTargetException e) { JavaPlugin.log(e); if (e.getCause() instanceof CoreException) showUnexpectedError((CoreException)e.getCause()); } }
private void run(ICompilationUnit cu) { if (!ActionUtil.isEditable(fEditor, getShell(), cu)) return; ICleanUp[] cleanUps= createCleanUps(new ICompilationUnit[] { cu }); if (cleanUps == null) return; if (!ElementValidator.check(cu, getShell(), getActionName(), fEditor != null)) return; try { performRefactoring(new ICompilationUnit[] { cu }, cleanUps); } catch (InvocationTargetException e) { JavaPlugin.log(e); if (e.getCause() instanceof CoreException) showUnexpectedError((CoreException)e.getCause()); } catch (JavaModelException e) { showUnexpectedError(e); } }
/** * @param units * to clean up * @param cleanUps * clean ups to execute on units * * @throws JavaModelException * @throws InvocationTargetException */ protected void performRefactoring(ICompilationUnit[] units, ICleanUp[] cleanUps) throws JavaModelException, InvocationTargetException { RefactoringExecutionStarter.startCleanupRefactoring(units, cleanUps, getShell(), false, getActionName()); }
public ICompilationUnit[] getCompilationUnits(IStructuredSelection selection) { HashSet<IJavaElement> result= new HashSet<>(); Object[] selected= selection.toArray(); for (int i= 0; i < selected.length; i++) { Object element= selected[i]; collectCompilationUnits(element, result); } return result.toArray(new ICompilationUnit[result.size()]); }
private void run(ICompilationUnit cu) { if (!ActionUtil.isEditable(fEditor, getShell(), cu)) return; ICleanUp[] cleanUps= getCleanUps(new ICompilationUnit[] { cu }); if (cleanUps == null) return; if (!ElementValidator.check(cu, getShell(), getActionName(), fEditor != null)) return; try { performRefactoring(new ICompilationUnit[] { cu }, cleanUps); } catch (InvocationTargetException e) { JavaPlugin.log(e); if (e.getCause() instanceof CoreException) showUnexpectedError((CoreException)e.getCause()); } }
private void runOnMultiple(final ICompilationUnit[] cus) { ICleanUp[] cleanUps= createCleanUps(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= cu.getPath().makeRelative().toString(); 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()); } catch (JavaModelException e) { showUnexpectedError(e); } }
protected void performRefactoring(ICompilationUnit[] units, ICleanUp[] cleanUps) throws InvocationTargetException { RefactoringExecutionStarter.startCleanupRefactoring(units, cleanUps, false, getShell(), false, getActionName()); }
@Override public void run(ITextSelection selection) { ICompilationUnit cu= getCompilationUnit(fEditor); if (cu != null) { run(cu); } }
public ICompilationUnit[] getCompilationUnits(IStructuredSelection selection) { HashSet<IJavaElement> result= new HashSet<>(); Object[] selected= selection.toArray(); for (int i= 0; i < selected.length; i++) { Object element= selected[i]; collectCompilationUnits(element, result); } return result.toArray(new ICompilationUnit[result.size()]); }
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()); } }
@Override public void run(IStructuredSelection selection) { ICompilationUnit[] cus= getCompilationUnits(selection); if (cus.length == 0) { MessageDialog.openInformation(getShell(), getActionName(), ActionMessages.CleanUpAction_EmptySelection_description); } else if (cus.length == 1) { run(cus[0]); } else { runOnMultiple(cus); } }
@Override public void selectionChanged(ITextSelection selection) { setEnabled(getCompilationUnit(fEditor) != null); }
protected void performRefactoring(ICompilationUnit[] units, ICleanUp[] cleanUps) throws InvocationTargetException { RefactoringExecutionStarter.startCleanupRefactoring(units, cleanUps, false, getShell(), false, getActionName()); }
@Override public void run(ITextSelection selection) { ICompilationUnit cu= getCompilationUnit(fEditor); if (cu != null) { run(cu); } }
@Override public void selectionChanged(IStructuredSelection selection) { setEnabled(isEnabled(selection)); }
private void collectCompilationUnits(IPackageFragmentRoot root, Collection<IJavaElement> result) throws JavaModelException { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { IJavaElement[] children= root.getChildren(); for (int i= 0; i < children.length; i++) { collectCompilationUnits((IPackageFragment)children[i], result); } } }