Java Code Examples for org.eclipse.ltk.core.refactoring.RefactoringStatus#getSeverity()
The following examples show how to use
org.eclipse.ltk.core.refactoring.RefactoringStatus#getSeverity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChangeUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Creates a {@link Change} from the given {@link Refactoring}. * * @param errorLevel the error level for the condition checking which should * cause the change creation to fail * * @return a non-null {@link Change} * @throws RefactoringException if there was a problem creating the change */ public static Change createChange(IWorkspace workspace, IProgressMonitor pm, Refactoring refactoring, int errorLevel) throws RefactoringException { CreateChangeOperation createChangeOperation = ChangeUtilities.createCreateChangeOperation( refactoring, errorLevel); try { workspace.run(createChangeOperation, pm); RefactoringStatus status = createChangeOperation.getConditionCheckingStatus(); if (status.getSeverity() >= errorLevel) { // Could not create the change, throw an exception with the failure // status message throw new RefactoringException( status.getMessageMatchingSeverity(status.getSeverity())); } } catch (CoreException e) { throw new RefactoringException(e); } return createChangeOperation.getChange(); }
Example 2
Source File: CallInliner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public RefactoringStatus initialize(ASTNode invocation, int severity) { RefactoringStatus result= new RefactoringStatus(); fInvocation= invocation; fLocals= new ArrayList<VariableDeclarationStatement>(3); checkMethodDeclaration(result, severity); if (result.getSeverity() >= severity) return result; initializeRewriteState(); initializeTargetNode(); flowAnalysis(); fContext= new CallContext(fInvocation, fInvocationScope, fTargetNode.getNodeType(), fImportRewrite); try { computeRealArguments(); computeReceiver(); } catch (BadLocationException exception) { JavaPlugin.log(exception); } checkInvocationContext(result, severity); return result; }
Example 3
Source File: IntroduceFactoryInputPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void validateInput(boolean methodName) { RefactoringStatus merged= new RefactoringStatus(); if (fMethodNameStatus != null && (methodName || fMethodNameStatus.hasError())) merged.merge(fMethodNameStatus); if (fDestinationStatus != null && (!methodName || fDestinationStatus.hasError())) merged.merge(fDestinationStatus); setPageComplete(!merged.hasError()); int severity= merged.getSeverity(); String message= merged.getMessageMatchingSeverity(severity); if (severity >= RefactoringStatus.INFO) { setMessage(message, severity); } else { setMessage("", NONE); //$NON-NLS-1$ } }
Example 4
Source File: RenameRefactoringExecuter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void run(IProgressMonitor pm) throws CoreException { try { pm.beginTask("", 11); pm.subTask(""); final RefactoringStatus status = refactoring.checkAllConditions(SubMonitor.convert(pm, 4)); if (status.getSeverity() >= RefactoringStatus.WARNING) { final boolean[] canceled = { false }; shell.getDisplay().syncExec(new Runnable() { @Override public void run() { canceled[0] = showStatusDialog(status); } }); if (canceled[0]) { throw new OperationCanceledException(); } } Change change = refactoring.createChange(SubMonitor.convert(pm, 2)); change.initializeValidationData(SubMonitor.convert(pm, 1)); performChangeOperation = new PerformChangeOperation(change); performChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), refactoring.getName()); performChangeOperation.setSchedulingRule(ResourcesPlugin.getWorkspace().getRoot()); } finally { pm.done(); } }
Example 5
Source File: RefactoringExecutionHelper.java From typescript.java with MIT License | 5 votes |
@Override public void run(IProgressMonitor pm) throws CoreException { try { pm.beginTask("", fForked && !fForkChangeExecution ? 7 : 11); //$NON-NLS-1$ pm.subTask(""); //$NON-NLS-1$ final RefactoringStatus status= fRefactoring.checkAllConditions(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); if (status.getSeverity() >= fStopSeverity) { final boolean[] canceled= { false }; if (fForked) { fParent.getDisplay().syncExec(new Runnable() { @Override public void run() { canceled[0]= showStatusDialog(status); } }); } else { canceled[0]= showStatusDialog(status); } if (canceled[0]) { throw new OperationCanceledException(); } } fChange= fRefactoring.createChange(new SubProgressMonitor(pm, 2, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); fChange.initializeValidationData(new SubProgressMonitor(pm, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); fPerformChangeOperation= new PerformChangeOperation(fChange);//RefactoringUI.createUIAwareChangeOperation(fChange); fPerformChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), fRefactoring.getName()); if (fRefactoring instanceof IScheduledRefactoring) fPerformChangeOperation.setSchedulingRule(((IScheduledRefactoring)fRefactoring).getSchedulingRule()); if (!fForked || fForkChangeExecution) fPerformChangeOperation.run(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); } finally { pm.done(); } }
Example 6
Source File: RefactoringExecutionHelper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void run(IProgressMonitor pm) throws CoreException { try { pm.beginTask("", fForked && !fForkChangeExecution ? 7 : 11); //$NON-NLS-1$ pm.subTask(""); //$NON-NLS-1$ final RefactoringStatus status= fRefactoring.checkAllConditions(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); if (status.getSeverity() >= fStopSeverity) { final boolean[] canceled= { false }; if (fForked) { fParent.getDisplay().syncExec(new Runnable() { public void run() { canceled[0]= showStatusDialog(status); } }); } else { canceled[0]= showStatusDialog(status); } if (canceled[0]) { throw new OperationCanceledException(); } } fChange= fRefactoring.createChange(new SubProgressMonitor(pm, 2, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); fChange.initializeValidationData(new SubProgressMonitor(pm, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); fPerformChangeOperation= new PerformChangeOperation(fChange);//RefactoringUI.createUIAwareChangeOperation(fChange); fPerformChangeOperation.setUndoManager(RefactoringCore.getUndoManager(), fRefactoring.getName()); if (fRefactoring instanceof IScheduledRefactoring) fPerformChangeOperation.setSchedulingRule(((IScheduledRefactoring)fRefactoring).getSchedulingRule()); if (!fForked || fForkChangeExecution) fPerformChangeOperation.run(new SubProgressMonitor(pm, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); } finally { pm.done(); } }
Example 7
Source File: IntroduceIndirectionInputPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void validateInput() { RefactoringStatus merged= new RefactoringStatus(); merged.merge(getIntroduceIndirectionRefactoring().setIntermediaryTypeName(fIntermediaryTypeName.getText())); merged.merge(getIntroduceIndirectionRefactoring().setIntermediaryMethodName(fIntermediaryMethodName.getText())); setPageComplete(!merged.hasError()); int severity= merged.getSeverity(); String message= merged.getMessageMatchingSeverity(severity); if (severity >= RefactoringStatus.INFO) { setMessage(message, severity); } else { setMessage("", NONE); //$NON-NLS-1$ } }
Example 8
Source File: ExtractConstantWizard.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected RefactoringStatus validateTextField(String text) { try { getExtractConstantRefactoring().setConstantName(text); updatePreviewLabel(); RefactoringStatus result= getExtractConstantRefactoring().checkConstantNameOnChange(); if (fOriginalMessageType == IMessageProvider.INFORMATION && result.getSeverity() == RefactoringStatus.OK) return RefactoringStatus.createInfoStatus(fOriginalMessage); else return result; } catch (JavaModelException e) { JavaPlugin.log(e); return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.ExtractConstantInputPage_Internal_Error); } }
Example 9
Source File: InlineMethodRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException { pm.beginTask("", 20); //$NON-NLS-1$ fChangeManager= new TextChangeManager(); RefactoringStatus result= new RefactoringStatus(); fSourceProvider.initialize(); fTargetProvider.initialize(); pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_searching); RefactoringStatus searchStatus= new RefactoringStatus(); String binaryRefsDescription= Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description , BasicElementLabels.getJavaElementName(fSourceProvider.getMethodName())); ReferencesInBinaryContext binaryRefs= new ReferencesInBinaryContext(binaryRefsDescription); ICompilationUnit[] units= fTargetProvider.getAffectedCompilationUnits(searchStatus, binaryRefs, new SubProgressMonitor(pm, 1)); binaryRefs.addErrorIfNecessary(searchStatus); if (searchStatus.hasFatalError()) { result.merge(searchStatus); return result; } IFile[] filesToBeModified= getFilesToBeModified(units); result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext())); if (result.hasFatalError()) return result; result.merge(ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1))); checkOverridden(result, new SubProgressMonitor(pm, 4)); IProgressMonitor sub= new SubProgressMonitor(pm, 15); sub.beginTask("", units.length * 3); //$NON-NLS-1$ for (int c= 0; c < units.length; c++) { ICompilationUnit unit= units[c]; sub.subTask(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_processing, BasicElementLabels.getFileName(unit))); CallInliner inliner= null; try { boolean added= false; MultiTextEdit root= new MultiTextEdit(); CompilationUnitChange change= (CompilationUnitChange)fChangeManager.get(unit); change.setEdit(root); BodyDeclaration[] bodies= fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1)); if (bodies.length == 0) continue; inliner= new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider); for (int b= 0; b < bodies.length; b++) { BodyDeclaration body= bodies[b]; inliner.initialize(body); RefactoringStatus nestedInvocations= new RefactoringStatus(); ASTNode[] invocations= removeNestedCalls(nestedInvocations, unit, fTargetProvider.getInvocations(body, new SubProgressMonitor(sub, 2))); for (int i= 0; i < invocations.length; i++) { ASTNode invocation= invocations[i]; result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity())); if (result.hasFatalError()) break; if (result.getSeverity() < fTargetProvider.getStatusSeverity()) { added= true; TextEditGroup group= new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_inline); change.addTextEditGroup(group); result.merge(inliner.perform(group)); } else { fDeleteSource= false; } } // do this after we have inlined the method calls. We still want // to generate the modifications. if (!nestedInvocations.isOK()) { result.merge(nestedInvocations); fDeleteSource= false; } } if (!added) { fChangeManager.remove(unit); } else { root.addChild(inliner.getModifications()); ImportRewrite rewrite= inliner.getImportEdit(); if (rewrite.hasRecordedChanges()) { TextEdit edit= rewrite.rewriteImports(null); if (edit instanceof MultiTextEdit ? ((MultiTextEdit)edit).getChildrenSize() > 0 : true) { root.addChild(edit); change.addTextEditGroup( new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] {edit})); } } } } finally { if (inliner != null) inliner.dispose(); } sub.worked(1); if (sub.isCanceled()) throw new OperationCanceledException(); } result.merge(searchStatus); sub.done(); pm.done(); return result; }
Example 10
Source File: ReplaceInvocationsRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException { pm.beginTask("", 20); //$NON-NLS-1$ fChangeManager= new TextChangeManager(); RefactoringStatus result= new RefactoringStatus(); fSourceProvider= resolveSourceProvider(fMethodBinding, result); if (result.hasFatalError()) return result; result.merge(fSourceProvider.checkActivation()); if (result.hasFatalError()) return result; fSourceProvider.initialize(); fTargetProvider.initialize(); pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_searching); RefactoringStatus searchStatus= new RefactoringStatus(); String binaryRefsDescription= Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description , BasicElementLabels.getJavaElementName(fSourceProvider.getMethodName())); ReferencesInBinaryContext binaryRefs= new ReferencesInBinaryContext(binaryRefsDescription); ICompilationUnit[] units= fTargetProvider.getAffectedCompilationUnits(searchStatus, binaryRefs, new SubProgressMonitor(pm, 1)); binaryRefs.addErrorIfNecessary(searchStatus); if (searchStatus.hasFatalError()) { result.merge(searchStatus); return result; } IFile[] filesToBeModified= getFilesToBeModified(units); result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext())); if (result.hasFatalError()) return result; result.merge(ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1))); checkOverridden(result, new SubProgressMonitor(pm, 4)); IProgressMonitor sub= new SubProgressMonitor(pm, 15); sub.beginTask("", units.length * 3); //$NON-NLS-1$ for (int c= 0; c < units.length; c++) { ICompilationUnit unit= units[c]; sub.subTask(Messages.format(RefactoringCoreMessages.InlineMethodRefactoring_processing, BasicElementLabels.getFileName(unit))); CallInliner inliner= null; try { boolean added= false; MultiTextEdit root= new MultiTextEdit(); CompilationUnitChange change= (CompilationUnitChange)fChangeManager.get(unit); change.setEdit(root); BodyDeclaration[] bodies= fTargetProvider.getAffectedBodyDeclarations(unit, new SubProgressMonitor(pm, 1)); if (bodies.length == 0) continue; inliner= new CallInliner(unit, (CompilationUnit) bodies[0].getRoot(), fSourceProvider); for (int b= 0; b < bodies.length; b++) { BodyDeclaration body= bodies[b]; inliner.initialize(body); RefactoringStatus nestedInvocations= new RefactoringStatus(); ASTNode[] invocations= removeNestedCalls(nestedInvocations, unit, fTargetProvider.getInvocations(body, new SubProgressMonitor(sub, 2))); for (int i= 0; i < invocations.length; i++) { ASTNode invocation= invocations[i]; result.merge(inliner.initialize(invocation, fTargetProvider.getStatusSeverity())); if (result.hasFatalError()) break; if (result.getSeverity() < fTargetProvider.getStatusSeverity()) { added= true; TextEditGroup group= new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_inline); change.addTextEditGroup(group); result.merge(inliner.perform(group)); } } // do this after we have inlined the method calls. We still want // to generate the modifications. result.merge(nestedInvocations); } if (!added) { fChangeManager.remove(unit); } else { root.addChild(inliner.getModifications()); ImportRewrite rewrite= inliner.getImportEdit(); if (rewrite.hasRecordedChanges()) { TextEdit edit= rewrite.rewriteImports(null); if (edit instanceof MultiTextEdit ? ((MultiTextEdit)edit).getChildrenSize() > 0 : true) { root.addChild(edit); change.addTextEditGroup( new TextEditGroup(RefactoringCoreMessages.InlineMethodRefactoring_edit_import, new TextEdit[] {edit})); } } } } finally { if (inliner != null) inliner.dispose(); } sub.worked(1); if (sub.isCanceled()) throw new OperationCanceledException(); } result.merge(searchStatus); sub.done(); pm.done(); return result; }