KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > annotation > compiler > AnnotationDocletTag


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop.annotation.compiler;
23
24 import com.thoughtworks.qdox.model.AbstractJavaEntity;
25 import com.thoughtworks.qdox.model.DocletTag;
26
27 import org.jboss.aop.annotation.factory.duplicate.ast.ASTAnnotation;
28 import org.jboss.aop.annotation.factory.duplicate.ast.ASTStart;
29 import org.jboss.aop.annotation.factory.duplicate.ast.AnnotationParser;
30 import org.jboss.aop.annotation.factory.duplicate.ast.ParseException;
31
32 import java.io.StringReader JavaDoc;
33 import java.util.Map JavaDoc;
34
35 /**
36  * Comment
37  *
38  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
39  * @version $Revision: 57019 $
40  *
41  **/

42 public class AnnotationDocletTag implements DocletTag
43 {
44    private static final long serialVersionUID = 1L;
45    
46    private String JavaDoc name;
47    private final String JavaDoc value;
48    private final int lineNumber;
49    private ASTAnnotation ast;
50
51    private AbstractJavaEntity owner;
52
53    public AnnotationDocletTag(String JavaDoc name, String JavaDoc value, int lineNumber)
54    {
55       this.name = name;
56       this.value = value;
57       this.lineNumber = lineNumber;
58       if (name.startsWith("@"))
59       {
60          if (name.indexOf('(') != -1)
61          {
62             throw new RuntimeException JavaDoc("illegal annotation syntax for doclet at line number " + lineNumber + ". You should have a space after the tag name otherwise the compiler messes up. " + name + " ***value=" + value);
63             /* Can't do this because there may be a space in a string @annotation("hello world")
64             if (value == null) value = "";
65             String full = name + value;
66             int index = full.indexOf('(');
67             name = full.substring(0, index);
68             value = full.substring(index);
69             */

70          }
71          AnnotationParser parser = new AnnotationParser(new StringReader JavaDoc(name + value));
72          try
73          {
74             ASTStart start = parser.Start();
75             ast = (ASTAnnotation) start.jjtGetChild(0);
76          }
77          catch (ParseException e)
78          {
79             throw new RuntimeException JavaDoc(e); //To change body of catch statement use Options | File Templates.
80
}
81          this.name = name.substring(1);
82       }
83    }
84
85    public AnnotationDocletTag(String JavaDoc name, String JavaDoc value)
86    {
87       this(name, value, 0);
88    }
89
90    public ASTAnnotation getAnnotation()
91    {
92       return ast;
93    }
94
95    public String JavaDoc getName()
96    {
97       return name;
98    }
99
100    public String JavaDoc getValue()
101    {
102       return value;
103    }
104
105    public String JavaDoc[] getParameters()
106    {
107       return null;
108    }
109
110    public Map JavaDoc getNamedParameterMap()
111    {
112       return null;
113    }
114
115    public String JavaDoc getNamedParameter(String JavaDoc key)
116    {
117       return null;
118    }
119
120    public int getLineNumber()
121    {
122       return lineNumber;
123    }
124
125    public final AbstractJavaEntity getContext()
126    {
127       return owner;
128    }
129
130    public void setContext(AbstractJavaEntity owner)
131    {
132       this.owner = owner;
133    }
134
135 }
136
Popular Tags