struct replace - giving up

what I tried to do (IDEA 4.5.4):
put a System.out at the beginning of each method in a class.

based on template:

class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$);
}

btw., why the terminating semicolon?

I modify it like this:
class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$)
{
$block$
}
}

-> no occurances found in file.

how is it supposed to work?

14 comments
Comment actions Permalink

Check out your variable constraints.
You need to specify the statements in method body if you want to modify
them, like
class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$) {
$Statements$; // min occurences = 0, max occurences = many
}
}


Michael Damberger wrote:

what I tried to do (IDEA 4.5.4):
put a System.out at the beginning of each method in a class.

based on template:

class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$);
}

btw., why the terminating semicolon?

I modify it like this:
class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$)
{
$block$
}
}

-> no occurances found in file.

how is it supposed to work?



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

0
Comment actions Permalink

thanks for reply - still does not work.
with your template and constraints,
it deletes all my methods - that's all.

replacement template:
class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$)
{
System.out.println("$MethodName$");
$statement$;
}
}

0
Comment actions Permalink

Does the matches are found?

For the class replacement one needs also some variable in search /
replace pattern
that will get the value for nonmatched class content:

like

search pattern:
class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$)
{
$statement$;
}
$Remaining // for nonmatched content, 0..max_value
}

replace pattern:
class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$)
{
System.out.println("$MethodName$");
$statement$;
}
$Remaining
}

Currently the SSR does not work properly with multiple methods at once
so you will not get adequate results in many methods of the same class.

Michael Damberger wrote:

thanks for reply - still does not work.
with your template and constraints,
it deletes all my methods - that's all.

replacement template:
class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$)
{
System.out.println("$MethodName$");
$statement$;
}
}



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

0
Comment actions Permalink

yes, the matches are found.
but the replacing still does not work, even with the added
$Remaining$ (0,max)

0
Comment actions Permalink

Hi,

I tried with Irida, some changes were not backported to 4.5 branch :(

Michael Damberger wrote:

yes, the matches are found.
but the replacing still does not work, even with the added
$Remaining$ (0,max)



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

0
Comment actions Permalink

Maxim,

SS is a very powerful tool, but it is very fiddley and
hard to get right and has no adequate documentation at
this point (which is understandable, in my opinion given
the scope of the tool).

I would propose that you provide us with whatever rules
and logic is being used in a form that is close to the
implementation, not to some document which is hard to
correlate to an actual example.

For example, introducing a class { ... } construct
certainly looks like it imposes different logic on the
search (you sort of said that in some very old post long
time ago) than searching for a method invocation.

We need to know what decisions are being made by the
search engine for all these different forms and how each
of the options interact ***in the context of the KIND of
pattern being composed***

I'm not asking that you open the implementation to us,
but it probably is close to what is needed - the help
available is not all that useful without the association
to the context (the type of search).

just my 2c

0
Comment actions Permalink

I'm sure, it would be very helpful, if all default templates would be
described with the help of examples in some kind of tutorial.

Tom

0
Comment actions Permalink

Yeah tutorial and many real world examples. I can't manage to get this
thing to do what I want it to do 99% of the time. My feeling is that if
it's this hard for developers to use, then there is a serious usability
issue.

R

0
Comment actions Permalink

Hi,

http://www.onboard.jetbrains.com/is1/articles/04/10/ssr/

Robert S. Sfeir wrote:

Yeah tutorial and many real world examples. I can't manage to get this
thing to do what I want it to do 99% of the time. My feeling is that if
it's this hard for developers to use, then there is a serious usability
issue.

R



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

0
Comment actions Permalink

http://www.onboard.jetbrains.com/is1/articles/04/10/ssr/

- Depending on template being entered (expression , statement, class,
javadoc) the search is done in the scopes that allows such kind of the
constructs.
- Additionally, text constraints without regular expressions (including
aligned on word) is used to optimize all files scan (just files
containing intersection of needed words is searched)

- Most of the problems is that the used specified pattern does not
represent valid expression / statement(s), class or javadoc (like just
method without class body). There will be preview for the source being
searched and detection of the invalid templates specified but most
likely this will happen after Irida release.

Bonny Rais wrote:

Maxim,

SS is a very powerful tool, but it is very fiddley and
hard to get right and has no adequate documentation at
this point (which is understandable, in my opinion given
the scope of the tool).

I would propose that you provide us with whatever rules
and logic is being used in a form that is close to the
implementation, not to some document which is hard to
correlate to an actual example.

For example, introducing a class { ... } construct
certainly looks like it imposes different logic on the
search (you sort of said that in some very old post long
time ago) than searching for a method invocation.

We need to know what decisions are being made by the
search engine for all these different forms and how each
of the options interact ***in the context of the KIND of
pattern being composed***

I'm not asking that you open the implementation to us,
but it probably is close to what is needed - the help
available is not all that useful without the association
to the context (the type of search).

just my 2c



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

0
Comment actions Permalink

In article <da376h$4rt$1@is.intellij.net>,
Maxim Mossienko <Maxim.Mossienko@jetbrains.com> wrote:

- Most of the problems is that the used specified pattern does not
represent valid expression / statement(s), class or javadoc (like just
method without class body). There will be preview for the source being
searched and detection of the invalid templates specified but most
likely this will happen after Irida release.


This would definitely be an improvement.

Thanks
R

0
Comment actions Permalink

I think working examples would be best...

I've got a similar problem, I don't have the solution yet but think am close to a working solution. Maybe someone can add the missing element.

What I want to do:
I'd like to replace every occurrence of "Logger.log(ex)" within a method m and class c with "Logger.log(c, m, ex)"

My current search pattern looks like this:
class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$)
{
$statement1$;
Logger.log($ex$);
$statement2$;
}
$Remaining$
}

the constraints are:
$Class$ and $ex$: 1
$ReturnType$: 0,1 (matches also void)
everything else: 0..n

What doesn't work yet is matching methods independent of the number of parameters. Whether the constraints of $ParameterType$ and $Parameter$ are set to 0 or 1 or 0,1 or 0,n or 2 - only one type of method is found.

Maybe this helps to find a working example for such or a similar problem together.

cheers
pat

0
Comment actions Permalink

Hi,

This seems due to the occurence constraints for $MethodName$ just 1, one
method just is found.
But the replacement with many methods matched will not work, file JIRA
issue for the support

Lisser wrote:

I think working examples would be best...

I've got a similar problem, I don't have the solution yet but think am close to a working solution. Maybe someone can add the missing element.

What I want to do:
I'd like to replace every occurrence of "Logger.log(ex)" within a method m and class c with "Logger.log(c, m, ex)"

My current search pattern looks like this:
class $Class$ {
$ReturnType$ $MethodName$($ParameterType$ $Parameter$)
{
$statement1$;
Logger.log($ex$);
$statement2$;
}
$Remaining$
}

the constraints are:
$Class$ and $ex$: 1
$ReturnType$: 0,1 (matches also void)
everything else: 0..n

What doesn't work yet is matching methods independent of the number of parameters. Whether the constraints of $ParameterType$ and $Parameter$ are set to 0 or 1 or 0,1 or 0,n or 2 - only one type of method is found.

Maybe this helps to find a working example for such or a similar problem together.

cheers
pat



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

0
Comment actions Permalink

http://www.onboard.jetbrains.com/is1/articles/04/10/ssr/


The document is too confusing, especially page 4. I don't see a "red
string". You describe this and that, but not always with good examples
and not very pedagogically. While it looks good for printing, but the
two-column style and the one column pictures occuring somewhere else
make it not easier.

Tom

0

Please sign in to leave a comment.