Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Need help on designning text utilities tool...

Reply
Thread Tools

Need help on designning text utilities tool...

 
 
mfazdlie@gmail.com
Guest
Posts: n/a
 
      06-25-2007
Hello to all,

I'm mfazdlie, postgraduate student from malaysia, currently doing a
research on java tools, my supervisor adviced me to contact you all
has i am having difficulties in Object Oriented Programming especially
java programming... I need advice how to build a program that will
insert a text automatically in java class program/ source code... for
example...

i have this java class...


class mainprog
{
public void method1( )
{
System.out.println("In method1"); //Inserted automatically by
another program JAVA or C++

//bla... bla.. instructions

System.out.println("End method1"); //Inserted automatically by
another program JAVA or C++
}

public void method2( )
{
System.out.println("In method2"); //Inserted automatically by
another program JAVA or C++

//bla... bla.. instructions

System.out.println("End method2"); //Inserted automatically by
another program JAVA or C++
}
}

Hint:- (Hope this idea help)

The program search line by line text... found the class.. then take
the name class.. then search again.. until found ' { ' ( braclet/
curly bracket) count is = 1 then search again found method.. take
method name.. then after 1st method identify the ' { ' again count is
+ 1 then insert the [ System.out.println(" In + 'method name'
"); ]then search again until found ' } ' then count is - 1 and so on,
before end of the that method, insert [ System.out.println(" End +
'method name' "); ]

Really need help on this... no idea how to build this program??

Your assistance is highly appreciated..

Desperado...

MFO

 
Reply With Quote
 
 
 
 
Proton Projects - Moin
Guest
Posts: n/a
 
      06-25-2007
On Jun 25, 7:56 am, (E-Mail Removed) wrote:
> Hello to all,
>
> I'm mfazdlie, postgraduate student from malaysia, currently doing a
> research on java tools, my supervisor adviced me to contact you all
> has i am having difficulties in Object Oriented Programming especially
> java programming... I need advice how to build a program that will
> insert a text automatically in java class program/ source code... for
> example...
>
> i have this java class...
>
> class mainprog
> {
> public void method1( )
> {
> System.out.println("In method1"); //Inserted automatically by
> another program JAVA or C++
>
> //bla... bla.. instructions
>
> System.out.println("End method1"); //Inserted automatically by
> another program JAVA or C++
> }
>
> public void method2( )
> {
> System.out.println("In method2"); //Inserted automatically by
> another program JAVA or C++
>
> //bla... bla.. instructions
>
> System.out.println("End method2"); //Inserted automatically by
> another program JAVA or C++
> }
>
> }
>
> Hint:- (Hope this idea help)
>
> The program search line by line text... found the class.. then take
> the name class.. then search again.. until found ' { ' ( braclet/
> curly bracket) count is = 1 then search again found method.. take
> method name.. then after 1st method identify the ' { ' again count is
> + 1 then insert the [ System.out.println(" In + 'method name'
> "); ]then search again until found ' } ' then count is - 1 and so on,
> before end of the that method, insert [ System.out.println(" End +
> 'method name' "); ]
>
> Really need help on this... no idea how to build this program??
>
> Your assistance is highly appreciated..
>
> Desperado...
>
> MFO


Hi,

This can be done easily using the java.io packages.
Try to get the java file as the input
Using the BufferedReader class exist in the java.io. packages try to
read the file line by line using readLine() method

I suggest you not to do new iteration for getting class name or method

Run the iterator of reading the file top to bottom and you need to
have simple if statements to check for package, import, class keywords
and methods...
Need to have some counter to do increments...and
finally print the summary...

This is the fair idea of solving the problem...but you need to handle
some corner cases like inner classes, anonymous class and runnable
interface method declarations....

~Moin

 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      06-25-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> The program search line by line text... found the class.. then take
> the name class.. then search again.. until found ' { ' ( braclet/
> curly bracket) count is = 1 then search again found method.. take
> method name.. then after 1st method identify the ' { ' again count is
> + 1 then insert the [ System.out.println(" In + 'method name'
> "); ]then search again until found ' } ' then count is - 1 and so on,
> before end of the that method, insert [ System.out.println(" End +
> 'method name' "); ]
>
> Really need help on this... no idea how to build this program??


I may being naive about this but it sounds to me like you are describing
a parser. I.e., what the compiler does to compile a program. Besides {
and a count, you'll have to deal with comments (don't count a { if it's
in a comment), strings (ditto; no {'s within "'s) and possibly several
more things I've forgot.

I'd look at a full parser; it'll be easier to modify when you find
additional complications besides just comments and string (which I'm
sure there will be; stuff always happens). Maybe use yacc?

But besides that the idea of making a parser to modify Java and
instrument it so that methods indicate their entry and exit is interesting.

Question: What happens if this instrumentation is run twice? Do you
want to end up with two printlns at the start of each method?

Question: Why not just use the java.util.logging.Logger.entering()
method instead of println?

 
Reply With Quote
 
Martin Gregorie
Guest
Posts: n/a
 
      06-25-2007
Mark Space wrote:
> I'd look at a full parser; it'll be easier to modify when you find
> additional complications besides just comments and string (which I'm
> sure there will be; stuff always happens). Maybe use yacc?
>

Hey, this is Java. Use CoCo/R, not lex and yacc.


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      06-25-2007
Martin Gregorie wrote:
> Mark Space wrote:
>> I'd look at a full parser; it'll be easier to modify when you find
>> additional complications besides just comments and string (which I'm
>> sure there will be; stuff always happens). Maybe use yacc?
>>

> Hey, this is Java. Use CoCo/R, not lex and yacc.
>
>


Sorry, my age is showing. CoCo/R seems like an excellent suggestion.
 
Reply With Quote
 
JT
Guest
Posts: n/a
 
      06-25-2007
Mark Space wrote:
> Martin Gregorie wrote:
>> Mark Space wrote:
>>> I'd look at a full parser; it'll be easier to modify when you find
>>> additional complications besides just comments and string (which I'm
>>> sure there will be; stuff always happens). Maybe use yacc?
>>>

>> Hey, this is Java. Use CoCo/R, not lex and yacc.
>>
>>

>
> Sorry, my age is showing. CoCo/R seems like an excellent suggestion.

Ok, so what is CoCo/R?

http://www.ssw.uni-linz.ac.at/coco/

What's the reason for doing this?
 
Reply With Quote
 
Mark Space
Guest
Posts: n/a
 
      06-26-2007
JT wrote:

> Ok, so what is CoCo/R?
>
> http://www.ssw.uni-linz.ac.at/coco/
>
> What's the reason for doing this?


Compilers and parsers are such a common concept in computer science that
they have their own specialized implementations and languages.

Java is a general purpose programming language. For certain
applications, it's better to use the special purpose tool. CoCo/R is one.

All this from someone who is not a compiler guy....
 
Reply With Quote
 
MFO
Guest
Posts: n/a
 
      06-26-2007
Thank's Guys for your reply..
I had never learnt this Java Program before.. this is the 1st time...
so lot of new jargon to me.. i'm appreciate if you guys could share a
source code of any application related.. so that i can learn myself..
thru that examples..

TQ

 
Reply With Quote
 
Martin Gregorie
Guest
Posts: n/a
 
      06-26-2007
MFO wrote:
> Thank's Guys for your reply..
> I had never learnt this Java Program before.. this is the 1st time...
> so lot of new jargon to me.. i'm appreciate if you guys could share a
> source code of any application related.. so that i can learn myself..
> thru that examples..
>

CoCo/R has quite a good PDF manual. Just be sure to download that along
with the code and executables.

I was able to use it pretty much straight away, but then I have used lex
& yacc to solve problems rather than to write compilers. As always, if
you prefer a book there's an O'Reilly one about lex & yacc that should
be easily adaptable to learning CoCo/R.


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help re Proxy utilities - comments-suggestions - TIA wrinklewart@yahoo.com Computer Security 0 12-06-2006 07:52 PM
utilities: what do I need? melanie bennett Computer Support 4 06-02-2005 05:39 AM
Ruby utilities for part of speech tagging and text categorization Mark Watson Ruby 1 04-04-2005 05:32 PM
Mac G5 OS 10 and a Epson 7600 Need help with print utilities bob j Digital Photography 5 03-03-2004 04:15 PM
HTML text filters, display control, utilities _eee_ ASP .Net 3 02-28-2004 10:58 PM



Advertisments