Trying to replace deprecated class using Structural Search Inspection

I would like to replace the following
static Category cat = Category.getInstance(Reports.class.getName());
with
static Logger cat=Logger.getLogger(Reports.class)
or even
static Logger cat=Logger.getLogger(Reports.class.getName())

I tried to create a replacement template where the search was
static Category cat = Category.getInstance($Arg$);

but the inspection never seems to find the instance?

I am not sure what I am doing wrong and have tried even just looking for "Category" as a search template and it still was not found.

Any Ideas?
I am using idea 10.5 Ultimate

6 comments
Comment actions Permalink

Do you use Structural Search diectly or Structural Search inspection?

0
Comment actions Permalink

I tried to create a new Structural Search Inspection by adding a "Replace Template", then got frustrated and just focused on the Search template

0
Comment actions Permalink

Structural search inspection with this template
static Category cat = Category.getInstance($Arg$);
flags first cat definition in the class

public class F {
  static Category cat = Category.getInstance(F.class.getName());
  Category cat = Category.getInstance(F.class.getName());
}

please post your search template and example code that does not work for you

0
Comment actions Permalink

The structural seach did work for me but did not solve my issue. Consider the following code:

package com.ias.core.calendar;

import com.ias.framework.io.util.RecordUpdateException;

import com.ias.framework.security.jdbc.ConnectionsManager;

import com.ias.framework.jdbc.OptimaConnection;

import com.ias.framework.lib.Util;

import org.apache.log4j.Category;

import java.io.IOException;

import java.sql.*;

public class Household extends IASContact {

  static Category cat = Category.getInstance(Household.class);

..
}

I have two primary goals and one minor one.
1. Replace Category with Logger
2. Replace import org.apache.log4j.Category; with import org.apache.log4j.Logger;
minor. Would be nice, refactor cat to LOGGER.

Figuring I could do the first two item with one or two structral search and replaces I tried the following:
I created a search

import $arg1$;

and set the arg1's regular expression to org\.apache\.log4j\.Category trying both a limited and unlimited search and found nothing, may be I have the reg exp wrong?


0
Comment actions Permalink

Actually, SSR does not support searching imports since it is possible to search such string using reg exp search.
Also note that you can have fully qualified class name in your replacement template (with shorten fully qualified name option on). like following:
org.apache.log4j.Logger.getLogger($a$) , this will add the import of org.apache.log4j.Logger if needed

0

Please sign in to leave a comment.