Java 类org.eclipse.xtext.xbase.XNumberLiteral 实例源码

项目:xtext-extras    文件:NumberLiterals.java   
protected String getTypeQualifier(XNumberLiteral literal) {
    String valueAsLowerCase = literal.getValue().toLowerCase();
    switch (getBase(literal)) {
        case 16:
            int index = valueAsLowerCase.indexOf('#');
            if (index != -1)
                return valueAsLowerCase.substring(index + 1);
            else
                return "";
        case 10:
            if (valueAsLowerCase.endsWith("bi") || valueAsLowerCase.endsWith("bd"))
                return valueAsLowerCase.substring(valueAsLowerCase.length() - 2);
            char lastChar = valueAsLowerCase.charAt(literal.getValue().length() - 1);
            switch (lastChar) {
                case 'l':
                case 'd':
                case 'f':
                    return Character.toString(lastChar);
                default:
                    return "";
            }
        default:
            throw new IllegalArgumentException("Invalid number literal base " + getBase(literal));
    }
}
项目:xtext-extras    文件:NumberLiterals.java   
protected String getXbaseDigits(XNumberLiteral literal) {
    String value = literal.getValue();
    int length = value.length();
    String typeQualifier = getTypeQualifier(literal);
    switch (getBase(literal)) {
        case 10:
            return value.substring(0, length - typeQualifier.length());
        case 16:
            if (equal("", typeQualifier))
                return value.substring(2, length - typeQualifier.length());
            else
                return value.substring(2, length - typeQualifier.length() - 1);
        default:
            throw new IllegalArgumentException("Invalid number literal base " + getBase(literal));
    }
}
项目:xtext-extras    文件:NumberLiterals.java   
protected boolean isFloatingPoint(XNumberLiteral literal) {
    if (literal.getValue().indexOf('.') != -1) {
        return true;
    }
    String lowerCaseValue = literal.getValue().toLowerCase();
    switch (getBase(literal)) {
        case 16:
            return false;
        case 10:
            if (lowerCaseValue.indexOf('e') != -1)
                return true;
            char lastChar = lowerCaseValue.charAt(literal.getValue().length() - 1);
            return lastChar == 'd' || lastChar == 'f';
        default:
            throw new IllegalArgumentException("Invalid number literal base " + getBase(literal));
    }
}
项目:xtext-extras    文件:NumberLiterals.java   
protected Class<? extends Number> getExplicitJavaType(XNumberLiteral literal) {
    String typeQualifier = getTypeQualifier(literal);
    if (equal("", typeQualifier))
        return null;
    else if (equal("f", typeQualifier))
        return Float.TYPE;
    else if (equal("l", typeQualifier))
        return Long.TYPE;
    else if (equal("d", typeQualifier))
        return Double.TYPE;
    else if (equal("bi", typeQualifier))
        return BigInteger.class;
    else if (equal("bd", typeQualifier))
        return BigDecimal.class;
    else
        throw new IllegalArgumentException("Invalid type qualifier " + typeQualifier);
}
项目:xtext-extras    文件:NumberLiterals.java   
public String getExponent(XNumberLiteral literal, String digits) {
    if (isHex(literal))
        return null;
    int e = digits.indexOf('e');
    if (e == -1) {
        e = digits.indexOf('E');
    }
    if (e != -1) {
        if (e != digits.length() - 1 && (digits.charAt(e + 1) == '+' || digits.charAt(e + 1) == '-')) {
            e++;
        }
        if (e < digits.length() - 1) {
            String exponent = digits.substring(e + 1);
            return exponent;
        }
    }
    return null;
}
项目:xtext-extras    文件:NumberLiterals.java   
public BigDecimal toBigDecimal(XNumberLiteral literal) {
    if (isFloatingPoint(literal)) {
        String digits = getDigits(literal);
        String exponent = getExponent(literal, digits);
        if (exponent != null && exponent.length() > 10) {
            throw new NumberFormatException("Too many nonzero exponent digits.");
        }
        return new BigDecimal(digits);
    } else {
        int base = getBase(literal);
        switch (base) {
            case 16:
                return new BigDecimal(new BigInteger(getDigits(literal), base));
            case 10:
                return new BigDecimal(getDigits(literal));
            default:
                throw new IllegalArgumentException("Invalid number literal base " + base);
        }
    }
}
项目:xtext-extras    文件:LiteralsCompiler.java   
@Override
protected void internalToConvertedExpression(XExpression obj, ITreeAppendable appendable) {
    if (obj instanceof XStringLiteral) {
        _toJavaExpression((XStringLiteral) obj, appendable);
    } else if (obj instanceof XNumberLiteral) {
        _toJavaExpression((XNumberLiteral) obj, appendable);
    } else if (obj instanceof XNullLiteral) {
        _toJavaExpression((XNullLiteral) obj, appendable);
    } else if (obj instanceof XBooleanLiteral) {
        _toJavaExpression((XBooleanLiteral) obj, appendable);
    } else if (obj instanceof XTypeLiteral) {
        _toJavaExpression((XTypeLiteral) obj, appendable);
    } else {
        super.internalToConvertedExpression(obj, appendable);
    }
}
项目:xtext-extras    文件:LiteralsCompiler.java   
@Override
protected void doInternalToJavaStatement(XExpression obj, ITreeAppendable appendable, boolean isReferenced) {
    if (obj instanceof XStringLiteral) {
        _toJavaStatement((XStringLiteral) obj, appendable, isReferenced);
    } else if (obj instanceof XNumberLiteral) {
        _toJavaStatement((XNumberLiteral) obj, appendable, isReferenced);
    } else if (obj instanceof XNullLiteral) {
        _toJavaStatement((XNullLiteral) obj, appendable, isReferenced);
    } else if (obj instanceof XBooleanLiteral) {
        _toJavaStatement((XBooleanLiteral) obj, appendable, isReferenced);
    } else if (obj instanceof XTypeLiteral) {
        _toJavaStatement((XTypeLiteral) obj, appendable, isReferenced);
    } else {
        super.doInternalToJavaStatement(obj, appendable, isReferenced);
    }
}
项目:xtext-extras    文件:XbaseInterpreter.java   
/**
 * @param context unused in this context but required for dispatching
 * @param indicator unused in this context but required for dispatching
 */
