org.eclipse.ltk.core.refactoring.TextFileChange Java Examples
The following examples show how to use
org.eclipse.ltk.core.refactoring.TextFileChange.
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: DeleteChangeCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException { try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu); TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true)); TextChange textChange= manager.get(cu); if (textChange instanceof TextFileChange) { TextFileChange tfc= (TextFileChange) textChange; tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE); } String message= RefactoringCoreMessages.DeleteChangeCreator_1; TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits); return textChange; } finally { RefactoringFileBuffers.release(cu); } }
Example #2
Source File: JsniReferenceChangeTest.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public void testPerform() throws CoreException { // Create a dummy change for updating references in RefactorTest.java // to the class R to its new name 'RRR' ICompilationUnit cu = refactorTestClass.getCompilationUnit(); GWTRefactoringSupport support = new DummyRefactoringSupport(); JsniReferenceChangeFactory factory = new JsniReferenceChangeFactory(support); IJsniReferenceChange jsniChange = factory.createChange(cu); // Add one dummy edit to the change TextEdit oldRootEdit = new MultiTextEdit(); oldRootEdit.addChild(new ReplaceEdit(252, 0, "")); ((TextFileChange)jsniChange).setEdit(oldRootEdit); // Perform the change (this should replace the original edits with new ones // with the correct offsets). ((TextFileChange)jsniChange).perform(new NullProgressMonitor()); // Verify that the change still has one edit TextEdit newRootEdit = ((TextFileChange)jsniChange).getEdit(); assertEquals(1, newRootEdit.getChildrenSize()); }
Example #3
Source File: JsniTypeReferenceChangeFactoryTest.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public void testCreateChange() { JsniTypeReferenceChangeFactory factory = new JsniTypeReferenceChangeFactory( null); // This file doesn't need to actually exist in the workspace IFile file = Util.getWorkspaceRoot().getFile( new Path("/Project/src/com/google/gwt/GWT.java")); // Create a change and verify its properties TextFileChange change = factory.createChange(file); assertEquals(file, change.getFile()); assertTrue(change instanceof IJsniTypeReferenceChange); IJsniTypeReferenceChange jsniRefChange = (IJsniTypeReferenceChange) change; ICompilationUnit cu = (ICompilationUnit) JavaCore.create(file); assertEquals(jsniRefChange.getCompilationUnit(), cu); }
Example #4
Source File: GetterSetterCorrectionSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public TextFileChange getChange(IFile file) throws CoreException { final SelfEncapsulateFieldRefactoring refactoring= new SelfEncapsulateFieldRefactoring(fField); refactoring.setVisibility(Flags.AccPublic); refactoring.setConsiderVisibility(false);//private field references are just searched in local file refactoring.checkInitialConditions(new NullProgressMonitor()); refactoring.checkFinalConditions(new NullProgressMonitor()); Change createdChange= refactoring.createChange(new NullProgressMonitor()); if (createdChange instanceof CompositeChange) { Change[] children= ((CompositeChange) createdChange).getChildren(); for (int i= 0; i < children.length; i++) { Change curr= children[i]; if (curr instanceof TextFileChange && ((TextFileChange) curr).getFile().equals(file)) { return (TextFileChange) curr; } } } return null; }
Example #5
Source File: JsniReferenceChangeFactoryTest.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public void testCreateChange() { JsniReferenceChangeFactory factory = new JsniReferenceChangeFactory(null); // This file doesn't need to actually exist in the workspace IFile file = Util.getWorkspaceRoot().getFile( new Path("/Project/src/com/google/gwt/GWT.java")); // Create a change and verify its properties TextFileChange change = factory.createChange(file); assertEquals(file, change.getFile()); assertTrue(change instanceof IJsniReferenceChange); IJsniReferenceChange jsniRefChange = (IJsniReferenceChange) change; ICompilationUnit cu = (ICompilationUnit) JavaCore.create(file); assertEquals(jsniRefChange.getCompilationUnit(), cu); }
Example #6
Source File: ExtractMethodRefactoring.java From JDeodorant with MIT License | 6 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { try { pm.beginTask("Creating change...", 1); final Collection<TextFileChange> changes = new ArrayList<TextFileChange>(); changes.add(compilationUnitChange); CompositeChange change = new CompositeChange(getName(), changes.toArray(new Change[changes.size()])) { @Override public ChangeDescriptor getDescriptor() { ICompilationUnit sourceICompilationUnit = (ICompilationUnit)sourceCompilationUnit.getJavaElement(); String project = sourceICompilationUnit.getJavaProject().getElementName(); String description = MessageFormat.format("Extract from method ''{0}''", new Object[] { sourceMethodDeclaration.getName().getIdentifier()}); String comment = MessageFormat.format("Extract from method ''{0}'' variable ''{1}''", new Object[] { sourceMethodDeclaration.getName().getIdentifier(), slice.getLocalVariableCriterion().toString()}); return new RefactoringChangeDescriptor(new ExtractMethodRefactoringDescriptor(project, description, comment, sourceCompilationUnit, slice)); } }; return change; } finally { pm.done(); } }
Example #7
Source File: ChangeUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Destructively clones a {@link CompilationUnitChange} where the cloned * change will have a different compilation unit. This does not update text * regions or anything more than setting the change properties and moving text * edits from the old to new change. * * @param originalChange the original change, this change's internal state * will likely become invalid (its text edits will be moved to the * new change) * @param cu the compilation unit to be used for the new * {@link CompilationUnitChange} * @return the cloned {@link CompilationUnitChange} */ public static CompilationUnitChange cloneCompilationUnitChangeWithDifferentCu( TextFileChange originalChange, ICompilationUnit cu) { CompilationUnitChange newChange = new CompilationUnitChange( originalChange.getName(), cu); newChange.setEdit(originalChange.getEdit()); newChange.setEnabledShallow(originalChange.isEnabled()); newChange.setKeepPreviewEdits(originalChange.getKeepPreviewEdits()); newChange.setSaveMode(originalChange.getSaveMode()); newChange.setTextType(originalChange.getTextType()); // Copy the changes over TextEditUtilities.moveTextEditGroupsIntoChange( originalChange.getChangeGroups(), newChange); return newChange; }
Example #8
Source File: QualifiedNameSearchResult.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public Change getSingleChange(IFile[] alreadyTouchedFiles) { Collection<TextChange> values= fChanges.values(); if (values.size() == 0) { return null; } CompositeChange result= new CompositeChange(RefactoringCoreMessages.QualifiedNameSearchResult_change_name); result.markAsSynthetic(); List<IFile> files= Arrays.asList(alreadyTouchedFiles); for (Iterator<TextChange> iter= values.iterator(); iter.hasNext();) { TextFileChange change= (TextFileChange)iter.next(); if (!files.contains(change.getFile())) { result.add(change); } } return result; }
Example #9
Source File: QualifiedNameSearchResult.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public Change getSingleChange(IFile[] alreadyTouchedFiles) { Collection<TextChange> values= fChanges.values(); if (values.size() == 0) return null; CompositeChange result= new CompositeChange(RefactoringCoreMessages.QualifiedNameSearchResult_change_name); result.markAsSynthetic(); List<IFile> files= Arrays.asList(alreadyTouchedFiles); for (Iterator<TextChange> iter= values.iterator(); iter.hasNext();) { TextFileChange change= (TextFileChange)iter.next(); if (!files.contains(change.getFile())) { result.add(change); } } return result; }
Example #10
Source File: RegionUpdaterChange.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Creates a region updater change. * * @param compilationUnitChange the compilation unit change whose text edits * will be updated * @param regionUpdaters a list of updaters for text edits in the compilation * unit change * @param referenceUpdater aids in finding the corresponding AST nodes for * those that have been refactored (e.g. if FooService was renamed to * BarService, this instance would pass that knowledge) */ public RegionUpdaterChange(String name, TextFileChange compilationUnitChange, List<RegionUpdater> regionUpdaters, ReferenceUpdater referenceUpdater) { super(name); assert compilationUnitChange.getModifiedElement() instanceof ICompilationUnit; this.compilationUnitChange = compilationUnitChange; this.regionUpdaters = regionUpdaters; this.referenceUpdater = referenceUpdater; // Do not show this in previews markAsSynthetic(); // Wrap the original compilation unit add(compilationUnitChange); }
Example #11
Source File: NLSPropertyFileModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static Change removeKeys(IPath propertyFilePath, List<String> keys) throws CoreException { String name= Messages.format(NLSMessages.NLSPropertyFileModifier_remove_from_property_file, BasicElementLabels.getPathLabel(propertyFilePath, false)); TextChange textChange= new TextFileChange(name, getPropertyFile(propertyFilePath)); textChange.setTextType("properties"); //$NON-NLS-1$ PropertyFileDocumentModel model= new PropertyFileDocumentModel(textChange.getCurrentDocument(new NullProgressMonitor())); for (Iterator<String> iterator= keys.iterator(); iterator.hasNext();) { String key= iterator.next(); TextEdit edit= model.remove(key); if (edit != null) { TextChangeCompatibility.addTextEdit(textChange, Messages.format(NLSMessages.NLSPropertyFileModifier_remove_entry, BasicElementLabels.getJavaElementName(key)), edit); } } return textChange; }
Example #12
Source File: DeleteChangeCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static TextChange addTextEditFromRewrite(TextChangeManager manager, ICompilationUnit cu, ASTRewrite rewrite) throws CoreException { try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(cu); TextEdit resultingEdits= rewrite.rewriteAST(buffer.getDocument(), cu.getJavaProject().getOptions(true)); TextChange textChange= manager.get(cu); if (textChange instanceof TextFileChange) { TextFileChange tfc= (TextFileChange) textChange; tfc.setSaveMode(TextFileChange.KEEP_SAVE_STATE); } String message= RefactoringCoreMessages.DeleteChangeCreator_1; TextChangeCompatibility.addTextEdit(textChange, message, resultingEdits); return textChange; } finally { RefactoringFileBuffers.release(cu); } }
Example #13
Source File: DeletePackageFragmentRootChange.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected Change doDelete(IProgressMonitor pm) throws CoreException { if (! confirmDeleteIfReferenced()) return new NullChange(); int resourceUpdateFlags= IResource.KEEP_HISTORY; int jCoreUpdateFlags= IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH | IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH; pm.beginTask("", 2); //$NON-NLS-1$ IPackageFragmentRoot root= getRoot(); IResource rootResource= root.getResource(); CompositeChange result= new CompositeChange(getName()); ResourceDescription rootDescription = ResourceDescription.fromResource(rootResource); IJavaProject[] referencingProjects= JavaElementUtil.getReferencingProjects(root); HashMap<IFile, String> classpathFilesContents= new HashMap<IFile, String>(); for (int i= 0; i < referencingProjects.length; i++) { IJavaProject javaProject= referencingProjects[i]; IFile classpathFile= javaProject.getProject().getFile(".classpath"); //$NON-NLS-1$ if (classpathFile.exists()) { classpathFilesContents.put(classpathFile, getFileContents(classpathFile)); } } root.delete(resourceUpdateFlags, jCoreUpdateFlags, new SubProgressMonitor(pm, 1)); rootDescription.recordStateFromHistory(rootResource, new SubProgressMonitor(pm, 1)); for (Iterator<Entry<IFile, String>> iterator= classpathFilesContents.entrySet().iterator(); iterator.hasNext();) { Entry<IFile, String> entry= iterator.next(); IFile file= entry.getKey(); String contents= entry.getValue(); //Restore time stamps? This should probably be some sort of UndoTextFileChange. TextFileChange classpathUndo= new TextFileChange(Messages.format(RefactoringCoreMessages.DeletePackageFragmentRootChange_restore_file, BasicElementLabels.getPathLabel(file.getFullPath(), true)), file); classpathUndo.setEdit(new ReplaceEdit(0, getFileLength(file), contents)); result.add(classpathUndo); } result.add(new UndoDeleteResourceChange(rootDescription)); pm.done(); return result; }
Example #14
Source File: RefactoringCorrectionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected TextChange createTextChange() throws CoreException { init(fRefactoring); fRefactoringStatus= fRefactoring.checkFinalConditions(new NullProgressMonitor()); if (fRefactoringStatus.hasFatalError()) { TextFileChange dummyChange= new TextFileChange("fatal error", (IFile) getCompilationUnit().getResource()); //$NON-NLS-1$ dummyChange.setEdit(new InsertEdit(0, "")); //$NON-NLS-1$ return dummyChange; } return (TextChange) fRefactoring.createChange(new NullProgressMonitor()); }
Example #15
Source File: AddResourcesToClientBundleAction.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public void run(IProgressMonitor monitor) throws CoreException { ICompilationUnit icu = clientBundle.getCompilationUnit(); CompilationUnit cu = JavaASTUtils.parseCompilationUnit(icu); ImportRewrite importRewrite = StubUtility.createImportRewrite(cu, true); // Find the target type declaration TypeDeclaration typeDecl = JavaASTUtils.findTypeDeclaration(cu, clientBundle.getFullyQualifiedName()); if (typeDecl == null) { throw new CoreException( StatusUtilities.newErrorStatus("Missing ClientBundle type " + clientBundle.getFullyQualifiedName(), GWTPlugin.PLUGIN_ID)); } // We need to rewrite the AST of the ClientBundle type declaration ASTRewrite astRewrite = ASTRewrite.create(cu.getAST()); ChildListPropertyDescriptor property = ASTNodes.getBodyDeclarationsProperty(typeDecl); ListRewrite listRewriter = astRewrite.getListRewrite(typeDecl, property); // Add the new resource methods boolean addComments = StubUtility.doAddComments(icu.getJavaProject()); for (ClientBundleResource resource : resources) { listRewriter.insertLast(resource.createMethodDeclaration(clientBundle, astRewrite, importRewrite, addComments), null); } // Create the edit to add the methods and update the imports TextEdit rootEdit = new MultiTextEdit(); rootEdit.addChild(astRewrite.rewriteAST()); rootEdit.addChild(importRewrite.rewriteImports(null)); // Apply the change to the compilation unit CompilationUnitChange cuChange = new CompilationUnitChange( "Update ClientBundle", icu); cuChange.setSaveMode(TextFileChange.KEEP_SAVE_STATE); cuChange.setEdit(rootEdit); cuChange.perform(new NullProgressMonitor()); }
Example #16
Source File: PasteAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public Change createChange(IProgressMonitor pm) throws CoreException { ASTParser p= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); p.setSource(getDestinationCu()); CompilationUnit cuNode= (CompilationUnit) p.createAST(pm); ASTRewrite rewrite= ASTRewrite.create(cuNode.getAST()); TypedSource source= null; for (int i= fSources.length - 1; i >= 0; i--) { source= fSources[i]; final ASTNode destination= getDestinationNodeForSourceElement(fDestination, source.getType(), cuNode); if (destination != null) { if (destination instanceof CompilationUnit) insertToCu(rewrite, createNewNodeToInsertToCu(source, rewrite), (CompilationUnit) destination); else if (destination instanceof AbstractTypeDeclaration) insertToType(rewrite, createNewNodeToInsertToType(source, rewrite), (AbstractTypeDeclaration) destination); } } final CompilationUnitChange result= new CompilationUnitChange(ReorgMessages.PasteAction_change_name, getDestinationCu()); try { ITextFileBuffer buffer= RefactoringFileBuffers.acquire(getDestinationCu()); TextEdit rootEdit= rewrite.rewriteAST(buffer.getDocument(), fDestination.getJavaProject().getOptions(true)); if (getDestinationCu().isWorkingCopy()) result.setSaveMode(TextFileChange.LEAVE_DIRTY); TextChangeCompatibility.addTextEdit(result, ReorgMessages.PasteAction_edit_name, rootEdit); } finally { RefactoringFileBuffers.release(getDestinationCu()); } return result; }
Example #17
Source File: CleanUpRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Change[] getResult() { Change[] result= new Change[fSolutions.size()]; int i=0; for (Iterator<Entry<ICompilationUnit, List<CleanUpChange>>> iterator= fSolutions.entrySet().iterator(); iterator.hasNext();) { Entry<ICompilationUnit, List<CleanUpChange>> entry= iterator.next(); List<CleanUpChange> changes= entry.getValue(); ICompilationUnit unit= entry.getKey(); int saveMode; if (fLeaveFilesDirty) { saveMode= TextFileChange.LEAVE_DIRTY; } else { saveMode= TextFileChange.KEEP_SAVE_STATE; } if (changes.size() == 1) { CleanUpChange change= changes.get(0); change.setSaveMode(saveMode); result[i]= change; } else { MultiStateCompilationUnitChange mscuc= new MultiStateCompilationUnitChange(getChangeName(unit), unit); for (int j= 0; j < changes.size(); j++) { mscuc.addChange(createGroupFreeChange(changes.get(j))); } mscuc.setSaveMode(saveMode); result[i]= mscuc; } i++; } return result; }
Example #18
Source File: DefaultChangeFactoryTest.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
public void testCreateChange() { DefaultChangeFactory factory = new DefaultChangeFactory(); // This file doesn't need to actually exist in the workspace IFile file = Util.getWorkspaceRoot().getFile( new Path("/Project/src/com/google/gwt/GWT.java")); // Create a text file change and verify its properties TextFileChange change = factory.createChange(file); assertEquals(file, change.getFile()); assertEquals(file.getName(), change.getName()); }
Example #19
Source File: RegionUpdaterChangeWeavingVisitor.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
private void wrapAndReplaceChange(Change change, final List<RegionUpdater> regionUpdaters) { ChangeUtilities.replaceChange(change, new ReplacementChangeFactory() { public Change createChange(Change originalChange) { Change wrappedChange = new RegionUpdaterChange("", (TextFileChange) originalChange, regionUpdaters, referenceUpdater); return wrappedChange; } }); }
Example #20
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected static CompilationUnitChange createCompilationUnitChange(CompilationUnitRewrite rewrite) throws CoreException { CompilationUnitChange change= rewrite.createChange(true); if (change != null) change.setSaveMode(TextFileChange.KEEP_SAVE_STATE); return change; }
Example #21
Source File: FixCorrectionProposal.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected TextChange createTextChange() throws CoreException { CompilationUnitChange createChange= fFix.createChange(null); createChange.setSaveMode(TextFileChange.LEAVE_DIRTY); if (fFix instanceof ILinkedFix) { setLinkedProposalModel(((ILinkedFix) fFix).getLinkedPositions()); } return createChange; }
Example #22
Source File: RenameRefactoringProcessor.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
/** * @return true if was successfully registered, false if it is overridden by the delete change */ public boolean registerTextFileChange(File file, CompositeChange parentChange, TextFileChange textFileChange) { if (!isFileWillBeDeleted(file)) { file2TextFileChange.put(file, textFileChange); registerParent(parentChange, textFileChange); return true; } return false; }
Example #23
Source File: FixCorrectionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override protected TextChange createTextChange() throws CoreException { CompilationUnitChange createChange = fFix.createChange(null); createChange.setSaveMode(TextFileChange.LEAVE_DIRTY); // if (fFix instanceof ILinkedFix) { // setLinkedProposalModel(((ILinkedFix) fFix).getLinkedPositions()); // } return createChange; }
Example #24
Source File: RefactoringCorrectionProposal.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override protected TextChange createTextChange() throws CoreException { init(fRefactoring); fRefactoringStatus = fRefactoring.checkFinalConditions(new NullProgressMonitor()); if (fRefactoringStatus.hasFatalError()) { TextFileChange dummyChange = new TextFileChange("fatal error", (IFile) getCompilationUnit().getResource()); //$NON-NLS-1$ dummyChange.setEdit(new InsertEdit(0, "")); //$NON-NLS-1$ return dummyChange; } return (TextChange) fRefactoring.createChange(new NullProgressMonitor()); }
Example #25
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
protected static CompilationUnitChange createCompilationUnitChange(CompilationUnitRewrite rewrite) throws CoreException { CompilationUnitChange change= rewrite.createChange(true); if (change != null) { change.setSaveMode(TextFileChange.KEEP_SAVE_STATE); } return change; }
Example #26
Source File: RefactoringDocumentProviderTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Test public void testFileDocument() throws Exception { IRefactoringDocument document = createAndCheckDocument(testFile); assertTrue(document instanceof FileDocument); assertEquals(testFile, ((FileDocument) document).getFile()); assertEquals(TEST_FILE_CONTENT, document.getOriginalContents()); Change change = document.createChange(CHANGE_NAME, textEdit); assertTrue(change instanceof TextFileChange); assertEquals(CHANGE_NAME, change.getName()); Change undoChange = checkEdit(document, textEdit); assertNotNull(undoChange); }
Example #27
Source File: TextChangeCombiner.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected Object getKey(TextChange change) { if (change instanceof CompilationUnitChange) return ((CompilationUnitChange) change).getCompilationUnit(); else if (change instanceof TextFileChange) return ((TextFileChange) change).getFile(); else if (change instanceof EditorDocumentChange) { return ((EditorDocumentChange) change).getEditor(); } else { LOG.error("Unhandled TextChange type: " + change.getClass().getName()); } return null; }
Example #28
Source File: DefaultRefactoringDocumentProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Change createChange(String name, TextEdit textEdit) { TextFileChange textFileChange = new TextFileChange(name, redirectedFile); textFileChange.setSaveMode(TextFileChange.FORCE_SAVE); textFileChange.setEdit(textEdit); textFileChange.setTextType(getURI().fileExtension()); return textFileChange; }
Example #29
Source File: DefaultRefactoringDocumentProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public Change createChange(String name, TextEdit textEdit) { TextFileChange textFileChange = new TextFileChange(name, file); textFileChange.setSaveMode(TextFileChange.FORCE_SAVE); textFileChange.setEdit(textEdit); textFileChange.setTextType(getURI().fileExtension()); return textFileChange; }
Example #30
Source File: ChangeConverter.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void _handleReplacements(ITextDocumentChange change) { if (!change.getReplacements().isEmpty()) { IFile file = resourceUriConverter.toFile(change.getOldURI()); if (!canWrite(file)) { issues.add(RefactoringIssueAcceptor.Severity.FATAL, "Affected file '" + file.getFullPath() + "' is read-only"); } checkDerived(file); List<ReplaceEdit> textEdits = change.getReplacements().stream().map(replacement -> { return new ReplaceEdit(replacement.getOffset(), replacement.getLength(), replacement.getReplacementText()); }).collect(Collectors.toList()); MultiTextEdit textEdit = new MultiTextEdit(); textEdit.addChildren(textEdits.toArray(new TextEdit[textEdits.size()])); ITextEditor openEditor = findOpenEditor(file); final TextChange ltkChange; if (openEditor == null) { TextFileChange textFileChange = new TextFileChange(change.getOldURI().lastSegment(), file); textFileChange.setSaveMode(TextFileChange.FORCE_SAVE); ltkChange = textFileChange; } else { ltkChange = new EditorDocumentChange(currentChange.getName(), openEditor, false); } ltkChange.setEdit(textEdit); ltkChange.setTextType(change.getOldURI().fileExtension()); addChange(ltkChange); } }