You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClassFileBasedByteCodeProvider.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 v 2.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors:
  9. * IBM Corporation - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.ajdt.internal.compiler;
  12. import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
  13. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  14. import org.aspectj.weaver.bcel.UnwovenClassFile;
  15. import org.aspectj.weaver.bcel.UnwovenClassFileWithThirdPartyManagedBytecode;
  16. /**
  17. * @author colyer
  18. *
  19. * Adaptor for ClassFiles that lets them act as the bytecode repository
  20. * for UnwovenClassFiles (asking a ClassFile for its bytes causes a
  21. * copy to be made).
  22. */
  23. public class ClassFileBasedByteCodeProvider
  24. implements UnwovenClassFileWithThirdPartyManagedBytecode.IByteCodeProvider{
  25. private ClassFile cf;
  26. public ClassFileBasedByteCodeProvider(ClassFile cf) {
  27. this.cf = cf;
  28. }
  29. public byte[] getBytes() {
  30. return cf.getBytes();
  31. }
  32. public static UnwovenClassFile[] unwovenClassFilesFor(CompilationResult result,
  33. IOutputClassFileNameProvider nameProvider) {
  34. ClassFile[] cfs = result.getClassFiles();
  35. UnwovenClassFile[] ret = new UnwovenClassFile[result.compiledTypes.size()];
  36. int i=0;
  37. for (Object o : result.compiledTypes.keySet()) {
  38. char[] className = (char[]) o;
  39. ClassFile cf = (ClassFile) result.compiledTypes.get(className);
  40. // OPTIMIZE use char[] for classname
  41. ClassFileBasedByteCodeProvider p = new ClassFileBasedByteCodeProvider(cf);
  42. String fileName = nameProvider.getOutputClassFileName(cf.fileName(), result);
  43. ret[i++] = new UnwovenClassFileWithThirdPartyManagedBytecode(fileName, new String(className).replace('/', '.'), p);
  44. }
  45. return ret;
  46. }
  47. }