@SuppressWarnings("unchecked")
protected Object _doEvaluate(XNumberLiteral literal, IEvaluationContext context, CancelIndicator indicator) {
    IResolvedTypes resolvedTypes = typeResolver.resolveTypes(literal);
    LightweightTypeReference expectedType = resolvedTypes.getExpectedType(literal);
    Class<? extends Number> type = numberLiterals.getJavaType(literal);
    if (expectedType != null && expectedType.isSubtypeOf(Number.class)) {
        try {
            Class<?> expectedClassType = getJavaType(expectedType.toJavaCompliantTypeReference().getType());
            if (expectedClassType.isPrimitive()) {
                expectedClassType = ReflectionUtil.getObjectType(expectedClassType);
            }
            if (Number.class != expectedClassType && Number.class.isAssignableFrom(expectedClassType)) {
                type = (Class<? extends Number>) expectedClassType;
            }
        } catch (ClassNotFoundException e) {
        }
    }
    return numberLiterals.numberValue(literal, type);
}
项目:xtext-extras    文件:ConstantExpressionValidator.java   
public boolean isConstant(final XExpression expression) {
  if (expression instanceof XAbstractFeatureCall) {
    return _isConstant((XAbstractFeatureCall)expression);
  } else if (expression instanceof XBooleanLiteral) {
    return _isConstant((XBooleanLiteral)expression);
  } else if (expression instanceof XCastedExpression) {
    return _isConstant((XCastedExpression)expression);
  } else if (expression instanceof XNumberLiteral) {
    return _isConstant((XNumberLiteral)expression);
  } else if (expression instanceof XStringLiteral) {
    return _isConstant((XStringLiteral)expression);
  } else if (expression instanceof XTypeLiteral) {
    return _isConstant((XTypeLiteral)expression);
  } else if (expression != null) {
    return _isConstant(expression);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(expression).toString());
  }
}
项目:xtext-extras    文件:JvmTypesBuilderTest.java   
@Test
public void testIntegerAnnotation() {
  try {
    final XAnnotationsFactory f = XAnnotationsFactory.eINSTANCE;
    final XExpression e = this.expression("\'Foo\'");
    final XAnnotation anno = f.createXAnnotation();
    JvmType _findDeclaredType = this.references.findDeclaredType(TestAnnotation3.class, e);
    final JvmAnnotationType annotatiomType = ((JvmAnnotationType) _findDeclaredType);
    anno.setAnnotationType(annotatiomType);
    final XAnnotationElementValuePair pair = f.createXAnnotationElementValuePair();
    pair.setElement(IterableExtensions.<JvmOperation>head(annotatiomType.getDeclaredOperations()));
    pair.setValue(this.expression("10"));
    EList<XAnnotationElementValuePair> _elementValuePairs = anno.getElementValuePairs();
    this._jvmTypesBuilder.<XAnnotationElementValuePair>operator_add(_elementValuePairs, pair);
    final JvmGenericType type = this.typesFactory.createJvmGenericType();
    this._jvmTypesBuilder.addAnnotation(type, anno);
    Assert.assertEquals(anno.getAnnotationType(), IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getAnnotation());
    Assert.assertEquals(1, IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues().size());
    JvmAnnotationValue _head = IterableExtensions.<JvmAnnotationValue>head(IterableExtensions.<JvmAnnotationReference>head(type.getAnnotations()).getValues());
    final JvmCustomAnnotationValue value = ((JvmCustomAnnotationValue) _head);
    EObject _head_1 = IterableExtensions.<EObject>head(value.getValues());
    Assert.assertTrue((_head_1 instanceof XNumberLiteral));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:dsl-devkit    文件:FormalParameterCheckBase.java   
/**
 * Validates that all XNumberLiterals in this expression, which occurs on the right-hand side of a formal parameter
 * declaration/definition, have indeed integral values.
 * 
 * @param value
 *          to check
 * @param issueCode
 *          to issue if the validation fails
 */
protected void checkRightHandSideHasOnlyIntegralNumbers(final XExpression value, final String issueCode) {
  if (value != null) {
    List<XExpression> exprs = (value instanceof XListLiteral) ? ((XListLiteral) value).getElements() : Collections.singletonList(value);
    for (XExpression expr : exprs) {
      XExpression e = expr;
      while (e instanceof XUnaryOperation) {
        e = ((XUnaryOperation) e).getOperand();
      }
      if (e instanceof XNumberLiteral) {
        try {
          Integer.decode(((XNumberLiteral) e).getValue());
        } catch (NumberFormatException ex) {
          error("Only integral values as numbers are allowed in check parameters", expr, null, issueCode); // TODO: NLS
        }
      }
    }
  }
}
项目:xtext-extras    文件:XbaseValidator.java   
@Check
protected void checkNumberFormat(XNumberLiteral literal) {
    try {
        numberLiterals.numberValue(literal, numberLiterals.getJavaType(literal));
    } catch (Exception e) {
        error("Invalid number format: " + e.getMessage(), Literals.XNUMBER_LITERAL__VALUE, INVALID_NUMBER_FORMAT);
    }
}
项目:xtext-extras    文件:NumberLiterals.java   
public String toJavaLiteral(XNumberLiteral literal, boolean removeUnderscores) {
    if (getJavaType(literal).isPrimitive()) {
        boolean floatingPoint = isFloatingPoint(literal);
        String value = literal.getValue();
        if (!floatingPoint && !value.startsWith("0x")) {
            // strip leading zeros since they denote octal literals
            value = value.replaceAll("^[0_]+(\\d)", "$1");
        }
        if (removeUnderscores)
            return value.replace("_", "").replace("#", "");
        else
            return value.replace("#", "");
    } else
        return null;
}
项目:xtext-extras    文件:NumberLiterals.java   
protected boolean isHex(XNumberLiteral literal) {
    String text = literal.getValue();
    if (text.length() >= 2) {
        char second = text.charAt(1);
        return text.charAt(0) == '0' && (second == 'X' || second =='x');
    }
    return false;
}
项目:xtext-extras    文件:XExpressionHelper.java   
/**
 * @return whether the expression itself (not its children) possibly causes a side-effect
 */
public boolean hasSideEffects(XExpression expr) {
    if (expr instanceof XClosure
        || expr instanceof XStringLiteral
        || expr instanceof XTypeLiteral
        || expr instanceof XBooleanLiteral
        || expr instanceof XNumberLiteral
        || expr instanceof XNullLiteral
        || expr instanceof XAnnotation
        )
        return false;
    if(expr instanceof XCollectionLiteral) {
        for(XExpression element: ((XCollectionLiteral)expr).getElements()) {
            if(hasSideEffects(element))
                return true;
        }
        return false;
    }
    if (expr instanceof XAbstractFeatureCall) {
        XAbstractFeatureCall featureCall = (XAbstractFeatureCall) expr;
        return hasSideEffects(featureCall, true);
    }
    if (expr instanceof XConstructorCall) {
        XConstructorCall constrCall = (XConstructorCall) expr;
        return findPureAnnotation(constrCall.getConstructor()) == null;
    }
    return true;
}
项目:xtext-extras    文件:LiteralsCompiler.java   
@Override
protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) {
    if (expr instanceof XBooleanLiteral
        || expr instanceof XStringLiteral
        || expr instanceof XNumberLiteral
        || expr instanceof XTypeLiteral
        || expr instanceof XClosure
        || expr instanceof XNullLiteral)
        return false;
    return super.isVariableDeclarationRequired(expr,b, recursive);
}
项目:xtext-extras    文件:ConstantConditionsInterpreter.java   
public EvaluationResult internalEvaluate(final XExpression it, final EvaluationContext context) {
  if (it instanceof XBinaryOperation) {
    return _internalEvaluate((XBinaryOperation)it, context);
  } else if (it instanceof XUnaryOperation) {
    return _internalEvaluate((XUnaryOperation)it, context);
  } else if (it instanceof XAbstractFeatureCall) {
    return _internalEvaluate((XAbstractFeatureCall)it, context);
  } else if (it instanceof XBooleanLiteral) {
    return _internalEvaluate((XBooleanLiteral)it, context);
  } else if (it instanceof XCastedExpression) {
    return _internalEvaluate((XCastedExpression)it, context);
  } else if (it instanceof XNullLiteral) {
    return _internalEvaluate((XNullLiteral)it, context);
  } else if (it instanceof XNumberLiteral) {
    return _internalEvaluate((XNumberLiteral)it, context);
  } else if (it instanceof XStringLiteral) {
    return _internalEvaluate((XStringLiteral)it, context);
  } else if (it instanceof XTypeLiteral) {
    return _internalEvaluate((XTypeLiteral)it, context);
  } else if (it != null) {
    return _internalEvaluate(it, context);
  } else if (it == null) {
    return _internalEvaluate((Void)null, context);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, context).toString());
  }
}
项目:xtext-extras    文件:SwitchConstantExpressionsInterpreter.java   
public Object internalEvaluate(final XExpression it, final Context ctx) {
  if (it instanceof XBinaryOperation) {
    return _internalEvaluate((XBinaryOperation)it, ctx);
  } else if (it instanceof XUnaryOperation) {
    return _internalEvaluate((XUnaryOperation)it, ctx);
  } else if (it instanceof XAbstractFeatureCall) {
    return _internalEvaluate((XAbstractFeatureCall)it, ctx);
  } else if (it instanceof XBooleanLiteral) {
    return _internalEvaluate((XBooleanLiteral)it, ctx);
  } else if (it instanceof XCastedExpression) {
    return _internalEvaluate((XCastedExpression)it, ctx);
  } else if (it instanceof XNumberLiteral) {
    return _internalEvaluate((XNumberLiteral)it, ctx);
  } else if (it instanceof XStringLiteral) {
    return _internalEvaluate((XStringLiteral)it, ctx);
  } else if (it instanceof XTypeLiteral) {
    return _internalEvaluate((XTypeLiteral)it, ctx);
  } else if (it instanceof XAnnotation) {
    return _internalEvaluate((XAnnotation)it, ctx);
  } else if (it != null) {
    return _internalEvaluate(it, ctx);
  } else if (it == null) {
    return _internalEvaluate((Void)null, ctx);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, ctx).toString());
  }
}
项目:xtext-extras    文件:XbaseHighlightingCalculator.java   
@Override
protected boolean highlightElement(EObject object, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
    if (object instanceof XAbstractFeatureCall) {
        if (((XAbstractFeatureCall) object).isPackageFragment()) {
            return true;
        }
        if (SPECIAL_FEATURE_NAMES.contains(((XAbstractFeatureCall) object).getConcreteSyntaxFeatureName())) {
            return false;
        }
        operationCanceledManager.checkCanceled(cancelIndicator);
        computeFeatureCallHighlighting((XAbstractFeatureCall) object, acceptor);
    } else if (object instanceof JvmTypeParameter) {
        highlightTypeParameter((JvmTypeParameter) object, acceptor);
    } else if (object instanceof JvmFormalParameter) {
        highlightFormalParameter((JvmFormalParameter) object, acceptor);
    } else if (object instanceof XVariableDeclaration) {
        highlightVariableDeclaration((XVariableDeclaration) object, acceptor);
    } else if (object instanceof XNumberLiteral) {
        highlightNumberLiterals((XNumberLiteral) object, acceptor);
    } else if (object instanceof XConstructorCall) {
        highlightConstructorCall((XConstructorCall) object, acceptor);
    } else if (object instanceof XAnnotation) {
        // Handle XAnnotation in a special way because we want the @ highlighted too
        highlightAnnotation((XAnnotation) object, acceptor);
    } else {
        computeReferencedJvmTypeHighlighting(acceptor, object, cancelIndicator);
    }
    return false;
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testAddition_1() throws Exception {
    XBinaryOperation operation = (XBinaryOperation) expression("3 + 4 + 5");

    XBinaryOperation leftOperand = (XBinaryOperation) operation.getLeftOperand();
    assertEquals("3", ((XNumberLiteral) leftOperand.getLeftOperand()).getValue());
    assertEquals("4", ((XNumberLiteral) leftOperand.getRightOperand()).getValue());

    assertEquals("5", ((XNumberLiteral) operation.getRightOperand()).getValue());
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testFeatureCall_3() throws Exception {
    XMemberFeatureCall call = (XMemberFeatureCall) expression("'holla'.bar(4)");
    assertNotNull(call);
    assertEquals(2, call.getExplicitArguments().size());
    assertEquals("4", ((XNumberLiteral) call.getExplicitArguments().get(1)).getValue());
    assertTrue(call.getExplicitArguments().get(0) instanceof XStringLiteral);
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testFeatureCall_4() throws Exception {
    XFeatureCall call = (XFeatureCall) expression("bar(0,1,2)");
    assertNotNull(call);
    assertEquals("bar",call.getConcreteSyntaxFeatureName());
    assertEquals(3, call.getExplicitArguments().size());
    for (int i = 0; i < 3; i++)
        assertEquals(""+ i, ((XNumberLiteral) call.getExplicitArguments().get(i)).getValue());
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testSwitch_1() throws Exception {
    XSwitchExpression se = (XSwitchExpression) expression("switch number{case 1:'1' case 2:'2' default:'3'}");
    assertTrue(se.getDefault() instanceof XStringLiteral);
    assertEquals(2, se.getCases().size());
    assertTrue(se.getSwitch() instanceof XFeatureCall);

    XCasePart case1 = se.getCases().get(0);
    assertEquals("1", ((XNumberLiteral) case1.getCase()).getValue());
    assertTrue(case1.getThen() instanceof XStringLiteral);

    XCasePart case2 = se.getCases().get(1);
    assertEquals("2", ((XNumberLiteral) case2.getCase()).getValue());
    assertTrue(case2.getThen() instanceof XStringLiteral);
}
项目:xtext-extras    文件:XbaseParserTest.java   
@Test public void testReturnExpressionInBlock_1() throws Exception {
    XBlockExpression block = (XBlockExpression) expression(
        "{ return 1 2 }");
    assertEquals(2, block.getExpressions().size());
    assertTrue(block.getExpressions().get(0) instanceof XReturnExpression);
    XReturnExpression returnExpression = (XReturnExpression) block.getExpressions().get(0);
    assertTrue(returnExpression.getExpression() instanceof XNumberLiteral);
}
项目:xtext-extras    文件:AbstractExpectationTest.java   
@Test
public void testInvocationOnPrimitive() {
  ExpectationTestingTypeComputer _typeComputer = this.getTypeComputer();
  final Function1<XExpression, Boolean> _function = (XExpression it) -> {
    return Boolean.valueOf((it instanceof XNumberLiteral));
  };
  _typeComputer.setPredicate(_function);
  this.expects("1L.intValue").types(((String) null)).finalizedAs(((String) null)).queriedAs("Long");
}
项目:dsl-devkit    文件:AbstractCheckSemanticSequencer.java   
/**
 * Constraint:
 *     value=Number
 */
protected void sequence_XNumberLiteral(EObject context, XNumberLiteral semanticObject) {
    if(errorAcceptor != null) {
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XNUMBER_LITERAL__VALUE) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XNUMBER_LITERAL__VALUE));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getXNumberLiteralAccess().getValueNumberParserRuleCall_1_0(), semanticObject.getValue());
    feeder.finish();
}
项目:dsl-devkit    文件:AbstractCheckCfgSemanticSequencer.java   
/**
 * Constraint:
 *     value=Number
 */
protected void sequence_XNumberLiteral(EObject context, XNumberLiteral semanticObject) {
    if(errorAcceptor != null) {
        if(transientValues.isValueTransient(semanticObject, XbasePackage.Literals.XNUMBER_LITERAL__VALUE) == ValueTransient.YES)
            errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XbasePackage.Literals.XNUMBER_LITERAL__VALUE));
    }
    INodesForEObjectProvider nodes = createNodeProvider(semanticObject);
    SequenceFeeder feeder = createSequencerFeeder(semanticObject, nodes);
    feeder.accept(grammarAccess.getXNumberLiteralAccess().getValueNumberParserRuleCall_1_0(), semanticObject.getValue());
    feeder.finish();
}
项目:xtext-extras    文件:AbstractXbaseSemanticSequencer.java   
@Deprecated
protected void sequence_XNumberLiteral(EObject context, XNumberLiteral semanticObject) {
    sequence_XNumberLiteral(createContext(context, semanticObject), semanticObject);
}
项目:xtext-extras    文件:NumberLiterals.java   
public int getBase(XNumberLiteral literal) {
    if (isHex(literal))
        return 16;
    else
        return 10;
}
项目:xtext-extras    文件:NumberLiterals.java   
public String toJavaLiteral(XNumberLiteral literal) {
    return toJavaLiteral(literal, true);
}
项目:xtext-extras    文件:NumberLiterals.java   
public String getDigits(XNumberLiteral literal) {
    return getXbaseDigits(literal).replace("_", "");
}
项目:xtext-extras    文件:NumberLiterals.java   
public Class<? extends Number> getJavaType(XNumberLiteral literal) {
    Class<? extends Number> explicitType = getExplicitJavaType(literal);
    return (explicitType == null) ? (isFloatingPoint(literal)) ? Double.TYPE : Integer.TYPE : explicitType;
}
项目:xtext-extras    文件:NumberLiterals.java   
public BigInteger toBigInteger(XNumberLiteral literal) {
    if (isFloatingPoint(literal))
        return toBigDecimal(literal).toBigInteger();
    else
        return new BigInteger(getDigits(literal), getBase(literal));
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
@Override
public void computeTypes(XExpression expression, ITypeComputationState state) {
    if (expression instanceof XAssignment) {
        _computeTypes((XAssignment)expression, state);
    } else if (expression instanceof XAbstractFeatureCall) {
        _computeTypes((XAbstractFeatureCall)expression, state);
    } else if (expression instanceof XDoWhileExpression) {
        _computeTypes((XDoWhileExpression)expression, state);
    } else if (expression instanceof XWhileExpression) {
        _computeTypes((XWhileExpression)expression, state);
    } else if (expression instanceof XBlockExpression) {
        _computeTypes((XBlockExpression)expression, state);
    } else if (expression instanceof XBooleanLiteral) {
        _computeTypes((XBooleanLiteral)expression, state);
    } else if (expression instanceof XCastedExpression) {
        _computeTypes((XCastedExpression)expression, state);
    } else if (expression instanceof XClosure) {
        _computeTypes((XClosure)expression, state);
    } else if (expression instanceof XConstructorCall) {
        _computeTypes((XConstructorCall)expression, state);
    } else if (expression instanceof XForLoopExpression) {
        _computeTypes((XForLoopExpression)expression, state);
    } else if (expression instanceof XBasicForLoopExpression) {
        _computeTypes((XBasicForLoopExpression)expression, state);
    } else if (expression instanceof XIfExpression) {
        _computeTypes((XIfExpression)expression, state);
    } else if (expression instanceof XInstanceOfExpression) {
        _computeTypes((XInstanceOfExpression)expression, state);
    } else if (expression instanceof XNumberLiteral) {
        _computeTypes((XNumberLiteral)expression, state);
    } else if (expression instanceof XNullLiteral) {
        _computeTypes((XNullLiteral)expression, state);
    } else if (expression instanceof XReturnExpression) {
        _computeTypes((XReturnExpression)expression, state);
    } else if (expression instanceof XStringLiteral) {
        _computeTypes((XStringLiteral)expression, state);
    } else if (expression instanceof XSwitchExpression) {
        _computeTypes((XSwitchExpression)expression, state);
    } else if (expression instanceof XThrowExpression) {
        _computeTypes((XThrowExpression)expression, state);
    } else if (expression instanceof XTryCatchFinallyExpression) {
        _computeTypes((XTryCatchFinallyExpression)expression, state);
    } else if (expression instanceof XTypeLiteral) {
        _computeTypes((XTypeLiteral)expression, state);
    } else if (expression instanceof XVariableDeclaration) {
        _computeTypes((XVariableDeclaration)expression, state);
    } else if (expression instanceof XListLiteral) {
        _computeTypes((XListLiteral)expression, state);
    } else if (expression instanceof XSetLiteral) {
        _computeTypes((XSetLiteral)expression, state);
    } else if (expression instanceof XSynchronizedExpression) {
        _computeTypes((XSynchronizedExpression)expression, state);
    } else {
        throw new UnsupportedOperationException("Missing type computation for expression type: " + expression.eClass().getName() + " / " + state);
    }
}
项目:xtext-extras    文件:XbaseTypeComputer.java   
protected void _computeTypes(XNumberLiteral object, ITypeComputationState state) {
    // TODO evaluate expectation if no specific suffix is given
    LightweightTypeReference result = getTypeForName(numberLiterals.getJavaType(object), state);
    state.acceptActualType(result);
}
项目:xtext-extras    文件:LiteralsCompiler.java   
public void _toJavaStatement(XNumberLiteral expr, ITreeAppendable b, boolean isReferenced) {
    generateComment(expr, b, isReferenced);
}
项目:xtext-extras    文件:XbaseInterpreter.java   
/**
 * don't call this directly. Always call evaluate() internalEvaluate()
 */
protected Object doEvaluate(XExpression expression, IEvaluationContext context, CancelIndicator indicator) {
    if (expression instanceof XAssignment) {
      return _doEvaluate((XAssignment)expression, context, indicator);
    } else if (expression instanceof XDoWhileExpression) {
      return _doEvaluate((XDoWhileExpression)expression, context, indicator);
    } else if (expression instanceof XMemberFeatureCall) {
      return _doEvaluate((XMemberFeatureCall)expression, context, indicator);
    } else if (expression instanceof XWhileExpression) {
      return _doEvaluate((XWhileExpression)expression, context, indicator);
    } else if (expression instanceof XFeatureCall) {
        return _doEvaluate((XFeatureCall)expression, context, indicator);
    } else if (expression instanceof XAbstractFeatureCall) {
        return _doEvaluate((XAbstractFeatureCall)expression, context, indicator);
    } else if (expression instanceof XBlockExpression) {
      return _doEvaluate((XBlockExpression)expression, context, indicator);
    } else if (expression instanceof XSynchronizedExpression) {
      return _doEvaluate((XSynchronizedExpression)expression, context, indicator);
    } else if (expression instanceof XBooleanLiteral) {
      return _doEvaluate((XBooleanLiteral)expression, context, indicator);
    } else if (expression instanceof XCastedExpression) {
      return _doEvaluate((XCastedExpression)expression, context, indicator);
    } else if (expression instanceof XClosure) {
      return _doEvaluate((XClosure)expression, context, indicator);
    } else if (expression instanceof XConstructorCall) {
      return _doEvaluate((XConstructorCall)expression, context, indicator);
    } else if (expression instanceof XForLoopExpression) {
      return _doEvaluate((XForLoopExpression)expression, context, indicator);
    } else if (expression instanceof XBasicForLoopExpression) {
      return _doEvaluate((XBasicForLoopExpression)expression, context, indicator);
    } else if (expression instanceof XIfExpression) {
      return _doEvaluate((XIfExpression)expression, context, indicator);
    } else if (expression instanceof XInstanceOfExpression) {
      return _doEvaluate((XInstanceOfExpression)expression, context, indicator);
    } else if (expression instanceof XNullLiteral) {
      return _doEvaluate((XNullLiteral)expression, context, indicator);
    } else if (expression instanceof XNumberLiteral) {
      return _doEvaluate((XNumberLiteral)expression, context, indicator);
    } else if (expression instanceof XReturnExpression) {
      return _doEvaluate((XReturnExpression)expression, context, indicator);
    } else if (expression instanceof XStringLiteral) {
      return _doEvaluate((XStringLiteral)expression, context, indicator);
    } else if (expression instanceof XSwitchExpression) {
      return _doEvaluate((XSwitchExpression)expression, context, indicator);
    } else if (expression instanceof XThrowExpression) {
      return _doEvaluate((XThrowExpression)expression, context, indicator);
    } else if (expression instanceof XTryCatchFinallyExpression) {
      return _doEvaluate((XTryCatchFinallyExpression)expression, context, indicator);
    } else if (expression instanceof XTypeLiteral) {
      return _doEvaluate((XTypeLiteral)expression, context, indicator);
    } else if (expression instanceof XVariableDeclaration) {
          return _doEvaluate((XVariableDeclaration)expression, context, indicator);
    } else if (expression instanceof XListLiteral) {
          return _doEvaluate((XListLiteral)expression, context, indicator);
    } else if (expression instanceof XSetLiteral) {
          return _doEvaluate((XSetLiteral)expression, context, indicator);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.<Object>asList(expression, context, indicator).toString());
    }
}
项目:xtext-extras    文件:ConstantExpressionValidator.java   
protected boolean _isConstant(final XNumberLiteral expression) {
  return true;
}
项目:xtext-extras    文件:XbaseImplicitReturnFinder.java   
protected void _findImplicitReturns(final XNumberLiteral expression, final ImplicitReturnFinder.Acceptor acceptor) {
  acceptor.accept(expression);
}