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


Java INode.getOffset方法代码示例

本文整理汇总了Java中org.eclipse.xtext.nodemodel.INode.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java INode.getOffset方法的具体用法?Java INode.getOffset怎么用?Java INode.getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.xtext.nodemodel.INode的用法示例。


在下文中一共展示了INode.getOffset方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeNodeButKeepComments

import org.eclipse.xtext.nodemodel.INode; //导入方法依赖的package包/类
private static IChange removeNodeButKeepComments(IXtextDocument doc, INode importNode) throws BadLocationException {
	if (importNode == null)
		return IChange.IDENTITY;

	int end = importNode.getEndOffset();
	int offset = importNode.getOffset();
	return ChangeProvider.removeText(doc, offset, end - offset, true);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:9,代码来源:ImportsRemovalChangesComputer2.java

示例2: updateMelange

import org.eclipse.xtext.nodemodel.INode; //导入方法依赖的package包/类
protected void updateMelange(ExecutionEvent event, Language language, String xtextPath){
	// Compute offset & new string
	int startOffset = -1;
	int length = -1;
	String newRegion = null;
	
	EStructuralFeature xtext = language.eClass().getEStructuralFeature("xtext");
	List<INode> nodesXtext = NodeModelUtils.findNodesForFeature(language, xtext);
	
	if(!nodesXtext.isEmpty()){
		INode nodeXtext = nodesXtext.get(0);
		startOffset = nodeXtext.getOffset();
		length = nodeXtext.getLength();
		newRegion = "\""+xtextPath+"\"";
	}
	else{//insert after operators
		EStructuralFeature operators = language.eClass().getEStructuralFeature("operators");
		List<INode> nodesOp = NodeModelUtils.findNodesForFeature(language, operators);
		int lastOffset = -1;
		for(INode node : nodesOp){
			if(node.getEndOffset() > lastOffset) lastOffset = node.getEndOffset();
		}
		if(lastOffset != -1){
			
				startOffset = lastOffset;
				length = 0;
				newRegion = "\n\n\txtext \""+xtextPath+"\"";
			
		}
	}
	
	// Replace in document or Melange file
	if(startOffset != -1 && length != -1 && newRegion != null){
		int _startOffset = startOffset;
		int _length = length;
		String _newRegion = newRegion;
		XtextEditor editor = EditorUtils.getActiveXtextEditor();
		if (editor != null && editor.getLanguageName().equals(MELANGE_EDITOR)) { //Update the editor content
			IXtextDocument document = editor.getDocument();
			document.modify((XtextResource it) -> {
				document.replace(_startOffset,_length, _newRegion);
				return null; // no computed value
			});
		}
		else{ //Update the Melange file content
			
			try {
				//Load Melange file
				String melangeWSLocation = language.eResource().getURI().toPlatformString(true);
				URI uri = language.eResource().getURI();
				String melangeLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()+melangeWSLocation;
				List<String> lines = Files.readAllLines(Paths.get(melangeLocation));
				
				StringBuffer newContent = new StringBuffer();
				lines.forEach(
						line -> newContent.append(line+"\n")
						);
				
				newContent.replace(startOffset,startOffset+length, newRegion);
				
				//Write new content
				Files.write(Paths.get(melangeLocation), newContent.toString().getBytes());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}
}
 
开发者ID:eclipse,项目名称:gemoc-studio-modeldebugging,代码行数:70,代码来源:CreateXtextEditorProjectHandler.java

示例3: updateMelange

import org.eclipse.xtext.nodemodel.INode; //导入方法依赖的package包/类
protected void updateMelange(ExecutionEvent event, Language language, String siriusPath){
	// Compute offset & new string
	int startOffset = -1;
	int length = -1;
	String newRegion = null;
	
	EStructuralFeature sirius = language.eClass().getEStructuralFeature("sirius");
	List<INode> nodesSirius = NodeModelUtils.findNodesForFeature(language, sirius);
	
	if(!nodesSirius.isEmpty()){
		INode nodeSirius = nodesSirius.get(0);
		startOffset = nodeSirius.getOffset();
		length = nodeSirius.getLength();
		newRegion = "\""+siriusPath+"\"";
	}
	else{//insert after operators
		EStructuralFeature operators = language.eClass().getEStructuralFeature("operators");
		List<INode> nodesOp = NodeModelUtils.findNodesForFeature(language, operators);
		int lastOffset = -1;
		for(INode node : nodesOp){
			if(node.getEndOffset() > lastOffset) lastOffset = node.getEndOffset();
		}
		if(lastOffset != -1){
			
				startOffset = lastOffset;
				length = 0;
				newRegion = "\n\n\tsirius \""+siriusPath+"\"";
			
		}
	}
	
	// Replace in document or Melange file
	if(startOffset != -1 && length != -1 && newRegion != null){
		int _startOffset = startOffset;
		int _length = length;
		String _newRegion = newRegion;
		XtextEditor editor = EditorUtils.getActiveXtextEditor();
		if (editor != null && editor.getLanguageName().equals(MELANGE_EDITOR)) { //Update the editor content
			IXtextDocument document = editor.getDocument();
			document.modify((XtextResource it) -> {
				document.replace(_startOffset,_length, _newRegion);
				return null; // no computed value
			});
		}
		else{ //Update the Melange file content
			
			try {
				//Load Melange file
				String melangeWSLocation = language.eResource().getURI().toPlatformString(true);
				URI uri = language.eResource().getURI();
				String melangeLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()+melangeWSLocation;
				List<String> lines = Files.readAllLines(Paths.get(melangeLocation));
				
				StringBuffer newContent = new StringBuffer();
				lines.forEach(
						line -> newContent.append(line+"\n")
						);
				
				newContent.replace(startOffset,startOffset+length, newRegion);
				
				//Write new content
				Files.write(Paths.get(melangeLocation), newContent.toString().getBytes());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}
}
 
开发者ID:eclipse,项目名称:gemoc-studio-modeldebugging,代码行数:70,代码来源:CreateSiriusEditorProjectHandler.java


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