在 Intellij 上使用结构替换时如何添加正确的导入?
How to add correct import when using Structural replace on Intellij?
使用 Intellij Structural find/replace 向 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 class 有多个选项。我如何指示 Intellij 也将 import org.springframework.context.annotation.Lazy;
添加到替换文件中?
您可以在替换中使用完全限定名称并启用 Shorten fully qualified names
复选框。这将在替换时添加导入。
使用 Intellij Structural find/replace 向 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 class 有多个选项。我如何指示 Intellij 也将 import org.springframework.context.annotation.Lazy;
添加到替换文件中?
您可以在替换中使用完全限定名称并启用 Shorten fully qualified names
复选框。这将在替换时添加导入。