Hi Nicolas,

thank you for your answer and explanation.
I would have hoped that generic methods would be expressed similar to generic types/classes.

But "binding" the generic Types like TValue to the method seem to make sense and it is consistent to the way generic classes are handled in InFamix, e.g:

(FAMIX.ParameterizableClass (id: 154)
    (sourceAnchor (ref: 784753))
    (isStub true)
    (parentPackage (ref: 5))
    (name 'HashMap')
)

(FAMIX.ParameterType (id: 155)
    (name 'K')
    (container (ref: 154))
)

But how do you handle concrete usages of the generic method like
ClassWithGenericMethod.useTheGeneric("hi generic method");  // type inference
        ClassWithGenericMethod.useTheGeneric(1.5d);  // type inference
       
InFamix generates the following:
(FAMIX.Invocation
    (sender (ref: 19))
    (candidates (ref: 25))
    (signature 'useTheGeneric(_unknown_path::TValue)')
)

(FAMIX.Invocation
    (sender (ref: 19))
    (candidates (ref: 25))
    (signature 'useTheGeneric(_unknown_path::TValue)')
)

based on the source code. It does not "detect" the concrete types. If you would parse compiled code this might change...
 

Thanks once again for your feedback!
Thomas

Hi Thomas,

sorry I did not spot this email earlier.

Here's what I get with VerveineJ:

    (FAMIX.Method (id: 58)
        (name 'getTheGeneric')
        (cyclomaticComplexity 1)
        (declaredType (ref: 28))
        (hasClassScope true)
        (modifiers 'public')
        (numberOfStatements 1)
        (parentType (ref: 17))
        (signature 'getTheGeneric(String)')
        (sourceAnchor (ref: 57)))
    (FAMIX.Type (id: 28)
        (name 'TResult')
        (container (ref: 58))
        (isStub true))

so TResult is simply a type defined by the method getTheGeneric.
Same goes for TValue
There is nothing special marking them as "VariableTypes"

    (FAMIX.Method (id: 34)
        (name 'useTheGeneric')
        (cyclomaticComplexity 1)
        (declaredType (ref: 50))
        (hasClassScope true)
        (modifiers 'public')
        (numberOfStatements 2)
        (parentType (ref: 17))
        (signature 'useTheGeneric(TValue)')
        (sourceAnchor (ref: 37)))
    (FAMIX.Parameter (id: 36)
        (name 'value')
        (declaredType (ref: 14))
        (parentBehaviouralEntity (ref: 34)))
    (FAMIX.Type (id: 14)
        (name 'TValue')
        (container (ref: 34))
        (isStub true))


nicolas

PS: I see that verveineJ treat them as stubs.
I am not sure whether this is right. It should probably not ...


On 18/09/2014 20:52, Thomas Haug wrote:
Hi everybody,

I hope my question is not off topic:
I am currently trying to figure out how to describe generic methods in Famix 3.0 (for the .NET FamixGenerator)
 For example in Java you can write the following code.
public class ClassWithGenericMethod {
    public static  <TResult> TResult getTheGeneric(String resource) {
	return null;
    }
    
    public static  <TValue> void useTheGeneric(TValue value) {
        System.out.println("value '"+value +"' type: "+value.getClass());
    }

If I run InFamix on this code I get an Famix file containing something like:

1 method:
(FAMIX.Method (id: 24)
	(sourceAnchor (ref: 60))
	(parentType (ref: 30))
	(declaredType (ref: 33))
	(name 'getTheGeneric')
	(signature 'getTheGeneric(_unknown_path::String)')
	(hasClassScope true)
	(isPublic true)
	(isPureAccessor true)
	(ATFD 0.00)
	(ALD 0.00)
	(CYCLO 1.00)
	(DR 0.00)
	(ICDO 1.00)
	(ICIO 1.00)
	(LOC 3.00)
	(LOCOMM 1.00)
	(LDA 1.00)
	(MAXNESTING 1.00)
	(NOAV 0.00)
	(NOOC 0.00)
	(NOPAR 1.00)
	(OCDO 0.00)
	(OCIO 0.00)
)

But id 33 is not existing.


2 method:
(FAMIX.Method (id: 25)
	(sourceAnchor (ref: 61))
	(parentType (ref: 30))
	(declaredType (ref: 28))
	(name 'useTheGeneric')
	(signature 'useTheGeneric(_unknown_path::TValue)')
	(hasClassScope true)
	(isPublic true)
	(ATFD 0.00)
	(ALD 0.00)
	(CYCLO 1.00)
	(DR 0.00)
	(ICDO 1.00)
	(ICIO 1.00)
	(LOC 3.00)
	(LOCOMM 1.00)
	(LDA 1.00)
	(MAXNESTING 1.00)
	(NOAV 2.00)
	(NOOC 2.00)
	(NOPAR 1.00)
	(OCDO 0.00)
	(OCIO 0.00)
)

(FAMIX.Parameter (id: 35)
	(name 'value')
	(parentBehaviouralEntity (ref: 25))
	(declaredType (ref: 36))
	(position 0)
)

But id 36 is not existing.


I am wondering if there should be something like ParameterizableMethod (like ParameterizableClass?

Can anybody give me some clues?


Thank you very much
Thomas


-----------
Thomas Haug

Principal Consultant

MATHEMA Software GmbH

Anschrift:
  Henkestraße 91
  91052 E r l a n g e n
Telefon:
  09131/8903- 0
Telefax:
  09131/8903-55
E-Mail:
  thomas.haug@mathema.de
Internet:
  http://www.mathema.de
Handelsregister:
  HR B 8965, Fürth/Bayern
Geschäftsführer:
  Michael Wiedeking
  Andreas Hanke




_______________________________________________
Moose-dev mailing list
Moose-dev@iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev


_______________________________________________
Moose-dev mailing list
Moose-dev@iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev