use IDEA to make all methods public in some java files

I want to make all class definitions, constructors, methods
public in some java files for testing purposes.

this should be possible by the powers of IDEA,
using PSI-API - right?

thanks for any help

12 comments
Comment actions Permalink

what are you trying to test? I've never seen or heard of testing that requires everything to be public. If you start calling private methods in your test it will (and should) fail.

0
Comment actions Permalink

I want to make some tests using an external framework.
I need some base functionality of that framework to run
my own tests. The framework has the core base classes
defined package local and final...

I just would like to have those classes and methods
(that were pacakge local) public, to be able to write
some easy test cases. the private methods may stay private.

0
Comment actions Permalink

ok, I see it is easier to make a new TestClass
in the same package ;)

Nevertheless I would like to know if something like
"make all methods public" would be possible via
some API of IDEA.

0
Comment actions Permalink

If you put your test code in a separate source tree whose lower branches
mirror the directory/package structure of the code you want to test, the
test code will be able to call package-default, protected, and public
methods.

For example if the code you want to test is in package

com.mycom.foo.

Set up another source tree like this

../test/upperbranch/com/mycom/foo/MyTester.java

If you include both source trees in your IntelliJ project, you will be able
to compile both your production code and test code together and easily run
your tests without modifying your production code.

Ted Hill


"Michael Damberger" <michael.damberger@t-online.de> wrote in message
news:7037214.1056456763238.JavaMail.itn@is.intellij.net...

I want to make some tests using an external framework.
I need some base functionality of that framework to run
my own tests. The framework has the core base classes
defined package local and final...

>

I just would like to have those classes and methods
(that were pacakge local) public, to be able to write
some easy test cases. the private methods may stay private.

>
>



0
Comment actions Permalink

IMHO having an api to make everything public would be very bad. You would very rarely want this feature and it would be too tempting for new programmers.

0
Comment actions Permalink

I want an api not only for "making everything public",
but for source code modification at a high level.

I often wish for such a feature to automate stupid
tasks that ends up in very much typing... ;)


0
Comment actions Permalink

yes you are right, that's the easiest way for accessing some package local classes,
thanks!

0
Comment actions Permalink

It would certainly be possible to write such a thing. In fact, if I'm remembering my PSI right, it should be pretty easy (~50 lines). That said, it's the wrong solution. For the sort of "white box" testing you describe, either parallel package structures or using the reflection API are prefered solutions. There's a JUnit extension (whose name escapes me, too much chardonnay last night) that uses reflection that would do what you want.

--Dave

0
Comment actions Permalink

just curious what kind of high level tasks are you speaking of? I'm having a hard time coming up with safe things that can be applied to all source code. Maybe comment out all System.out.println statements but what else???

0
Comment actions Permalink

you're right, it is not appropriate for that topic -
but I'm very interested in any sample code snippets,
if available :)

0
Comment actions Permalink

understand me right: forget about the topic,
what I'm interested in is just access to IDEAs code
inspection and modification capabilities.

Having that, you can create your own refactorings and "automated-code-changes" of any kind you can think ok.

For example: I have field variables in a class
and have to change their type. Then there are assignments
to those fields, like

Vector list2;
Vector list3;

public void someMethod()
{
list2 = new Vector();
list3 = new Vector();
}

say, types shall be changed to ArrayList.
I could taylor a refactoring that takes specifically
the fields list2,list3, changes the type into ArrayList,
and also the assignments.

This is just an example, it is easy to think of
examples from real world coding that require much
more changes by hand that COULD be automated.

There is some threshold of amount of manual code
editing that follows some kind of pattern,
when I start wishing for an automation,
say you have to change 20 lines of code in 10 java
files...

the powers of IDEA are perfectly suited,
much more then regexp.

Did I make myself understandable?

0
Comment actions Permalink

>understand me right: forget about the topic,
>what I'm interested in is just access to IDEAs code
>inspection and modification capabilities.


>Having that, you can create your own refactorings >and "automated-code-changes" of any kind you can think ok.

Yes, but it's not a trivial operation. The APIs you need are available, but are undocumented and unstable, and some of the more valuable parts for your purposes (intentions, inspections, code warnings) have only been opened very recently (like, late last week).

The best thing I can tell you is to look at example plugins, available on www.intellij.org. Good plugins for the sort of thing your asking about are IntentionPowerPack, AutoboxingIntentions, and InspectThis.

Good Luck!

0

Please sign in to leave a comment.