Java Code Examples for org.eclipse.xtext.util.ITextRegion#EMPTY_REGION
The following examples show how to use
org.eclipse.xtext.util.ITextRegion#EMPTY_REGION .
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: OutlineNodeElementOpener.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public void open(IOutlineNode node, ISourceViewer textViewer) { if (node != null) { ITextRegion textRegion = node.getSignificantTextRegion(); if (textRegion != null && textRegion != ITextRegion.EMPTY_REGION) { int offset = textRegion.getOffset(); int length = textRegion.getLength(); textViewer.setRangeIndication(offset, length, true); textViewer.revealRange(offset, length); textViewer.setSelectedRange(offset, length); } else { node.tryReadOnly(new IUnitOfWork.Void<EObject>() { @Override public void process(EObject state) throws Exception { openEObject(state); } }); } } }
Example 2
Source File: DefaultLocationInFileProvider.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.3 */ protected ITextRegion createRegion(List<INode> nodes, RegionDescription query) { if (query == RegionDescription.FULL || query == RegionDescription.SIGNIFICANT) return createRegion(nodes); ITextRegion result = ITextRegion.EMPTY_REGION; for (INode node : nodes) { for(INode leafNode: node.getLeafNodes()) { if (!isHidden(leafNode, query)) { ITextRegionWithLineInformation region = leafNode.getTextRegionWithLineInformation(); if (region.getLength() != 0) { result = result.merge(toZeroBasedRegion(region)); } } } } return result; }
Example 3
Source File: AbstractParseTreeConstructor.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override public TreeConstructionReport serializeSubtree(EObject object, ITokenStream out) throws IOException { TreeConstructionReportImpl report = createReport(object); AbstractToken root = serialize(object, report); Set<ICompositeNode> roots = Sets.newHashSet(); Map<EObject, AbstractToken> obj2token = Maps.newHashMap(); collectRootsAndEObjects(root, obj2token, roots); // dump("", root); Map<ILeafNode, EObject> comments = commentAssociater.associateCommentsWithSemanticEObjects(object, roots); for (ICompositeNode r : roots) assignNodesByMatching(obj2token, r, comments); WsMergerStream wsout = new WsMergerStream(out); // dump("", root); // System.out.println(EmfFormatter.objToStr(roots.iterator().next(), // ParsetreePackage.Literals.ABSTRACT_NODE__TOTAL_LENGTH, // ParsetreePackage.Literals.ABSTRACT_NODE__TOTAL_OFFSET, // ParsetreePackage.Literals.ABSTRACT_NODE__TOTAL_LINE, ParsetreePackage.Literals.ABSTRACT_NODE__PARENT)); ITextRegion previousLocation = ITextRegion.EMPTY_REGION; initStream(root, wsout); previousLocation = write(root, wsout, previousLocation); wsout.flush(); report.setPreviousLocation(previousLocation); return report; }
Example 4
Source File: TreeAppendableUtil.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public ITreeAppendable traceSignificant(ITreeAppendable appendable, EObject source, boolean useForDebugging) { if (appendable instanceof TreeAppendable) { return ((TreeAppendable) appendable).trace(source, ILocationInFileProviderExtension.RegionDescription.SIGNIFICANT, useForDebugging); } else { ITextRegionWithLineInformation it = (ITextRegionWithLineInformation) locationProvider .getSignificantTextRegion(source); if (it != null && it != ITextRegion.EMPTY_REGION) { return appendable.trace(new LocationData(it.getOffset(), it.getLength(), it.getLineNumber(), it.getEndLineNumber(), null), useForDebugging); } else { return appendable; } } }
Example 5
Source File: AbstractOutlineNode.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * A {@link BackgroundOutlineTreeProvider} must use * {@link #AbstractOutlineNode(IOutlineNode, ImageDescriptor, Object, boolean)} instead. */ protected AbstractOutlineNode(IOutlineNode parent, Image image, Object text, boolean isLeaf) { this.text = text == null ? "<unnamed>" : text; this.image = image; this.isLeaf = isLeaf; setParent(parent); textRegion = ITextRegion.EMPTY_REGION; }
Example 6
Source File: AbstractOutlineNode.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.4 */ protected AbstractOutlineNode(IOutlineNode parent, ImageDescriptor imageDescriptor, Object text, boolean isLeaf) { this.text = text == null ? "<unnamed>" : text; this.imageDescriptor = imageDescriptor; this.isLeaf = isLeaf; setParent(parent); textRegion = ITextRegion.EMPTY_REGION; }
Example 7
Source File: AstSelectionProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public ITextRegion selectLast(XtextResource resource, ITextRegion currentEditorSelection) { if (selectionHistory.isEmpty()) { return ITextRegion.EMPTY_REGION; } if (!currentEditorSelection.equals(selectionHistory.pop())) { selectionHistory.clear(); return ITextRegion.EMPTY_REGION; } return selectionHistory.isEmpty() ? ITextRegion.EMPTY_REGION : selectionHistory.peek(); }
Example 8
Source File: AstSelectionProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public ITextRegion selectEnclosing(XtextResource resource, ITextRegion currentEditorSelection) { Pair<EObject, EObject> currentlySelected = getSelectedAstElements(resource, currentEditorSelection); if (currentlySelected == null) { IParseResult parseResult = resource.getParseResult(); if (parseResult != null) { ICompositeNode rootNode = parseResult.getRootNode(); int offset = getSelectionOffset(rootNode, currentEditorSelection); INode node = findLeafNodeAtOffset(rootNode, offset); if (node != null) { ITextRegion fineGrainedRegion = computeInitialFineGrainedSelection(node, currentEditorSelection); if (fineGrainedRegion != null) { selectionHistory.clear(); register(currentEditorSelection); return register(fineGrainedRegion); } EObject eObject = findSemanticObjectFor(node); return register(getTextRegion(eObject)); } } } else { EObject first = currentlySelected.getFirst(); if (first.eContainer() != null) { return register(getTextRegion(first.eContainer())); } } return ITextRegion.EMPTY_REGION; }
Example 9
Source File: AstSelectionProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public ITextRegion selectNext(XtextResource resource, ITextRegion currentEditorSelection) { Pair<EObject, EObject> currentlySelected = getSelectedAstElements(resource, currentEditorSelection); if (currentlySelected == null) { return selectEnclosing(resource, currentEditorSelection); } EObject second = currentlySelected.getSecond(); EObject nextSibling = EcoreUtil2.getNextSibling(second); if (nextSibling != null) { return register(getRegion(Tuples.create(currentlySelected.getFirst(), nextSibling))); } else { if (second.eContainer() == null) return ITextRegion.EMPTY_REGION; return register(getRegion(Tuples.create(second.eContainer(), second.eContainer()))); } }
Example 10
Source File: AstSelectionProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public ITextRegion selectPrevious(XtextResource resource, ITextRegion currentEditorSelection) { Pair<EObject, EObject> currentlySelected = getSelectedAstElements(resource, currentEditorSelection); if (currentlySelected == null) { return selectEnclosing(resource, currentEditorSelection); } EObject first = currentlySelected.getFirst(); EObject previousSibling = EcoreUtil2.getPreviousSibling(first); if (previousSibling != null) { return register(getRegion(Tuples.create(previousSibling,currentlySelected.getSecond()))); } else { if (first.eContainer() == null) return ITextRegion.EMPTY_REGION; return register(getRegion(Tuples.create(first.eContainer(), first.eContainer()))); } }
Example 11
Source File: AstSelectionProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected ITextRegion register(ITextRegion textRegion) { if (textRegion == null) { return ITextRegion.EMPTY_REGION; } if (selectionHistory.isEmpty() || !selectionHistory.peek().equals(textRegion)) { selectionHistory.push(textRegion); } return textRegion; }
Example 12
Source File: AstSelectionAction.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void run() { ITextSelection selection = (ITextSelection) xtextEditor.getSelectionProvider().getSelection(); ITextRegion currentEditorSelection = new TextRegion(selection.getOffset(), selection.getLength()); ITextRegion nextSelection = xtextEditor.getDocument().priorityReadOnly(createTextSelectionWork(currentEditorSelection)); if (nextSelection == null || nextSelection == ITextRegion.EMPTY_REGION || nextSelection.equals(currentEditorSelection)) { return; } xtextEditor.selectAndReveal(nextSelection.getOffset(), nextSelection.getLength()); }
Example 13
Source File: DefaultLocationInFileProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.3 */ protected ITextRegion doGetTextRegion(EObject obj, /* @NonNull */ RegionDescription query) { ICompositeNode node = findNodeFor(obj); if (node == null) { if (obj.eContainer() == null) return ITextRegion.EMPTY_REGION; return getTextRegion(obj.eContainer(), query); } List<INode> nodes = null; if (query == RegionDescription.SIGNIFICANT) nodes = getLocationNodes(obj); if (nodes == null || nodes.isEmpty()) nodes = Collections.<INode>singletonList(node); return createRegion(nodes, query); }
Example 14
Source File: DefaultLocationInFileProvider.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected ITextRegion createRegion(final List<INode> nodes) { ITextRegion result = ITextRegion.EMPTY_REGION; for (INode node : nodes) { if (!isHidden(node)) { ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation(); if (region.getLength() != 0) { result = result.merge(toZeroBasedRegion(region)); } } } return result; }
Example 15
Source File: AbstractSourceView.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
protected ITextRegion computeSelectedText(IWorkbenchPartSelection workbenchPartSelection) { return ITextRegion.EMPTY_REGION; }
Example 16
Source File: XtendLocationInFileProvider.java From xtext-xtend with Eclipse Public License 2.0 | 4 votes |
@Override public ITextRegion getSignificantTextRegion(EObject element) { if (element instanceof RichStringLiteral) { ICompositeNode elementNode = findNodeFor(element); if (elementNode == null) { return ITextRegion.EMPTY_REGION; } ITextRegion result = ITextRegion.EMPTY_REGION; for (INode node : elementNode.getLeafNodes()) { if (isHidden(node)) { continue; } EObject grammarElement = node.getGrammarElement(); if (!(grammarElement instanceof RuleCall)) { continue; } RuleCall ruleCall = (RuleCall) grammarElement; ITextRegionWithLineInformation region = node.getTextRegionWithLineInformation(); int offset = region.getOffset(); int length = region.getLength(); if (grammarAccess.getRICH_TEXTRule() == ruleCall.getRule()) { offset += 3; length -= 6; } else if (grammarAccess.getRICH_TEXT_STARTRule() == ruleCall.getRule()) { offset += 3; length -= 4; } else if (grammarAccess.getRICH_TEXT_ENDRule() == ruleCall.getRule()) { offset += 1; length -= 4; } else if (grammarAccess.getRICH_TEXT_INBETWEENRule() == ruleCall.getRule()) { offset += 1; length -= 2; } else if (grammarAccess.getCOMMENT_RICH_TEXT_ENDRule() == ruleCall.getRule()) { offset += 2; length -= 5; } else if (grammarAccess.getCOMMENT_RICH_TEXT_INBETWEENRule() == ruleCall.getRule()) { offset += 2; length -= 3; } else { continue; } result = result.merge(toZeroBasedRegion(new TextRegionWithLineInformation(offset, length, region.getLineNumber(), region.getEndLineNumber()))); } return result; } return super.getSignificantTextRegion(element); }