Create a Java class from a groovy test file in IntelliJ - java

Trying to do TDD in a java project using groovy tests, I need to generate java classes on the fly (Alt+Enter from the test on the name of a class I want to introduce -> Create class -> Select the java main package as Target destination).
The problem is that, even if the Target destination is a java source directory, IntelliJ generates a groovy class.
Is there any way to quickly generate a Java class, instead?

With the current version of IntelliJ IDEA (2016.2.4) the only solution I found is to generate a groovy class (Alt+Enter| Create class from the test) and then convert it to Java (Refactor | Convert to Java).
To make it faster I also added a shortcut for Convert to Java: Ctrl+Shift+O was the best available option for me.

Looks like now it's not possible.
This guide is exactly for this TDD workflow and there are no mentions about it.
Also I made research through IntelliJ's issues and didn't find any similar task.
And finally I post feature request for that.

Related

Get ClassNames acroos Java Projects

I need to develop a Tool for checking certain Java Code conventions for all the java classes present in a Java Project.
For one of the rules(i.e;Checking the Class Name Convention)I need to get all the Class Names given the Folder Name.Instead of parsing it line by line,can anybody suggest me a better way to do the same.
NOTE 1: Reflection is not an option because it doesn't work across java projects.I can not use build path as well since there would be many projects at run time for which i need to check the code conventions.
NOTE 2: Currently,I ma using eclipse IDE to build this,but in run time I am not even sure whether they would be using only eclipse IDE.Hence,when you suggest any eclipse plugin ,please bear this in mind.
Thanks in advance:)

Running a quick code test in eclipse

Is there a plugin in eclipse where can type in a quick java code sample and run it? I remember seeing something like this a long time ago.
You can use the Scrapbook:
You need to explicitly reference all class files using a full package name, but you can get around this by importing all the libraries (including the JRE libraries) you need onto the runtime classpath.

Find dead class in Java with Eclipse

I am new ( and only person ) on old Java project. Couple guys have developed this before me. Is there any tool ( plugin for Eclipse would be nice ) which can find in project dead classes ( classes that are declared but they don't use anymore anywhere ?
You could use the Emma plugin to determine code coverage and look for the classes with 0% coverage after a full run.
To make sure before you remove classes, use the eclipse function that shows all references to the class in case it is used in exception handling.
Looks like similar question already asked on Stackoverfow check out the following links already asked on SO
How to find unused/dead code in java projects
Find unused classes in a Java Eclipse project
Check out the answers
http://eclipsenuggets.blogspot.com/2007/05/here-is-quick-way-to-eliminate-dead.html
This worked for me (although I tried it several years ago)
IntelliJ has a "Find Usages" that you can apply to classes, methods, strings - anything. Perhaps the Eclipse help can turn up such a thing.
Or maybe you should switch to IntelliJ.
IntelliJ can also generate UML that includes dependencies. Any class or package without a dependency would be a good candidate for removal. You'd get a quick visual that way.

Verifying Java Class Library in Netbeans 6.9.1

I am new to java and to netbeans so my apologies if this is a simple question.
I made a 'Java Class Library' Project in Netbeans 6.9.1
I added a few classes to it and hit 'Build'. It builds with no errors. However the problem is I know there are errors.
It seems as though I can make up class names and hit build and it doesnt provide me with any feedback.
How can I make it so that netbeans validates my code when buildling a class library?
I am unable to 'run' the project becuase there is no Main. However this is a class library and I dont want to make test applications in my library.
Edit:
For example I can write the following and a 'clean & build' still works
MadeUpName x = new MadeUpName();
This will build even though I have no class or reference to a class that contains
MadeUpName
I also have no 'Import' statments as of yet and it still builds....
Thanks, stephanie
1) To test a Java Class Library project you should create another project and add your "Java Class Library" project as project dependency. In this new testing project you can write class with main method to test features of the class library. When you will build the test project NetBeans IDE will also build the class library project and will add the JAR file in the class path of the testing project.
2) If the Java Class Library projects compiles through "Clean & Build" that means the project has no syntax errors. That means your code may have logical errors which are not detected by the Java compiler. Usually class library developers create JUnit test cases to find out logical errors, and you are also strongly advised to use JUnit tests for your project.
with regards
Tushar Joshi, Nagpur
Ideally you should test a class library by writing unit tests (rather than test applications) that exercise the classes in your library. There are several unit-testing frameworks available that can help you write the unit tests. The most popular is JUnit.
The test cases should be placed in a different source folder in the same project as the code they are testing. When you build the project you should ensure that the test classes are not included in the JAR file. If you use a build tool like Maven it will do this for you as long as you follow it's project conventions.
Update
Based on your comments, and the fact that you tagged your question with Groovy, I'm guessing that the library is written in Groovy? Your problem seems to be that Netbeans doesn't perform the kind of type-checking that you get with Java (or other statically-typed languages)?
Because Groovy is a dynamic language, it's not possible for the compiler to perform the same rigorous type-checking that you get with Java, but at the very least the Netbeans Groovy editor should provide some hints/warnings if you're referencing classes that don't exist (for example). Are you sure you're opening the code in the correct editor (you may need to install a Groovy plugin first).
You should use GroovyTestCase, rather than JUnit directly to test a Groovy library.

Tool for creating Dynamically Generated Code in Java (In Eclipse)

In Visual Studio land, I used to be able to define a structure in an XSD file and add a special attribute to it which would cause it to be dynamically compiled and available to use with intellisense in the other C# files in the application. I am not sure exactly what the term for this is, perhaps "dynamic code generation."
I am trying to accomplish the same in Java using Eclipse IDE. Basically what I am looking for is a tool that will allow me to specify some template and generate Java code from it in a "hot folder" that will allow me code complete in the other static Java files.
Does anyone know of a solution for this? I know it is possible in Visual Studio, but I can't seem to find anything for Eclipse.
Ok, here is exactly what I want to do.
Step 1. I create a folder called templates
Step 2. I create a file called HelloWord.ibes
Step 3. Code it automatically generated in my src folder HelloWorld.java
I want to be able to do this in eclipse easily.
You may create an ant build file that does the source generation for you. Then you are free to use any code generator you like. Ant support is part of the eclipse IDE. If you prefer maven, there's a nice eclipse pluging available (that's what I actually use for source code generation based on jaxb, javacc and xdoclet...).
Technically spoken, you just add another eclipse builder which is invoked anytime eclipse detects a change in your code base.
If you already have a code generator in mind, just 'ask' the internet if there's a plugin available.
Edit
On how to install a builder: This is done automatically. For maven, you just install the maven plugin (m2eclipse) and enable maven dependencies for a project. Then if you look at the projects properties pages (Builder section), you find a second entry in the list of builders.
It's similiar with ant, even easier, because ant is already integrated. "enable" ant for a project and the builder is added to the list of builders for the project. You can deselect it at any time if it kills performance or switch of automatic building (I don't know by heart how to enable ant builds for a project, but I remember that the eclipse help had sufficiant informations).
All about ant can be found here: Apache Ant
Creating a new builder is difficult, as it has to be coded in java and added to eclipse as a plugin. I bet you don't want to follow that track ;)
I'm not sure whether you have seen the code template option?
Preferences.Java, Code Style then Code Templates
How
to add code templates
Useful
code templates

Categories

Resources