Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ClassFileBasedByteCodeProvider.java 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. import java.util.Iterator;
  13. import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
  14. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  15. import org.aspectj.weaver.bcel.UnwovenClassFile;
  16. import org.aspectj.weaver.bcel.UnwovenClassFileWithThirdPartyManagedBytecode;
  17. /**
  18. * @author colyer
  19. *
  20. * Adaptor for ClassFiles that lets them act as the bytecode repository
  21. * for UnwovenClassFiles (asking a ClassFile for its bytes causes a
  22. * copy to be made).
  23. */
  24. public class ClassFileBasedByteCodeProvider
  25. implements UnwovenClassFileWithThirdPartyManagedBytecode.IByteCodeProvider{
  26. private ClassFile cf;
  27. public ClassFileBasedByteCodeProvider(ClassFile cf) {
  28. this.cf = cf;
  29. }
  30. public byte[] getBytes() {
  31. return cf.getBytes();
  32. }
  33. public static UnwovenClassFile[] unwovenClassFilesFor(CompilationResult result,
  34. IOutputClassFileNameProvider nameProvider) {
  35. ClassFile[] cfs = result.getClassFiles();
  36. UnwovenClassFile[] ret = new UnwovenClassFile[result.compiledTypes.size()];
  37. int i=0;
  38. for (Iterator iterator = result.compiledTypes.keySet().iterator(); iterator.hasNext();) {
  39. char[] className = (char[])iterator.next();
  40. ClassFile cf = (ClassFile)result.compiledTypes.get(className);
  41. // OPTIMIZE use char[] for classname
  42. ClassFileBasedByteCodeProvider p = new ClassFileBasedByteCodeProvider(cf);
  43. String fileName = nameProvider.getOutputClassFileName(cf.fileName(), result);
  44. ret[i++] = new UnwovenClassFileWithThirdPartyManagedBytecode(fileName,new String(className).replace('/','.'),p);
  45. }
  46. return ret;
  47. }
  48. }