使用 Intellij Structural 查找/替換向 Java 代碼添加元素時,如何添加缺少的匯入?
例如,在執行以下結構(不是文本,不是正則運算式)搜索時:
尋找:
@$Annotation [Text=Autowired]$
$FieldType$ $Field [Text=X]$ = $Init$;
代替:
@Lazy
@$Annotation$
$FieldType$ $Field$ = $Init$;
它正確地在正確的地方添加了注釋
@Autowired
@Getter
Private X x;
// Is replaced with:
@Getter
@Lazy
@Autowired
Private X x;
但是,它不會添加匯入,因為 Lazy 類有多個選項。如何指示 Intellij 也添加import org.springframework.context.annotation.Lazy;到替換檔案中?
uj5u.com熱心網友回復:
您可以在替換中使用完全限定名稱并啟用Shorten fully qualified names復選框。這將在替換時添加匯入。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/402328.html
標籤:
