Replace one of annotation parameters with IntelliJ IDEA's Structural replace

谁说胖子不能爱 提交于 2019-12-11 08:01:56

问题


I have many classes with the Spring @ContextConfiguration annotation. The annotation has the classes parameter, which can be an array.

Now most of my classes look like this:

@RunWith(SpringJUnit4ClassRunner.class)         
@ContextConfiguration(classes = {
        ThisShellBeTwoClassesInContextHierarchyConfig.class,
        SomeTest.SomeTestConfig.class,
        WhateverConfig.class
})
@Transactional
public class SomeTest { ...

Desired output of some magical batch operation would be following:

@RunWith(SpringJUnit4ClassRunner.class)         
@ContextHierarchy(classes = {
        @ContextConfiguration(classes = { ConfigA.class }),
        @ContextConfiguration(classes = { ConfigB.class }),
        @ContextConfiguration(classes = {
            SomeTest.SomeTestConfig.class,
            WhateverConfig.class
        })
})
@Transactional
public class SomeTest { ...

So far, I was not even able to have the IntelliJ IDEA Structural replace tool find annotations with the classes parameter, let alone replacing it. Even simplified structure like this

@$Annotation$($param$ = { $ctx$ })

doesn't find anything. The occurrences of ctx are set to unlimited.

How should I properly work with the annotation parameters?


回答1:


It seems that because of a bug it is not possible to match arrays (ElementValueArrayInitializer) in annotation name-value pairs. You can match the annotation you want using a query like:

@$Annotation$($param$ = $value$)

But this is probably not very helpful.



来源:https://stackoverflow.com/questions/45148556/replace-one-of-annotation-parameters-with-intellij-ideas-structural-replace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!