how to tell 2 methods are override-equivalent

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

how to tell 2 methods are override-equivalent

Hamlin Li

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin

Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Vicente Romero-2
Hi Hamlin,

How do you obtain m2? I mean at some point it should have been obtained from an executable element or similar. In the worst case you can always generate a simple test case and try to compile it for example:

class Test {
    void getContent(java.lang.Class<?>[] c) {}
    void getContent(java.lang.Class[] c) {}
}

this one will fail saying that both methods have the same erasure,

HTH,
Vicente

On 03/16/2017 11:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin


Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Hamlin Li

Hi Vicente,

Thank you for responding, please check the comments inline.

On 2017/3/17 21:08, Vicente Romero wrote:
Hi Hamlin,

How do you obtain m2? I mean at some point it should have been obtained from an executable element or similar.
I have a java doclet which scans jdk versions iteratively, m2 was got in previous round of run of the tool , then it's stored in a file (for example when scan jdk 1.8 source code), then parsed and retrieved from the file again (for example when scan jdk 9 source code).
In the worst case you can always generate a simple test case and try to compile it for example:

class Test {
    void getContent(java.lang.Class<?>[] c) {}
    void getContent(java.lang.Class[] c) {}
}

this one will fail saying that both methods have the same erasure,
Yes, it should fail.
In my situation, "getContent(java.lang.Class[] c) {}" is the code in jdk 1.8, "getContent(java.lang.Class<?>[] c) {}" is the corresponding code in jdk 9. When I scan jdk 9 source code, I need to tell that getContent(java.lang.Class<?>[] c) and getContent(java.lang.Class[] c) are in fact the same method, rather than 2 different methods.

Thank you
-Hamlin

HTH,
Vicente

On 03/16/2017 11:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin



Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Jonathan Gibbons
In reply to this post by Hamlin Li

Hamlin,

Use Element.asType() to move from the Element world to the TypeMirror world.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/element/Element.html#asType--

Use Types.asElement(TypeMirror) to go in the reverse direction, from a TypeMirror to an Element.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/util/Types.html#asElement-javax.lang.model.type.TypeMirror-
but note the reverse direction is lossy and may throw exceptions:
    e.g. for type "int", there is no direct element equivalent;  for type List<String>, the element will be the declaration List<T>
       
-- Jon

On 3/16/17 8:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin


Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Martin Buchholz-3
In reply to this post by Hamlin Li
My ancient script findMissingSince examined the generated javadoc for various jdk revisions and parsed the resulting html via regexes (despite http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags).

Whether using hacky regexes or "proper" tools aware of the java language, there is a need to compare method signatures.  Erasure-equivalent methods are the "same" method.

(As always, it would be nice if the resulting code were available to anyone.)


On Sun, Mar 19, 2017 at 7:13 PM, Hamlin Li <[hidden email]> wrote:

Hi Vicente,

Thank you for responding, please check the comments inline.

On 2017/3/17 21:08, Vicente Romero wrote:
Hi Hamlin,

How do you obtain m2? I mean at some point it should have been obtained from an executable element or similar.
I have a java doclet which scans jdk versions iteratively, m2 was got in previous round of run of the tool , then it's stored in a file (for example when scan jdk 1.8 source code), then parsed and retrieved from the file again (for example when scan jdk 9 source code).
In the worst case you can always generate a simple test case and try to compile it for example:

class Test {
    void getContent(java.lang.Class<?>[] c) {}
    void getContent(java.lang.Class[] c) {}
}

this one will fail saying that both methods have the same erasure,
Yes, it should fail.
In my situation, "getContent(java.lang.Class[] c) {}" is the code in jdk 1.8, "getContent(java.lang.Class<?>[] c) {}" is the corresponding code in jdk 9. When I scan jdk 9 source code, I need to tell that getContent(java.lang.Class<?>[] c) and getContent(java.lang.Class[] c) are in fact the same method, rather than 2 different methods.

Thank you
-Hamlin


HTH,
Vicente

