Clover coverage report - MetaClass - 1.1
Coverage timestamp: Tue Apr 27 2004 10:46:24 EST
file stats: LOC: 108   Methods: 5
NCLOC: 60   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AddMetaDataAdapter.java 100% 100% 100% 100%
coverage
 1   
 /*
 2   
  * Copyright (C) The MetaClass Group. All rights reserved.
 3   
  *
 4   
  * This software is published under the terms of the Spice
 5   
  * Software License version 1.1, a copy of which has been included
 6   
  * with this distribution in the LICENSE.txt file.
 7   
  */
 8   
 package org.codehaus.metaclass.io;
 9   
 
 10   
 import java.io.ByteArrayOutputStream;
 11   
 import java.io.IOException;
 12   
 import org.objectweb.asm.Attribute;
 13   
 import org.objectweb.asm.ClassAdapter;
 14   
 import org.objectweb.asm.ClassVisitor;
 15   
 import org.codehaus.metaclass.model.ClassDescriptor;
 16   
 
 17   
 /**
 18   
  * Create a ClassAdapter that simply adds the MetaClass metadata to .class
 19   
  * file.
 20   
  *
 21   
  * @author Peter Donald
 22   
  * @version $Revision: 1.2 $ $Date: 2003/12/11 08:41:50 $
 23   
  */
 24   
 class AddMetaDataAdapter
 25   
     extends ClassAdapter
 26   
 {
 27   
     /** The class descriptor to add. */
 28   
     final ClassDescriptor m_descriptor;
 29   
 
 30   
     /** The IOE exception thrown when serializing descriptor. */
 31   
     private IOException m_ioe;
 32   
 
 33   
     /**
 34   
      * Create the adapter.
 35   
      *
 36   
      * @param cv the visitor to delegate to.
 37   
      * @param descriptor the descriptor to add
 38   
      */
 39  12
     AddMetaDataAdapter( final ClassVisitor cv,
 40   
                         final ClassDescriptor descriptor )
 41   
     {
 42  12
         super( cv );
 43  12
         m_descriptor = descriptor;
 44   
     }
 45   
 
 46   
     /**
 47   
      * @see ClassAdapter#visitAttribute(Attribute)
 48   
      */
 49  4
     public void visitAttribute( final Attribute attr )
 50   
     {
 51  4
         if( !MetaClassIOASM.ATTRIBUTE_NAME.equals( attr.type ) )
 52   
         {
 53  2
             super.visitAttribute( attr );
 54   
         }
 55   
     }
 56   
 
 57   
     /**
 58   
      * @see ClassAdapter#visit(int, String, String, String[], String)
 59   
      */
 60  8
     public void visit( final int access,
 61   
                        final String name,
 62   
                        final String superName,
 63   
                        final String[] interfaces,
 64   
                        final String sourceFile )
 65   
     {
 66  8
         super.visit( access, name, superName, interfaces, sourceFile );
 67  8
         try
 68   
         {
 69  8
             final byte[] bytes = toBytes();
 70  6
             final Attribute attr =
 71   
                 new Attribute( MetaClassIOASM.ATTRIBUTE_NAME,
 72   
                                bytes,
 73   
                                0,
 74   
                                bytes.length );
 75  6
             super.visitAttribute( attr );
 76   
         }
 77   
         catch( final IOException ioe )
 78   
         {
 79  2
             m_ioe = ioe;
 80   
         }
 81   
     }
 82   
 
 83   
     /**
 84   
      * Convert ClassDescriptor into bytes.
 85   
      *
 86   
      * @return the bytes
 87   
      * @throws IOException if unable to convert descriptor into bytes
 88   
      */
 89  6
     byte[] toBytes()
 90   
         throws IOException
 91   
     {
 92  6
         final ByteArrayOutputStream output = new ByteArrayOutputStream();
 93  6
         MetaClassIOBinary.IO.serializeClass( output, m_descriptor );
 94  6
         final byte[] bytes = output.toByteArray();
 95  6
         return bytes;
 96   
     }
 97   
 
 98   
     /**
 99   
      * Return the IOException thrown during serialization.
 100   
      *
 101   
      * @return the IOException thrown during serialization.
 102   
      */
 103  2
     IOException getIoe()
 104   
     {
 105  2
         return m_ioe;
 106   
     }
 107   
 }
 108