1 2 package net.firstpartners.nounit.reader.bytecode; 3 4 27 28 import java.io.File ; 29 import java.io.IOException ; 30 31 import net.firstpartners.nounit.reader.ISnippetFactory; 32 import net.firstpartners.nounit.snippet.ISnippet; 33 import net.firstpartners.nounit.snippet.SnippetClass; 34 import net.firstpartners.nounit.snippet.Snippets; 35 import net.firstpartners.nounit.utility.NoUnitException; 36 37 import org.gjt.jclasslib.io.ClassFileReader; 38 import org.gjt.jclasslib.structures.ClassFile; 39 import org.gjt.jclasslib.structures.InvalidByteCodeException; 40 41 44 public class ByteCodeClassSnippetFactory extends AbstractByteCodeSnippetFactory 45 implements ISnippetFactory { 46 47 50 private File innerSourceFile; 51 52 56 public ByteCodeClassSnippetFactory(File sourceFile ){ 57 innerSourceFile = sourceFile; 58 } 59 60 64 public ByteCodeClassSnippetFactory(String sourceFile ){ 65 innerSourceFile = new File (sourceFile ); 66 } 67 68 72 public Snippets getSnippets() throws NoUnitException 73 { 74 Snippets thisClass = new Snippets(); 75 76 try { 77 ClassFile thisClassFile = 79 ClassFileReader.readFromFile( innerSourceFile ); 80 81 ISnippetFactory myMethodFactory = 83 new ByteCodeMethodSnippetFactory( thisClassFile ); 84 Snippets methods = myMethodFactory.getSnippets(); 85 86 int thisClassInPool = thisClassFile.getThisClass(); 88 String name = 89 thisClassFile.getConstantPoolEntryName( thisClassInPool ); 90 name = cleanValues( name ); 91 92 String access = thisClassFile.getAccessFlagsVerbose(); 93 94 int superClassInPool = thisClassFile.getSuperClass(); 95 String superClass = 96 thisClassFile.getConstantPoolEntryName( superClassInPool ); 97 superClass=cleanValues( superClass ); 98 99 ISnippet classSnippet = new SnippetClass( name, access, 101 superClass, methods ); 102 103 thisClass.add( classSnippet ); 104 105 } catch ( InvalidByteCodeException ibce ) { 106 throw new NoUnitException ( ibce, 107 "Could not read Snippets from Source" ); 108 } catch ( IOException ie ) { 109 throw new NoUnitException ( ie, 110 "Could not read Snippets from Source" ); 111 } 112 return thisClass; 113 } 114 } 115 | Popular Tags |