com.sun.tools.classfile.Annotation Java Examples

The following examples show how to use com.sun.tools.classfile.Annotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAnnotationInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void testElementValue(
        TestResult testResult,
        ClassFile classFile,
        Annotation.element_value element_value)
        throws ConstantPoolException {
    testTag(testResult, element_value.tag);
    Annotation ev = ((Annotation.Annotation_element_value) element_value).annotation_value;
    testResult.checkEquals(
            classFile.constant_pool.getUTF8Info(ev.type_index).value,
            String.format("L%s;", annotationName),
            "type_index");
    for (int i = 0; i < ev.num_element_value_pairs; ++i) {
        Annotation.element_value_pair pair = ev.element_value_pairs[i];
        Pair expectedPair = annotation.elementValues.get(i);
        expectedPair.elementValue.testElementValue(testResult, classFile, pair.value);
        testResult.checkEquals(
                classFile.constant_pool.getUTF8Info(pair.element_name_index).value,
                expectedPair.elementName,
                "element_name_index");
    }
}
 
Example #2
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void parseAnnotation(Annotation anno, Element p) {
    Element ea = new Element("Annotation");
    ea.setAttr("name", "" + x.getCpString(anno.type_index));
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element evpe = new Element("Element");
        evpe.setAttr("tag", "" + evp.value.tag);
        evpe.setAttr("value", x.getCpString(evp.element_name_index));
        Element child = aev.visit(evp.value, evpe);
        if (child != null) {
            evpe.add(child);
        }
        ea.add(evpe);
    }
    ea.trimToSize();
    p.add(ea);
}
 
Example #3
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void parseAnnotation(Annotation anno, Element p) {
    Element ea = new Element("Annotation");
    ea.setAttr("name", "" + x.getCpString(anno.type_index));
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element evpe = new Element("Element");
        evpe.setAttr("tag", "" + evp.value.tag);
        evpe.setAttr("value", x.getCpString(evp.element_name_index));
        Element child = aev.visit(evp.value, evpe);
        if (child != null) {
            evpe.add(child);
        }
        ea.add(evpe);
    }
    ea.trimToSize();
    p.add(ea);
}
 
Example #4
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void parseAnnotation(Annotation anno, Element p) {
    Element ea = new Element("Annotation");
    ea.setAttr("name", "" + x.getCpString(anno.type_index));
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element evpe = new Element("Element");
        evpe.setAttr("tag", "" + evp.value.tag);
        evpe.setAttr("value", x.getCpString(evp.element_name_index));
        Element child = aev.visit(evp.value, evpe);
        if (child != null) {
            evpe.add(child);
        }
        ea.add(evpe);
    }
    ea.trimToSize();
    p.add(ea);
}
 
Example #5
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void parseAnnotation(Annotation anno, Element p) {
    Element ea = new Element("Annotation");
    ea.setAttr("name", "" + x.getCpString(anno.type_index));
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element evpe = new Element("Element");
        evpe.setAttr("tag", "" + evp.value.tag);
        evpe.setAttr("value", x.getCpString(evp.element_name_index));
        Element child = aev.visit(evp.value, evpe);
        if (child != null) {
            evpe.add(child);
        }
        ea.add(evpe);
    }
    ea.trimToSize();
    p.add(ea);
}
 
Example #6
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void parseAnnotation(Annotation anno, Element p) {
    Element ea = new Element("Annotation");
    ea.setAttr("name", "" + x.getCpString(anno.type_index));
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element evpe = new Element("Element");
        evpe.setAttr("tag", "" + evp.value.tag);
        evpe.setAttr("value", x.getCpString(evp.element_name_index));
        Element child = aev.visit(evp.value, evpe);
        if (child != null) {
            evpe.add(child);
        }
        ea.add(evpe);
    }
    ea.trimToSize();
    p.add(ea);
}
 
Example #7
Source File: ClassReader.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute ripa,
                                                         Element p) {
    Element e = new Element(x.getCpString(ripa.attribute_name_index));
    for (Annotation[] pa : ripa.parameter_annotations) {
        parseAnnotations(pa, e);
    }
    p.add(e);
    return null;
}
 
Example #8
Source File: ClassReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute ripa,
                                                         Element p) {
    Element e = new Element(x.getCpString(ripa.attribute_name_index));
    for (Annotation[] pa : ripa.parameter_annotations) {
        parseAnnotations(pa, e);
    }
    p.add(e);
    return null;
}
 
