use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class ExpressionVisitor method checkConcreteConstructor.
private boolean checkConcreteConstructor(TypedDeclaration member, Tree.StaticMemberOrTypeExpression that) {
if (isConstructor(member)) {
Scope container = member.getContainer();
Constructor cons = (Constructor) member.getTypeDeclaration();
if (cons.isAbstract()) {
that.addError("partial constructor cannot be invoked: '" + member.getName(unit) + "' is abstract");
return false;
} else if (container instanceof Class) {
Class c = (Class) container;
if (c.isAbstract()) {
that.addError("class cannot be instantiated: '" + member.getName(unit) + "' is a constructor for the abstract class '" + c.getName(unit));
return false;
} else {
return true;
}
} else {
return false;
}
} else {
return true;
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class ExpressionVisitor method resolveQualifiedMemberExpression.
private TypedDeclaration resolveQualifiedMemberExpression(Tree.QualifiedMemberExpression that, boolean error) {
Tree.Identifier id = that.getIdentifier();
boolean nameNonempty = id != null && !id.getText().equals("");
if (nameNonempty && checkMember(that)) {
Tree.Primary primary = that.getPrimary();
String name = name(id);
List<Type> signature = that.getSignature();
boolean spread = that.getEllipsis();
String container;
boolean ambiguous;
TypedDeclaration member;
Type pt;
if (primary instanceof Tree.Package) {
Package pack = unit.getPackage();
container = "package '" + pack.getNameAsString() + "'";
member = getPackageTypedDeclaration(name, signature, spread, unit);
ambiguous = false;
pt = null;
} else {
pt = primary.getTypeModel().resolveAliases();
TypeDeclaration d = getDeclaration(that, pt);
if (d instanceof Constructor) {
d = d.getExtendedType().getDeclaration();
}
container = "type '" + d.getName(unit) + "'";
Scope scope = that.getScope();
member = getTypedMember(d, name, signature, spread, unit, scope);
ambiguous = member == null && d.isMemberAmbiguous(name, unit, signature, spread);
if (member == null) {
container += memberCorrectionMessage(name, d, scope, unit, cancellable);
}
}
if (member == null) {
if (error) {
if (ambiguous) {
that.addError("method or attribute is ambiguous: '" + name + "' for " + container);
} else {
that.addError("method or attribute is not defined: '" + name + "' in " + container, 100);
unit.setUnresolvedReferences();
}
}
} else {
member = (TypedDeclaration) handleAbstractionOrHeader(member, that, error);
if (error) {
checkStaticPrimary(that, primary, member, pt);
}
that.setDeclaration(member);
resetSuperReference(that);
boolean selfReference = isSelfReference(primary);
if (!selfReference && !member.isShared()) {
member.setOtherInstanceAccess(true);
}
if (error) {
if (checkConcreteConstructor(member, that)) {
checkQualifiedVisibility(that, member, name, container, selfReference);
}
checkSuperMember(that, signature, spread);
}
}
return member;
} else {
return null;
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class ExpressionVisitor method visit.
@Override
public void visit(Tree.TypeLiteral that) {
if (that instanceof Tree.InterfaceLiteral || that instanceof Tree.ClassLiteral || that instanceof Tree.NewLiteral || that instanceof Tree.AliasLiteral || that instanceof Tree.TypeParameterLiteral) {
declarationLiteral = true;
} else {
modelLiteral = true;
}
try {
super.visit(that);
} finally {
declarationLiteral = false;
modelLiteral = false;
}
Type t;
TypeDeclaration d;
Tree.StaticType type = that.getType();
Node errorNode;
if (type != null) {
t = type.getTypeModel();
d = t.getDeclaration();
errorNode = type;
} else {
errorNode = that;
ClassOrInterface classOrInterface = getContainingClassOrInterface(that.getScope());
if (that instanceof Tree.ClassLiteral || that instanceof Tree.InterfaceLiteral) {
d = classOrInterface;
if (d == null) {
errorNode.addError("no containing type");
// EARLY EXIT!!
return;
} else {
t = classOrInterface.getType();
}
} else {
errorNode.addError("missing type reference");
// EARLY EXIT!!
return;
}
}
if (t != null) {
that.setDeclaration(d);
that.setWantsDeclaration(true);
if (that instanceof Tree.ClassLiteral) {
if (!(d instanceof Class)) {
if (d != null) {
errorNode.addError("referenced declaration is not a class" + getDeclarationReferenceSuggestion(d));
}
that.setTypeModel(unit.getClassDeclarationType());
} else {
that.setTypeModel(unit.getClassDeclarationType((Class) d));
}
} else if (that instanceof Tree.NewLiteral) {
if (d instanceof Class) {
Class c = (Class) d;
Constructor defaultConstructor = c.getDefaultConstructor();
if (defaultConstructor != null) {
d = defaultConstructor;
}
}
if (d instanceof Constructor) {
Constructor c = (Constructor) d;
if (c.getParameterList() == null) {
that.setTypeModel(unit.getValueConstructorDeclarationType());
} else {
that.setTypeModel(unit.getCallableConstructorDeclarationType());
}
} else if (d != null) {
errorNode.addError("referenced declaration is not a constructor" + getDeclarationReferenceSuggestion(d));
}
} else if (that instanceof Tree.InterfaceLiteral) {
if (!(d instanceof Interface)) {
if (d != null) {
errorNode.addError("referenced declaration is not an interface" + getDeclarationReferenceSuggestion(d));
}
}
that.setTypeModel(unit.getInterfaceDeclarationType());
} else if (that instanceof Tree.AliasLiteral) {
if (!(d instanceof TypeAlias)) {
errorNode.addError("referenced declaration is not a type alias" + getDeclarationReferenceSuggestion(d));
}
that.setTypeModel(unit.getAliasDeclarationType());
} else if (that instanceof Tree.TypeParameterLiteral) {
if (!(d instanceof TypeParameter)) {
errorNode.addError("referenced declaration is not a type parameter" + getDeclarationReferenceSuggestion(d));
}
that.setTypeModel(unit.getTypeParameterDeclarationType());
} else if (d != null) {
that.setWantsDeclaration(false);
t = t.resolveAliases();
if (t == null || t.isUnknown()) {
return;
}
// checkNonlocalType(that.getType(), t.getDeclaration());
if (d instanceof Constructor) {
if (((Constructor) d).isAbstraction()) {
errorNode.addError("constructor is overloaded");
} else {
that.setTypeModel(unit.getConstructorMetatype(t));
}
} else if (d instanceof Class) {
// checkNonlocal(that, t.getDeclaration());
that.setTypeModel(unit.getClassMetatype(t));
} else if (d instanceof Interface) {
that.setTypeModel(unit.getInterfaceMetatype(t));
} else {
that.setTypeModel(unit.getTypeMetaType(t));
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class JsCompiler method getStitchedFile.
VirtualFile getStitchedFile(final Declaration d, final String suffix) {
String fqn = d.getQualifiedNameString();
String name = d.getName();
if (name == null && d instanceof Constructor) {
name = "default$constructor";
if (fqn.endsWith(".null")) {
fqn = fqn.substring(0, fqn.length() - 4);
}
fqn = fqn + name;
}
if (fqn.startsWith("ceylon.language")) {
fqn = fqn.substring(15);
}
if (fqn.startsWith("::")) {
fqn = fqn.substring(2);
}
fqn = fqn.replace('.', '/').replace("::", "/");
File path;
if (isCompilingLanguageModule()) {
path = new File(Stitcher.LANGMOD_JS_SRC, fqn + suffix);
} else {
PhasedUnit pu = tc.getPhasedUnitFromRelativePath(d.getUnit().getRelativePath());
path = new File(getFullPath(pu).getParentFile(), name + suffix);
}
return findFile(path);
}
use of org.eclipse.ceylon.model.typechecker.model.Constructor in project ceylon by eclipse.
the class TypeUtils method encodeForRuntime.
public static void encodeForRuntime(final Node that, final Declaration d, final GenerateJsVisitor gen, final RuntimeMetamodelAnnotationGenerator annGen) {
gen.out("function(){return{mod:$CCMM$");
List<TypeParameter> tparms = d instanceof Generic ? d.getTypeParameters() : null;
List<Type> satisfies = null;
List<Type> caseTypes = null;
if (d instanceof Class) {
Class _cd = (Class) d;
if (_cd.getExtendedType() != null) {
gen.out(",'super':");
metamodelTypeNameOrList(false, that, d.getUnit().getPackage(), _cd.getExtendedType(), null, gen);
}
// Parameter types
if (_cd.getParameterList() != null) {
gen.out(",", MetamodelGenerator.KEY_PARAMS, ":");
encodeParameterListForRuntime(false, that, _cd.getParameterList(), gen);
}
satisfies = _cd.getSatisfiedTypes();
caseTypes = _cd.getCaseTypes();
} else if (d instanceof Interface) {
Interface _id = (Interface) d;
satisfies = _id.getSatisfiedTypes();
caseTypes = _id.getCaseTypes();
if (_id.isAlias()) {
ArrayList<Type> s2 = new ArrayList<>(satisfies.size() + 1);
s2.add(_id.getExtendedType());
s2.addAll(satisfies);
satisfies = s2;
}
} else if (d instanceof FunctionOrValue) {
gen.out(",", MetamodelGenerator.KEY_TYPE, ":");
if (d instanceof Function && ((Function) d).getParameterLists().size() > 1) {
Type callableType = ((Function) d).getTypedReference().getFullType();
// This needs a new setting to resolve types but not type parameters
metamodelTypeNameOrList(false, that, d.getUnit().getPackage(), that.getUnit().getCallableReturnType(callableType), null, gen);
} else {
// This needs a new setting to resolve types but not type parameters
metamodelTypeNameOrList(false, that, d.getUnit().getPackage(), ((FunctionOrValue) d).getType(), null, gen);
}
if (d instanceof Function) {
gen.out(",", MetamodelGenerator.KEY_PARAMS, ":");
// Parameter types of the first parameter list
encodeParameterListForRuntime(false, that, ((Function) d).getFirstParameterList(), gen);
tparms = d.getTypeParameters();
}
} else if (d instanceof Constructor) {
gen.out(",", MetamodelGenerator.KEY_PARAMS, ":");
encodeParameterListForRuntime(false, that, ((Constructor) d).getFirstParameterList(), gen);
}
if (!d.isToplevel()) {
// Find the first container that is a Declaration
Declaration _cont = ModelUtil.getContainingDeclaration(d);
// Skip over anonymous types/funs as well as local non-captured fields
while (_cont.isAnonymous() || !(_cont.isToplevel() || _cont.isClassOrInterfaceMember() || _cont instanceof Value == false)) {
// Neither do we skip classes, even if they're anonymous
if ((_cont instanceof Value && (((Value) _cont).isJsCaptured())) || _cont instanceof Class) {
break;
}
Declaration __d = ModelUtil.getContainingDeclaration(_cont);
if (__d == null)
break;
_cont = __d;
}
gen.out(",$cont:");
boolean generateName = true;
if ((_cont.getName() != null && _cont.isAnonymous() && _cont instanceof Function) || (_cont instanceof Value && !((Value) _cont).isTransient())) {
// Anon functions don't have metamodel so go up until we find a non-anon container
Declaration _supercont = ModelUtil.getContainingDeclaration(_cont);
while (_supercont != null && _supercont.getName() != null && _supercont.isAnonymous()) {
_supercont = ModelUtil.getContainingDeclaration(_supercont);
}
if (_supercont == null) {
// If the container is a package, add it because this isn't really toplevel
generateName = false;
gen.out("0");
} else {
_cont = _supercont;
}
}
if (generateName) {
if (_cont instanceof Value) {
if (AttributeGenerator.defineAsProperty(_cont)) {
gen.qualify(that, _cont);
}
gen.out(gen.getNames().getter(_cont, true));
} else if (_cont instanceof Setter) {
gen.out("{setter:");
if (AttributeGenerator.defineAsProperty(_cont)) {
gen.qualify(that, _cont);
gen.out(gen.getNames().getter(((Setter) _cont).getGetter(), true), ".set");
} else {
gen.out(gen.getNames().setter(((Setter) _cont).getGetter()));
}
gen.out("}");
} else {
boolean inProto = gen.opts.isOptimize() && (_cont.getContainer() instanceof TypeDeclaration);
final String path = gen.qualifiedPath(that, _cont, inProto);
if (path != null && !path.isEmpty()) {
gen.out(path, ".");
}
final String contName = gen.getNames().name(_cont);
gen.out(contName);
}
}
}
if (tparms != null && !tparms.isEmpty()) {
gen.out(",", MetamodelGenerator.KEY_TYPE_PARAMS, ":{");
encodeTypeParametersForRuntime(that, d, tparms, true, gen);
gen.out("}");
}
if (satisfies != null && !satisfies.isEmpty()) {
gen.out(",", MetamodelGenerator.KEY_SATISFIES, ":[");
boolean first = true;
for (Type st : satisfies) {
if (!first)
gen.out(",");
first = false;
metamodelTypeNameOrList(false, that, d.getUnit().getPackage(), st, null, gen);
}
gen.out("]");
}
if (caseTypes != null && !caseTypes.isEmpty()) {
gen.out(",of:[");
boolean first = true;
for (Type st : caseTypes) {
// teeheehee
final TypeDeclaration std = st.getDeclaration();
if (!first)
gen.out(",");
first = false;
if (ModelUtil.isConstructor(std)) {
if (std.isAnonymous()) {
// Value constructor
gen.out(gen.getNames().name(d), ".", gen.getNames().valueConstructorName(std));
} else {
gen.out("/*TODO callable constructor*/");
}
} else if (std.isAnonymous()) {
if (std.isStatic()) {
gen.out(gen.getNames().name(ModelUtil.getContainingDeclaration(std)), ".$st$.", gen.getNames().objectName(std));
} else {
gen.out(gen.getNames().getter(std, true));
}
} else {
metamodelTypeNameOrList(false, that, d.getUnit().getPackage(), st, null, gen);
}
}
gen.out("]");
}
if (annGen != null) {
annGen.generateAnnotations();
}
// Path to its model
gen.out(",d:");
outputModelPath(d, gen);
gen.out("};}");
}
Aggregations