有没有人有java注释“java.lang.Synthetic”的背景?

时间:2013-09-12 16:08:01

标签: java annotations

有没有人对java注释“java.lang.Synthetic”有背景知识。我在JavaEE企业应用程序中列出注释事件时遇到了它。注释发生在com.sun.xml包中的几个类上。我找不到这个注释的文档。例如,它是一个官方注释,由java编译器生成以指示合成访问器(例如,参见Synthetic accessor method warning)?这似乎不太可能,因为没有可用的文档。但是,在“java.lang”包中的放置给出了一些官方外观的注释。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

仔细阅读ASM表明这是ASM添加的“虚拟”参数注释。

请参阅:

http://asm.ow2.org/index.html

http://websvn.ow2.org/filedetails.php?repname=asm&path=%2Ftrunk%2Fasm%2Fsrc%2Forg%2Fobjectweb%2Fasm%2FClassReader.java

使用:

private void readParameterAnnotations(int v, final String desc,
        final char[] buf, final boolean visible, final MethodVisitor mv) {
    int i;
    int n = b[v++] & 0xFF;
    // workaround for a bug in javac (javac compiler generates a parameter
    // annotation array whose size is equal to the number of parameters in
    // the Java source file, while it should generate an array whose size is
    // equal to the number of parameters in the method descriptor - which
    // includes the synthetic parameters added by the compiler). This work-
    // around supposes that the synthetic parameters are the first ones.
    int synthetics = Type.getArgumentTypes(desc).length - n;
    AnnotationVisitor av;
    for (i = 0; i < synthetics; ++i) {
        // virtual annotation to detect synthetic parameters in MethodWriter
        av = mv.visitParameterAnnotation(i, "Ljava/lang/Synthetic;", false);
        if (av != null) {
            av.visitEnd();
        }
    }
    for (; i < n + synthetics; ++i) {
        int j = readUnsignedShort(v);
        v += 2;
        for (; j > 0; --j) {
            av = mv.visitParameterAnnotation(i, readUTF8(v, buf), visible);
            v = readAnnotationValues(v + 2, buf, true, av);
        }
    }
}