Structural Search not working with Generic Vars

I have variables of the following form:

public static final MyClass MY_VAR = new MyClass("someString");

and the following structural search works fine:

public static final TCPropertyKeyPath $var$ = new TCPropertyKeyPath($string$);

(where $string$ java expression type is String, and occurrances are 1,1).


However, if one of my variables has generics:

public static final MyClass<ClassA,ClassB> MY_VAR = new MyClass<ClassA,ClassB>("someString");

then I cannot construct a search string that will match. For example, the following does not work at all:

public static final TCPropertyKeyPath <$arg1$,$arg2$> $var$ = new TCPropertyKeyPath <$arg1$,$arg2$>($string$);

(where occurances on arg1,arg2 are 1,1).

Can anyone offer input?

Thank You,
Eric

6 comments

Sorry, I had a typo in my message. TCPropertyKeyPath should just read 'MyClass'. But the question stil stands. The following search string does not work, and I am wondering why:

public static final MyClass<$arg1$,$arg2$> $var$ = new MyClass<$arg1$,$arg2$>($string$);

0

I really need this to work because I am relying on structural search/replace to reformat the code as follows:

public static final MyClass<ClassA,ClassB> MY_VAR = new MyClass<ClassA,ClassB>("someString");

-->

public static final MyClass<ClassA,ClassB> MY_VAR = new MyClass<ClassA,ClassB>() {
public ClassB targetMethod() {
return someString();
}
}

I have a bad feeling this won't work. :( It seems as if the structural search breaks down if you add generics to the equation.

This is strange because IDEA defines the following template (which does work):

$Type$ <$GenericArgument$> $Var$ = $Init$;

So you would think you could modify that as I have done:

public static final MyClass<$arg1$,$arg2$> $var$ = new MyClass<$arg1$,$arg2$>($string$);

but alas my example doesn't work. Maybe I'm doing something slightly wrong?

- Eric

0

Seems to be bug, but this works

public static final MyClass<$ClassA$,$ClassB$> $MY_VAR$ = $Init$;

public static final MyClass<$ClassA$,$ClassB$> $MY_VAR$ = $Init$ {
public $ClassB$ targetMethod() {
return someString();
}
}

Eric H. wrote:

I really need this to work because I am relying on structural search/replace to reformat the code as follows:

public static final MyClass<ClassA,ClassB> MY_VAR = new MyClass<ClassA,ClassB>("someString");

-->

public static final MyClass<ClassA,ClassB> MY_VAR = new MyClass<ClassA,ClassB>() {
public ClassB targetMethod() {
return someString();
}
}

I have a bad feeling this won't work. :( It seems as if the structural search breaks down if you add generics to the equation.

This is strange because IDEA defines the following template (which does work):

$Type$ <$GenericArgument$> $Var$ = $Init$;

So you would think you could modify that as I have done:

public static final MyClass<$arg1$,$arg2$> $var$ = new MyClass<$arg1$,$arg2$>($string$);

but alas my example doesn't work. Maybe I'm doing something slightly wrong?

- Eric



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Thanks for the solution, but I still need to define a variable on the right side of the equation (within the $Init$ clause), so your solution won't quite work.

How would I go about doing this. Change:

public static final MyClass MY_VAR = = new MyClass("$string$");

to:

public static final MyClass<CurrentClass, Object> = new MyClass<CurrentClass, Object>("$string$", CurrentClass.class, Object.class);

A search-replace template like the one below doesn't work because IDEA seems to incorrectly assemble the first set of $SomeStatements$ (0,unlimited), and it ends up putting the replaced string at the top of the file. My files are quite complex with Annotated fields & methods, and sometimes static blocks at the top of files. I am thinking the IDEA search/replace is getting confused by all these things when assembling $SomeStatements$?

class $Class$ {
$SomeStatements$;
MyClass $FieldName$ = new MyClass("$string$");
$MoreStatements$;
}

class $Class$ {
$SomeStatements$;
MyClass<$Class$, Object> $FieldName$ = new MyClass<$Class$, Object>("$string$", $Class$.class, Object.class);
$MoreStatements$;
}

0

Class based replacements indeed likely to change ordering of
fields/methods (and I am going to fix it in next version due to large
amount of work required) so I think you need to proceed with declaration
based replacement.
Btw, I fixed original problem.

Eric H. wrote:

Thanks for the solution, but I still need to define a variable on the right side of the equation (within the $Init$ clause), so your solution won't quite work.

How would I go about doing this. Change:

public static final MyClass MY_VAR = = new MyClass("$string$");

to:

public static final MyClass<CurrentClass, Object> = new MyClass<CurrentClass, Object>("$string$", CurrentClass.class, Object.class);

A search-replace template like the one below doesn't work because IDEA seems to incorrectly assemble the first set of $SomeStatements$ (0,unlimited), and it ends up putting the replaced string at the top of the file. My files are quite complex with Annotated fields & methods, and sometimes static blocks at the top of files. I am thinking the IDEA search/replace is getting confused by all these things when assembling $SomeStatements$?

class $Class$ {
$SomeStatements$;
MyClass $FieldName$ = new MyClass("$string$");
$MoreStatements$;
}

class $Class$ {
$SomeStatements$;
MyClass<$Class$, Object> $FieldName$ = new MyClass<$Class$, Object>("$string$", $Class$.class, Object.class);
$MoreStatements$;
}



--
Best regards,
Maxim Mossienko
IntelliJ Labs / JetBrains Inc.
http://www.intellij.com
"Develop with pleasure!"

0

Can I download a build with this fix anywhere?

0

Please sign in to leave a comment.