I think this is not supported in Eclipse, but I would like to find each closing bracket of each method I declare and replace it with one more code line before it closes.
I tried to find by regex “public.*\}” or “public[.\s]*\}” but it does not find a single method declaration.
Although some posts declare that Eclipse has multi-line search&replace capabilities, using regular expressions. I think it is not so.
The examples usually given just recognize a specific newline when the regex know where it is expected.
This is possible but not with regexp. Instead, write a small Java program and add
org.eclipse.jdt.core_3*.jarto the classpath. You can find this JAR in theplugins/folder of your Eclipse installation.The JAR contains the Eclipse compiler which has an API to convert Java source to the AST. Iterate over the AST, locale all methods and add the new code using AST nodes. There are methods to turn an AST into a string. Use that to generate the new source code.
If you have no idea how the new AST nodes should look like, add the code to a single method and print the result.
Another alternative would be to use AOP which allows you to wrap methods at runtime.
[EDIT] See the code in
org.eclipse.jdt.internal.corext.refactoring.surround.SurroundWithTryCatchRefactoringfor an example (source on grepcode)