score:0
do it with a regular expression and verify it.
i'm assuming that each call to somemethod
spans only one line. if not this method is still useful but slower.
copy the original file.
use ctrl+alt+h to show the callers of somemethod
and get a count of them.
do regex search and replaces restricted to the proper area :
find : somemethod(somefield,([ ]*constant_[0-9]+)[ ]*,[ ]*true[ ]*)[ ]*;
replace : doitwith("$1");
find : somemethod(somefield,([ ]*constant_[0-9]+)[ ]*,[ ]*false[ ]*)[ ]*;
replace : doitnotwith("$1");
make a diff of the original file and the new file showing only the lines of the original file which have changed.
diff --changed-group-format='%<' --unchanged-group-format='' original.java refactored.java | wc
you should get the same number of lines as you got in the callers of somemethod.
if the calls to somemethod are multiline, or if you want greater verification, just drop | wc
to see the lines which were modified in the original file to ensure that only the correct lines have been modified.
score:0
alas i know nothing in eclipse that allows to do this today. this is something i would like to achieve one day in autorefactor: https://github.com/jnrouvignac/autorefactor/issues/8
however the road to get there is quite long.
the only ways i know today are to extract local variables then extract method (as you suggested) or use regexes (as somebody else suggested).
score:1
i don't know of any utility that would do this directly.
i think using a regular expression is the only to go. first, you will need to create the two target methods doitwith
and doitnotwith
. then, you can highlight the contents of the method contentofsomemethods
, hit ctrl+f, and use the following regular expressions:
find:
somemethod\(somefield, (\w*), true\);
replace with:doitwith(\1);
and then
find:
somemethod\(somefield, (\w*), false\);
replace with:doitnotwith(\1);
be sure to check "regular expressions" and "selected lines". here's a picture of it:
the regular expressions match the constant that is used inside the function call with (\w*)
and then it is used during the replacement with \1
. using this regular expression only on the selected lines minimizes the chance of breaking unrelated code.
Source: stackoverflow.com
Related Query
- How to extract a method in eclipse that converts a field or constant value to a parameter
- How do I modify the set method signature that Eclipse auto generates?
- How to display all methods that are called within a specific method in Eclipse Java?
- How to set Run Configuration and Debug Configuration in Eclipse to choose the class that has the main method as the start-up class?
- How can I use Extract Method on code that has different constants?
- eclipse : How can I change method signature with change return value too
- How to change the value of ${user} variable used in Eclipse templates
- How do I configure the proxy settings so that Eclipse can download new plugins?
- shortcut : how to get eclipse to go to the ONLY implementation of an interface's method
- How to exclude a folder that is producing warnings/errors in an Eclipse project?
- How to achieve that Eclipse clean and build (aka rebuild)?
- How to see from where a public method is called in Eclipse using Java?
- Android NDK debugging in Eclipse - how to stop segfaults/SIGILL that only occur when stepping in native code
- ctrl-click goes to the declaration of the method I clicked. For interfaces with one implementation, how can I just directly go to that implementation?
- How do I search files in Eclipse so the results shows files that do NOT contain the search term?
- How can I get Eclipse to index an entire C/C++ source tree that contains multiple "make projects"?
- How to search for a method name in Eclipse
- How to fix a workspace in eclipse that does not open anymore?
- How to set JVM arguments in tomcat that work both in eclipse and using the startup.bat
- Eclipse shortcut to find all children class that override a method
- How to get Eclipse to jump to failed JUnit test when test is not a Java method
- How to generate return value type and variable assignment in Eclipse java editor?
- How can I look at the current environmental variables that eclipse IDE is using?
- How to avoid Eclipse importing a class when putting the class name in the comments, so that checkstyle does not complain later?
- Generate local variable to receive the return value of a method eclipse
- How to configure Eclipse formatter to not insert blank line between field declarations?
- How to get back a file that was excluded from a build configuration in Eclipse CDT?
- How do I get the current method from the active Eclipse editor?
- How to recover Java file from Eclipse Project that damaged by getting power off?
- How to force Eclipse to restart an app that has not changed
More Query from same tag
- How do I sign an Android APK which was built with PhoneGap Build?
- Eclipse PDT, how do I get the files on the server?
- Two gui windows pop up instead of one
- Eclipse import from git not recognizing source folders
- why didn't my g++ and gcc version get upgraded?
- Automatic update of generated css files via m2e
- Getting specific object of JSON object(XML type)
- Eclipse svn file scheduled for addition, but is missing
- Message: 'chromedriver' executable needs to be in PATH
- Classpath in Eclipse Vs IntelliJ
- Eclipse: UTF-8 encoding not shown correctly in Texlipse editor
- How to run maven project in eclipse
- java.lang.OutOfMemoryError: GC overhead limit exceeded evenif if with -Xms1024M -Xmx2048M
- Multiple IDE debugging in Eclipse
- Phonegap Geolocation doesn't show coordinates
- Android custom keyboard xml file
- GWT-JRE-Emulated classes aware Eclipse?
- Eclipse Update folders to HEAD Automatically
- Parse console output to make error messages link to source code (similar to quickfix lists in vim)
- In Eclipse where to add an external library for a Contextlistener?
- Angular js plugin not showing up in eclipse
- Eclipse Scala IDE: can't open hierarchy for standard library classes
- Line numbers not updating on 2nd monitor - Eclipse STS 2.8.1RELEASE - OS X Lion
- Deploy same eclipse project with different property files to 2 different apache tomcats
- Eclipse error create android app:Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'
- Net-SNMP returns HexString and then just String (Eclipse and Pydev)
- JAR File is Viewed as Folder
- Short cut key for Navigation from one file to another file in eclipse?
- Eclipse not publishing to Apache 6.0.32 - Could not publish to the server
- Android Eclipse- Downloading an image from a URL to storage on phone