Automated conversion from XDoclet to annoations - java

Does anybody know of a way to convert xdoclet to annotations in an automated fashion? It seems to me that it should be possible to have equivalent annotations/annotation preprocessors for anything that xdoclet does but manually converting things is really tedious on large systems.

Offhand I don't know of anything that does this. However, it is possible to write: every JavaDoc object (such as MethodDoc) provides the position() method, which gives the source position of the associated declaration. Read the entire source file into an ArrayList by lines, for each tag prepend the appropriate annotation to the associated line (you don't want to add new lines to the list, because that would throw off the counts), then write the file back out.
An interesting solution, but I suspect that it will be better over the long run to do it manually, one set of tags at a time.

Related

Save values to file(e.g yml) in java

First of all this might be a dumb question and I searched for some days but didn't find an answer. So if there is an existing answer concerning my question, I would be grateful for a link.
I don't know if anyone of you ever coded Spigot, Paper or Bukkit, but there was a class called YamlConfiguration which had the following methods:
public FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
cfg.set(path.path2, "hello");
cfg.getInt/String/...(path.path2); (which obviously returns "hello")
cfg.save(file);
The produced file then looks like this:
path:
path2: "hello"
So you could basically save any value in those files and reuse them even if your program has been restarted.
I know have moved forward from Spigot/Paper to native Java and I'm missing something like that Yaml-thing. The only thing I found was a kind of a config file, where every time the whole file is overwritten, when I try to add values.
Can you show me a proper way of saving values to a file? (would be nice without libraries)
I'm missing sth like that Yaml-thing
SnakeYAML should have you covered. Without knowing anything about your use-case, it makes no sense to discuss its usage here since its documentation already does cover the general topics.
The only thing I found was a kind of a config file, where everytime the whole file is overwritten, when I try to add values.
Saving as YAML will always overwrite the complete file as well. Serialization does not really work with append-only. (Serialization is the term to search for when you want functionality like this, by the way.)
If you mean that previous values were deleted, that probably was because you didn't load the file's content before or some other coding error, but since you don't show your code, we can only speculate.
Can you show me a proper way of saving values to a file?
People will have quite different opinions on what would be a proper way and therefore it is not a good question to ask here. It also heavily depends on your use-case.
would be nice without libraries
So you're basically saying „previously I used a library which had a nice feature but I want to have that feature without using a library“. This stance won't get you far in today's increasingly modular software world.
For example, JAXB which offers (de)serialization from/to XML was previously part of Java SE, but has been removed as of Java SE 11 and is a separate library now.

Can `lucene 5.0.0`'s SmartChineseAnalyzer specify or add my custom dictionary?

The cnsmart chinese analyzer of lucene performs well.
In specific domain, though, I need to expand its dictionary.
I wonder whether cnsmart can support adding a custom dictionary or replacing the existing one?
SmartChineseAnalyzer remains experimental, and I don't see a good way to specify where to pull in a custom dictionary. There are some hooks for it, if you take a look in the AnalyzerProfile, and it seems like you should be able to load a custom dictionary via an "analysis.data.dir" system property. From the source:
// Try the system property:-Danalysis.data.dir=/path/to/analysis-data
ANALYSIS_DATA_DIR = System.getProperty("analysis.data.dir", "");
However, looking at the WordDictionary source, this looks like it is (still) going to only be loaded if the embedded dictionary fails to load. Since it is embedded in the jar, it generally would not be expected to ever fail.
Considering all that, probably the easiest way to use your own dictionary will be to grab the lucene-analyzers-smartcn-5.0.0.jar, extract it, replace org/apache/lucene/analysis/cn/smart/hhmm/coredict.mem with your dictionary, and rebuild the jar.
See LUCENE-1817 : it is impossible to use a custom dictionary for SmartChineseAnalyzer for some discussion on this. Rather old, but again, looking at the source, it looks like everything said there still applies.
All of this is assuming your dictionary is in a format that is readable by the analyzer. There is a bigramdict.mem alongside coredict.mem in the jar, presumably an expanded dictionary not in standard use due to performance concerns, so that might be worth trying as well.

Java- Quitting the programme midway and resuming where you left off?

I am doing a java project and have several methods. Would like to know if its possible to quit the programme after the 3rd method for example and then when resuming the programme it continues from there? Any information regarding this would be helpful
THank you
Not without some kind of external persistence mechanism, no.
Once the process is done, it's done.
Why do you want to do this? There may be a better solution.
Otherwise, it would be along the lines of saving data in some particular format (JSON, YAML, etc..) and then have a parser that could determine where the last program left off. It's somewhat vague, so it also depends on what you're attempting to "save".
Potentially could do something hacky if you ran the program with a wrapper.
Edit:
You could serialize your classes, which in turn would allow you to be able to save the fields of any objects you have, however everything you have would need to implement Serializable and be saved to a file.
So after a little bit of googling, I found that there is also the XStream library, which serializes objects to XML without needing to implement an interface. In that sense, you could serialize objects themselves, but wouldn't be able to, say, continue from the middle of a method. (Having a string you can parse to start in different locations could be one option).

Intellij IDEA String handling features and retriving messages from properties files

I have recently stumbled upon a neat feature in Intellij IDEA that has let me to question one of my practices. It's the String auto-complete. Basically, if I define a key-value pair in a properties file, and then begin typing a String in java code that has the save value as the key in the properties files, IDEA can auto-complete it. More, I can navigate to it with ctrl+click and can refactor it!
The practice that I was talking about is related to displaying a value from the properties file. I am currently using an enum for this, whose types have the same name as the keys in the properties file. I was doing this because I gained type checking and refactoring. But it seems that I can have the same benefits just by using strings in IDEA (well, it doesn't really give me type checking, but it's kind of close).
I was wondering if any of you are using simple String values for retrieving messages. Is this a good practice?
I don't think it's a good practice. You shouldn't depend on your IDE when you're developing application. If somebody elses uses e.g. eclipse he has a chance to mess up all this.I like solution with enums more than string only because it gives compile time checks. You can even build you enum so it also reads properties file and every item in enum contains both key and value from property file.
A compromise would be to have an enum with properties where enum value is the property string. This way you get type safety and IDEA will recognize that enum value comes from property and let you easily navigate to it.
Its probably better to use an Enum and to make everyone you work with use intellij, if they complain show them this question (and many others).
Also worth bearing in mind that some string values require compile time constants , which makes things a bit more complex.

How can I set globals to JSLint to ignore for a whole set of files?

I'd like to run JSLint4Java as part of my build process. I have about 1000 JS files in a library, and don't really want to add a
/*globals foo, bar, baz */
header to each of them -- especially since many of them are from an external library (Dojo). If I don't add the header, though, JSLint complains about the same five globals on nearly every single file. Is there a way to tell JSLint to ignore them? Some things I've thought of so far:
Some sort of AntFileMap task that creates a virtual directory hierarchy that's an exact copy of another hierarchy, but has a filter applied to each file (in this case, prepend with a /*globals */ header).
Hack JSLint4Java to accept a set of globals which it prepends as a comment to the beginning of every file it processes.
I've never seen anything like (1). (2) seems relatively easy, but I'd prefer to use original tools if possible. Any better suggestions?
From http://www.ohloh.net/p/jslint4java
News 2009-12-02. jslint4java 1.3.3 is
released. Noteworthy alterations: Add
support for the predef option, to
allow specifying a list of predefined
global variables.
Sounds like what you might be looking for. Try the --help option to get the syntax, maybe?
You can also use LintRoller - a Node.js utility for checking entire directories or projects against JSLint, JSHint and other validations.

Categories