use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class InheritanceVisitor method checkDirectSubtype.
private static boolean checkDirectSubtype(TypeDeclaration td, Node node, Type type) {
boolean found = false;
TypeDeclaration ctd = type.getDeclaration();
if (td instanceof Interface) {
for (Type st : ctd.getSatisfiedTypes()) {
if (st != null && st.resolveAliases().getDeclaration().equals(td)) {
found = true;
}
}
} else if (td instanceof Class) {
Type et = ctd.getExtendedType();
if (et != null && et.resolveAliases().getDeclaration().equals(td)) {
found = true;
}
}
if (!found) {
node.addError("case type is not a direct subtype of enumerated type: " + ctd.getName(node.getUnit()));
}
return found;
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class InheritanceVisitor method visit.
@Override
public void visit(Tree.ExtendedType that) {
super.visit(that);
TypeDeclaration td = (TypeDeclaration) that.getScope();
if (!td.isAlias()) {
Tree.SimpleType et = that.getType();
if (et != null) {
Tree.InvocationExpression ie = that.getInvocationExpression();
Class clazz = (Class) td;
boolean hasConstructors = clazz.hasConstructors() || clazz.hasEnumerated();
boolean anonymous = clazz.isAnonymous();
if (ie == null) {
if (!hasConstructors || anonymous) {
et.addError("missing instantiation arguments");
}
} else {
if (hasConstructors && !anonymous) {
et.addError("unnecessary instantiation arguments");
}
}
Unit unit = that.getUnit();
Type type = et.getTypeModel();
if (type != null) {
checkSelfTypes(et, td, type);
checkExtensionOfMemberType(et, td, type);
// checkCaseOfSupertype(et, td, type);
Type ext = td.getExtendedType();
TypeDeclaration etd = ext == null ? null : ext.getDeclaration();
TypeDeclaration aetd = type.getDeclaration();
if (aetd instanceof Constructor && aetd.isAbstract()) {
et.addError("extends a partial constructor: '" + aetd.getName(unit) + "' is declared abstract");
}
while (etd != null && etd.isAlias()) {
Type etdet = etd.getExtendedType();
etd = etdet == null ? null : etdet.getDeclaration();
}
if (etd != null) {
if (etd.isFinal()) {
et.addError("extends a final class: '" + etd.getName(unit) + "' is declared final");
}
if (aetd instanceof Class && !contains(aetd, that.getScope())) {
Class c = (Class) aetd;
Constructor dc = c.getDefaultConstructor();
if (dc != null && !dc.isShared()) {
that.addError("extends a class with an unshared default constructor: default constructor of '" + c.getName(unit) + "' is not 'shared'");
}
}
if (etd.isSealed() && !unit.inSameModule(etd)) {
String moduleName = etd.getUnit().getPackage().getModule().getNameAsString();
et.addError("extends a sealed class in a different module: '" + etd.getName(unit) + "' in '" + moduleName + "' is sealed");
}
}
}
checkSupertypeVarianceAnnotations(et);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class InheritanceVisitor method visit.
@Override
public void visit(Tree.Constructor that) {
super.visit(that);
Constructor c = that.getConstructor();
Scope container = c.getContainer();
if (container instanceof Class) {
Class cl = (Class) container;
List<TypedDeclaration> caseValues = cl.getCaseValues();
if (caseValues != null && !c.isAbstract() && !cl.isAbstract()) {
that.addError("concrete enumerated class may not have non-partial callable constructor: enumerated class '" + cl.getName() + "' is not abstract and constructor '" + c.getName() + "' is not partial");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class LocalDeclarationVisitor method visit.
@Override
public void visit(Tree.ObjectDefinition that) {
visitLocalDecl(that);
// use the same qualifier for the object type
Class c = that.getAnonymousClass();
Value v = that.getDeclarationModel();
if (c != null && v != null) {
c.setQualifier(v.getQualifier());
}
Map<String, Integer> oldLocalNames = localNames;
localNames = new HashMap<String, Integer>();
super.visit(that);
localNames = oldLocalNames;
}
use of org.eclipse.ceylon.model.typechecker.model.Class in project ceylon by eclipse.
the class TypeHierarchyVisitor method getOrBuildType.
/*private void removeTrailing(String trailingString, StringBuilder sb) {
final int length = sb.length();
sb.delete(length-trailingString.length(), length);
}*/
private Type getOrBuildType(TypeDeclaration declaration) {
Type type = types.get(new TypeDeclKey(declaration));
if (type == null) {
type = new Type();
type.declaration = declaration;
for (Declaration member : declaration.getMembers()) {
if (!(member instanceof FunctionOrValue || member instanceof Class) || isConstructor(member) || member.isStatic() || isAbstraction(member)) {
continue;
}
if (declaration.isNative() && member.isNative()) {
// Make sure we get the right member declaration (the one for the same backend as its container)
Backends backends = declaration.getNativeBackends();
member = getNativeDeclaration(member, backends);
if (member == null) {
continue;
}
}
final String name = member.getName();
Type.Members members = type.membersByName.get(name);
if (members == null) {
members = new Type.Members();
members.name = name;
type.membersByName.put(name, members);
}
if (member.isActual()) {
members.actuals.add(member);
if (!member.isFormal()) {
members.actualsNonFormals.add(member);
}
}
if (member.isFormal()) {
members.formals.add(member);
}
/*if (!member.isFormal() && member.isInterfaceMember()) {
members.concretesOnInterfaces.add(member);
}*/
if (member.isDefault()) {
members.defaults.add(member);
}
if (!member.isFormal() && !member.isDefault() && member.isShared()) {
members.nonFormalsNonDefaults.add(member);
}
if (member.isShared()) {
members.shared.add(member);
}
}
types.put(new TypeDeclKey(declaration), type);
}
return type;
}
Aggregations