Search in sources :

Example 1 with TypeAnnotation

use of com.sun.tools.classfile.TypeAnnotation in project checker-framework by typetools.

the class ComparisionException method compare.

public static boolean compare(List<Pair<String, TypeAnnotation.Position>> expectedAnnos, List<TypeAnnotation> actualAnnos, ClassFile cf) throws InvalidIndex, UnexpectedEntry {
    if (actualAnnos.size() != expectedAnnos.size()) {
        throw new ComparisionException("Wrong number of annotations", expectedAnnos, actualAnnos);
    }
    for (Pair<String, TypeAnnotation.Position> e : expectedAnnos) {
        String aName = e.first;
        TypeAnnotation.Position expected = e.second;
        TypeAnnotation actual = findAnnotation(aName, expected, actualAnnos, cf);
        if (actual == null) {
            throw new ComparisionException("Expected annotation not found: " + aName + " position: " + expected, expectedAnnos, actualAnnos);
        }
    }
    return true;
}
Also used : TypeAnnotation(com.sun.tools.classfile.TypeAnnotation)

Example 2 with TypeAnnotation

use of com.sun.tools.classfile.TypeAnnotation in project jdk8u_jdk by JetBrains.

the class AnnotationsElementVisitor method visitRuntimeInvisibleTypeAnnotations.

@Override
public Element visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute rita, Element p) {
    Element e = new Element(x.getCpString(rita.attribute_name_index));
    for (TypeAnnotation pa : rita.annotations) {
        parseTypeAnnotations(pa, e);
    }
    e.sort();
    p.add(e);
    return null;
}
Also used : TypeAnnotation(com.sun.tools.classfile.TypeAnnotation) Element(xmlkit.XMLKit.Element)

Example 3 with TypeAnnotation

use of com.sun.tools.classfile.TypeAnnotation in project jdk8u_jdk by JetBrains.

the class AnnotationsElementVisitor method visitRuntimeVisibleTypeAnnotations.

@Override
public Element visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute rvta, Element p) {
    Element e = new Element(x.getCpString(rvta.attribute_name_index));
    for (TypeAnnotation pa : rvta.annotations) {
        parseTypeAnnotations(pa, e);
    }
    e.sort();
    p.add(e);
    return null;
}
Also used : TypeAnnotation(com.sun.tools.classfile.TypeAnnotation) Element(xmlkit.XMLKit.Element)

Example 4 with TypeAnnotation

use of com.sun.tools.classfile.TypeAnnotation in project checker-framework by typetools.

the class TADescriptions method runDriver.

protected void runDriver(Object object) throws Exception {
    int passed = 0, failed = 0;
    Class<?> clazz = object.getClass();
    out.println("Tests for " + clazz.getName());
    // Find methods
    for (Method method : clazz.getMethods()) {
        List<Pair<String, TypeAnnotation.Position>> expected = expectedOf(method);
        if (expected == null) {
            continue;
        }
        if (method.getReturnType() != String.class) {
            throw new IllegalArgumentException("Test method needs to return a string: " + method);
        }
        String testClass = PersistUtil.testClassOf(method);
        try {
            String compact = (String) method.invoke(object);
            String fullFile = PersistUtil.wrap(compact);
            ClassFile cf = PersistUtil.compileAndReturn(fullFile, testClass);
            List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf);
            ReferenceInfoUtil.compare(expected, actual, cf);
            out.println("PASSED:  " + method.getName());
            ++passed;
        } catch (Throwable e) {
            out.println("FAILED:  " + method.getName());
            out.println("    " + e.toString());
            ++failed;
        }
    }
    out.println();
    int total = passed + failed;
    out.println(total + " total tests: " + passed + " PASSED, " + failed + " FAILED");
    out.flush();
    if (failed != 0) {
        throw new RuntimeException(failed + " tests failed");
    }
}
Also used : TypeAnnotation(com.sun.tools.classfile.TypeAnnotation) ClassFile(com.sun.tools.classfile.ClassFile) Method(java.lang.reflect.Method) Pair(org.checkerframework.javacutil.Pair)

Aggregations

TypeAnnotation (com.sun.tools.classfile.TypeAnnotation)4 Element (xmlkit.XMLKit.Element)2 ClassFile (com.sun.tools.classfile.ClassFile)1 Method (java.lang.reflect.Method)1 Pair (org.checkerframework.javacutil.Pair)1