use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class BoxingDeclarationVisitor method visit.
@Override
public void visit(AttributeSetterDefinition that) {
super.visit(that);
Setter declaration = that.getDeclarationModel();
// deal with invalid input
if (declaration == null)
return;
// To determine boxing for a setter we use its parameter
TypedDeclaration paramDeclaration = declaration.getParameter().getModel();
boxAttribute(paramDeclaration, that);
// Now copy the settings from the parameter to the setter itself
declaration.setUnboxed(paramDeclaration.getUnboxed());
// Then we check if there are any overriding compiler annotations
boxFromAnnotation(declaration, that);
// And finally we copy the setting back again to make sure they're really the same
paramDeclaration.setUnboxed(declaration.getUnboxed());
}
use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class ClassOrPackageDoc method doc.
protected final void doc(String id, String name, Declaration d) throws IOException {
String declarationName = Util.getDeclarationName(d);
id = (id != null ? id : name);
boolean alias = Util.nullSafeCompare(name, declarationName) != 0;
// put the id on the td because IE8 doesn't support id attributes on tr (yeah right)
open("tr");
open("td id='" + id + "' nowrap");
writeIcon(d);
if (!(d instanceof Constructor)) {
around("code class='decl-label'", name);
close("td");
open("td");
}
writeLinkOneSelf(id);
if (alias) {
writeTagged(d);
writeAlias(d);
} else {
writeLinkSource(d);
writeTagged(d);
if (d instanceof Functional) {
writeParameterLinksIfRequired((Functional) d);
}
open("code class='signature'");
around("span class='modifiers'", getModifiers(d));
write(" ");
if (!ModelUtil.isConstructor(d)) {
if (!Decl.isDynamic(d)) {
if (d instanceof Functional && ((Functional) d).isDeclaredVoid()) {
around("span class='void'", "void");
} else if (d instanceof TypedDeclaration) {
linkRenderer().to(((TypedDeclaration) d).getType()).useScope(d).write();
} else {
linkRenderer().to(d).useScope(d).write();
}
} else {
around("span class='dynamic'", "dynamic");
}
}
write(" ");
open("span class='identifier'");
write(name);
close("span");
if (isConstantValue(d)) {
writeConstantValue((Value) d);
}
if (d instanceof Generic) {
writeTypeParameters(d.getTypeParameters(), d);
}
if (d instanceof Functional) {
writeParameterList((Functional) d, d);
}
if (d instanceof Generic) {
writeTypeParametersConstraints(d.getTypeParameters(), d);
}
if (d instanceof Value) {
Setter setter = ((Value) d).getSetter();
if (setter != null && Util.getAnnotation(setter.getUnit(), setter.getAnnotations(), "doc") != null) {
tool.warningSetterDoc(d.getQualifiedNameString(), d);
}
}
close("code");
writeDescription(d);
}
close("td");
close("tr");
}
use of org.eclipse.ceylon.model.typechecker.model.Setter 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.Setter in project ceylon by eclipse.
the class ExpressionVisitor method visit.
/*private void checkKeyValueType(Tree.Variable key, Tree.Variable value,
Tree.SpecifierExpression se) {
if (key.getType()!=null && value.getType()!=null) {
Type kt = key.getType().getTypeModel();
Type vt = value.getType().getTypeModel();
if (!isTypeUnknown(kt) && !isTypeUnknown(vt)) {
checkType(unit.getIterableType(unit.getEntryType(kt, vt)), se);
}
}
}*/
@Override
public void visit(Tree.AttributeGetterDefinition that) {
Value val = that.getDeclarationModel();
Declaration od = beginReturnDeclaration(val);
Tree.Type type = that.getType();
Tree.Type rt = beginReturnScope(type);
super.visit(that);
endReturnScope(rt, val);
endReturnDeclaration(od);
Setter setter = val.getSetter();
if (setter != null) {
setter.getParameter().getModel().setType(val.getType());
}
if (type instanceof Tree.LocalModifier) {
if (isTypeUnknown(type.getTypeModel())) {
type.addError("getter type could not be inferred");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.AttributeDeclaration that) {
super.visit(that);
Value val = that.getDeclarationModel();
Tree.SpecifierOrInitializerExpression sie = that.getSpecifierOrInitializerExpression();
if (!val.isActual() || // accountForIntermediateRefinements()
isTypeUnknown(val.getType())) {
inferType(that, sie);
}
Tree.Type type = that.getType();
if (type != null) {
Type t = type.getTypeModel();
if (type instanceof Tree.LocalModifier && !isNativeForWrongBackend(val, unit)) {
if (val.isParameter() && !val.isInferred()) {
type.addError("parameter may not have inferred type: '" + val.getName() + "' must declare an explicit type");
} else if (isTypeUnknown(t)) {
if (sie == null) {
type.addError("value must specify an explicit type or definition", 200);
} else if (!hasError(sie)) {
type.addError("value type could not be inferred: '" + val.getName() + "'" + getTypeUnknownError(t));
}
}
}
if (!isTypeUnknown(t)) {
checkType(t, val, sie, 2100);
}
}
Setter setter = val.getSetter();
if (setter != null) {
setter.getParameter().getModel().setType(val.getType());
}
}
Aggregations