Java Code Examples for jdk.jfr.AnnotationElement#getValue()

The following examples show how to use jdk.jfr.AnnotationElement#getValue() . 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: EventClassBuilder.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void buildClassInfo() {
    String internalSuperName = ASMToolkit.getInternalName(Event.class.getName());
    String internalClassName = type.getInternalName();
    classWriter.visit(52, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, internalClassName, null, internalSuperName, null);

    for (AnnotationElement a : annotationElements) {
        String descriptor = ASMToolkit.getDescriptor(a.getTypeName());
        AnnotationVisitor av = classWriter.visitAnnotation(descriptor, true);
        for (ValueDescriptor v : a.getValueDescriptors()) {
            Object value = a.getValue(v.getName());
            String name = v.getName();
            if (v.isArray()) {
                AnnotationVisitor arrayVisitor = av.visitArray(name);
                Object[] array = (Object[]) value;
                for (int i = 0; i < array.length; i++) {
                    arrayVisitor.visit(null, array[i]);
                }
                arrayVisitor.visitEnd();
            } else {
                av.visit(name, value);
            }
        }
        av.visitEnd();
    }
}
 
Example 2
Source File: PrettyWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void printAnnotation(AnnotationElement a) throws IOException {
    StringJoiner sj = new StringJoiner(", ");
    for (ValueDescriptor v : a.getValueDescriptors()) {
        StringBuilder sb = new StringBuilder();
        Object o = a.getValue(v.getName());
        if (o instanceof String) {
            sb.append("\"");
            sb.append((String) o);
            sb.append("\"");
        } else {
            sb.append(o);
        }
        sj.add(sb.toString());
    }
    print(sj.toString());
}
 
Example 3
Source File: TestDescription.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        EventType t = EventType.getEventType(DescriptionEvent.class);

        // field description
        AnnotationElement aMax = Events.getAnnotation(t.getField("field"), Description.class);
        String d = (String) aMax.getValue("value");
        Asserts.assertEquals("Field Annotation", d, "Incorrect annotation for field, got '" + d + "'");

        // event description
        d = t.getAnnotation(Description.class).value();
        Asserts.assertEquals("Event Annotation", d, "Incorrect annotation for event, got '" + d + "'");

        // annotation description
        AnnotationElement a = Events.getAnnotationByName(t, AnnotationWithDescription.class.getName());
        Description de = a.getAnnotation(Description.class);
        Asserts.assertEquals("Meta Annotation", de.value(), "Incorrect annotation for event, got '" + de.value() + "'");

        for (SettingDescriptor v: t.getSettingDescriptors()) {
            if (v.getName().equals("dummy")) {
                Description settingDescription = v.getAnnotation(Description.class);
                Asserts.assertEquals(settingDescription.value(), "Setting description", "Incorrect description for setting");
            }
        }
    }
 
Example 4
Source File: EventClassBuilder.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void buildClassInfo() {
    String internalSuperName = ASMToolkit.getInternalName(Event.class.getName());
    String internalClassName = type.getInternalName();
    classWriter.visit(52, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, internalClassName, null, internalSuperName, null);

    for (AnnotationElement a : annotationElements) {
        String descriptor = ASMToolkit.getDescriptor(a.getTypeName());
        AnnotationVisitor av = classWriter.visitAnnotation(descriptor, true);
        for (ValueDescriptor v : a.getValueDescriptors()) {
            Object value = a.getValue(v.getName());
            String name = v.getName();
            if (v.isArray()) {
                AnnotationVisitor arrayVisitor = av.visitArray(name);
                Object[] array = (Object[]) value;
                for (int i = 0; i < array.length; i++) {
                    arrayVisitor.visit(null, array[i]);
                }
                arrayVisitor.visitEnd();
            } else {
                av.visit(name, value);
            }
        }
        av.visitEnd();
    }
}
 
Example 5
Source File: TestDescription.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        EventType t = EventType.getEventType(DescriptionEvent.class);

        // field description
        AnnotationElement aMax = Events.getAnnotation(t.getField("field"), Description.class);
        String d = (String) aMax.getValue("value");
        Asserts.assertEquals("Field Annotation", d, "Incorrect annotation for field, got '" + d + "'");

        // event description
        d = t.getAnnotation(Description.class).value();
        Asserts.assertEquals("Event Annotation", d, "Incorrect annotation for event, got '" + d + "'");

        // annotation description
        AnnotationElement a = Events.getAnnotationByName(t, AnnotationWithDescription.class.getName());
        Description de = a.getAnnotation(Description.class);
        Asserts.assertEquals("Meta Annotation", de.value(), "Incorrect annotation for event, got '" + de.value() + "'");

        for (SettingDescriptor v: t.getSettingDescriptors()) {
            if (v.getName().equals("dummy")) {
                Description settingDescription = v.getAnnotation(Description.class);
                Asserts.assertEquals(settingDescription.value(), "Setting description", "Incorrect description for setting");
            }
        }
    }
 
