当前位置: 首页>>代码示例>>Java>>正文


Java XNumberLiteral类代码示例

本文整理汇总了Java中org.eclipse.xtext.xbase.XNumberLiteral的典型用法代码示例。如果您正苦于以下问题:Java XNumberLiteral类的具体用法?Java XNumberLiteral怎么用?Java XNumberLiteral使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XNumberLiteral类属于org.eclipse.xtext.xbase包,在下文中一共展示了XNumberLiteral类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTypeQualifier

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
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));
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:26,代码来源:NumberLiterals.java

示例2: getXbaseDigits

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
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));
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:NumberLiterals.java

示例3: isFloatingPoint

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
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));
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:18,代码来源:NumberLiterals.java

示例4: getExplicitJavaType

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:18,代码来源:NumberLiterals.java

示例5: getExponent

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:NumberLiterals.java

示例6: toBigDecimal

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
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);
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:21,代码来源:NumberLiterals.java

示例7: internalToConvertedExpression

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:LiteralsCompiler.java

示例8: doInternalToJavaStatement

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:LiteralsCompiler.java

示例9: _doEvaluate

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
/**
 * @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);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:24,代码来源:XbaseInterpreter.java

示例10: isConstant

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
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());
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:21,代码来源:ConstantExpressionValidator.java

示例11: testIntegerAnnotation

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:27,代码来源:JvmTypesBuilderTest.java

示例12: checkRightHandSideHasOnlyIntegralNumbers

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
/**
 * 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
        }
      }
    }
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:28,代码来源:FormalParameterCheckBase.java

示例13: checkNumberFormat

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
@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);
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:XbaseValidator.java

示例14: toJavaLiteral

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:16,代码来源:NumberLiterals.java

示例15: isHex

import org.eclipse.xtext.xbase.XNumberLiteral; //导入依赖的package包/类
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;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:9,代码来源:NumberLiterals.java


注:本文中的org.eclipse.xtext.xbase.XNumberLiteral类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。