use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class SmallDeclarationVisitor method setSmallType.
protected static void setSmallType(FunctionOrValue f) {
Type t = smallUnderlyingType(f.getType());
f.setType(t);
if (f instanceof Value) {
Setter s = ((Value) f).getSetter();
if (s != null) {
s.getParameter().getModel().setType(t);
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.Setter in project ceylon by eclipse.
the class JsonPackage method loadAttribute.
FunctionOrValue loadAttribute(String name, Map<String, Object> m, Scope parent, List<TypeParameter> typeParameters) {
String metatype = (String) m.get(KEY_METATYPE);
Value d = new Value();
d.setTransient(METATYPE_GETTER.equals(metatype));
d.setName(name);
d.setContainer(parent);
d.setScope(parent);
d.setUnit(u2);
if (parent == this) {
u2.addDeclaration(d);
addMember(null);
}
setAnnotations(d, (Integer) m.remove(KEY_PACKED_ANNS), m.remove(KEY_ANNOTATIONS));
d.setDynamic(m.remove(KEY_DYNAMIC) != null);
if (m.containsKey("var")) {
d.setVariable(true);
}
@SuppressWarnings("unchecked") final Map<String, Object> ktype = (Map<String, Object>) m.get(KEY_TYPE);
d.setType(getTypeFromJson(ktype, parent instanceof Declaration ? (Declaration) parent : null, typeParameters));
@SuppressWarnings("unchecked") final Map<String, Object> smap = (Map<String, Object>) m.remove("$set");
if (smap != null) {
Setter s = new Setter();
s.setName(name);
s.setContainer(parent);
s.setScope(parent);
s.setUnit(u2);
s.setGetter(d);
d.setSetter(s);
if (parent == this) {
u2.addDeclaration(s);
addMember(null);
}
setAnnotations(s, (Integer) smap.remove(KEY_PACKED_ANNS), smap.remove(KEY_ANNOTATIONS));
s.setType(d.getType());
}
return d;
}
use of org.eclipse.ceylon.model.typechecker.model.Setter 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.Setter 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.Setter in project ceylon by eclipse.
the class SpecificationVisitor method visit.
@Override
public void visit(Tree.AttributeSetterDefinition that) {
Setter d = that.getDeclarationModel();
if (d == declaration || d.getParameter().getModel() == declaration) {
declare();
specify();
}
super.visit(that);
}
Aggregations