Home » Modeling » EMF » How to get the org.eclipse.uml2.uml.Type?
| | | | | | |
Re: How to get the org.eclipse.uml2.uml.Type? [message #962838 is a reply to message #962826] |
Mon, 29 October 2012 11:11 |
Taimo Maier Messages: 14 Registered: October 2012 |
Junior Member |
|
|
You're right, sorry...
For exmaple I need to give the parameter Type to the methode createAssociation(...,
..., ..., ..., ..., Type end1Type, ..., ..., ..., ..., ...) or for createOwnedAttribute(..., Type type)
|
|
|
Re: How to get the org.eclipse.uml2.uml.Type? [message #962865 is a reply to message #962838] |
Mon, 29 October 2012 11:39 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
Taimo,
There's nothing in UML that restricts these types to correspond in any
way to anything in Java. You might generate C++ from your UML model.
So I don't understand how you expect there to be any mechanism for
determining a UML Type given only a Java Class. If you're using UML in
some specific way, i.e., in a way that lets you specify how UML Types
correspond to Java, that's something you've not explained.
On 29/10/2012 12:11 PM, Taimo Maier wrote:
> You're right, sorry...
> For exmaple I need to give the parameter Type to the methode
> createAssociation(...,
> .., ..., ..., ..., Type end1Type, ..., ..., ..., ..., ...) or for
> createOwnedAttribute(..., Type type)
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| | |
Re: How to get the org.eclipse.uml2.uml.Type? [message #962972 is a reply to message #962951] |
Mon, 29 October 2012 13:17 |
|
Hi, Taimo,
The Type is some element in your UML model. If your model doesn't
already contain the Type instance that you need, then you will have to
create it.
There are many different kinds of Type that you can create in a UML
model: Class, Interface, DataType, Actor, UseCase, Node, even
Association, to name just a few. Presumably you will create UML Class
elements to represent Java classes and UML Interface elements to
represent java interfaces (I'm just guessing).
A UML Package element has short-cut methods for create some types, like
createOwnedClass(...). Otherwise you can always use the UMLFactory to
create the kind of Type that you need and add it to a Package's
getOwnedTypes() list.
HTH,
Christian
On 2012-10-29 13:04:01 +0000, Taimo Maier said:
> The aim is to generate UML or EMF files to generate models from given
> classes with information like attributes, associations, etc. It's a
> Java stand alone project and the information are readout via
> Reflection. So I'm looking for a possibility to get the Type for the
> methods createAttribute, createAssociation, etc.
> http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.uml2.doc%2Freferences%2Fjavadoc%2Forg%2Feclipse%2Fuml2%2Fuml%2FType.html
>
|
|
| | |
Re: How to get the org.eclipse.uml2.uml.Type? [message #963146 is a reply to message #963125] |
Mon, 29 October 2012 15:54 |
|
Hi, Taimo,
Now you're creating an Ecore model representing your Java classes, not
a UML model? Didn't you need a UML model?
Ecore is a modeling language like UML: if you need to create a model
of your Java classes using Ecore, then you have to create appropriate
EClassifiers as you would have to create appropriate Types in a UML
model.
I think there's something fundamental missing from the discussion,
which probably is an incorrect assumption about Ecore's and UML's
capabilities. Your application cannot just "get" an Ecore EClassifier
or a UML Type "from" a Java class. Your application has to *create*
the model.
Cheers,
Christian
On 2012-10-29 15:43:21 +0000, Taimo Maier said:
> Okay, at the moment I try another way:
> Like in my code example I get a Type (paratype) and now I have to know
> the EClassifier. How can I get the EClassifier from paratype?
>
>
> Method[] m = c.getDeclaredMethods();
> Class[] paratypes;
>
> for (Method method : m) {
> paratypes = method.getParameterTypes();
>
> if(paratypes.length > 0) {
> for (Class paratype : paratypes) {
>
> ..
>
>
>
> private void addEAttribute(EClass clazz, String name, EClassifier type)
> {
> final EAttribute attribute =
> EcoreFactory.eINSTANCE.createEAttribute();
> attribute.setName(name);
> attribute.setEType(type);
> clazz.getEStructuralFeatures().add(attribute);
> }
|
|
| |
Re: How to get the org.eclipse.uml2.uml.Type? [message #963237 is a reply to message #963215] |
Mon, 29 October 2012 17:07 |
|
Hi, Taimo,
What didn't work?
What is "methodenParameterList" ? Is it a list of EClassifiers? Or a
list of EParameters?
You probably don't want to create a new EDataType for every Java method
parameter type, because many methods will have parameters of the same
type, so you will end up creating EDataTypes for the same Java classes
over and over again. Not to mention that you aren't adding them to the
model. They need to be added to some EPackage.
I think Ed's suggestion to take a step back and consider what you are
actually trying to do is good advice. If it doesn't matter whether the
model is an Ecore or a UML model, then it seems doubtful that the model
can be of any use at all.
Cheers,
Christian
On 2012-10-29 16:51:16 +0000, Taimo Maier said:
> Yes, now I'm creating an Ecore model. In the end it doesn't matter
> whether it's an Ecore model or an UML model.
>
> How do you mean? I tried this, but it didn't work...
>
> for (Method method : m) {
>
> //mod = method.getModifiers();
> paratypes = method.getParameterTypes();
>
> if(paratypes.length > 0) {
> for (Class paratype : paratypes) {
>
> EDataType type = null;
> type.setInstanceClass(paratype.getClass());
> type.setInstanceClassName(paratype.toString());
> methodenParameterList.add(type);
>
> Quote:
>> I think there's something fundamental missing from the discussion,
>> which probably is an incorrect assumption about Ecore's and UML's
>> capabilities. Your application cannot just "get" an Ecore EClassifier
>> or a UML Type "from" a Java class. Your application has to *create*
>> the model.
>
> I'm very new to this topic, so it can be that I do something wrong this
> is why I asked you :) So thank a lot for your (Christian W. Damus, Ed
> Merks and Ed Willink) help :)
|
|
| |
Re: How to get the org.eclipse.uml2.uml.Type? [message #964164 is a reply to message #963237] |
Tue, 30 October 2012 10:04 |
Taimo Maier Messages: 14 Registered: October 2012 |
Junior Member |
|
|
Christian W. Damus wrote on Mon, 29 October 2012 13:07Hi, Taimo,
What didn't work?
Here is the error message:
Quote:java.lang.NullPointerException
at main.MethodenInfoPluglet.methodsParameterType(Unknown Source)
Quote:What is "methodenParameterList" ? Is it a list of EClassifiers? Or a
list of EParameters?
It's better when I post the full code.
methodsParameterType from the class MethodenInfoPluglet:
@SuppressWarnings("unchecked")
public EList<EClassifier> methodsParameterType(Class c) throws ClassNotFoundException {
EList<EClassifier> methodenParameterList = new BasicEList<EClassifier>();
Method[] m = c.getDeclaredMethods();
Class[] paratypes;
for (Method method : m) {
//mod = method.getModifiers();
paratypes = method.getParameterTypes();
if(paratypes.length > 0) {
for (Class paratype : paratypes) {
EDataType type = null;
type.setInstanceClass(paratype.getClass());
type.setInstanceClassName(paratype.toString());
methodenParameterList.add(type);
}
} else
methodenParameterList.add(null);
}
return methodenParameterList;
}
public class ModellErstellenPluglet3 {
PackageInfoPluglet packageInfoPluglet = new PackageInfoPluglet();
KlassenInfoPluglet klassenInfoPluglet = new KlassenInfoPluglet();
AttributeInfoPluglet attributeInfoPluglet = new AttributeInfoPluglet();
MethodenInfoPluglet methodenInfoPluglet = new MethodenInfoPluglet();
EntityInfoPluglet entityInfoPluglet = new EntityInfoPluglet();
public void diagrammErstellen(final String directory, final java.lang.Class<?> clazz) throws ClassNotFoundException {
// Methoden
final EList<String> methodsWithoutReturnNameList = methodenInfoPluglet.methodenOhneRueckgabewertAusgeben(clazz);
final EList<EClassifier> methodsParameterTypeList = methodenInfoPluglet.methodsParameterType(clazz);
...
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());
URI fileUri = URI.createFileURI("C:/" + directory + className + "1.ecore");
Resource res = resourceSet.createResource(fileUri);
EPackage ePackage = createPackage(packageName);
EClass eClass = createEClass(ePackage, className);
for (int i=0; i < methodsWithoutReturnNameList.size(); i++) {
addEOperation(eClass, methodsWithoutReturnNameList.get(i), methodsWithoutReturnNameList, methodsParameterTypeList);
}
...
}
private EOperation addEOperation(EClass clazz, String name, EList<String> paramNames, EList<EClassifier> paramTypes) { // , EClassifier type
final EOperation tempEOperation = EcoreFactory.eINSTANCE.createEOperation();
// tempOperation.setEType(value);
tempEOperation.setName(name);
if (paramNames != null) {
for (int i = 0; i < paramNames.size(); i++) {
createOwnedParameter(tempEOperation, paramNames.get(i)); // , paramTypes.get(i)
}
}
clazz.getEOperations().add(tempEOperation);
return tempEOperation;
}
So the tempEOperation.setEType(); needs an EClassifier.
Quote:I think Ed's suggestion to take a step back and consider what you are
actually trying to do is good advice.
I try to explain: The aim is to create models from given classes. The information like attributes, operations, etc. must be in the model (So I think it doesn't matter whether it's an Ecore model or an UML model? The aim is that all information are in the model). I readout all information via Reflection in Java and in the methodsParameterType I get the Type, but it's an Java type, but .setEType() needs an EClassifier. So the question is how to get the EClassifier. I hope that it's clear now.
[Updated on: Tue, 30 October 2012 10:07] Report message to a moderator
|
|
|
Re: How to get the org.eclipse.uml2.uml.Type? [message #964362 is a reply to message #964164] |
Tue, 30 October 2012 13:11 |
|
Hi, Taimo,
OK, I see. So, you will probably have to create and maintain a model
that has EPackages for each Java package, or one EPackage to collect
all the Java types that you're working with. Every time you need to
get an EClassifier for some Java class, you would need to look for it
in the model in case it was encountered before and added to the model.
If you don't already have it, then create the EClassifier and add it to
the appropriate EPackage in your model so you can find it again, later.
Rather than collect method parameter type EClasses in a list, why not
just create and add the EParameters to the EOperation? Then you'll
have a model of the operation.
Ed suggested looking at an example that builds an Ecore model from
Java. That should definitely help.
cW
|
|
| |
Re: How to get the org.eclipse.uml2.uml.Type? [message #964450 is a reply to message #964414] |
Tue, 30 October 2012 14:25 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
Taimo,
You need to demonstrate a little more initiative. I already pointed out
code that does a very similar thing, so have a look at that rather than
asking someone to spell out every detail for you.
On 30/10/2012 2:54 PM, Taimo Maier wrote:
> Okay thank you for your answer, but I don't know how to realize this
> step programmatically from getting the normal Java Type to getting the
> EParameter or EClass.
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Fri Sep 20 17:24:09 GMT 2024
Powered by FUDForum. Page generated in 0.05277 seconds
|