use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class AnnotationUtil method isNaturalTarget.
/**
* Whether an annotation (with the given {@code annotationCtorDecl}
* annotation constructor) used on the given declaration ({@code useSite})
* should be added to the Java annotations of the given generated program
* elements ({@code target})
* @param annotationCtorDecl
* @param useSite
* @param target
* @return
*/
public static boolean isNaturalTarget(// use site is either a Declaration, or a Package, or a Module,
Function annotationCtorDecl, // module imports
Object useSite, OutputElement target) {
EnumSet<AnnotationTarget> interopTargets;
if (annotationCtorDecl instanceof AnnotationProxyMethod) {
AnnotationProxyMethod annotationProxyMethod = (AnnotationProxyMethod) annotationCtorDecl;
if (annotationProxyMethod.getAnnotationTarget() == target) {
// Foo__WHATEVER, so honour the WHATEVER
return true;
}
interopTargets = annotationProxyMethod.getAnnotationTargets();
} else {
interopTargets = null;
}
if (useSite instanceof Declaration) {
if (ModelUtil.isConstructor((Declaration) useSite)) {
if (useSite instanceof Functional) {
return target == OutputElement.CONSTRUCTOR;
} else if (useSite instanceof Value) {
// If the constructor has a getter we can't annotate, let's
// put the annotations on the constructor
Class constructedClass = ModelUtil.getConstructedClass((Declaration) useSite);
// See CeylonVisitor.transformSingletonConstructor for those tests
if (constructedClass.isToplevel() || constructedClass.isClassMember())
return target == OutputElement.GETTER;
return target == OutputElement.CONSTRUCTOR;
}
} else if (useSite instanceof Class) {
if (((Class) useSite).getParameterList() != null && interopTargets != null && interopTargets.contains(AnnotationTarget.CONSTRUCTOR) && !interopTargets.contains(AnnotationTarget.TYPE)) {
return target == OutputElement.CONSTRUCTOR;
}
return target == OutputElement.TYPE;
} else if (useSite instanceof Interface) {
return target == OutputElement.TYPE;
} else if (useSite instanceof Value) {
Value value = (Value) useSite;
boolean p = value.isParameter() && target == OutputElement.PARAMETER;
if (annotationCtorDecl instanceof AnnotationProxyMethod) {
if (!value.isTransient() && (interopTargets == null || interopTargets.contains(AnnotationTarget.FIELD))) {
return target == OutputElement.FIELD;
} else {
return target == OutputElement.GETTER;
}
} else {
return p || target == OutputElement.GETTER;
}
} else if (useSite instanceof Setter) {
return target == OutputElement.SETTER;
} else if (useSite instanceof Function) {
return target == OutputElement.METHOD;
} else if (useSite instanceof Constructor) {
return target == OutputElement.CONSTRUCTOR;
} else if (useSite instanceof TypeAlias) {
return target == OutputElement.TYPE;
}
} else if (useSite instanceof Package) {
return (annotationCtorDecl instanceof AnnotationProxyMethod) ? target == OutputElement.PACKAGE : target == OutputElement.TYPE;
} else if (useSite instanceof Module) {
return target == OutputElement.TYPE;
} else if (useSite instanceof Tree.ImportModule) {
return target == OutputElement.FIELD;
}
throw new RuntimeException("" + useSite);
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class ExpressionVisitor method getCallableBottomType.
private Type getCallableBottomType(int size) {
Type paramListType;
Type nothingType = unit.getNothingType();
Type anythingType = unit.getAnythingType();
if (size < 0) {
paramListType = anythingType;
} else {
paramListType = unit.getEmptyType();
Class tuple = unit.getTupleDeclaration();
for (int i = 0; i < size; i++) {
paramListType = appliedType(tuple, anythingType, anythingType, paramListType);
}
}
Interface callable = unit.getCallableDeclaration();
return appliedType(callable, nothingType, paramListType);
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class ExpressionVisitor method checkDelegatedConstructor.
protected void checkDelegatedConstructor(Tree.DelegatedConstructor dc, Constructor c, Node node) {
if (dc == null) {
if (c.isClassMember()) {
Class clazz = (Class) c.getContainer();
Type et = clazz.getExtendedType();
if (et != null && !et.isBasic()) {
TypeDeclaration superclass = et.getDeclaration();
if (superclass != null) {
node.addError("constructor must explicitly delegate to some superclass constructor: '" + clazz.getName() + "' extends '" + superclass.getName() + "'");
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.ClassDeclaration that) {
super.visit(that);
Class alias = that.getDeclarationModel();
Type et = alias.getExtendedType();
Tree.ClassSpecifier cs = that.getClassSpecifier();
if (cs != null && et != null) {
TypeDeclaration etd = et.getDeclaration();
if (etd instanceof Constructor) {
etd = etd.getExtendedType().getDeclaration();
}
if (etd instanceof Class) {
// TODO: some of this belongs in InheritanceVisitor!
Class c = (Class) etd;
if (c.isAbstract()) {
if (!alias.isFormal() && !alias.isAbstract()) {
that.addError("alias of abstract class must be annotated abstract", 310);
}
}
if (c.isAbstraction()) {
that.addError("class alias may not alias overloaded class");
} else {
Tree.InvocationExpression ie = cs.getInvocationExpression();
if (ie != null) {
checkClassAliasParameters(alias, that, ie);
}
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class ExpressionVisitor method visitGenericQualifiedTypeReference.
private void visitGenericQualifiedTypeReference(Tree.QualifiedTypeExpression that, Type outerType, TypeDeclaration type) {
if (type instanceof Class && type.isParameterized()) {
Class generic = (Class) type;
Scope scope = that.getScope();
Type target = outerType.getTypeMember(type, typeParametersAsArgList(generic));
that.setTarget(target);
Type functionType = genericFunctionType(generic, scope, type, target, unit);
that.setTypeModel(functionType);
checkNotJvm(that, "type functions are not supported on the JVM: '" + type.getName(unit) + "' is generic (specify explicit type arguments)");
}
}
Aggregations