experiments/java/src/stx/libjava/tools/compiler/ecj/CompilerTypeRegistry.java
branchdevelopment
changeset 2477 6e37b62e21b5
equal deleted inserted replaced
2476:d24ce8174195 2477:6e37b62e21b5
       
     1 package stx.libjava.tools.compiler.ecj;
       
     2 
       
     3 import java.io.ByteArrayInputStream;
       
     4 import java.io.IOException;
       
     5 import java.io.InputStream;
       
     6 import java.util.HashMap;
       
     7 import java.util.Map;
       
     8 
       
     9 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
       
    10 import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
       
    11 import org.eclipse.jdt.internal.compiler.env.IBinaryType;
       
    12 
       
    13 /**
       
    14  * A registry for binary types. Eventually will do some caching in the future...
       
    15  * @author Jan Vrany
       
    16  *
       
    17  */
       
    18 public class CompilerTypeRegistry {
       
    19 	protected Map<String, IBinaryType> typeMap = new HashMap<String, IBinaryType>();
       
    20 	
       
    21 	public IBinaryType get(String name) {
       
    22 		return typeMap.get(name);
       
    23 	}
       
    24 	
       
    25 	public void put(String name, IBinaryType type) {
       
    26 		typeMap.put(name,type);
       
    27 	}
       
    28 		
       
    29 	public void put(String name, InputStream classfile) {
       
    30 		try {
       
    31 			put(name, ClassFileReader.read(classfile, (new String(name).replace('.', '/') + ".class")));
       
    32 		} catch (ClassFormatException e) {
       
    33 			throw new RuntimeException(e);
       
    34 		} catch (IOException e) {
       
    35 			throw new RuntimeException(e);
       
    36 		}
       
    37 	}
       
    38 	
       
    39 	public void put(String name, byte[] classfile) {
       
    40 		put(name, new ByteArrayInputStream(classfile));
       
    41 	}
       
    42 	
       
    43 	
       
    44 
       
    45 }