2013-04-15 32 views
-1

假設我有很多的變量有沒有一種快速的方式來適應變量的功能?

String not_id, not_section, not_steet, not_sqTotal, not_sqLiving, not_sqKitchen, not_flat, not_floor, not_floors, not_text, user_phone1, user_phone2, user_contact, not_region, not_district, not_settle, not_price, not_photo, not_date, not_date_till, not_up, not_premium, not_status; 

not_id= not_section= not_steet= not_sqTotal= not_sqLiving= 
       not_sqKitchen= not_flat= not_floor= not_floors= not_text= 
       user_phone1= user_phone2= user_contact= not_region= not_district= 
       not_settle= not_price= not_photo= not_date= not_date_till= not_up= 
       not_premium= not_status=region_title=district_title=settle_title=section_title=""; 

,我需要使用someFunction

not_id = someFunction(not_id); 

改變自己的價值觀我該怎麼辦所有變量這樣的行動?

請不要建議使用數組,列表和其他類型的集合,如果它假設將變量名稱更改爲統一的名稱。

我知道在java本身內部是否存在這樣的可能性,eclipse ide或eclipse插件。

+0

唯一的方法是重複行...但爲什麼你不只是使用數組串[])? – jamp

+0

您將以代碼重複和維護地獄結束這樣的變量聲明。改爲使用地圖。 – Bananeweizen

+0

我需要這個gui,我不知道我可以如何使用gui使用地圖 – Yarh

回答

1

這會導致有些不可維護的代碼,但您可以通過正則表達式搜索&替換第二條語句,用「var_name = someFunction(var_name);」替換「var_name =」,這很容易做到。

查找:([^ =])+ =

替換爲:\ 1 = someFunction(\ 1);

1

someFunction的java方法嗎?或者它是一些簡單的變壓器,從not_([a-z])(\w*)變爲not[A-Z]\2?如果你只是改變變量名稱,使用eclipse優秀的重構重命名綁定到Ctrl+Shift+R,可以改變所有發生的事情考慮範圍規則

+0

這是一個java方法,但您的提示也是有用的 – Yarh

相關問題