Java Code Examples for org.eclipse.ltk.core.refactoring.RefactoringStatus#merge()
The following examples show how to use
org.eclipse.ltk.core.refactoring.RefactoringStatus#merge() .
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: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Checks whether the method has references to type variables or generic * types. * * @param monitor * the progress monitor to display progress * @param declaration * the method declaration to check for generic types * @param status * the status of the condition checking */ protected void checkGenericTypes(final IProgressMonitor monitor, final MethodDeclaration declaration, final RefactoringStatus status) { Assert.isNotNull(monitor); Assert.isNotNull(declaration); Assert.isNotNull(status); try { monitor.beginTask("", 1); //$NON-NLS-1$ monitor.setTaskName(RefactoringCoreMessages.MoveInstanceMethodProcessor_checking); final AstNodeFinder finder= new GenericReferenceFinder(declaration); declaration.accept(finder); if (!finder.getStatus().isOK()) status.merge(finder.getStatus()); } finally { monitor.done(); } }
Example 2
Source File: RenameCompilationUnitProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException { try{ if (fWillRenameType && (!fCu.isStructureKnown())){ RefactoringStatus result1= new RefactoringStatus(); RefactoringStatus result2= new RefactoringStatus(); result2.merge(Checks.checkCompilationUnitNewName(fCu, removeFileNameExtension(getNewElementName()))); if (result2.hasFatalError()) { result1.addError(Messages.format(RefactoringCoreMessages.RenameCompilationUnitRefactoring_not_parsed_1, BasicElementLabels.getFileName(fCu))); } else { result1.addError(Messages.format(RefactoringCoreMessages.RenameCompilationUnitRefactoring_not_parsed, BasicElementLabels.getFileName(fCu))); } result1.merge(result2); } if (fWillRenameType) { return fRenameTypeProcessor.checkFinalConditions(pm, context); } else { return Checks.checkCompilationUnitNewName(fCu, removeFileNameExtension(getNewElementName())); } } finally{ pm.done(); } }
Example 3
Source File: RenamePackageProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private RefactoringStatus checkPackageName(String newName) throws CoreException { RefactoringStatus status= new RefactoringStatus(); IPackageFragmentRoot[] roots= fPackage.getJavaProject().getPackageFragmentRoots(); Set<String> topLevelTypeNames= getTopLevelTypeNames(); for (int i= 0; i < roots.length; i++) { IPackageFragmentRoot root= roots[i]; if (! isPackageNameOkInRoot(newName, root)) { String rootLabel = JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT); String newPackageName= BasicElementLabels.getJavaElementName(getNewElementName()); String message= Messages.format(RefactoringCoreMessages.RenamePackageRefactoring_aleady_exists, new Object[]{ newPackageName, rootLabel}); status.merge(RefactoringStatus.createWarningStatus(message)); status.merge(checkTypeNameConflicts(root, newName, topLevelTypeNames)); } } return status; }
Example 4
Source File: RenameTypeProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private RefactoringStatus analyzeAffectedCompilationUnits(IProgressMonitor pm) throws CoreException { RefactoringStatus result = new RefactoringStatus(); result.merge(Checks.checkCompileErrorsInAffectedFiles(fReferences, fType.getResource())); pm.beginTask("", fReferences.length); //$NON-NLS-1$ result.merge(checkConflictingTypes(pm)); return result; }
Example 5
Source File: RenamePackageProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
void doRename(IProgressMonitor pm, RefactoringStatus result) throws CoreException { pm.beginTask("", 16); //$NON-NLS-1$ if (fProcessor.getUpdateReferences()){ pm.setTaskName(RefactoringCoreMessages.RenamePackageRefactoring_searching); String binaryRefsDescription= Messages.format(RefactoringCoreMessages.ReferencesInBinaryContext_ref_in_binaries_description , getElementLabel(fPackage)); ReferencesInBinaryContext binaryRefs= new ReferencesInBinaryContext(binaryRefsDescription); fOccurrences= getReferences(new SubProgressMonitor(pm, 4), binaryRefs, result); fReferencesToTypesInNamesakes= getReferencesToTypesInNamesakes(new SubProgressMonitor(pm, 4), result); fReferencesToTypesInPackage= getReferencesToTypesInPackage(new SubProgressMonitor(pm, 4), binaryRefs, result); binaryRefs.addErrorIfNecessary(result); pm.setTaskName(RefactoringCoreMessages.RenamePackageRefactoring_checking); result.merge(analyzeAffectedCompilationUnits()); pm.worked(1); } else { fOccurrences= new SearchResultGroup[0]; pm.worked(13); } if (result.hasFatalError()) { return; } if (fProcessor.getUpdateReferences()) { addReferenceUpdates(new SubProgressMonitor(pm, 3)); } else { pm.worked(3); } pm.done(); }
Example 6
Source File: CleanUpRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private RefactoringStatus checkPostConditions(SubProgressMonitor monitor) throws CoreException { RefactoringStatus result= new RefactoringStatus(); ICleanUp[] cleanUps= getCleanUps(); monitor.beginTask("", cleanUps.length); //$NON-NLS-1$ monitor.subTask(FixMessages.CleanUpRefactoring_checkingPostConditions_message); try { for (int j= 0; j < cleanUps.length; j++) { result.merge(cleanUps[j].checkPostConditions(new SubProgressMonitor(monitor, 1))); } } finally { monitor.done(); } return result; }
Example 7
Source File: ExtractFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException { try { pm.beginTask(RefactoringCoreMessages.ExtractTempRefactoring_checking_preconditions, 4); RefactoringStatus result = new RefactoringStatus(); result.merge(checkMatchingFragments()); return result; } finally { pm.done(); } }
Example 8
Source File: PushDownRefactoringProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ @Override public RefactoringStatus checkFinalConditions(IProgressMonitor monitor, CheckConditionsContext context) throws CoreException, OperationCanceledException { try { monitor.beginTask(RefactoringCoreMessages.PushDownRefactoring_checking, 5); clearCaches(); ICompilationUnit unit= getDeclaringType().getCompilationUnit(); if (fLayer) unit= unit.findWorkingCopy(fOwner); resetWorkingCopies(unit); final RefactoringStatus result= new RefactoringStatus(); result.merge(checkMembersInDestinationClasses(new SubProgressMonitor(monitor, 1))); result.merge(checkElementsAccessedByModifiedMembers(new SubProgressMonitor(monitor, 1))); result.merge(checkReferencesToPushedDownMembers(new SubProgressMonitor(monitor, 1))); if (!JdtFlags.isAbstract(getDeclaringType()) && getAbstractDeclarationInfos().length != 0) result.merge(checkConstructorCalls(getDeclaringType(), new SubProgressMonitor(monitor, 1))); else monitor.worked(1); if (result.hasFatalError()) return result; List<IMember> members= new ArrayList<IMember>(fMemberInfos.length); for (int index= 0; index < fMemberInfos.length; index++) { if (fMemberInfos[index].getAction() != MemberActionInfo.NO_ACTION) members.add(fMemberInfos[index].getMember()); } fMembersToMove= members.toArray(new IMember[members.size()]); fChangeManager= createChangeManager(new SubProgressMonitor(monitor, 1), result); if (result.hasFatalError()) return result; Checks.addModifiedFilesToChecker(ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits()), context); return result; } finally { monitor.done(); } }
Example 9
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private static void checkName(RefactoringStatus status, String name, List<IMethodBinding> usedNames, IType type, boolean reUseExistingField, IField field) { if ("".equals(name)) { //$NON-NLS-1$ status.addFatalError(RefactoringCoreMessages.Checks_Choose_name); return; } boolean isStatic = false; try { isStatic = Flags.isStatic(field.getFlags()); } catch (JavaModelException e) { JavaLanguageServerPlugin.log(e); } status.merge(Checks.checkMethodName(name, field)); for (Iterator<IMethodBinding> iter = usedNames.iterator(); iter.hasNext();) { IMethodBinding method = iter.next(); String selector = method.getName(); if (selector.equals(name)) { if (!reUseExistingField) { status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_method_exists, new String[] { BindingLabelProviderCore.getBindingLabel(method, JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(type.getElementName()) })); } else { boolean methodIsStatic = Modifier.isStatic(method.getModifiers()); if (methodIsStatic && !isStatic) { status.addWarning(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_static_method_but_nonstatic_field, new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) })); } if (!methodIsStatic && isStatic) { status.addFatalError(Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_nonstatic_method_but_static_field, new String[] { BasicElementLabels.getJavaElementName(method.getName()), BasicElementLabels.getJavaElementName(field.getElementName()) })); } return; } } } if (reUseExistingField) { status.addFatalError(Messages.format( RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_methoddoesnotexist_status_fatalError, new String[] { BasicElementLabels.getJavaElementName(name), BasicElementLabels.getJavaElementName(type.getElementName())})); } }
Example 10
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 11
Source File: RenameTypeParameterProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public RenameTypeParameterProcessor(JavaRefactoringArguments arguments, RefactoringStatus status) { this(null); status.merge(initialize(arguments)); }
Example 12
Source File: IntroduceIndirectionRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private RefactoringStatus updateMethodInvocation(MethodInvocation originalInvocation, IMember enclosing, CompilationUnitRewrite unitRewriter) throws JavaModelException { RefactoringStatus status= new RefactoringStatus(); // If the method invocation utilizes type arguments, skip this // call as the new target method may have additional parameters if (originalInvocation.typeArguments().size() > 0) return createWarningAboutCall(enclosing, originalInvocation, RefactoringCoreMessages.IntroduceIndirectionRefactoring_call_warning_type_arguments); MethodInvocation newInvocation= unitRewriter.getAST().newMethodInvocation(); List<Expression> newInvocationArgs= newInvocation.arguments(); List<Expression> originalInvocationArgs= originalInvocation.arguments(); // static call => always use a qualifier String qualifier= unitRewriter.getImportRewrite().addImport(fIntermediaryTypeBinding); newInvocation.setExpression(ASTNodeFactory.newName(unitRewriter.getAST(), qualifier)); newInvocation.setName(unitRewriter.getAST().newSimpleName(getIntermediaryMethodName())); final Expression expression= originalInvocation.getExpression(); if (!isStaticTarget()) { // Add the expression as the first parameter if (expression == null) { // There is no expression for this call. Use a (possibly qualified) "this" expression. ThisExpression expr= unitRewriter.getAST().newThisExpression(); RefactoringStatus qualifierStatus= qualifyThisExpression(expr, originalInvocation, enclosing, unitRewriter); status.merge(qualifierStatus); if (qualifierStatus.hasEntries()) // warning means don't include this invocation return status; newInvocationArgs.add(expr); } else { Expression expressionAsParam= (Expression) unitRewriter.getASTRewrite().createMoveTarget(expression); newInvocationArgs.add(expressionAsParam); } } else { if (expression != null) { // Check if expression is the type name. If not, there may // be side effects (e.g. inside methods) -> don't update if (! (expression instanceof Name) || ASTNodes.getTypeBinding((Name) expression) == null) return createWarningAboutCall(enclosing, originalInvocation, RefactoringCoreMessages.IntroduceIndirectionRefactoring_call_warning_static_expression_access); } } for (int i= 0; i < originalInvocationArgs.size(); i++) { Expression originalInvocationArg= originalInvocationArgs.get(i); Expression movedArg= (Expression) unitRewriter.getASTRewrite().createMoveTarget(originalInvocationArg); newInvocationArgs.add(movedArg); } unitRewriter.getASTRewrite().replace(originalInvocation, newInvocation, unitRewriter.createGroupDescription(RefactoringCoreMessages.IntroduceIndirectionRefactoring_group_description_replace_call)); return status; }
Example 13
Source File: NLSRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException { checkParameters(); try { pm.beginTask(NLSMessages.NLSRefactoring_checking, 5); RefactoringStatus result= new RefactoringStatus(); result.merge(checkIfAnythingToDo()); if (result.hasFatalError()) { return result; } pm.worked(1); result.merge(validateModifiesFiles()); if (result.hasFatalError()) { return result; } pm.worked(1); if (pm.isCanceled()) throw new OperationCanceledException(); result.merge(checkSubstitutionPattern()); pm.worked(1); if (pm.isCanceled()) throw new OperationCanceledException(); result.merge(checkKeys()); pm.worked(1); if (pm.isCanceled()) throw new OperationCanceledException(); if (!propertyFileExists() && willModifyPropertyFile()) { String msg= Messages.format(NLSMessages.NLSRefactoring_will_be_created, BasicElementLabels.getPathLabel(getPropertyFilePath(), false)); result.addInfo(msg); } pm.worked(1); return result; } finally { pm.done(); } }
Example 14
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static RefactoringStatus checkForMainAndNativeMethods(IType[] types) throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); for (int i= 0; i < types.length; i++) result.merge(checkForMainAndNativeMethods(types[i])); return result; }
Example 15
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static RefactoringStatus checkForMainAndNativeMethods(IType type) throws JavaModelException { RefactoringStatus result= new RefactoringStatus(); result.merge(checkForMainAndNativeMethods(type.getMethods())); result.merge(checkForMainAndNativeMethods(type.getTypes())); return result; }
Example 16
Source File: IntroduceIndirectionRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public IntroduceIndirectionRefactoring(JavaRefactoringArguments arguments, RefactoringStatus status) { this((ICompilationUnit) null, 0, 0); RefactoringStatus initializeStatus= initialize(arguments); status.merge(initializeStatus); }
Example 17
Source File: ExtractClassRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private RefactoringStatus updateReferences(IType type, ParameterObjectFactory pof, IProgressMonitor pm) throws CoreException { RefactoringStatus status= new RefactoringStatus(); pm.beginTask(RefactoringCoreMessages.ExtractClassRefactoring_progress_updating_references, 100); try { pm.worked(10); if (pm.isCanceled()) throw new OperationCanceledException(); List<IField> validIFields= new ArrayList<IField>(); for (Iterator<FieldInfo> iterator= fVariables.values().iterator(); iterator.hasNext();) { FieldInfo info= iterator.next(); if (isCreateField(info)) validIFields.add(info.ifield); } if (validIFields.size() == 0) { status.addWarning(RefactoringCoreMessages.ExtractClassRefactoring_warning_no_fields_moved, JavaStatusContext.create(type)); return status; } SearchPattern pattern= RefactoringSearchEngine.createOrPattern(validIFields.toArray(new IField[validIFields.size()]), IJavaSearchConstants.ALL_OCCURRENCES); SearchResultGroup[] results= RefactoringSearchEngine.search(pattern, RefactoringScopeFactory.create(type), pm, status); SubProgressMonitor spm= new SubProgressMonitor(pm, 90); spm.beginTask(RefactoringCoreMessages.ExtractClassRefactoring_progress_updating_references, results.length * 10); try { for (int i= 0; i < results.length; i++) { SearchResultGroup group= results[i]; ICompilationUnit unit= group.getCompilationUnit(); CompilationUnitRewrite cuRewrite; if (unit.equals(fBaseCURewrite.getCu())) cuRewrite= fBaseCURewrite; else cuRewrite= new CompilationUnitRewrite(unit); spm.worked(1); status.merge(replaceReferences(pof, group, cuRewrite)); if (cuRewrite != fBaseCURewrite) //Change for fBaseCURewrite will be generated later fChangeManager.manage(unit, cuRewrite.createChange(true, new SubProgressMonitor(spm, 9))); if (spm.isCanceled()) throw new OperationCanceledException(); } } finally { spm.done(); } } finally { pm.done(); } return status; }
Example 18
Source File: MoveStaticMembersProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public MoveStaticMembersProcessor(JavaRefactoringArguments arguments, RefactoringStatus status) { fDelegateUpdating= false; fDelegateDeprecation= true; RefactoringStatus initializeStatus= initialize(arguments); status.merge(initializeStatus); }
Example 19
Source File: RenameFieldProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 2 votes |
/** * Creates a new rename enum const processor. * * @param arguments * the arguments * * @param status * the status */ public RenameFieldProcessor(JavaRefactoringArguments arguments, RefactoringStatus status) { this(null); RefactoringStatus initializeStatus= initialize(arguments); status.merge(initializeStatus); }
Example 20
Source File: ExtractSupertypeProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 2 votes |
/** * Creates a new extract supertype refactoring processor from refactoring arguments. * * @param arguments * the refactoring arguments * @param status * the resulting status */ public ExtractSupertypeProcessor(JavaRefactoringArguments arguments, RefactoringStatus status) { super(null, null, true); RefactoringStatus initializeStatus= initialize(arguments); status.merge(initializeStatus); }