Example #9
Source File: ClassReader.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute rvpa,
                                                       Element p) {
    Element e = new Element(x.getCpString(rvpa.attribute_name_index));
    for (Annotation[] pa : rvpa.parameter_annotations) {
       parseAnnotations(pa, e);
    }
    p.add(e);
    return null;
}
 
Example #10
Source File: ClassReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitArray(Array_element_value a, Element p) {
 Element el = new Element("Array");
    for (Annotation.element_value v : a.values) {
       Element child = visit(v, el);
       if (child != null) {
           el.add(child);
       }
    }
    el.trimToSize();
    return el;
}
 
Example #11
Source File: TestAnnotationInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void testElementValue(TestResult testResult,
                             ClassFile classFile,
                             Annotation.element_value element_value)
        throws ConstantPoolException {
    testTag(testResult, element_value.tag);
    Annotation.Primitive_element_value ev =
            (Annotation.Primitive_element_value) element_value;
    ConstantPool.CONSTANT_Double_info info = (ConstantPool.CONSTANT_Double_info)
            classFile.constant_pool.get(ev.const_value_index);
    testResult.checkEquals(info.value, value, "const_value_index");
}
 
Example #12
Source File: TestAnnotationInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void testElementValue(
        TestResult testResult,
        ClassFile classFile,
        Annotation.element_value element_value)
        throws ConstantPoolException {
    testTag(testResult, element_value.tag);
    Annotation.Class_element_value ev = (Annotation.Class_element_value) element_value;
    String expectedClassName = className.replace(".class", "");
    expectedClassName = mappedClassName.getOrDefault(expectedClassName,
            String.format("Ljava/lang/%s;", expectedClassName));
    testResult.checkEquals(
            classFile.constant_pool.getUTF8Info(ev.class_info_index).value,
            expectedClassName, "class_info_index : " + expectedClassName);
}
 
Example #13
Source File: ClassReader.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute ripa,
                                                         Element p) {
    Element e = new Element(x.getCpString(ripa.attribute_name_index));
    for (Annotation[] pa : ripa.parameter_annotations) {
        parseAnnotations(pa, e);
    }
    p.add(e);
    return null;
}
 
Example #14
Source File: TestAnnotationInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void testElementValue(TestResult testResult,
                             ClassFile classFile,
                             Annotation.element_value element_value)
        throws ConstantPoolException {
    testTag(testResult, element_value.tag);
    Annotation.Primitive_element_value ev =
            (Annotation.Primitive_element_value) element_value;
    ConstantPool.CONSTANT_Integer_info info =
            (ConstantPool.CONSTANT_Integer_info) classFile.constant_pool.get(ev.const_value_index);
    testResult.checkEquals(info.value, value, "const_value_index : " + value);
}
 
Example #15
Source File: CreateSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private Annotation[][] createParameterAnnotations(List<CPInfo> constantPool, List<List<AnnotationDescription>> desc) {
    Annotation[][] result = new Annotation[desc.size()][];
    int i = 0;

    for (List<AnnotationDescription> paramAnnos : desc) {
        result[i++] = createAnnotations(constantPool, paramAnnos);
    }

    return result;
}
 
Example #16
Source File: AnnotationWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void write(Annotation annot, boolean resolveIndices) {
    writeDescriptor(annot.type_index, resolveIndices);
    boolean showParens = annot.num_element_value_pairs > 0 || !resolveIndices;
    if (showParens)
        print("(");
    for (int i = 0; i < annot.num_element_value_pairs; i++) {
        if (i > 0)
            print(",");
        write(annot.element_value_pairs[i], resolveIndices);
    }
    if (showParens)
        print(")");
}
 
Example #17
Source File: ClassReader.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute rvpa,
                                                       Element p) {
    Element e = new Element(x.getCpString(rvpa.attribute_name_index));
    for (Annotation[] pa : rvpa.parameter_annotations) {
       parseAnnotations(pa, e);
    }
    p.add(e);
    return null;
}
 
Example #18
Source File: AnnotationDefaultVerifier.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void testElementValue(
        TestResult testCase,
        ClassFile classFile,
        Annotation.element_value element_value,
        String[] values) throws ConstantPool.InvalidIndex {
    Annotation.Primitive_element_value ev =
            (Annotation.Primitive_element_value) element_value;
    ConstantPool.CONSTANT_Integer_info info =
            (ConstantPool.CONSTANT_Integer_info)
                    classFile.constant_pool.get(ev.const_value_index);
    testCase.checkEquals(info.value, Integer.parseInt(values[0]), "const_value_index");
}
 
