本文整理汇总了Java中org.eclipse.text.edits.MultiTextEdit.apply方法的典型用法代码示例。如果您正苦于以下问题:Java MultiTextEdit.apply方法的具体用法?Java MultiTextEdit.apply怎么用?Java MultiTextEdit.apply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.text.edits.MultiTextEdit
的用法示例。
在下文中一共展示了MultiTextEdit.apply方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeComment
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private void removeComment(IDocument doc, int offset) {
try {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
ITypedRegion par = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, offset, false);
int beg = par.getOffset();
int len = par.getLength();
String comment = doc.get(beg, len);
int eLen = markerLen(comment);
int bLen = eLen + 1;
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new DeleteEdit(beg, bLen));
edit.addChild(new DeleteEdit(beg + len - eLen, eLen));
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure removing comment " + e.getMessage());
}
}
示例2: fixEmptyVariables
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables) throws MalformedTreeException, BadLocationException {
IDocument doc= new Document(buffer.getString());
int nLines= doc.getNumberOfLines();
MultiTextEdit edit= new MultiTextEdit();
HashSet<Integer> removedLines= new HashSet<Integer>();
for (int i= 0; i < variables.length; i++) {
TemplateVariable position= findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
if (position == null || position.getLength() > 0) {
continue;
}
int[] offsets= position.getOffsets();
for (int k= 0; k < offsets.length; k++) {
int line= doc.getLineOfOffset(offsets[k]);
IRegion lineInfo= doc.getLineInformation(line);
int offset= lineInfo.getOffset();
String str= doc.get(offset, lineInfo.getLength());
if (Strings.containsOnlyWhitespaces(str) && nLines > line + 1 && removedLines.add(new Integer(line))) {
int nextStart= doc.getLineOffset(line + 1);
edit.addChild(new DeleteEdit(offset, nextStart - offset));
}
}
}
edit.apply(doc, 0);
return doc.get();
}
示例3: applyGenerateProperties
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private IDocument applyGenerateProperties(MockupGeneratePropertiesRequestProcessor requestProcessor)
throws BadLocationException, MalformedTreeException, MisconfigurationException {
IDocument refactoringDoc = new Document(data.source);
MultiTextEdit multi = new MultiTextEdit();
for (GeneratePropertiesRequest req : requestProcessor.getRefactoringRequests()) {
SelectionState state = req.getSelectionState();
if (state.isGetter()) {
multi.addChild(new GetterMethodEdit(req).getEdit());
}
if (state.isSetter()) {
multi.addChild(new SetterMethodEdit(req).getEdit());
}
if (state.isDelete()) {
multi.addChild(new DeleteMethodEdit(req).getEdit());
}
multi.addChild(new PropertyEdit(req).getEdit());
}
multi.apply(refactoringDoc);
return refactoringDoc;
}
示例4: remove
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private void remove(int beg, int len, int markLen) {
try {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new DeleteEdit(beg - markLen, markLen));
edit.addChild(new DeleteEdit(beg + len, markLen));
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure removing mark" + e.getMessage());
}
}
示例5: addComment
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private void addComment(IDocument doc, int beg, int len) {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new InsertEdit(beg, getCommentBeg()));
edit.addChild(new InsertEdit(beg + len, getCommentEnd()));
try {
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure creating comment " + e.getMessage());
}
}
示例6: fixEmptyVariables
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables)
throws MalformedTreeException, BadLocationException {
IDocument doc = new Document(buffer.getString());
int nLines = doc.getNumberOfLines();
MultiTextEdit edit = new MultiTextEdit();
HashSet<Integer> removedLines = new HashSet<Integer>();
for (int i = 0; i < variables.length; i++) {
TemplateVariable position =
findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
if (position == null || position.getLength() > 0) {
continue;
}
int[] offsets = position.getOffsets();
for (int k = 0; k < offsets.length; k++) {
int line = doc.getLineOfOffset(offsets[k]);
IRegion lineInfo = doc.getLineInformation(line);
int offset = lineInfo.getOffset();
String str = doc.get(offset, lineInfo.getLength());
if (Strings.containsOnlyWhitespaces(str)
&& nLines > line + 1
&& removedLines.add(new Integer(line))) {
int nextStart = doc.getLineOffset(line + 1);
edit.addChild(new DeleteEdit(offset, nextStart - offset));
}
}
}
edit.apply(doc, 0);
return doc.get();
}
示例7: applyExtractMethod
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private IDocument applyExtractMethod(RefactoringInfo info, MockupExtractMethodRequestProcessor requestProcessor)
throws BadLocationException, MalformedTreeException, MisconfigurationException {
ExtractMethodRequest req = requestProcessor.getRefactoringRequests().get(0);
ExtractMethodEdit extractedMethodEdit = new ExtractMethodEdit(req);
ExtractCallEdit callExtractedMethodEdit = new ExtractCallEdit(req);
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(extractedMethodEdit.getEdit());
edit.addChild(callExtractedMethodEdit.getEdit());
IDocument refactoringDoc = new Document(data.source);
edit.apply(refactoringDoc);
return refactoringDoc;
}
示例8: doApply
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
/**
* Really do apply the proposal. Assumed to be run within the prevent flickering mode.
*/
private int doApply(QualifiedName qualifiedName, String alias, IDocument document,
ConfigurableCompletionProposal proposal) throws BadLocationException {
String shortSemanticReplacementString = alias != null ? alias : lastSegmentOrDefaultHost(qualifiedName);
String shortSyntacticReplacementString = valueConverter.toString(shortSemanticReplacementString);
ImportRewriter importRewriter = importRewriterFactory.create(document, context);
ReplaceEdit replaceEdit = new ReplaceEdit(
proposal.getReplacementOffset(),
proposal.getReplacementLength(),
shortSyntacticReplacementString);
MultiTextEdit compound = new MultiTextEdit();
AliasLocation aliasLocation = null;
if (alias != null) {
aliasLocation = importRewriter.addSingleImport(qualifiedName, alias, compound);
} else {
importRewriter.addSingleImport(qualifiedName, compound);
}
compound.addChild(replaceEdit);
Position caret = new Position(proposal.getReplacementOffset(), 0);
document.addPosition(caret);
compound.apply(document);
document.removePosition(caret);
int cursorPosition = caret.getOffset();
proposal.setReplacementOffset(cursorPosition - shortSemanticReplacementString.length());
proposal.setCursorPosition(shortSemanticReplacementString.length());
if (aliasLocation != null) {
final int aliasOffset = aliasLocation.getBaseOffset() + aliasLocation.getRelativeOffset();
final int aliasLength = shortSyntacticReplacementString.length();
N4JSCompletionProposal castedProposal = (N4JSCompletionProposal) proposal;
castedProposal.setLinkedModeBuilder((appliedProposal, currentDocument) -> {
try {
LinkedPositionGroup group = new LinkedPositionGroup();
group.addPosition(new LinkedPosition(
currentDocument,
aliasOffset,
aliasLength,
LinkedPositionGroup.NO_STOP));
group.addPosition(new LinkedPosition(
currentDocument,
proposal.getReplacementOffset(),
proposal.getCursorPosition(),
LinkedPositionGroup.NO_STOP));
proposal.setSelectionStart(proposal.getReplacementOffset());
proposal.setSelectionLength(proposal.getCursorPosition());
LinkedModeModel model = new LinkedModeModel();
model.addGroup(group);
model.forceInstall();
LinkedModeUI ui = new LinkedModeUI(model, viewer);
ui.setExitPolicy(new IdentifierExitPolicy('\n'));
ui.setExitPosition(
viewer,
proposal.getCursorPosition() + proposal.getReplacementOffset(),
0,
Integer.MAX_VALUE);
ui.setCyclingMode(LinkedModeUI.CYCLE_NEVER);
ui.enter();
} catch (BadLocationException e) {
logger.error(e.getMessage(), e);
}
});
}
return cursorPosition;
}
示例9: toggle
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private void toggle(int beg, int len) {
// if surrounded by marks, remove them
String mark = isMarked(beg, len);
if (qualified(mark)) {
remove(beg, len, mark.length());
return;
}
if (mark == null || mark.charAt(0) == markSpec[1].charAt(0)) {
mark = markSpec[0];
} else {
mark = markSpec[1];
}
// add surrounding marks
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new InsertEdit(beg, mark));
edit.addChild(new InsertEdit(beg + len, mark));
// // remove any included marks
// if (len > 0) {
// try {
// String text = doc.get(beg, len);
// Pattern srch = Pattern.compile(Pattern.quote(markSpec[0]));
// Matcher matcher = srch.matcher(text);
// while (matcher.find()) {
// int start = matcher.start();
// int stop = matcher.end();
// edit.addChild(new DeleteEdit(beg + start, stop - start + 1));
// }
// } catch (MalformedTreeException | BadLocationException e) {}
// }
try {
edit.apply(doc);
undoMgr.endCompoundChange();
editor.setCursorOffset(cpos + markSpec[0].length());
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure applying mark" + e.getMessage());
}
}
示例10: createRangeMarkers
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private List<TypedPosition> createRangeMarkers(TemplateVariable[] variables, IDocument document)
throws MalformedTreeException, BadLocationException {
Map<ReplaceEdit, String> markerToOriginal = new HashMap<ReplaceEdit, String>();
MultiTextEdit root = new MultiTextEdit(0, document.getLength());
List<TextEdit> edits = new ArrayList<TextEdit>();
boolean hasModifications = false;
for (int i = 0; i != variables.length; i++) {
final TemplateVariable variable = variables[i];
int[] offsets = variable.getOffsets();
String value = variable.getDefaultValue();
if (isWhitespaceVariable(value)) {
// replace whitespace positions with unformattable comments
String placeholder = COMMENT_START + value + COMMENT_END;
for (int j = 0; j != offsets.length; j++) {
ReplaceEdit replace = new ReplaceEdit(offsets[j], value.length(), placeholder);
root.addChild(replace);
hasModifications = true;
markerToOriginal.put(replace, value);
edits.add(replace);
}
} else {
for (int j = 0; j != offsets.length; j++) {
RangeMarker marker = new RangeMarker(offsets[j], value.length());
root.addChild(marker);
edits.add(marker);
}
}
}
if (hasModifications) {
// update the document and convert the replaces to markers
root.apply(document, TextEdit.UPDATE_REGIONS);
}
List<TypedPosition> positions = new ArrayList<TypedPosition>();
for (Iterator<TextEdit> it = edits.iterator(); it.hasNext(); ) {
TextEdit edit = it.next();
try {
// abuse TypedPosition to piggy back the original contents of the position
final TypedPosition pos =
new TypedPosition(edit.getOffset(), edit.getLength(), markerToOriginal.get(edit));
document.addPosition(CATEGORY, pos);
positions.add(pos);
} catch (BadPositionCategoryException x) {
Assert.isTrue(false);
}
}
return positions;
}
示例11: createRangeMarkers
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private List<TypedPosition> createRangeMarkers(TemplateVariable[] variables, IDocument document) throws MalformedTreeException, BadLocationException {
Map<ReplaceEdit, String> markerToOriginal= new HashMap<ReplaceEdit, String>();
MultiTextEdit root= new MultiTextEdit(0, document.getLength());
List<TextEdit> edits= new ArrayList<TextEdit>();
boolean hasModifications= false;
for (int i= 0; i != variables.length; i++) {
final TemplateVariable variable= variables[i];
int[] offsets= variable.getOffsets();
String value= variable.getDefaultValue();
if (isWhitespaceVariable(value)) {
// replace whitespace positions with unformattable comments
String placeholder= COMMENT_START + value + COMMENT_END;
for (int j= 0; j != offsets.length; j++) {
ReplaceEdit replace= new ReplaceEdit(offsets[j], value.length(), placeholder);
root.addChild(replace);
hasModifications= true;
markerToOriginal.put(replace, value);
edits.add(replace);
}
} else {
for (int j= 0; j != offsets.length; j++) {
RangeMarker marker= new RangeMarker(offsets[j], value.length());
root.addChild(marker);
edits.add(marker);
}
}
}
if (hasModifications) {
// update the document and convert the replaces to markers
root.apply(document, TextEdit.UPDATE_REGIONS);
}
List<TypedPosition> positions= new ArrayList<TypedPosition>();
for (Iterator<TextEdit> it= edits.iterator(); it.hasNext();) {
TextEdit edit= it.next();
try {
// abuse TypedPosition to piggy back the original contents of the position
final TypedPosition pos= new TypedPosition(edit.getOffset(), edit.getLength(), markerToOriginal.get(edit));
document.addPosition(CATEGORY, pos);
positions.add(pos);
} catch (BadPositionCategoryException x) {
Assert.isTrue(false);
}
}
return positions;
}
示例12: addJavadocComments
import org.eclipse.text.edits.MultiTextEdit; //导入方法依赖的package包/类
private void addJavadocComments(IProgressMonitor monitor) throws CoreException {
ICompilationUnit cu= fMembers[0].getCompilationUnit();
ITextFileBufferManager manager= FileBuffers.getTextFileBufferManager();
IPath path= cu.getPath();
manager.connect(path, LocationKind.IFILE, new SubProgressMonitor(monitor, 1));
try {
IDocument document= manager.getTextFileBuffer(path, LocationKind.IFILE).getDocument();
String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
MultiTextEdit edit= new MultiTextEdit();
for (int i= 0; i < fMembers.length; i++) {
IMember curr= fMembers[i];
int memberStartOffset= getMemberStartOffset(curr, document);
String comment= null;
switch (curr.getElementType()) {
case IJavaElement.TYPE:
comment= createTypeComment((IType) curr, lineDelim);
break;
case IJavaElement.FIELD:
comment= createFieldComment((IField) curr, lineDelim);
break;
case IJavaElement.METHOD:
comment= createMethodComment((IMethod) curr, lineDelim);
break;
}
if (comment == null) {
StringBuffer buf= new StringBuffer();
buf.append("/**").append(lineDelim); //$NON-NLS-1$
buf.append(" *").append(lineDelim); //$NON-NLS-1$
buf.append(" */").append(lineDelim); //$NON-NLS-1$
comment= buf.toString();
} else {
if (!comment.endsWith(lineDelim)) {
comment= comment + lineDelim;
}
}
final IJavaProject project= cu.getJavaProject();
IRegion region= document.getLineInformationOfOffset(memberStartOffset);
String line= document.get(region.getOffset(), region.getLength());
String indentString= Strings.getIndentString(line, project);
String indentedComment= Strings.changeIndent(comment, 0, project, indentString, lineDelim);
edit.addChild(new InsertEdit(memberStartOffset, indentedComment));
monitor.worked(1);
}
edit.apply(document); // apply all edits
} catch (BadLocationException e) {
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
} finally {
manager.disconnect(path, LocationKind.IFILE,new SubProgressMonitor(monitor, 1));
}
}