use of org.eclipse.ceylon.model.loader.model.LazyInterface 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.LazyInterface 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.LazyInterface 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;
}
use of org.eclipse.ceylon.model.loader.model.LazyInterface in project ceylon by eclipse.
the class AbstractModelLoader method makeLazyInterface.
protected LazyInterface makeLazyInterface(ClassMirror classMirror, boolean isNativeHeader) {
LazyInterface iface = new LazyInterface(classMirror, this);
iface.setSealed(classMirror.getAnnotation(CEYLON_LANGUAGE_SEALED_ANNOTATION) != null);
iface.setDynamic(classMirror.getAnnotation(CEYLON_DYNAMIC_ANNOTATION) != null);
if (iface.isCeylon()) {
AnnotationMirror container = classMirror.getAnnotation(CEYLON_CONTAINER_ANNOTATION);
if (container != null) {
Object value = container.getValue("isStatic");
if (value != null) {
iface.setStatic(Boolean.TRUE.equals(value));
}
}
} else {
iface.setStatic(classMirror.getEnclosingClass() != null);
}
manageNativeBackend(iface, classMirror, isNativeHeader);
return iface;
}
use of org.eclipse.ceylon.model.loader.model.LazyInterface in project ceylon by eclipse.
the class AbstractModelLoader method setInterfaceCompanionClass.
protected void setInterfaceCompanionClass(Declaration d, ClassOrInterface container, LazyPackage pkg) {
// find its companion class in its real container
ClassMirror containerMirror = null;
if (container instanceof LazyClass) {
containerMirror = ((LazyClass) container).classMirror;
} else if (container instanceof LazyInterface) {
// container must be a LazyInterface, as TypeAlias doesn't contain anything
containerMirror = ((LazyInterface) container).companionClass;
if (containerMirror == null) {
throw new ModelResolutionException("Interface companion class for " + container.getQualifiedNameString() + " not set up");
}
}
String companionName;
if (containerMirror != null)
companionName = containerMirror.getFlatName() + "$" + NamingBase.suffixName(NamingBase.Suffix.$impl, d.getName());
else {
// toplevel
String p = pkg.getNameAsString();
companionName = "";
if (!p.isEmpty())
companionName = p + ".";
companionName += NamingBase.suffixName(NamingBase.Suffix.$impl, d.getName());
}
ClassMirror companionClass = lookupClassMirror(pkg.getModule(), companionName);
if (companionClass == null) {
((Interface) d).setCompanionClassNeeded(false);
}
((LazyInterface) d).companionClass = companionClass;
}
Aggregations