use of org.eclipse.ceylon.model.typechecker.model.Generic in project ceylon by eclipse.
the class ClassOrPackageDoc method doc.
protected final void doc(String id, String name, Declaration d) throws IOException {
String declarationName = Util.getDeclarationName(d);
id = (id != null ? id : name);
boolean alias = Util.nullSafeCompare(name, declarationName) != 0;
// put the id on the td because IE8 doesn't support id attributes on tr (yeah right)
open("tr");
open("td id='" + id + "' nowrap");
writeIcon(d);
if (!(d instanceof Constructor)) {
around("code class='decl-label'", name);
close("td");
open("td");
}
writeLinkOneSelf(id);
if (alias) {
writeTagged(d);
writeAlias(d);
} else {
writeLinkSource(d);
writeTagged(d);
if (d instanceof Functional) {
writeParameterLinksIfRequired((Functional) d);
}
open("code class='signature'");
around("span class='modifiers'", getModifiers(d));
write(" ");
if (!ModelUtil.isConstructor(d)) {
if (!Decl.isDynamic(d)) {
if (d instanceof Functional && ((Functional) d).isDeclaredVoid()) {
around("span class='void'", "void");
} else if (d instanceof TypedDeclaration) {
linkRenderer().to(((TypedDeclaration) d).getType()).useScope(d).write();
} else {
linkRenderer().to(d).useScope(d).write();
}
} else {
around("span class='dynamic'", "dynamic");
}
}
write(" ");
open("span class='identifier'");
write(name);
close("span");
if (isConstantValue(d)) {
writeConstantValue((Value) d);
}
if (d instanceof Generic) {
writeTypeParameters(d.getTypeParameters(), d);
}
if (d instanceof Functional) {
writeParameterList((Functional) d, d);
}
if (d instanceof Generic) {
writeTypeParametersConstraints(d.getTypeParameters(), d);
}
if (d instanceof Value) {
Setter setter = ((Value) d).getSetter();
if (setter != null && Util.getAnnotation(setter.getUnit(), setter.getAnnotations(), "doc") != null) {
tool.warningSetterDoc(d.getQualifiedNameString(), d);
}
}
close("code");
writeDescription(d);
}
close("td");
close("tr");
}
use of org.eclipse.ceylon.model.typechecker.model.Generic in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.TypeParameterList that) {
super.visit(that);
if (declaration instanceof Generic) {
Generic g = (Generic) declaration;
g.setTypeParameters(getTypeParameters(that));
}
}
use of org.eclipse.ceylon.model.typechecker.model.Generic in project ceylon by eclipse.
the class ClassTransformer method typeParametersForInstantiator.
/**
* When generating an instantiator method if the inner class has a type
* parameter with the same name as a type parameter of an outer type, then the
* instantiator method shouldn't declare its own type parameter of that
* name -- it should use the captured one. This method filters out the
* type parameters of the inner class which are the same as type parameters
* of the outer class so that they can be captured.
*/
private java.util.List<TypeParameter> typeParametersForInstantiator(final Class model) {
java.util.List<TypeParameter> filtered = new ArrayList<TypeParameter>();
java.util.List<TypeParameter> tps = model.getTypeParameters();
if (tps != null) {
for (TypeParameter tp : tps) {
boolean omit = false;
Scope s = model.getContainer();
while (!(s instanceof Package)) {
if (s instanceof Generic) {
for (TypeParameter outerTp : ((Generic) s).getTypeParameters()) {
if (tp.getName().equals(outerTp.getName())) {
omit = true;
}
}
}
s = s.getContainer();
}
if (!omit) {
filtered.add(tp);
}
}
}
return filtered;
}
use of org.eclipse.ceylon.model.typechecker.model.Generic in project ceylon by eclipse.
the class ClassTransformer method typeParametersOfAllContainers.
private java.util.List<TypeParameter> typeParametersOfAllContainers(final ClassOrInterface model, boolean includeModelTypeParameters) {
java.util.List<java.util.List<TypeParameter>> r = new ArrayList<java.util.List<TypeParameter>>(1);
Scope s = model.getContainer();
while (!(s instanceof Package)) {
if (s instanceof Generic) {
r.add(0, ((Generic) s).getTypeParameters());
}
s = s.getContainer();
}
Set<String> names = new HashSet<String>();
for (TypeParameter tp : model.getTypeParameters()) {
names.add(tp.getName());
}
java.util.List<TypeParameter> result = new ArrayList<TypeParameter>(1);
for (java.util.List<TypeParameter> tps : r) {
for (TypeParameter tp : tps) {
if (names.add(tp.getName())) {
result.add(tp);
}
}
}
if (includeModelTypeParameters)
result.addAll(model.getTypeParameters());
return result;
}
use of org.eclipse.ceylon.model.typechecker.model.Generic in project ceylon by eclipse.
the class JsonPackage method parseTypeParameters.
/**
* Creates a list of TypeParameter from a list of maps.
* @param typeParams The list of maps to create the TypeParameters.
* @param container The declaration which owns the resulting type parameters.
* @param existing A list of type parameters declared in the parent scopes which can be referenced from
* the ones that have to be parsed.
*/
private List<TypeParameter> parseTypeParameters(List<Map<String, Object>> typeParams, final Declaration container, List<TypeParameter> existing) {
if (typeParams == null)
return Collections.emptyList();
// New array with existing parms to avoid modifying that one
List<TypeParameter> allparms = new ArrayList<>((existing == null ? 0 : existing.size()) + typeParams.size());
if (existing != null && !existing.isEmpty()) {
allparms.addAll(existing);
}
List<TypeParameter> tparms = new ArrayList<>(typeParams.size());
// First create the type parameters
for (Map<String, Object> tp : typeParams) {
final Declaration maybe;
if (tp.get(KEY_METATYPE) instanceof TypeParameter) {
maybe = (TypeParameter) tp.get(KEY_METATYPE);
} else {
maybe = container.getDirectMember((String) tp.get(KEY_NAME), null, false);
}
if (maybe instanceof TypeParameter) {
// we already had it (from partial loading elsewhere)
allparms.add((TypeParameter) maybe);
tparms.add((TypeParameter) maybe);
tp.put(KEY_METATYPE, maybe);
} else {
TypeParameter tparm = new TypeParameter();
tparm.setUnit(container.getUnit());
tparm.setDeclaration(container);
container.getMembers().add(tparm);
if (tp.containsKey(KEY_NAME)) {
tparm.setName((String) tp.get(KEY_NAME));
} else if (!tp.containsKey(KEY_TYPES)) {
throw new IllegalArgumentException("Invalid type parameter map " + tp);
}
String variance = (String) tp.get(KEY_DS_VARIANCE);
if ("out".equals(variance)) {
tparm.setCovariant(true);
} else if ("in".equals(variance)) {
tparm.setContravariant(true);
}
if (container instanceof Scope) {
Scope scope = (Scope) container;
tparm.setContainer(scope);
tparm.setScope(scope);
}
tparm.setDefaulted(tp.containsKey(KEY_DEFAULT));
tparms.add(tparm);
allparms.add(tparm);
tp.put(KEY_METATYPE, tparm);
}
}
if (container instanceof Generic) {
((Generic) container).setTypeParameters(tparms);
}
// Second, add defaults and heritage
for (Map<String, Object> tp : typeParams) {
TypeParameter tparm = (TypeParameter) tp.get(KEY_METATYPE);
if (tparm.getExtendedType() == null) {
if (tp.containsKey(KEY_PACKAGE)) {
// Looks like this never happens but...
Type subtype = getTypeFromJson(tp, container, allparms);
tparm.setExtendedType(subtype);
} else if (tp.containsKey(KEY_TYPES)) {
if (!("u".equals(tp.get("comp")) || "i".equals(tp.get("comp")))) {
throw new IllegalArgumentException("Only union or intersection types are allowed as 'comp'");
}
Type subtype = getTypeFromJson(tp, container, allparms);
tparm.setName(subtype.asString());
tparm.setExtendedType(subtype);
} else {
tparm.setExtendedType(getTypeFromJson(voidclass, container, null));
}
}
if (tparm.isDefaulted()) {
@SuppressWarnings("unchecked") final Map<String, Object> deftype = (Map<String, Object>) tp.get(KEY_DEFAULT);
tparm.setDefaultTypeArgument(getTypeFromJson(deftype, container, existing));
}
if (tp.containsKey(KEY_SATISFIES)) {
@SuppressWarnings("unchecked") final List<Map<String, Object>> stypes = (List<Map<String, Object>>) tp.get(KEY_SATISFIES);
tparm.setSatisfiedTypes(parseTypeList(stypes, allparms));
tparm.setConstrained(true);
} else if (tp.containsKey("of")) {
@SuppressWarnings("unchecked") final List<Map<String, Object>> oftype = (List<Map<String, Object>>) tp.get("of");
tparm.setCaseTypes(parseTypeList(oftype, allparms));
tparm.setConstrained(true);
}
}
return tparms;
}
Aggregations