Question

I have classes A and B that look like this:

public class A {
}

and

import org.hibernate.annotations.Formula;
import javax.persistence.Column;

public class B extends A {
    @Formula("formula")
    private String formula;

    @Column(name = "col1")
    @Formula("formula")
    private String field;
}

I need to find fields that do not have the annotation @Column I cannot use pure regular expressions, because I only need to look into classes that have class A in hierarchy.

I started with search

class $Class$ extends $superClass$ {
    @$annotation$
    private String $field$;
}

where $annotation$ is "Column" ("Invert condition" = true, "Whole words only" = true), but it matches field's formula annotation @Formula.

Annotation names are just an example (this case is not a common problem that could be covered by some inspection in IDEA).

Maybe you have ideas how to do this?

Was it helpful?

Solution

Change the constraints for the $annotation$ variable to:

  • Invert condition: false
  • Whole words only: false
  • Minimum count: 0
  • Maximum count: 0

"Invert condition" works like a boolean NOT. When enabled it matches names not like the specified pattern. In your case "Formula" is indeed not like "Column" and matches. By setting minimum and maximum count to zero instead, you're telling Structural Search you are searching for field with zero occurrences of an annotation with name "Column", which should get you the results you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top