Issue 495 in moose-technology: Parametrized Types - Generics

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
22 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology
Status: New
Owner: [hidden email]
Labels: Type-Enhancement Priority-Medium Component-Famix

New issue 495 by [hidden email]: Parametrized Types - Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Use Parametrized Types (i.e., a parameterTypes property in FAMIXClass) in  
Moose to deal with (Java) code like this: ClassFoo<A,B,C>, where A, B and C  
are parameters of ClassFoo.
VerveineJ must export this property in its .mse files.


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #1 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

I suggest to use the EntityState>>attributes cache of MooseEntity to store  
extended properties like #parameterTypes. And declare this extension in  
Famix-Java. The cache was made for such language-specific extensions which  
require states.

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #2 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

This is indeed what I proposed as well. Andre? :)

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #3 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

OK! Thanks for the suggestion. Indeed I implemented creating a  
instanceVariable and I committed some minutes ago, before see this  
email :). But no problem, I will follow the suggestion.

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology
Updates:
        Status: Fixed

Comment #4 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

It was added the attributes *parameterTypes* to FAMIXClass; and  
*declaredArgumentTypes* to FAMIXMethod and FAMIXStructuralEntity.

The parameterTypes is to deal with Java class which contains parameters in  
its declaration. Example:

public class Dictionary<A,B,C> {
        …
}

The declaredArgumentTypes is to deal with code which contains arguments in  
its declatedType, i.e., in FAMIXMethod (its return type) and in  
FAMIXStructuralEntity (attribute, parameter, local variable, etc.).  
Examples:

public Map<B,NamedEntity> mapBind;

public Collection<T> getEntityByName(Class<T> fmxClass, String name) {
                Collection<T> ret = new LinkedList<T>();
                Collection<NamedEntity> l_name = mapName.get(name);
                …
}

There are tests in FamixJavaTest>>testImportArgumentTypes and  
FamixJavaTest>>testImportParameterTypes using these attributes.


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology
Updates:
        Status: Started

Comment #5 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Good work.

In the meantime I payed a bit more thought to this. Now, we have the  
extensions in three places. I think it would be cleaner to introduce two  
new entities:
- FAMIXParameterizedClass as a subclass of FAMIXClass - for the definition  
of a generic class
- FAMIXSpecificParameterizedType as an instance of FAMIXType - for the  
actual specific types specified as types of arguments

What do you think?

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #6 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Yes, it is a cleaner solution. The FAMIXParameterizedClass was our first  
idea, but create only the properties was simpler.
What do you mean with "FAMIXSpecificParameterizedType as an instance of  
FAMIXType"? Do you mean FAMIXSpecificParameterizedType as a subclass of  
FAMIXType?

BTW, I think that only FAMIXParameterizedType is a better name.

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #7 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Indeed, I meant "FAMIXSpecificParameterizedType as a subclass of FAMIXType".

I also thought of FAMIXParameterizedType, but then it would be quite  
confusing to distinguish between this and FAMIXParameterizedClass. So, even  
if the name is longer and maybe clumsier, it would be worth it.

Here are other options:
- FAMIXGenericClass / FAMIXParameterizableClass
- FAMIXParameterizedType

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology
Updates:
        Labels: Milestone-4.3

Comment #8 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Will you then change the implementation? It would be cool to fix it because  
like that we can also change the inFusion exporter to populate this  
information.

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #9 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Yes. First of all I need to change (a lot :), I guess) VerveineJ to export  
these information, and then, change the Moose meta-model.

BTW, I have some questions. In the code below:

public class Class1<A,B,C> {

        public Map<String,String> attribute1;
       
        public String attribute2;

        public Map<String,String> method1(Map<String,String> parameter1) {
                Collection<String> localVariable1;
                ...
        }
        ...
}

"Class1" is a FAMIXParameterizedClass with parameterTypes property A, B and  
C.

The total of FAMIXSpecificParameterizedType is 7 (one for each argument, as  
you said "for the actual specific types specified as types of arguments")?

"attribute1" contains two FAMIXSpecificParameterizedType stored in its  
(FAMIXStructuralEntity) declaredArgumentTypes property (which should be a  
<derived> property, the same to others declaredArgumentTypes properties).  
That's it?

