當前位置: 首頁>>代碼示例>>Java>>正文


Java INode.getEndOffset方法代碼示例

本文整理匯總了Java中org.eclipse.xtext.nodemodel.INode.getEndOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java INode.getEndOffset方法的具體用法?Java INode.getEndOffset怎麽用?Java INode.getEndOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.xtext.nodemodel.INode的用法示例。


在下文中一共展示了INode.getEndOffset方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: IEObjectCoveringRegion

import org.eclipse.xtext.nodemodel.INode; //導入方法依賴的package包/類
/***/
@Creates
public IEObjectCoveringRegion IEObjectCoveringRegion() {
	final boolean haveRegion = region != null;

	int offset = haveRegion ? region.getOffset() : this.matchedOffset;
	int length = haveRegion ? region.getLength() : 0;
	int endOffset = offset + length;
	EObject semanticObject = null;

	INode node = NodeModelUtils.findLeafNodeAtOffset(resource.getParseResult().getRootNode(), offset);
	while (node != null) {
		EObject actualObject = NodeModelUtils.findActualSemanticObjectFor(node);
		if (actualObject != null) {
			if (haveRegion) {
				int nodeEndOffset = node.getEndOffset();
				if (nodeEndOffset <= endOffset || semanticObject == null) {
					semanticObject = actualObject;
				}
				if (nodeEndOffset >= endOffset) {
					break;
				}
			} else { // no region given, just a matched offset
				if (semanticObject == null) {
					semanticObject = actualObject;
					break;
				}
			}
		}
		node = node.getParent();
	}
	return new EObjectCoveringRegion(semanticObject, offset);
}
 
開發者ID:eclipse,項目名稱:n4js,代碼行數:34,代碼來源:N4JSOffsetAdapter.java

示例2: 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

示例3: 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

示例4: 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.getEndOffset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。