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


Java ILeafNode.getOffset方法代码示例

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


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

示例1: getCrossReferenceNode

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
 * @since 2.1
 */
public INode getCrossReferenceNode(XtextResource resource, ITextRegion region) {
	IParseResult parseResult = resource.getParseResult();
	if (parseResult != null) {
		ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset());
		INode crossRefNode = findCrossReferenceNode(leaf);
		// if not a cross reference position and the cursor is at the beginning of a node try the previous one.
		if (crossRefNode == null && leaf != null && region.getLength()==0 && leaf.getOffset() == region.getOffset()) {
			leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), region.getOffset() - 1);
			return findCrossReferenceNode(leaf);
		} else if (crossRefNode != null && crossRefNode.getEndOffset() >= region.getOffset() + region.getLength()) {
			return crossRefNode;
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:EObjectAtOffsetHelper.java

示例2: internalResolveElementAt

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected EObject internalResolveElementAt(XtextResource resource, int offset, boolean containment) {
	if(!containment) {
		EObject crossRef = resolveCrossReferencedElementAt(resource, offset);
		if (crossRef != null)
			return crossRef;
	}
	IParseResult parseResult = resource.getParseResult();
	if (parseResult != null) {
		ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
		if (leaf != null && leaf.isHidden() && leaf.getOffset() == offset) {
			leaf = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset - 1);
		}
		if (leaf != null) {
			return NodeModelUtils.findActualSemanticObjectFor(leaf);
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:EObjectAtOffsetHelper.java

示例3: getIndentation

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected String getIndentation(ICompositeNode root, int fromOffset) {
	if (fromOffset == 0)
		return "";

	List<ILeafNode> r = new ArrayList<ILeafNode>();
	// add all nodes until fromOffset
	for(ILeafNode l: root.getLeafNodes()) {
		if (l.getOffset() >= fromOffset)
			break;
		else
			r.add(l);
	}

	// go backwards until first linewrap
	Pattern p = Pattern.compile("(\\n|\\r)([ \\t]*)");
	for (int i = r.size() - 1; i >= 0; i--) {
		Matcher m = p.matcher(r.get(i).getText());
		if (m.find()) {
			String ind = m.group(2);
			while (m.find())
				ind = m.group(2);
			return ind;
		}
	}
	return "";
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:27,代码来源:DefaultNodeModelFormatter.java

示例4: findTasks

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected List<Task> findTasks(final ILeafNode node, final TaskTags taskTags) {
  boolean _canContainTaskTags = this.canContainTaskTags(node);
  if (_canContainTaskTags) {
    final List<Task> tasks = this.parser.parseTasks(this.stripText(node, node.getText()), taskTags);
    final Consumer<Task> _function = (Task it) -> {
      int _offset = it.getOffset();
      int _offset_1 = node.getOffset();
      int _plus = (_offset + _offset_1);
      it.setOffset(_plus);
      int _lineNumber = it.getLineNumber();
      int _startLine = node.getStartLine();
      int _plus_1 = (_lineNumber + _startLine);
      int _minus = (_plus_1 - 1);
      it.setLineNumber(_minus);
    };
    tasks.forEach(_function);
    return tasks;
  }
  return Collections.<Task>unmodifiableList(CollectionLiterals.<Task>newArrayList());
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:21,代码来源:DefaultTaskFinder.java

示例5: getOffsetForText

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
 * Gets the offset for given text by analyzing the parse tree and looking for leaf nodes having
 * a text attribute matching given value. Returns the first instance found and an error value if
 * no match found.
 *
 * @param model
 *          the model
 * @param text
 *          the text
 * @return the offset for text
 */
public static int getOffsetForText(final EObject model, final String text) {
  Iterable<ILeafNode> parseTreeNodes = NodeModelUtils.getNode(model).getLeafNodes();

  try {
    ILeafNode result = Iterables.find(parseTreeNodes, new Predicate<ILeafNode>() {
      @Override
      public boolean apply(final ILeafNode input) {
        return text.equals(input.getText());
      }
    });
    return result.getOffset();
  } catch (NoSuchElementException e) {
    return LEAF_NOT_FOUND_VALUE;
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:27,代码来源:AbstractSyntaxColoringTest.java

示例6: getOffsetForText

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
 * Gets the offset for given text by analyzing the parse tree and looking for leaf nodes having
 * a text attribute matching given value. Returns the first instance found and an error value if
 * no match found.
 *
 * @param model
 *          the model
 * @param text
 *          the text
 * @return the offset for text
 */
protected int getOffsetForText(final EObject model, final String text) {
  Iterable<ILeafNode> parseTreeNodes = NodeModelUtils.getNode(model).getLeafNodes();

  try {
    ILeafNode result = Iterables.find(parseTreeNodes, new Predicate<ILeafNode>() {
      @Override
      public boolean apply(final ILeafNode input) {
        return text.equals(input.getText());
      }
    });
    return result.getOffset();
  } catch (NoSuchElementException e) {
    return LEAF_NOT_FOUND_VALUE;
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:27,代码来源:AbstractHyperlinkHelperTest.java

示例7: getHiddenLeafsBefore

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
public HiddenLeafs getHiddenLeafsBefore(final INode node) {
  HiddenLeafs _xblockexpression = null;
  {
    final Function1<ILeafNode, Boolean> _function = (ILeafNode it) -> {
      boolean _isHidden = it.isHidden();
      return Boolean.valueOf((!_isHidden));
    };
    final ILeafNode start = this._nodeModelAccess.findNextLeaf(node, _function);
    final List<ILeafNode> nodes = this.findPreviousHiddenLeafs(start);
    HiddenLeafs _xifexpression = null;
    if ((start != null)) {
      int _xifexpression_1 = (int) 0;
      boolean _isEmpty = nodes.isEmpty();
      if (_isEmpty) {
        _xifexpression_1 = start.getOffset();
      } else {
        _xifexpression_1 = IterableExtensions.<ILeafNode>head(nodes).getOffset();
      }
      _xifexpression = this.newHiddenLeafs(_xifexpression_1, nodes);
    } else {
      int _offset = 0;
      if (node!=null) {
        _offset=node.getOffset();
      }
      _xifexpression = new HiddenLeafs(_offset);
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:31,代码来源:HiddenLeafAccess.java

示例8: createContext

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected HoverContext createContext(final Document document, final XtextResource resource, final int offset) {
  final EObject crossLinkedEObject = this._eObjectAtOffsetHelper.resolveCrossReferencedElementAt(resource, offset);
  if ((crossLinkedEObject != null)) {
    boolean _eIsProxy = crossLinkedEObject.eIsProxy();
    if (_eIsProxy) {
      return null;
    }
    final IParseResult parseResult = resource.getParseResult();
    if ((parseResult == null)) {
      return null;
    }
    ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
    if ((((leafNode != null) && leafNode.isHidden()) && (leafNode.getOffset() == offset))) {
      leafNode = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), (offset - 1));
    }
    if ((leafNode == null)) {
      return null;
    }
    final ITextRegion leafRegion = leafNode.getTextRegion();
    return new HoverContext(document, resource, offset, leafRegion, crossLinkedEObject);
  }
  final EObject element = this._eObjectAtOffsetHelper.resolveElementAt(resource, offset);
  if ((element == null)) {
    return null;
  }
  final ITextRegion region = this._iLocationInFileProvider.getSignificantTextRegion(element);
  return new HoverContext(document, resource, offset, region, element);
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:29,代码来源:HoverService.java

示例9: computeRegions

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
 * Computes regions between a given string to search and different ends searched by their precedence
 *
 * @param regions - List to put new regions in
 * @param leafNodes - nodes to search in
 * @param toSearch - String to search
 * @param ends - ends in decreasing precedence
 * @since 2.6
 */
protected void computeRegions(List<ReplaceRegion> regions, Iterable<ILeafNode> leafNodes, String toSearch, String... ends) {
	for (ILeafNode leafNode : leafNodes) {
		String text = leafNode.getText();
		int offset = leafNode.getOffset();
		int position = text.indexOf(toSearch);
		int textLength = text.length();
		while (position != -1) {
			int beginIndex = position + toSearch.length();
			// Skip leading whitespaces
			if(Character.isWhitespace(text.charAt(beginIndex))){
				while(beginIndex < textLength && Character.isWhitespace(text.charAt(beginIndex))){
					beginIndex ++;
				}
			}
			int endIndex = -1;
			for (int i = ends.length -1; i >= 0; i--) {
				String end = ends[i];
				int endCandidate = text.indexOf(end, beginIndex);
				if (endCandidate != -1)  {
					if (endIndex == -1) {
						endIndex = endCandidate;
					} else {
						if (endIndex > endCandidate) {
							endIndex = endCandidate;
						}
					}
				}
			}
			if (endIndex == -1) { 
				break;
			} else {
				String simpleName = text.substring(beginIndex, endIndex).replaceAll(" ", "");
				if(simpleName.length() > 0 && simpleName.matches("[0-9a-zA-Z\\.\\$_]*")){
					ReplaceRegion region = new ReplaceRegion(offset + beginIndex, simpleName.length(), simpleName);
					regions.add(region);
				}
			} 
			position = text.indexOf(toSearch, endIndex);
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:51,代码来源:MultiLineJavaDocTypeReferenceProvider.java


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