Java Code Examples for org.eclipse.xtext.nodemodel.INode#getText()
The following examples show how to use
org.eclipse.xtext.nodemodel.INode#getText() .
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: XAbstractFeatureCallImplCustom.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public String getConcreteSyntaxFeatureName() { List<INode> list = NodeModelUtils.findNodesForFeature(this, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE); if (list.size()!=1) { if (feature == null || feature.eIsProxy()) return "<unkown>"; return String.format("<implicit: %s>", feature.getIdentifier()); } INode node = list.get(0); if (node instanceof ILeafNode) { return node.getText(); } StringBuilder result = new StringBuilder(); for(ILeafNode leafNode: node.getLeafNodes()) { if (!leafNode.isHidden()) result.append(leafNode.getText()); } return result.toString(); }
Example 2
Source File: GrammarUtil.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public static String getTypeRefName(TypeRef typeRef) { if (typeRef.getClassifier() != null) return typeRef.getClassifier().getName(); final ICompositeNode node = NodeModelUtils.getNode(typeRef); if (node != null) { final BidiIterator<INode> leafNodes = node.getAsTreeIterable().iterator(); while (leafNodes.hasPrevious()) { INode previous = leafNodes.previous(); if (previous instanceof ILeafNode && !((ILeafNode) previous).isHidden()) { String result = previous.getText(); if (result != null && result.startsWith("^")) { result = result.substring(1); } return result; } } } return null; }
Example 3
Source File: XtendJavaDocCompletionProposalComputer.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected boolean isValidPositionForTypeProposal(ContentAssistContext contentAssistContext){ INode currentNode = contentAssistContext.getCurrentNode(); String content = currentNode.getText(); int offsetInNode = contentAssistContext.getOffset() - currentNode.getOffset() - contentAssistContext.getPrefix().length(); String textInFront = content.substring(0, offsetInNode); int lastIndexOfLink = textInFront.lastIndexOf(IJavaDocTypeReferenceProvider.LINK_TAG_WITH_SUFFIX); if(lastIndexOfLink != -1){ if(textInFront.substring(lastIndexOfLink, offsetInNode).trim().equals(IJavaDocTypeReferenceProvider.LINK_TAG)) return true; } int lastIndexOfSee = textInFront.lastIndexOf(IJavaDocTypeReferenceProvider.SEE_TAG_WITH_SUFFIX); if(lastIndexOfSee != -1){ if(textInFront.substring(lastIndexOfSee, offsetInNode).trim().equals(IJavaDocTypeReferenceProvider.SEE_TAG)) return true; } return false; }
Example 4
Source File: XtendProposalProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public void completeInRichString(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { INode node = context.getCurrentNode(); ITextRegion textRegion = node.getTextRegion(); int offset = textRegion.getOffset(); int length = textRegion.getLength(); String currentNodeText = node.getText(); if (currentNodeText.startsWith("\u00BB") && offset + 1 <= context.getOffset() || currentNodeText.startsWith("'''") && offset + 3 <= context.getOffset()) { if (context.getOffset() > offset && context.getOffset() < offset + length) addGuillemotsProposal(context, acceptor); } else if (currentNodeText.startsWith("\u00AB\u00AB")) { try { IDocument document = context.getViewer().getDocument(); int nodeLine = document.getLineOfOffset(offset); int completionLine = document.getLineOfOffset(context.getOffset()); if (completionLine > nodeLine) { addGuillemotsProposal(context, acceptor); } } catch (BadLocationException e) { // ignore } } }
Example 5
Source File: XtendProposalProvider.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override public void completeMember_Exceptions(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { if (getXbaseCrossReferenceProposalCreator().isShowSmartProposals()) { INode lastCompleteNode = context.getLastCompleteNode(); if (lastCompleteNode instanceof ILeafNode && !((ILeafNode) lastCompleteNode).isHidden()) { if (lastCompleteNode.getLength() > 0 && lastCompleteNode.getTotalEndOffset() == context.getOffset()) { String text = lastCompleteNode.getText(); char lastChar = text.charAt(text.length() - 1); if (Character.isJavaIdentifierPart(lastChar)) { return; } } } getTypesProposalProvider().createSubTypeProposals( typeReferences.findDeclaredType(Throwable.class, model), this, context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, createVisibilityFilter(context, IJavaSearchConstants.CLASS), getQualifiedNameValueConverter(), acceptor); } else { super.completeJvmParameterizedTypeReference_Type(model, assignment, context, acceptor); } }
Example 6
Source File: DotSemanticHighlightingCalculator.java From gef with Eclipse Public License 2.0 | 6 votes |
private void provideHighlightingForArrowTypeString(INode node, IHighlightedPositionAcceptor acceptor) { String arrowTypeString = node.getText(); int offset = node.getOffset(); String suffix = null; // quoted attribute value if (arrowTypeString.length() > 0 && arrowTypeString.charAt(0) == '"') { // trim the leading '"' and trailing '"' symbols arrowTypeString = arrowTypeString.substring(1, arrowTypeString.length() - 1); // increase offset correspondingly offset++; // adapt highlighting to quoted style suffix = DotHighlightingConfiguration.QUOTED_SUFFIX; } // delegate the highlighting of the the arrowType substring to the // corresponding sub-grammar highlighter DotSubgrammarHighlighter arrowTypeHighlighter = new DotSubgrammarHighlighter( DotActivator.ORG_ECLIPSE_GEF_DOT_INTERNAL_LANGUAGE_DOTARROWTYPE); arrowTypeHighlighter.provideHightlightingFor(arrowTypeString, offset, acceptor, suffix); }
Example 7
Source File: DotHtmlLabelProposalProvider.java From gef with Eclipse Public License 2.0 | 6 votes |
private void proposeHtmlBgColorAttributeValues(ContentAssistContext context, ICompletionProposalAcceptor acceptor) { INode currentNode = context.getCurrentNode(); String fullText = currentNode.getText(); String text = fullText; int beginReplacementOffset = currentNode.getOffset(); if (context.getPrefix().contains(":")) { //$NON-NLS-1$ int colonOffset = fullText.indexOf(':') + 1; text = fullText.substring(colonOffset); beginReplacementOffset += colonOffset; } else { beginReplacementOffset += beginsWithQuote(text) ? 1 : 0; } proposeHtmlColorAttributeValues(context, acceptor, text.replaceAll("['\"]", ""), //$NON-NLS-1$ //$NON-NLS-2$ beginReplacementOffset, context.getOffset()); if (!fullText.contains(":")) { //$NON-NLS-1$ acceptor.accept(new ConfigurableCompletionProposal(":", //$NON-NLS-1$ context.getOffset(), 0, 1)); } }
Example 8
Source File: SerializerTester.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected String getTextFromNodeModel(EObject semanticObject) { Resource res = semanticObject.eResource(); if (res instanceof XtextResource && res.getContents().contains(semanticObject)) return ((XtextResource) res).getParseResult().getRootNode().getText(); INode node = NodeModelUtils.getNode(semanticObject); Assert.assertNotNull(node); return node.getText(); }
Example 9
Source File: DebugSequenceAcceptor.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String node2text(INode node) { if (node == null) return "(node is null)"; if (node instanceof ILeafNode) return titles.doSwitch(node.getGrammarElement()) + " -> " + node.getText(); if (node instanceof ICompositeNode) return titles.doSwitch(node.getGrammarElement()); return "(unknown node)"; }
Example 10
Source File: SingleLineCommentDocumentationProvider.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Get single line comments before the context element. The returned documentation is never {@code null}. * <p> * {@inheritDoc} */ @Override public String getDocumentation(final EObject context) { StringBuilder builder = new StringBuilder(); for (INode node : getDocumentationNodes(context)) { String comment = node.getText(); builder.append(extractDocumentation(comment)); } return builder.toString(); }
Example 11
Source File: DebugSequenceAcceptor.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected String node2text(INode node) { if (node == null) return "(node is null)"; if (node instanceof ILeafNode) return titles.doSwitch(node.getGrammarElement()) + " -> " + node.getText(); if (node instanceof ICompositeNode) return titles.doSwitch(node.getGrammarElement()); return "(unknown node)"; }
Example 12
Source File: BaseContentAssistParser.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected boolean appendTextToParse(ICompositeNode node, int offset, boolean skipOptional, StringBuilder result) { for (INode child : node.getChildren()) { if (child instanceof ILeafNode) { String text = child.getText(); if (child.getTotalEndOffset() >= offset) { String sub = text.substring(0, offset - child.getTotalOffset()); result.append(sub); return true; } else { result.append(text); } } else { if (!skipOptional) { if (appendTextToParse((ICompositeNode) child, offset, child.getTotalEndOffset() < offset, result)) { return true; } } else { String skippedAs = getReplacement((ICompositeNode) child); if (skippedAs != null) { result.append(skippedAs); } else { if (appendTextToParse((ICompositeNode) child, offset, true, result)) { return true; } } } } } return false; }
Example 13
Source File: ProposalConflictHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public boolean existsConflict(INode lastCompleteNode, int offset, String proposal, ContentAssistContext context) { String lastCompleteText = lastCompleteNode.getText(); int endOffset = offset - lastCompleteNode.getTotalOffset(); lastCompleteText = lastCompleteText.substring(0, Math.max(endOffset, 0)); if (Strings.isEmpty(lastCompleteText)) return false; return existsConflict(lastCompleteText, proposal, context); }
Example 14
Source File: KeywordSerializer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public String serializeAssignedKeyword(EObject context, Keyword keyword, Object value, INode node, Acceptor errorAcceptor) { if (node != null && node.getGrammarElement() == keyword) return node.getText(); return keyword.getValue(); }
Example 15
Source File: SerializerTester.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected String getTextFromNodeModel(EObject semanticObject) { Resource res = semanticObject.eResource(); if (res instanceof XtextResource && res.getContents().contains(semanticObject)) return ((XtextResource) res).getParseResult().getRootNode().getText(); INode node = NodeModelUtils.getNode(semanticObject); Assert.assertNotNull(node); return node.getText(); }
Example 16
Source File: ValidatingRichStringAcceptor.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected void resetCurrentOffset(/* @Nullable */ RichStringLiteral origin) { if (root == null) root = origin; if (origin != null && origin != recent) { if (wasCurrentOffset == -1) wasCurrentOffset = currentOffset; int diff = lastOffsetOfLiteral - currentOffset; // no actions are involved, we are interested in the real node recent = origin; List<INode> featureNodes = NodeModelUtils.findNodesForFeature(origin, XbasePackage.Literals.XSTRING_LITERAL__VALUE); if (featureNodes.size() == 1) { INode node = featureNodes.get(0); ITextRegion textRegion = node.getTextRegion(); currentOffset = textRegion.getOffset(); String nodeText = node.getText(); if (nodeText.endsWith("'''")) { lastOffsetOfLiteral = currentOffset + textRegion.getLength() - 3; } else if (nodeText.endsWith("''")) { lastOffsetOfLiteral = currentOffset + textRegion.getLength() - 2; } else if (nodeText.endsWith("'") || nodeText.endsWith("\u00AB")) { lastOffsetOfLiteral = currentOffset + textRegion.getLength() - 1; } if (nodeText.charAt(0) == '\'') { currentOffset += 3; } else { currentOffset += 1; } } currentOffset -= diff; } }
Example 17
Source File: SerializerTestHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected String getTextFromNodeModel(EObject semanticObject) { Resource res = semanticObject.eResource(); if (res instanceof XtextResource && res.getContents().contains(semanticObject)) return ((XtextResource) res).getParseResult().getRootNode().getText(); INode node = NodeModelUtils.getNode(semanticObject); Assert.assertNotNull(node); return node.getText(); }
Example 18
Source File: ProposalConflictHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public boolean existsConflict(INode lastCompleteNode, int offset, String proposal, ContentAssistContext context) { String lastCompleteText = lastCompleteNode.getText(); int endOffset = offset - lastCompleteNode.getTotalOffset(); lastCompleteText = lastCompleteText.substring(0, Math.max(endOffset, 0)); if (Strings.isEmpty(lastCompleteText)) return false; return existsConflict(lastCompleteText, proposal, context); }
Example 19
Source File: IgnoreCaseKeywordSerializer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@Override public String serializeAssignedKeyword(EObject context, Keyword keyword, Object value, INode node, Acceptor errorAcceptor) { if (node != null && node.getGrammarElement() == keyword) return node.getText(); return keyword.getValue(); }
Example 20
Source File: AbstractSyntacticSequencer.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
@SuppressWarnings("deprecation") protected void accept(ISynState emitter, INode node, RuleCallStack stack) { switch (emitter.getType()) { case UNASSIGNED_PARSER_RULE_ENTER: RuleCall rc1 = (RuleCall) emitter.getGrammarElement(); delegate.enterUnassignedParserRuleCall(rc1); stack.push(rc1); return; case UNASSIGNED_PARSER_RULE_EXIT: RuleCall rc2 = (RuleCall) emitter.getGrammarElement(); delegate.leaveUnssignedParserRuleCall(rc2); RuleCall lastRc = stack.pop(); if (lastRc != rc2) { if (errorAcceptor != null) errorAcceptor.accept(diagnosticProvider.createUnexpectedStackStateDiagnostic( contexts.get(contexts.size() - 1).semanticObject, stack, lastRc, emitter)); } return; case UNASSIGEND_ACTION_CALL: delegate.acceptUnassignedAction((Action) emitter.getGrammarElement()); return; case UNASSIGEND_KEYWORD: Keyword keyword = (Keyword) emitter.getGrammarElement(); String token = node != null ? node.getText() : keyword.getValue(); delegate.acceptUnassignedKeyword(keyword, token, (ILeafNode) node); return; case UNASSIGNED_DATATYPE_RULE_CALL: RuleCall rc3 = (RuleCall) emitter.getGrammarElement(); String value3 = getUnassignedRuleCallToken(rc3, node); delegate.acceptUnassignedDatatype(rc3, value3, (ICompositeNode) node); return; case UNASSIGNED_TERMINAL_RULE_CALL: RuleCall rc4 = (RuleCall) emitter.getGrammarElement(); String value4 = getUnassignedRuleCallToken(rc4, node); delegate.acceptUnassignedTerminal(rc4, value4, (ILeafNode) node); return; case ASSIGNED_ACTION_CALL: case ASSIGNED_BOOLEAN_KEYWORD: case ASSIGNED_CROSSREF_DATATYPE_RULE_CALL: case ASSIGNED_CROSSREF_ENUM_RULE_CALL: case ASSIGNED_CROSSREF_KEYWORD: case ASSIGNED_CROSSREF_TERMINAL_RULE_CALL: case ASSIGNED_DATATYPE_RULE_CALL: case ASSIGNED_ENUM_RULE_CALL: case ASSIGNED_KEYWORD: case ASSIGNED_PARSER_RULE_CALL: case ASSIGNED_TERMINAL_RULE_CALL: case START: case STOP: case TRANSITION: } throw new RuntimeException("invalid state for emitting: " + emitter + " (" + emitter.getType() + ")"); }