Java Code Cleaner - java

Anyone recommend a good code cleaner for Java. If it had a Netbeans plugin, that would be awesome. Just looking for something simple.
Put variables and functions in order based off scope.
Format the code (Hungarian style)
A really awesome feature would be if it could group together functions that implement a interface for a class.

If you use Alt+Shift+F in Netbeans, it should clean it up for you automatically. You can set preferences within Netbeans as well.

Related

creating dsl editor in java

I'm looking forward to create a Domain Specific Language editor in java.
I'm just starting up so i'm here to get some ideas where to start.
What i want is to create an interface like for my editor may be like eclipse (IDE) and i want it to work like eclipse but for my language as eclipse do for java.
auto completion, spell checking, highlighting text auto end braces etc.
I've Goggled about the topic and i got this:
XTEXT
"Building your own domain-specific languages has never been so easy.
Just put your grammar in place and you not only get the working parser
and linker but also first class Eclipse support."
As it says first class Eclipse support, i don't want eclipse support but i want a complete new interface for this. can i perform what i want using XTEXT or i should use something else?
Please guide me, do tell me if i'm wrong at some point here.
Thanks alot.

Are these Eclipse variables encrypted?

I was doing some development on Java using Eclipse. After setting the break point, but found the variables are looks like in the following image, such as a, a, what does these mean, are they encrypted?
I have done some other project, but the variables should have some readable names on them.
It looks like you are debugging code that has been obfuscated. Specifically, the AssemblerInput class. Either you obfuscated it yourself, or you are using a 3rd-party library that has been obfuscated.
Eclipse didn't do it ...
It is from some Development kit. I just run the examples, nothing with the code.
Well, the library in the development kit is obfuscated.
Any idea on how to restore that?
There is no way to restore the original symbols. The only way forward is to request a non-obfuscated version of the library from the supplier ... or find an alternative to the library.

Using WindowBuilder + Scala, any good ideas?

I have here a small Scala console application and its working fine. I have now just one trouble: this application should be extended. One of the requests are, that there should be a GUI (AWT,SWT, Swig - doesnt matter, it just have to run on windows).
Well I really dont want to write my own GUI. I like tools like the WindowBuilder. Can I combine this effective? If I would create the GUI with the editor, I'll get generated Java code right? Could this be a problem? I just have to create a Mixin-Project, build the GUI and for each GUI element (Button or whatever with a listener) allocate a scala function. So I dont have to rewrite any of the scala stuff, just point to the function. Is this how it could work? Any suggestions? Thank you
Edit: For me it looks dirty to generate java code in a scala application, but well as I see there is no other solution.
I've done this several times and see no problem with mixing Java and Scala code in one project.
To make things easier for Scala compiler don't put Java and Scala classes into the same package.

Is there any program like LINQPad for Java?

I've found LINQPad to be extremely useful when answering StackOverflow questions for C# or VB.NET. It allows me to write up some quick code, run it, and (if I want) see a nicely-formatted dump of the results. That way I can be sure that the code I post actually runs. Thus far I haven't seen anything that I can use to achieve the same result with Java. Is there anything like that out there?
I am not looking for something to query data sources; I just want a light-weight IDE. These are the features I'm particularly interested in:
The ability to write and run short snippets of code without establishing a whole project or file structure.
Reporting of compiler and runtime errors in the code when it is run.
The ability to add references to a particular editor instance.
Syntax highlighting and Autocomplete/Intellisense would be a plus.
JPad - A java scratchpad for running snippets
Since I also couldn't find one I've decided to write one. Currently it can:
Run java snippets (no class / imports / public blah... needed).
Contains drivers for MS/MySQL/Postgres.
Output results as HTML tables
It's very rough but I will add to it over time. Feedback is definitely welcome.
This may help : http://www.browxy.com:9000/codeRunner
EDIT: Url seems to have changed to http://www.browxy.com
You can use the Groovy web console ; it's possible to speak java in groovy land.
Java Snippet Runner:
Does something similar to Linqpad (jar file, not just for macs)
http://mac.softpedia.com/get/Development/Java/Java-Snippet-Runner.shtml
Code Runner (Commercial):
for Mac's only, it'll run code snippets in Java, and lots of other languages too (e.g. Objective C)
http://krillapps.com/coderunner/
http://ideone.com is an online service that has the features you want.
I've been using JEdit for a long time, which is a very powerful cross-platform editor, NOT an IDE. It does have plugins to execute Java code right in the editor, and even uses BSH for macros.
I was looking for a "Java LinqPad" also, and i came across :
this
I've been using IntelliJ IDEA and it works really well as a Groovy scratchpad. The Community Edition is free too.
You need to create a new project, but then can add Groovy scripts to it and run them on the fly. Not had any luck with the actual Scratch File functionality though.
Being a Jetbrains editor it's pretty slick too. (Unlike some of the other options)
Nothing beats LinqPad though.

