Skip to content

Commit

Permalink
metamodel #226: implement the new Attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Jul 16, 2013
1 parent 3ab6d91 commit 07a68b7
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 34 deletions.
@@ -0,0 +1,70 @@
package com.redhat.ceylon.compiler.java.runtime.metamodel;

import ceylon.language.metamodel.Attribute$impl;
import ceylon.language.metamodel.AttributeType$impl;
import ceylon.language.metamodel.DeclarationType$impl;
import ceylon.language.metamodel.Value;
import ceylon.language.metamodel.declaration.AttributeDeclaration;

import com.redhat.ceylon.compiler.java.metadata.Ignore;
import com.redhat.ceylon.compiler.java.metadata.TypeInfo;
import com.redhat.ceylon.compiler.java.runtime.model.TypeDescriptor;
import com.redhat.ceylon.compiler.typechecker.model.ProducedType;

public class AppliedAttribute<Container, Type>
extends AppliedMember<Container, ceylon.language.metamodel.Value<? extends Type>>
implements ceylon.language.metamodel.Attribute<Container, Type> {

private FreeAttribute declaration;
private ProducedType type;
private ceylon.language.metamodel.Type closedType;

public AppliedAttribute(TypeDescriptor $reifiedType, TypeDescriptor $reifiedKind,
FreeAttribute declaration, ProducedType type) {
super($reifiedType, $reifiedKind);
this.declaration = declaration;
this.type = type;
this.closedType = Metamodel.getAppliedMetamodel(type);
}

@Override
@Ignore
public AttributeType$impl<Type> $ceylon$language$metamodel$AttributeType$impl() {
// TODO Auto-generated method stub
return null;
}

@Override
@Ignore
public DeclarationType$impl $ceylon$language$metamodel$DeclarationType$impl() {
// TODO Auto-generated method stub
return null;
}

@Override
@Ignore
public Attribute$impl<Container, Type> $ceylon$language$metamodel$Attribute$impl() {
// TODO Auto-generated method stub
return null;
}

@Override
@TypeInfo("ceylon.language.metamodel.declaration::AttributeDeclaration")
public AttributeDeclaration getDeclaration() {
return declaration;
}

@Override
@TypeInfo("ceylon.language.metamodel::Type")
public ceylon.language.metamodel.Type getType() {
return closedType;
}

@Override
protected Value<? extends Type> bindTo(Object instance) {
// FIXME: add AttributeDeclaration.isVariable or something
return (((com.redhat.ceylon.compiler.typechecker.model.Value)declaration.declaration).isVariable()
? new AppliedVariable(null, declaration, type, instance)
: new AppliedValue(null, declaration, type, instance));
}
}
Expand Up @@ -234,17 +234,10 @@ ceylon.language.metamodel.Member<SubType, Kind> getAttribute(@Ignore TypeDescrip
final FreeAttribute value = declaration.findValue(name);
if(value == null)
return null;
final com.redhat.ceylon.compiler.typechecker.model.Value decl = (com.redhat.ceylon.compiler.typechecker.model.Value) value.declaration;
final ProducedType valueType = decl.getType().substitute(producedType.getTypeArguments());

return new AppliedMember<SubType, Kind>($reifiedSubType, $reifiedKind/*, (AppliedClassOrInterfaceType<SubType>) this*/){
@Override
protected Kind bindTo(Object instance) {
return (Kind) (decl.isVariable()
? new AppliedVariable(null, value, valueType, instance)
: new AppliedValue(null, value, valueType, instance));
}
};
com.redhat.ceylon.compiler.typechecker.model.Value decl = (com.redhat.ceylon.compiler.typechecker.model.Value) value.declaration;
ProducedType valueType = decl.getType().substitute(producedType.getTypeArguments());
TypeDescriptor reifiedValueType = Metamodel.getTypeDescriptorForProducedType(valueType);
return new AppliedAttribute($reifiedSubType, reifiedValueType, value, valueType);
}

@Override
Expand Down
Expand Up @@ -3,10 +3,15 @@
import java.util.Collections;
import java.util.List;

import ceylon.language.metamodel.Attribute$impl;
import ceylon.language.metamodel.AttributeType$impl;
import ceylon.language.metamodel.DeclarationType$impl;
import ceylon.language.metamodel.Member$impl;
import ceylon.language.metamodel.declaration.AttributeDeclaration;