On 03/16/2017 11:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin




Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Jonathan Gibbons
In reply to this post by Jonathan Gibbons
Hamlin,

Note that while it is relative easy to convert a string containing a type name (such as "java.net.URL") to an Element and/or TypeMirror, in general it will not be possible to convert a string like "getContent(java.lang.Class[])" to a Element or TypeMirror, because the string as written does not contain sufficient information.

Even if you did provide more info, you would still have to be careful to evaluate the string in the same compilation context as that to which you are comparing it, for the comparison to have any chance of succeeding. Given your other message mentioning a doclet, you are effectively asking to be able to compile fragments of code (i.e. strings) in the context of your doclet, and that is not possible with the existing public API.

-- Jon

On 03/21/2017 02:28 PM, Jonathan Gibbons wrote:

Hamlin,

Use Element.asType() to move from the Element world to the TypeMirror world.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/element/Element.html#asType--

Use Types.asElement(TypeMirror) to go in the reverse direction, from a TypeMirror to an Element.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/util/Types.html#asElement-javax.lang.model.type.TypeMirror-
but note the reverse direction is lossy and may throw exceptions:
    e.g. for type "int", there is no direct element equivalent;  for type List<String>, the element will be the declaration List<T>
       
-- Jon

On 3/16/17 8:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin



Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Hamlin Li

On 2017/3/22 8:50, Jonathan Gibbons wrote:
Hamlin,

Note that while it is relative easy to convert a string containing a type name (such as "java.net.URL") to an Element and/or TypeMirror, in general it will not be possible to convert a string like "getContent(java.lang.Class[])" to a Element or TypeMirror, because the string as written does not contain sufficient information.

Even if you did provide more info, you would still have to be careful to evaluate the string in the same compilation context as that to which you are comparing it, for the comparison to have any chance of succeeding.
Hi Jon,

Thank you for explanation.
Given your other message mentioning a doclet, you are effectively asking to be able to compile fragments of code (i.e. strings) in the context of your doclet, and that is not possible with the existing public API.
Although it's bad news to me, it saves my time from continuing work in this direction. :-)
I will try to find some workaround solve the issue.

Thank you
-Hamlin
-- Jon

On 03/21/2017 02:28 PM, Jonathan Gibbons wrote:

Hamlin,

Use Element.asType() to move from the Element world to the TypeMirror world.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/element/Element.html#asType--

Use Types.asElement(TypeMirror) to go in the reverse direction, from a TypeMirror to an Element.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/util/Types.html#asElement-javax.lang.model.type.TypeMirror-
but note the reverse direction is lossy and may throw exceptions:
    e.g. for type "int", there is no direct element equivalent;  for type List<String>, the element will be the declaration List<T>
       
-- Jon

On 3/16/17 8:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin




Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Hamlin Li
In reply to this post by Martin Buchholz-3
Hi Martin,

On 2017/3/22 5:50, Martin Buchholz wrote:
My ancient script findMissingSince examined the generated javadoc for various jdk revisions and parsed the resulting html via regexes (despite http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags).
Thank you for the information.
I find some information about findMissingSince at https://bugs.openjdk.java.net/browse/JDK-6367207, but can not find the valid code.

Whether using hacky regexes or "proper" tools aware of the java language, there is a need to compare method signatures.  Erasure-equivalent methods are the "same" method.
Agree, it's the issue I'm trying to resolve.

(As always, it would be nice if the resulting code were available to anyone.)
Agree, I will try to open it when it's good time.
For now, it's not mature enough, there are some issues to solve, enhancements to do, and the design/implementation is specific for jdk.
When the functionality is ready, I will discuss with stakeholders and management about it.

Thank you
-Hamlin


On Sun, Mar 19, 2017 at 7:13 PM, Hamlin Li <[hidden email]> wrote:

Hi Vicente,

Thank you for responding, please check the comments inline.

On 2017/3/17 21:08, Vicente Romero wrote:
Hi Hamlin,

