Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parametrized Types - Generics #495

Closed
seandenigris opened this issue Aug 3, 2015 · 19 comments
Closed

Parametrized Types - Generics #495

seandenigris opened this issue Aug 3, 2015 · 19 comments

Comments

@seandenigris
Copy link
Contributor

Originally reported on Google Code with 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.

Reported by andrehoraa on 2011-01-17 08:55:21

@seandenigris
Copy link
Contributor Author

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.

Reported by simon.denier on 2011-01-19 11:18:57

@seandenigris
Copy link
Contributor Author

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

Reported by tudor.girba on 2011-01-19 12:06:25

@seandenigris
Copy link
Contributor Author

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.

Reported by andrehoraa on 2011-01-19 13:12:52

@seandenigris
Copy link
Contributor Author

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.

Reported by andrehoraa on 2011-01-19 15:51:57

  • Status changed: Fixed

@seandenigris
Copy link
Contributor Author

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?

Reported by tudor.girba on 2011-01-19 22:39:16

  • Status changed: Started

@seandenigris
Copy link
Contributor Author

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.

Reported by andrehoraa on 2011-01-19 23:36:25

@seandenigris
Copy link
Contributor Author

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

Reported by tudor.girba on 2011-01-19 23:50:55

@seandenigris
Copy link
Contributor Author

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.

Reported by tudor.girba on 2011-01-20 10:15:21

  • Labels added: Milestone-4.3

@seandenigris
Copy link
Contributor Author

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?

Reported by andrehoraa on 2011-01-20 11:03:02

@seandenigris
Copy link
Contributor Author

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

Reported by tudor.girba on 2011-01-20 11:16:26

@seandenigris
Copy link
Contributor Author

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

Reported by andrehoraa on 2011-01-20 14:18:46

@seandenigris
Copy link
Contributor Author

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

Reported by andrehoraa on 2011-02-07 15:08:57

  • Status changed: Fixed

@seandenigris
Copy link
Contributor Author

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.

Reported by tudor.girba on 2011-02-09 14:38:03

  • Status changed: Started

@seandenigris
Copy link
Contributor Author

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

Reported by andrehoraa on 2011-02-09 15:20:06

@seandenigris
Copy link
Contributor Author

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

Reported by tudor.girba on 2011-02-10 08:32:41

  • Status changed: Fixed

@seandenigris
Copy link
Contributor Author

Yes, I saw :). Thanks!

Reported by andrehoraa on 2011-02-10 08:35:25

@seandenigris
Copy link
Contributor Author

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()); 
  } 
}

Reported by tudor.girba on 2011-02-10 08:54:52

  • Status changed: Started

@seandenigris
Copy link
Contributor Author

Now I introduced ParameterType that has as container the ParameterizableClass.

Reported by tudor.girba on 2011-02-13 17:14:57

@seandenigris
Copy link
Contributor Author

The current solution is reasonable. I mark it as fixed.

Reported by tudor.girba on 2011-02-16 12:06:24

  • Status changed: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant