1 26 27 package net.sourceforge.groboutils.codecoverage.v2.compiler; 28 29 import java.io.IOException ; 30 import java.io.OutputStream ; 31 32 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 33 import net.sourceforge.groboutils.codecoverage.v2.datastore.AnalysisModuleSet; 34 import net.sourceforge.groboutils.codecoverage.v2.datastore.ClassRecord; 35 import net.sourceforge.groboutils.codecoverage.v2.datastore.IClassMetaDataWriter; 36 import net.sourceforge.groboutils.codecoverage.v2.datastore.IMetaDataWriter; 37 38 39 47 public class PostCompileClass 48 { 49 private IMetaDataWriter out; 50 private AnalysisModuleSet amSet; 51 private ParseCoverageLogger pcl; 52 53 54 62 public PostCompileClass( IMetaDataWriter writer, 63 IAnalysisModule[] modules ) 64 { 65 this( new ParseCoverageLogger(), writer, modules ); 66 } 67 68 69 80 public PostCompileClass( ParseCoverageLogger pcl, IMetaDataWriter writer, 81 IAnalysisModule[] modules ) 82 { 83 if (writer == null || modules == null || pcl == null) 84 { 85 throw new IllegalArgumentException ("no null args"); 86 } 87 88 this.out = writer; 89 this.amSet = new AnalysisModuleSet( modules ); 90 this.pcl = pcl; 91 } 92 93 94 99 public void postCompile( String filename, byte[] classFile, 100 OutputStream classOut ) 101 throws IOException 102 { 103 if (this.pcl == null) 104 { 105 throw new IllegalStateException ( "pcl is null." ); 106 } 107 ModifiedClass mc = new ModifiedClass( this.pcl, filename, classFile ); 108 109 int amCount = amSet.getAnalysisModuleCount(); 110 ModifiedMethod[] mmL = mc.getMethods(); 111 for (short moduleIndex = 0; moduleIndex < amCount; ++moduleIndex) 112 { 113 IAnalysisModule am = this.amSet.getAnalysisModuleAt( moduleIndex ); 114 ClassRecord cr = mc.createClassRecord( this.amSet ); 115 116 for (int methodI = 0; methodI < mmL.length; ++methodI) 117 { 118 DefaultMethodCode dmc = new DefaultMethodCode( moduleIndex, 119 mmL[ methodI ], cr ); 120 am.analyze( dmc ); 121 } 122 123 IClassMetaDataWriter cmdw = this.out.getClassWriter( am ); 125 try 126 { 127 cmdw.writeClassRecord( cr ); 128 } 129 finally 130 { 131 cmdw.close(); 132 } 133 } 134 135 byte[] modClassFile = mc.getModifiedClass(); 136 classOut.write( modClassFile ); 137 } 138 } 139 140 | Popular Tags |