How do you obtain m2? I mean at some point it should have been obtained from an executable element or similar.
I have a java doclet which scans jdk versions iteratively, m2 was got in previous round of run of the tool , then it's stored in a file (for example when scan jdk 1.8 source code), then parsed and retrieved from the file again (for example when scan jdk 9 source code).
In the worst case you can always generate a simple test case and try to compile it for example:

class Test {
    void getContent(java.lang.Class<?>[] c) {}
    void getContent(java.lang.Class[] c) {}
}

this one will fail saying that both methods have the same erasure,
Yes, it should fail.
In my situation, "getContent(java.lang.Class[] c) {}" is the code in jdk 1.8, "getContent(java.lang.Class<?>[] c) {}" is the corresponding code in jdk 9. When I scan jdk 9 source code, I need to tell that getContent(java.lang.Class<?>[] c) and getContent(java.lang.Class[] c) are in fact the same method, rather than 2 different methods.

Thank you
-Hamlin


HTH,
Vicente

On 03/16/2017 11:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin





Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Vicente Romero-2
In reply to this post by Hamlin Li
Hi Hamlin

On 03/22/2017 04:57 AM, Hamlin Li wrote:

On 2017/3/22 8:50, Jonathan Gibbons wrote:
Hamlin,

Note that while it is relative easy to convert a string containing a type name (such as "java.net.URL") to an Element and/or TypeMirror, in general it will not be possible to convert a string like "getContent(java.lang.Class[])" to a Element or TypeMirror, because the string as written does not contain sufficient information.

Even if you did provide more info, you would still have to be careful to evaluate the string in the same compilation context as that to which you are comparing it, for the comparison to have any chance of succeeding.
Hi Jon,

Thank you for explanation.
Given your other message mentioning a doclet, you are effectively asking to be able to compile fragments of code (i.e. strings) in the context of your doclet, and that is not possible with the existing public API.
Although it's bad news to me, it saves my time from continuing work in this direction. :-)
I will try to find some workaround solve the issue.

If you have access to the method's descriptor, I believe that you could use it to convert from the method descriptor to the types you need for your comparison, please let me know if you want to explore that option,

Vicente


Thank you
-Hamlin
-- Jon

On 03/21/2017 02:28 PM, Jonathan Gibbons wrote:

Hamlin,

Use Element.asType() to move from the Element world to the TypeMirror world.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/element/Element.html#asType--

Use Types.asElement(TypeMirror) to go in the reverse direction, from a TypeMirror to an Element.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/util/Types.html#asElement-javax.lang.model.type.TypeMirror-
but note the reverse direction is lossy and may throw exceptions:
    e.g. for type "int", there is no direct element equivalent;  for type List<String>, the element will be the declaration List<T>
       
-- Jon

On 3/16/17 8:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin





Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Hamlin Li



On 2017/3/22 22:01, Vicente Romero wrote:
Hi Hamlin

On 03/22/2017 04:57 AM, Hamlin Li wrote:

On 2017/3/22 8:50, Jonathan Gibbons wrote:
Hamlin,

Note that while it is relative easy to convert a string containing a type name (such as "java.net.URL") to an Element and/or TypeMirror, in general it will not be possible to convert a string like "getContent(java.lang.Class[])" to a Element or TypeMirror, because the string as written does not contain sufficient information.

Even if you did provide more info, you would still have to be careful to evaluate the string in the same compilation context as that to which you are comparing it, for the comparison to have any chance of succeeding.
Hi Jon,

Thank you for explanation.
Given your other message mentioning a doclet, you are effectively asking to be able to compile fragments of code (i.e. strings) in the context of your doclet, and that is not possible with the existing public API.
Although it's bad news to me, it saves my time from continuing work in this direction. :-)
I will try to find some workaround solve the issue.

If you have access to the method's descriptor, I believe that you could use it to convert from the method descriptor to the types you need for your comparison, please let me know if you want to explore that option,
Hi Vicente,

I'd like to try your option. But sorry, I'm a little bit confused, do you mean if I have a string representing the method's descriptor then the method descriptor can be converted into a valid ExecutableElement instance which can be used to compare with another one by Elements.overrides(ExecutableElement, ExecutableElement, TypeElement)?

