本文整理汇总了Java中org.eclipse.xtext.nodemodel.util.NodeModelUtils.findLeafNodeAtOffset方法的典型用法代码示例。如果您正苦于以下问题:Java NodeModelUtils.findLeafNodeAtOffset方法的具体用法?Java NodeModelUtils.findLeafNodeAtOffset怎么用?Java NodeModelUtils.findLeafNodeAtOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.nodemodel.util.NodeModelUtils
的用法示例。
在下文中一共展示了NodeModelUtils.findLeafNodeAtOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectAllResolutions
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
* CollectAll resolutions under the cursor at offset.
*
*/
List<IssueResolution> collectAllResolutions(XtextResource resource, RegionWithCursor offset,
Multimap<Integer, Issue> offset2issue) {
EObject script = resource.getContents().get(0);
ICompositeNode scriptNode = NodeModelUtils.getNode(script);
ILeafNode offsetNode = NodeModelUtils.findLeafNodeAtOffset(scriptNode, offset.getGlobalCursorOffset());
int offStartLine = offsetNode.getTotalStartLine();
List<Issue> allIssues = QuickFixTestHelper.extractAllIssuesInLine(offStartLine, offset2issue);
List<IssueResolution> resolutions = Lists.newArrayList();
for (Issue issue : allIssues) {
if (issue.getLineNumber() == offsetNode.getStartLine()
&& issue.getLineNumber() <= offsetNode.getEndLine()) {
Display.getDefault().syncExec(() -> resolutions.addAll(quickfixProvider.getResolutions(issue)));
}
}
return resolutions;
}
示例2: getLocationData
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Override
protected IssueLocation getLocationData(EObject obj, EStructuralFeature structuralFeature, int index) {
if (NodeModelUtils.getNode(obj) == null) {
ITextRegion location = locationInFileProvider.getSignificantTextRegion(obj);
if (location != null) {
ICompositeNode rootNode = NodeModelUtils.getNode(EcoreUtil.getRootContainer(obj));
if (rootNode != null) {
ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(rootNode, location.getOffset());
return getLocationForNode(leafNode);
}
} else {
return super.getLocationData(obj.eContainer(), null, index);
}
}
return super.getLocationData(obj, structuralFeature, index);
}
示例3: getCrossReferenceNode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的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;
}
示例4: internalResolveElementAt
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的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;
}
示例5: setUp
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
with(ReferenceGrammarTestLanguageStandaloneSetup.class);
model = "// comment before root\n" +
"\n" +
" spielplatz 0 \"Rummel\" {\n" +
" // comment belongs to next composite\n" +
" kind // inner comment\n" +
" ( Bob 1) // trailing comment\n" +
" // comment in next line\n" +
" }\n" +
"// comment after root\n";
rootNode = getRootNode(model);
kindLeaf = NodeModelUtils.findLeafNodeAtOffset(rootNode, model.indexOf("kind") + 1);
hiddenLeaf = kindLeaf.getNextSibling();
kindNode = kindLeaf.getParent();
}
示例6: testErrorMarkers
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void testErrorMarkers() throws Exception {
with(ReferenceGrammarTestLanguageStandaloneSetup.class);
// model contains an error due to missing ) at idx 23
String model = "spielplatz 1 {kind (k 1}";
XtextResource resource = getResourceFromStringAndExpect(model, 1);
assertEquals(1, resource.getErrors().size());
assertEquals(1, Iterables.size(resource.getParseResult().getSyntaxErrors()));
ICompositeNode rootNode = resource.getParseResult().getRootNode();
ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(rootNode, model.length() - 1);
assertTrue(leaf.getSyntaxErrorMessage() != null);
// resource.update(23, 0, ")");
// assertTrue(resource.getParseResult().getParseErrors().isEmpty());
IParseResult reparse = reparse(resource.getParseResult(), 23, 0, ")");
rootNode = reparse.getRootNode();
String expectedFixedModel = "spielplatz 1 {kind (k 1)}";
String fixedModel = rootNode.getText();
assertEquals("serialized model as expected", expectedFixedModel, fixedModel);
resource = getResourceFromString(fixedModel);
assertEquals("full reparse is fine", 0, resource.getErrors().size());
assertFalse("partial reparse is fine", reparse.hasSyntaxErrors());
}
示例7: findEntryPoint
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
public ICompositeNode findEntryPoint(IParseResult parseResult, int offset) {
ICompositeNode rootNode = parseResult.getRootNode();
if (rootNode.getTotalLength() == offset) {
return null;
}
ILeafNode leafNode = NodeModelUtils.findLeafNodeAtOffset(rootNode, offset);
ICompositeNode parent = leafNode.getParent();
ICompositeNode result = findEntryPoint(parent, offset);
if (result != null) {
EObject grammarElement = result.getGrammarElement();
if (grammarElement instanceof AbstractElement) {
return result;
}
}
return null;
}
示例8: createHyperlinksByOffset
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void createHyperlinksByOffset(final XtextResource resource, final int offset, final IHyperlinkAcceptor acceptor) {
final IParseResult parseResult = resource.getParseResult();
if (parseResult == null || parseResult.getRootNode() == null) {
return; // Return, no need to call in super.createAdditionalHyperlinks
}
// Check if the current parse tree node represents an override keyword, in which case we want to link
// to the overridden rule
INode node = NodeModelUtils.findLeafNodeAtOffset(parseResult.getRootNode(), offset);
if (node != null && isOverrideKeyword(node.getGrammarElement())) {
Rule rule = (Rule) eObjectAtOffsetHelper.resolveElementAt(resource, offset);
Region region = new Region(node.getOffset(), node.getLength());
List<Rule> extendedRules = getExtendedRules(rule);
for (Rule extendedRule : extendedRules) {
createHyperlinksTo(resource, region, extendedRule, acceptor);
}
}
super.createHyperlinksByOffset(resource, offset, acceptor);
}
示例9: IEObjectCoveringRegion
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的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);
}
示例10: findActualSemanticObjectFor
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
public EObject findActualSemanticObjectFor(final ICompositeNode rootNode, final ITextRegion textRegion) {
ILeafNode leafNodeAtOffset = NodeModelUtils.findLeafNodeAtOffset(rootNode, textRegion.getOffset());
EObject semanticElementOffset = leafNodeAtOffset.getSemanticElement();
ICompositeNode actualOffsetNode = NodeModelUtils.findActualNodeFor(semanticElementOffset);
int _offset = textRegion.getOffset();
int _length = textRegion.getLength();
final int endOffset = (_offset + _length);
while (((actualOffsetNode.getParent() != null) && (actualOffsetNode.getTotalEndOffset() < endOffset))) {
actualOffsetNode = actualOffsetNode.getParent();
}
final EObject actualSemanticObj = actualOffsetNode.getSemanticElement();
return actualSemanticObj;
}
示例11: highlightAnnotation
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
protected void highlightAnnotation(XAnnotation annotation, IHighlightedPositionAcceptor acceptor, String highlightingConfiguration) {
JvmType annotationType = annotation.getAnnotationType();
if (annotationType != null && !annotationType.eIsProxy() && annotationType instanceof JvmAnnotationType) {
ICompositeNode xannotationNode = NodeModelUtils.findActualNodeFor(annotation);
if (xannotationNode != null) {
ILeafNode firstLeafNode = NodeModelUtils.findLeafNodeAtOffset(xannotationNode, xannotationNode.getOffset() );
if(firstLeafNode != null)
highlightNode(acceptor, firstLeafNode, highlightingConfiguration);
}
highlightReferenceJvmType(acceptor, annotation, XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, annotationType, highlightingConfiguration);
}
}
示例12: testFindActualSemanticObjectFor
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void testFindActualSemanticObjectFor() throws Exception {
String modelAsString = "actions attribute ref attr1 attr2;";
int idx = modelAsString.indexOf("attr1");
Model model = (Model) getModelAndExpect(modelAsString, 1); /* linking issue */
INode root = NodeModelUtils.getNode(model).getRootNode();
ILeafNode leafNodeAtOffset = NodeModelUtils.findLeafNodeAtOffset(root, idx);
assertEquals("attr1", leafNodeAtOffset.getText());
EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(leafNodeAtOffset);
assertSame(model.getAttributes().get(0), semanticObject);
}
示例13: testGetLinkedObjects
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
@Test public void testGetLinkedObjects() throws Exception {
XtextResource r = getResourceFromString("type TypeA extends TypeB type TypeB extends TypeA type AnotherType extends TypeA");
Main model = (Main) r.getParseResult().getRootASTElement();
ILeafNode leaf = NodeModelUtils.findLeafNodeAtOffset(r.getParseResult().getRootNode(), 6);
assertEquals(3, model.getTypes().size());
EObject context = model.getTypes().get(0);
Assignment asExtends = get(LangATestLanguageGrammarAccess.class).getTypeAccess().getExtendsAssignment_2_1();
CrossReference xref = (CrossReference) asExtends.getTerminal();
EReference ref = GrammarUtil.getReference(xref, context.eClass());
assertEquals(1, getLinkingService().getLinkedObjects(context, ref, leaf).size());
}
示例14: createContext
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的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);
}
示例15: isXbaseLocalVariableName
import org.eclipse.xtext.nodemodel.util.NodeModelUtils; //导入方法依赖的package包/类
/**
* Checks whether given EObject represents a Xbase local variable.
*
* @param eObject
* to be checked
* @return true if the given object does not represent a xbase local variable
*/
public boolean isXbaseLocalVariableName(final EObject eObject) {
INode semanticNode = NodeModelUtils.getNode(eObject);
if (semanticNode != null) {
INode leafNode = NodeModelUtils.findLeafNodeAtOffset(semanticNode, semanticNode.getTotalOffset());
AbstractRule containingRule = GrammarUtil.containingRule(leafNode.getGrammarElement());
if (leafNode != null && containingRule != null && "ValidID".equals(containingRule.getName())) {
return true;
}
}
return false;
}