use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class ExpressionVisitor method checkDefaultConstructorVisibility.
private boolean checkDefaultConstructorVisibility(Tree.MemberOrTypeExpression that, TypeDeclaration type) {
if (type instanceof Class && !contains(type, that.getScope()) && !that.getStaticMethodReferencePrimary()) {
Class c = (Class) type;
Constructor dc = c.getDefaultConstructor();
if (dc != null && !dc.isShared()) {
that.addError("default constructor for class '" + c.getName(unit) + "' is not 'shared'");
return false;
}
}
return true;
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class RefinementVisitor method checkMember.
private void checkMember(Tree.Declaration that, Declaration member) {
String name = member.getName();
if (name == null) {
return;
}
if (member instanceof Setter) {
Setter setter = (Setter) member;
Value getter = setter.getGetter();
Declaration rd = getter.getRefinedDeclaration();
member.setRefinedDeclaration(rd);
return;
}
ClassOrInterface type = (ClassOrInterface) member.getContainer();
if (member.isFormal() && type instanceof Class) {
Class c = (Class) type;
if (!c.isAbstract() && !c.isFormal()) {
if (c.isClassOrInterfaceMember()) {
that.addError("formal member belongs to concrete nested class: '" + member.getName() + "' is a member of class '" + c.getName() + "' which is neither 'abstract' nor 'formal'", 1100);
} else {
that.addError("formal member belongs to concrete class: '" + member.getName() + "' is a member of class '" + c.getName() + "' which is not annotated 'abstract'", 1100);
}
}
}
if (member.isStatic() && !type.isToplevel()) {
that.addError("static member belongs to a nested class: '" + member.getName() + "' is a member of nested type '" + type.getName() + "'");
}
if (type.isDynamic()) {
if (member instanceof Class) {
that.addError("member class belongs to dynamic interface");
} else if (!member.isFormal()) {
that.addError("non-formal member belongs to dynamic interface");
}
}
if (member instanceof Functional && !that.hasErrors() && isOverloadedVersion(member)) {
checkOverloadedAnnotation(that, member);
checkOverloadedParameters(that, member);
}
checkRefinement(that, member, type);
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class SpecificationVisitor method visit.
@Override
public void visit(Tree.DelegatedConstructor that) {
boolean odc = inDelegatedContructor;
inDelegatedContructor = true;
super.visit(that);
inDelegatedContructor = odc;
Tree.SimpleType type = that.getType();
if (type != null) {
delegatedConstructor = type.getDeclarationModel();
if (delegatedConstructor instanceof Class) {
// this case is not actually legal
Class c = (Class) delegatedConstructor;
delegatedConstructor = c.getDefaultConstructor();
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.AnyClass that) {
Class c = that.getDeclarationModel();
visitDeclaration(that, c);
Scope o = enterScope(c);
super.visit(that);
exitScope(o);
Tree.ParameterList pl = that.getParameterList();
if (pl != null) {
pl.getModel().setFirst(true);
c.addParameterList(pl.getModel());
}
// TODO: is this still necessary??
if (c.isClassOrInterfaceMember() && c.getContainer() instanceof TypedDeclaration) {
that.addUnsupportedError("nested classes of inner classes are not yet supported");
}
Tree.Identifier identifier = that.getIdentifier();
if (c.isAbstract() && c.isFinal()) {
that.addError("class may not be both 'abstract' and 'final': '" + name(identifier) + "'");
}
if (c.isFormal() && c.isFinal()) {
that.addError("class may not be both 'formal' and 'final': '" + name(identifier) + "'");
}
if (hasAnnotation(that.getAnnotationList(), "service", that.getUnit())) {
if (!c.getTypeParameters().isEmpty()) {
that.addError("service class may not be generic");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class DeclarationVisitor method initClassOverloads.
// A class with an overloaded default constructor
// is represented in the model as an overloaded
// class with multiple Class objects. The Constructor
// objects themselves are not represented as
// overloaded since we never look them up directly
// at the invocation site
private static void initClassOverloads(Scope scope, Class abstraction, Unit unit) {
ArrayList<Declaration> overloads = new ArrayList<Declaration>(3);
for (Declaration d : abstraction.getMembers()) {
if (isDefaultConstructor(d)) {
Constructor cc = (Constructor) d;
Class overload = new Class();
overload.setName(abstraction.getName());
overload.setUnit(unit);
overload.setScope(abstraction.getScope());
overload.setContainer(abstraction.getContainer());
overload.setOverloaded(true);
overload.setExtendedType(abstraction.getType());
overload.setParameterList(cc.getParameterList());
overload.setNativeBackends(abstraction.getNativeBackends());
overload.setFinal(abstraction.isFinal());
overloads.add(overload);
unit.addDeclaration(overload);
scope.addMember(overload);
}
}
abstraction.setOverloads(overloads);
}
Aggregations