use of org.eclipse.ceylon.model.typechecker.model.Interface 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.Interface in project ceylon by eclipse.
the class TypePrinter method abbreviateCallable.
public static boolean abbreviateCallable(Type pt) {
if (pt.isInterface()) {
TypeDeclaration dec = pt.getDeclaration();
Unit unit = dec.getUnit();
Interface callableDeclaration = unit.getCallableDeclaration();
return dec.equals(callableDeclaration) && pt.getTypeArgumentList().size() == 2 && pt.getTypeArgumentList().get(0) != null;
} else {
return false;
}
}
use of org.eclipse.ceylon.model.typechecker.model.Interface 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.Interface in project ceylon by eclipse.
the class ExpressionVisitor method checkSequencedIndirectArgument.
private void checkSequencedIndirectArgument(List<Tree.PositionalArgument> args, Type paramType) {
Type set = paramType == null ? null : unit.getIteratedType(paramType);
for (int j = 0; j < args.size(); j++) {
Tree.PositionalArgument a = args.get(j);
Type at = a.getTypeModel();
if (!isTypeUnknown(at) && !isTypeUnknown(paramType)) {
if (a instanceof Tree.SpreadArgument) {
at = spreadType(at, unit, true);
checkAssignable(at, paramType, a, "spread argument must be assignable to variadic parameter", 2101);
} else {
checkAssignable(at, set, a, "argument must be assignable to variadic parameter", 2101);
// if we already have an arg to a nonempty variadic parameter,
// we can treat it like a possibly-empty variadic now
Interface sd = unit.getSequentialDeclaration();
paramType = paramType.getSupertype(sd);
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Interface in project ceylon by eclipse.
the class ExpressionVisitor method visitEqualityOperator.
private void visitEqualityOperator(Tree.BinaryOperatorExpression that) {
Type lhst = leftType(that);
Type rhst = rightType(that);
if (!isTypeUnknown(rhst) && !isTypeUnknown(lhst)) {
Type obt = unit.getObjectType();
checkAssignable(lhst, obt, that.getLeftTerm(), "operand expression must be of type 'Object'");
checkAssignable(rhst, obt, that.getRightTerm(), "operand expression must be of type 'Object'");
if (intersectionType(lhst, rhst, unit).isNothing()) {
Interface ld = unit.getListDeclaration();
Interface sd = unit.getSetDeclaration();
Interface md = unit.getMapDeclaration();
if (!(lhst.getDeclaration().inherits(ld) && rhst.getDeclaration().inherits(ld)) && !(lhst.getDeclaration().inherits(sd) && rhst.getDeclaration().inherits(sd)) && !(lhst.getDeclaration().inherits(md) && rhst.getDeclaration().inherits(md)) && !(lhst.isInteger() && rhst.isFloat()) && !(lhst.isFloat() && rhst.isInteger())) {
that.addUsageWarning(Warning.disjointEquals, "tests equality for operands with disjoint types: '" + lhst.asString(unit) + "' and '" + rhst.asString(unit) + "' are disjoint");
}
}
if (lhst.isCallable()) {
that.getLeftTerm().addUsageWarning(Warning.expressionTypeCallable, "equality test not meaningful for function references: expression is of type 'Callable'");
}
if (rhst.isCallable()) {
that.getRightTerm().addUsageWarning(Warning.expressionTypeCallable, "equality test not meaningful for function references: expression is of type 'Callable'");
}
if (lhst.isIterable()) {
that.getLeftTerm().addUsageWarning(Warning.expressionTypeIterable, "equality test not meaningful for abstract streams: expression is of type 'Iterable'");
}
if (rhst.isIterable()) {
that.getRightTerm().addUsageWarning(Warning.expressionTypeIterable, "equality test not meaningful for abstract streams: expression is of type 'Iterable'");
}
}
that.setTypeModel(unit.getBooleanType());
}
Aggregations