Example #19
Source File: ClassReader.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitAnnotation(Annotation_element_value a, Element p) {
    Element el = new Element("Annotation");
    Annotation anno = a.annotation_value;
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element child = visit(evp.value, el);
        if (child != null) {
            el.add(child);
        }
    }
    el.trimToSize();
    return el;
}
 
Example #20
Source File: AnnotationDefaultVerifier.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void testElementValue(
        TestResult testCase,
        ClassFile classFile,
        Annotation.element_value element_value,
        String[] values) throws ConstantPool.InvalidIndex {
    Annotation.Primitive_element_value ev =
            (Annotation.Primitive_element_value) element_value;
    ConstantPool.CONSTANT_Float_info info =
            (ConstantPool.CONSTANT_Float_info)
                    classFile.constant_pool.get(ev.const_value_index);
    testCase.checkEquals(info.value, Float.parseFloat(values[0]), "const_value_index");
}
 
Example #21
Source File: AnnotationWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void write(Annotation annot, boolean resolveIndices) {
    writeDescriptor(annot.type_index, resolveIndices);
    boolean showParens = annot.num_element_value_pairs > 0 || !resolveIndices;
    if (showParens)
        print("(");
    for (int i = 0; i < annot.num_element_value_pairs; i++) {
        if (i > 0)
            print(",");
        write(annot.element_value_pairs[i], resolveIndices);
    }
    if (showParens)
        print(")");
}
 
Example #22
Source File: ClassReader.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute rvpa,
                                                       Element p) {
    Element e = new Element(x.getCpString(rvpa.attribute_name_index));
    for (Annotation[] pa : rvpa.parameter_annotations) {
       parseAnnotations(pa, e);
    }
    p.add(e);
    return null;
}
 
Example #23
Source File: ClassReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitAnnotation(Annotation_element_value a, Element p) {
    Element el = new Element("Annotation");
    Annotation anno = a.annotation_value;
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element child = visit(evp.value, el);
        if (child != null) {
            el.add(child);
        }
    }
    el.trimToSize();
    return el;
}
 
Example #24
Source File: TestAnnotationInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void testElementValue(TestResult testResult,
                             ClassFile classFile,
                             Annotation.element_value element_value)
        throws ConstantPool.InvalidIndex {
    testTag(testResult, element_value.tag);
    Annotation.Primitive_element_value ev =
            (Annotation.Primitive_element_value) element_value;
    ConstantPool.CONSTANT_Float_info info =
            (ConstantPool.CONSTANT_Float_info) classFile.constant_pool.get(ev.const_value_index);
    testResult.checkEquals(info.value, value, "const_value_index");
}
 
Example #25
Source File: ClassReader.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitArray(Array_element_value a, Element p) {
 Element el = new Element("Array");
    for (Annotation.element_value v : a.values) {
       Element child = visit(v, el);
       if (child != null) {
           el.add(child);
       }
    }
    el.trimToSize();
    return el;
}
 
Example #26
Source File: ClassReader.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute ripa,
                                                         Element p) {
    Element e = new Element(x.getCpString(ripa.attribute_name_index));
    for (Annotation[] pa : ripa.parameter_annotations) {
        parseAnnotations(pa, e);
    }
    p.add(e);
    return null;
}
 
Example #27
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitAnnotation(Annotation_element_value a, Element p) {
    Element el = new Element("Annotation");
    Annotation anno = a.annotation_value;
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element child = visit(evp.value, el);
        if (child != null) {
            el.add(child);
        }
    }
    el.trimToSize();
    return el;
}
 
Example #28
Source File: ClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitArray(Array_element_value a, Element p) {
 Element el = new Element("Array");
    for (Annotation.element_value v : a.values) {
       Element child = visit(v, el);
       if (child != null) {
           el.add(child);
       }
    }
    el.trimToSize();
    return el;
}
 
Example #29
Source File: ClassReader.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Element visitAnnotation(Annotation_element_value a, Element p) {
    Element el = new Element("Annotation");
    Annotation anno = a.annotation_value;
    for (Annotation.element_value_pair evp : anno.element_value_pairs) {
        Element child = visit(evp.value, el);
        if (child != null) {
            el.add(child);
        }
    }
    el.trimToSize();
    return el;
}
 
Example #30
Source File: AnnotationWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void write(Annotation annot, boolean resolveIndices) {
    writeDescriptor(annot.type_index, resolveIndices);
    boolean showParens = annot.num_element_value_pairs > 0 || !resolveIndices;
    if (showParens)
        print("(");
    for (int i = 0; i < annot.num_element_value_pairs; i++) {
        if (i > 0)
            print(",");
        write(annot.element_value_pairs[i], resolveIndices);
    }
    if (showParens)
        print(")");
}