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.

ReadingAttributesTest.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* *******************************************************************
  2. * Copyright (c) 2009 Contributors
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement
  11. * ******************************************************************/
  12. package org.aspectj.weaver.tools;
  13. import java.io.ByteArrayInputStream;
  14. import java.io.File;
  15. import java.io.IOException;
  16. import org.aspectj.apache.bcel.classfile.Attribute;
  17. import org.aspectj.apache.bcel.classfile.JavaClass;
  18. import org.aspectj.apache.bcel.classfile.Unknown;
  19. import org.aspectj.apache.bcel.util.ClassPath;
  20. import org.aspectj.apache.bcel.util.SyntheticRepository;
  21. import org.aspectj.weaver.VersionedDataInputStream;
  22. import org.aspectj.weaver.WeaverStateInfo;
  23. import junit.framework.TestCase;
  24. public class ReadingAttributesTest extends TestCase {
  25. public void testSkip() {} // Review what to do about these tests
  26. public void xtestWeaverStateInfo() throws ClassNotFoundException, IOException {
  27. JavaClass jc = getClassFrom(new File("n:/temp"), "com.springsource.petclinic.domain.Visit");
  28. assertNotNull(jc);
  29. Attribute[] attrs = jc.getAttributes();
  30. for (int i = 0; i < attrs.length; i++) {
  31. System.out.println(attrs[i].getName());
  32. if (attrs[i].getName().endsWith("WeaverState")) {
  33. Unknown u = (Unknown) attrs[i];
  34. VersionedDataInputStream vdis = new VersionedDataInputStream(new ByteArrayInputStream(u.getBytes()), null);
  35. // WeaverStateInfo wsi =
  36. WeaverStateInfo.read(vdis, null);
  37. // System.out.println(wsi);
  38. }
  39. }
  40. // Method[] meths = jc.getMethods();
  41. // Method oneWeWant = null;
  42. // for (int i = 0; i < meths.length && oneWeWant == null; i++) {
  43. // Method method = meths[i];
  44. // if (method.getName().equals("main")) {
  45. // oneWeWant = meths[i];
  46. // }
  47. // }
  48. }
  49. public SyntheticRepository createRepos(File cpentry) {
  50. ClassPath cp = new ClassPath(cpentry + File.pathSeparator + System.getProperty("java.class.path"));
  51. return SyntheticRepository.getInstance(cp);
  52. }
  53. protected JavaClass getClassFrom(File where, String clazzname) throws ClassNotFoundException {
  54. SyntheticRepository repos = createRepos(where);
  55. return repos.loadClass(clazzname);
  56. }
  57. }