use of org.eclipse.ceylon.model.loader.model.LazyClass in project ceylon by eclipse.
the class Strategy method generateJpaCtor.
static boolean generateJpaCtor(ClassOrInterface declarationModel) {
if (declarationModel instanceof Class && !(declarationModel instanceof ClassAlias) && declarationModel.isToplevel()) {
Class cls = (Class) declarationModel;
if (cls.getCaseValues() != null && !cls.getCaseValues().isEmpty()) {
return false;
}
if (hasNullaryNonJpaConstructor(cls)) {
// The class will already have a nullary ctor
return false;
}
for (Annotation annotation : cls.getAnnotations()) {
Declaration annoDecl = cls.getUnit().getImportedDeclaration(annotation.getName(), null, false);
if (annoDecl != null && annoDecl.getQualifiedNameString().equals("java.lang::nonbean")) {
return false;
}
}
boolean hasDelegatableSuper = false;
Class superClass = (Class) cls.getExtendedType().getDeclaration();
if (superClass instanceof LazyClass && !((LazyClass) superClass).isCeylon()) {
if (superClass.isAbstraction()) {
for (Declaration s : superClass.getOverloads()) {
if (s instanceof Class && isNullary((Class) s)) {
hasDelegatableSuper = true;
break;
}
}
} else {
// If the superclass is Java then generate a Jpa constructor
// if there's a nullary superclass constructor we can call
hasDelegatableSuper = isNullary(superClass);
}
} else {
hasDelegatableSuper = hasNullaryNonJpaConstructor(superClass) || hasJpaConstructor(superClass);
}
boolean constrained = cls.getCaseValues() != null && !cls.getCaseValues().isEmpty() || cls.hasEnumerated() && Decl.hasOnlyValueConstructors(cls);
return hasDelegatableSuper && !constrained;
} else {
return false;
}
}
use of org.eclipse.ceylon.model.loader.model.LazyClass in project ceylon by eclipse.
the class Metamodel method getTypeDescriptorForProducedType.
public static TypeDescriptor getTypeDescriptorForProducedType(org.eclipse.ceylon.model.typechecker.model.Type type) {
TypeDeclaration declaration = type.getDeclaration();
if (type.isNothing()) {
return TypeDescriptor.NothingType;
}
if (type.isUnion()) {
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getCaseTypes());
return TypeDescriptor.union(tdArgs);
}
if (type.isIntersection()) {
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getSatisfiedTypes());
return TypeDescriptor.intersection(tdArgs);
}
if (declaration instanceof LazyClass) {
ReflectionClass classMirror = (ReflectionClass) ((LazyClass) declaration).classMirror;
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
if (type.getQualifyingType() != null)
return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
return ret;
}
if (declaration instanceof LazyInterface) {
ReflectionClass classMirror = (ReflectionClass) ((LazyInterface) declaration).classMirror;
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
if (type.getQualifyingType() != null)
return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
return ret;
}
if (declaration instanceof FunctionOrValueInterface) {
TypedDeclaration underlyingDeclaration = ((FunctionOrValueInterface) declaration).getUnderlyingDeclaration();
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
TypeDescriptor ret;
if (underlyingDeclaration.isToplevel()) {
ReflectionClass classMirror;
// type arguments
if (underlyingDeclaration instanceof Setter)
underlyingDeclaration = ((Setter) underlyingDeclaration).getGetter();
if (underlyingDeclaration instanceof LazyValue)
classMirror = (ReflectionClass) ((LazyValue) underlyingDeclaration).classMirror;
else if (underlyingDeclaration instanceof LazyFunction)
classMirror = (ReflectionClass) ((LazyFunction) underlyingDeclaration).classMirror;
else
throw Metamodel.newModelError("Unsupported underlying declaration type: " + underlyingDeclaration);
ret = TypeDescriptor.functionOrValue(classMirror.klass, tdArgs);
} else
ret = TypeDescriptor.functionOrValue(underlyingDeclaration.getPrefixedName(), tdArgs);
if (type.getQualifyingType() != null)
return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
return ret;
}
if (declaration instanceof UnknownType) {
((UnknownType) declaration).reportErrors();
}
throw Metamodel.newModelError("Unsupported declaration type: " + (declaration == null ? "null" : declaration.getClass()));
}
use of org.eclipse.ceylon.model.loader.model.LazyClass in project ceylon by eclipse.
the class DeclarationErrorVisitor method visit.
public void visit(Tree.ExtendedType that) {
that.getType().visit(this);
// error if we tried to generate a ctor for this class.
if (that.getType().getDeclarationModel() instanceof LazyClass && !((LazyClass) that.getType().getDeclarationModel()).isCeylon()) {
boolean hasPrivateCtor = false;
List<Declaration> overloads = ((LazyClass) that.getType().getDeclarationModel()).getOverloads();
if (overloads != null) {
for (Declaration ctor : overloads) {
if (!ctor.isShared()) {
hasPrivateCtor = true;
break;
}
}
}
if (hasPrivateCtor && that.getInvocationExpression() != null) {
that.getInvocationExpression().visit(this);
}
}
}
use of org.eclipse.ceylon.model.loader.model.LazyClass in project ceylon by eclipse.
the class AbstractModelLoader method addInnerClassesFromAnnotation.
private void addInnerClassesFromAnnotation(ClassOrInterface klass, AnnotationMirror membersAnnotation) {
@SuppressWarnings("unchecked") List<AnnotationMirror> members = (List<AnnotationMirror>) membersAnnotation.getValue();
for (AnnotationMirror member : members) {
TypeMirror javaClassMirror = (TypeMirror) member.getValue("klass");
String javaClassName;
// void.class is the default value, I guess it's a primitive?
if (javaClassMirror != null && !javaClassMirror.isPrimitive()) {
javaClassName = javaClassMirror.getQualifiedName();
} else {
// we get the class name as a string
String name = (String) member.getValue("javaClassName");
ClassMirror container = null;
if (klass instanceof LazyClass) {
container = ((LazyClass) klass).classMirror;
} else if (klass instanceof LazyInterface) {
if (((LazyInterface) klass).isCeylon())
container = ((LazyInterface) klass).companionClass;
else
container = ((LazyInterface) klass).classMirror;
}
if (container == null)
throw new ModelResolutionException("Unknown container type: " + klass + " when trying to load inner class " + name);
javaClassName = container.getQualifiedName() + "$" + name;
}
Declaration innerDecl = convertToDeclaration(ModelUtil.getModuleContainer(klass), klass, javaClassName, DeclarationType.TYPE);
if (innerDecl == null)
throw new ModelResolutionException("Failed to load inner type " + javaClassName + " for outer type " + klass.getQualifiedNameString());
if (shouldLinkNatives(innerDecl)) {
initNativeHeaderMember(innerDecl);
}
}
}
use of org.eclipse.ceylon.model.loader.model.LazyClass in project ceylon by eclipse.
the class AbstractModelLoader method findLocalContainerFromAnnotationAndSetCompanionClass.
private Scope findLocalContainerFromAnnotationAndSetCompanionClass(Package pkg, Interface declaration, AnnotationMirror localContainerAnnotation) {
@SuppressWarnings("unchecked") List<String> path = (List<String>) localContainerAnnotation.getValue("path");
// we start at the package
Scope scope = pkg;
for (String name : path) {
scope = (Scope) getDirectMember(scope, name);
}
String companionClassName = (String) localContainerAnnotation.getValue("companionClassName");
if (companionClassName == null || companionClassName.isEmpty()) {
declaration.setCompanionClassNeeded(false);
return scope;
}
ClassMirror container;
Scope javaClassScope;
if (scope instanceof TypedDeclaration && ((TypedDeclaration) scope).isMember())
javaClassScope = scope.getContainer();
else
javaClassScope = scope;
if (javaClassScope instanceof LazyInterface) {
container = ((LazyInterface) javaClassScope).companionClass;
} else if (javaClassScope instanceof LazyClass) {
container = ((LazyClass) javaClassScope).classMirror;
} else if (javaClassScope instanceof LazyValue) {
container = ((LazyValue) javaClassScope).classMirror;
} else if (javaClassScope instanceof LazyFunction) {
container = ((LazyFunction) javaClassScope).classMirror;
} else if (javaClassScope instanceof SetterWithLocalDeclarations) {
container = ((SetterWithLocalDeclarations) javaClassScope).classMirror;
} else {
throw new ModelResolutionException("Unknown scope class: " + javaClassScope);
}
String qualifiedCompanionClassName = container.getQualifiedName() + "$" + companionClassName;
ClassMirror companionClassMirror = lookupClassMirror(pkg.getModule(), qualifiedCompanionClassName);
if (companionClassMirror == null)
throw new ModelResolutionException("Could not find companion class mirror: " + qualifiedCompanionClassName);
((LazyInterface) declaration).companionClass = companionClassMirror;
return scope;
}
Aggregations