Thank you
-Hamlin

Vicente


Thank you
-Hamlin
-- Jon

On 03/21/2017 02:28 PM, Jonathan Gibbons wrote:

Hamlin,

Use Element.asType() to move from the Element world to the TypeMirror world.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/element/Element.html#asType--

Use Types.asElement(TypeMirror) to go in the reverse direction, from a TypeMirror to an Element.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/util/Types.html#asElement-javax.lang.model.type.TypeMirror-
but note the reverse direction is lossy and may throw exceptions:
    e.g. for type "int", there is no direct element equivalent;  for type List<String>, the element will be the declaration List<T>
       
-- Jon

On 3/16/17 8:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin






Reply | Threaded
Open this post in threaded view
|

Re: how to tell 2 methods are override-equivalent

Vicente Romero-2


On 03/24/2017 05:21 AM, Hamlin Li wrote:



On 2017/3/22 22:01, Vicente Romero wrote:
Hi Hamlin

On 03/22/2017 04:57 AM, Hamlin Li wrote:

On 2017/3/22 8:50, Jonathan Gibbons wrote:
Hamlin,

Note that while it is relative easy to convert a string containing a type name (such as "java.net.URL") to an Element and/or TypeMirror, in general it will not be possible to convert a string like "getContent(java.lang.Class[])" to a Element or TypeMirror, because the string as written does not contain sufficient information.

Even if you did provide more info, you would still have to be careful to evaluate the string in the same compilation context as that to which you are comparing it, for the comparison to have any chance of succeeding.
Hi Jon,

Thank you for explanation.
Given your other message mentioning a doclet, you are effectively asking to be able to compile fragments of code (i.e. strings) in the context of your doclet, and that is not possible with the existing public API.
Although it's bad news to me, it saves my time from continuing work in this direction. :-)
I will try to find some workaround solve the issue.

If you have access to the method's descriptor, I believe that you could use it to convert from the method descriptor to the types you need for your comparison, please let me know if you want to explore that option,
Hi Vicente,

I'd like to try your option. But sorry, I'm a little bit confused, do you mean if I have a string representing the method's descriptor then the method descriptor can be converted into a valid ExecutableElement instance which can be used to compare with another one by Elements.overrides(ExecutableElement, ExecutableElement, TypeElement)?

correct that's what I meant,


Thank you
-Hamlin

Vicente


Vicente


Thank you
-Hamlin
-- Jon

On 03/21/2017 02:28 PM, Jonathan Gibbons wrote:

Hamlin,

Use Element.asType() to move from the Element world to the TypeMirror world.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/element/Element.html#asType--

Use Types.asElement(TypeMirror) to go in the reverse direction, from a TypeMirror to an Element.
http://download.java.net/java/jdk9/docs/api/javax/lang/model/util/Types.html#asElement-javax.lang.model.type.TypeMirror-
but note the reverse direction is lossy and may throw exceptions:
    e.g. for type "int", there is no direct element equivalent;  for type List<String>, the element will be the declaration List<T>
       
-- Jon

On 3/16/17 8:15 PM, Hamlin Li wrote:

Hi,

( I'm not sure if this is the right alias to ask the question, please help forward if necessary. )

I have a question about telling whether one method is subsignature of another one. My situation is,

1. there is a TypeElement t1 which represents java.net.URL, and a ExecutableElement m1 which represents getContent(java.lang.Class<?>[]),

2. there is a String t2 which is "java.net.URL", and another String m2 which is "getContent(java.lang.Class[])".

The difference between m1 and m2 is that, m1 is an instance of ExecutableElement, m2 is an instance of String; there is a wildcard type argument in m1.


Is there a way to tell whether m1 and m2 are override-equivalent, m2 is subsignature of m1?

I suppose I should use javax.lang.model.util.Types.isSubsignature(ExecutableType m1, ExecutableType m2), but I don't know how can I convert ExecutableElement m1 and String m2 to ExecutableType.

Or I'm in wrong direction?


Thank you

-Hamlin