2 回答

TA貢獻2003條經驗 獲得超2個贊
看起來Java | Visibility | Field name hides field in superclass檢查所做的事情與您需要的類似。
如果你想用結構搜索來做到這一點,你可以做這樣的事情。搜索模板:
class $X$ {
RefCount $f$;
}
并在“完全匹配”上添加以下“腳本”過濾器:
import com.intellij.psi.*;
for (PsiClass aClass : X.getSupers()) { // X refers to the template var $X$
for (PsiField field : aClass.getAllFields()) {
// compares the type of the super field with the type of field $a$
if (field.getType().equals(a.getType())) {
return true;
}
}
}
return false;

TA貢獻1775條經驗 獲得超11個贊
看起來新版本的 IntelliJ (2018.3) 使這變得相當容易,盡管有點尷尬。如果我知道這即將到來,我會很想使用預覽版。
訣竅是首先為基類創(chuàng)建(并保存?。┮粋€搜索模板;例如像這樣:
class $Class$ {RefCount $count$;}
然后做這樣的事情:
class $Child$ extends $Base$ {RefCount $count$;}
$Base$
然后添加一個引用您保存的模板的“參考”過濾器。
如果 Child 擴展 Parent 進而擴展 GrandParent,則此技巧不起作用,其中該字段在 Child 和 GrandParent 中聲明,但不在 Parent 中。我認為這可以在沒有太多麻煩的情況下解決這個問題,但我實際上不知道該怎么做。
添加回答
舉報