use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class DocumentExtensions method newPosition.
public Position newPosition(final Resource resource, final int offset) {
if ((resource instanceof XtextResource)) {
final ICompositeNode rootNode = ((XtextResource) resource).getParseResult().getRootNode();
final LineAndColumn lineAndColumn = NodeModelUtils.getLineAndColumn(rootNode, offset);
int _line = lineAndColumn.getLine();
int _minus = (_line - 1);
int _column = lineAndColumn.getColumn();
int _minus_1 = (_column - 1);
return new Position(_minus, _minus_1);
}
return null;
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class EntryPointFinder method normalizeToParent.
protected ICompositeNode normalizeToParent(ICompositeNode result) {
if (result == null) {
return result;
}
ICompositeNode parent = result.getParent();
while (parent != null && parent.getFirstChild().equals(result) && parent.getLookAhead() == result.getLookAhead()) {
result = parent;
parent = result.getParent();
}
return result;
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class DefaultHierarchyNodeLocationProvider method toTextRegionWithLineInformation.
protected ITextRegionWithLineInformation toTextRegionWithLineInformation(final EObject obj, final ITextRegion textRegion) {
if ((textRegion == null)) {
return ITextRegionWithLineInformation.EMPTY_REGION;
}
if ((textRegion instanceof ITextRegionWithLineInformation)) {
return ((ITextRegionWithLineInformation) textRegion);
}
final ICompositeNode node = NodeModelUtils.getNode(obj);
if ((node == null)) {
int _offset = textRegion.getOffset();
int _length = textRegion.getLength();
return new TextRegionWithLineInformation(_offset, _length, 0, 0);
}
int _line = NodeModelUtils.getLineAndColumn(node, textRegion.getOffset()).getLine();
final int startLine = (_line - 1);
int _offset_1 = textRegion.getOffset();
int _length_1 = textRegion.getLength();
int _plus = (_offset_1 + _length_1);
int _line_1 = NodeModelUtils.getLineAndColumn(node, _plus).getLine();
final int endLine = (_line_1 - 1);
int _offset_2 = textRegion.getOffset();
int _length_2 = textRegion.getLength();
return new TextRegionWithLineInformation(_offset_2, _length_2, startLine, endLine);
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class AbstractCompletePrefixProviderTest method assertLastCompleteNode.
private void assertLastCompleteNode(final String model, final String expectation) {
try {
int offset = model.indexOf("<|>");
if ((offset == (-1))) {
offset = model.length();
}
int completionOffset = model.indexOf("<|>", offset);
if ((completionOffset == (-1))) {
completionOffset = offset;
}
final Tree tree = this.parseHelper.parse(model.replace("<|>", ""));
final ICompositeNode nodeModel = NodeModelUtils.findActualNodeFor(tree);
final INode completeNode = this.getTestee().getLastCompleteNodeByOffset(nodeModel, offset, completionOffset);
this.assertNodeModel(expectation, completeNode);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.nodemodel.ICompositeNode in project xtext-core by eclipse.
the class BaseContentAssistParser method getFollowElements.
public Collection<FE> getFollowElements(IParseResult parseResult, EntryPointFinder entryPointFinder, int offset, boolean strict) {
ICompositeNode entryPoint = entryPointFinder.findEntryPoint(parseResult, offset);
if (entryPoint != null) {
String parseMe = getTextToParse(parseResult, entryPoint, offset);
TokenSource tokenSource = createTokenSource(parseMe);
InternalParser parser = createParser();
parser.setStrict(strict);
ObservableXtextTokenStream tokens = new ObservableXtextTokenStream(tokenSource, parser);
tokens.setInitialHiddenTokens(getInitialHiddenTokens());
parser.setTokenStream(tokens);
IUnorderedGroupHelper helper = createUnorderedGroupHelper();
parser.setUnorderedGroupHelper(helper);
helper.initializeWith(parser);
tokens.setListener(parser);
try {
Collection<FE> followElements = getFollowElements(parser, getEntryGrammarElement(entryPoint));
return Lists.newArrayList(followElements);
} catch (InfiniteRecursion infinite) {
return Lists.newArrayList(parser.getFollowElements());
}
} else {
String text = parseResult.getRootNode().getText();
String parseMe = text.substring(0, offset);
initializeFor(NodeModelUtils.getEntryParserRule(parseResult.getRootNode()));
Collection<FE> followElements = getFollowElements(parseMe, strict);
return followElements;
}
}
Aggregations