Reputation: 488
In Eclipse IDE, I have a Java method with a lot of nullable parameters
src.myCrazyFunction(year, name, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
I want to call the function with city parameter 'NY'. By the use of Javadoc tooltip, I have to count parameters until "String city" and then:
src.myFunction(year, name, null, null, null, null, null, null, null, null, null, null, 'NY', null, null, null, null, null, null, null, null, null, null, null);
Counting parameters it's really boring each time I have to use this method.
Could I know the name of the parameter where the cursor is? CTRL+SPACE would be for all the parameters...
Upvotes: 2
Views: 1874
Reputation: 9209
Press Parameter Hints / Context Information - Ctrl+Shift+SPACE
Upvotes: 2
Reputation: 159215
As explained by @nos in a comment, pressing ctrl+space
in Eclipse will popup a tooltip that highlights (in bold) the parameter where the cursor is, as illustrated in in image provided by @nos:
However, that still requires IDE support and is relatively cumbersome to use (you have to position cursor and trigger it to use it), so you should consider other means.
No method should take 24 parameters, but if you absolute must, then your should comment all parameter values that are not self-explanatory, e.g. year
and name
are probably explanatory enough, but values like null
, 0
, false
, 42
, true
, etc. does not convey meaning, so you should comment them:
src.myFunction(year,
name,
/*address1*/null,
/*address2*/null,
/*city*/null,
/*state*/"NY",
/*zipcode*/null);
That way a casual observer will know exactly what the values mean.
Another way to do this is to wrap all the parameter values in a POJO and use the builder pattern.
src.myFunction(new MyPojo()
.setYear(year)
.setName(name)
.setState("NY"));
Upvotes: 0
Reputation: 5591
First thing : you should change this method if it's really like that, it's insane. Second, I don't know what you really mean, but in Eclipse when you will type src.
it will show you all the available methods, click on your method and code will be generated with parameter names as arguments (for you to change that). For example if you type "someString".indexOf
and you pick a method it will generate "someString".indexOf(ch, fromIndex)
(those are not variables or anything, those are parameter names specified in indexOf
method declaration, they will give compile-time error if you don't change them). You can see your parameter names, so it's fast to change specific one to NY
, you will still have to write the nulls yourself tho. I hope I understood you correctly.
Upvotes: 1