use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class TypeUtils method generateModelPath.
/**
* Returns the list of keys to get from the package to the declaration, in the model.
*/
public static List<String> generateModelPath(final Declaration d) {
final ArrayList<String> sb = new ArrayList<>();
final Package pkg = d.getUnit().getPackage();
sb.add(pkg.isLanguagePackage() ? "$" : pkg.getNameAsString());
if (d.isToplevel()) {
sb.add(d.getName());
if (d instanceof Setter) {
sb.add("$set");
}
} else {
Declaration p = d;
final int i = sb.size();
while (p instanceof Declaration) {
if (p instanceof Setter) {
sb.add(i, "$set");
}
final String mname = TypeUtils.modelName(p);
if (!(mname.startsWith("anon$") || mname.startsWith("anonymous#"))) {
sb.add(i, mname);
// Build the path in reverse
if (!p.isToplevel()) {
if (p instanceof Class) {
sb.add(i, p.isAnonymous() ? MetamodelGenerator.KEY_OBJECTS : MetamodelGenerator.KEY_CLASSES);
} else if (p instanceof org.eclipse.ceylon.model.typechecker.model.Interface) {
sb.add(i, MetamodelGenerator.KEY_INTERFACES);
} else if (p instanceof Function) {
if (!p.isAnonymous()) {
sb.add(i, MetamodelGenerator.KEY_METHODS);
}
} else if (p instanceof TypeAlias || p instanceof Setter) {
sb.add(i, MetamodelGenerator.KEY_ATTRIBUTES);
} else if (p instanceof Constructor || ModelUtil.isConstructor(p)) {
sb.add(i, MetamodelGenerator.KEY_CONSTRUCTORS);
} else {
// It's a value
TypeDeclaration td = ((TypedDeclaration) p).getTypeDeclaration();
sb.add(i, (td != null && td.isAnonymous()) ? MetamodelGenerator.KEY_OBJECTS : MetamodelGenerator.KEY_ATTRIBUTES);
}
}
}
p = ModelUtil.getContainingDeclaration(p);
while (p != null && p instanceof ClassOrInterface == false && !(p.isToplevel() || p.isAnonymous() || p.isClassOrInterfaceMember() || p.isJsCaptured())) {
p = ModelUtil.getContainingDeclaration(p);
}
}
}
return sb;
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class JsIdentifierNames method originalDeclaration.
private Declaration originalDeclaration(Declaration decl) {
Declaration refinedDecl = decl;
while (true) {
Declaration d = refinedDecl.getRefinedDeclaration();
if ((d == null) || (d == refinedDecl)) {
break;
}
refinedDecl = d;
}
return refinedDecl;
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class JsOutput method publishUnsharedDeclarations.
public void publishUnsharedDeclarations(JsIdentifierNames names) {
// #489 lists with unshared toplevel members of each package
for (org.eclipse.ceylon.model.typechecker.model.Package pkg : module.getPackages()) {
ArrayList<Declaration> unsharedDecls = new ArrayList<>(pkg.getMembers().size());
for (Declaration d : pkg.getMembers()) {
if (!d.isShared() && !(d.isAnonymous() && d.getName() != null && d.getName().startsWith("anonymous#")) && (!d.isNative() || d.getNativeBackends().supports(Backend.JavaScript))) {
unsharedDecls.add(d);
}
}
if (!unsharedDecls.isEmpty()) {
out("ex$.$pkgunsh$", pkg.getNameAsString().replace('.', '$'), "={");
boolean first = true;
for (Declaration d : unsharedDecls) {
if (d.getName() == null)
continue;
// TODO only use quotes when absolutely necessary
if (d.isAnonymous()) {
// Don't generate anything for anonymous types
} else if (d instanceof Setter) {
// ignore
if (((Setter) d).getGetter() == null) {
if (first)
first = false;
else
out(",");
out("'", d.getName(), "':", names.setter(d));
}
} else if (d instanceof Value) {
if (first)
first = false;
else
out(",");
out("'", d.getName(), "':", names.getter(d, true));
} else {
if (first)
first = false;
else
out(",");
out("'", d.getName(), "':", names.name(d));
}
}
out("};\n");
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class RefinementVisitor method checkNonMember.
private void checkNonMember(Tree.Declaration that, Declaration dec) {
boolean mayBeShared = !(dec instanceof TypeParameter);
boolean nonTypeMember = !dec.isClassOrInterfaceMember();
String name = dec.getName();
if (dec.isStatic()) {
if (nonTypeMember) {
that.addError("static declaration is not a member of a class or interface: '" + name + "' is not defined directly in the body of a class or interface");
} else {
ClassOrInterface type = (ClassOrInterface) dec.getContainer();
if (!type.isToplevel()) {
that.addError("static declaration belongs to a nested a class or interface: '" + name + "' is a member of nested type '" + type.getName() + "'");
}
}
}
if (nonTypeMember && mayBeShared) {
if (dec.isActual()) {
that.addError("actual declaration is not a member of a class or interface: '" + name + "'", 1301);
}
if (dec.isFormal()) {
that.addError("formal declaration is not a member of a class or interface: '" + name + "'", 1302);
}
if (dec.isDefault()) {
that.addError("default declaration is not a member of a class or interface: '" + name + "'", 1303);
}
} else if (!dec.isShared() && mayBeShared) {
if (dec.isActual()) {
that.addError("actual declaration must be shared: '" + name + "'", 701);
}
if (dec.isFormal()) {
that.addError("formal declaration must be shared: '" + name + "'", 702);
}
if (dec.isDefault()) {
that.addError("default declaration must be shared: '" + name + "'", 703);
}
} else {
if (dec.isActual()) {
that.addError("declaration may not be actual: '" + name + "'", 1301);
}
if (dec.isFormal()) {
that.addError("declaration may not be formal: '" + name + "'", 1302);
}
if (dec.isDefault()) {
that.addError("declaration may not be default: '" + name + "'", 1303);
}
}
if (isOverloadedVersion(dec)) {
if (isConstructor(dec)) {
checkOverloadedAnnotation(that, dec);
checkOverloadedParameters(that, dec);
} else {
that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
}
} else if (isAbstraction(dec)) {
// that is considered overloaded in the model
if (that instanceof Tree.ClassDefinition && !that.hasErrors()) {
Tree.ClassDefinition def = (Tree.ClassDefinition) that;
// this is an abstraction
Class abs = (Class) dec;
// correctly located)
for (Tree.Statement st : def.getClassBody().getStatements()) {
if (st instanceof Tree.Constructor) {
Tree.Constructor node = (Tree.Constructor) st;
if (node.getIdentifier() == null) {
Constructor con = node.getConstructor();
// get the corresponding overloaded version
Class cla = classOverloadForConstructor(abs, con);
checkOverloadedAnnotation(node, con);
checkOverloadedParameters(node, cla);
}
}
}
}
}
if (isConstructor(dec) && dec.isShared()) {
Scope container = dec.getContainer();
if (container instanceof Class) {
Class clazz = (Class) container;
Declaration member = intersectionOfSupertypes(clazz).getDeclaration().getMember(name, null, false);
if (member != null && member.isShared() && !isConstructor(member)) {
Declaration supertype = (Declaration) member.getContainer();
that.addError("constructor has same name as an inherited member '" + clazz.getName() + "' inherits '" + member.getName() + "' from '" + supertype.getName(that.getUnit()) + "'");
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Declaration in project ceylon by eclipse.
the class RefinementVisitor method inheritDefaultedArguments.
private void inheritDefaultedArguments(Declaration d) {
Declaration rd = d.getRefinedDeclaration();
if (rd != d && rd instanceof Functional && d instanceof Functional) {
Functional fd = (Functional) d;
Functional frd = (Functional) rd;
List<ParameterList> tdpls = fd.getParameterLists();
List<ParameterList> rdpls = frd.getParameterLists();
if (!tdpls.isEmpty() && !rdpls.isEmpty()) {
List<Parameter> tdps = tdpls.get(0).getParameters();
List<Parameter> rdps = rdpls.get(0).getParameters();
for (int i = 0; i < tdps.size() && i < rdps.size(); i++) {
Parameter tdp = tdps.get(i);
Parameter rdp = rdps.get(i);
if (tdp != null && rdp != null) {
tdp.setDefaulted(rdp.isDefaulted());
}
}
}
}
}
Aggregations