Coverage Report - org.apache.commons.classscan.bcel.BcelAnnotation
 
Classes in this File Line Coverage Branch Coverage Complexity
BcelAnnotation
100%
15/15
100%
4/4
1.333
 
 1  
 /*
 2  
  * Licensed under the Apache License, Version 2.0 (the "License");
 3  
  * you may not use this file except in compliance with the License.
 4  
  * You may obtain a copy of the License at
 5  
  *
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  *
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package org.apache.commons.classscan.bcel;
 15  
 
 16  
 import java.util.Set;
 17  
 
 18  
 import org.apache.bcel.classfile.AnnotationEntry;
 19  
 import org.apache.bcel.classfile.ElementValuePair;
 20  
 import org.apache.commons.classscan.builtin.ClassNameHelper;
 21  
 import org.apache.commons.classscan.spi.model.SpiMetaAnnotation;
 22  
 import org.apache.commons.classscan.spi.model.SpiMetaClassLoader;
 23  
 import org.apache.commons.classscan.util.NameSet;
 24  
 
 25  
 public class BcelAnnotation implements SpiMetaAnnotation {
 26  
 
 27  
     private final String name;
 28  
     private final NameSet<SpiProperty> properties;
 29  
 
 30  32461
     public BcelAnnotation(AnnotationEntry annotation) {
 31  32461
         name = ClassNameHelper.internalToCanonicalName(annotation.getAnnotationType());
 32  
 
 33  32461
         ElementValuePair[] elementValuePairs = annotation.getElementValuePairs();
 34  32461
         if (elementValuePairs.length == 0) {
 35  27093
             properties = NameSet.emptyNameSet();
 36  
         }
 37  
         else {
 38  5368
             properties = new NameSet<SpiProperty>(fillMapAndArray(elementValuePairs));
 39  
         }
 40  32461
     }
 41  
 
 42  
         @Override
 43  
         public boolean resolve(SpiMetaClassLoader classLoader) {
 44  32428
                 return properties.resolve(classLoader);
 45  
         }
 46  
 
 47  
     private SpiProperty[] fillMapAndArray(ElementValuePair[] evPairs) {
 48  5368
         SpiProperty[] values = new SpiProperty[evPairs.length];
 49  11495
         for (int i = 0; i < evPairs.length; ++i) {
 50  6127
             values[i] = new BcelProperty(evPairs[i]);
 51  
         }
 52  5368
         return values;
 53  
     }
 54  
 
 55  
     @Override
 56  
     public String getName() {
 57  4818
         return name;
 58  
     }
 59  
 
 60  
     @Override
 61  
     public Set<? extends Property> getProperties() {
 62  22
         return properties;
 63  
     }
 64  
 
 65  
     @Override
 66  
     public Property getProperty(String propertyName) {
 67  44
         return properties.getValue(propertyName);
 68  
     }
 69  
 }