| Creating a Java Class Programmatically by means of Java Model [message #1100258] |
Mon, 02 September 2013 18:53  |
Rafael Durelli Messages: 51 Registered: September 2012 |
Member |
|
|
Hello guys.
Now I am having another issue. Now I don't know how to instantiate the class Type programmatically. I'am trying to create a Java class by means of Java Model. Thus, firstly, I created an instance of ClassDeclaration. Then, I set all information of this class, such visibility, also instantiated the Class Modifier to set the ClassDeclaration with the keywords Abstract and Public. But I'm facing an issue and I need to create an attribute to this Class. I know that I have to instantiate an FieldDeclaration, this is done. THe real problem is to instantiate the classes TypeAccess and Type.
See the source-code bellow:
Modifier modifierClass = JavaFactory.eINSTANCE.createModifier();
modifierClass.setInheritance(InheritanceKind.ABSTRACT);
modifierClass.setVisibility(VisibilityKind.PUBLIC);
modifierClass.setStatic(false);
modifierClass.setTransient(false);
modifierClass.setVolatile(false);
modifierClass.setNative(false);
modifierClass.setStrictfp(false);
modifierClass.setSynchronized(false);
Modifier modifierAtt = JavaFactory.eINSTANCE.createModifier();
modifierAtt.setVisibility(VisibilityKind.PRIVATE);
modifierAtt.setInheritance(InheritanceKind.NONE);
modifierAtt.setStatic(false);
modifierAtt.setTransient(false);
modifierAtt.setVolatile(false);
modifierAtt.setNative(false);
modifierAtt.setStrictfp(false);
modifierAtt.setSynchronized(false);
FieldDeclaration attibute1 = JavaFactory.eINSTANCE.createFieldDeclaration();
attibute1.setModifier(modifierAtt);
attibute1.setName("kind");
attibute1.setType(typeAcessFinal);
ClassDeclaration classDecl = JavaFactory.eINSTANCE.createClassDeclaration();
classDecl.setName("Animal");
classDecl.setModifier(modifierClass);
classDecl.getBodyDeclarations().add(attibute1);
Thus, how to instantiate the the class Type programmatically?
|
|
|
|
|
|
|
| Re: Creating a Java Class Programmatically by means of Java Model [message #1100686 is a reply to message #1100636] |
Tue, 03 September 2013 08:50   |
Hugo Bruneliere Messages: 560 Registered: July 2009 |
Senior Member |
|
|
Hello,
If you have MoDisco installed in your Eclipse (as I think it is), you can quickly get a Java model out of your Java project by right-clicking on it and then select "Discovery -> Discoverers -> Discover Java project...".
For more information on the Java discoverer, I encourage you to take a look to the corresponding section of the MoDisco documentation.
Once done, you can navigate this model using the MoDisco Model Browser and then find out about its structure.
Best regards,
------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
|
|
|
|
|
|
|
| Re: Creating a Java Class Programmatically by means of Java Model [message #1101280 is a reply to message #1101265] |
Wed, 04 September 2013 04:49   |
Hugo Bruneliere Messages: 560 Registered: July 2009 |
Senior Member |
|
|
Hello Rafael,
If you look to the structure of the Java metamodel (e.g. on the left panel when opening a Java model in the MoDisco Model Browser) and to the Java model itself, you will see that Type is an abstract concept.
ClassDeclaration, InterfaceDeclaration, EnumDeclaration or PrimitiveTypeXXX are types that you can actually instantiate and then set as the type of a FieldDeclaration.
Again, I really advice you to take a deep look to a discovered Java model in the MoDisco Model Browser to have a better idea of how it has to be structured.
Best regards,
------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
|
|
|
|
|
|
| Re: Creating a Java Class Programmatically by means of Java Model [message #1101960 is a reply to message #1101646] |
Thu, 05 September 2013 02:41   |
Hugo Bruneliere Messages: 560 Registered: July 2009 |
Senior Member |
|
|
Hello,
You can find an EMF FAQ entry related to this issue.
If the PrimitiveTypeInt element is well contained in the Model element, this probably means that your Model element is not contained in an EMF resource as it should be: could you check this?
Best regards,
------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
|
|
|
|
Powered by
FUDForum. Page generated in 0.02224 seconds