public static Stream<Compound> getDeclarationAndTypeAttributes(Symbol sym) {
    Symbol typeAnnotationOwner;
    switch (sym.getKind()) {
      case PARAMETER:
        typeAnnotationOwner = sym.owner;
        break;
      default:
        typeAnnotationOwner = sym;
    }
    return Streams.concat(
            sym.getRawAttributes().stream(),
            typeAnnotationOwner.getRawTypeAttributes().stream()
                .filter(anno -> isAnnotationOnType(sym, anno.position)))
        .collect(
            groupingBy(c -> c.type.asElement().getQualifiedName(), LinkedHashMap::new, toList()))
        .values().stream()
        .map(c -> c.get(0));
  }
public static Stream < Compound > getDeclarationAndTypeAttributes ( Symbol sym ) { Symbol typeAnnotationOwner ; switch ( sym . getKind ( ) ) { case PARAMETER : typeAnnotationOwner = sym . owner ; break ; default : typeAnnotationOwner = sym ; } return Streams . concat ( sym . getRawAttributes ( ) . stream ( ) , typeAnnotationOwner . getRawTypeAttributes ( ) . stream ( ) . filter ( anno -> isAnnotationOnType ( sym , anno . position ) ) ) . collect ( groupingBy ( c -> c . type . asElement ( ) . getQualifiedName ( ) , LinkedHashMap :: new , toList ( ) ) ) . values ( ) . stream ( ) . map ( c -> c . get ( 0 ) ) ; }
Returns declaration annotations of the given symbol, as well as 'top-level' type annotations,
including :

<ul>
<li>Type annotations of the return type of a method.
<li>Type annotations on the type of a formal parameter or field.
</ul>

<p>One might expect this to be equivalent to information returned by {@link
com.sun.tools.javac.code.Type#getAnnotationMirrors}, but javac doesn't associate type
annotation information with types for symbols completed from class files, so that approach
doesn't work across compilation boundaries.