Java Code Examples for org.eclipse.xtext.nodemodel.ICompositeNode#getTotalLength()
The following examples show how to use
org.eclipse.xtext.nodemodel.ICompositeNode#getTotalLength() .
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: DefaultTextEditComposer.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public void beginRecording(Resource newResource) { reset(); if (newResource != resource) { if (resource != null) resource.eAdapters().remove(this); newResource.eAdapters().add(this); resource = newResource; } if (resource.getContents().isEmpty()) { resourceSize = 0; } else { final EObject root = resource.getContents().get(0); ICompositeNode rootNode = NodeModelUtils.getNode(root); if (rootNode == null) { throw new IllegalStateException("Cannot find root node in resource " + resource.getURI()); } resourceSize = rootNode.getTotalLength(); } recording = true; }
Example 2
Source File: PartialParsingHelper.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public PartialParsingPointers calculatePartialParsingPointers(IParseResult previousParseResult, final int offset, int replacedTextLength) { int myOffset = offset; int myReplacedTextLength = replacedTextLength; ICompositeNode oldRootNode = previousParseResult.getRootNode(); if (myOffset == oldRootNode.getTotalLength() && myOffset != 0) { // newText is appended, so look for the last original character instead --myOffset; myReplacedTextLength = 1; } // include any existing parse errors Range range = new Range(myOffset, myReplacedTextLength + myOffset); if (previousParseResult.hasSyntaxErrors()) range.mergeAllSyntaxErrors(oldRootNode); myOffset = range.getOffset(); List<ICompositeNode> nodesEnclosingRegion = collectNodesEnclosingChangeRegion(oldRootNode, range); List<ICompositeNode> validReplaceRootNodes = internalFindValidReplaceRootNodeForChangeRegion(nodesEnclosingRegion, range); filterInvalidRootNodes(oldRootNode, validReplaceRootNodes); if (validReplaceRootNodes.isEmpty()) { validReplaceRootNodes = Collections.singletonList(oldRootNode); } return new PartialParsingPointers(oldRootNode, myOffset, myReplacedTextLength, validReplaceRootNodes, nodesEnclosingRegion); }
Example 3
Source File: EntryPointFinder.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
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; }
Example 4
Source File: FixedPartialParsingHelper.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
public PartialParsingPointers calculatePartialParsingPointers(final IParseResult previousParseResult, final int offset, final int replacedTextLength) { int myOffset = offset; int myReplacedTextLength = replacedTextLength; ICompositeNode oldRootNode = previousParseResult.getRootNode(); if (myOffset == oldRootNode.getTotalLength() && myOffset != 0) { // newText is appended, so look for the last original character instead --myOffset; myReplacedTextLength = 1; } // include any existing parse errors Range range = new Range(myOffset, myReplacedTextLength + myOffset); if (previousParseResult.hasSyntaxErrors()) { range.mergeAllSyntaxErrors(oldRootNode); } myOffset = range.getOffset(); List<ICompositeNode> nodesEnclosingRegion = collectNodesEnclosingChangeRegion(oldRootNode, range); List<ICompositeNode> validReplaceRootNodes = internalFindValidReplaceRootNodeForChangeRegion(nodesEnclosingRegion, range); filterInvalidRootNodes(oldRootNode, validReplaceRootNodes); if (validReplaceRootNodes.isEmpty()) { validReplaceRootNodes = Collections.singletonList(oldRootNode); } return new PartialParsingPointers(oldRootNode, myOffset, myReplacedTextLength, validReplaceRootNodes, nodesEnclosingRegion); }
Example 5
Source File: EvaluatedTemplate.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public EvaluatedTemplate(Codetemplate template) { TemplateBody body = template.getBody(); StringBuilder buffer = new StringBuilder(); StringBuilder original = new StringBuilder(); mappedOffsetHints = Lists.newArrayList(); int lastOffset = 0; for(TemplatePart part: body.getParts()) { ICompositeNode node = NodeModelUtils.getNode(part); if (node != null) { mappedOffsetHints.add(Tuples.create(buffer.length(), node.getTotalOffset())); lastOffset = node.getTotalOffset() + node.getTotalLength(); original.append(node.getText()); if (part instanceof Literal) { buffer.append(((Literal) part).getValue()); } else if (part instanceof Dollar) { buffer.append("$"); } else if (part instanceof Variable) { if (((Variable) part).getName() != null) { buffer.append(((Variable) part).getName()); } } } } mappedOffsetHints.add(Tuples.create(buffer.length(), lastOffset)); evaluatedResult = buffer.toString(); originalTemplate = original.toString(); }
Example 6
Source File: InvariantChecker.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected int doCheckCompositeNodeAndReturnTotalLength(ICompositeNode node, int startsAt) { if (node.getTotalOffset() != startsAt) throw new InconsistentNodeModelException("node with unexpected offset"); int length = 0; Iterator<AbstractNode> iter = ((CompositeNode) node).basicGetChildren().iterator(); while(iter.hasNext()) { INode child = iter.next(); length += doCheckChildNodeAndReturnTotalLength(child, node, startsAt + length); } if (length != node.getTotalLength()) throw new InconsistentNodeModelException("node's computed length differs from actual total length"); return length; }
Example 7
Source File: Serializer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.22 */ protected int calculateReplaceRegionLength(ICompositeNode node, String text) { int oldTextLength = node.getTotalLength(); int newTextLength = text.length(); if (newTextLength > oldTextLength) { String remainingText = text.substring(oldTextLength); if (isWhitespace(remainingText) && hiddenNodeFollows(node)) { return newTextLength; } } return oldTextLength; }
Example 8
Source File: InvariantChecker.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected void doCheckInvariant(ICompositeNode rootNode) { int length = doCheckChildNodeAndReturnTotalLength(rootNode, null, 0); if (length != rootNode.getTotalLength()) throw new InconsistentNodeModelException("node's computed length differs from actual total length"); }