Extract Method - allow multiple return types when they're matching classes

I just tried to extract some code but it was blocked by IDEA due to
having multiple return paths. However, I think this limitation should
be relaxed in the cases were each return path returns a consistent type
(and using the super-most, or interface class as the return).

In the example, the return types are PsiClass and null. null should be
allowed as it is a valid return type. IDEA could also intelligently (if
told to do so) add the @Nullable annotation to the extracted method.

Thoughts? I've entered this in JIRA as IDEA-6537 along with the snippet
of code I was using:

http://jetbrains.net/jira/browse/IDEA-6537

Mark

2 comments

In article <drk7u4$n05$2@is.intellij.net>, mark@talios.com says...

I just tried to extract some code but it was blocked by IDEA due to
having multiple return paths. However, I think this limitation should
be relaxed in the cases were each return path returns a consistent type
(and using the super-most, or interface class as the return).

In the example, the return types are PsiClass and null. null should be
allowed as it is a valid return type. IDEA could also intelligently (if
told to do so) add the @Nullable annotation to the extracted method.

Thoughts? I've entered this in JIRA as IDEA-6537 along with the snippet
of code I was using:

http://jetbrains.net/jira/browse/IDEA-6537

Mark

I prefer having methods with only one return path. As long as I can turn
that off, shrug.
--
-


David H. McCoy


-


0

David H. McCoy wrote on 31/01/06 14:48:

I prefer having methods with only one return path. As long as I can turn
that off, shrug.


True, in this particular instance, the 4 lines were repeated 4-5 times
and came up as part of a duplicate search, the only difference being one
variable. So extracting the duplicate made sense.

But yeh - optional is good.

0

Please sign in to leave a comment.