So, which should be the fully qualified name of these  
FAMIXSpecificParameterizedType? I ask this because, for example, they are  
not the same String type of "attribute2" (which is a "normal" FAMIXType).

Moreover, which new properties will FAMIXSpecificParameterizedType  
contains? I see two:
- Type: link FAMIXSpecificParameterizedType to its "real" type (the  
FAMIXType String, in the example)
- Position: its position in the list of argument.
What do you think?

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #10 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Not quite.

There should be only 4 FAMIXSpecificParameterizedType.

"attribute1" will have one such FAMIXParameterizedType, in which:
- baseType ->Map
- parameterTypes -> Collection with the first element pointing to String,  
and the second one pointing to String

This is specific because the argument types point to a certain class.

"Class1" will be indeed a FAMIXParameterizedClass, in which:
- typeArguments -> collection with symbols


Regarding names, I think I like these ones the best:
- FAMIXParameterizableClass (although the parameterizable word does not  
exist in English, it does appear in code)
- FAMIXParameterizedType

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #11 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

OK. Now it is cleaner. I was thinking in a different way.
If I have more questions I return.
Thanks!

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology
Updates:
        Status: Fixed

Comment #12 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Added classes FAMIXParameterizedType (with the property parameterTypes) and  
FAMIXParameterizableClass (with the properties argumentTypes and baseType);  
and tests in FamixParameterizedTypeTest and FamixParameterizableClassTest.

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology
Updates:
        Status: Started

Comment #13 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

It's not quite correct because the argumentTypes are not types, they are  
just symbols :). I am reviewing this right now. Until then, I am reopening  
the issue.

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #14 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Thanks. But I think that FAMIXParameterizableClass>>parameterTypes are just  
symbols. FAMIXParameterizedType>>argumentTypes are types.

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology
Updates:
        Status: Fixed

Comment #15 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

They were types :), but it is fixed now.

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #16 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Yes, I saw :). Thanks!

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology
Updates:
        Status: Started

Comment #17 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

So, now we have ParameterizableClass having parameters as a collection of  
strings. The problem is that in this way we cannot model the below case.

First, T should actually be some sort of a local type that can be used as  
declaredType.

Second, T should also be allowed to inherit.

What a mess. Any ideas of how to model that?

----EXAMPLE----

interface MinMax<T extends Comparable<T>> {
   T min();
   T max();
}

class MyClass<T extends Comparable<T>> implements MinMax<T> {
   T[] vals;

   MyClass(T[] o) { vals = o; }

   public T min() {
     T v = vals[0];
     for(int i=1; i < vals.length; i++)
       if(vals[i].compareTo(v) < 0) v = vals[i];

     return v;
   }

   public T max() {
     T v = vals[0];

     for(int i=1; i < vals.length; i++)
       if(vals[i].compareTo(v) > 0) v = vals[i];

     return v;
   }
}

public class GenIFDemo {
   public static void main(String args[]) {
     Integer inums[] = {3, 6, 2, 8, 6 };
     Character chs[] = {'b', 'r', 'p', 'w' };

     MyClass<Integer> iob = new MyClass<Integer>(inums);
     MyClass<Character> cob = new MyClass<Character>(chs);

     System.out.println("Max value in inums: " + iob.max());
     System.out.println("Min value in inums: " + iob.min());

     System.out.println("Max value in chs: " + cob.max());
     System.out.println("Min value in chs: " + cob.min());
   }
}

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

moose-technology

Comment #18 on issue 495 by [hidden email]: Parametrized Types -  
Generics
http://code.google.com/p/moose-technology/issues/detail?id=495

Now I introduced ParameterType that has as container the  
ParameterizableClass.

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Issue 495 in moose-technology: Parametrized Types - Generics

Alexandre Bergel

I haven't closely followed the topic, but infusion does not provide parameter information if I remember correctly.
Does Verveine completely replace infusion?

The moose book does nor mention verveine: http://www.themoosebook.org/book/externals/import-export/java

Cheers,
Alexandre


Le 13 févr. 2011 à 14:16, [hidden email] a écrit :

>
> Comment #18 on issue 495 by [hidden email]: Parametrized Types - Generics
> http://code.google.com/p/moose-technology/issues/detail?id=495
>
> Now I introduced ParameterType that has as container the ParameterizableClass.
>
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
12