use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class JsonPackage method loadMethod.
@SuppressWarnings("unchecked")
Function loadMethod(String name, Map<String, Object> m, Scope parent, final List<TypeParameter> existing) {
Function md = new Function();
md.setName(name);
m.remove(KEY_NAME);
md.setContainer(parent);
md.setScope(parent);
setAnnotations(md, (Integer) m.remove(KEY_PACKED_ANNS), m.remove(KEY_ANNOTATIONS));
md.setUnit(u2);
if (parent == this) {
// Top-level declarations are directly added to the unit
u2.addDeclaration(md);
addMember(null);
}
if (m.containsKey(KEY_FLAGS)) {
int flags = (int) m.remove(KEY_FLAGS);
md.setDeclaredVoid((flags & 1) > 0);
md.setDeferred((flags & 2) > 0);
}
md.setDynamic(m.remove(KEY_DYNAMIC) != null);
final List<TypeParameter> tparms = parseTypeParameters((List<Map<String, Object>>) m.get(KEY_TYPE_PARAMS), md, existing);
final List<TypeParameter> allparms = JsonPackage.merge(tparms, existing);
md.setType(getTypeFromJson((Map<String, Object>) m.remove(KEY_TYPE), parent instanceof Declaration ? (Declaration) parent : null, allparms));
List<List<Map<String, Object>>> paramLists = (List<List<Map<String, Object>>>) m.remove(KEY_PARAMS);
if (paramLists == null) {
md.addParameterList(new ParameterList());
} else {
boolean first = true;
for (List<Map<String, Object>> plist : paramLists) {
ParameterList _params = parseParameters(plist, md, allparms);
_params.setNamedParametersSupported(first);
first = false;
md.addParameterList(_params);
for (Parameter p : _params.getParameters()) {
md.addMember(p.getModel());
}
}
}
return md;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class JsonPackage method loadTypeAlias.
/**
* Load a type alias, creating it if necessary.
* @return The TypeAlias declaration.
*/
@SuppressWarnings("unchecked")
private TypeAlias loadTypeAlias(String name, Map<String, Object> m, Scope parent, List<TypeParameter> existing) {
TypeAlias alias;
if (m.get(KEY_METATYPE) instanceof TypeAlias) {
// It's been loaded already
alias = (TypeAlias) m.get(KEY_METATYPE);
if (m.size() == 1) {
return alias;
}
} else {
Declaration maybe = parent.getDirectMember(name, null, false);
if (maybe == null) {
alias = new TypeAlias();
alias.setContainer(parent);
alias.setScope(parent);
alias.setName(name);
alias.setUnit(u2);
setAnnotations(alias, (Integer) m.remove(KEY_PACKED_ANNS), m.remove(KEY_ANNOTATIONS));
m.put(KEY_METATYPE, alias);
} else if (maybe instanceof TypeAlias) {
alias = (TypeAlias) maybe;
} else {
throw new IllegalStateException(maybe + " should be an TypeAlias");
}
}
// Gather available type parameters
List<Map<String, Object>> listOfMaps = (List<Map<String, Object>>) m.get(KEY_TYPE_PARAMS);
final List<TypeParameter> tparms;
if (listOfMaps != null && alias.getTypeParameters().size() < listOfMaps.size()) {
tparms = parseTypeParameters(listOfMaps, alias, existing);
alias.setTypeParameters(tparms);
} else {
tparms = alias.getTypeParameters();
}
final List<TypeParameter> allparms = JsonPackage.merge(tparms, existing);
// All interfaces extend Object, except aliases
if (alias.getExtendedType() == null) {
alias.setExtendedType(getTypeFromJson((Map<String, Object>) m.get("$alias"), parent instanceof Declaration ? (Declaration) parent : null, allparms));
}
if (m.containsKey(KEY_SELF_TYPE)) {
for (TypeParameter _tp : tparms) {
if (_tp.getName().equals(m.get(KEY_SELF_TYPE))) {
alias.setSelfType(_tp.getType());
}
}
}
if (m.containsKey("of")) {
alias.setCaseTypes(parseTypeList((List<Map<String, Object>>) m.remove("of"), allparms));
}
if (m.containsKey(KEY_SATISFIES)) {
List<Map<String, Object>> stypes = (List<Map<String, Object>>) m.remove(KEY_SATISFIES);
alias.setSatisfiedTypes(parseTypeList(stypes, allparms));
}
m.clear();
m.put(KEY_METATYPE, alias);
if (parent == this) {
u2.addDeclaration(alias);
}
parent.addMember(alias);
return alias;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class JsonPackage method loadInterface.
@SuppressWarnings("unchecked")
Interface loadInterface(String name, Map<String, Object> m, Scope parent, final List<TypeParameter> existing) {
// Check if it's been loaded first
// It hasn't been loaded, so create it
Interface t;
m.remove(KEY_NAME);
if (m.get(KEY_METATYPE) instanceof Interface) {
t = (Interface) m.get(KEY_METATYPE);
if (m.size() <= 3) {
// it's been loaded
return t;
}
} else {
if (m.containsKey("$alias")) {
t = new InterfaceAlias();
} else {
t = new Interface();
}
t.setContainer(parent);
t.setScope(parent);
t.setName(name);
t.setUnit(u2);
if (parent == this) {
u2.addDeclaration(t);
}
parent.addMember(t);
m.put(KEY_METATYPE, t);
setAnnotations(t, (Integer) m.remove(KEY_PACKED_ANNS), m.remove(KEY_ANNOTATIONS));
}
if (m.remove(KEY_DYNAMIC) != null) {
t.setDynamic(true);
}
List<TypeParameter> tparms = t.getTypeParameters();
List<Map<String, Object>> listOfMaps = (List<Map<String, Object>>) m.get(KEY_TYPE_PARAMS);
if (listOfMaps != null && (tparms == null || tparms.size() < listOfMaps.size())) {
tparms = parseTypeParameters(listOfMaps, t, existing);
m.remove(KEY_TYPE_PARAMS);
}
final List<TypeParameter> allparms = JsonPackage.merge(tparms, existing);
// All interfaces extend Object, except aliases
if (t.getExtendedType() == null) {
if (t.isAlias()) {
t.setExtendedType(getTypeFromJson((Map<String, Object>) m.remove("$alias"), parent instanceof Declaration ? (Declaration) parent : null, allparms));
} else {
t.setExtendedType(getTypeFromJson(objclass, parent instanceof Declaration ? (Declaration) parent : null, null));
}
}
if (m.containsKey(KEY_SELF_TYPE)) {
for (TypeParameter _tp : tparms) {
if (_tp.getName().equals(m.get(KEY_SELF_TYPE))) {
t.setSelfType(_tp.getType());
_tp.setSelfTypedDeclaration(t);
}
}
m.remove(KEY_SELF_TYPE);
}
if (m.containsKey("of") && t.getCaseTypes() == null) {
t.setCaseTypes(parseTypeList((List<Map<String, Object>>) m.remove("of"), allparms));
}
if (m.containsKey(KEY_SATISFIES)) {
for (Type s : parseTypeList((List<Map<String, Object>>) m.remove(KEY_SATISFIES), allparms)) {
t.getSatisfiedTypes().add(s);
}
}
addAttributesAndMethods(m, t, allparms);
if (m.containsKey(KEY_INTERFACES)) {
Map<String, Map<String, Object>> cdefs = (Map<String, Map<String, Object>>) m.remove(KEY_INTERFACES);
for (Map.Entry<String, Map<String, Object>> cdef : cdefs.entrySet()) {
loadInterface(cdef.getKey(), cdef.getValue(), t, allparms);
}
}
if (m.containsKey(KEY_CLASSES)) {
Map<String, Map<String, Object>> cdefs = (Map<String, Map<String, Object>>) m.remove(KEY_CLASSES);
for (Map.Entry<String, Map<String, Object>> cdef : cdefs.entrySet()) {
loadClass(cdef.getKey(), cdef.getValue(), t, allparms);
}
}
if (t.isDynamic() && (getModule().getJsMajor() < 9 || (getModule().getJsMajor() == 9 && getModule().getJsMinor() < 1))) {
// previous versions did not set dynamic flag on members
t.makeMembersDynamic();
}
return t;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class JsonPackage method merge.
/**
* Create a new list that contains all the type parameters in the first list,
* and the type parameters from the second list that don't have any names already present in the first list.
*/
public static List<TypeParameter> merge(List<TypeParameter> l1, List<TypeParameter> l2) {
int size = (l1 == null ? 0 : l1.size()) + (l2 == null ? 0 : l2.size());
ArrayList<TypeParameter> merged = new ArrayList<>(size);
HashSet<String> names = new HashSet<>();
if (l1 != null) {
for (TypeParameter t : l1) {
merged.add(t);
names.add(t.getName());
}
}
if (l2 != null) {
for (TypeParameter t : l2) {
if (!names.contains(t.getName())) {
merged.add(t);
}
}
}
return merged;
}
use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.
the class JsonPackage method loadClass.
/**
* Loads a class from the specified map. To avoid circularities, when the class is being created it is
* added to the map, and once it's been fully loaded, all other keys are removed.
*/
@SuppressWarnings("unchecked")
org.eclipse.ceylon.model.typechecker.model.Class loadClass(String name, Map<String, Object> m, Scope parent, final List<TypeParameter> existing) {
org.eclipse.ceylon.model.typechecker.model.Class cls;
m.remove(KEY_NAME);
if (m.get(KEY_METATYPE) instanceof org.eclipse.ceylon.model.typechecker.model.Class) {
cls = (org.eclipse.ceylon.model.typechecker.model.Class) m.get(KEY_METATYPE);
if (m.size() <= 3) {
// It's been fully loaded
return cls;
}
} else {
// It's not there, so create it
if (m.containsKey("$alias")) {
cls = new org.eclipse.ceylon.model.typechecker.model.ClassAlias();
} else {
cls = new org.eclipse.ceylon.model.typechecker.model.Class();
}
cls.setAbstract(m.remove("abstract") != null);
cls.setAnonymous(m.remove("$anon") != null);
cls.setDynamic(m.remove(KEY_DYNAMIC) != null);
cls.setContainer(parent);
cls.setScope(parent);
cls.setName(name);
cls.setUnit(u2);
if (parent == this) {
u2.addDeclaration(cls);
}
parent.addMember(cls);
m.put(KEY_METATYPE, cls);
setAnnotations(cls, (Integer) m.remove(KEY_PACKED_ANNS), m.remove(KEY_ANNOTATIONS));
}
// Type parameters are about the first thing we need to load
final List<TypeParameter> tparms = parseTypeParameters((List<Map<String, Object>>) m.remove(KEY_TYPE_PARAMS), cls, existing);
final List<TypeParameter> allparms = JsonPackage.merge(tparms, existing);
if (m.containsKey(KEY_SELF_TYPE)) {
for (TypeParameter t : tparms) {
if (t.getName().equals(m.get(KEY_SELF_TYPE))) {
cls.setSelfType(t.getType());
}
}
}
// This is to avoid circularity
if (!(isLanguagePackage() && ("Nothing".equals(name) || "Anything".equals(name)))) {
if (cls.getExtendedType() == null) {
if (m.containsKey("super")) {
Type father = getTypeFromJson((Map<String, Object>) m.get("super"), parent instanceof Declaration ? (Declaration) parent : null, allparms);
if (father != null) {
m.remove("super");
cls.setExtendedType(father);
}
} else {
cls.setExtendedType(getTypeFromJson(idobj, parent instanceof Declaration ? (Declaration) parent : null, allparms));
}
}
}
if (cls instanceof ClassAlias) {
ClassAlias ca = (ClassAlias) cls;
if (m.containsKey(KEY_CONSTRUCTOR)) {
String constructorName = (String) m.get(KEY_CONSTRUCTOR);
Function ctorFn = (Function) ca.getExtendedType().getDeclaration().getDirectMember(constructorName, null, false);
ca.setConstructor(ctorFn.getType().getDeclaration());
} else {
ca.setConstructor(ca.getExtendedType().getDeclaration());
}
}
if (m.containsKey(KEY_CONSTRUCTORS)) {
final Map<String, Map<String, Object>> constructors = (Map<String, Map<String, Object>>) m.remove(KEY_CONSTRUCTORS);
for (Map.Entry<String, Map<String, Object>> cons : constructors.entrySet()) {
Constructor cnst = new Constructor();
cnst.setName("$def".equals(cons.getKey()) ? null : cons.getKey());
cnst.setContainer(cls);
cnst.setScope(cls);
cnst.setUnit(cls.getUnit());
cnst.setExtendedType(cls.getType());
cnst.setDynamic(cons.getValue().remove(KEY_DYNAMIC) != null);
setAnnotations(cnst, (Integer) cons.getValue().remove(KEY_PACKED_ANNS), cons.getValue().remove(KEY_ANNOTATIONS));
final List<Map<String, Object>> modelPlist = (List<Map<String, Object>>) cons.getValue().remove(KEY_PARAMS);
cls.addMember(cnst);
if (modelPlist == null) {
// It's a value constructor
cls.setEnumerated(true);
Value cv = new Value();
cv.setName(cnst.getName());
cv.setType(cnst.getType());
cv.setContainer(cls);
cv.setScope(cls);
cv.setUnit(cls.getUnit());
cv.setVisibleScope(cls.getVisibleScope());
cv.setShared(cls.isShared());
cv.setDeprecated(cls.isDeprecated());
cls.addMember(cv);
} else {
cls.setConstructors(true);
final ParameterList plist = parseParameters(modelPlist, cnst, allparms);
cnst.addParameterList(plist);
plist.setNamedParametersSupported(true);
Function cf = new Function();
cf.setName(cnst.getName());
final Type ft = cnst.appliedType(cnst.getExtendedType(), Collections.<Type>emptyList());
cf.setType(ft);
cf.addParameterList(plist);
cf.setContainer(cls);
cf.setScope(cls);
cf.setUnit(cls.getUnit());
cf.setVisibleScope(cnst.getVisibleScope());
cf.setShared(cnst.isShared());
cf.setDeprecated(cnst.isDeprecated());
cf.setDynamic(cnst.isDynamic());
cls.addMember(cf);
}
if (cons.getValue().containsKey(KEY_JS_TSENUM)) {
cnst.setTypescriptEnum((String) cons.getValue().get(KEY_JS_TSENUM));
}
}
} else {
ParameterList plist = parseParameters((List<Map<String, Object>>) m.remove(KEY_PARAMS), cls, allparms);
plist.setNamedParametersSupported(true);
cls.setParameterList(plist);
}
if (m.containsKey("of") && cls.getCaseTypes() == null) {
cls.setCaseTypes(parseTypeList((List<Map<String, Object>>) m.get("of"), allparms));
m.remove("of");
}
if (m.containsKey(KEY_SATISFIES)) {
List<Map<String, Object>> stypes = (List<Map<String, Object>>) m.remove(KEY_SATISFIES);
cls.setSatisfiedTypes(parseTypeList(stypes, allparms));
}
if (m.containsKey(KEY_OBJECTS)) {
for (Map.Entry<String, Map<String, Object>> inner : ((Map<String, Map<String, Object>>) m.get(KEY_OBJECTS)).entrySet()) {
loadObject(inner.getKey(), inner.getValue(), cls, allparms);
}
m.remove(KEY_OBJECTS);
}
addAttributesAndMethods(m, cls, allparms);
if (m.containsKey(KEY_INTERFACES)) {
Map<String, Map<String, Object>> cdefs = (Map<String, Map<String, Object>>) m.get(KEY_INTERFACES);
for (Map.Entry<String, Map<String, Object>> cdef : cdefs.entrySet()) {
loadInterface(cdef.getKey(), cdef.getValue(), cls, allparms);
}
m.remove(KEY_INTERFACES);
}
if (m.containsKey(KEY_CLASSES)) {
Map<String, Map<String, Object>> cdefs = (Map<String, Map<String, Object>>) m.get(KEY_CLASSES);
for (Map.Entry<String, Map<String, Object>> cdef : cdefs.entrySet()) {
loadClass(cdef.getKey(), cdef.getValue(), cls, allparms);
}
m.remove(KEY_CLASSES);
}
if (cls.isDynamic() && (getModule().getJsMajor() < 9 || (getModule().getJsMajor() == 9 && getModule().getJsMinor() < 1))) {
// previous versions did not set dynamic flag on members
cls.makeMembersDynamic();
}
return cls;
}
Aggregations