org.eclipse.xtext.nodemodel.INode Java Examples
The following examples show how to use
org.eclipse.xtext.nodemodel.INode.
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: XtendEObjectAtOffsetHelper.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
@Override protected EObject resolveCrossReferencedElement(INode node) { EObject referencedElement = super.resolveCrossReferencedElement(node); EObject referenceOwner = NodeModelUtils.findActualSemanticObjectFor(node); if(referenceOwner instanceof XConstructorCall) { if (referenceOwner.eContainer() instanceof AnonymousClass) { AnonymousClass anon = (AnonymousClass) referenceOwner.eContainer(); JvmGenericType superType = anonymousClassUtil.getSuperType(anon); if(superType != null) { if (referencedElement instanceof JvmGenericType) return superType; else if(referencedElement instanceof JvmConstructor) { if(superType.isInterface()) return superType; JvmConstructor superConstructor = anonymousClassUtil.getSuperTypeConstructor(anon); if(superConstructor != null) return superConstructor; } } } } return referencedElement; }
Example #2
Source File: AnonymousClassUtil.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
public JvmDeclaredType getSuperTypeNonResolving(AnonymousClass anonymousClass, IScope typeScope) { XConstructorCall constructorCall = anonymousClass.getConstructorCall(); EObject constructorProxy = (EObject) constructorCall.eGet(XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR, false); IEObjectDescription description = null; if (constructorProxy != null) { if (!constructorProxy.eIsProxy()) { return getSuperType(anonymousClass); } String fragment = EcoreUtil.getURI(constructorProxy).fragment(); INode node = uriEncoder.getNode(constructorCall, fragment); String name = linkingHelper.getCrossRefNodeAsString(node, true); QualifiedName superTypeName = qualifiedNameConverter.toQualifiedName(name); description = typeScope.getSingleElement(superTypeName); } if (description == null || !EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_DECLARED_TYPE, description.getEClass())) { description = typeScope.getSingleElement(QualifiedName.create("java", "lang", "Object")); } if (description != null && EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_DECLARED_TYPE, description.getEClass())) { JvmDeclaredType type = (JvmDeclaredType) description.getEObjectOrProxy(); if (!type.eIsProxy()) return type; return (JvmDeclaredType) EcoreUtil.resolve(type, anonymousClass); } return null; }
Example #3
Source File: NodeModelUtils.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public static ParserRule getEntryParserRule(INode node) { ICompositeNode root = node.getRootNode(); EObject ge1 = root.getGrammarElement(); if (ge1 instanceof ParserRule) { return (ParserRule) ge1; } else if (ge1 instanceof Action) { INode firstChild = root.getFirstChild(); while (firstChild.getGrammarElement() instanceof Action && firstChild instanceof CompositeNode) { firstChild = ((CompositeNode)firstChild).getFirstChild(); } EObject ge2 = firstChild.getGrammarElement(); if (ge2 instanceof ParserRule) { return (ParserRule) ge2; } } throw new IllegalStateException("No Root Parser Rule found; The Node Model is broken."); }
Example #4
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 #5
Source File: PartialContentAssistContextFactory.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Override protected void handleLastCompleteNodeIsAtEndOfDatatypeNode() { String prefix = getPrefix(lastCompleteNode); INode previousNode = getLastCompleteNodeByOffset(rootNode, lastCompleteNode.getOffset()); EObject previousModel = previousNode.getSemanticElement(); INode currentDatatypeNode = getContainingDatatypeRuleNode(currentNode); Collection<FollowElement> followElements = parseFollowElements(lastCompleteNode.getOffset(), false); int prevSize = contextBuilders.size(); doCreateContexts(previousNode, currentDatatypeNode, prefix, previousModel, followElements); if (lastCompleteNode instanceof ILeafNode && lastCompleteNode.getGrammarElement() == null && contextBuilders.size() != prevSize) { handleLastCompleteNodeHasNoGrammarElement(contextBuilders.subList(prevSize, contextBuilders.size()), previousModel); } }
Example #6
Source File: Bug437669Test.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
@Test public void testUnresolved_02() { Type type = getContext(); INode nameNode = NodeModelUtils.findNodesForFeature(type, ImportedURIPackage.Literals.TYPE__NAME).get(0); resolve(type, "BlaBlaBla", nameNode.getOffset(), nameNode.getLength()); Resource resource = type.eResource(); assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size()); LineAndColumn lineAndColumn = NodeModelUtils.getLineAndColumn(nameNode, nameNode.getOffset()); Diagnostic diagnostic = (Diagnostic) resource.getErrors().get(0); assertEquals(nameNode.getOffset(), diagnostic.getOffset()); assertEquals(nameNode.getLength(), diagnostic.getLength()); assertEquals(lineAndColumn.getLine(), diagnostic.getLine()); assertEquals(lineAndColumn.getColumn(), diagnostic.getColumn()); assertEquals("Couldn't resolve reference to Type 'BlaBlaBla'.", diagnostic.getMessage()); }
Example #7
Source File: N4JSDocHelper.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Get JSDoc comment for the given element. The element may be an AST node such as <code>N4MethodDeclaration</code> * or a type model element such as <code>TMethod</code>. In the latter case, this method will follow the link to the * AST which may cause a load of the N4JS resource if it is not fully loaded (i.e. if only the TModule was loaded * from the Xtext index). * <p> * Thus, <b>this method may have a side effect on the containing resource of the given element</b>. If that is not * desired, use method {@link #getDocSafely(ResourceSet, EObject)} instead. */ public String getDoc(EObject element) { if (element == null) throw new IllegalArgumentException("element must not be null"); if (element.eIsProxy()) { return null; // throw new IllegalArgumentException("element must not be proxy: " + element.toString()); } final List<INode> docNodes = documentationProviderExt.getDocumentationNodes(element); if (!docNodes.isEmpty()) { final StringBuilder sb = new StringBuilder(docNodes.get(0).getText()); for (int idx = 1; idx < docNodes.size(); idx++) { sb.append("\n").append(docNodes.get(idx).getText()); } return sb.toString(); } return null; }
Example #8
Source File: SequenceFeeder.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected void acceptRuleCall(RuleCall rc, Object value, String token, int index, INode node) { CrossReference crossRef = GrammarUtil.containingCrossReference(rc); if (crossRef != null) { if (rc.getRule() instanceof ParserRule) sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index, getCompositeNode(node)); else if (rc.getRule() instanceof TerminalRule) sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, getLeafNode(node)); else if (rc.getRule() instanceof EnumRule) sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, getCompositeNode(node)); } else { if (rc.getRule() instanceof ParserRule) { AbstractRule rule = rc.getRule(); if (rule.getType() != null && rule.getType().getClassifier() instanceof EClass) acceptEObjectRuleCall(rc, (EObject) value, getCompositeNode(node)); else sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, getCompositeNode(node)); } else if (rc.getRule() instanceof TerminalRule) sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, getLeafNode(node)); else if (rc.getRule() instanceof EnumRule) sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, getCompositeNode(node)); } }
Example #9
Source File: XbaseFormatter2.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
protected XClosure builder(final List<XExpression> params) { XClosure _xifexpression = null; XExpression _last = IterableExtensions.<XExpression>last(params); boolean _tripleNotEquals = (_last != null); if (_tripleNotEquals) { XClosure _xblockexpression = null; { INode _nodeForEObject = this._nodeModelAccess.nodeForEObject(IterableExtensions.<XExpression>last(params)); final EObject grammarElement = ((ICompositeNode) _nodeForEObject).getFirstChild().getGrammarElement(); XClosure _xifexpression_1 = null; if (((Objects.equal(grammarElement, this._xbaseGrammarAccess.getXMemberFeatureCallAccess().getMemberCallArgumentsXClosureParserRuleCall_1_1_4_0()) || Objects.equal(grammarElement, this._xbaseGrammarAccess.getXFeatureCallAccess().getFeatureCallArgumentsXClosureParserRuleCall_4_0())) || Objects.equal(grammarElement, this._xbaseGrammarAccess.getXConstructorCallAccess().getArgumentsXClosureParserRuleCall_5_0()))) { XExpression _last_1 = IterableExtensions.<XExpression>last(params); _xifexpression_1 = ((XClosure) _last_1); } _xblockexpression = _xifexpression_1; } _xifexpression = _xblockexpression; } return _xifexpression; }
Example #10
Source File: DotHtmlLabelValidator.java From gef with Eclipse Public License 2.0 | 6 votes |
private void reportRangeBasedError(String issueCode, String message, EObject object, EStructuralFeature feature, String[] issueData) { List<INode> nodes = NodeModelUtils.findNodesForFeature(object, feature); if (nodes.size() != 1) { throw new IllegalStateException( "Exact 1 node is expected for the feature, but got " + nodes.size() + " node(s)."); } INode node = nodes.get(0); int offset = node.getTotalOffset(); int length = node.getLength(); getMessageAcceptor().acceptError(message, object, offset, length, issueCode, issueData); }
Example #11
Source File: NodeModelBasedRegionAccessBuilder.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
protected EObject findGrammarElement(INode node, EObject obj) { INode current = node; String feature = obj.eContainingFeature().getName(); while (current != null) { EObject grammarElement = current.getGrammarElement(); Assignment assignment = GrammarUtil.containingAssignment(grammarElement); if (assignment != null && feature.equals(assignment.getFeature())) return grammarElement; if (grammarElement instanceof Action) { Action action = (Action) grammarElement; if (feature.equals(action.getFeature())) return grammarElement; else if (current == node && current instanceof ICompositeNode) { INode child = ((ICompositeNode) current).getFirstChild(); while (child instanceof ICompositeNode) { EObject grammarElement2 = child.getGrammarElement(); Assignment assignment2 = GrammarUtil.containingAssignment(grammarElement2); if (assignment2 != null && feature.equals(assignment2.getFeature())) return grammarElement2; // if (child.hasDirectSemanticElement() && child.getSemanticElement() != obj) // break; child = ((ICompositeNode) child).getFirstChild(); } } } if (current.hasDirectSemanticElement() && current.getSemanticElement() != obj) return null; current = current.getParent(); } return null; }
Example #12
Source File: XbaseIdeContentProposalProvider.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
protected void completeBinaryOperation(final EObject model, final Assignment assignment, final ContentAssistContext context, final IIdeContentProposalAcceptor acceptor) { if ((model instanceof XBinaryOperation)) { int _length = context.getPrefix().length(); boolean _tripleEquals = (_length == 0); if (_tripleEquals) { final INode currentNode = context.getCurrentNode(); final int offset = currentNode.getOffset(); final int endOffset = currentNode.getEndOffset(); if ((((offset < context.getOffset()) && (endOffset >= context.getOffset())) && (currentNode.getGrammarElement() instanceof CrossReference))) { return; } } int _endOffset = NodeModelUtils.findActualNodeFor(model).getEndOffset(); int _offset = context.getOffset(); boolean _lessEqualsThan = (_endOffset <= _offset); if (_lessEqualsThan) { AbstractElement _terminal = assignment.getTerminal(); this.createReceiverProposals(((XExpression) model), ((CrossReference) _terminal), context, acceptor); } else { AbstractElement _terminal_1 = assignment.getTerminal(); this.createReceiverProposals(((XBinaryOperation)model).getLeftOperand(), ((CrossReference) _terminal_1), context, acceptor); } } else { final EObject previousModel = context.getPreviousModel(); if ((previousModel instanceof XExpression)) { if (((context.getPrefix().length() == 0) && (NodeModelUtils.getNode(previousModel).getEndOffset() > context.getOffset()))) { return; } AbstractElement _terminal_2 = assignment.getTerminal(); this.createReceiverProposals(((XExpression)previousModel), ((CrossReference) _terminal_2), context, acceptor); } } }
Example #13
Source File: XbaseHyperLinkHelper.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected boolean isNameNode(EObject element, EStructuralFeature feature, ILeafNode node) { List<INode> nameNode = NodeModelUtils.findNodesForFeature(element, feature); for (INode iNode : nameNode) { if (iNode.getOffset() <= node.getOffset() && iNode.getLength()>= node.getLength()) { return true; } } return false; }
Example #14
Source File: LazyLinkingResource2.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} * * @return true if the {@link ICrossReferenceHelper} returns true */ @Override public boolean suppressDiagnostic(final Triple<EObject, EReference, INode> triple) { final EObject context = triple.getFirst(); final EReference reference = triple.getSecond(); final INode node = triple.getThird(); return crossReferenceHelper.isOptionalReference(context, reference, node); }
Example #15
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 #16
Source File: Bug291022TestLanguageSyntacticSequencer.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected void emitUnassignedTokens(EObject semanticObject, ISynTransition transition, INode fromNode, INode toNode) { if (transition.getAmbiguousSyntaxes().isEmpty()) return; List<INode> transitionNodes = collectNodes(fromNode, toNode); for (AbstractElementAlias syntax : transition.getAmbiguousSyntaxes()) { List<INode> syntaxNodes = getNodesFor(transitionNodes, syntax); if (match_ModelElement_SemicolonKeyword_3_0_or___LeftCurlyBracketKeyword_3_1_0_RightCurlyBracketKeyword_3_1_2__.equals(syntax)) emit_ModelElement_SemicolonKeyword_3_0_or___LeftCurlyBracketKeyword_3_1_0_RightCurlyBracketKeyword_3_1_2__(semanticObject, getLastNavigableState(), syntaxNodes); else if (match_RootModel___LeftCurlyBracketKeyword_3_0_RightCurlyBracketKeyword_3_2__q.equals(syntax)) emit_RootModel___LeftCurlyBracketKeyword_3_0_RightCurlyBracketKeyword_3_2__q(semanticObject, getLastNavigableState(), syntaxNodes); else acceptNodes(getLastNavigableState(), syntaxNodes); } }
Example #17
Source File: ADDRESSValueConverter.java From solidity-ide with Eclipse Public License 1.0 | 5 votes |
public BigInteger toValue(String string, INode node) { if (Strings.isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to number.", node, null); try { return new BigInteger(string.substring(2), 16); } catch (NumberFormatException e) { throw new ValueConverterException("Couldn't convert '" + string + "' to number.", node, null); } }
Example #18
Source File: AbstractNode.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.5 */ @Override public int getEndOffset() { BidiIterator<AbstractNode> iter = basicIterator(); while(iter.hasPrevious()) { INode prev = iter.previous(); if (prev instanceof ILeafNode && !((ILeafNode) prev).isHidden()) { return prev.getTotalEndOffset(); } } return getTotalEndOffset(); }
Example #19
Source File: EmitterNodeUtil.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private static INode findNext(INode node, INode to) { if (node instanceof ICompositeNode) { INode firstChild = ((ICompositeNode) node).getFirstChild(); if (firstChild != null) { if (firstChild == to) { return null; } return firstChild; } } return findNextSibling(node, to); }
Example #20
Source File: XImportDeclarationImplCustom.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
@Override public String getImportedTypeName() { String result = getImportedNamespace(); if (result == null) { if (this.eIsSet(XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE)) { JvmType unresolvedType = (JvmType) this.eGet(XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE, false); if(!unresolvedType.eIsProxy()) return unresolvedType.getIdentifier(); List<INode> list = NodeModelUtils.findNodesForFeature(this, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE); StringBuilder sb = new StringBuilder(); for (INode iNode : list) { sb.append(NodeModelUtils.getTokenText(iNode).replace("^", "")); } result = sb.toString().replace(" ", ""); if (isStatic()) { return trim(result, 1); } return result; } return null; } if (isWildcard()) { return trim(result, 2); } return result; }
Example #21
Source File: NodeTreeIterator.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public INode next() { if (next == null && !hasNext()) throw new NoSuchElementException(); lastNextReturned = next; lastPreviousReturned = null; afterAdvance(); return lastNextReturned; }
Example #22
Source File: SequencerTestLanguageSyntacticSequencer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override protected void emitUnassignedTokens(EObject semanticObject, ISynTransition transition, INode fromNode, INode toNode) { if (transition.getAmbiguousSyntaxes().isEmpty()) return; List<INode> transitionNodes = collectNodes(fromNode, toNode); for (AbstractElementAlias syntax : transition.getAmbiguousSyntaxes()) { List<INode> syntaxNodes = getNodesFor(transitionNodes, syntax); acceptNodes(getLastNavigableState(), syntaxNodes); } }
Example #23
Source File: DefaultQuickfixProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
private CrossReference findCrossReference(EObject context, INode node) { if (node == null || (node.hasDirectSemanticElement() && context.equals(node.getSemanticElement()))) return null; EObject grammarElement = node.getGrammarElement(); if (grammarElement instanceof CrossReference) { return (CrossReference) grammarElement; } else return findCrossReference(context, node.getParent()); }
Example #24
Source File: RichStringFormatter.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected boolean _hasSyntaxError(final NodeEObjectRegion region) { final BidiTreeIterator<INode> i = region.getNode().getAsTreeIterable().iterator(); while (i.hasNext()) { SyntaxErrorMessage _syntaxErrorMessage = i.next().getSyntaxErrorMessage(); boolean _tripleNotEquals = (_syntaxErrorMessage != null); if (_tripleNotEquals) { return true; } } return false; }
Example #25
Source File: Ecore2XtextTestSyntacticSequencer.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected void emitUnassignedTokens(EObject semanticObject, ISynTransition transition, INode fromNode, INode toNode) { if (transition.getAmbiguousSyntaxes().isEmpty()) return; List<INode> transitionNodes = collectNodes(fromNode, toNode); for (AbstractElementAlias syntax : transition.getAmbiguousSyntaxes()) { List<INode> syntaxNodes = getNodesFor(transitionNodes, syntax); acceptNodes(getLastNavigableState(), syntaxNodes); } }
Example #26
Source File: LazyLinkingTestLanguageSyntacticSequencer.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override protected void emitUnassignedTokens(EObject semanticObject, ISynTransition transition, INode fromNode, INode toNode) { if (transition.getAmbiguousSyntaxes().isEmpty()) return; List<INode> transitionNodes = collectNodes(fromNode, toNode); for (AbstractElementAlias syntax : transition.getAmbiguousSyntaxes()) { List<INode> syntaxNodes = getNodesFor(transitionNodes, syntax); acceptNodes(getLastNavigableState(), syntaxNodes); } }
Example #27
Source File: GH1462Test.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void test12b() throws Exception { disableSerializerTest(); Root root = (Root) getModel("#12 1 2 s"); Rule12 rule12 = (Rule12) root.getElement(); assertEquals(1, rule12.getLeft()); // TODO (sza, cdi): This should be an invalid grammar instead assertTrue(rule12.isRight()); INode featureNode = NodeModelUtils.findNodesForFeature(rule12, Gh1462TestPackage.Literals.RULE12__RIGHT).get(0); assertEquals(" 2", featureNode.getText()); assertTrue(featureNode.hasDirectSemanticElement()); EObject element = featureNode.getSemanticElement(); assertNull(element.eResource()); }
Example #28
Source File: NodeModelUtilsTest.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Test public void testFindNodesForFeature_Cardinality_0() throws Exception { Grammar grammar = (Grammar) getModel("grammar foo.Bar with org.eclipse.xtext.common.Terminals generate foo 'bar' Model: name+='foo'*;"); Assignment assignment = (Assignment) grammar.getRules().get(0).getAlternatives(); List<INode> nodes = NodeModelUtils.findNodesForFeature(assignment, XtextPackage.eINSTANCE.getAbstractElement_Cardinality()); assertEquals(1, nodes.size()); assertEquals("*", nodes.get(0).getText().trim()); }
Example #29
Source File: TokenUtil.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
public EObject getTokenOwner(INode node) { if (node.hasDirectSemanticElement()) return node.getSemanticElement(); if (node.getParent() != null) { if (node.getParent().hasDirectSemanticElement()) return node.getParent().getSemanticElement(); EObject parentGrammarElement = node.getParent().getGrammarElement(); boolean isParser = GrammarUtil.isEObjectRule(parentGrammarElement) || GrammarUtil.isEObjectRuleCall(parentGrammarElement); for (INode sibling : node.getParent().getChildren()) if (sibling.hasDirectSemanticElement() && (isParser || sibling.getGrammarElement() instanceof Action)) return sibling.getSemanticElement(); } return node.getSemanticElement(); }
Example #30
Source File: INTValueConverter.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@Override public Integer toValue(String string, INode node) { if (Strings.isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to an int value.", node, null); try { int intValue = Integer.parseInt(string, 10); return Integer.valueOf(intValue); } catch (NumberFormatException e) { throw new ValueConverterException("Couldn't convert '" + string + "' to an int value.", node, e); } }