Type Refactoring

I thought, the latest builds of IDEA contain the ability to change the type
of a local variable, field or parameter within its valid bounds (like with
the Type Refactoring plug-in) and even be able to replace array with lists
and visa versa. Where can I find this feature in #8769?

Tom

12 comments
Comment actions Permalink

Hello Tom,

I thought, the latest builds of IDEA contain the ability to change the
type of a local variable, field or parameter within its valid bounds
(like with the Type Refactoring plug-in) and even be able to replace
array with lists and visa versa. Where can I find this feature in
#8769?


Ctrl-Shift-F6 (Type Migration)

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hello Tom,

Type Migration refactoring can change type of variable, field, parameter,
return value of the method with corresponding dependencies changes. Though
it doesn't suggest you the new type due to this waterflow changes you can
change e.g. integer to string and fix only input values ...

Thank you
-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

I thought, the latest builds of IDEA contain the ability to change the
type of a local variable, field or parameter within its valid bounds
(like with the Type Refactoring plug-in) and even be able to replace
array with lists and visa versa. Where can I find this feature in
#8769?

Tom



0
Comment actions Permalink

Thanks. Maybe I expect something different than you provide, because my
first tests are not successful.

Please take a look at following example:

private void foo() {
final List list = bar(); for (final Object s : list) { System.out.println(s); } } private List bar() { return new ArrayList(); } I try to change the type of variable 'list' and I expect to see at least following type suggestion: Collection preferable following suggestions, too: List extends String> List List> Collection Collection extends String> Collection Collection>]]>

But I don't get ANY suggestion at all! If I still need to guess and type the
new type myself, I could change it in the code directly.

Tom

0
Comment actions Permalink

Hello Tom,

Exactly. As I said this refactoring doesn't check how type may be weakened
but allows to change this type to any new type with conequence changes of
dependant types ...

It is possible to write a "global" inspection: type may be weakened and as
a quickfix use this refactoring. Though there is a problem: where to report
wakeness? On wich type element from the chain of connected types?

Local inspection type may be weakened already present: you may give it a try

Thank you

-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

Thanks. Maybe I expect something different than you provide, because
my first tests are not successful.

Please take a look at following example:

private void foo() {
final List<String> list = bar();
for (final Object s : list) {
System.out.println(s);
}
}
private List<String> bar() {
return new ArrayList<String>();
}
I try to change the type of variable 'list' and I expect to see at
least following type suggestion:

Collection<String>

preferable following suggestions, too:

List<? extends String>
List<Object>
List<?>
Collection<String>
Collection<? extends String>
Collection<Object>
Collection<?>
But I don't get ANY suggestion at all! If I still need to guess and
type the new type myself, I could change it in the code directly.

Tom



0
Comment actions Permalink

OK, in this case it seems I still have to maintain the Type Refactoring
plug-in to get the feature I want.

Just curious: why you always talk about "weaken type"? I want to be free to
change the type to any one within it's valid bounds - not just use a super
class; sometimes also using a subclass could be useful to prepare a refactoring.

Tom

0
Comment actions Permalink

Tom,

may be because most of the time i'd like to weaken type.

Does Type Refactoring analyze types outside of method bounds?

Thank you
-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

OK, in this case it seems I still have to maintain the Type
Refactoring plug-in to get the feature I want.

Just curious: why you always talk about "weaken type"? I want to be
free to change the type to any one within it's valid bounds - not just
use a super class; sometimes also using a subclass could be useful to
prepare a refactoring.

Tom



0
Comment actions Permalink

may be because most of the time i'd like to weaken type.


Most often, yes, but I had a couple of times to use subclasses to prepare
splitting a class hierarchy into two hierarchies.

Does Type Refactoring analyze types outside of method bounds?


If you refer to the plug-in (which was later incorporated into RefactorJ by
Sixth and Red River): it analyzed read and write usages of local variables
and fields, in the latter case of course not limited to the current
method/class. This was to a time where Java 1.4 was up-to-date and generics
not yet available. I did not implemented support for method parameters or
method return values.

Tom

0
Comment actions Permalink

Hello Tom,

I can see only suggestions to weaken type in RefactorJ. Seems that it is
feasible to include these suggestions into Type Migration.

Thank you
-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

>> may be because most of the time i'd like to weaken type.
>>

Most often, yes, but I had a couple of times to use subclasses to
prepare splitting a class hierarchy into two hierarchies.

>> Does Type Refactoring analyze types outside of method bounds?
>>

If you refer to the plug-in (which was later incorporated into
RefactorJ by Sixth and Red River): it analyzed read and write usages
of local variables and fields, in the latter case of course not
limited to the current method/class. This was to a time where Java 1.4
was up-to-date and generics not yet available. I did not implemented
support for method parameters or method return values.

Tom



0
Comment actions Permalink

I can see only suggestions to weaken type in RefactorJ. Seems that it is
feasible to include these suggestions into Type Migration.


Please include all suggestions, not just those to weaken the type. Thanks.

Tom

0
Comment actions Permalink

Hello Tom,

I am going to add quickfix to weaken type inspection - so may be opposite
won't be available soon ...

Sorry

-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

>> I can see only suggestions to weaken type in RefactorJ. Seems that it
>> is feasible to include these suggestions into Type Migration.
>>

Please include all suggestions, not just those to weaken the type.
Thanks.

Tom



0
Comment actions Permalink

Could you add the type suggestions to the Type Migration dialog instead?

Tom

0
Comment actions Permalink

Tom,

Yes, I can.

I am not sure that i'll be able to do it before 8.0 though

-


Anna Kozlova
JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

Could you add the type suggestions to the Type Migration dialog
instead?

Tom



0

Please sign in to leave a comment.