use of com.redhat.ceylon.model.typechecker.model.Class in project ceylon-compiler by ceylon.
the class ExpressionTransformer method checkForByteLiterals.
private JCExpression checkForByteLiterals(Tree.InvocationExpression ce) {
// same test as in BoxingVisitor.isByteLiteral()
if (ce.getPrimary() instanceof Tree.BaseTypeExpression && ce.getPositionalArgumentList() != null) {
java.util.List<Tree.PositionalArgument> positionalArguments = ce.getPositionalArgumentList().getPositionalArguments();
if (positionalArguments.size() == 1) {
PositionalArgument argument = positionalArguments.get(0);
if (argument instanceof Tree.ListedArgument && ((Tree.ListedArgument) argument).getExpression() != null) {
Term term = ((Tree.ListedArgument) argument).getExpression().getTerm();
boolean negative = false;
if (term instanceof Tree.NegativeOp) {
negative = true;
term = ((Tree.NegativeOp) term).getTerm();
}
if (term instanceof Tree.NaturalLiteral) {
Declaration decl = ((Tree.BaseTypeExpression) ce.getPrimary()).getDeclaration();
if (decl instanceof Class) {
String name = decl.getQualifiedNameString();
if (name.equals("ceylon.language::Byte")) {
at(ce);
try {
long value = literalValue((Tree.NaturalLiteral) term);
if (negative)
value = -value;
// assignment, not for method calls, so it's simpler to always cast
return make().TypeCast(syms().byteType, make().Literal(value));
} catch (ErroneousException e) {
// replaced with a throw.
return e.makeErroneous(this);
}
}
}
}
}
}
}
return null;
}
Aggregations