文字
分享


JavaTM 2 Platform
Standard Ed. 6

javax.lang.model.element
接口 AnnotationValueVisitor<R,P>

类型参数:
R - 此 visitor 的方法的返回类型
所有已知实现类:
AbstractAnnotationValueVisitor6, SimpleAnnotationValueVisitor6

1

public interface <b>AnnotationValueVisitor<R,P></b>

注释类型元素值的 visitor,使用 visitor 设计模式的变体。标准 visitor 基于类型层次结构成员的具体类型进行调度,与它不同,此 visitor 基于存储数据的类型进行调度;对于存储,没有不同的子类,例如 boolean 值和 int 值。在编译时某个值的类型未知时,实现此接口的类被用来对该值进行操作。在将 visitor 传递给某个值的 accept 方法时,适用于该值的 visitXYZ 方法将被调用。

如果附加参数 pnull,则实现此接口的类有可能抛出 NullPointerException;有关详细信息,请参阅实现类的文档。

警告: 以后可能会向此接口添加一些方法,以适应添加到 Java™ 编程语言未来版本中的新(当前未知的)语言结构。所以,直接实现此接口的 visitor 类可能与平台的未来版本不兼容。为了避免这种不兼容性,建议 visitor 实现扩展实现此接口的抽象 visitor 类。不过,API 通常应该使用此 visitor 接口作为参数类型、返回类型等,而不是将它作为抽象类之一。

从以下版本开始:
1.6

方法摘要
 R visit(AnnotationValue av)
          等效于 v.visit(av, null) 的便捷方法。
 R visit(AnnotationValue av, P p)
          访问注释值。
 R visitAnnotation(AnnotationMirror a, P p)
          访问注释中的 annotation 值。
 R visitArray(List<? extends AnnotationValue> vals, P p)
          访问注释中的 array 值。
 R visitBoolean(boolean b, P p)
          访问注释中的 boolean 值。
 R visitByte(byte b, P p)
          访问注释中的 byte 值。
 R visitChar(char c, P p)
          访问注释中的 char 值。
 R visitDouble(double d, P p)
          访问注释中的 double 值。
 R visitEnumConstant(VariableElement c, P p)
          访问注释中的 enum 值。
 R visitFloat(float f, P p)
          访问注释中的 float 值。
 R visitInt(int i, P p)
          访问注释中的 int 值。
 R visitLong(long i, P p)
          访问注释中的 long 值。
 R visitShort(short s, P p)
          访问注释中的 short 值。
 R visitString(String s, P p)
          访问注释中的 string 值。
 R visitType(TypeMirror t, P p)
          访问注释中的 type 值。
 R visitUnknown(AnnotationValue av, P p)
          访问未知种类的注释值。
 

方法详细信息

visit

1

2

R <b>visit</b>(AnnotationValue av,

        P p)

访问注释值。

参数:
av - 要访问的值
p - 特定于 visitor 的参数
返回:
特定于 visitor 的结果

visit

1

R <b>visit</b>(AnnotationValue av)

等效于 v.visit(av, null) 的便捷方法。

参数:
av - 要访问的值
返回:
特定于 visitor 的结果

visitBoolean

1

2

R <b>visitBoolean</b>(boolean b,

               P p)

访问注释中的 boolean 值。

参数:
b - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitByte

1

2

R <b>visitByte</b>(byte b,

            P p)

访问注释中的 byte 值。

参数:
b - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitChar

1

2

R <b>visitChar</b>(char c,

            P p)

访问注释中的 char 值。

参数:
c - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitDouble

1

2

R <b>visitDouble</b>(double d,

              P p)

访问注释中的 double 值。

参数:
d - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitFloat

1

2

R <b>visitFloat</b>(float f,

             P p)

访问注释中的 float 值。

参数:
f - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitInt

1

2

R <b>visitInt</b>(int i,

           P p)

访问注释中的 int 值。

参数:
i - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitLong

1

2

R <b>visitLong</b>(long i,

            P p)

访问注释中的 long 值。

参数:
i - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitShort

1

2

R <b>visitShort</b>(short s,

             P p)

访问注释中的 short 值。

参数:
s - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitString

1

2

R <b>visitString</b>(String s,

              P p)

访问注释中的 string 值。

参数:
s - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitType

1

2

R <b>visitType</b>(TypeMirror t,

            P p)

访问注释中的 type 值。

参数:
t - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitEnumConstant

1

2

R <b>visitEnumConstant</b>(VariableElement c,

                    P p)

访问注释中的 enum 值。

参数:
c - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitAnnotation

1

2

R <b>visitAnnotation</b>(AnnotationMirror a,

                  P p)

访问注释中的 annotation 值。

参数:
a - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitArray

1

2

R <b>visitArray</b>(List<? extends AnnotationValue> vals,

             P p)

访问注释中的 array 值。

参数:
vals - 要访问的值
p - 特定于 visitor 的参数
返回:
访问结果

visitUnknown

1

2

R <b>visitUnknown</b>(AnnotationValue av,

               P p)

访问未知种类的注释值。如果语言有所发展并且新类型的值可以存储在注释中,则会发生这种情况。

参数:
av - 要访问的未知值
p - 特定于 visitor 的参数
返回:
访问结果
抛出:
UnknownAnnotationValueException - visitor 实现可以有选择地抛出此异常

JavaTM 2 Platform
Standard Ed. 6

提交错误或意见
有关更多的 API 参考资料和开发人员文档,请参阅 Java 2 SDK SE 开发人员文档。该文档包含更详细的、面向开发人员的描述,以及总体概述、术语定义、使用技巧和工作代码示例。

版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。

上一篇:AnnotationValue下一篇:Element