Example 6
Source File: EventClassBuilder.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void buildClassInfo() {
    String internalSuperName = ASMToolkit.getInternalName(Event.class.getName());
    String internalClassName = type.getInternalName();
    classWriter.visit(52, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER, internalClassName, null, internalSuperName, null);

    for (AnnotationElement a : annotationElements) {
        String descriptor = ASMToolkit.getDescriptor(a.getTypeName());
        AnnotationVisitor av = classWriter.visitAnnotation(descriptor, true);
        for (ValueDescriptor v : a.getValueDescriptors()) {
            Object value = a.getValue(v.getName());
            String name = v.getName();
            if (v.isArray()) {
                AnnotationVisitor arrayVisitor = av.visitArray(name);
                Object[] array = (Object[]) value;
                for (int i = 0; i < array.length; i++) {
                    arrayVisitor.visit(null, array[i]);
                }
                arrayVisitor.visitEnd();
            } else {
                av.visit(name, value);
            }
        }
        av.visitEnd();
    }
}
 
Example 7
Source File: TestDescription.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        EventType t = EventType.getEventType(DescriptionEvent.class);

        // field description
        AnnotationElement aMax = Events.getAnnotation(t.getField("field"), Description.class);
        String d = (String) aMax.getValue("value");
        Asserts.assertEquals("Field Annotation", d, "Incorrect annotation for field, got '" + d + "'");

        // event description
        d = t.getAnnotation(Description.class).value();
        Asserts.assertEquals("Event Annotation", d, "Incorrect annotation for event, got '" + d + "'");

        // annotation description
        AnnotationElement a = Events.getAnnotationByName(t, AnnotationWithDescription.class.getName());
        Description de = a.getAnnotation(Description.class);
        Asserts.assertEquals("Meta Annotation", de.value(), "Incorrect annotation for event, got '" + de.value() + "'");

        for (SettingDescriptor v: t.getSettingDescriptors()) {
            if (v.getName().equals("dummy")) {
                Description settingDescription = v.getAnnotation(Description.class);
                Asserts.assertEquals(settingDescription.value(), "Setting description", "Incorrect description for setting");
            }
        }
    }
 
Example 8
Source File: TestGetAnnotations.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void assertAnnotation(List<AnnotationElement> annos, String name, Object expectedValue) {
    for (AnnotationElement a : annos) {
        if (a.getTypeName().equals(name)) {
            Object value = a.getValue("value");
            Asserts.assertTrue(Objects.deepEquals(value, expectedValue), "Found annotation " + name + " but value was "+ value +" but expected " + expectedValue);
        }
    }
}
 
Example 9
Source File: Events.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void assertAnnotation(ValueDescriptor field, Class<? extends java.lang.annotation.Annotation> annotationClass, String value) throws Exception {
    AnnotationElement a = getAnnotation(field, annotationClass);
    Object v = a.getValue("value");
    if (!v.equals(value)) {
        throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName() + " to have value " + value + ", but got " + v);
    }
}
 
Example 10
Source File: PrettyWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void printAnnotation(AnnotationElement a) {
    StringJoiner sj = new StringJoiner(", ", "(", ")");
    List<ValueDescriptor> vs = a.getValueDescriptors();
    for (ValueDescriptor v : vs) {
        Object o = a.getValue(v.getName());
        if (vs.size() == 1 && v.getName().equals("value")) {
            sj.add(textify(o));
        } else {
            sj.add(v.getName() + "=" + textify(o));
        }
    }
    print(sj.toString());
}
 
Example 11
Source File: TestGetAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void assertAnnotation(List<AnnotationElement> annos, String name, Object expectedValue) {
    for (AnnotationElement a : annos) {
        if (a.getTypeName().equals(name)) {
            Object value = a.getValue("value");
            Asserts.assertTrue(Objects.deepEquals(value, expectedValue), "Found annotation " + name + " but value was "+ value +" but expected " + expectedValue);
        }
    }
}
 
Example 12
Source File: Events.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void assertAnnotation(ValueDescriptor field, Class<? extends java.lang.annotation.Annotation> annotationClass, String value) throws Exception {
    AnnotationElement a = getAnnotation(field, annotationClass);
    Object v = a.getValue("value");
    if (!v.equals(value)) {
        throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName() + " to have value " + value + ", but got " + v);
    }
}
 
Example 13
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void printAnnotation(AnnotationElement a) {
    StringJoiner sj = new StringJoiner(", ", "(", ")");
    List<ValueDescriptor> vs = a.getValueDescriptors();
    for (ValueDescriptor v : vs) {
        Object o = a.getValue(v.getName());
        if (vs.size() == 1 && v.getName().equals("value")) {
            sj.add(textify(o));
        } else {
            sj.add(v.getName() + "=" + textify(o));
        }
    }
    print(sj.toString());
}
 
Example 14
Source File: TestGetAnnotations.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void assertAnnotation(List<AnnotationElement> annos, String name, Object expectedValue) {
    for (AnnotationElement a : annos) {
        if (a.getTypeName().equals(name)) {
            Object value = a.getValue("value");
            Asserts.assertTrue(Objects.deepEquals(value, expectedValue), "Found annotation " + name + " but value was "+ value +" but expected " + expectedValue);
        }
    }
}
 
Example 15
Source File: Events.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void assertAnnotation(ValueDescriptor field, Class<? extends java.lang.annotation.Annotation> annotationClass, String value) throws Exception {
    AnnotationElement a = getAnnotation(field, annotationClass);
    Object v = a.getValue("value");
    if (!v.equals(value)) {
        throw new Exception("Expected " + annotationClass.getSimpleName() + " on field " + field.getName() + " to have value " + value + ", but got " + v);
    }
}