Code Collaborator, Class' name change - java

my scenario is: I have a class named "A.java", but now I'm realizing that "A" is not appropriate any more, so, I have changed it for "B.java", after I did this, I tried to create a code review for this change and other internal changes for that class, but I faced with an obviously thing: code Collaborator tool creates two different files and clearly it doesn't show as one, like I need it, would be great have a good suggestion, thanks in advance!
Ps: I've tried changing only the file name but this is causing various issues...

Related

How to add parameter label in IntelliJ?

I just started using IntelliJ and while creating my first class and method I noticed something. When I wrote GomokuClient(4000); to call on a class from a imported library I of course got a error for the code not being complete, so I pressed the little red bulb to see the issue, and I selected the recommended fix. The fix looked like this:
Now I'm wondering, how do I write the portNumber:label in the parameter myself for other methods. Looked really nice and very helpful, and I'd like to know how to do this myself.
thanks beforehand!
The fix done by the IDE was not about setting parameter label, but instead adding the new() for ensuring the constructor call.
What you additionally see there is a feature of IntelliJ to show method's parameter hints/labels for easy understanding (readability) of the code. You can read more about parameter hints here: https://www.jetbrains.com/help/webstorm/viewing-method-parameter-information.html.

Matlab's Tab completion for classes

I have the following project on my hands, and I am banging my head to the wall for this "little" caveat.
In the project Matlab classes are used. Due to the structure of the project, I have the folders structured as follows:
+a/+b/+c/
Then, on c there are a bunch of other subfolders declared:
+a/+b/+c/+d
+a/+b/+c/+e
+a/+b/+c/+f
+a/+b/+c/+g
On one of those folders (let's sat +e) is where I am implementing my .m classes, which contain properties, as well as Static methods:
+a/+b/+c/+e/my_class_1.m
+a/+b/+c/+e/my_class_2.m
+a/+b/+c/+e/my_class_3.m
+a/+b/+c/+e/my_class_4.m
So let's take a look into my startup.m file:
% add the path to the class
addpath(genpath('<previous_path_to_a>'));
% import the module
import a.b.c.e.*
What I would like to do now is to be able to press my_class_1. + Tab on the Matlab prompt and be shown the properties and methods available for that given class.
I know I could just use Matlab's methods() function for this, or the properties() one, but it would be really nice to be able to just type:
help my_class_1. + Tab
to be able to select the given method and see it's documentation.
Otherwise I have, as I said, to call methods() first to see what the names of the class's own methods are for this particular class, to be able to access its documentation.
Edit:
Of course, what does work is typing the whole path, in my example:
help a.b.c.e.my_class_1. + Tab
The question is how to get rid off those previously annoying a.b.c.e.
Hmm, looks like you're right. Tab completion of methods and properties only seems to work with fully qualified class names, even if the class is on the path and imported.
I don't know of a workaround. If I were you, I'd enter an enhancement request with MathWorks for that. It would seem like an obvious and nice thing to have.

Multiple classes in the same eclipse window

I'm reading Thinking in Java and it's frustrating to declare each class in a separate window in Eclipse, as the examples often contain 6-7 very simple classes.
I can just make a new class file, make one class public in this class file and the others with default access, but I don't know what should be the class' name I created. For example, I do the following:
New -> Class -> and then I must choose a class name, let's say it's Dog.
Now, in this file, I have this:
public class Dog {
}
class Cat {
}
But since I have two classes, it's a little weird to have this class file (I don't know if it's the right word here?) to be named Dog in Eclipse (The name in the src folder).
Is there a better way to declare multiple classes in the same window(?) in Eclipse?
A java file can have at most only one public class into it. And the name of that file should be same as of that public class.
I would say the frustration are not genuine because:
This is the how Java is designed and makes all sense to define each
class in a separate file. (Unless you want to write your own compiler)
You may want to use some shortcuts e.g.
Cntrl + Shift + R` to search a class
Alt + Shift + R to rename
You can update Eclipse to use shortcut for switching within classes.
What you're doing isn't going to compile. Each top level java class must be declared in a file with the same name. It will give you an error "Cat must be declared in its own file" or something like that. If you really want to, you can put the Cat class inside of the Dog class, which is called an inner class. However since they aren't related classes you shouldn't do that. Just declare each one in its own file.
Keep each class in it's own position. If your class is small and data can be exposed you can consider using nested (inner) class.
By the way, in Eclipse you can show multiple class at same time. Just drag you file title to some place.
To actually answer your question, rather than leave a bunch of comments stating why you shouldn't (which you seem to understand already), no. There isn't really a better way to do what you want. I don't know if it will compile or not (I seem to recall seeing that in the past in Java 5), but KyleM seems to think not so we'll go with that.
Short answer: no, there is not a better way to declare multiple classes in the same file.
(I don't want to suggest inner classes because that is kind of complicated for someone just starting java, as your post suggests).
Don't mix Eclipse window with files, you can understand a .java file as a container for a java class. It's the standard way and it would help you to have a more clear project when it becomes bigger.
You can have more information about this here
If you want 2 classes in the screen you can split the eclipse editor window by dragging the opened tab file and drop it on the tabs zone.
Unfortunately you do have to do this the long way, as everyone else has suggested / insisted. If the problem is a matter of clicking around through tabs, though, eclipse does allow you to drag tabs into new windows on the screen, which lets you view potentially all of them at once.
You also end up with an "overview" of the classes in the file explorer on the left of the screen, if that's more along the lines of what you're looking for.
Good luck (:

How to parse a Java file and change the name of a variable/method name/class name automatically?

I would like to know which is in your opinion the best way to parse a Java file and automatically change either a variable name, a method name or the class name. I would like to do so because I want to offuscate some code by just changing one small part of it (one of the three cited above).
For example I could have a class that has a global variable public static final int index = 0 and I would like to change it to public static final int xxx = 0. Of course i should be replaced to xxx in each occurrence in the file. Same goes for class name or method name.
I've been told ANTLR may work for me, but I've never used it and I don't want to waste time learning it if then I discover it's not suited for my purpose.
Thanks
EDIT:
I do not need to obfuscate the code, I need to change a small part of it. Either one of those mentioned above.
If you only need to change a few such identifiers, then refactoring (supported by most IDEs, including Eclipse) is simple, quick, and reliable.
If you need to change a lot (for example, if you're trying to replace uses of english with roughly equivalent identifiers in a foreign language - e.g., counter => compteur), then I'd personally find myself using something scriptable, like sed or Perl. And I'd be very careful to make sure I was hitting exact matches (e.g., when changing lie to truth, that I don't also change belief' to 'betruthf)
One caution if you go with an automated, do-a-lot-at-a-time solution: be very sure you can test functionality before and after to assure that you haven't broken anything.
Maybe the easiest is to use an existing code obfuscator, like the free Proguard :
http://proguard.sourceforge.net/
Use a code obfuscator to do the work for you.
Or use an IDE like Eclipse, which has this kind of thing built in using the Refactor menu.

Can one automatically create javadoc tags for an entire Eclipse project?

I know one can use '<alt><shift>J' to create tags for a single code element (class method for example).
But is there a way to automatically create these tags for every class in the entire project? Or even just at package or class level?
Have you looked at JAutodoc?
Not that I know of.
What would that be good for anyway? Autogenerated Javadoc comments are worse than useless; I'd rather not have them cluttering up my code, and Javadoc will provide as much information even with no comment present.
Automatic generated JavaDoc is a pain, because other people never now what the method should do and yourself will also not know it, when you look at the class one year later.
Please comment your methods by yourself or do not comment the method.
My company is using checkstyle to force the employers to add javadoc. Some employers hate it to comment their methods and just type sensless comments. It would be better that their is no comment than a useless.
With checkstyle you can find all undocumented methods, to document them in a well format.
What will help you to document an init method like
"init has to be called before any
other method and initializes the class
ActionDummy"
it is better to tell what exactly is done
Inizializes the default state of the
action provider. Some state variables can be
overriden by the listener when ....

Categories

Resources