Any way to enforce naming standards in android? - java

I am aware of http://omnidroid.googlecode.com/svn/tools/Eclipse_Formatter-ITP_Conventions.xml that can be imported into my Android projects Formatter , but it doesn't enforce naming convention standards. I know there are many standards available per project but I'd rather if there were rules set to ensure it. Is there another XML file I can import into my formatter to ensure such? Something like the Resource Style Rules at the end of the page at https://github.com/iamshanedoyle/Android-CodingConvention would be great to have, but I don't really know how to code this into the XML file?

Formatter can only help you to maintain formatting.
Also check the Code Style part of the project configuration, like variable prefixes and suffixes; those help to use Content Assist for example with getters: if you have a member named m_x and prefix is set to m_ you get a suggestion for getX()/setX(T) upon pressing Ctrl+Space; without it, you'd get a funny getM_x() suggestion.
The best solution to your problem may be setting up PMD/Checkstyle for your project and failing build in CI if invalid code is submitted.
I sometimes set all these up together, so Formatter/Code Style helps to write code which adheres to PMD/Checkstyle rules. Also I set up Save Actions in Eclipse so that I don't have to press Ctrl+Shift+F and Ctrl+Shift+O, etc. repeatedly, just a simple Ctrl+S does the work.

Related

Java UML editable component/lib

I have a task where we need to generate UML(or similar) from XML and will be able to edit text, property type and drag dependency row. But I can't find any Java lib or component wich will allow me to do such.
For example PlantText is a good lib but it does not allow to make edit.
If someone known such lib/compoment please share.
Thanks
EDIT:
Sorry, maybe I wasn't wrote clear. Actually, I need library which I can implement into my project, and after I will be able to generate UML from my project, then edit it and save into XML.
draw.io is very good site where you can create (not only) UML's and save them to XML file so in future you can edit it. The drawback is it is not automatic and must be drawn from scratch.

Java: Simple Validation API Validation Strategy Change

This is in reference to the question posted at org.netbeans.validation.api.ui.ValidationGroup.add() - How to specify ValidationStrategy?
I am trying to do something similar. Please guide me on what needs to be changed and where. I went through the given links but couldn't find the relevant info.
P.S.: Asking in a separate question because I can't comment on the original one due to lack of reputation points.
Regards
Uday
I found out what was required.
Check out the code from their repository (https://svn.kenai.com/svn/simplevalidation~src) and open ValidationAPI as a project in Netbeans (or whatever IDE you're using).
To change the default validation strategy you'll need to make the changes in ValidationGroup and SwingValidationGroup classes under org.netbeans.validation.api.ui and org.netbeans.validation.api.ui.swing respectively.
In these classes find ValidationStrategy.DEFAULT and replace it with the strategy you want (INPUT_VERIFIER, ON_FOCUS_LOSS, ON_CHANGE_OR_ACTION).
Build the project to generate a new jar and incorporate that jar in your own project.
That's it.

Translate English to some other Language in RAD or Eclipse

I have written comments in English in my Java files but now my client wants it in Spanish, So is there any tool/Plugin available in RAD or ECLIPSE IDE to convert all the comments in other language. I am using google translator to convert comments manually.
I'm not aware of any plugin like that. First, I would make sure the client really really wants this. Doing an automatic translate of highly technical text will not give a very good quality. I question if they will be usable at all, do a test translate of a couple of comments first to get approval.
If they really want something that is usable someone with language and technical skill would have to manually translate everything, which would take time/money.
But, if I had to do it, I would take the idea from this answer to automatically launch a web browser from Eclipse, and use the URL to google translate, https://translate.google.se/#en/es/${selected_text}, should work.
If the codebase is large and the comments can be easily found, such as a javadoc, I would write some script to automatically handle this. Google translate has an API you can use. See REST API doc
Every now and then a developer has to work on a code base that is in a language that is unknown to him. In this case, he would need to copy variable, class, method names to Google Translate to see what they actually mean.
The Source Code Translation in Eclipse tries to help such developers, by providing a popup with the translated words, when hovering the mouse over them. The plugin is able to handle compound words or phrases that use camelCase or underscore "_" as separation methods.
For the plugin to work, a properties file containing the word to be translated, and the translation needs to be created and added from the Preferences section of the plugin.
Add this URL to your Eclipse Installation to reach this solution's update site.
https://github.com/Testehan/TranslationPluginInstall/raw/master
In External Tools Configurations
Location : ${system_path:cmd.exe}
Arguments : /C start "" "https://translate.google.com/#en/fr/${selected_text}"

Applying a new code template to existing java file

We have lot of java files which were developed using a code formatter ,code style (has copyright info) templates. Now we decided to update the formatter and style template. Is it possible to update all the java files based on the new code formatter and code style templates?
It is a tedious process to manually go and edit all copy right statements in the java files. So if we could do it quickly, it will be very helpful for us.
We are using eclipse v3.4 for our development.
Eclipse 3.4 is quite old, so I'm not 100% sure this feature is available...
Right-click on the project or package you want to format, and select Source > Format.
That will only apply the format settings selected in Preferences/Java/ Code Style/Formatter. It will not add or alter code or comments. You choose a template when you create a new class/file.
yes, manually this works with Ctrl-Shift-f, which autoformats the current code / class, with the formatting rules.
For full automatic reformatting via batch you need further answers. But beware sometimes the rukles can destroy the readability of some special classes.
I would prefer manually go throug all classes, and apply Ctrl-Shift-f.
During this you might see, than some formatting rules should be adapted.

Create user variable in Intellij File Template

I am trying to use Intellij's file templates (not live templates) to help mitigate how much boilerplate code I use when making Services, daos, and their interfaces.
I am able to use all the system defined variables just fine, such as
${PACKAGE_NAME}
What I want though, is to be able to use my own variable names, like
${MY_USER_INPUT}
however, when i do this like above, I get an error
The documentation says :
It is also possible to specify arbitrary number of custom variables in format ${<VARIABLE_NAME>}.
and then Intellij is supposed to prompt the user for the value.
However, this just plain doesn't work for me. What am I missing?
Looks like a bug, submitted as IDEA-63628. Please watch/vote.
I use the custom variabeles in alot of template and ${MY_USER_INPUT} should work.
What error do you get ? what vesion of IntelliJ Do you use ?
In general stating "however, when i do this like above, I get an error" really isent helpfull people cannot guess whats wrong if you dont tell us, you should at least post a clear example of you file template and the exact error.

Categories

Resources