Doxygen with custom annotations - java

I couldn't really find anythingon this anywhere: i'd like to use custom annotations with doxygen. To be more exact, I have an #android before every method thats supported on android, and would like doxygen to recognize, support and link his, similar to what it does with xrefitem. Is that possible?
The ultimate awesomeness would be to be able to do some light inference on this. For example, i'd like to infer he supportion level of a class from the percentage of it's method that are annotated wih android. I knowhat i can do somthing like that with java and inspectors, i'm just not sure if i could do this with doxygen.
Thanks a lot!

If you start with reading the documentation for \xrefitem here:
http://www.doxygen.org/commands.html#cmdxrefitem
you'll find that you can define custom commands via ALIASES, which are documented in more detail here
http://www.doxygen.org/custcmd.html
The computation of a 'coverage level' is not directly supported. You could check if you can use doxygen's XML output for that (see config option GENERATE_XML).

Related

Can I use custom annotations to classify Java classes?

Is it possible that use self defined Annotation to classify java class into different product function ? (Following are my thoughts)
If not, are there any other method to achieve the same purpose in Android project?
Step1: use self defined annotation to make clear java class's function
#SelfDefinedAnnotation( "product-function-a" )
class MyClass {
void func() {
//do something
}
}
Step2: during building period, generate a mapping file like this
MyClass -> product-function-a
YourClass -> product-function-b
I'm not sure about android (never worked with it), but in pure java its possible for sure.
You should define an annotation with retention policy SOURCE and since you're talking about build time, define an annotation processor. This is something that is "hooked" into the compilation process and allows creating such a mapping (I assume you want to store it in some kind of file, maybe *.properties file, or even generate a java source code with these definitions.
The annotation processor is broad topic, there are many ways to register them, so it pretty much depends on how do you build your stuff exactly, but its a general direction.
Please check out this tutorial it talks about annotation processors, the ways to register them, to associate with your custom annotation and so forth.
One suggestion though, if you're about to generate Java Source class and not just a properties file, this tutorial goes "low level" and tries to prepare the syntax by itself, I suggest using a much nicer (IMO) Java Poet library that will help to generate a proper java code

How does BeanProperty.create work?

I'm trying to get beans binding to work, because it seems like the closest thing to functional reactive programming I can get NetBeans GUI builder to give me. I'm trying to understand how the code in http://javakenai-dev.cognisync.net/pub/a/2008/03/20/synchronizing-properties-with-beans-binding.html works. In particular, I'm trying to figure out how the TintedPanel example works. It seems like BeanProperty.create either has to do voodoo magic, access private fields, or take the string it gets, capitalize the first letter, prepend "get" or "set" to that, and do runtime introspection to change the string into a method it can call. Can someone point me at complete source code for the TintedPanel example, or explain to me how BeanProperty.create works (preferably with a self-contained working example)?
It looks like JSR 295 the beans binding spec is withdrawn:
https://jcp.org/en/jsr/detail?id=295
There are a couple other SO posts with suggestions for other libraries, or pointers to the old beans binding source:
What will replace Beans Binding in Java 7?
What is the state of Java Beans Binding?
Good luck!

Write An Annotation to Constrain Class/Method Naming in Java?

I'm trying to find a way to use annotation to constrain namings in Java. Might be something looks like this:
#Getter
public String getXxx();
And when the method name does not meet the convention, for example not started with "get", the compiler will throw some error. So that during the coding progress in IDE, such like eclipse, the developer will be able to notice.
I'm getting some ideas from this article, but it's too long and complex for me.
Any simpler examples or directions would be very nice.
Check out the custom annotations guide HERE
It also shows you how to use reflection to get info from the annotated elements, you could easily use this to fetch the method name and verify whether it meets your convention and take appropriate actions etc...
Didn't get to do it myself but it appears to be possible. You can do some background reading or go directly to the 3rd party tool they link.

Dependency Injection With Annotations

I would like to build my own custom DI framework based on Java annotations and I need a little direction to get started. I know it would be much easier to use one of the many wonderful frameworks out there such as guice or spring, but for the sake of my own curiosity, i'd like to build my own.
I'm not very familiar with annotations, so i'm having a bit of trouble finding resources and would really appreciate someone just sort of spelling out a few of the steps i'll need to take to get started.
As fore mentioned, id like to take a factory approach and somehow label my getters with an #Resource or #Injectable type annotation, and then in my business classes be able to set my variable dependencies with an #Inject annotation and have the resource automatically available.
Does anyone have any sort of resource they can pass along to help me understand the process of tagging methods based on annotations and then retrieving values from a separate class based on an annotation. A little direction is all I need, something to get me started. And of course i'll be happy to post a little code sample here once I get going, for the sake of others future reading of course.
EDIT
The resources I am using to put this together:
Java Reflection: Annotations
How to find annotations in a given package: Stack Overflow ?
Scanning Annotations at Runtime
I have not actually finished writing this yet, but the basic task list is going to be as follows (for anyone who might be interested in doing something similar in the future)
At class runtime scan for all #Inject fields and get object type.
Scan all classes (or just a specific package of classes (I haven't
decided yet)) for annotated methods #InjectableResource.
Loop all annotated methods and find the method that returns the
object type I am looking for.
Run the method and get the dependency.
It will also be helpful to note that when scanning all the classes I will be using a library called Javassist. Basically what this does is allows me to read the bytecode information of each class without actually loading the class. So I can read the annotation strings without creating serious memory problems.
Interesting that you want to build your own. I love Google Guice - it makes code so elegant and simple.
I've used this guide before which I found pretty useful for learning about annotations and how you can pull them out of classes and methods.
You will have to define your own Annotations which is done using #interface. Then you will have to define some kind of class for doing bindings e.g. where you see an interface bind in this concrete class. Finally, you will need some logic to pull it altogether e.g. go through each class, find each annotation, and then find a suitable binding.
Give consideration to things like lazy instantiation through Reflections and singletons. Guice, for example, allows you to use a singleton so your only using one instance of the concrete class, or you can bind a new version each time.
Good luck!
Have a look at the following methods:
java/lang/Class.html#getAnnotation(java.lang.Class)
java/lang/Class.html#getAnnotations()
java/lang/Class.html#getDeclaredAnnotations()
Methods of the same name also exist for the java/lang/reflect/Method, java/lang/reflect/Field and java/lang/reflect/Constructor classes.
So in order to use these sorts of methods, you need to know a bit about Java reflection.

add class name to element in uibinder xml file

The following replaces any current css class names. It appears to call setStyleName.
<g:DecoratorPanel styleName="{style.myCssClass}">
What I really want to do is add a class name, like calling addStyleName.
Is it possible to do what I'm attempting?
Use addStyleNames in such situations, like this:
<g:DecoratorPanel addStyleNames="{style.myCssClass}">
It's a little trick I picked up on the GWT's Google Group - too bad it's not (?) mentioned in the official documentation.
PS: I'm actually missing a really comprehensive documentation for UiBinder. I grepped the GWT sources for addStyleNames and found this file: WidgetBasedUi.ui.xml - it seems to contain some interesting use cases for UiBinder, including the one with addStyleNames.
If someone knows any other good/secret references for UiBinder, please share :)
Yes addStyleNames is the solution. And it is actually mentioned in the documentation: UiObject. See section "Use in UiBinder Templates".

Categories