Java Code Examples for org.eclipse.xtext.nodemodel.ICompositeNode#hasDirectSemanticElement()
The following examples show how to use
org.eclipse.xtext.nodemodel.ICompositeNode#hasDirectSemanticElement() .
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: TokenSequencePreservingPartialParsingHelper.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected EObject getOldSemanticElement(ICompositeNode replaceMe, PartialParsingPointers parsingPointers) { EObject oldSemanticElement = null; if (replaceMe.hasDirectSemanticElement()) { oldSemanticElement = replaceMe.getSemanticElement(); } else { List<ICompositeNode> nodesEnclosingRegion = parsingPointers.getNodesEnclosingRegion(); for (int i = nodesEnclosingRegion.size() - 1; i >= 0; --i) { ICompositeNode enclosingNode = nodesEnclosingRegion.get(i); if (enclosingNode == replaceMe) { break; } if (enclosingNode.hasDirectSemanticElement()) oldSemanticElement = enclosingNode.getSemanticElement(); } } return oldSemanticElement; }
Example 2
Source File: AbstractCleaningLinker.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * @return true, if the parent node could contain cross references to the same semantic element as the given node. */ protected boolean shouldCheckParentNode(INode node) { EObject grammarElement = node.getGrammarElement(); if (grammarElement instanceof AbstractElement) { ICompositeNode parent = node.getParent(); if (parent != null) { if (!parent.hasDirectSemanticElement()) { if (isContainedInFragmentRule(grammarElement)) { return false; } Assignment assignment = GrammarUtil.containingAssignment(grammarElement); if (assignment == null) { return true; } } if (grammarElement instanceof Action) { if (isContainedInFragmentRule(grammarElement)) { return parent.getGrammarElement() instanceof RuleCall; } } } } return false; }
Example 3
Source File: N4JSQuickfixProvider.java From n4js with Eclipse Public License 1.0 | 5 votes |
private ICompositeNode findParentNodeWithSemanticElementOfType(ICompositeNode node, Class<?> semanticElementType) { ICompositeNode parentNode = node.getParent(); while (!parentNode.hasDirectSemanticElement() || !semanticElementType.isInstance(parentNode.getSemanticElement())) { parentNode = parentNode.getParent(); } return parentNode; }
Example 4
Source File: FlexerBasedContentAssistParser.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected String getReplacement(ICompositeNode node) { if (node.hasDirectSemanticElement()) { EObject semanticElement = node.getSemanticElement(); if (semanticElement instanceof XBlockExpression) { return "{}"; } } return null; }
Example 5
Source File: NodeModelUtils.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
/** * <p>Returns the node that covers all assigned values of the given object. It handles the semantics of {@link Action * actions} and {@link RuleCall unassigned rule calls}. The returned node will include unassigned surrounding leafs, * e.g. if you use something like {@code Parenthesized expressions} redundant parentheses will be part of the returned node.</p> * <p>Consider the following simple expression (a number literal): * <pre> * ((1)) * </pre> * Assuming it was parsed from a grammar like this: * <pre> * Expression: Number | Parentheses; * Parentheses: '(' Expression ')'; * Number: value=INT * </pre> * The actual node for the only semantic object that was produced from the input {@code ((1))} is the root node * even though the minimal node would be the one with the text {@code 1}. * * @param semanticObject the semantic object whose node should be provided. * @return the node that covers all assigned values of the given object. */ /* @Nullable */ public static ICompositeNode findActualNodeFor(/* @Nullable */ EObject semanticObject) { ICompositeNode node = getNode(semanticObject); if (node != null) { while(GrammarUtil.containingAssignment(node.getGrammarElement()) == null) { ICompositeNode parent = node.getParent(); if (parent != null && !parent.hasDirectSemanticElement() && !GrammarUtil.isEObjectFragmentRuleCall(parent.getGrammarElement())) { node = parent; } else { break; } } } return node; }