本文整理汇总了Java中org.eclipse.text.edits.RangeMarker类的典型用法代码示例。如果您正苦于以下问题:Java RangeMarker类的具体用法?Java RangeMarker怎么用?Java RangeMarker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RangeMarker类属于org.eclipse.text.edits包,在下文中一共展示了RangeMarker类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getBlocks
import org.eclipse.text.edits.RangeMarker; //导入依赖的package包/类
private String[] getBlocks(RangeMarker[] markers) throws BadLocationException {
String[] result = new String[markers.length];
for (int i = 0; i < markers.length; i++) {
RangeMarker marker = markers[i];
String content = fDocument.get(marker.getOffset(), marker.getLength());
String lines[] = Strings.convertIntoLines(content);
Strings.trimIndentation(lines, fTypeRoot.getJavaProject(), false);
if (fMarkerMode == STATEMENT_MODE
&& lines.length == 2
&& isSingleControlStatementWithoutBlock()) {
lines[1] = CodeFormatterUtil.createIndentString(1, fTypeRoot.getJavaProject()) + lines[1];
}
result[i] = Strings.concatenate(lines, TextUtilities.getDefaultLineDelimiter(fDocument));
}
return result;
}
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:SourceProvider.java
示例2: createMethodContent
import org.eclipse.text.edits.RangeMarker; //导入依赖的package包/类
/**
* Creates the method content of the moved method.
*
* @param document
* the document representing the source compilation unit
* @param declaration
* the source method declaration
* @param rewrite
* the ast rewrite to use
* @return the string representing the moved method body
* @throws BadLocationException
* if an offset into the document is invalid
*/
protected String createMethodContent(final IDocument document, final MethodDeclaration declaration, final ASTRewrite rewrite) throws BadLocationException {
Assert.isNotNull(document);
Assert.isNotNull(declaration);
Assert.isNotNull(rewrite);
final IRegion range= new Region(declaration.getStartPosition(), declaration.getLength());
final RangeMarker marker= new RangeMarker(range.getOffset(), range.getLength());
final IJavaProject project= fMethod.getJavaProject();
final TextEdit[] edits= rewrite.rewriteAST(document, project.getOptions(true)).removeChildren();
for (int index= 0; index < edits.length; index++)
marker.addChild(edits[index]);
final MultiTextEdit result= new MultiTextEdit();
result.addChild(marker);
final TextEditProcessor processor= new TextEditProcessor(document, new MultiTextEdit(0, document.getLength()), TextEdit.UPDATE_REGIONS);
processor.getRoot().addChild(result);
processor.performEdits();
final IRegion region= document.getLineInformation(document.getLineOfOffset(marker.getOffset()));
return Strings.changeIndent(document.get(marker.getOffset(), marker.getLength()), Strings.computeIndentUnits(document.get(region.getOffset(), region.getLength()), project), project, "", TextUtilities.getDefaultLineDelimiter(document)); //$NON-NLS-1$
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:32,代码来源:MoveInstanceMethodProcessor.java
示例3: preVisit
import org.eclipse.text.edits.RangeMarker; //导入依赖的package包/类
public void preVisit(ASTNode node) {
// copies, then range marker
CopySourceInfo[] infos= this.eventStore.getNodeCopySources(node);
doCopySourcePreVisit(infos, this.sourceCopyEndNodes);
TextEditGroup editGroup= this.eventStore.getTrackedNodeData(node);
if (editGroup != null) {
SourceRange range= getExtendedRange(node);
int offset= range.getStartPosition();
int length= range.getLength();
TextEdit edit= new RangeMarker(offset, length);
addEditGroup(editGroup, edit);
addEdit(edit);
this.currentEdit= edit;
}
ensureSpaceBeforeReplace(node);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:ASTRewriteAnalyzer.java
示例4: getBlocks
import org.eclipse.text.edits.RangeMarker; //导入依赖的package包/类
private String[] getBlocks(RangeMarker[] markers) throws BadLocationException {
String[] result= new String[markers.length];
for (int i= 0; i < markers.length; i++) {
RangeMarker marker= markers[i];
String content= fDocument.get(marker.getOffset(), marker.getLength());
String lines[]= Strings.convertIntoLines(content);
Strings.trimIndentation(lines, fTypeRoot.getJavaProject(), false);
if (fMarkerMode == STATEMENT_MODE && lines.length == 2 && isSingleControlStatementWithoutBlock()) {
lines[1]= CodeFormatterUtil.createIndentString(1, fTypeRoot.getJavaProject()) + lines[1];
}
result[i]= Strings.concatenate(lines, TextUtilities.getDefaultLineDelimiter(fDocument));
}
return result;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:SourceProvider.java
示例5: processElement
import org.eclipse.text.edits.RangeMarker; //导入依赖的package包/类
/**
* Method processElement.
* @param unit
* @param source
*/
private String processElement(ICompilationUnit unit, char[] source) {
Document document = new Document(new String(source));
CompilerOptions options = new CompilerOptions(unit.getJavaProject().getOptions(true));
ASTParser parser = ASTParser.newParser(this.apiLevel);
parser.setCompilerOptions(options.getMap());
parser.setSource(source);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setResolveBindings(false);
org.eclipse.jdt.core.dom.CompilationUnit ast = (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(null);
ASTRewrite rewriter= sortCompilationUnit(ast, null);
if (rewriter == null)
return document.get();
TextEdit edits = rewriter.rewriteAST(document, unit.getJavaProject().getOptions(true));
RangeMarker[] markers = null;
if (this.positions != null) {
markers = new RangeMarker[this.positions.length];
for (int i = 0, max = this.positions.length; i < max; i++) {
markers[i]= new RangeMarker(this.positions[i], 0);
insert(edits, markers[i]);
}
}
try {
edits.apply(document, TextEdit.UPDATE_REGIONS);
if (this.positions != null) {
for (int i= 0, max = markers.length; i < max; i++) {
this.positions[i]= markers[i].getOffset();
}
}
} catch (BadLocationException e) {
// ignore
}
return document.get();
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:42,代码来源:SortElementsOperation.java
示例6: createRangeMarkers
import org.eclipse.text.edits.RangeMarker; //导入依赖的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;
}
开发者ID:eclipse,项目名称:che,代码行数:53,代码来源:JavaFormatter.java
示例7: createRangeMarkers
import org.eclipse.text.edits.RangeMarker; //导入依赖的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;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:51,代码来源:JavaFormatter.java
注:本文中的org.eclipse.text.edits.RangeMarker类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论