当前位置: 首页>>代码示例>>Java>>正文


Java TemplateVariable.getOffsets方法代码示例

本文整理汇总了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();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:StubUtility.java

示例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();
	}
 
开发者ID:curiosag,项目名称:ftc,代码行数:12,代码来源:TweakedTemplateProposal.java

示例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);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:CompilationUnitContextType.java

示例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();
}
 
开发者ID:eclipse,项目名称:che,代码行数:30,代码来源:StubUtility.java

示例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();
  }
 
开发者ID:eclipse,项目名称:che,代码行数:12,代码来源:TemplateProposal.java

示例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();
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:14,代码来源:SnippetTemplateProposal.java

示例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);
			}
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:13,代码来源:CompilationUnitContextType.java

示例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();
	}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:12,代码来源:TemplateProposal.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:JavaStatementPostfixContext.java

示例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.");
            }
        }
    }
}
 
开发者ID:forcedotcom,项目名称:idecore,代码行数:13,代码来源:ForceTemplateContextType.java

示例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);
			}
		}
	}
}
 
开发者ID:GoClipse,项目名称:goclipse,代码行数:13,代码来源:LangTemplateContextType.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:53,代码来源:JavaFormatter.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:51,代码来源:JavaFormatter.java


注:本文中的org.eclipse.jface.text.templates.TemplateVariable.getOffsets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。