Java Code Examples for org.eclipse.xtext.nodemodel.ICompositeNode#getEndOffset()
The following examples show how to use
org.eclipse.xtext.nodemodel.ICompositeNode#getEndOffset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void completeXFeatureCall_Feature(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { if (model != null) { if (typeResolver.resolveTypes(model).hasExpressionScope(model, IExpressionScope.Anchor.WITHIN)) { return; } } if (model instanceof XMemberFeatureCall) { ICompositeNode node = NodeModelUtils.getNode(model); int endOffset = node.getEndOffset(); if (isInMemberFeatureCall(model, endOffset, context)) { return; } } createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor); }
Example 2
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void completeXBasicForLoopExpression_InitExpressions(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { ICompositeNode node = NodeModelUtils.getNode(model); if (node.getOffset() >= context.getOffset()) { createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor); return; } if (model instanceof XBasicForLoopExpression) { List<XExpression> children = ((XBasicForLoopExpression) model).getInitExpressions(); if (!children.isEmpty()) { for(int i = children.size() - 1; i >= 0; i--) { XExpression child = children.get(i); ICompositeNode childNode = NodeModelUtils.getNode(child); if (childNode.getEndOffset() <= context.getOffset()) { createLocalVariableAndImplicitProposals(child, IExpressionScope.Anchor.AFTER, context, acceptor); return; } } } } createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor); }
Example 3
Source File: XbaseQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected int[] getOffsetAndLength(XIfExpression ifExpression, ICompositeNode node) { int offset = node.getOffset(); int length = node.getLength(); if (ifExpression.getElse() != null) { ICompositeNode elseNode = NodeModelUtils.findActualNodeFor(ifExpression.getElse()); if (elseNode != null) { length = elseNode.getOffset() - offset; } } else { XIfExpression parentIfExpression = EcoreUtil2.getContainerOfType(ifExpression.eContainer(), XIfExpression.class); if (parentIfExpression != null && parentIfExpression.getElse() == ifExpression) { ICompositeNode thenNode = NodeModelUtils.findActualNodeFor(parentIfExpression.getThen()); if (thenNode != null) { int endOffset = thenNode.getEndOffset(); length = length + (offset - endOffset); offset = endOffset; } } } return new int[] { offset, length }; }
Example 4
Source File: InsertionOffsets.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected int inEmpty(final XtendTypeDeclaration ownerType) { int _xblockexpression = (int) 0; { final ICompositeNode classNode = NodeModelUtils.findActualNodeFor(ownerType); final Function1<ILeafNode, Boolean> _function = (ILeafNode it) -> { String _text = it.getText(); return Boolean.valueOf(Objects.equal(_text, "{")); }; final ILeafNode openingBraceNode = IterableExtensions.<ILeafNode>findFirst(classNode.getLeafNodes(), _function); int _xifexpression = (int) 0; if ((openingBraceNode != null)) { int _offset = openingBraceNode.getOffset(); _xifexpression = (_offset + 1); } else { _xifexpression = classNode.getEndOffset(); } _xblockexpression = _xifexpression; } return _xblockexpression; }
Example 5
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void completeXBasicForLoopInit(final EObject model, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { final ICompositeNode node = NodeModelUtils.getNode(model); int _offset = node.getOffset(); int _offset_1 = context.getOffset(); boolean _greaterEqualsThan = (_offset >= _offset_1); if (_greaterEqualsThan) { this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor); return; } if ((model instanceof XBasicForLoopExpression)) { final EList<XExpression> children = ((XBasicForLoopExpression)model).getInitExpressions(); for (int i = (children.size() - 1); (i >= 0); i--) { { final XExpression child = children.get(i); final ICompositeNode childNode = NodeModelUtils.getNode(child); int _endOffset = childNode.getEndOffset(); int _offset_2 = context.getOffset(); boolean _lessEqualsThan = (_endOffset <= _offset_2); if (_lessEqualsThan) { this.createLocalVariableAndImplicitProposals(child, IExpressionScope.Anchor.AFTER, context, acceptor); return; } } } } this.createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor); }
Example 6
Source File: XbaseProposalProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void completeWithinBlock(EObject model, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { ICompositeNode node = NodeModelUtils.getNode(model); if (node.getOffset() >= context.getOffset()) { createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor); return; } if (model instanceof XBlockExpression) { List<XExpression> children = ((XBlockExpression) model).getExpressions(); if (!children.isEmpty()) { for(int i = children.size() - 1; i >= 0; i--) { XExpression child = children.get(i); ICompositeNode childNode = NodeModelUtils.getNode(child); if (childNode.getEndOffset() <= context.getOffset()) { createLocalVariableAndImplicitProposals(child, IExpressionScope.Anchor.AFTER, context, acceptor); return; } } } } int endOffset = node.getEndOffset(); if (endOffset <= context.getOffset()) { if (model instanceof XFeatureCall && model.eContainer() instanceof XClosure || endOffset == context.getOffset() && context.getPrefix().length() == 0) return; if (isInMemberFeatureCall(model, endOffset, context)) return; createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.AFTER, context, acceptor); return; } else if (isInMemberFeatureCall(model, endOffset, context)) { return; } if (model instanceof XClosure) return; createLocalVariableAndImplicitProposals(model, IExpressionScope.Anchor.BEFORE, context, acceptor); }
Example 7
Source File: InsertionOffsets.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public int inEmpty(EObject element) { ICompositeNode compositeNode = NodeModelUtils.findActualNodeFor(element); for (ILeafNode leafNode : compositeNode.getLeafNodes()) { if ("{".equals(leafNode.getText())) { return leafNode.getOffset() + 1; } } return compositeNode.getEndOffset(); }
Example 8
Source File: ExtractMethodHandler.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void updateSelection(final XtextEditor editor, List<XExpression> expressions) { ICompositeNode firstNode = NodeModelUtils.getNode(expressions.get(0)); ICompositeNode lastNode = NodeModelUtils.getNode(expressions.get(expressions.size() - 1)); if (firstNode != null && lastNode != null) { int correctedSelectionOffset = firstNode.getOffset(); int correctedSelectionLength = lastNode.getEndOffset() - correctedSelectionOffset; editor.selectAndReveal(correctedSelectionOffset, correctedSelectionLength); } }
Example 9
Source File: InsertionOffsets.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected int after(final EObject element) { int _xblockexpression = (int) 0; { final ICompositeNode node = NodeModelUtils.findActualNodeFor(element); _xblockexpression = node.getEndOffset(); } return _xblockexpression; }
Example 10
Source File: AbstractParseTreeConstructor.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected void assignNodesByMatching(Map<EObject, AbstractToken> eObject2Token, ICompositeNode rootNode, Map<ILeafNode, EObject> comments) throws IOException { NodeIterator contents = new NodeIterator(rootNode); while (contents.hasNext()) { INode containedNode = contents.next(); AbstractRule rule = containedNode.getGrammarElement() instanceof AbstractRule ? (AbstractRule) containedNode .getGrammarElement() : null; if (hiddenTokenHelper.isWhitespace(rule)) continue; else if (containedNode instanceof ILeafNode && hiddenTokenHelper.isComment(rule)) assignComment((ILeafNode) containedNode, eObject2Token, comments); else if (tokenUtil.isToken(containedNode)) { Pair<List<ILeafNode>, List<ILeafNode>> leadingAndTrailingHiddenTokens = tokenUtil .getLeadingAndTrailingHiddenTokens(containedNode); for (ILeafNode leadingHiddenNode : leadingAndTrailingHiddenTokens.getFirst()) { if (tokenUtil.isCommentNode(leadingHiddenNode)) { assignComment(leadingHiddenNode, eObject2Token, comments); } } assignTokenByMatcher(containedNode, eObject2Token); for (ILeafNode trailingHiddenNode : leadingAndTrailingHiddenTokens.getSecond()) { if (tokenUtil.isCommentNode(trailingHiddenNode)) { assignComment(trailingHiddenNode, eObject2Token, comments); } } contents.prune(); ICompositeNode parentNode = containedNode.getParent(); while (parentNode != null && assignTokenDirect(parentNode, eObject2Token)) parentNode = parentNode.getParent(); if (containedNode.getOffset() > rootNode.getEndOffset()) { break; } } } }
Example 11
Source File: SARLQuickfixProvider.java From sarl with Apache License 2.0 | 5 votes |
/** Replies the index where import declaration could be inserted into the given container. * * @param script the script to consider for the insertion * @return the insertion index. */ public int getImportInsertOffset(SarlScript script) { final ICompositeNode node = NodeModelUtils.findActualNodeFor(script.getImportSection()); if (node == null) { final List<INode> children = NodeModelUtils.findNodesForFeature(script, XtendPackage.eINSTANCE.getXtendFile_Package()); if (children.isEmpty()) { return 0; } return children.get(0).getEndOffset(); } return node.getEndOffset(); }
Example 12
Source File: ReturnTypeAddModification.java From sarl with Apache License 2.0 | 5 votes |
@Override public void apply(EObject element, IModificationContext context) throws Exception { final XtendExecutable xtendExecutable = EcoreUtil2.getContainerOfType(element, XtendExecutable.class); final int insertPosition; if (xtendExecutable.getExpression() == null) { final ICompositeNode functionNode = NodeModelUtils.findActualNodeFor(xtendExecutable); if (functionNode == null) { throw new IllegalStateException("functionNode may not be null"); //$NON-NLS-1$ } insertPosition = functionNode.getEndOffset(); } else { final ICompositeNode expressionNode = NodeModelUtils.findActualNodeFor(xtendExecutable.getExpression()); if (expressionNode == null) { throw new IllegalStateException("expressionNode may not be null"); //$NON-NLS-1$ } insertPosition = expressionNode.getOffset(); } final ReplacingAppendable appendable = getTools().getAppendableFactory().create(context.getXtextDocument(), (XtextResource) xtendExecutable.eResource(), insertPosition, 0); if (xtendExecutable.getExpression() == null) { appendable.append(" "); //$NON-NLS-1$ } appendable.append(getTools().getGrammarAccess().getColonKeyword()); appendable.append(" "); //$NON-NLS-1$ appendable.append(this.expectedType); if (xtendExecutable.getExpression() != null) { appendable.append(" "); //$NON-NLS-1$ } appendable.commitChanges(); }
Example 13
Source File: TokenSequencePreservingPartialParsingHelper.java From xtext-extras with Eclipse Public License 2.0 | 4 votes |
@Override public IParseResult reparse(IParser parser, IParseResult previousParseResult, ReplaceRegion changedRegion) { if (isBrokenPreviousState(previousParseResult, changedRegion.getOffset())) { return fullyReparse(parser, previousParseResult, changedRegion); } ICompositeNode oldRootNode = previousParseResult.getRootNode(); Iterator<ILeafNode> leafNodes = oldRootNode.getLeafNodes().iterator(); ILeafNode leftNode = getLeftNode(leafNodes, changedRegion.getOffset()); if (leftNode == null) { return fullyReparse(parser, previousParseResult, changedRegion); } ILeafNode rightNode = getRightNode(leafNodes, changedRegion.getEndOffset()); if (rightNode == null) { return fullyReparse(parser, previousParseResult, changedRegion); } while(leafNodes.hasNext()) { if (leafNodes.next().getSyntaxErrorMessage() != null) { return fullyReparse(parser, previousParseResult, changedRegion); } } String originalText = oldRootNode.getText().substring(leftNode.getTotalOffset()); StringBuilder newTextBuilder = new StringBuilder(originalText); changedRegion.shiftBy(-leftNode.getTotalOffset()).applyTo(newTextBuilder); String newText = newTextBuilder.toString(); if (originalText.equals(newText)) { // nothing to do return previousParseResult; } int originalLength = rightNode.getTotalEndOffset() - leftNode.getTotalOffset(); int expectedLength = originalLength - changedRegion.getLength() + changedRegion.getText().length(); if (!isSameTokenSequence(originalText.substring(0, originalLength), newText, expectedLength)) { // different token sequence, cannot perform a partial parse run return fullyReparse(parser, previousParseResult, changedRegion); } PartialParsingPointers parsingPointers = calculatePartialParsingPointers(oldRootNode, leftNode, rightNode); ICompositeNode replaceMe = getReplacedNode(parsingPointers); if (replaceMe == null || replaceMe == oldRootNode || replaceMe.getOffset() == 0 && replaceMe.getEndOffset() == oldRootNode.getLength()) { return fullyReparse(parser, previousParseResult, changedRegion); } String reparseRegion = insertChangeIntoReplaceRegion(replaceMe, changedRegion); EObject oldSemanticElement = getOldSemanticElement(replaceMe, parsingPointers); if (oldSemanticElement == null) return fullyReparse(parser, previousParseResult, changedRegion); if (oldSemanticElement == replaceMe.getParent().getSemanticElement()) { throw new IllegalStateException("oldParent == oldElement"); } IParseResult newParseResult = doParseRegion(parser, parsingPointers, replaceMe, reparseRegion); if (newParseResult == null) { throw new IllegalStateException("Could not perform a partial parse operation"); } replaceOldSemanticElement(oldSemanticElement, previousParseResult, newParseResult); nodeModelBuilder.replaceAndTransferLookAhead(replaceMe, newParseResult.getRootNode()); ((ParseResult) newParseResult).setRootNode(oldRootNode); StringBuilder builder = new StringBuilder(oldRootNode.getText()); changedRegion.applyTo(builder); nodeModelBuilder.setCompleteContent(oldRootNode, builder.toString()); return newParseResult; }