Skip to content

Commit

Permalink
If some variants are deprecated, consider them last.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Apr 19, 2017
1 parent 31a77f6 commit 45ae0fc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion core/src/main/java/org/kohsuke/stapler/ClassDescriptor.java
Expand Up @@ -150,7 +150,17 @@ private List<MethodMirror> findMethods(Class c, java.lang.reflect.Type logical,
Arrays.sort(declaredMethods, new Comparator<Method>() {
@Override
public int compare(Method m1, Method m2) {
return m1.toString().compareTo(m2.toString());
boolean m1d = m1.getAnnotation(Deprecated.class) != null;
boolean m2d = m2.getAnnotation(Deprecated.class) != null;
if (m1d && !m2d) {
// Prefer nondeprecated to deprecated.
return 1;
} else if (!m1d && m2d) {
return -1;
} else {
// Sort by string representation, so for example doFoo() is preferred to doFoo(StaplerRequest, StaplerResponse).
return m1.toString().compareTo(m2.toString());
}
}
});
for (Method m : declaredMethods) {
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/java/org/kohsuke/stapler/DispatcherTest.java
Expand Up @@ -275,10 +275,11 @@ public void testRequirePostOnBase() throws Exception {

public void testOverloads() throws Exception {
TextPage p = new WebClient().getPage(new URL(url, "overloaded/x"));
assertEquals("doX()", p.getContent().trim());
assertEquals("doX(StaplerRequest)", p.getContent().trim());
}
public final Object overloaded = new Overloaded();
public static class Overloaded {
@Deprecated
public HttpResponse doX() {
return HttpResponses.plainText("doX()");
}
Expand Down

0 comments on commit 45ae0fc

Please sign in to comment.