use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class DeclarationVisitor method visit.
@Override
public void visit(Tree.AttributeSetterDefinition that) {
Setter s = new Setter();
s.setImplemented(that.getBlock() != null);
that.setDeclarationModel(s);
visitDeclaration(that, s);
Scope o = enterScope(s);
Parameter p = new Parameter();
p.setHidden(true);
Value v = new Value();
v.setInitializerParameter(p);
p.setModel(v);
v.setName(s.getName());
p.setName(s.getName());
p.setDeclaration(s);
visitElement(that, v);
unit.addDeclaration(v);
Scope sc = getContainer(that);
sc.addMember(v);
s.setParameter(p);
super.visit(that);
exitScope(o);
if (that.getSpecifierExpression() == null && that.getBlock() == null && !isNativeHeader(s) && !isNativeHeader(s.getGetter())) {
that.addError("setter declaration must have a body or => specifier");
}
}
use of org.eclipse.ceylon.model.typechecker.model.Scope in project ceylon by eclipse.
the class DeclarationVisitor method visit.
public void visit(Tree.SuperType that) {
super.visit(that);
if (inExtends) {
final Scope scope = that.getScope();
Type t = new LazyType(unit) {
@Override
public TypeDeclaration initDeclaration() {
ClassOrInterface ci = getContainingClassOrInterface(scope);
if (ci == null) {
return null;
} else {
if (ci.isClassOrInterfaceMember()) {
ClassOrInterface oci = (ClassOrInterface) ci.getContainer();
return intersectionOfSupertypes(oci).getDeclaration();
} else {
return null;
}
}
}
@Override
public Map<TypeParameter, Type> initTypeArguments() {
return emptyMap();
}
};
that.setTypeModel(t);
}
}
use of org.eclipse.ceylon.model.typechecker.model.Scope 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.Scope 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.Scope in project ceylon by eclipse.
the class ClassTransformer method transformTypeParameters.
<T> void transformTypeParameters(GenericBuilder<T> classBuilder, Declaration model) {
java.util.List<TypeParameter> typeParameters = Strategy.getEffectiveTypeParameters(model);
if (typeParameters != null) {
for (TypeParameter param : typeParameters) {
Scope cont = param.getContainer();
if (cont instanceof TypeDeclaration) {
TypeDeclaration container = (TypeDeclaration) cont;
classBuilder.typeParameter(param);
if (classBuilder instanceof ClassDefinitionBuilder) {
// Copy to the companion too
ClassDefinitionBuilder companionBuilder = ((ClassDefinitionBuilder) classBuilder).getCompanionBuilder(container);
if (companionBuilder != null)
companionBuilder.typeParameter(param);
}
}
}
}
}
Aggregations