private static void convertTextChange(WorkspaceEdit root, IJavaElement element, TextChange textChange) { TextEdit textEdits = textChange.getEdit(); if (textEdits == null) { return; } ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); convertTextEdit(root, compilationUnit, textEdits); }
public static void addTextEdit(TextChange change, String name, TextEdit edit) { Assert.isNotNull(change); Assert.isNotNull(name); Assert.isNotNull(edit); TextEdit root= change.getEdit(); if (root == null) { root= new MultiTextEdit(); change.setEdit(root); } insert(root, edit); change.addTextEditGroup(new TextEditGroup(name, edit)); }
public static void addTextEdit(TextChange change, String name, TextEdit edit) throws MalformedTreeException { Assert.isNotNull(change); Assert.isNotNull(name); Assert.isNotNull(edit); TextEdit root= change.getEdit(); if (root == null) { root= new MultiTextEdit(); change.setEdit(root); } insert(root, edit); change.addTextEditGroup(new TextEditGroup(name, edit)); }
/** * Creates the text change for this proposal. * This method is only called once and only when no text change has been passed in * {see #CUCorrectionProposal(String, ICompilationUnit, TextChange, int, Image)}. * * @return the created text change * @throws CoreException if the creation of the text change failed */ public TextChange createTextChange() throws CoreException { TextChange change = getNewChange(); // initialize text change IDocument document= change.getCurrentDocument(new NullProgressMonitor()); addEdits(document, change.getEdit()); return change; }
/** * Creates the text change for this proposal. * This method is only called once and only when no text change has been passed in * {@link #CUCorrectionProposal(String, ICompilationUnit, TextChange, int, Image)}. * * @return the created text change * @throws CoreException if the creation of the text change failed */ protected TextChange createTextChange() throws CoreException { TextChange change = fProposalCore.getNewChange(); // initialize text change IDocument document= change.getCurrentDocument(new NullProgressMonitor()); addEdits(document, change.getEdit()); return change; }
public static void addTextEdit(TextChange change, String name, TextEdit edit) throws MalformedTreeException { Assert.isNotNull(change); Assert.isNotNull(name); Assert.isNotNull(edit); TextEdit root= change.getEdit(); if (root == null) { root= new MultiTextEdit(); change.setEdit(root); } insert(root, edit); change.addTextEditGroup(new TextEditGroup(name, edit)); }
public static void addTextEdit(TextChange change, String name, TextEdit edit) throws MalformedTreeException { Assert.isNotNull(change); Assert.isNotNull(name); Assert.isNotNull(edit); TextEdit root= change.getEdit(); if (root == null) { root= new MultiTextEdit(); change.setEdit(root); } insert(root, edit); change.addTextEditGroup(new TextEditGroup(name, edit)); }
public static void addTextEdit(TextChange change, String name, TextEdit[] edits) { Assert.isNotNull(change); Assert.isNotNull(name); Assert.isNotNull(edits); TextEdit root= change.getEdit(); if (root == null) { root= new MultiTextEdit(); change.setEdit(root); } for (int i= 0; i < edits.length; i++) { insert(root, edits[i]); } change.addTextEditGroup(new TextEditGroup(name, edits)); }
private TextEditProcessor createTextEditProcessor(ComposableBufferChange change, IDocument document, int flags, boolean preview) { List<TextEdit> excludes= new ArrayList<>(0); for (final Iterator<TextEditBasedChangeGroup> iterator= change.getGroups().iterator(); iterator.hasNext();) { TextEditBasedChangeGroup group= iterator.next(); if (!group.isEnabled()) excludes.addAll(Arrays.asList(group.getTextEdits())); } if (preview) { fCopier= new TextEditCopier(change.getEdit()); TextEdit copiedEdit= fCopier.perform(); boolean keep= getKeepPreviewEdits(); if (keep) flags= flags | TextEdit.UPDATE_REGIONS; LocalTextEditProcessor result= new LocalTextEditProcessor(document, copiedEdit, flags); result.setExcludes(mapEdits(excludes.toArray(new TextEdit[excludes.size()]), fCopier)); if (!keep) fCopier= null; return result; } else { LocalTextEditProcessor result= new LocalTextEditProcessor(document, change.getEdit(), flags | TextEdit.UPDATE_REGIONS); result.setExcludes(excludes.toArray(new TextEdit[excludes.size()])); return result; } }
private TextEditProcessor createTextEditProcessor(ComposableBufferChange change, IDocument document, int flags, boolean preview) { List<TextEdit> excludes= new ArrayList<>(0); for (final Iterator<TextEditBasedChangeGroup> iterator= change.getGroups().iterator(); iterator.hasNext();) { TextEditBasedChangeGroup group= iterator.next(); if (!group.isEnabled()) excludes.addAll(Arrays.asList(group.getTextEdits())); } if (preview) { fCopier= new TextEditCopier(change.getEdit()); TextEdit copiedEdit= fCopier.perform(); boolean keep= getKeepPreviewEdits(); if (keep) flags= flags | TextEdit.UPDATE_REGIONS; LocalTextEditProcessor result= new LocalTextEditProcessor(document, copiedEdit, flags); result.setExcludes(mapEdits(excludes.toArray(new TextEdit[excludes.size()]), fCopier)); if (!keep) fCopier= null; return result; } else { LocalTextEditProcessor result= new LocalTextEditProcessor(document, change.getEdit(), flags | TextEdit.UPDATE_REGIONS); result.setExcludes(excludes.toArray(new TextEdit[excludes.size()])); return result; } }
/** * Adds a new text change to this composite change. * <p> * The text change which is added is not changed in any way. Rather * the contents of the text change are retrieved and stored internally * in this composite text change. * </p> * * @param change * the text change to add */ public final void addChange(final TextChange change) { Assert.isNotNull(change); final ComposableBufferChange result= new ComposableBufferChange(); result.setEdit(change.getEdit()); final TextEditBasedChangeGroup[] groups= change.getChangeGroups(); final List list= new ArrayList(groups.length); for (int index= 0; index < groups.length; index++) { final TextEditBasedChangeGroup group= new ComposableBufferChangeGroup(this, groups[index].getTextEditGroup()); list.add(group); addChangeGroup(group); } result.setGroups(list); fChanges.add(result); }
/** * Adds a new text change to this composite change. * <p> * The text change which is added is not changed in any way. Rather * the contents of the text change are retrieved and stored internally * in this composite text change. * </p> * * @param change * the text change to add */ public final void addChange(final TextChange change) { Assert.isNotNull(change); final ComposableBufferChange result= new ComposableBufferChange(); result.setEdit(change.getEdit()); final TextEditBasedChangeGroup[] groups= change.getChangeGroups(); final List<TextEditBasedChangeGroup> list= new ArrayList<>(groups.length); for (int index= 0; index < groups.length; index++) { final TextEditBasedChangeGroup group= new ComposableBufferChangeGroup(this, groups[index].getTextEditGroup()); list.add(group); addChangeGroup(group); } result.setGroups(list); fChanges.add(result); }
public static void addTextEdit(TextChange change, String name, TextEdit edit, GroupCategorySet groupCategories) throws MalformedTreeException { Assert.isNotNull(change); Assert.isNotNull(name); Assert.isNotNull(edit); TextEdit root= change.getEdit(); if (root == null) { root= new MultiTextEdit(); change.setEdit(root); } insert(root, edit); change.addTextEditChangeGroup(new TextEditChangeGroup( change, new CategorizedTextEditGroup(name, edit, groupCategories))); }
public static void addTextEdit(TextChange change, String name, TextEdit edit, GroupCategorySet groupCategories) throws MalformedTreeException { Assert.isNotNull(change); Assert.isNotNull(name); Assert.isNotNull(edit); TextEdit root= change.getEdit(); if (root == null) { root= new MultiTextEdit(); change.setEdit(root); } insert(root, edit); change.addTextEditChangeGroup(new TextEditChangeGroup( change, new CategorizedTextEditGroup(name, edit, groupCategories))); }
public static void addTextEdit(TextChange change, String name, TextEdit edit, GroupCategorySet groupCategories) throws MalformedTreeException { Assert.isNotNull(change); Assert.isNotNull(name); Assert.isNotNull(edit); TextEdit root= change.getEdit(); if (root == null) { root= new MultiTextEdit(); change.setEdit(root); } insert(root, edit); change.addTextEditChangeGroup(new TextEditChangeGroup( change, new CategorizedTextEditGroup(name, edit, groupCategories))); }
private void addWorkspaceEdit(ICompilationUnit cu, CUCorrectionProposal proposal, WorkspaceEdit rootEdit) throws CoreException { TextChange textChange = proposal.getTextChange(); TextEdit edit = textChange.getEdit(); TextEditConverter converter = new TextEditConverter(cu, edit); List<org.eclipse.lsp4j.TextEdit> edits = converter.convert(); if (ChangeUtil.hasChanges(edits)) { rootEdit.getChanges().put(JDTUtils.toURI(cu), edits); } } }
@Override public String getAdditionalProposalInfo(IProgressMonitor monitor) throws CoreException { StringBuffer buf= new StringBuffer(); TextChange change = getTextChange(); change.setKeepPreviewEdits(true); IDocument previewDocument = change.getPreviewDocument(monitor); TextEdit rootEdit = change.getPreviewEdit(change.getEdit()); EditAnnotator ea = new EditAnnotator(buf, previewDocument); rootEdit.accept(ea); ea.unchangedUntil(previewDocument.getLength()); // Final pre-existing // region return buf.toString(); }
private static WorkspaceEdit convertChangeToWorkspaceEdit(ICompilationUnit unit, Change change) throws CoreException { WorkspaceEdit $ = new WorkspaceEdit(); if (change instanceof TextChange) { TextEditConverter converter = new TextEditConverter(unit, ((TextChange) change).getEdit()); String uri = JDTUtils.toURI(unit); $.getChanges().put(uri, converter.convert()); } else if (change instanceof ResourceChange) { ChangeUtil.convertResourceChange((ResourceChange) change, $); } else if (change instanceof CompositeChange) { ChangeUtil.convertCompositeChange(change, $); } return $; }
@Override public Object getAdditionalProposalInfo(IProgressMonitor monitor) { StringBuffer buf= new StringBuffer(); try { TextChange change= fCUProposal.getTextChange(); change.setKeepPreviewEdits(true); IDocument previewDocument= change.getPreviewDocument(monitor); TextEdit rootEdit= change.getPreviewEdit(change.getEdit()); EditAnnotator ea= new EditAnnotator(buf, previewDocument); rootEdit.accept(ea); ea.unchangedUntil(previewDocument.getLength()); // Final pre-existing region } catch (CoreException e) { JavaManipulationPlugin.log(e); } return buf.toString(); }
@Override public Object getAdditionalProposalInfo(IProgressMonitor monitor) { StringBuffer buf= new StringBuffer(); try { TextChange change= getTextChange(); change.setKeepPreviewEdits(true); IDocument previewDocument= change.getPreviewDocument(monitor); TextEdit rootEdit= change.getPreviewEdit(change.getEdit()); EditAnnotator ea= new EditAnnotator(buf, previewDocument); rootEdit.accept(ea); ea.unchangedUntil(previewDocument.getLength()); // Final pre-existing region } catch (CoreException e) { JavaPlugin.log(e); } return buf.toString(); }