Java Code Examples for org.eclipse.ltk.core.refactoring.RefactoringStatus#hasError()
The following examples show how to use
org.eclipse.ltk.core.refactoring.RefactoringStatus#hasError() .
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: ChangeBuilder.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Creates a refactoring (or returns a previously created refactoring). */ public Refactoring createRefactoring() throws RefactoringException { if (refactoring != null) { return refactoring; } RefactoringStatus status = new RefactoringStatus(); D descriptor = createDescriptor(); try { refactoring = descriptor.createRefactoring(status); } catch (CoreException e) { throw new RefactoringException(e); } if (refactoring == null) { throw new RefactoringException( String.format( "The refactoring descriptor (%s) was unable to create a refactoring.", descriptor.getClass().getSimpleName())); } if (status.hasError()) { throw new RefactoringException( status.getMessageMatchingSeverity(RefactoringStatus.ERROR)); } return refactoring; }
Example 2
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public final RefactoringStatus checkInitialConditions(final IProgressMonitor monitor) throws CoreException, OperationCanceledException { Assert.isNotNull(monitor); final RefactoringStatus status= new RefactoringStatus(); try { monitor.beginTask("", 4); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking); status.merge(Checks.checkIfCuBroken(fMethod)); if (!status.hasError()) { checkMethodDeclaration(new SubProgressMonitor(monitor, 1), status); if (status.isOK()) { final MethodDeclaration declaration= ASTNodeSearchUtil.getMethodDeclarationNode(fMethod, fSourceRewrite.getRoot()); checkGenericTypes(new SubProgressMonitor(monitor, 1), declaration, status); checkMethodBody(new SubProgressMonitor(monitor, 1), declaration, status); checkPossibleTargets(new SubProgressMonitor(monitor, 1), declaration, status); } } } finally { monitor.done(); } return status; }
Example 3
Source File: SelectionTransferDropAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private int handleValidateMove(Object target) throws JavaModelException{ if (fMoveProcessor == null) { IMovePolicy policy= ReorgPolicyFactory.createMovePolicy(ReorgUtils.getResources(fElements), ReorgUtils.getJavaElements(fElements)); if (policy.canEnable()) fMoveProcessor= new JavaMoveProcessor(policy); } if (!canMoveElements()) return DND.DROP_NONE; if (fMoveProcessor == null) return DND.DROP_NONE; RefactoringStatus moveStatus= fMoveProcessor.setDestination(ReorgDestinationFactory.createDestination(target, getCurrentLocation())); if (moveStatus.hasError()) return DND.DROP_NONE; return DND.DROP_MOVE; }
Example 4
Source File: ExtractMethodComposite.java From Pydev with Eclipse Public License 1.0 | 6 votes |
public boolean validate() { if (argumentsTable != null) { VariableCellValidator cellValidator = new VariableCellValidator(this.page, getArgumentsTable(), scopeAdapter); cellValidator.validate(); } RefactoringStatus status = new RefactoringStatus(); NameValidator nameValidator = new NameValidator(status, scopeAdapter); nameValidator.validateMethodName(getFunctionName()); nameValidator.validateUniqueFunction(getFunctionName()); if (status.hasError()) { page.setErrorMessage(status.getMessageMatchingSeverity(RefactoringStatus.WARNING)); } return !status.hasError(); }
Example 5
Source File: VariableCellValidator.java From Pydev with Eclipse Public License 1.0 | 6 votes |
private void validateArguments() { RefactoringStatus status = new RefactoringStatus(); NameValidator validator = new NameValidator(status, this.scope); TableItem[] items = table.getItems(); for (TableItem item : items) { if (item instanceof SimpleTableItem) { SimpleTableItem variableItem = (SimpleTableItem) item; if (variableItem.hasNewName()) { validator.validateVariableName(item.getText()); validator.validateUniqueVariable(item.getText()); } } } if (status.hasError()) { page.setErrorMessage(status.getMessageMatchingSeverity(RefactoringStatus.WARNING)); } }
Example 6
Source File: JdtRenameRefactoringParticipantProcessor.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { RefactoringStatus status = preCheckInitialConditions(pm); if(status.hasError()) return status; return super.checkInitialConditions(pm); }
Example 7
Source File: RenameAnalyzeUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * This method analyzes a set of local variable renames inside one cu. It checks whether * any new compile errors have been introduced by the rename(s) and whether the correct * node(s) has/have been renamed. * * @param analyzePackages the LocalAnalyzePackages containing the information about the local renames * @param cuChange the TextChange containing all local variable changes to be applied. * @param oldCUNode the fully (incl. bindings) resolved AST node of the original compilation unit * @param recovery whether statements and bindings recovery should be performed when parsing the changed CU * @return a RefactoringStatus containing errors if compile errors or wrongly renamed nodes are found * @throws CoreException thrown if there was an error greating the preview content of the change */ public static RefactoringStatus analyzeLocalRenames(LocalAnalyzePackage[] analyzePackages, TextChange cuChange, CompilationUnit oldCUNode, boolean recovery) throws CoreException { RefactoringStatus result= new RefactoringStatus(); ICompilationUnit compilationUnit= (ICompilationUnit) oldCUNode.getJavaElement(); String newCuSource= cuChange.getPreviewContent(new NullProgressMonitor()); CompilationUnit newCUNode= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(newCuSource, compilationUnit, true, recovery, null); result.merge(analyzeCompileErrors(newCuSource, newCUNode, oldCUNode)); if (result.hasError()) { return result; } for (int i= 0; i < analyzePackages.length; i++) { ASTNode enclosing= getEnclosingBlockOrMethodOrLambda(analyzePackages[i].fDeclarationEdit, cuChange, newCUNode); // get new declaration IRegion newRegion= RefactoringAnalyzeUtil.getNewTextRange(analyzePackages[i].fDeclarationEdit, cuChange); ASTNode newDeclaration= NodeFinder.perform(newCUNode, newRegion.getOffset(), newRegion.getLength()); Assert.isTrue(newDeclaration instanceof Name); VariableDeclaration declaration= getVariableDeclaration((Name) newDeclaration); Assert.isNotNull(declaration); SimpleName[] problemNodes= ProblemNodeFinder.getProblemNodes(enclosing, declaration, analyzePackages[i].fOccurenceEdits, cuChange); result.merge(RefactoringAnalyzeUtil.reportProblemNodes(newCuSource, problemNodes)); } return result; }
Example 8
Source File: ExtractInterfaceProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public final RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, final CheckConditionsContext context) throws CoreException, OperationCanceledException { Assert.isNotNull(monitor); Assert.isNotNull(context); final RefactoringStatus status= new RefactoringStatus(); fChangeManager= new TextEditBasedChangeManager(); try { monitor.beginTask("", 1); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.ExtractInterfaceProcessor_checking); status.merge(Checks.checkIfCuBroken(fSubType)); if (!status.hasError()) { if (fSubType.isBinary() || fSubType.isReadOnly() || !fSubType.exists()) status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractInterfaceProcessor_no_binary, JavaStatusContext.create(fSubType))); else if (fSubType.isAnonymous()) status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractInterfaceProcessor_no_anonymous, JavaStatusContext.create(fSubType))); else if (fSubType.isAnnotation()) status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ExtractInterfaceProcessor_no_annotation, JavaStatusContext.create(fSubType))); else { status.merge(checkSuperType()); if (!status.hasFatalError()) { if (!status.hasFatalError()) { fChangeManager= createChangeManager(new SubProgressMonitor(monitor, 1), status); if (!status.hasFatalError()) { Checks.addModifiedFilesToChecker(ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits()), context); } } } } } } finally { monitor.done(); } return status; }
Example 9
Source File: RenameAnalyzeUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * This method analyzes a set of local variable renames inside one cu. It checks whether * any new compile errors have been introduced by the rename(s) and whether the correct * node(s) has/have been renamed. * * @param analyzePackages the LocalAnalyzePackages containing the information about the local renames * @param cuChange the TextChange containing all local variable changes to be applied. * @param oldCUNode the fully (incl. bindings) resolved AST node of the original compilation unit * @param recovery whether statements and bindings recovery should be performed when parsing the changed CU * @return a RefactoringStatus containing errors if compile errors or wrongly renamed nodes are found * @throws CoreException thrown if there was an error greating the preview content of the change */ public static RefactoringStatus analyzeLocalRenames(LocalAnalyzePackage[] analyzePackages, TextChange cuChange, CompilationUnit oldCUNode, boolean recovery) throws CoreException { RefactoringStatus result= new RefactoringStatus(); ICompilationUnit compilationUnit= (ICompilationUnit) oldCUNode.getJavaElement(); String newCuSource= cuChange.getPreviewContent(new NullProgressMonitor()); CompilationUnit newCUNode= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(newCuSource, compilationUnit, true, recovery, null); result.merge(analyzeCompileErrors(newCuSource, newCUNode, oldCUNode)); if (result.hasError()) return result; for (int i= 0; i < analyzePackages.length; i++) { ASTNode enclosing= getEnclosingBlockOrMethodOrLambda(analyzePackages[i].fDeclarationEdit, cuChange, newCUNode); // get new declaration IRegion newRegion= RefactoringAnalyzeUtil.getNewTextRange(analyzePackages[i].fDeclarationEdit, cuChange); ASTNode newDeclaration= NodeFinder.perform(newCUNode, newRegion.getOffset(), newRegion.getLength()); Assert.isTrue(newDeclaration instanceof Name); VariableDeclaration declaration= getVariableDeclaration((Name) newDeclaration); Assert.isNotNull(declaration); SimpleName[] problemNodes= ProblemNodeFinder.getProblemNodes(enclosing, declaration, analyzePackages[i].fOccurenceEdits, cuChange); result.merge(RefactoringAnalyzeUtil.reportProblemNodes(newCuSource, problemNodes)); } return result; }
Example 10
Source File: RefactoringExecutionStarter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void startIntroduceParameterObject(IMethod method, Shell shell) throws CoreException { RefactoringStatus availability= Checks.checkAvailability(method); if (availability.hasError()){ MessageDialog.openError(shell, RefactoringMessages.RefactoringExecutionStarter_IntroduceParameterObject_problem_title, RefactoringMessages.RefactoringExecutionStarter_IntroduceParameterObject_problem_description); return; } IntroduceParameterObjectDescriptor ipod= RefactoringSignatureDescriptorFactory.createIntroduceParameterObjectDescriptor(); ipod.setMethod(method); IntroduceParameterObjectProcessor processor= new IntroduceParameterObjectProcessor(ipod); final RefactoringStatus status= processor.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) { final Object element= entry.getData(); IMethod superMethod= (IMethod) element; availability= Checks.checkAvailability(superMethod); if (availability.hasError()){ MessageDialog.openError(shell, RefactoringMessages.RefactoringExecutionStarter_IntroduceParameterObject_problem_title, RefactoringMessages.RefactoringExecutionStarter_IntroduceParameterObject_problem_description); return; } String message= Messages.format(RefactoringMessages.RefactoringErrorDialogUtil_okToPerformQuestion, entry.getMessage()); if (element != null && MessageDialog.openQuestion(shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, message)) { ipod= RefactoringSignatureDescriptorFactory.createIntroduceParameterObjectDescriptor(); ipod.setMethod(superMethod); processor= new IntroduceParameterObjectProcessor(ipod); } else processor=null; } } if (processor != null) { Refactoring refactoring= new ProcessorBasedRefactoring(processor); IntroduceParameterObjectWizard wizard= new IntroduceParameterObjectWizard(processor, refactoring); new RefactoringStarter().activate(wizard, shell, RefactoringMessages.OpenRefactoringWizardAction_refactoring, RefactoringSaveHelper.SAVE_REFACTORING); } }
Example 11
Source File: ParameterEditDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IStatus validateType() { if (fType == null) return null; String type= fType.getText(); RefactoringStatus status= TypeContextChecker.checkParameterTypeSyntax(type, fContext.getCuHandle().getJavaProject()); if (status == null || status.isOK()) return Status.OK_STATUS; if (status.hasError()) return createErrorStatus(status.getEntryWithHighestSeverity().getMessage()); else return createWarningStatus(status.getEntryWithHighestSeverity().getMessage()); }
Example 12
Source File: CleanUpPostSaveListener.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private int showStatus(RefactoringStatus status) { if (!status.hasError()) return Window.OK; Shell shell= PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); Dialog dialog= RefactoringUI.createRefactoringStatusDialog(status, shell, "", false); //$NON-NLS-1$ return dialog.open(); }
Example 13
Source File: RenameRefactoringXpectMethod.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Rename refactoring Xpect method */ // Note: arg1=OFFSET makes the 'offset' parameter contain the right offset value @ParameterParser(syntax = "('at' arg2=OFFSET 'to' arg3=STRING) ('resource' arg4=STRING)?") @Xpect @ConsumedIssues({ Severity.INFO, Severity.ERROR, Severity.WARNING }) public void renameRefactoring( @StringDiffExpectation(whitespaceSensitive = false) IStringDiffExpectation expectation, // arg0 @ThisResource XtextResource resource, // arg1 IEObjectCoveringRegion offset, // arg2 String newName, // arg3 String specifiedResourcePath, // arg4 @N4JSCommaSeparatedValuesExpectation IN4JSCommaSeparatedValuesExpectation expectedResult) throws Exception { try { EObject context = offset.getEObject(); EObject selectedElement = offsetHelper.resolveElementAt((XtextResource) context.eResource(), offset.getOffset()); // LiteralOrComputedPropertyName does not have a type model but its container does if (selectedElement instanceof LiteralOrComputedPropertyName) { selectedElement = selectedElement.eContainer(); } // An IdentifierRef refers to an AST FormalParameter and not TFormalParameter if (!(selectedElement instanceof FormalParameter) && (N4JSLanguageUtils.getDefinedTypeModelElement(selectedElement) != null)) { selectedElement = N4JSLanguageUtils.getDefinedTypeModelElement(selectedElement); } // while (selectedElement != null) { // while (Display.getCurrent().readAndDispatch()) // ; // Display.getCurrent().sleep(); // } URI targetResourceUri = context.eResource().getURI(); Optional<XtextEditor> editorOp = EditorsUtil.openXtextEditor(targetResourceUri, N4JSActivator.ORG_ECLIPSE_N4JS_N4JS); XtextEditor editor = editorOp.get(); final ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection(); IRenameElementContext renameElementContext = renameContextFactory .createRenameElementContext( selectedElement, editor, selection, resource); IRenameSupport renameSupport = renameSupportFactory.create(renameElementContext, newName); // HACK, use reflection to obtain the private field 'renameRefactoring' since we need it to verify the // conditions // Field field = renameSupport.getClass().getDeclaredField("renameRefactoring"); // field.setAccessible(true); ProcessorBasedRefactoring refactoring = (ProcessorBasedRefactoring) ReflectionUtil.getFieldValue( renameSupport, "renameRefactoring"); RefactoringStatus status = refactoring.checkAllConditions(new NullProgressMonitor()); // If rename refactoring's conditions are not satisfied, validate the error message if (status.hasError()) { RefactoringStatusEntry[] entries = status.getEntries(); List<String> errorMessages = Arrays.stream(entries).map(statusEntry -> statusEntry.getMessage()) .collect(Collectors.toList()); expectedResult.assertEquals(errorMessages); } else { String beforeRenameContent = getResourceContentWithoutXpectComment(specifiedResourcePath, resource); renameSupport.startDirectRefactoring(); String afterRenameContent = getResourceContentWithoutXpectComment(specifiedResourcePath, resource); expectation.assertDiffEquals(beforeRenameContent, afterRenameContent); } } finally { EditorsUtil.forceCloseAllEditors(); } }
Example 14
Source File: N4JSRenameElementProcessor.java From n4js with Eclipse Public License 1.0 | 4 votes |
private RefactoringStatus checkDuplicateName(EObject context, String newName) { RefactoringStatus status = new RefactoringStatus(); // Check name conflicts of TMembers if (context instanceof TMember) { TMember member = (TMember) context; status.merge(checkDuplicateMember(member, newName)); } if (status.hasError()) { return status; } if (context instanceof TEnumLiteral) { TEnumLiteral enumLit = (TEnumLiteral) context; status.merge(checkDuplicateEnum((TEnum) enumLit.eContainer(), newName)); } if (status.hasError()) { return status; } if (context instanceof FormalParameter) { FormalParameter fpar = (FormalParameter) context; FunctionDefinition method = (FunctionDefinition) fpar.eContainer(); status.merge(checkDuplicateFormalParam(fpar, method.getFpars(), newName)); } if (status.hasError()) { return status; } // Check name conflicts in variable environment scope using Scope for ContentAssist EObject astContext = null; if (context instanceof SyntaxRelatedTElement) { astContext = ((SyntaxRelatedTElement) context).getAstElement(); } else { astContext = context; } IScope scope = scopeProvider.getScopeForContentAssist(astContext, N4JSPackage.Literals.IDENTIFIER_REF__ID); for (IEObjectDescription desc : scope.getAllElements()) { if (desc.getName().toString().equals(newName)) { status.merge(RefactoringStatus.createFatalErrorStatus( "Problem in " + trimPlatformPart(desc.getEObjectURI().trimFragment().toString()) + ": Another element in the same scope with name '" + newName + "' already exists")); if (status.hasError()) { return status; } } } return status; }
Example 15
Source File: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public final RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, final CheckConditionsContext context) throws CoreException, OperationCanceledException { Assert.isNotNull(monitor); Assert.isNotNull(context); Assert.isNotNull(fTarget); final RefactoringStatus status= new RefactoringStatus(); fChangeManager= new TextChangeManager(); try { monitor.beginTask("", 4); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking); status.merge(Checks.checkIfCuBroken(fMethod)); if (!status.hasError()) { checkGenericTarget(new SubProgressMonitor(monitor, 1), status); if (status.isOK()) { final IType type= getTargetType(); if (type != null) { if (type.isBinary() || type.isReadOnly() || !fMethod.exists() || fMethod.isBinary() || fMethod.isReadOnly()) status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_binary, JavaStatusContext.create(fMethod))); else { status.merge(Checks.checkIfCuBroken(type)); if (!status.hasError()) { if (!type.exists() || type.isBinary() || type.isReadOnly()) status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_binary, JavaStatusContext.create(fMethod))); checkConflictingTarget(new SubProgressMonitor(monitor, 1), status); checkConflictingMethod(new SubProgressMonitor(monitor, 1), status); Checks.addModifiedFilesToChecker(computeModifiedFiles(fMethod.getCompilationUnit(), type.getCompilationUnit()), context); monitor.worked(1); if (!status.hasFatalError()) fChangeManager= createChangeManager(status, new SubProgressMonitor(monitor, 1)); } } } else status.merge(RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.MoveInstanceMethodProcessor_no_resolved_target, JavaStatusContext.create(fMethod))); } } } finally { monitor.done(); } return status; }
Example 16
Source File: IntroduceIndirectionRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private RefactoringStatus updateTargetVisibility(IProgressMonitor monitor) throws JavaModelException, CoreException { RefactoringStatus result= new RefactoringStatus(); // Adjust the visibility of the method and of the referenced type. Note that // the target method may not be in the target type; and in this case, the type // of the target method does not need a visibility adjustment. // This method is called after all other changes have been // created. Changes induced by this method will be attached to those changes. result.merge(adjustVisibility((IType) fIntermediaryFirstParameterType.getJavaElement(), fIntermediaryType, monitor)); if (result.hasError()) return result; // binary ModifierKeyword neededVisibility= getNeededVisibility(fTargetMethod, fIntermediaryType); if (neededVisibility != null) { result.merge(adjustVisibility(fTargetMethod, neededVisibility, monitor)); if (result.hasError()) return result; // binary // Need to adjust the overridden methods of the target method. ITypeHierarchy hierarchy= fTargetMethod.getDeclaringType().newTypeHierarchy(null); MethodOverrideTester tester= new MethodOverrideTester(fTargetMethod.getDeclaringType(), hierarchy); IType[] subtypes= hierarchy.getAllSubtypes(fTargetMethod.getDeclaringType()); for (int i= 0; i < subtypes.length; i++) { IMethod method= tester.findOverridingMethodInType(subtypes[i], fTargetMethod); if (method != null && method.exists()) { result.merge(adjustVisibility(method, neededVisibility, monitor)); if (monitor.isCanceled()) throw new OperationCanceledException(); if (result.hasError()) return result; // binary } } } return result; }