]> source.dussan.org Git - aspectj.git/blob
77872416a1027598d885e342b7bd1350058f60bf
[aspectj.git] /
1 /*******************************************************************************
2  * Copyright (c) 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.aspectj.ajdt.internal.compiler;
12
13 import java.util.Iterator;
14
15 import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
16 import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
17 import org.aspectj.weaver.bcel.UnwovenClassFile;
18 import org.aspectj.weaver.bcel.UnwovenClassFileWithThirdPartyManagedBytecode;
19
20 /**
21  * @author colyer
22  *
23  *      Adaptor for ClassFiles that lets them act as the bytecode repository
24  *      for UnwovenClassFiles (asking a ClassFile for its bytes causes a 
25  *      copy to be made).
26  */
27 public class ClassFileBasedByteCodeProvider 
28            implements UnwovenClassFileWithThirdPartyManagedBytecode.IByteCodeProvider{
29         
30         private ClassFile cf;
31                 
32         public ClassFileBasedByteCodeProvider(ClassFile cf) {
33                 this.cf = cf;
34         }
35                 
36         public byte[] getBytes() {
37                 return cf.getBytes();
38         }
39                 
40         public static UnwovenClassFile[] unwovenClassFilesFor(CompilationResult result, 
41                                                                                             IOutputClassFileNameProvider nameProvider) {
42                 ClassFile[] cfs = result.getClassFiles();
43                 UnwovenClassFile[] ret = new UnwovenClassFile[result.compiledTypes.size()];
44                 int i=0;
45                 for (Object o : result.compiledTypes.keySet()) {
46                         char[] className = (char[]) o;
47                         ClassFile cf = (ClassFile) result.compiledTypes.get(className);
48                         // OPTIMIZE use char[] for classname
49                         ClassFileBasedByteCodeProvider p = new ClassFileBasedByteCodeProvider(cf);
50                         String fileName = nameProvider.getOutputClassFileName(cf.fileName(), result);
51                         ret[i++] = new UnwovenClassFileWithThirdPartyManagedBytecode(fileName, new String(className).replace('/', '.'), p);
52                 }
53                 return ret;
54         }
55                 
56 }