"Zhijun Hao" <haozhijun.fu...@gmail.com> wrote on 04/23/2012 08:47:17 AM
>
> Hi, I want to add another annotation to the current X10 system.
> I found the current X10 annotations are defined as public interfaces
> (in src-x10/x10/lang/annotations/), and I also found some code
> snippets in x10.compiler/src/x10, but I can’t understand the entire
mechanism.
>
Hi,
Adding annotations really has two stages.
To annotate something, all you need to do is define a new X10
interface that extends one of the Annotation interfaces. (There are a
number of these in x10.compiler.*, but there is nothing special about this
package; they could be defined anywhere). You can now annotate your code.
Of course, you may have wanted the compiler to understand your
annotation and do something different when it encounters a
class/field/method/etc. that has been annotated. To do this, you need to
modify the part of the compiler that you want to behave differently to
check to see if an annotation is present and if so to do something about
it. You'll find a number of example of this in the compiler. If you poke
around in the compiler and look at places where the annotationMatching
method is used, you'll see plenty of examples. Typically something like:
boolean inlineInClassDecl = false;
try {
Type annotation = xts.systemResolver().findOne
(HEADER_ANNOTATION);
if (!((X10Ext) dec.ext()).annotationMatching
(annotation).isEmpty()) {
inlineInClassDecl = true;
}
} catch (SemanticException e) {
/* Ignore exception when looking for annotation */
}
..... code that does something different depending on the value
of inlineInClassDecl ....
hope this helps,
--dave
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users