No subject


Tue Jun 24 21:06:34 EDT 2008


types, or use any other method to get annotation information.

Not every tree has an assoicated Element. In particular any tree node =
within a method does not have an Element. However, you can use =
getUnderlyingType() in AnnotatedTypeMirror to get the TypeMirror. From =
there if the type is a DeclaredType (check with getKind()) you can cast =
to DeclaredType and get its Element. Pass the Element back into the =
AnnotatedTypeFactory to get the annotations.

Note: doing this will give you the element of the declared type, not the =
element of the declaration. E.g.

@A public class ClsA { }
public class ClsB {
   private @B ClsA fieldA=3D new ClsA();
   public void m() {
       fieldA.toString();
   }
}

If you use the above technique to get the Element, you will get =
annotation A, not annotation B. The AnnotatedTypeMirror will (by =
default) annotate all uses of fieldA with @B. In general you should not =
ask Element for annotations, as this ignores any implicit annotations =
that might be added, and those that can only be added in JSR-308 (e.g. =
class A extends @Anno B).
On Dec 18, 2008, at 9:21 AM, Chester Chen wrote:


1.  How do I traverse over an ancestors or referenced classes ?=20

    Once I found the Tree node in the AST, how to I find the class, =
parent class and their annoation information ?=20

2.How I can get Element from a Tree Node ?=20

=20


Thanks

Chester

_______________________________________________
JSR308 mailing list
JSR308 at lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/jsr308




------_=_NextPart_001_01C9614A.1371656C
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">


<META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR></HEAD>
<BODY=20
style=3D"word-wrap: break-word; webkit-nbsp-mode: space; =
webkit-line-break: after-white-space">
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>Artemus, </SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>&nbsp;&nbsp; Thanks for the detailed reply.=20
</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>&nbsp;&nbsp; I did not follow&nbsp;your last =
point :=20
</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>&nbsp;&nbsp;&nbsp; &gt;"....you will get =
annotation A,=20
not&nbsp;annotation&nbsp;B. The AnnotatedTypeMirror will (by default) =
annotate=20
all uses of fieldA with @B."</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>&nbsp;</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>&nbsp;&nbsp; do you mean to =
say</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>&nbsp;</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D188224519-18122008><FONT=20
color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>&nbsp;&nbsp;&nbsp; ....you will get =
annotation A,=20
not&nbsp;annotation&nbsp;B. The AnnotatedTypeMirror will (by default) =
annotate=20
all uses of fieldA with<STRONG> <FONT=20
color=3D#ff0000>@A</FONT></STRONG>.</SPAN></FONT></SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D188224519-18122008><FONT=20
color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008></SPAN></FONT></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D188224519-18122008><FONT=20
color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D188224519-18122008>&nbsp;&nbsp;Any=20
way, I will tries this out. </SPAN></FONT></SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D188224519-18122008><FONT=20
color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008></SPAN></FONT></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D188224519-18122008><FONT=20
color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>Thanks</SPAN></FONT></SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D188224519-18122008><FONT=20
color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008></SPAN></FONT></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D188224519-18122008><FONT=20
color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D188224519-18122008>Chester</SPAN></FONT></SPAN></FONT></DIV>
<BLOCKQUOTE style=3D"MARGIN-RIGHT: 0px">
  <DIV align=3Dleft class=3DOutlookMessageHeader dir=3Dltr><FONT =
face=3DTahoma=20
  size=3D2>-----Original Message-----<BR><B>From:</B> Artemus Harper=20
  [mailto:subanark at gmail.com]<BR><B>Sent:</B> Thursday, December 18, =
2008 10:28=20
  AM<BR><B>To:</B> Chester Chen<BR><B>Cc:</B> JSR 308 (Annotations) =
mailing=20
  list<BR><B>Subject:</B> Re: [JSR308] Other questions related to =
Annotation=20
  processing<BR><BR></DIV></FONT>You need to ask the =
AnnotatedTypeFactory for a=20
  AnnotatedTypeMirror for the tree node. E.g.
  <DIV>AnnotatedTypeMirror type =3D =
atypeFactory.getAnnotatedType(node);</DIV>
  <DIV><BR></DIV>
  <DIV>From AnnotatedTypeMirror you can use directSuperTypes() to get =
