use of org.eclipse.ceylon.model.typechecker.model.Constructor 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.Constructor in project ceylon by eclipse.
the class SpecificationVisitor method visit.
@Override
public void visit(Tree.Constructor that) {
Function f = that.getDeclarationModel();
Constructor c = that.getConstructor();
if (f == declaration || c == declaration) {
declare();
specify();
}
super.visit(that);
if (declaration.getContainer() == c.getContainer() && that == lastConstructor && initedByEveryConstructor) {
definitely = true;
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor 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);
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class DeclarationVisitor method checkForNativeAnnotation.
private void checkForNativeAnnotation(Tree.Declaration that, Declaration model, Scope scope) {
Unit unit = model.getUnit();
if (model.isNative()) {
Backends mbackends = model.getNativeBackends();
boolean isHeader = model.isNativeHeader();
String name = model.getName();
boolean canBeNative = canBeNative(that);
if (canBeNative) {
Backends moduleBackends = unit.getPackage().getModule().getNativeBackends();
Backends backends = model.getScope().getScopedBackends();
if (!isHeader && !moduleBackends.none() && !mbackends.supports(moduleBackends)) {
that.addError("native backend name on declaration conflicts with module descriptor: '\"" + mbackends.names() + "\"' is not '\"" + moduleBackends.names() + "\"' for '" + name + "'");
} else if (!isHeader && !backends.none() && !backends.supports(mbackends)) {
that.addError("native backend for declaration conflicts with its scope: native implementation '" + name + "' for '\"" + mbackends.names() + "\"' occurs in a scope which only supports '\"" + backends.names() + "\"'");
}
if (isHeader && existImplementations(model)) {
that.addError("native header must be declared before its implementations: the native header '" + name + "' is declared after an implementation");
}
if (model instanceof Interface && ((Interface) model).isAlias()) {
that.addError("interface alias may not be marked native: '" + name + "' (add a body if a native interface was intended)");
}
model.setNativeBackends(mbackends);
Declaration member = getNativeHeader(model);
if (member == null || member.isNativeImplementation()) {
// it's not shared
if (!isHeader && mustHaveHeader(model) && !moduleBackends.equals(mbackends)) {
that.addError("shared native implementation must have a header: '" + model.getName() + "' has no native header");
}
}
if (member == null) {
if (model.isNativeHeader()) {
handleNativeHeader(model, name);
if (that instanceof Tree.ObjectDefinition) {
Tree.ObjectDefinition od = (Tree.ObjectDefinition) that;
handleNativeHeader(od.getAnonymousClass(), name);
} else if (that instanceof Tree.Constructor) {
Tree.Constructor c = (Tree.Constructor) that;
handleNativeHeader(c.getConstructor(), name);
}
} else {
member = model.getContainer().getDirectMemberForBackend(model.getName(), mbackends);
if (member != null && member != model) {
that.addError("duplicate native implementation: the implementation '" + name + "' for '\"" + mbackends.names() + "\"' is not unique");
unit.getDuplicateDeclarations().add(member);
}
}
} else {
if (member.isNative()) {
List<Declaration> overloads = member.getOverloads();
if (isHeader && member.isNativeHeader()) {
that.addError("duplicate native header: the header for '" + name + "' is not unique");
unit.getDuplicateDeclarations().add(member);
} else {
Declaration overload = findOverloadForBackend(mbackends, model, overloads);
if (overload != null) {
that.addError("duplicate native implementation: the implementation '" + name + "' for '\"" + mbackends.names() + "\"' is not unique");
unit.getDuplicateDeclarations().add(overload);
}
}
if (isAllowedToChangeModel(member) && !hasModelInOverloads(model, overloads)) {
overloads.add(model);
if (that instanceof Tree.ObjectDefinition) {
Tree.ObjectDefinition od = (Tree.ObjectDefinition) that;
Declaration objImplCls = od.getAnonymousClass();
Value value = (Value) member;
Class objHdrCls = (Class) value.getType().getDeclaration();
objHdrCls.getOverloads().add(objImplCls);
} else if (that instanceof Tree.Constructor) {
Tree.Constructor c = (Tree.Constructor) that;
Declaration cd = c.getConstructor();
FunctionOrValue fov = (FunctionOrValue) member;
Constructor hdr = (Constructor) fov.getType().getDeclaration();
hdr.getOverloads().add(cd);
}
}
} else {
if (isHeader) {
that.addError("native header for non-native declaration: '" + name + "' is not declared native");
} else {
that.addError("native implementation for non-native header: '" + name + "' is not declared native");
}
}
}
} else if (!(model instanceof Setter) && !isHeader) {
if (!canBeNative) {
that.addError("native declaration is not a class, constructor, method, attribute or object: '" + name + "' may not be annotated 'native'");
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class DeclarationVisitor method handleNativeHeader.
private void handleNativeHeader(Declaration model, String name) {
// Deal with implementations from the ModelLoader
ArrayList<FunctionOrValue> loadedFunctionsOrValues = null;
ArrayList<ClassOrInterface> loadedClasses = null;
ArrayList<Constructor> loadedConstructors = null;
for (Backend backendToSearch : Backend.getRegisteredBackends()) {
Declaration overloadFromModelLoader = model.getContainer().getDirectMemberForBackend(name, backendToSearch.asSet());
if (overloadFromModelLoader instanceof FunctionOrValue) {
if (loadedFunctionsOrValues == null) {
loadedFunctionsOrValues = new ArrayList<FunctionOrValue>();
}
FunctionOrValue fov = (FunctionOrValue) overloadFromModelLoader;
loadedFunctionsOrValues.add(fov);
} else if (overloadFromModelLoader instanceof ClassOrInterface) {
if (loadedClasses == null) {
loadedClasses = new ArrayList<ClassOrInterface>();
}
ClassOrInterface c = (ClassOrInterface) overloadFromModelLoader;
loadedClasses.add(c);
} else if (overloadFromModelLoader instanceof Constructor) {
if (loadedConstructors == null) {
loadedConstructors = new ArrayList<Constructor>();
}
Constructor c = (Constructor) overloadFromModelLoader;
loadedConstructors.add(c);
}
}
// Initialize the header's overloads
if (model instanceof FunctionOrValue) {
FunctionOrValue m = (FunctionOrValue) model;
if (loadedFunctionsOrValues != null) {
m.initOverloads(loadedFunctionsOrValues.toArray(NO_FUNCTIONS_OR_VALUES));
} else {
m.initOverloads();
}
} else if (model instanceof ClassOrInterface) {
ClassOrInterface c = (ClassOrInterface) model;
if (loadedClasses != null) {
c.initOverloads(loadedClasses.toArray(NO_CLASSES));
} else {
c.initOverloads();
}
} else if (model instanceof Constructor) {
Constructor c = (Constructor) model;
if (loadedConstructors != null) {
c.initOverloads(loadedConstructors.toArray(NO_CONSTRUCTORS));
} else {
c.initOverloads();
}
}
}
Aggregations