dcsimg
java src transformation
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Cheng_Fang
Posted On:   Tuesday, June 3, 2003 01:58 PM

I want to use antlr to preform some java src manipulation, for example, from try { getResource(); } catch (SqlException se) { throw new ResourceException("Failed to get resource"); } ==> try { getResource(); } catch (SqlException se) { throw new ResourceException("Failed to get resource", se); } Catch block is the only place I need to change code, and other parts should be intact. I am new to antlr and I am reading docs and tutorials, but haven't found a good way for this kind of transformation. Can you please advise? thanks.    More>>

I want to use antlr to preform some java src manipulation, for example, from

			
try {
getResource();
} catch (SqlException se) {
throw new ResourceException("Failed to get resource");
}


==>
			
try {
getResource();
} catch (SqlException se) {
throw new ResourceException("Failed to get resource", se);
}


Catch block is the only place I need to change code, and other parts should be intact. I am new to antlr and I am reading docs and tutorials, but haven't found a good way for this kind of transformation. Can you please advise? thanks.    <<Less

Re: java src transformation

Posted By:   SRIRAM_SRINIVASAN  
Posted On:   Monday, June 16, 2003 10:48 PM

If you just wanted to solve this particular problem, I
thought of a perl snippet before I could think of an ANTLR one ...



while (defined($line = <>)) {
# if line is of the form "catch ( "
if ($line =~ /catch *(w+ +(w+)/) {
# store the second word into $varName
$varName = $1;
print $line;
# Next line
$line = <>;
# If the next line contains a throw, but no mention
# $varName, insert ", $varName" just before
# the closing paren.
if (($line =~ /throw/) && ($line !~ /$varName/)) {
$line =~ s/)/,$varName)/;
}
}
print $line;
}
About | Sitemap | Contact