org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker Java Examples
The following examples show how to use
org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker.
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: JavaRenameProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public final RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException { ResourceChangeChecker checker= context.getChecker(ResourceChangeChecker.class); IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory(); RefactoringStatus result= doCheckFinalConditions(pm, context); if (result.hasFatalError()) { return result; } IFile[] changed= getChangedFiles(); for (int i= 0; i < changed.length; i++) { deltaFactory.change(changed[i]); } fRenameModifications= computeRenameModifications(); fRenameModifications.buildDelta(deltaFactory); fRenameModifications.buildValidateEdits(context.getChecker(ValidateEditChecker.class)); return result; }
Example #2
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context, IReorgQueries reorgQueries) throws CoreException { Assert.isNotNull(reorgQueries); ResourceChangeChecker checker= context.getChecker(ResourceChangeChecker.class); IFile[] allModifiedFiles= getAllModifiedFiles(); RefactoringModifications modifications= getModifications(); IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory(); for (int i= 0; i < allModifiedFiles.length; i++) { deltaFactory.change(allModifiedFiles[i]); } if (modifications != null) { modifications.buildDelta(deltaFactory); modifications.buildValidateEdits(context.getChecker(ValidateEditChecker.class)); } return new RefactoringStatus(); }
Example #3
Source File: JavaRenameProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public final RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException, OperationCanceledException { ResourceChangeChecker checker= (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class); IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory(); RefactoringStatus result= doCheckFinalConditions(pm, context); if (result.hasFatalError()) return result; IFile[] changed= getChangedFiles(); for (int i= 0; i < changed.length; i++) { deltaFactory.change(changed[i]); } fRenameModifications= computeRenameModifications(); fRenameModifications.buildDelta(deltaFactory); fRenameModifications.buildValidateEdits((ValidateEditChecker)context.getChecker(ValidateEditChecker.class)); return result; }
Example #4
Source File: MoveStaticMembersProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException { fTarget= null; try { pm.beginTask(RefactoringCoreMessages.MoveMembersRefactoring_checking, 10); RefactoringStatus result= new RefactoringStatus(); fSource.clearASTAndImportRewrites(); result.merge(checkDestinationType()); if (result.hasFatalError()) return result; result.merge(checkDestinationInsideTypeToMove()); if (result.hasFatalError()) return result; result.merge(MemberCheckUtil.checkMembersInDestinationType(fMembersToMove, fDestinationType)); if (result.hasFatalError()) return result; result.merge(checkNativeMovedMethods(new SubProgressMonitor(pm, 1))); if (result.hasFatalError()) return result; List<ICompilationUnit> modifiedCus= new ArrayList<ICompilationUnit>(); createChange(modifiedCus, result, new SubProgressMonitor(pm, 7)); IFile[] changedFiles= getAllFilesToModify(modifiedCus); ResourceChangeChecker checker= (ResourceChangeChecker)context.getChecker(ResourceChangeChecker.class); for (int i= 0; i < changedFiles.length; i++) { checker.getDeltaFactory().change(changedFiles[i]); } return result; } finally { pm.done(); } }
Example #5
Source File: Checks.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void addModifiedFilesToChecker(IFile[] filesToModify, CheckConditionsContext context) { ResourceChangeChecker checker= (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class); IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory(); for (int i= 0; i < filesToModify.length; i++) { deltaFactory.change(filesToModify[i]); } }
Example #6
Source File: ExtractMethodRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Checks if the refactoring can be activated. Activation typically means, if a * corresponding menu entry can be added to the UI. * * @param pm a progress monitor to report progress during activation checking. * @return the refactoring status describing the result of the activation check. * @throws CoreException if checking fails */ @Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { RefactoringStatus result= new RefactoringStatus(); pm.beginTask("", 100); //$NON-NLS-1$ if (fSelectionStart < 0 || fSelectionLength == 0) return mergeTextSelectionStatus(result); IFile[] changedFiles= ResourceUtil.getFiles(new ICompilationUnit[]{fCUnit}); result.merge(Checks.validateModifiesFiles(changedFiles, getValidationContext())); if (result.hasFatalError()) return result; result.merge(ResourceChangeChecker.checkFilesToBeChanged(changedFiles, new SubProgressMonitor(pm, 1))); if (fRoot == null) { fRoot= RefactoringASTParser.parseWithASTProvider(fCUnit, true, new SubProgressMonitor(pm, 99)); } fImportRewriter= StubUtility.createImportRewrite(fRoot, true); fAST= fRoot.getAST(); fRoot.accept(createVisitor()); fSelectionStart= fAnalyzer.getSelection().getOffset(); fSelectionLength= fAnalyzer.getSelection().getLength(); result.merge(fAnalyzer.checkInitialConditions(fImportRewriter)); if (result.hasFatalError()) return result; if (fVisibility == -1) { setVisibility(Modifier.PRIVATE); } initializeParameterInfos(); initializeUsedNames(); initializeDuplicates(); initializeDestinations(); return result; }
Example #7
Source File: JavaDeleteProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException { pm.beginTask(RefactoringCoreMessages.DeleteRefactoring_1, 1); try{ fWasCanceled= false; RefactoringStatus result= new RefactoringStatus(); recalculateElementsToDelete(); checkDirtyCompilationUnits(result); checkDirtyResources(result); fDeleteModifications= new DeleteModifications(); fDeleteModifications.delete(fResources); fDeleteModifications.delete(fJavaElements); List<IResource> packageDeletes= fDeleteModifications.postProcess(); TextChangeManager manager= new TextChangeManager(); fDeleteChange= DeleteChangeCreator.createDeleteChange(manager, fResources, fJavaElements, getProcessorName(), packageDeletes); ResourceChangeChecker checker= (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class); IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory(); fDeleteModifications.buildDelta(deltaFactory); IFile[] files= ResourceUtil.getFiles(manager.getAllCompilationUnits()); for (int i= 0; i < files.length; i++) { deltaFactory.change(files[i]); } return result; } catch (OperationCanceledException e) { fWasCanceled= true; throw e; } finally{ pm.done(); } }
Example #8
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context, IReorgQueries reorgQueries) throws CoreException { Assert.isNotNull(reorgQueries); ResourceChangeChecker checker= (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class); IFile[] allModifiedFiles= getAllModifiedFiles(); RefactoringModifications modifications= getModifications(); IResourceChangeDescriptionFactory deltaFactory= checker.getDeltaFactory(); for (int i= 0; i < allModifiedFiles.length; i++) { deltaFactory.change(allModifiedFiles[i]); } if (modifications != null) { modifications.buildDelta(deltaFactory); modifications.buildValidateEdits((ValidateEditChecker) context.getChecker(ValidateEditChecker.class)); } return new RefactoringStatus(); }
Example #9
Source File: ChangedFilesChecker.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Checks the given files that have been changed by validating them with the workspace. * * @param files the files to check * @param validationContext the context for validating the files. Should be the value of * {@link org.eclipse.ltk.core.refactoring.Refactoring#getValidationContext()}. * @param refactoringStatus the value to store the detection of problems. * @throws CoreException when the validation is canceled */ public static void checkFiles(Collection<IFile> files, Object validationContext, RefactoringStatus refactoringStatus) throws CoreException { List<IFile> readOnly = new ArrayList<IFile>(); for (IFile file : files) { if (file.isReadOnly()) { readOnly.add(file); } } if (ResourcesPlugin.getPlugin() == null) { //i.e.: in test mode we won't be able to get the workspace return; } if (!readOnly.isEmpty()) { IFile[] readOnlyFiles = readOnly.toArray(new IFile[readOnly.size()]); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IStatus status = workspace.validateEdit(readOnlyFiles, validationContext); if (status.getSeverity() == IStatus.CANCEL) { throw new OperationCanceledException(); } refactoringStatus.merge(RefactoringStatus.create(status)); if (refactoringStatus.hasFatalError()) { return; } } refactoringStatus.merge(ResourceChangeChecker.checkFilesToBeChanged( files.toArray(new IFile[files.size()]), null)); }
Example #10
Source File: ExtractMethodRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
/** * Checks if the refactoring can be activated. Activation typically means, * if a corresponding menu entry can be added to the UI. * * @param pm * a progress monitor to report progress during activation * checking. * @return the refactoring status describing the result of the activation * check. * @throws CoreException * if checking fails */ @Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { RefactoringStatus result = new RefactoringStatus(); pm.beginTask("", 100); //$NON-NLS-1$ if (fSelectionStart < 0 || fSelectionLength == 0) { return mergeTextSelectionStatus(result); } IFile[] changedFiles = ResourceUtil.getFiles(new ICompilationUnit[] { fCUnit }); result.merge(Checks.validateModifiesFiles(changedFiles, getValidationContext(), pm)); if (result.hasFatalError()) { return result; } result.merge(ResourceChangeChecker.checkFilesToBeChanged(changedFiles, new SubProgressMonitor(pm, 1))); if (fRoot == null) { fRoot = RefactoringASTParser.parseWithASTProvider(fCUnit, true, new SubProgressMonitor(pm, 99)); } fImportRewriter = CodeStyleConfiguration.createImportRewrite(fRoot, true); fAST = fRoot.getAST(); fRoot.accept(createVisitor()); fSelectionStart = fAnalyzer.getSelection().getOffset(); fSelectionLength = fAnalyzer.getSelection().getLength(); result.merge(fAnalyzer.checkInitialConditions(fImportRewriter)); if (result.hasFatalError()) { return result; } if (fVisibility == -1) { setVisibility(Modifier.PRIVATE); } initializeParameterInfos(); initializeUsedNames(); initializeDuplicates(); initializeDestinations(); return result; }
Example #11
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException { pm.beginTask(NO_NAME, 12); pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_checking_preconditions); RefactoringStatus result = new RefactoringStatus(); fRewriter = ASTRewrite.create(fRoot.getAST()); fChangeManager.clear(); boolean usingLocalGetter = isUsingLocalGetter(); boolean usingLocalSetter = isUsingLocalSetter(); result.merge(checkMethodNames(usingLocalGetter, usingLocalSetter)); pm.worked(1); if (result.hasFatalError()) { return result; } pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_searching_for_cunits); final SubProgressMonitor subPm = new SubProgressMonitor(pm, 5); ICompilationUnit[] affectedCUs = RefactoringSearchEngine.findAffectedCompilationUnits(SearchPattern.createPattern(fField, IJavaSearchConstants.REFERENCES), RefactoringScopeFactory.create(fField, fConsiderVisibility), subPm, result, true); checkInHierarchy(result, usingLocalGetter, usingLocalSetter); if (result.hasFatalError()) { return result; } pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_analyzing); IProgressMonitor sub = new SubProgressMonitor(pm, 5); sub.beginTask(NO_NAME, affectedCUs.length); IVariableBinding fieldIdentifier = fFieldDeclaration.resolveBinding(); ITypeBinding declaringClass = ASTNodes.getParent(fFieldDeclaration, AbstractTypeDeclaration.class).resolveBinding(); List<TextEditGroup> ownerDescriptions = new ArrayList<>(); ICompilationUnit owner = fField.getCompilationUnit(); fImportRewrite = StubUtility.createImportRewrite(fRoot, true); for (int i = 0; i < affectedCUs.length; i++) { ICompilationUnit unit = affectedCUs[i]; sub.subTask(BasicElementLabels.getFileName(unit)); CompilationUnit root = null; ASTRewrite rewriter = null; ImportRewrite importRewrite; List<TextEditGroup> descriptions; if (owner.equals(unit)) { root = fRoot; rewriter = fRewriter; importRewrite = fImportRewrite; descriptions = ownerDescriptions; } else { root = new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(unit, true); rewriter = ASTRewrite.create(root.getAST()); descriptions = new ArrayList<>(); importRewrite = StubUtility.createImportRewrite(root, true); } checkCompileErrors(result, root, unit); AccessAnalyzer analyzer = new AccessAnalyzer(this, unit, fieldIdentifier, declaringClass, rewriter, importRewrite); root.accept(analyzer); result.merge(analyzer.getStatus()); if (!fSetterMustReturnValue) { fSetterMustReturnValue= analyzer.getSetterMustReturnValue(); } if (result.hasFatalError()) { fChangeManager.clear(); return result; } descriptions.addAll(analyzer.getGroupDescriptions()); if (!owner.equals(unit)) { createEdits(unit, rewriter, descriptions, importRewrite); } sub.worked(1); if (pm.isCanceled()) { throw new OperationCanceledException(); } } ownerDescriptions.addAll(addGetterSetterChanges(fRoot, fRewriter, owner.findRecommendedLineSeparator(), usingLocalSetter, usingLocalGetter)); createEdits(owner, fRewriter, ownerDescriptions, fImportRewrite); sub.done(); IFile[] filesToBeModified = ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits()); result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext(), pm)); if (result.hasFatalError()) { return result; } ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1)); return result; }
Example #12
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 #13
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; }
Example #14
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException { pm.beginTask(NO_NAME, 12); pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_checking_preconditions); RefactoringStatus result= new RefactoringStatus(); fRewriter= ASTRewrite.create(fRoot.getAST()); fChangeManager.clear(); boolean usingLocalGetter=isUsingLocalGetter(); boolean usingLocalSetter=isUsingLocalSetter(); result.merge(checkMethodNames(usingLocalGetter,usingLocalSetter)); pm.worked(1); if (result.hasFatalError()) return result; pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_searching_for_cunits); final SubProgressMonitor subPm= new SubProgressMonitor(pm, 5); ICompilationUnit[] affectedCUs= RefactoringSearchEngine.findAffectedCompilationUnits( SearchPattern.createPattern(fField, IJavaSearchConstants.REFERENCES), RefactoringScopeFactory.create(fField, fConsiderVisibility), subPm, result, true); checkInHierarchy(result, usingLocalGetter, usingLocalSetter); if (result.hasFatalError()) return result; pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_analyzing); IProgressMonitor sub= new SubProgressMonitor(pm, 5); sub.beginTask(NO_NAME, affectedCUs.length); IVariableBinding fieldIdentifier= fFieldDeclaration.resolveBinding(); ITypeBinding declaringClass= ((AbstractTypeDeclaration)ASTNodes.getParent(fFieldDeclaration, AbstractTypeDeclaration.class)).resolveBinding(); List<TextEditGroup> ownerDescriptions= new ArrayList<TextEditGroup>(); ICompilationUnit owner= fField.getCompilationUnit(); fImportRewrite= StubUtility.createImportRewrite(fRoot, true); for (int i= 0; i < affectedCUs.length; i++) { ICompilationUnit unit= affectedCUs[i]; sub.subTask(BasicElementLabels.getFileName(unit)); CompilationUnit root= null; ASTRewrite rewriter= null; ImportRewrite importRewrite; List<TextEditGroup> descriptions; if (owner.equals(unit)) { root= fRoot; rewriter= fRewriter; importRewrite= fImportRewrite; descriptions= ownerDescriptions; } else { root= new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(unit, true); rewriter= ASTRewrite.create(root.getAST()); descriptions= new ArrayList<TextEditGroup>(); importRewrite= StubUtility.createImportRewrite(root, true); } checkCompileErrors(result, root, unit); AccessAnalyzer analyzer= new AccessAnalyzer(this, unit, fieldIdentifier, declaringClass, rewriter, importRewrite); root.accept(analyzer); result.merge(analyzer.getStatus()); if (!fSetterMustReturnValue) fSetterMustReturnValue= analyzer.getSetterMustReturnValue(); if (result.hasFatalError()) { fChangeManager.clear(); return result; } descriptions.addAll(analyzer.getGroupDescriptions()); if (!owner.equals(unit)) createEdits(unit, rewriter, descriptions, importRewrite); sub.worked(1); if (pm.isCanceled()) throw new OperationCanceledException(); } ownerDescriptions.addAll(addGetterSetterChanges(fRoot, fRewriter, owner.findRecommendedLineSeparator(),usingLocalSetter, usingLocalGetter)); createEdits(owner, fRewriter, ownerDescriptions, fImportRewrite); sub.done(); IFile[] filesToBeModified= ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits()); result.merge(Checks.validateModifiesFiles(filesToBeModified, getValidationContext())); if (result.hasFatalError()) return result; ResourceChangeChecker.checkFilesToBeChanged(filesToBeModified, new SubProgressMonitor(pm, 1)); return result; }