-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
fix: cleaning of method signature computation #1561
Conversation
need #1562 first in order to strengthen the test case |
how can client choose that? I see that return value is actually not printed only if it is undefined. What about new method |
What about new method |getSignature(boolean includingReturnType)|?
I'm not in favor of this kind of dual-behavior method because there are hard to test, maintain and
understand.
Or an global switch or hook which let's client register own signature printer (it is probably
over-engineered?)
Interesting. That's an option for a future PR.
|
I looked at gumtree-spoon-ast-diff project today and the labels for nodes of methods are made using method.getSignature(). This PR will may be break this algorithm, because in this case it was correct to ignore type of returned value. Will there be an easy way to generate method signature without return type, which may be different and is really not relevant in many cases? |
I looked at gumtree-spoon-ast-diff project today and the labels for nodes of methods are made
using method.getSignature(). This PR will may be break this algorithm, because in this case it was
correct to ignore type of returned value.
I'm not sure. It may do the opposite: make it work better :-)
I've just started Travis with a signature without the return type to see what tests are broken ...
or not.
|
43d7cef
to
ac737f5
Compare
It seems to be doable to remove the return type from the signature. |
ImportTest.testWithInnerEnumDoesNotImportStaticInnerMethods is also in fact easy to fix. So it seems we can go for a getSignature without return type. WDYT? |
I can imagine that some clients will want to see return type and some wont ... Anyway I agree that this PR makes sense and Spoon should print signatures more consistent then till now. So I agree that your PR is a good way! |
when #1562 is merged, I'll improve the test, and then if everybody's OK, we'll proceed then. |
ready for review |
@@ -448,7 +448,9 @@ protected boolean addMethodImport(CtExecutableReference ref) { | |||
protected boolean isImportedInMethodImports(CtExecutableReference<?> ref) { | |||
if (!(ref.isImplicit()) && methodImports.containsKey(ref.getSimpleName())) { | |||
CtExecutableReference<?> exist = methodImports.get(ref.getSimpleName()); | |||
if (exist.getSignature().equals(ref.getSignature())) { | |||
if ((exist.getDeclaringType() != null ? exist.getDeclaringType().getQualifiedName() : "" + "." + exist.getSignature()).equals( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add brackets around (x?y:z)
, so the precedence of operators is clear even for me ;-)
Or better to create private (or public?) method `getQualifiedSignature()'
private static String getShortSignatureForJavadoc(CtExecutableReference<?> ref) { | ||
SignaturePrinter sp = new SignaturePrinter(); | ||
sp.writeNameAndParameters(ref); | ||
return ref.getDeclaringType().getSimpleName() + CtExecutable.EXECUTABLE_SEPARATOR + sp.getSignature(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about new public class MethodSignatureHelper
, which would implement
- getSignature(...)
- getJavaDocSignature(...)
- getQualifiedSignature(...)
- .,. ?
@@ -38,6 +36,8 @@ | |||
|
|||
private final StringBuffer signature = new StringBuffer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about faster StringBuilder
?
@@ -686,7 +686,7 @@ public void testSnippedWithComments(){ | |||
assertTrue(clazz1==builder.getSnippetCompilationUnit().getDeclaredTypes().get(0)); | |||
|
|||
CtMethod<?> methodString = (CtMethod<?>) clazz1.getMethods().toArray()[0]; | |||
assertEquals("java.io.File foo(java.lang.String)", methodString.getSignature()); | |||
assertEquals("foo", methodString.getSimpleName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? methodString.getSignature() fails here?
This implementation is OK for me. The comments above are optional. |
That could be interesting, yes.
|
thanks, changed. |
Thank You Martin for this fix! |
We have problems regarding method signatures:
This PR fixes 1) and makes a sensible choice for 2)
Fix #1483