Read java comments with the M3 library - rascal

I would like to know how Rascal can read Java comments like this:
//This intent is used to share the picture between Android applications
Intent shareIntent = new Intent();
Or this:
/**
* This method can be called to share the picture between Android Applications
*/
private void shareImage() {
...
}
The method createAstFromFile seems to skip these comments.
Thanks in advance.

Comments are not included in the ASTs, but you can get the from the M3 model using #documentation field:
anno rel[loc definition, loc comments] M3#documentation;

Related

Dart Keyboard Event Command Line

I've been monkeying around with Dart (& Flutter more specifically on mobile) and have become quite interested in trying Flutter on Desktop.
Anyways, for this one app idea, I need the ability to create a key event. From my research, I found this: https://api.dartlang.org/stable/2.2.0/dart-html/KeyEvent-class.html which mentions a KeyEvent however this primarily relates to Dart:HTML (which I presume just means browser only).
Does Dart run in the command line support any ability for generating key events? Like say I wanted an app to type something for a user.
Thanks!
#Isaac has basically explained it in his comment but this is how it looks like in code:
import 'dart:io';
void main(){
stdin.echoMode = false;
stdin.lineMode = false;
while(true){
if(stdin.readByteSync() == 102){ // f
print('You payed respect');
}
else{break;}
}
}

Redstone mapper with flutter

I want to use the redstone mapper to decode Json to objects.
However flutter doesn't support mirrors and so I cannot initialize the mapper over the normal way with bootstrapMapper();
Therefore I looked it up, I have to use staticBootstrapMapper(...)
/**
* initialize the mapper system.
*
* This function provides a mapper implementation that
* uses data generated by the redstone_mapper's transformer,
* instead of relying on the mirrors API.
*
*/
void staticBootstrapMapper(Map<Type, TypeInfo> types) {
_staticTypeInfo = types;
configure(_getOrCreateMapper, _createValidator);
}
Link to source code
I dont know what I should put into the map of Map<Type, TypeInfo> types.
Lets say I want to use ObjectData to transform json data to this object.
But how do I have to use this initializing method? Unfortunately I didnt find an example how to use this static bootstrap manager.
class ObjectData {
#Field()
#NotEmpty()
DataType dateType; // might be a User object
#Field()
#NotEmpty()
String id;
#Field()
#NotEmpty()
List<String> versions;
}
Mirrors isn't supported in Flutter, as noted above in comments.
You might want try alternative packages that don't rely on mirrors:
https://pub.dartlang.org/packages/json_serializable
https://pub.dartlang.org/packages/built_value
Of those two (and others) json_serializable looks like the easiest to get started, but might not have as many features.

Incompatible OSAL interfaces in Rhapsody

