Home | History | Annotate | Download | only in util
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package dex.reader.util;
     18 
     19 import java.util.HashMap;
     20 import java.util.HashSet;
     21 import java.util.Map;
     22 import java.util.Set;
     23 
     24 import javax.tools.FileObject;
     25 import javax.tools.ForwardingJavaFileManager;
     26 import javax.tools.JavaFileObject;
     27 import javax.tools.StandardJavaFileManager;
     28 
     29 /**
     30  * {@code SpecialJavaFileManager} is a file manager which returns
     31  * {@link MemoryByteCode} objects for its output and keeps track of them.
     32  */
     33 /* package */ class SpecialJavaFileManager extends
     34         ForwardingJavaFileManager<StandardJavaFileManager> {
     35 
     36     private Map<String, MemoryByteCode> store;
     37 
     38     public SpecialJavaFileManager(StandardJavaFileManager sjfm) {
     39         super(sjfm);
     40         store = new HashMap<String, MemoryByteCode>();
     41     }
     42 
     43     public JavaFileObject getJavaFileForOutput(Location location, String name,
     44             JavaFileObject.Kind kind, FileObject sibling) {
     45         MemoryByteCode mbc = new MemoryByteCode(name);
     46         store.put(name, mbc);
     47         return mbc;
     48     }
     49 
     50     public Set<MemoryByteCode> getAllMemoryByteCodes() {
     51         return new HashSet<MemoryByteCode>(store.values());
     52     }
     53 
     54     public MemoryByteCode getMemoryByteCode(String className) {
     55         return store.get(className);
     56     }
     57 }
     58