Need "Create method"

If I have a Java class like JavaTestClass shown below, the editor shows
the call to "bob" in red and offers me the option to "Create method
'bob()'". Now I realize that in Scala it's a little trickier because a
method call doesn't necessarily have parenthesis and so can look like a
field reference - but still, the IDE could offer us a choice of possible
remedies.

package some.package;

public class JavaTestClass
{
     public void testMethod() {
         bob();
     }
}

0
10 comments

+100

the choices should be:
create private/protected (if i want to create the method in my superclass - this one could also be added to the java suggestions)  method inside current class
create public/protected method in target class
and the same for fields

0

Realistically, you have to offer ever scope in which the definition would be visible, including inner methods, companion methods etc. And owing to the uniform access principle, you have to offer creating val, var or def when the name is not followed by an open parenthesis.

The other issue that makes this feature not yet feasible is the absence of a reliable determination that a given name has no visible defintiion.

Personally, I'm OK with writing my own code...


Randall Schulz

0

in 70% of my cases, "create public method in target class" would be what i want. about 10% are "create field", and the rest would be the nasty stuff you mentioned. a 100%-solution would be about 10x more complex than the simple one, and if i had to choose between nothing, the low budget solution in a month or the full solution in about 2 years, i'd pick the low budget solution. it'd be far from perfect, but it would speed things up greatly.

0

If JetBrains had more resources to devote to the Scala plug-in, I wouldn't mind them doing things like this, but since I think of it as catering to a style of programming characterized by an lack of planning and design, I'm not in favor of giving it a high priority. I've never used it when using IDEA for Java programming and I don't antipicate using it for Scala.


Randall Schulz

0

i think you misunderstood. imagine coding in a test-first manner. you create a test and begin to type:
val x = new Something() <- alt+enter to create the class
x.createFoo("someParam") <- alt+enter to create the method, then jump back via ctrl+alt+left, then extract a local variable. on the result, you do:
assertTrue(fooFromX.someField) <- alt+enter on the field to create it in the result class.

it's possible with any of the top 3 java ides, and this is just the way i prefer to code. i jump around a lot and follow the execution path. many of my co-workers do it the same way. it's not that i don't know what method will be put where, it's just that i'm a lot faster this way. i am focused on what is the next step right now and "follow the flow". without this feature, i have to add a lot of manual jumping and/or code in the reverse direction (inside -> out instead of outside -> inside)

0

I understand perfectly well. I also do not subscribe to "test-first" coding.


Ranall Schulz

0

i think we can agree on this: afaik jetbrains has statistics about which feature is used how often. if it is used like crazy, then it should be implemented. if not, then not.

0

Statistics on use of an unimplememented feature?

In any event, I'm not JetBrains. I advocate only for my own interests and needs. I continue to object to the use of limited developer resources on what I deem ill-considered features.

So no, I don't think we agree on this.


Randall Schulz

0

it's implemented for java

0

These QuickFixes are typically referred to as "Create From Usage" fixes.

I assume that they will be provided, once more critical pieces (like type system, performance, error highlighting) have progressed.

0

Please sign in to leave a comment.