本文整理汇总了Java中org.eclipse.jface.text.templates.TemplateVariable.getOffsets方法的典型用法代码示例。如果您正苦于以下问题:Java TemplateVariable.getOffsets方法的具体用法?Java TemplateVariable.getOffsets怎么用?Java TemplateVariable.getOffsets使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.templates.TemplateVariable
的用法示例。
在下文中一共展示了TemplateVariable.getOffsets方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fixEmptyVariables
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的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();
}
示例2: getCaretOffset
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的package包/类
private int getCaretOffset(TemplateBuffer buffer) {
TemplateVariable[] variables = buffer.getVariables();
for (int i = 0; i != variables.length; i++) {
TemplateVariable variable = variables[i];
if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME))
return variable.getOffsets()[0];
}
return buffer.getString().length();
}
示例3: validateVariables
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的package包/类
@Override
protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
// check for multiple cursor variables
for (int i = 0; i < variables.length; i++) {
TemplateVariable var = variables[i];
if (var.getType().equals(GlobalTemplateVariables.Cursor.NAME)) {
if (var.getOffsets().length > 1) {
throw new TemplateException(
JavaTemplateMessages.ContextType_error_multiple_cursor_variables);
}
}
}
}
示例4: fixEmptyVariables
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的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();
}
示例5: getCaretOffset
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的package包/类
private int getCaretOffset(TemplateBuffer buffer) {
TemplateVariable[] variables = buffer.getVariables();
for (int i = 0; i != variables.length; i++) {
TemplateVariable variable = variables[i];
if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME))
return variable.getOffsets()[0];
}
return buffer.getString().length();
}
示例6: getCaretOffset
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的package包/类
private int getCaretOffset(TemplateBuffer buffer)
{
TemplateVariable[] variables = buffer.getVariables();
for (int i = 0; i != variables.length; i++)
{
TemplateVariable variable = variables[i];
if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME))
return variable.getOffsets()[0];
}
return buffer.getString().length();
}
示例7: validateVariables
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的package包/类
@Override
protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
// check for multiple cursor variables
for (int i= 0; i < variables.length; i++) {
TemplateVariable var= variables[i];
if (var.getType().equals(GlobalTemplateVariables.Cursor.NAME)) {
if (var.getOffsets().length > 1) {
throw new TemplateException(JavaTemplateMessages.ContextType_error_multiple_cursor_variables);
}
}
}
}
示例8: getCaretOffset
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的package包/类
private int getCaretOffset(TemplateBuffer buffer) {
TemplateVariable[] variables= buffer.getVariables();
for (int i= 0; i != variables.length; i++) {
TemplateVariable variable= variables[i];
if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME))
return variable.getOffsets()[0];
}
return buffer.getString().length();
}
示例9: evaluate
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的package包/类
@Override
public TemplateBuffer evaluate(Template template)
throws BadLocationException, TemplateException {
TemplateBuffer result = super.evaluate(template);
// After the template buffer has been created we are able to add out of range offsets
// This is not possible beforehand as it will result in an exception!
for (TemplateVariable tv : result.getVariables()) {
int[] outOfRangeOffsets = this.getVariableOutOfRangeOffsets(tv);
if (outOfRangeOffsets != null && outOfRangeOffsets.length > 0) {
int[] offsets = tv.getOffsets();
int[] newOffsets = new int[outOfRangeOffsets.length + offsets.length];
System.arraycopy(offsets, 0, newOffsets, 0, offsets.length);
for (int i = 0; i < outOfRangeOffsets.length; i++) {
newOffsets[i + offsets.length] = outOfRangeOffsets[i]; // - getAffectedSourceRegion().getOffset();
}
tv.setOffsets(newOffsets);
}
}
return result;
}
示例10: validateVariables
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的package包/类
@Override
protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
// check for multiple cursor variables
for (int i = 0; i < variables.length; i++) {
TemplateVariable var = variables[i];
if (var.getType().equals(GlobalTemplateVariables.Cursor.NAME)) {
if (var.getOffsets().length > 1) {
throw new TemplateException("Template has multiple cursor variables.");
}
}
}
}
示例11: validateVariables
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的package包/类
@Override
protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
// check for multiple cursor variables
for(int i = 0; i < variables.length; i++) {
TemplateVariable var = variables[i];
if(var.getType().equals(GlobalTemplateVariables.Cursor.NAME)) {
if(var.getOffsets().length > 1) {
throw new TemplateException(JavaTemplateMessages.ContextType_error_multiple_cursor_variables);
}
}
}
}
示例12: createRangeMarkers
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的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;
}
示例13: createRangeMarkers
import org.eclipse.jface.text.templates.TemplateVariable; //导入方法依赖的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;
}