import com.redhat.ceylon.compiler.java.metadata.Ceylon;
import com.redhat.ceylon.compiler.java.metadata.Ignore;
import com.redhat.ceylon.compiler.java.metadata.TypeInfo;
import com.redhat.ceylon.compiler.java.metadata.TypeParameter;
import com.redhat.ceylon.compiler.java.metadata.TypeParameters;
import com.redhat.ceylon.compiler.java.metadata.Variance;
Expand All @@ -17,20 +22,23 @@
@Ceylon(major = 5)
@com.redhat.ceylon.compiler.java.metadata.Class
@TypeParameters({
@TypeParameter(value = "Container", variance = Variance.IN),
@TypeParameter(value = "Type", variance = Variance.OUT),
})
public class FreeAttributeWithMember<Type, Declaration extends ceylon.language.metamodel.DeclarationType>
public class FreeAttributeWithMember<Container, Type>
extends FreeAttribute
implements ceylon.language.metamodel.Member<Type, Declaration> {
implements ceylon.language.metamodel.Attribute<Container, Type> {

private AppliedMember<Type, Declaration> memberDelegate;
@Ignore
private TypeDescriptor $reifiedType;
private TypeDescriptor $reifiedContainer;
@Ignore
private TypeDescriptor $reifiedDeclaration;
private TypeDescriptor $reifiedType;

protected FreeAttributeWithMember(@Ignore TypeDescriptor $reifiedType,
@Ignore TypeDescriptor $reifiedDeclaration,
private ceylon.language.metamodel.Type closedType;
private AppliedAttribute<Container, Type> memberDelegate;

protected FreeAttributeWithMember(@Ignore TypeDescriptor $reifiedContainer,
@Ignore TypeDescriptor $reifiedType,
TypedDeclaration declaration) {
super(declaration);
com.redhat.ceylon.compiler.typechecker.model.Value modelDecl = (com.redhat.ceylon.compiler.typechecker.model.Value)declaration;
Expand All @@ -39,51 +47,80 @@ protected FreeAttributeWithMember(@Ignore TypeDescriptor $reifiedType,
List<com.redhat.ceylon.compiler.typechecker.model.ProducedType> producedTypes = Collections.emptyList();
com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface container = (com.redhat.ceylon.compiler.typechecker.model.ClassOrInterface) declaration.getContainer();
final ProducedType appliedType = declaration.getProducedReference(container.getType(), producedTypes).getType();
this.$reifiedType = Metamodel.getTypeDescriptorForProducedType(container.getType());
TypeDescriptor attributeType = Metamodel.getTypeDescriptorForProducedType(appliedType);
this.$reifiedDeclaration = TypeDescriptor.klass(ceylon.language.metamodel.Value.class, attributeType);
memberDelegate = new AppliedMember<Type, Declaration>($reifiedType, $reifiedDeclaration){
@Override
protected Declaration bindTo(Object instance) {
return (Declaration) new AppliedValue(null, attributeDecl, appliedType, instance);
}
};
this.$reifiedContainer = Metamodel.getTypeDescriptorForProducedType(container.getType());
this.$reifiedType = Metamodel.getTypeDescriptorForProducedType(appliedType);
memberDelegate = new AppliedAttribute<Container, Type>(this.$reifiedContainer, this.$reifiedType, attributeDecl, appliedType);

this.closedType = Metamodel.getAppliedMetamodel(appliedType);
}

@Override
@Ignore
public Member$impl<Container, ceylon.language.metamodel.Value<? extends Type>> $ceylon$language$metamodel$Member$impl() {
// TODO Auto-generated method stub
return null;
}

@Override
@Ignore
public AttributeType$impl<Type> $ceylon$language$metamodel$AttributeType$impl() {
// TODO Auto-generated method stub
return null;
}

@Override
@Ignore
public DeclarationType$impl $ceylon$language$metamodel$DeclarationType$impl() {
// TODO Auto-generated method stub
return null;
}

@Override
@Ignore
public Member$impl<Type, Declaration> $ceylon$language$metamodel$Member$impl() {
public Attribute$impl<Container, Type> $ceylon$language$metamodel$Attribute$impl() {
// TODO Auto-generated method stub
return null;
}

@Override
@TypeInfo("ceylon.language.metamodel.declaration::AttributeDeclaration")
public AttributeDeclaration getDeclaration() {
return this;
}

@Override
@TypeInfo("ceylon.language.metamodel::Type")
public ceylon.language.metamodel.Type getType() {
return closedType;
}

@Override
@Ignore
public Declaration $call() {
public ceylon.language.metamodel.Value<? extends Type> $call() {
return memberDelegate.$call();
}

@Override
@Ignore
public Declaration $call(Object arg0) {
public ceylon.language.metamodel.Value<? extends Type> $call(Object arg0) {
return memberDelegate.$call(arg0);
}

@Override
@Ignore
public Declaration $call(Object arg0, Object arg1) {
public ceylon.language.metamodel.Value<? extends Type> $call(Object arg0, Object arg1) {
return memberDelegate.$call(arg0, arg1);
}

@Override
@Ignore
public Declaration $call(Object arg0, Object arg1, Object arg2) {
public ceylon.language.metamodel.Value<? extends Type> $call(Object arg0, Object arg1, Object arg2) {
return memberDelegate.$call(arg0, arg1, arg2);
}

@Override
@Ignore
public Declaration $call(Object... args) {
public ceylon.language.metamodel.Value<? extends Type> $call(Object... args) {
return memberDelegate.$call(args);
}

Expand All @@ -95,6 +132,6 @@ protected Declaration bindTo(Object instance) {

@Override
public TypeDescriptor $getType() {
return TypeDescriptor.klass(FreeAttributeWithMember.class, $reifiedType, $reifiedDeclaration);
return TypeDescriptor.klass(FreeAttributeWithMember.class, $reifiedContainer, $reifiedType);
}
}

0 comments on commit 07a68b7

Please sign in to comment.