use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class ExpressionTransformer method isReferenceInSameScope.
private boolean isReferenceInSameScope(Tree.StaticMemberOrTypeExpression expr) {
if (isWithinSyntheticClassBody()) {
return false;
}
Declaration decl = expr.getDeclaration();
Scope s = expr.getScope();
// are we in the same Declaration container?
while (s != null && s instanceof Declaration == false) {
s = s.getContainer();
}
return Decl.equalScopeDecl(s, decl);
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
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) {
if (((Class) decl).isByte()) {
at(ce);
try {
long value = literalValue((Tree.NaturalLiteral) term).longValue();
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;
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class ExpressionTransformer method makeTopLevelValueOrFunctionLiteral.
private JCTree makeTopLevelValueOrFunctionLiteral(Tree.MemberLiteral expr) {
Declaration declaration = expr.getDeclaration();
JCExpression toplevelCall = makeTopLevelValueOrFunctionDeclarationLiteral(declaration);
if (!expr.getWantsDeclaration()) {
ListBuffer<JCExpression> closedTypeArgs = new ListBuffer<JCExpression>();
// expr is of type Function<Type,Arguments> or Value<Get,Set> so we can get its type like that
JCExpression reifiedType = makeReifiedTypeArgument(expr.getTypeModel().getTypeArgumentList().get(0));
closedTypeArgs.append(reifiedType);
if (Decl.isMethod(declaration)) {
// expr is of type Function<Type,Arguments> so we can get its arguments type like that
Type argumentsType = typeFact().getCallableTuple(expr.getTypeModel());
JCExpression reifiedArguments = makeReifiedTypeArgument(argumentsType);
closedTypeArgs.append(reifiedArguments);
if (expr.getTypeArgumentList() != null) {
java.util.List<Type> typeModels = expr.getTypeArgumentList().getTypeModels();
if (typeModels != null) {
JCExpression closedTypesExpr = getClosedTypesSequential(typeModels);
// must apply it
closedTypeArgs.append(closedTypesExpr);
}
}
} else {
JCExpression reifiedSet;
Type ptype;
if (!((Value) declaration).isVariable())
ptype = typeFact().getNothingType();
else
ptype = expr.getTypeModel().getTypeArgumentList().get(0);
reifiedSet = makeReifiedTypeArgument(ptype);
closedTypeArgs.append(reifiedSet);
}
toplevelCall = make().Apply(null, makeSelect(toplevelCall, "apply"), closedTypeArgs.toList());
// add cast
Type exprType = expr.getTypeModel().resolveAliases();
JCExpression typeClass = makeJavaType(exprType, JT_NO_PRIMITIVES);
JCExpression rawTypeClass = makeJavaType(exprType, JT_NO_PRIMITIVES | JT_RAW);
return make().TypeCast(typeClass, make().TypeCast(rawTypeClass, toplevelCall));
}
return toplevelCall;
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class ExpressionTransformer method appendImplicitArguments.
private void appendImplicitArguments(Invocation invocation, TransformedInvocationPrimary transformedPrimary, ListBuffer<ExpressionAndType> result) {
// Implicit arguments
// except for Java array constructors
Declaration primaryDeclaration = invocation.getPrimaryDeclaration();
Tree.Term primary = invocation.getPrimary();
if (primaryDeclaration instanceof Value == false) {
if (primaryDeclaration instanceof Class == false || !isJavaArray(((Class) primaryDeclaration).getType())) {
invocation.addReifiedArguments(result);
}
}
if (!(primary instanceof Tree.BaseTypeExpression) && !(primary instanceof Tree.QualifiedTypeExpression) && (!(primary instanceof Tree.QualifiedMemberExpression) || !(((Tree.QualifiedMemberExpression) primary).getMemberOperator() instanceof Tree.SpreadOp)) && Invocation.onValueType(this, primary, primaryDeclaration) && transformedPrimary != null) {
result.add(new ExpressionAndType(transformedPrimary.expr, makeJavaType(primary.getTypeModel())));
}
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class ExpressionTransformer method needDollarThis.
boolean needDollarThis(Tree.StaticMemberOrTypeExpression expr) {
if (expr instanceof Tree.BaseMemberExpression || expr instanceof Tree.BaseTypeExpression) {
// We need to add a `$this` prefix to the member expression if:
// * The member was declared on an interface I and
// * The member is being used in the companion class of I or
// // REMOVED: some subinterface of I, and
// some member type of I, and
// * The member is shared (non-shared means its only on the companion class)
// FIXME: https://github.com/ceylon/ceylon-compiler/issues/1019
final Declaration decl = expr.getDeclaration();
if (!decl.isInterfaceMember())
return false;
// Find the method/getter/setter where the expr is being used
Scope scope = expr.getScope();
while (scope != null) {
// Is it being used in an interface (=> impl)
if (scope instanceof Interface && ((Interface) scope).getType().isSubtypeOf(scope.getDeclaringType(decl))) {
return decl.isShared();
}
scope = scope.getContainer();
}
}
return false;
}
Aggregations