How do I add methods and attributes using ObjectAid? - java

My goal is to add methods and attributes to the class diagram to make it generate stubs of code in the classes.
Here's an example:
If I'm just starting a project. I have a class called tuna and I want to add the methods swim(), eat() and poop() with it generating stubs. This way by the time I'm done with all the classes and start to code I won't forget what I was thinking.
Could ObjectAid be the wrong tool for the job?

ObjectAid can only show you the source code, you have to go to an editor to change it. When you double-click on a class, method or field, an editor will open at the proper location.

Related

When creating a Java class in IntelliJ: is there a wizard/menu to select the package and class to extend from?

One of the features I like of Eclipse is that when creating Java classes, a wizard is available to specify different properties for the class. Like its package, class to extend from...etc (see below in the screen cap).
Does IntelliJ provide something similar? I created a class but the process wasn't smooth. I had to...mark /java directory as Source Root...create new package...create a new class...and now, I want to extend from a different class other than Object... I would like to avoid doing this step by step, if possible.
I am using IntelliJ Community Edition, version 15.
No, there is no such wizard. Marking the directory as a source root is a one-time action, and is normally taken care of when you create the project. To specify the package, you can enter the package and class name directly in the "New Java class" dialog. If you want to extend a different class, the code completion will help you enter the "extends" or "implements" keyword and specify the base class name.
You can make package at the same time as you create java class.
When you do right click -> new -> java class : at the place of the name you can mark
my.new.package.ClassName and IntelliJ will create the package : my.new.package for you.
For more explication you can visit this page.
In IJ you don't need to write all of this stuff manually. Just right click on the method an choose Go to Test or press Ctrl-Shift-T. This functionality is described on the help page IntelliJ IDEA 15.0 Help /Creating Tests.
In the Create Test dialog:
Select the testing library to be used.
If the selected library is missing in your module, click the Fix button. As a result, the corresponding library will be automatically added to the module libraries.
Define the name and location of the test class to be generated.
In the Class name field, specify the name of the stub test class to be generated.
In the Superclass field, IntelliJ IDEA suggests the appropriate super class for JUnit3. For JUnit 4 and TestNG, this field is blank.
In the Destination package field, define where the generated test class should be placed.
Specify whether you want the setUp()/tearDown() methods (for JUnit), or the #Before/#After annotations to be generated.
In the table that shows the list of all the methods of the source class, select the ones you want to generate test methods for.
Click OK.
In addition to other answers if you hit Alt-Enter on any interface or abstract class name one of the intention options will be to create an implementation.

How to generate interface's methods into all implementation classes?

I am looking for some kind of refactoring feature in Eclipse to generate methods in implementation classes from an interface class. Let's say I have JavaClassImpl1 and JavaClassImpl2, which implement JavaClassInterface. What I'd like to do is when I add a method to JavaClassInterface, the refactoring option is to generate empty methods in all implementation classes, in this case, in JavaClassImpl1 and JavaClassImpl2.
If you haven't implemented all of the required methods in eclipse, it will show a bunch of compile-time errors in your class (the class will have a red underline).
If you hover over the class name, a pop-up will appear with available quick fixes, one of which will be Add unimplemented methods. If you select that eclipse will generate a stub for each unimplemented method.
Another way to access the same function is to rightclick in your class and select Source -> Override/Implement Methods... which will pop up a wizard which allows you to select which methods you would like eclipse to stub out for you.
Update
If the change you make to your interface is done via one of the eclipse refactor tools, then eclipse will generally update references to the thing that was changed. For instance, if you do a Refactor -> Introduce Parameter Object... on a method in your interface, then eclipse will automatically update implementing methods.
If you're adding code manually, eclipse doesn't even know about the change until the next time you compile, and you'll have to explicitly ask eclipse to refactor the code.

Eclipse: When displaying a list of methods (ctrl-space), is there a way to have methods in that class - bold?

Eclipse:
When displaying a list of methods (ctrl-space), is there a way to have methods found in that class have names in bold? Netbeans has or at least had a feature that would bold the names of methods found within that class while inherited methods remained normal text.
This made it very easy to know what methods are from within the class you are editing.
Is there a way to do this in the latest version of Eclipse?
Thanks.
It seems eclipse does not support it.
What I do in such cases (workaround):
Open the affected class (Navigate -> Open Type...)
Press CTRL-O, this will show the methods implemented in this class.
Press CTRL-O again, this will also show the inherited methods.

How to display java classes in eclipse calling a method from other class

I was wondering if there is a quick way of identifying or displaying which classes are trying to call a method.
Its easy to do this if there are only few classes present. But what if there are hundreds of classes trying to call a method in other classes. It would be extremly tedious if I do this manually. Is there a plugin or some built-in functions that would do this in eclipse?
The reason am asking is I wanted to map out different classes that are calling methods from other classes for easy debugging.
Right click your function, select references, and then choose what you want (generally project). That will show all the references to this function in the project. This also works for classes, variables, and probably other stuff too.
You can try an eclipse's Call Hierarchy feature. It shows you all the methods which directly call the method you are interested in. You can expand each caller and see what methods call it and so on.
You can do it buy right clicking on the method and selecting an "Open Call Hierarchy" menu item or pressing Ctrl+Alt+H Hotkey.

How to create a custom 'new class wizard' for Eclipse?

I would like to create a functionality ( for myself ), wherein on clicking a button ( or say firing any event or anything that can trigger my program ), a popup will be displayed which will ask the name of the Class, objects it have and few more thing. Then on pressing OK, it will create a java file with skeleton of predefined methods, inherit known interface and ...
So, basically how to do that? Do i need to create a plugin for eclipse or there is something else in eclipse for it.
PS Please change the title. I am unable to think of any better one.
As others said, you want to create a wizard, then you want to augment the New Class Wizard, which is doing something similar to what you want (but the default wizard don't allow you to to add fields and custom methods).
To create a wizard, you can use the "New File Wizard" extension template: Create a plug-in, then, go to the extensions tab, select Add..., and select the "Extension Wizards" tab. That will get you started on Eclipse wizards.
Once you've learned the basics of creating Wizards and pages, then, include the org.eclipse.jdt.ui and org.eclipse.jdt.core in your plug-in dependencies. Open the following type (Ctrl-Shift-T): "NewClassWizardPage". This is the page that is displayed when you select New > Class in the Package Explorer.
You can probably either copy this page and the parent pages to help you get started or just extend it (in my experience, internal Eclipse wizards such as this one are difficult to extend because they have lots of fields and methods that are package/private, so I usually end up copying the code as a starting point... don't forget to keep the license though!).
You more or less want to add your own wizzard to the 'new class' dialog .. right?
This was the first site I found when typing "creating your own new wizzard eclipse" in Google: http://www.eclipse.org/articles/article.php?file=Article-JFaceWizards/index.html
I may be mis-understanding the question, but it sounds like you are re-implementing the New Class Wizard that exists already.
It lets you name the class, the containing package. Can assign a superclass and/or interface and can also choose if you want to include the contructors for the superclass.
A new .java file is created with all known methods from declared interfaces and also any abstract methods from the superclass.
Edt: Title was changed whilst I was writing this reply to "How to creat a customer 'new class wizard; for Eclipse". It makes my answer slightly redundant but I'm not seeing any new functionality being added in the question.

Categories