use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class ClassTransformer method transformClassAliasInstantiator.
/**
* Builds the instantiator method for a class aliases. In 1.0 you can't
* actually invoke these, they exist just so there's somewhere to put the
* class alias annotations. In 1.2 (when we fix #1295) the
* instantiators will actually do something.
*/
private MethodDefinitionBuilder transformClassAliasInstantiator(final Tree.AnyClass def, Class model, Type aliasedClass) {
MethodDefinitionBuilder instantiator = MethodDefinitionBuilder.systemMethod(this, NamingBase.getAliasInstantiatorMethodName(model));
int f = 0;
if (Strategy.defaultParameterMethodStatic(def.getDeclarationModel())) {
f = STATIC;
}
instantiator.modifiers((modifierTransformation().classFlags(model) & ~FINAL) | f);
for (TypeParameter tp : typeParametersOfAllContainers(model, false)) {
instantiator.typeParameter(tp);
}
transformTypeParameters(instantiator, model);
instantiator.resultType(new TransformedType(makeJavaType(aliasedClass), null, makeAtNonNull()));
instantiator.annotationFlags(Annotations.MODEL_AND_USER | Annotations.IGNORE);
for (final Tree.Parameter param : def.getParameterList().getParameters()) {
// Overloaded instantiators
Parameter paramModel = param.getParameterModel();
at(param);
transformParameter(instantiator, param, paramModel, Decl.getMemberDeclaration(def, param));
}
instantiator.body(make().Throw(makeNewClass(makeJavaType(typeFact().getExceptionType(), JT_CLASS_NEW))));
return instantiator;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class ClassTransformer method producedTypeParameterBounds.
private java.util.List<java.util.List<Type>> producedTypeParameterBounds(final Reference typedMember, Generic subMethod) {
java.util.List<java.util.List<Type>> producedTypeParameterBounds = new ArrayList<java.util.List<Type>>(subMethod.getTypeParameters().size());
for (TypeParameter tp : subMethod.getTypeParameters()) {
java.util.List<Type> satisfiedTypes = tp.getType().getSatisfiedTypes();
ArrayList<Type> bounds = new ArrayList<>(satisfiedTypes.size());
for (Type bound : satisfiedTypes) {
if (typedMember instanceof Type) {
bounds.add(bound.substitute((Type) typedMember));
} else if (typedMember instanceof TypedReference) {
bounds.add(bound.substitute((TypedReference) typedMember));
}
}
producedTypeParameterBounds.add(bounds);
}
return producedTypeParameterBounds;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class ClassTransformer method addRefinedThrowerInstantiatorMethod.
private void addRefinedThrowerInstantiatorMethod(ClassDefinitionBuilder classBuilder, String message, ClassOrInterface classModel, Class formalClass, Reference unrefined) {
MethodDefinitionBuilder mdb = MethodDefinitionBuilder.systemMethod(this, naming.getInstantiatorMethodName(formalClass));
mdb.modifiers(modifierTransformation().classFlags(formalClass) & ~ABSTRACT);
for (TypeParameter tp : formalClass.getTypeParameters()) {
mdb.typeParameter(tp);
mdb.reifiedTypeParameter(tp);
}
for (Parameter formalP : formalClass.getParameterList().getParameters()) {
ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.systemParameter(this, formalP.getName());
pdb.sequenced(formalP.isSequenced());
pdb.defaulted(formalP.isDefaulted());
pdb.type(new TransformedType(makeJavaType(unrefined.getTypedParameter(formalP).getType())));
mdb.parameter(pdb);
}
mdb.resultType(makeJavaType(unrefined.getType()), null);
mdb.body(makeThrowUnresolvedCompilationError(message));
classBuilder.method(mdb);
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class ClassTransformer method refineMethod.
/*private Class refineClass(
Scope container,
Reference pr,
ClassOrInterface classModel,
Class formalClass,
Unit unit) {
Class refined = new Class();
refined.setActual(true);
refined.setShared(formalClass.isShared());
refined.setContainer(container);
refined.setExtendedType(formalClass.getType());
refined.setDeprecated(formalClass.isDeprecated());
refined.setName(formalClass.getName());
refined.setRefinedDeclaration(formalClass.getRefinedDeclaration());
refined.setScope(container);
//refined.setType(pr.getType());
refined.setUnit(unit);
for (ParameterList formalPl : formalClass.getParameterLists()) {
ParameterList refinedPl = new ParameterList();
for (Parameter formalP : formalPl.getParameters()){
Parameter refinedP = new Parameter();
refinedP.setAtLeastOne(formalP.isAtLeastOne());
refinedP.setDeclaration(refined);
refinedP.setDefaulted(formalP.isDefaulted());
refinedP.setDeclaredAnything(formalP.isDeclaredAnything());
refinedP.setHidden(formalP.isHidden());
refinedP.setSequenced(formalP.isSequenced());
refinedP.setName(formalP.getName());
final TypedReference typedParameter = pr.getTypedParameter(formalP);
FunctionOrValue paramModel;
if (formalP.getModel() instanceof Value) {
Value paramValueModel = refineValue((Value)formalP.getModel(), typedParameter, refined, classModel.getUnit());
paramValueModel.setInitializerParameter(refinedP);
paramModel = paramValueModel;
} else {
Function paramFunctionModel = refineMethod(refined, typedParameter, classModel, (Function)formalP.getModel(), unit);
paramFunctionModel.setInitializerParameter(refinedP);
paramModel = paramFunctionModel;
}
refinedP.setModel(paramModel);
refinedPl.getParameters().add(refinedP);
}
refined.addParameterList(refinedPl);
}
return refined;
}*/
private Function refineMethod(Scope container, TypedReference pr, ClassOrInterface classModel, Function formalMethod, Unit unit) {
Function refined = new Function();
refined.setActual(true);
refined.setShared(formalMethod.isShared());
refined.setContainer(container);
// in case there are subclasses
refined.setDefault(true);
refined.setDeferred(false);
refined.setDeprecated(formalMethod.isDeprecated());
refined.setName(formalMethod.getName());
refined.setRefinedDeclaration(formalMethod.getRefinedDeclaration());
refined.setScope(container);
refined.setType(pr.getType());
refined.setUnit(unit);
refined.setUnboxed(formalMethod.getUnboxed());
refined.setUntrustedType(formalMethod.getUntrustedType());
refined.setTypeErased(formalMethod.getTypeErased());
ArrayList<TypeParameter> refinedTp = new ArrayList<TypeParameter>();
;
for (TypeParameter formalTp : formalMethod.getTypeParameters()) {
refinedTp.add(formalTp);
}
refined.setTypeParameters(refinedTp);
for (ParameterList formalPl : formalMethod.getParameterLists()) {
ParameterList refinedPl = new ParameterList();
for (Parameter formalP : formalPl.getParameters()) {
Parameter refinedP = new Parameter();
refinedP.setAtLeastOne(formalP.isAtLeastOne());
refinedP.setDeclaration(refined);
refinedP.setDefaulted(formalP.isDefaulted());
refinedP.setDeclaredAnything(formalP.isDeclaredAnything());
refinedP.setHidden(formalP.isHidden());
refinedP.setSequenced(formalP.isSequenced());
refinedP.setName(formalP.getName());
final TypedReference typedParameter = pr.getTypedParameter(formalP);
FunctionOrValue paramModel;
if (formalP.getModel() instanceof Value) {
Value paramValueModel = refineValue((Value) formalP.getModel(), typedParameter, refined, classModel.getUnit());
paramValueModel.setInitializerParameter(refinedP);
paramModel = paramValueModel;
} else {
Function paramFunctionModel = refineMethod(refined, typedParameter, classModel, (Function) formalP.getModel(), unit);
paramFunctionModel.setInitializerParameter(refinedP);
paramModel = paramFunctionModel;
}
refinedP.setModel(paramModel);
refinedPl.getParameters().add(refinedP);
}
refined.addParameterList(refinedPl);
}
return refined;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class ClassTransformer method typeParametersForInstantiator.
/**
* When generating an instantiator method if the inner class has a type
* parameter with the same name as a type parameter of an outer type, then the
* instantiator method shouldn't declare its own type parameter of that
* name -- it should use the captured one. This method filters out the
* type parameters of the inner class which are the same as type parameters
* of the outer class so that they can be captured.
*/
private java.util.List<TypeParameter> typeParametersForInstantiator(final Class model) {
java.util.List<TypeParameter> filtered = new ArrayList<TypeParameter>();
java.util.List<TypeParameter> tps = model.getTypeParameters();
if (tps != null) {
for (TypeParameter tp : tps) {
boolean omit = false;
Scope s = model.getContainer();
while (!(s instanceof Package)) {
if (s instanceof Generic) {
for (TypeParameter outerTp : ((Generic) s).getTypeParameters()) {
if (tp.getName().equals(outerTp.getName())) {
omit = true;
}
}
}
s = s.getContainer();
}
if (!omit) {
filtered.add(tp);
}
}
}
return filtered;
}
Aggregations