Code / template generator for Java

For C#, I have often used CodeSmith and lately the T4 generator which is part of Visual Studio.
I'm looking for something similar for Java, in particular an Eclipse add-in since I do all my Java development using the Eclipse IDE.
I've found that freemarker does a pretty good job for generating any type of code. From the website:
FreeMarker is a "template engine"; a generic tool to generate text output (anything from HTML to autogenerated source code) based on templates. It's a Java package, a class library for Java programmers. It's not an application for end-users in itself, but something that programmers can embed into their products.
It is used by struts2 a lot. The website has a long list of other products that use freemarker.
I have worked with both Velocity and StringTemplate. Velocity is a bit more conventional (think JSP/ASP concepts), while StringTemplate seems a bit cleaner. in a sense described in this Artima interview. Both are pure templating engines, and will require you to write some code around them, if you want to do full-blown code generation from a model.
StringTemplate is used internally by ANTLR, which may be useful to your effort.
As an alternative approach, you could go with Eclipse, using EMF and JET.
You should try Telosys Tools, an Eclipse plugin for code generation working from an existing database with customizable Velocity templates
See: http://www.telosys.org/
Eclipse Marketplace : http://marketplace.eclipse.org/content/telosys-tools
The tutorials are here : https://sites.google.com/site/telosystutorial/
See this other question about CodeSmith : Is there any freeware tool available which is like Codesmith?
I use JavaForger to generate code from templates. It parses existing classes so that you can use that class-data inside your templates. It can both create new classes or insert code into existing classes. You can determine where generated code will be inserted based on a string conversion rule (e.g. myProject/dao/ProductDao.java => myProject/service/ProductService.java).
JavaForger is open source and uses FreeMarker as template engine and JavaParser as parser.
This is an old question but the only thing that comes close (for Java) to do what CodeSmith Generator does is Spring Roo.
The reason is that Java does not have Partial Classes like C# does. Spring Roo gets around this by using AspectJ ITDs.
My answer is to use StringTemplate, but there is a bit more to it than just what tool to use.
Is it the issue to generate java code? Or is it to use java tools? Programmers would be normally very comfortable writing code. Therefore, it would not be a leap to write some java classes and write a walk that would generate code using StringTemplate. I personally think it is a good exercise to create example models, generate your java code from the models. And depending on your use case you could end up writing JSON models by hand and never having to write any java code to produce the java code. Or you could end up writing Java classes that produce equivalent models.
You could use the StringTemplate based STST, which reads JSON. STST is command line based, and I am sure you could hook it to both eclipse and/or Visual Studio.
I personally think about portability, JSON is an extremely simple language. And almost every language has libraries that support it.
I'm not a C# man so I don't know what the equivalents would be, however I've found xdoclet to be very good in the past. I don't think it integrates with eclipse as such but you can run it from an ant script. Does things like generating Hibernate mapping files from annotated Java classes. Useful if that's what you're looking for :)
eclipse has a built-in template system.
look in window -> preferences -> java -> code style -> code templates
You might look at my plugin : http://fast-code.sourceforge.net/. It allows one to select multiple fields and generate code using user specified velocity templates.
Take a look at my project https://github.com/karajdaar/templator and see if that helps.
I wrote a simple web based application for my use.
its available at https://github.com/harish2704/templates
and a demo is available at http://templates-harish2704.rhcloud.com/
Its language independent tool. GUI supports several languages ( highlighting, snippet completion ect )

Categories