the super=20
  types, or use any other method to get annotation information.</DIV>
  <DIV><BR></DIV>
  <DIV>Not every tree has an assoicated Element. =
In&nbsp;particular&nbsp;any=20
  tree node within a method does not have an Element. However, you can =
use=20
  getUnderlyingType() in AnnotatedTypeMirror to get the TypeMirror. From =
there=20
  if the type is a DeclaredType (check with getKind()) you can cast to=20
  DeclaredType and get its Element. Pass the Element back into the=20
  AnnotatedTypeFactory to get the annotations.</DIV>
  <DIV><BR></DIV>
  <DIV>Note: doing this will give you the element of the declared type, =
not the=20
  element of the&nbsp;declaration. E.g.</DIV>
  <DIV><BR></DIV>
  <DIV>@A public class ClsA { }</DIV>
  <DIV>public class ClsB {</DIV>
  <DIV>&nbsp;&nbsp; private @B ClsA fieldA=3D new ClsA();</DIV>
  <DIV>&nbsp;&nbsp; public void m() {</DIV>
  <DIV>&nbsp;&nbsp; &nbsp; &nbsp; fieldA.toString();</DIV>
  <DIV>&nbsp;&nbsp; }</DIV>
  <DIV>}</DIV>
  <DIV><BR></DIV>
  <DIV>If you use the above technique to get the Element, you will get=20
  annotation A, not&nbsp;annotation&nbsp;B. The AnnotatedTypeMirror will =
(by=20
  default) annotate all uses of fieldA with @B. In general you should =
not ask=20
  Element for annotations, as this ignores any implicit annotations that =
might=20
  be added, and those that can only be added in JSR-308 (e.g. class A =
extends=20
  @Anno B).</DIV>
  <DIV>
  <DIV>
  <DIV>On Dec 18, 2008, at 9:21 AM, Chester Chen wrote:</DIV><BR=20
  class=3DApple-interchange-newline>
  <BLOCKQUOTE type=3D"cite">
    <DIV>
    <BLOCKQUOTE style=3D"MARGIN-RIGHT: 0px">
      <P><FONT size=3D2><FONT color=3D#0000ff><FONT face=3DArial><SPAN=20
      class=3D571091617-18122008>1. &nbsp;</SPAN>How do I traverse over =
an=20
      ancestors or referenced classes<SPAN class=3D571091617-18122008>=20
      ?&nbsp;</SPAN></FONT></FONT></FONT></P>
      <P><FONT size=3D2><FONT color=3D#0000ff><FONT face=3DArial><SPAN=20
      class=3D571091617-18122008>&nbsp;&nbsp;&nbsp; Once I found =
the&nbsp;Tree=20
      node in&nbsp;the AST, how to I&nbsp;find the class,=20
      parent&nbsp;class&nbsp;and their annoation&nbsp;information=20
      ?&nbsp;</SPAN></FONT></FONT></FONT></P>
      <P><FONT size=3D2><FONT color=3D#0000ff><FONT face=3DArial><SPAN=20
      class=3D571091617-18122008>2.How I can get Element from a Tree =
Node ?=20
      </SPAN></FONT></FONT></FONT></P>
      <DIV><FONT size=3D2><FONT color=3D#0000ff><FONT face=3DArial><SPAN =

      class=3D571091617-18122008></SPAN></FONT></FONT></FONT>&nbsp;<BR=20
      class=3Dwebkit-block-placeholder></DIV>
      <P><FONT size=3D2><FONT color=3D#0000ff><FONT face=3DArial><SPAN=20
      class=3D571091617-18122008>Thanks</SPAN></FONT></FONT></FONT></P>
      <P><FONT size=3D2><FONT color=3D#0000ff><FONT face=3DArial><SPAN=20
      =
class=3D571091617-18122008>Chester</SPAN></FONT></FONT></FONT></P></BLOCK=
QUOTE></DIV>_______________________________________________<BR>JSR308=20
    mailing list<BR><A=20
    =
href=3D"mailto:JSR308 at lists.csail.mit.edu">JSR308 at lists.csail.mit.edu</A>=
<BR>https://lists.csail.mit.edu/mailman/listinfo/jsr308<BR></BLOCKQUOTE><=
/DIV><BR></DIV></BLOCKQUOTE></BODY></HTML>

------_=_NextPart_001_01C9614A.1371656C--



More information about the JSR308 mailing list