Java Code Examples for org.eclipse.ltk.core.refactoring.TextChange#setEdit()
The following examples show how to use
org.eclipse.ltk.core.refactoring.TextChange#setEdit() .
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: AccessorClassModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static Change addFields(ICompilationUnit cu, List<String> fields) throws CoreException { AccessorClassModifier sourceModification= new AccessorClassModifier(cu); String message= Messages.format(NLSMessages.AccessorClassModifier_add_fields_to_accessor, BasicElementLabels.getFileName(cu)); TextChange change= new CompilationUnitChange(message, cu); MultiTextEdit multiTextEdit= new MultiTextEdit(); change.setEdit(multiTextEdit); for (int i= 0; i < fields.size(); i++) { String field= fields.get(i); NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null); sourceModification.addKey(substitution, change); } if (change.getChangeGroups().length == 0) return null; change.addEdit(sourceModification.getTextEdit()); return change; }
Example 2
Source File: AccessorClassModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static Change removeFields(ICompilationUnit cu, List<String> fields) throws CoreException { AccessorClassModifier sourceModification= new AccessorClassModifier(cu); String message= Messages.format(NLSMessages.AccessorClassModifier_remove_fields_from_accessor, BasicElementLabels.getFileName(cu)); TextChange change= new CompilationUnitChange(message, cu); MultiTextEdit multiTextEdit= new MultiTextEdit(); change.setEdit(multiTextEdit); for (int i= 0; i < fields.size(); i++) { String field= fields.get(i); NLSSubstitution substitution= new NLSSubstitution(NLSSubstitution.EXTERNALIZED, field, null, null, null); sourceModification.removeKey(substitution, change); } if (change.getChangeGroups().length == 0) return null; change.addEdit(sourceModification.getTextEdit()); return change; }
Example 3
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); } }
Example 4
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void createEdits(ICompilationUnit unit, ASTRewrite rewriter, List<TextEditGroup> groups, ImportRewrite importRewrite) throws CoreException { TextChange change = fChangeManager.get(unit); MultiTextEdit root = new MultiTextEdit(); change.setEdit(root); root.addChild(importRewrite.rewriteImports(null)); root.addChild(rewriter.rewriteAST()); for (Iterator<TextEditGroup> iter = groups.iterator(); iter.hasNext();) { change.addTextEditGroup(iter.next()); } }
Example 5
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void createEdits(ICompilationUnit unit, ASTRewrite rewriter, List<TextEditGroup> groups, ImportRewrite importRewrite) throws CoreException { TextChange change= fChangeManager.get(unit); MultiTextEdit root= new MultiTextEdit(); change.setEdit(root); root.addChild(importRewrite.rewriteImports(null)); root.addChild(rewriter.rewriteAST()); for (Iterator<TextEditGroup> iter= groups.iterator(); iter.hasNext();) { change.addTextEditGroup(iter.next()); } }
Example 6
Source File: NLSSourceModifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public static Change create(ICompilationUnit cu, NLSSubstitution[] subs, String substitutionPattern, IPackageFragment accessorPackage, String accessorClassName, boolean isEclipseNLS) throws CoreException { NLSSourceModifier sourceModification= new NLSSourceModifier(substitutionPattern, isEclipseNLS); String message= Messages.format(NLSMessages.NLSSourceModifier_change_description, BasicElementLabels.getFileName(cu)); TextChange change= new CompilationUnitChange(message, cu); MultiTextEdit multiTextEdit= new MultiTextEdit(); change.setEdit(multiTextEdit); boolean createImportForAccessor= true; for (int i= 0; i < subs.length; i++) { NLSSubstitution substitution= subs[i]; int newState= substitution.getState(); if (newState == NLSSubstitution.EXTERNALIZED && createImportForAccessor) { accessorClassName= sourceModification.createImportForAccessor(multiTextEdit, accessorClassName, accessorPackage, cu); createImportForAccessor= false; } if (substitution.hasStateChanged()) { if (newState == NLSSubstitution.EXTERNALIZED) { if (substitution.getInitialState() == NLSSubstitution.INTERNALIZED) { sourceModification.addNLS(substitution, change, accessorClassName); } else if (substitution.getInitialState() == NLSSubstitution.IGNORED) { sourceModification.addAccessor(substitution, change, accessorClassName); } } else if (newState == NLSSubstitution.INTERNALIZED) { if (substitution.getInitialState() == NLSSubstitution.IGNORED) { sourceModification.deleteTag(substitution, change); if (substitution.isValueRename()) { sourceModification.replaceValue(substitution, change); } } else if (substitution.getInitialState() == NLSSubstitution.EXTERNALIZED) { sourceModification.deleteAccessor(substitution, change, cu); if (!isEclipseNLS) sourceModification.deleteTag(substitution, change); } } else if (newState == NLSSubstitution.IGNORED) { if (substitution.getInitialState() == NLSSubstitution.INTERNALIZED) { sourceModification.addNLS(substitution, change, null); if (substitution.isValueRename()) { sourceModification.replaceValue(substitution, change); } } else { if (substitution.getInitialState() == NLSSubstitution.EXTERNALIZED) { sourceModification.deleteAccessor(substitution, change, cu); } } } } else { if (newState == NLSSubstitution.EXTERNALIZED) { if (substitution.isKeyRename()) { sourceModification.replaceKey(substitution, change); } if (substitution.isAccessorRename()) { sourceModification.replaceAccessor(substitution, change); } } else { if (substitution.isValueRename()) { sourceModification.replaceValue(substitution, change); } } } } return change; }