Metamodel: Value<> from Function parameter

54 views
Skip to first unread message

Wojciech Potiopa

unread,
Oct 7, 2016, 5:32:00 PM10/7/16
to ceylon-users
Hello. At beginning i want to apologise for lack of formatting and semantic errors as i'm writing this on a phone.
I'm creating a framework which uses annotations for Configuration of further operation.
In simple words there is an interface which can be annoted. Each it's method and their parameters may be annoted. I want to read this annotations. But for some components i want to read also annotations from underlaying type f.e. let's take method in interface

interface SomeInterface{

Clazz doThing(by("parameter") Clazz clazz);

}

And class Clazz

by("type")
class Clazz(){}

So i want to get from this method parameter - clazz, both annotations:

by("parameter")
by("type")

OK by so calling

'SomeInterface.doThing'.declaration.parameters.each(FunctionOrValueDeclaration element)=> element.annotations<Annotation>()....);
I can extract my first annotation

Now from the method i can obtain also parameter types. By calling Method.parameterTypes.
But in my application, annotations are obtained, when passed Model not declaration or specyfic type. So normally for method or attribute I would call bind on declaration. For the parametter there is apply method in ValueDeclaration (i dont care about functional parameters). It requires specyfic staticly typed type (Value<Clazz> val=parameter.apply()) which i dont have as all operations are generic. I cannot use a variable as type parametter obtained from Method.parameterTypes.
How to obtain Value<> for parameter of SomeInterface.doThing ?

Message has been deleted

Stephane Epardaud

unread,
Oct 12, 2016, 3:52:02 AM10/12/16
to ceylon...@googlegroups.com
Sure, you can apply your declarations to get models, even for parameters.