I'm trying to create OSAL (Operating System Abstraction Layer) adapter for FreeRTOS but confused with the provided interfaces.
For example, init function of RiCOSTask is defined as follows in the docs :
RiCBoolean RiCOSTask_init (RiCOSTask *const me,
RiCOSTaskEndCallBack tfunc, void *param,
const char *name, const long stackSize);
https://www.ibm.com/support/knowledgecenter/SSB2MU_8.1.3/com.ibm.rhp.reference.doc/topics/rhp_r_fw_init_ricostask.html
But RiCTaskEM calls this function like below :
RiCBoolean RiCTaskEM_init(RiCBoolean wrapTask,RiCThread * const
itsThread,RiCBoolean isThread,const RiCOSTaskEntryCallBack cbkFunc,const
RhpAddress cbkParam,RhpPositive initStaticPeriod)
{
..........
(RhpVoid) RiCOSTask_init(&(itsThread->osTask), cbkFunc, cbkParam, initStaticPeriod);
...........
}
I guess something is wrong with my configuration. I'm using SMXF with Rhapsody 8.1.3.
Another issue is, init function of my test class calls the RiCTaskEM_init method like below :
void smxfTestClass_Init(smxfTestClass* const me, RiCTaskEM * p_task) {
RiCTaskEM_init(&(me->ric_task), RiCFALSE, &(me->ric_thread), RiCTRUE,
(RiCOSTaskEntryCallBack)smxfTestClass_doExecute, me, 0U);
.......
}
But if I set a property of my class, eg. ActiveThreadName, the call to RiCTaskEM_Init function is changed like this :
void smxfTestClass_Init(smxfTestClass* const me, RiCTaskEM * p_task) {
RiCTaskEM_Init(&(me->ric_task), "Test", RiCOSDefaultThreadPriority,
RiCOSDefaultStackSize, RiCOSDefaultMessageQueueSize, RiCFALSE, NULL);
......
}
And the compilation fails because the prototype of RiCTaskEM_Init is not compatible with the above call. It is defined like this :
RiCBoolean RiCTaskEM_init(RiCBoolean wrapTask,RiCThread * const
itsThread,RiCBoolean isThread,const RiCOSTaskEntryCallBack cbkFunc,const
RhpAddress cbkParam,RhpPositive initStaticPeriod)
What is happening ? Do I have a mismatch between the Rhapsody version and the SMXF model I am using ?
Why RiCTaskEM_init method is called in a different way if I set a property of my class ? The second version seems to be the correct one but provided RiCTaskEM_init method is not compatible with that.
Do I have to modify functions of RiCTaskEM somehow ? I guess no because it belongs to framework, not the adaptor and OSAL adaptor guide doesn't mention anything about it. But the current implementation simply does not fit.
The documentation is written for the OXF, not for the SMXF Framework. As far as I know there is no real documentation for adapting an SMXF but.. the SMXF is there as a model (Check your /LangC/smxf directory)
this should make it easier to create an adapter.
Do you really need the SMXF or would an OXF suffice (or even another Framework like RXF?
Walter

Memory management with CORBA/TAO out parameters

Lets say I have an IDL function:
void foo(out Data d);
When I inherit from the generated code the signature will look sth like this:
void foo(IDL::Data_out d);
My first question is, what do I have to pass on the client side? I tried:
IDL::Data_out d;
_servantRef->foo(d);
but this doesn't work because Data_out doesn't have a default constructor. I then tried:
IDL::Data* d;
_servantRef->foo(d);
but now the compiler can't cast from IDL::Data* to IDL::Data_out. The following works but looks overcomplicated and thus not correct:
IDL::Data* d(NULL);
IDL::Data_out do(d);
_servantRef->foo(do);
How do I have to proceed from there? During its execution of foo() the servant will at some point allocate a data object like this:
void Servant::foo(IDL::Data_out d)
{
d = new Data();
}
I will then delete the object after having used it on the client side like this:
IDL::Data* d(NULL);
IDL::Data_out do(d);
_servantRef->foo(do);
delete d;
Is this at least correct by its idea or does this work differently? Would appreciate a little help or pointers to documentation where this is described in a understandable way.
You have to use the _var classes correctly, they are like an auto_ptr and make sure the memory is freed when the _var goes out of scope. The client code should be
IDL::Data_var d;
_servantRef->foo (d.out ());
The servant code should be
void Servant::foo(IDL::Data_out d)
{
d = new Data();
}
The new IDL to C++11 language mapping makes this way easier, there the client code is
IDL::Data d;
_servantRef->foo (d);
The servant code is
void Servant::foo(IDL::Data& d)
{
// modify d
}
See TAOX11 for more details about IDL to C++11.
Johnny Willemsen's answer is good. But you also asked:
Would appreciate a little help or pointers to documentation where this is described in a understandable way.
See the book Advanced CORBA Programming with C++ by Henning & Vinoski.
You can also download a copy of the official IDL to C++ language mapping document here. The IDL to C++11 language mapping is available here.

DynamicJasper(on Grails) Purposefully keep column or field blank(empty)

I want to generate a pdf report, where a column(or cell/field) is left blank(empty) on purpose. This column actually does have a value but, I'm choosing not to display it. The column title still needs to be displayed.
Example of where this could be useful:
Blank(empty) column: A comments or notes column down one side of a report.
Blank(empty) cell: A sudoku puzzle print-out.
Much appreciated. DynamicJasper is Awesome! Thanks to the dj-team.
Regards,
Pete
Glad to announce, solution found for adding an 'empty' column - and in short, it's to create a customExpression.
def cb = ColumnBuilder.getInstance()
cb = cb.setTitle("Notes")
cb = cb.setCustomExpression(new BlankExpression())
AbstractColumn columnNotes = cb.build()
Then add it to the rest of the report.
Class BlankExpression is
public class BlankExpression implements CustomExpression {
public BlankExpression() { }
public Object evaluate(Map fields, Map variables, Map parameters) {
return " ";
}
public String getClassName() {
return String.class.getName();
}
}
But there are a few issues relating to the use of customExpressions and grails.
1st issue: "getNew()" - The examples provided on the DJ website all use "getNew()"
http://dynamicjasper.sourceforge.net/docs/HOWTO%20Create%20Custom%20Expressions.html is an example of DynamicJasper v3.1.3 where as the Grails plugin is based on v.3.0.6 which only has a getInstance() method (deprecated in 3.1.3)
2nd issue: As far as I can see, groovy doesn't allow java-style inline class implementations, thus forcing us to create a separate class file. But this is not a big problem. I might be wrong about this, and please correct me.
Hope this helps you too.
Regards,
Pete

Resources