use of org.eclipse.ceylon.model.loader.model.LazyContainer in project ceylon by eclipse.
the class AbstractModelLoader method setTypeParametersFromAnnotations.
// from our annotation
private void setTypeParametersFromAnnotations(Scope scope, List<TypeParameter> params, AnnotatedMirror mirror, List<AnnotationMirror> typeParameterAnnotations, List<TypeParameterMirror> typeParameterMirrors) {
// We must first add every type param, before we resolve the bounds, which can
// refer to type params.
String selfTypeName = getSelfTypeFromAnnotations(mirror);
int i = 0;
for (AnnotationMirror typeParamAnnotation : typeParameterAnnotations) {
TypeParameter param = new TypeParameter();
param.setUnit(scope.getUnit());
param.setContainer(scope);
param.setScope(scope);
ModelUtil.setVisibleScope(param);
param.setDeclaration((Declaration) scope);
// let's not trigger the lazy-loading if we're completing a LazyClass/LazyInterface
if (scope instanceof LazyContainer)
((LazyContainer) scope).addMember(param);
else
// must be a method
scope.addMember(param);
param.setName((String) typeParamAnnotation.getValue("value"));
param.setExtendedType(typeFactory.getAnythingType());
if (i < typeParameterMirrors.size()) {
TypeParameterMirror typeParameterMirror = typeParameterMirrors.get(i);
param.setNonErasedBounds(hasNonErasedBounds(typeParameterMirror));
}
String varianceName = (String) typeParamAnnotation.getValue("variance");
if (varianceName != null) {
if (varianceName.equals("IN")) {
param.setContravariant(true);
} else if (varianceName.equals("OUT"))
param.setCovariant(true);
}
// If this is a self type param then link it to its type's declaration
if (param.getName().equals(selfTypeName)) {
param.setSelfTypedDeclaration((TypeDeclaration) scope);
}
params.add(param);
i++;
}
Module moduleScope = ModelUtil.getModuleContainer(scope);
// Now all type params have been set, we can resolve the references parts
Iterator<TypeParameter> paramsIterator = params.iterator();
for (AnnotationMirror typeParamAnnotation : typeParameterAnnotations) {
TypeParameter param = paramsIterator.next();
@SuppressWarnings("unchecked") List<String> satisfiesAttribute = (List<String>) typeParamAnnotation.getValue("satisfies");
setListOfTypes(param.getSatisfiedTypes(), satisfiesAttribute, scope, moduleScope, "type parameter '" + param.getName() + "' satisfied types");
@SuppressWarnings("unchecked") List<String> caseTypesAttribute = (List<String>) typeParamAnnotation.getValue("caseTypes");
if (caseTypesAttribute != null && !caseTypesAttribute.isEmpty())
param.setCaseTypes(new LinkedList<Type>());
setListOfTypes(param.getCaseTypes(), caseTypesAttribute, scope, moduleScope, "type parameter '" + param.getName() + "' case types");
String defaultValueAttribute = (String) typeParamAnnotation.getValue("defaultValue");
if (defaultValueAttribute != null && !defaultValueAttribute.isEmpty()) {
Type decodedType = decodeType(defaultValueAttribute, scope, moduleScope, "type parameter '" + param.getName() + "' defaultValue");
param.setDefaultTypeArgument(decodedType);
param.setDefaulted(true);
}
}
}
use of org.eclipse.ceylon.model.loader.model.LazyContainer in project ceylon by eclipse.
the class AbstractModelLoader method setContainer.
private void setContainer(ClassMirror classMirror, Declaration d, LazyPackage pkg) {
// add it to its package if it's not an inner class
if (!classMirror.isInnerClass() && !classMirror.isLocalClass()) {
d.setContainer(pkg);
d.setScope(pkg);
pkg.addCompiledMember(d);
if (d instanceof LazyInterface && ((LazyInterface) d).isCeylon()) {
setInterfaceCompanionClass(d, null, pkg);
}
ModelUtil.setVisibleScope(d);
} else if (classMirror.isLocalClass() && !classMirror.isInnerClass()) {
// set its container to the package for now, but don't add it to the package as a member because it's not
Scope localContainer = getLocalContainer(pkg, classMirror, d);
if (localContainer != null) {
d.setContainer(localContainer);
d.setScope(localContainer);
// do not add it as member, it has already been registered by getLocalContainer
} else {
d.setContainer(pkg);
d.setScope(pkg);
}
((LazyElement) d).setLocal(true);
} else if (d instanceof ClassOrInterface || d instanceof TypeAlias) {
// we have to set that one first
if (d instanceof Class == false || !((Class) d).isOverloaded()) {
ClassOrInterface container = getContainer(pkg.getModule(), classMirror);
if (d.isNativeHeader() && container.isNative()) {
container = (ClassOrInterface) ModelUtil.getNativeHeader(container);
} else if (d.isNativeImplementation() && // for every Java declaration, who don't have native headers
container.isNativeHeader()) {
container = (ClassOrInterface) ModelUtil.getNativeDeclaration(container, Backend.Java);
}
d.setContainer(container);
d.setScope(container);
if (d instanceof LazyInterface && ((LazyInterface) d).isCeylon()) {
setInterfaceCompanionClass(d, container, pkg);
}
// let's not trigger lazy-loading
((LazyContainer) container).addMember(d);
ModelUtil.setVisibleScope(d);
// now we can do overloads
if (d instanceof Class && ((Class) d).getOverloads() != null) {
for (Declaration overload : ((Class) d).getOverloads()) {
overload.setContainer(container);
overload.setScope(container);
// let's not trigger lazy-loading
((LazyContainer) container).addMember(overload);
ModelUtil.setVisibleScope(overload);
}
}
// Adds extra members for annotation interop.
if (d instanceof LazyInterface && !((LazyInterface) d).isCeylon() && ((LazyInterface) d).isAnnotationType()) {
for (Declaration decl : makeInteropAnnotation((LazyInterface) d, container)) {
container.addMember(decl);
}
}
}
}
}
use of org.eclipse.ceylon.model.loader.model.LazyContainer in project ceylon by eclipse.
the class AbstractModelLoader method setTypeParameters.
// from java type info
private void setTypeParameters(Scope scope, List<TypeParameter> params, List<TypeParameterMirror> typeParameters, boolean isCeylon) {
// refer to type params.
for (TypeParameterMirror typeParam : typeParameters) {
TypeParameter param = new TypeParameter();
param.setUnit(scope.getUnit());
param.setContainer(scope);
param.setScope(scope);
ModelUtil.setVisibleScope(param);
param.setDeclaration((Declaration) scope);
// let's not trigger the lazy-loading if we're completing a LazyClass/LazyInterface
if (scope instanceof LazyContainer)
((LazyContainer) scope).addMember(param);
else
// must be a method
scope.addMember(param);
param.setName(typeParam.getName());
param.setExtendedType(typeFactory.getAnythingType());
params.add(param);
}
boolean needsObjectBounds = !isCeylon && scope instanceof Function;
// Now all type params have been set, we can resolve the references parts
Iterator<TypeParameter> paramsIterator = params.iterator();
for (TypeParameterMirror typeParam : typeParameters) {
TypeParameter param = paramsIterator.next();
List<TypeMirror> bounds = typeParam.getBounds();
for (TypeMirror bound : bounds) {
Type boundType;
// we turn java's default upper bound java.lang.Object into ceylon.language.Object
if (sameType(bound, OBJECT_TYPE)) {
// especially since we do not want it for types
if (bounds.size() == 1)
break;
boundType = getNonPrimitiveType(getLanguageModule(), CEYLON_OBJECT_TYPE, scope);
} else
boundType = getNonPrimitiveType(ModelUtil.getModuleContainer(scope), bound, scope);
param.getSatisfiedTypes().add(boundType);
}
if (needsObjectBounds && param.getSatisfiedTypes().isEmpty()) {
Type boundType = getNonPrimitiveType(getLanguageModule(), CEYLON_OBJECT_TYPE, scope);
param.getSatisfiedTypes().add(boundType);
}
}
}
Aggregations