From 3e207615acea3f9ddce05e6874e43ca8baaf7aca Mon Sep 17 00:00:00 2001
From: Volker Berlin <volker.berlin@googlemail.com>
Date: Wed, 30 May 2018 18:31:17 +0200
Subject: [PATCH] add method getAnnotation

---
 .../inetsoftware/classparser/MethodInfo.java  | 34 ++++++++++++++++---
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/de/inetsoftware/classparser/MethodInfo.java b/src/de/inetsoftware/classparser/MethodInfo.java
index 54462fe..a745f87 100644
--- a/src/de/inetsoftware/classparser/MethodInfo.java
+++ b/src/de/inetsoftware/classparser/MethodInfo.java
@@ -1,5 +1,5 @@
 /*
-   Copyright 2011 - 2017 Volker Berlin (i-net software)
+   Copyright 2011 - 2018 Volker Berlin (i-net software)
 
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
@@ -18,6 +18,9 @@ package de.inetsoftware.classparser;
 
 import java.io.DataInputStream;
 import java.io.IOException;
+import java.util.Map;
+
+import javax.annotation.Nullable;
 
 import de.inetsoftware.classparser.Attributes.AttributeInfo;
 
@@ -42,6 +45,8 @@ public class MethodInfo {
 
     private ClassFile          classFile;
 
+    private Annotations        annotations;
+
     /**
      * Read the method_info structure
      * http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.6
@@ -152,10 +157,31 @@ public class MethodInfo {
      * Get the annotations with @Retention(RetentionPolicy.CLASS)
      * @return the annotations if there any exists else null
      */
+    @Nullable
     public Annotations getRuntimeInvisibleAnnotations() throws IOException {
-        AttributeInfo data = attributes.get( "RuntimeInvisibleAnnotations" );
-        if( data != null ) {
-            return new Annotations( data.getDataInputStream(), constantPool );
+        if( annotations == null ) {
+            AttributeInfo data = attributes.get( "RuntimeInvisibleAnnotations" );
+            if( data != null ) {
+                annotations =  new Annotations( data.getDataInputStream(), constantPool );
+            }
+        }
+        return annotations;
+    }
+
+    /**
+     * Get a single annotation or null
+     * 
+     * @param annotation
+     *            the class name of the annotation
+     * @return the value or null if not exists
+     * @throws IOException
+     *             if any I/O error occur
+     */
+    @Nullable
+    public Map<String, Object> getAnnotation( String annotation ) throws IOException {
+        Annotations annotations = getRuntimeInvisibleAnnotations();
+        if( annotations != null ) {
+            return annotations.get( annotation );
         }
         return null;
     }