Java Code Examples for com.sun.tools.classfile.TypeAnnotation#Position
The following examples show how to use
com.sun.tools.classfile.TypeAnnotation#Position .
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: Driver.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private Map<String, TypeAnnotation.Position> expectedOf(Method m) { TADescription ta = m.getAnnotation(TADescription.class); TADescriptions tas = m.getAnnotation(TADescriptions.class); if (ta == null && tas == null) return null; Map<String, TypeAnnotation.Position> result = new HashMap<String, TypeAnnotation.Position>(); if (ta != null) result.putAll(expectedOf(ta)); if (tas != null) { for (TADescription a : tas.value()) { result.putAll(expectedOf(a)); } } return result; }
Example 2
Source File: ReferenceInfoUtil.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static boolean compare(Map<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 (Map.Entry<String, TypeAnnotation.Position> e : expectedAnnos.entrySet()) { String aName = e.getKey(); TypeAnnotation.Position expected = e.getValue(); TypeAnnotation actual = findAnnotation(aName, actualAnnos, cf); if (actual == null) throw new ComparisionException("Expected annotation not found: " + aName); // TODO: you currently get an exception if the test case does not use all necessary // annotation attributes, e.g. forgetting the offset for a local variable. // It would be nicer to give an understandable warning instead. if (!areEquals(expected, actual.position)) { throw new ComparisionException("Unexpected position for annotation : " + aName + "\n Expected: " + expected.toString() + "\n Found: " + actual.position.toString()); } } return true; }
Example 3
Source File: ReferenceInfoUtil.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static boolean areEquals(TypeAnnotation.Position p1, TypeAnnotation.Position p2) { if (p1 == p2) return true; if (p1 == null || p2 == null) return false; return ((p1.type == p2.type) && (p1.location.equals(p2.location)) && areEquals(p1.offset, p2.offset) && areEquals(p1.lvarOffset, p2.lvarOffset) && areEquals(p1.lvarLength, p2.lvarLength) && areEquals(p1.lvarIndex, p2.lvarIndex) && areEquals(p1.bound_index, p2.bound_index) && areEquals(p1.parameter_index, p2.parameter_index) && areEquals(p1.type_index, p2.type_index) && areEquals(p1.exception_index, p2.exception_index)); }
Example 4
Source File: Driver.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private Map<String, TypeAnnotation.Position> expectedOf(Method m) { TADescription ta = m.getAnnotation(TADescription.class); TADescriptions tas = m.getAnnotation(TADescriptions.class); if (ta == null && tas == null) return null; Map<String, TypeAnnotation.Position> result = new HashMap<>(); if (ta != null) result.putAll(expectedOf(ta)); if (tas != null) { for (TADescription a : tas.value()) { result.putAll(expectedOf(a)); } } return result; }
Example 5
Source File: ReferenceInfoUtil.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static boolean compare(Map<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 (Map.Entry<String, TypeAnnotation.Position> e : expectedAnnos.entrySet()) { String aName = e.getKey(); TypeAnnotation.Position expected = e.getValue(); TypeAnnotation actual = findAnnotation(aName, actualAnnos, cf); if (actual == null) throw new ComparisionException("Expected annotation not found: " + aName); // TODO: you currently get an exception if the test case does not use all necessary // annotation attributes, e.g. forgetting the offset for a local variable. // It would be nicer to give an understandable warning instead. if (!areEquals(expected, actual.position)) { throw new ComparisionException("Unexpected position for annotation : " + aName + "\n Expected: " + expected.toString() + "\n Found: " + actual.position.toString()); } } return true; }
Example 6
Source File: ReferenceInfoUtil.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public static boolean compare(Map<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 (Map.Entry<String, TypeAnnotation.Position> e : expectedAnnos.entrySet()) { String aName = e.getKey(); TypeAnnotation.Position expected = e.getValue(); TypeAnnotation actual = findAnnotation(aName, actualAnnos, cf); if (actual == null) throw new ComparisionException("Expected annotation not found: " + aName); // TODO: you currently get an exception if the test case does not use all necessary // annotation attributes, e.g. forgetting the offset for a local variable. // It would be nicer to give an understandable warning instead. if (!areEquals(expected, actual.position)) { throw new ComparisionException("Unexpected position for annotation : " + aName + "\n Expected: " + expected.toString() + "\n Found: " + actual.position.toString()); } } return true; }
Example 7
Source File: ReferenceInfoUtil.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public static boolean areEquals(TypeAnnotation.Position p1, TypeAnnotation.Position p2) { if (p1 == p2) return true; if (p1 == null || p2 == null) return false; return ((p1.type == p2.type) && (p1.location.equals(p2.location)) && areEquals(p1.offset, p2.offset) && areEquals(p1.lvarOffset, p2.lvarOffset) && areEquals(p1.lvarLength, p2.lvarLength) && areEquals(p1.lvarIndex, p2.lvarIndex) && areEquals(p1.bound_index, p2.bound_index) && areEquals(p1.parameter_index, p2.parameter_index) && areEquals(p1.type_index, p2.type_index) && areEquals(p1.exception_index, p2.exception_index)); }
Example 8
Source File: Driver.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private Map<String, TypeAnnotation.Position> expectedOf(Method m) { TADescription ta = m.getAnnotation(TADescription.class); TADescriptions tas = m.getAnnotation(TADescriptions.class); if (ta == null && tas == null) return null; Map<String, TypeAnnotation.Position> result = new HashMap<String, TypeAnnotation.Position>(); if (ta != null) result.putAll(expectedOf(ta)); if (tas != null) { for (TADescription a : tas.value()) { result.putAll(expectedOf(a)); } } return result; }
Example 9
Source File: ReferenceInfoUtil.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static boolean compare(Map<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 (Map.Entry<String, TypeAnnotation.Position> e : expectedAnnos.entrySet()) { String aName = e.getKey(); TypeAnnotation.Position expected = e.getValue(); TypeAnnotation actual = findAnnotation(aName, actualAnnos, cf); if (actual == null) throw new ComparisionException("Expected annotation not found: " + aName); // TODO: you currently get an exception if the test case does not use all necessary // annotation attributes, e.g. forgetting the offset for a local variable. // It would be nicer to give an understandable warning instead. if (!areEquals(expected, actual.position)) { throw new ComparisionException("Unexpected position for annotation : " + aName + "\n Expected: " + expected.toString() + "\n Found: " + actual.position.toString()); } } return true; }
Example 10
Source File: Driver.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private Map<String, TypeAnnotation.Position> expectedOf(TADescription d) { String annoName = d.annotation(); TypeAnnotation.Position p = new TypeAnnotation.Position(); p.type = d.type(); if (d.offset() != NOT_SET) p.offset = d.offset(); if (d.lvarOffset().length != 0) p.lvarOffset = d.lvarOffset(); if (d.lvarLength().length != 0) p.lvarLength = d.lvarLength(); if (d.lvarIndex().length != 0) p.lvarIndex = d.lvarIndex(); if (d.boundIndex() != NOT_SET) p.bound_index = d.boundIndex(); if (d.paramIndex() != NOT_SET) p.parameter_index = d.paramIndex(); if (d.typeIndex() != NOT_SET) p.type_index = d.typeIndex(); if (d.exceptionIndex() != NOT_SET) p.exception_index = d.exceptionIndex(); if (d.genericLocation().length != 0) { p.location = TypeAnnotation.Position.getTypePathFromBinary(wrapIntArray(d.genericLocation())); } return Collections.singletonMap(annoName, p); }
Example 11
Source File: Driver.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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()) { Map<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 = testClassOf(method); for (String[] extraParams : extraParamsCombinations) { try { String compact = (String)method.invoke(object); String fullFile = wrap(compact); ClassFile cf = compileAndReturn(fullFile, testClass, extraParams); 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"); }
Example 12
Source File: ReferenceInfoUtil.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static boolean areEquals(TypeAnnotation.Position p1, TypeAnnotation.Position p2) { return p1 == p2 || !(p1 == null || p2 == null) && p1.type == p2.type && (p1.location.equals(p2.location)) && areEquals(p1.offset, p2.offset) && areEquals(p1.lvarOffset, p2.lvarOffset) && areEquals(p1.lvarLength, p2.lvarLength) && areEquals(p1.lvarIndex, p2.lvarIndex) && areEquals(p1.bound_index, p2.bound_index) && areEquals(p1.parameter_index, p2.parameter_index) && areEquals(p1.type_index, p2.type_index) && areEquals(p1.exception_index, p2.exception_index); }
Example 13
Source File: Driver.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private Map<String, TypeAnnotation.Position> expectedOf(TADescription d) { String annoName = d.annotation(); TypeAnnotation.Position p = new TypeAnnotation.Position(); p.type = d.type(); if (d.offset() != NOT_SET) p.offset = d.offset(); if (d.lvarOffset().length != 0) p.lvarOffset = d.lvarOffset(); if (d.lvarLength().length != 0) p.lvarLength = d.lvarLength(); if (d.lvarIndex().length != 0) p.lvarIndex = d.lvarIndex(); if (d.boundIndex() != NOT_SET) p.bound_index = d.boundIndex(); if (d.paramIndex() != NOT_SET) p.parameter_index = d.paramIndex(); if (d.typeIndex() != NOT_SET) p.type_index = d.typeIndex(); if (d.exceptionIndex() != NOT_SET) p.exception_index = d.exceptionIndex(); if (d.genericLocation().length != 0) { p.location = TypeAnnotation.Position.getTypePathFromBinary(wrapIntArray(d.genericLocation())); } return Collections.singletonMap(annoName, p); }
Example 14
Source File: Driver.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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()) { Map<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 = testClassOf(method); for (String[] extraParams : extraParamsCombinations) { try { String compact = (String)method.invoke(object); String fullFile = wrap(compact); ClassFile cf = compileAndReturn(fullFile, testClass, extraParams); 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"); }
Example 15
Source File: Driver.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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()) { Map<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 = testClassOf(method); for (String[] extraParams : extraParamsCombinations) { try { String compact = (String)method.invoke(object); String fullFile = wrap(compact); ClassFile cf = compileAndReturn(fullFile, testClass, extraParams); 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"); }
Example 16
Source File: Driver.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private Map<String, TypeAnnotation.Position> expectedOf(TADescription d) { String annoName = d.annotation(); TypeAnnotation.Position p = new TypeAnnotation.Position(); p.type = d.type(); if (d.offset() != NOT_SET) p.offset = d.offset(); if (d.lvarOffset().length != 0) p.lvarOffset = d.lvarOffset(); if (d.lvarLength().length != 0) p.lvarLength = d.lvarLength(); if (d.lvarIndex().length != 0) p.lvarIndex = d.lvarIndex(); if (d.boundIndex() != NOT_SET) p.bound_index = d.boundIndex(); if (d.paramIndex() != NOT_SET) p.parameter_index = d.paramIndex(); if (d.typeIndex() != NOT_SET) p.type_index = d.typeIndex(); if (d.exceptionIndex() != NOT_SET) p.exception_index = d.exceptionIndex(); if (d.genericLocation().length != 0) { p.location = TypeAnnotation.Position.getTypePathFromBinary(wrapIntArray(d.genericLocation())); } return Collections.singletonMap(annoName, p); }
Example 17
Source File: ReferenceInfoUtil.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public ComparisionException(String message, Map<String, TypeAnnotation.Position> expected, List<TypeAnnotation> found) { super(message); this.expected = expected; this.found = found; }
Example 18
Source File: ReferenceInfoUtil.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public ComparisionException(String message, Map<String, TypeAnnotation.Position> expected, List<TypeAnnotation> found) { super(message); this.expected = expected; this.found = found; }
Example 19
Source File: ReferenceInfoUtil.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public ComparisionException(String message, Map<String, TypeAnnotation.Position> expected, List<TypeAnnotation> found) { super(message); this.expected = expected; this.found = found; }
Example 20
Source File: ReferenceInfoUtil.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public ComparisionException(String message, Map<String, TypeAnnotation.Position> expected, List<TypeAnnotation> found) { super(message); this.expected = expected; this.found = found; }