On 11 October 2016 at 23:06, Wojciech Potiopa <wojciech...@gmail.com> wrote:
Hello, seems i was mistaken from the beginning. It is not possible (correct me if I'm wrong) to fetch generic OptionalAnnotation's or SequencedAnnotation's from Model declaration. So i made a fallback to optionalAnnotation and sequencedAnnotations built in top level functions and not caching results. But still can we construct a Model declaration from Method.declaration.parameters.first and Method.parameterTypes.first , like we can with function https://modules.ceylon-lang.org/repo/1/ceylon/language/1.3.0/module-doc/api/meta/declaration/FunctionDeclaration.type.html - apply?

--
You received this message because you are subscribed to the Google Groups "ceylon-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-users+unsubscribe@googlegroups.com.
To post to this group, send email to ceylon...@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceylon-users/6db5703e-f3a6-4384-b835-6fe446b950d9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Stéphane Épardaud
Message has been deleted

Stephane Epardaud

unread,
Oct 13, 2016, 3:57:56 AM10/13/16
to ceylon...@googlegroups.com
Oh sorry I got confused. I don't think you can apply method parameters, because they depend on the invocation, not the container. Perhaps we can support that in the future and just throw if you try to `get` them, this way you have access to the applied types. But not at the moment I don't think. Can't you do with declarations instead of models?

On 12 October 2016 at 22:39, Wojciech Potiopa <wojciech...@gmail.com> wrote:
Hi, that's what I'm struggling with.. it is not working.

shared test void functionParameterApplyTest() {
   
   
FunctionOrValueDeclaration? first = `function testFunc`.parameterDeclarations.first;
   
assert(exists first, first.name=="arg");
   
assert(is ValueDeclaration first);
   
Value<String,String> apply = first.apply<String,String>(); //ceylon.language.meta.model.TypeApplicationException "Cannot apply a member declaration with no container type: use memberApply"
   
print(apply);
}

shared test
void functionParameterMemberApplyTest() {
   
   
FunctionOrValueDeclaration? first = `function testFunc`.parameterDeclarations.first;
   
assert(exists first, first.name=="arg");
   
assert(is ValueDeclaration first);
   
ValueModel<> memberApply = first.memberApply(type(testFunc));//ceylon.language.Exception "parameterized test failed, argument provider probably returned incompatible values"
   
print(memberApply);
}



void testFunc(String arg){}



On Wednesday, 12 October 2016 09:52:02 UTC+2, Stéphane Épardaud wrote:
Sure, you can apply your declarations to get models, even for parameters.
On 11 October 2016 at 23:06, Wojciech Potiopa <wojciech...@gmail.com> wrote:
Hello, seems i was mistaken from the beginning. It is not possible (correct me if I'm wrong) to fetch generic OptionalAnnotation's or SequencedAnnotation's from Model declaration. So i made a fallback to optionalAnnotation and sequencedAnnotations built in top level functions and not caching results. But still can we construct a Model declaration from Method.declaration.parameters.first and Method.parameterTypes.first , like we can with function https://modules.ceylon-lang.org/repo/1/ceylon/language/1.3.0/module-doc/api/meta/declaration/FunctionDeclaration.type.html - apply?

On Friday, 7 October 2016 23:32:00 UTC+2, Wojciech Potiopa wrote:
Hello. At beginning i want to apologise for lack of formatting and semantic errors as i'm writing this on a phone.
I'm creating a framework which uses annotations for Configuration of further operation.
In simple words there is an interface which can be annoted. Each it's method and their parameters may be annoted. I want to read this annotations. But for some components i want to read also annotations from underlaying type f.e. let's take method in interface

interface SomeInterface{

Clazz doThing(by("parameter") Clazz clazz);

}

And class Clazz

by("type")
class Clazz(){}

So i want to get from this method parameter - clazz, both annotations:

by("parameter")
by("type")

OK by so calling

'SomeInterface.doThing'.declaration.parameters.each(FunctionOrValueDeclaration element)=> element.annotations<Annotation>()....);
I can extract my first annotation

Now from the method i can obtain also parameter types. By calling Method.parameterTypes.
But in my application, annotations are obtained, when passed Model not declaration or specyfic type. So normally for method or attribute I would call bind on declaration. For the  parametter there is apply method in ValueDeclaration (i dont care about functional parameters). It requires specyfic staticly typed type (Value<Clazz> val=parameter.apply()) which i dont have as all operations are generic. I cannot use a variable as type parametter obtained from  Method.parameterTypes.
How to obtain Value<> for parameter of SomeInterface.doThing  ?
 

--
You received this message because you are subscribed to the Google Groups "ceylon-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-users...@googlegroups.com.

To post to this group, send email to ceylon...@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-users.



--
Stéphane Épardaud

--
You received this message because you are subscribed to the Google Groups "ceylon-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-users+unsubscribe@googlegroups.com.
To post to this group, send email to ceylon...@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-users.

For more options, visit https://groups.google.com/d/optout.



--
Stéphane Épardaud

Stephane Epardaud

unread,
Oct 13, 2016, 4:30:11 AM10/13/16
to ceylon...@googlegroups.com
So for now you should match the parameter types with the parameter declarations, but in the future we can implement something better: https://github.com/ceylon/ceylon/issues/6581
--
Stéphane Épardaud
Message has been deleted

Stephane Epardaud

unread,
Oct 13, 2016, 7:56:16 AM10/13/16
to ceylon...@googlegroups.com
You can get all annotations from the declarations, I don't follow.

On 13 October 2016 at 13:51, Wojciech Potiopa <wojciech...@gmail.com> wrote:
Ok, Thank You for answering. I think i cannot do my annotation processing with declaration as i need underlying type f.e.:
Enter code here...final annotation class SeqAnno(shared String val) satisfies SequencedAnnotation<SeqAnno, Annotated>{}
annotation
SeqAnno seq(String val) => SeqAnno(val);


seq
("TestOne")
seq
("TestTwo")
interface AnnoTestInterface satisfies BaseInterface &OptionalBaseIFace {
   
    shared formal
OptionalBaseIFace testMethod(seq("Param") AnnoTestInterface param);
   
   
by("Method")
    seq
("Method")
    shared formal
BaseInterface test2Method(OptionalBaseIFace arg,by("Param") OptionalBaseIFace arg2);
   
}
seq
("TestBaseOne")
seq
("TestBaseTwo")
interface BaseInterface{
   
}


by ("Base")
shared
interface OptionalBaseIFace {
}

I want to fetch SeqAnno annotations from let say AnnoTestInterface but also if I'm fetching them i want to have annotations from BaseInterface and OptionalBaseIFace interfaces. The same with methods, attributes and parameters. So from what i see i cannot get thees types from declaration.

Thank you
Wojciech



--
Stéphane Épardaud



--
Stéphane Épardaud

--
You received this message because you are subscribed to the Google Groups "ceylon-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-users+unsubscribe@googlegroups.com.
To post to this group, send email to ceylon...@googlegroups.com.
Visit this group at https://groups.google.com/group/ceylon-users.

For more options, visit https://groups.google.com/d/optout.



--
Stéphane Épardaud
Reply all
Reply to author
Forward
Message has been deleted
0 new messages