private IStatus asStatus(RefactoringStatus status) { if (status.isOK()) { return Status.OK_STATUS; } else { return status.getEntryWithHighestSeverity().toStatus(); } }
/** * Adds an <code>INFO</code> entry filled with the given message and context to * this status. If the current severity is <code>OK</code> it will be changed to * <code>INFO</code>. It will remain unchanged otherwise. * * @param msg the message of the info entry * @param context the context of the info entry * * @see RefactoringStatusEntry */ public void addInfo(String msg, RefactoringStatusContext context) { fEntries.add(new RefactoringStatusEntry(RefactoringStatus.INFO, msg, context)); fSeverity= Math.max(fSeverity, INFO); }
switch (getSeverity()) { case RefactoringStatus.OK: statusSeverity= IStatus.OK; break; String pluginId= getPluginId(); int code= getCode(); if (pluginId == null) { pluginId= RefactoringCorePlugin.getPluginId(); code= IStatus.ERROR; return new Status(statusSeverity, pluginId, code, getMessage(), null);
/** * Returns the first entry managed by this refactoring status that * matches the given plug-in identifier and code. If more than one * entry exists that matches the criteria the first one in the list * of entries is returned. Returns <code>null</code> if no entry * matches. * * @param pluginId the entry's plug-in identifier * @param code the entry's code * @return the entry that matches the given plug-in identifier and * code; <code>null</code> otherwise */ public RefactoringStatusEntry getEntryMatchingCode(String pluginId, int code) { Assert.isTrue(pluginId != null); for (Iterator iter= fEntries.iterator(); iter.hasNext(); ) { RefactoringStatusEntry entry= (RefactoringStatusEntry)iter.next(); if (pluginId.equals(entry.getPluginId()) && entry.getCode() == code) return entry; } return null; }
public final boolean activate(final Refactoring ref, final Shell parent, final int saveMode) throws CoreException { final RefactoringStatus status= ref.checkInitialConditions(new NullProgressMonitor()); if (status.hasFatalError()) { final RefactoringStatusEntry entry= status.getEntryMatchingSeverity(RefactoringStatus.FATAL); if (entry.getCode() == RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD || entry.getCode() == RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE) { String message= entry.getMessage(); final Object element= entry.getData(); message= message + RefactoringMessages.RefactoringErrorDialogUtil_okToPerformQuestion; if (element != null && MessageDialog.openQuestion(shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, message)) { final IStructuredSelection selection= new StructuredSelection(element); // TODO: should not hijack this // ModifiyParametersAction. // The action is set up on an editor, but we use it // as if it were set up on a ViewPart. boolean wasEnabled= action.isEnabled(); action.selectionChanged(selection); if (action.isEnabled()) { action.run(selection); } else { MessageDialog.openInformation(shell, ActionMessages.ModifyParameterAction_problem_title, ActionMessages.ModifyParameterAction_problem_message); } action.setEnabled(wasEnabled); } return false; } } return super.activate(ref, parent, saveMode); } };
private boolean validChanges(CompositeChange change) { RefactoringStatus result= new RefactoringStatus(); List files= new ArrayList(); try { findFilesToBeModified(change, files); } catch (JavaModelException e) { JavaPlugin.log(e); return false; } result.merge(Checks.validateModifiesFiles((IFile[])files.toArray(new IFile[files.size()]), JavaPlugin.getActiveWorkbenchShell().getShell())); if (result.hasFatalError()) { RefactoringStatusEntry[] entries= result.getEntries(); IStatus status; if (entries.length > 1) { status= new MultiStatus(JavaUI.ID_PLUGIN, 0, result.getMessageMatchingSeverity(RefactoringStatus.ERROR), null); for (int i= 0; i < entries.length; i++) { ((MultiStatus)status).add(new Status(entries[i].getSeverity(), JavaUI.ID_PLUGIN, 0, entries[i].getMessage(), null)); } } else { RefactoringStatusEntry entry= entries[0]; status= new Status(entry.getSeverity(), JavaUI.ID_PLUGIN, 0, entry.getMessage(), null); } ErrorDialog.openError(JavaPlugin.getActiveWorkbenchShell().getShell(), CorrectionMessages.CorrectionMarkerResolutionGenerator__multiFixErrorDialog_Titel, CorrectionMessages.CorrectionMarkerResolutionGenerator_multiFixErrorDialog_description, status); return false; } return true; }
@Override public final int compare(final RefactoringStatusEntry entry1, final RefactoringStatusEntry entry2) { return entry1.getMessage().compareTo(entry2.getMessage()); } }, other).length > 0;
public int compare(Viewer viewer, Object e1, Object e2) { int r1= ((RefactoringStatusEntry)e1).getSeverity(); int r2= ((RefactoringStatusEntry)e2).getSeverity(); if (r1 < r2) return 1; if (r2 < r1) return -1; return 0; }
if (status.hasFatalError()) { RefactoringStatusEntry entry= status.getEntryMatchingSeverity(RefactoringStatus.FATAL); MessageDialog.openInformation(getShell(), getDialogTitle(), entry.getMessage()); if (entry.getContext() instanceof JavaStatusContext && fEditor != null) { JavaStatusContext context= (JavaStatusContext)entry.getContext(); ISourceRange range= context.getSourceRange(); fEditor.setHighlightRange(range.getOffset(), range.getLength(), true);
/** * {@inheritDoc} */ public IWizardPage getNextPage() { if (fChange != null && fRefactoring != null && !fStatus.hasFatalError()) { final RefactoringHistoryWizard result= getRefactoringHistoryWizard(); if (result != null) { final RefactoringStatus status= result.performPreviewChange(fChange, fRefactoring); if (!status.isOK()) { final RefactoringStatusEntry entry= status.getEntryWithHighestSeverity(); if (entry != null) { if (entry.getSeverity() == RefactoringStatus.INFO && entry.getCode() == RefactoringHistoryWizard.STATUS_CODE_INTERRUPTED) return this; final IErrorWizardPage page= result.getErrorPage(); if (page instanceof RefactoringHistoryErrorPage) { final RefactoringHistoryErrorPage extended= (RefactoringHistoryErrorPage) page; extended.setStatus(status); extended.setNextPageDisabled(fNextPageDisabled); extended.setTitle(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error_title); extended.setDescription(RefactoringUIMessages.RefactoringHistoryPreviewPage_apply_error); return extended; } } } } } return getWizard().getNextPage(this); }
@Override protected boolean selectStatusEntry(final RefactoringStatusEntry entry) { if (fSourceFolder != null) { final IPath source= fSourceFolder.getFullPath(); final RefactoringStatusContext context= entry.getContext(); if (context instanceof JavaStatusContext) { final JavaStatusContext extended= (JavaStatusContext) context; final ICompilationUnit unit= extended.getCompilationUnit(); if (unit != null) { final IResource resource= unit.getResource(); if (resource != null && source.isPrefixOf(resource.getFullPath())) return false; } } } return super.selectStatusEntry(entry); } }
if (status.hasFatalError()) { final RefactoringStatusEntry entry= status.getEntryMatchingSeverity(RefactoringStatus.FATAL); if (entry.getCode() == RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD || entry.getCode() == RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE) { String message= entry.getMessage(); final Object element= entry.getData(); IMethod superMethod= (IMethod) element; availability= Checks.checkAvailability(superMethod);
protected RefactoringStatus validateRefactoring() { RefactoringStatus status= new RefactoringStatus(); setErrorMessage(null); setMessage(null); setPageComplete(true); status.merge(validateTopLevel()); status.merge(validateClassName()); status.merge(validateParameterName()); status.merge(validateFields()); RefactoringStatusEntry highestSeverity= status.getEntryWithHighestSeverity(); if (highestSeverity != null) { switch (highestSeverity.getSeverity()) { case RefactoringStatus.ERROR: case RefactoringStatus.FATAL: setErrorMessage(highestSeverity.getMessage()); setPageComplete(false); break; case RefactoringStatus.WARNING: setMessage(highestSeverity.getMessage(), IMessageProvider.WARNING); break; case RefactoringStatus.INFO: setMessage(highestSeverity.getMessage(), IMessageProvider.INFORMATION); break; } } return status; }
@Override public final int compare(final RefactoringStatusEntry entry1, final RefactoringStatusEntry entry2) { return entry1.getMessage().compareTo(entry2.getMessage()); } }, other).length > 0;
/** * Adds the given <code>RefactoringStatusEntry</code>. The severity of this * status is set to the maximum of <code>fSeverity</code> and the severity of * the entry. * * @param entry the <code>RefactoringStatusEntry</code> to be added */ public void addEntry(RefactoringStatusEntry entry) { Assert.isNotNull(entry); fEntries.add(entry); fSeverity= Math.max(fSeverity, entry.getSeverity()); }
if (status.hasFatalError()) { RefactoringStatusEntry entry= status.getEntryMatchingSeverity(RefactoringStatus.FATAL); MessageDialog.openInformation(getShell(), getDialogTitle(), entry.getMessage()); if (entry.getContext() instanceof JavaStatusContext && fEditor != null) { JavaStatusContext context= (JavaStatusContext)entry.getContext(); ISourceRange range= context.getSourceRange(); fEditor.setHighlightRange(range.getOffset(), range.getLength(), true);
if (!status.isOK()) { final RefactoringStatusEntry entry= status.getEntryWithHighestSeverity(); if (entry.getSeverity() == RefactoringStatus.INFO && entry.getCode() == RefactoringHistoryWizard.STATUS_CODE_INTERRUPTED) return false; fErrorPage.setStatus(status);
/** * Returns the first entry managed by this refactoring status that * matches the given plug-in identifier and code. If more than one * entry exists that matches the criteria the first one in the list * of entries is returned. Returns <code>null</code> if no entry * matches. * * @param pluginId the entry's plug-in identifier * @param code the entry's code * @return the entry that matches the given plug-in identifier and * code; <code>null</code> otherwise */ public RefactoringStatusEntry getEntryMatchingCode(String pluginId, int code) { Assert.isTrue(pluginId != null); for (Iterator<RefactoringStatusEntry> iter= fEntries.iterator(); iter.hasNext(); ) { RefactoringStatusEntry entry= iter.next(); if (pluginId.equals(entry.getPluginId()) && entry.getCode() == code) return entry; } return null; }
@Override protected boolean selectStatusEntry(final RefactoringStatusEntry entry) { if (fSourceFolder != null) { final IPath source= fSourceFolder.getFullPath(); final RefactoringStatusContext context= entry.getContext(); if (context instanceof JavaStatusContext) { final JavaStatusContext extended= (JavaStatusContext) context; final ICompilationUnit unit= extended.getCompilationUnit(); if (unit != null) { final IResource resource= unit.getResource(); if (resource != null && source.isPrefixOf(resource.getFullPath())) return false; } } } return super.selectStatusEntry(entry); } }
if (status.hasFatalError()) { final RefactoringStatusEntry entry= status.getEntryMatchingSeverity(RefactoringStatus.FATAL); if (entry.getCode() == RefactoringStatusCodes.OVERRIDES_ANOTHER_METHOD || entry.getCode() == RefactoringStatusCodes.METHOD_DECLARED_IN_INTERFACE) { final Object element= entry.getData(); IMethod superMethod= (IMethod) element; availability= Checks.checkAvailability(superMethod); return; String message= Messages.format(RefactoringMessages.RefactoringErrorDialogUtil_okToPerformQuestion, entry.getMessage()); if (element != null && MessageDialog.openQuestion(shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, message)) { ipod= RefactoringSignatureDescriptorFactory.createIntroduceParameterObjectDescriptor();