use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.Declaration that) {
String filename = unit.getFilename();
Declaration model = that.getDeclarationModel();
if (isDescriptor(filename) && model.isToplevel()) {
that.addError("declaration may not occur in a module or package descriptor file");
}
Declaration d = beginDeclaration(model);
super.visit(that);
endDeclaration(d);
if (model.isClassOrInterfaceMember()) {
ClassOrInterface container = (ClassOrInterface) model.getContainer();
if (container.isFinal() && model.isDefault()) {
that.addError("member of final class may not be annotated 'default'", 1350);
}
}
if (model.isToplevel()) {
String name = model.getName();
if (name != null && name.endsWith("_")) {
that.addUnsupportedError("toplevel declaration name ending in _ not currently supported");
}
if (pkg.getNameAsString().endsWith("_")) {
that.addUnsupportedError("toplevel declaration belonging to package with name ending in _ not currently supported");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class DeclarationVisitor method checkForDuplicateDeclaration.
private static void checkForDuplicateDeclaration(Tree.Declaration that, Declaration model, Scope scope) {
String name = model.getName();
Unit unit = model.getUnit();
if (name != null) {
if (model instanceof Setter) {
Setter setter = (Setter) model;
checkGetterForSetter(that, setter, scope);
} else {
// this isn't the correct scope for declaration
// which follow an assertion, since it misses
// condition scopes, so use the argument scope
// Scope scope = model.getContainer();
boolean isControl;
do {
Declaration member = scope.getDirectMember(name, null, false);
if (member != null && member != model) {
boolean dup = false;
boolean possibleOverloadedMethod = member instanceof Function && model instanceof Function && scope instanceof ClassOrInterface && !member.isNative() && member.isShared() && model.isShared();
boolean legalOverloadedMethod = possibleOverloadedMethod;
if (legalOverloadedMethod) {
// anticipate that it might be
// an overloaded method - then
// further checking happens in
// RefinementVisitor
initFunctionOverload((Function) model, (Function) member, scope, unit);
} else if (canBeNative(member) && canBeNative(model) && model.isNative()) {
// just to make sure no error
// gets reported
} else {
dup = true;
if (possibleOverloadedMethod) {
// it as overloading anyway
if (initFunctionOverload((Function) model, (Function) member, scope, unit)) {
that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
}
} else {
that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
}
}
if (dup) {
unit.getDuplicateDeclarations().add(member);
}
}
isControl = scope instanceof ControlBlock;
scope = scope.getContainer();
} while (isControl);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.ClassDefinition that) {
Class c = new Class();
if (!isVeryAbstractClass(that, unit)) {
defaultExtendedToBasic(c);
}
that.setDeclarationModel(c);
super.visit(that);
if (that.getParameterList() == null) {
if (c.isClassOrInterfaceMember() && (c.isFormal() || c.isDefault() || c.isActual())) {
that.addError("member class declared 'formal', 'default', or 'actual' must have a parameter list");
}
Tree.AnnotationList al = that.getAnnotationList();
if (hasAnnotation(al, "sealed", unit)) {
that.addError("class without parameter list may not be annotated 'sealed'", 1800);
}
}
if (c.isSealed() && c.isFormal() && c.isClassOrInterfaceMember()) {
ClassOrInterface container = (ClassOrInterface) c.getContainer();
if (!container.isSealed()) {
that.addError("sealed formal member class does not belong to a sealed type", 1801);
}
}
if (c.isNativeImplementation()) {
addMissingHeaderMembers(c);
}
if (c.isAbstraction()) {
initClassOverloads(getContainer(that), c, unit);
}
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.ObjectDefinition that) {
Class c = new Class();
defaultExtendedToBasic(c);
c.setAnonymous(true);
that.setAnonymousClass(c);
visitDeclaration(that, c, false);
Value v = new Value();
that.setDeclarationModel(v);
visitDeclaration(that, v);
Type t = c.getType();
that.getType().setTypeModel(t);
v.setType(t);
v.setStatic(c.isStatic());
if (c.isStatic()) {
Scope container = v.getContainer();
if (container instanceof ClassOrInterface) {
ClassOrInterface ci = (ClassOrInterface) container;
if (!ci.getTypeParameters().isEmpty()) {
that.addError("anonymous class belonging to generic type may not be annotated 'static'");
}
}
}
Scope o = enterScope(c);
super.visit(that);
exitScope(o);
if (c.isInterfaceMember()) {
that.addError("object declaration may not occur directly in interface body");
}
if (c.isNativeImplementation()) {
addMissingHeaderMembers(c);
}
}
use of org.eclipse.ceylon.model.typechecker.model.ClassOrInterface in project ceylon by eclipse.
the class InheritanceVisitor method visit.
@Override
public void visit(Tree.SatisfiedTypes that) {
super.visit(that);
TypeDeclaration td = (TypeDeclaration) that.getScope();
if (td.isAlias()) {
return;
}
Set<TypeDeclaration> set = new HashSet<TypeDeclaration>();
if (td.getSatisfiedTypes().isEmpty()) {
// handle undecidable case
return;
}
Unit unit = that.getUnit();
for (Tree.StaticType t : that.getTypes()) {
Type type = t.getTypeModel();
if (!isTypeUnknown(type) && type.isClassOrInterface()) {
type = type.resolveAliases();
TypeDeclaration dec = type.getDeclaration();
if (td instanceof ClassOrInterface && !unit.getPackage().getModule().isLanguageModule()) {
if (unit.isCallableType(type)) {
t.addError("satisfies 'Callable'");
}
TypeDeclaration cad = unit.getConstrainedAnnotationDeclaration();
if (dec.equals(cad)) {
t.addError("directly satisfies 'ConstrainedAnnotation'");
}
}
if (!set.add(dec)) {
// this error is not really truly necessary
// but the spec says it is an error, and
// the backend doesn't like it
t.addError("duplicate satisfied type: '" + dec.getName(unit) + "' of '" + td.getName() + "'");
}
if (td instanceof ClassOrInterface) {
TypeDeclaration std = dec;
if (std.isSealed() && !unit.inSameModule(std)) {
String moduleName = std.getUnit().getPackage().getModule().getNameAsString();
t.addError("satisfies a sealed interface in a different module: '" + std.getName(unit) + "' in '" + moduleName + "'");
}
}
checkSelfTypes(t, td, type);
checkExtensionOfMemberType(t, td, type);
/*if (!(td instanceof TypeParameter)) {
checkCaseOfSupertype(t, td, type);
}*/
}
if (t instanceof Tree.SimpleType) {
Tree.SimpleType st = (Tree.SimpleType) t;
checkSupertypeVarianceAnnotations(st);
}
}
}
Aggregations