use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class ExpressionTransformer method transformBaseInstantiation.
private JCExpression transformBaseInstantiation(Invocation invocation, CallBuilder callBuilder, TransformedInvocationPrimary transformedPrimary) {
JCExpression resultExpr;
Tree.BaseTypeExpression type = (Tree.BaseTypeExpression) invocation.getPrimary();
Declaration declaration = type.getDeclaration();
invocation.location(callBuilder);
if (Strategy.generateInstantiator(declaration)) {
resultExpr = callBuilder.typeArguments(List.<JCExpression>nil()).invoke(naming.makeInstantiatorMethodName(transformedPrimary.expr, (Class) declaration)).build();
if (Strategy.isInstantiatorUntyped(declaration)) {
// $new method declared to return Object, so needs typecast
resultExpr = make().TypeCast(makeJavaType(((TypeDeclaration) declaration).getType()), resultExpr);
}
} else {
Type classType = (Type) type.getTarget();
if (isJavaArray(classType)) {
JCExpression typeExpr = makeJavaType(classType, AbstractTransformer.JT_CLASS_NEW | AbstractTransformer.JT_RAW);
callBuilder.javaArrayInstance(typeExpr);
if (isJavaObjectArray(classType)) {
Type elementType = classType.getTypeArgumentList().get(0);
MultidimensionalArray multiArray = getMultiDimensionalArrayInfo(elementType);
if (multiArray != null)
elementType = multiArray.type;
// array of Foo is fine, array of Nothing too
if (elementType.getDeclaration() instanceof ClassOrInterface || elementType.isNothing()) {
if (!elementType.getTypeArgumentList().isEmpty())
callBuilder.javaArrayInstanceNeedsCast(makeJavaType(classType, AbstractTransformer.JT_NO_PRIMITIVES));
} else {
// if it's an array of union, intersection or type param we need a runtime allocation
callBuilder.javaArrayInstanceIsGeneric(makeReifiedTypeArgument(elementType), multiArray != null ? multiArray.dimension + 1 : 1);
}
}
} else {
if (Decl.isConstructor(classType.getDeclaration())) {
classType = classType.getExtendedType();
}
JCExpression typeExpr = makeJavaType(classType, AbstractTransformer.JT_CLASS_NEW);
callBuilder.instantiate(typeExpr);
}
resultExpr = callBuilder.build();
}
return resultExpr;
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class MethodOrValueReferenceVisitor method isSelfCaptured.
/**
* Returns true if <code>that</code> is within the scope of the type of <code>d</code>,
* which must be a value declaration for an object declaration.
*/
private boolean isSelfCaptured(Primary that, TypedDeclaration d) {
TypeDeclaration type = d.getTypeDeclaration();
Scope scope = that.getScope();
while (scope != null && scope instanceof Package == false && !Decl.equalScopeDecl(scope, type)) {
scope = scope.getScope();
}
return Decl.equalScopeDecl(scope, type);
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class ForcedCaptureVisitor method isForcedCapture.
private boolean isForcedCapture(Tree.TypedDeclaration that) {
if (that.getAnnotationList() == null)
return false;
for (Annotation anno : that.getAnnotationList().getAnnotations()) {
Type type = anno.getTypeModel();
if (type == null || !type.isClassOrInterface())
continue;
TypeDeclaration decl = type.getDeclaration();
if (decl == null)
continue;
Module module = Decl.getModule(decl);
if (module == null)
continue;
if (module.getLanguageModule() == module)
continue;
// does not come from the language module
return true;
}
return false;
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class TypeFactory method getReferenceType.
public Type getReferenceType(Type value) {
final Type serializedValueType;
TypeDeclaration referenceTypeDecl = (TypeDeclaration) getLanguageModuleSerializationDeclaration("Reference");
serializedValueType = referenceTypeDecl.appliedType(null, Collections.singletonList(value));
return serializedValueType;
}
use of com.redhat.ceylon.model.typechecker.model.TypeDeclaration in project ceylon-compiler by ceylon.
the class UnknownTypeCollector method collectUnknownTypes.
private void collectUnknownTypes(Type type, Map<Declaration, Declaration> visited) {
if (type != null) {
type = type.resolveAliases();
if (type.isUnknown()) {
UnknownType ut = (UnknownType) type.getDeclaration();
ut.reportErrors();
// don't report it twice
ut.setErrorReporter(null);
} else if (type.isUnion()) {
for (Type t : type.getCaseTypes()) {
collectUnknownTypesResolved(t, visited);
}
} else if (type.isIntersection()) {
for (Type t : type.getSatisfiedTypes()) {
collectUnknownTypesResolved(t, visited);
}
} else if (type.isUnknown() || type.isTypeParameter()) {
// do nothing
} else {
TypeDeclaration declaration = type.getDeclaration();
if (visited.put(declaration, declaration) != null)
return;
if (type.isClassOrInterface()) {
// these are not resolved
if (type.getExtendedType() != null)
collectUnknownTypes(type.getExtendedType(), visited);
for (Type t : type.getSatisfiedTypes()) collectUnknownTypes(t, visited);
}
}
}
}
Aggregations