Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advanced search for java code [closed]

Is there any easy way to get advanced search in Java code? I'm migrating our application from Glassfish 2 to Glassfish 4. Few libraries changed their way of handling inputs and I would like find where this specific situations will occur.

For example: JPA 1.2

MyEntity some = entityManager.find(MyEntity.class, 1234);
some.setIdMyEntity(null);
entityManager.persist(some);

Code similar to this above was working in a way it persisted new entity with new auto generated id (if appropriate annotation was in entity).

JPA 2.2 The same code will produce error

The attribute [idMyEntity] of class [my.package.MyEntity] is mapped to a primary key column in the database. Updates are not allowed.

I understand reasons behind this change and I would like to fix my application and find places which need fix as precisely as it is possible.

To find these I used regular expression \.setId[a-zA-Z]+\(null\); However there are hundreds or even thousands of matches and 90% are false positives. That's why I would search engine which could do something like that:

Look for invocation of setter (which is related to field annotated as @Id) 
with argument null on object which is instance of class annotated as @Entity

As I told this is only example so basically what I'm looking for are ways of advanced searching in Java code. Anything more than dead simple search/ regular expression search/ find usages capabilities are welcome.

like image 856
zimi Avatar asked Mar 25 '26 02:03

zimi


1 Answers

You may use Intellij IDEA Structural Search https://www.jetbrains.com/idea/help/structural-search-and-replace-examples.html

like image 134
dgofactory Avatar answered Mar 26 '26 16:03

dgofactory



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!