[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-core-dev] APIs to remove redundant parenthesis

Hi all:

I am using JDT (latest version) to parse Java code in my research project. One particular issue
I met is how to use JDT to remove redundant parentheses. For example:

void rewriteTestConstructorExceptio
0() {
ÂÂÂ ÂÂÂ try {
ÂÂÂ ÂÂÂ ÂÂÂ {ÂÂÂ // r - 1
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ { / r -2
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ new CircularFifoBuffer(0);
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ } //r - 2
ÂÂÂ ÂÂÂ ÂÂÂ } //r-1
ÂÂÂ ÂÂÂ } catch (NullPointerException ex) {
ÂÂÂ ÂÂÂ ÂÂÂ return;
ÂÂÂ ÂÂÂ }
ÂÂÂ }


In the above example, parentheses r-1, r-2 and their corresponding matched ones are redundant.

A desirable output should be:

void rewriteTestConstructorExceptio0() {
ÂÂÂ ÂÂÂ try {
ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂ new CircularFifoBuffer(0);
ÂÂÂ ÂÂÂ } catch (NullPointerException ex) {
ÂÂÂ ÂÂÂ ÂÂÂ return;
ÂÂÂ ÂÂÂ }
ÂÂÂ }



I am wondering could I use JDT to remove some redundant parentheses? either by using
existing implementations in JDT, or writing my owner code (e.g. vistitors). Could any one
kindly give me some hints and comments to do that? or please point some resources
to me.

Any comments are highly appreciated!

--

ÂÂ Â Â Â ÂThanks

ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ Sai