问题
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