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.

Annotations.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*******************************************************************************
  2. * Copyright (c) 2004 IBM
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-v10.html
  7. *
  8. * Contributors:
  9. * Andy Clement - initial API and implementation
  10. *******************************************************************************/
  11. package org.aspectj.systemtest.ajc150;
  12. import java.io.File;
  13. import junit.framework.Test;
  14. import org.aspectj.apache.bcel.classfile.JavaClass;
  15. import org.aspectj.apache.bcel.classfile.Method;
  16. import org.aspectj.apache.bcel.util.ClassPath;
  17. import org.aspectj.apache.bcel.util.SyntheticRepository;
  18. import org.aspectj.testing.XMLBasedAjcTestCase;
  19. public class Annotations extends XMLBasedAjcTestCase {
  20. public static Test suite() {
  21. return XMLBasedAjcTestCase.loadSuite(Annotations.class);
  22. }
  23. protected File getSpecFile() {
  24. return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
  25. }
  26. public void testCompilingAnnotation() {
  27. runTest("compiling an annotation");
  28. }
  29. public void testCompilingAnnotatedFile() {
  30. runTest("compiling annotated file");
  31. }
  32. public void testCompilingUsingWithinAndAnnotationTypePattern() {
  33. runTest("annotations and within (src)");
  34. }
  35. /**
  36. * We had a bug where annotations were not present in the output class file for methods
  37. * that got woven. This was due to unpacking bugs in LazyMethodGen. This test compiles
  38. * a simple program then checks the annotations were copied across.
  39. */
  40. public void testBugWithAnnotationsLostOnWovenMethods() throws ClassNotFoundException {
  41. runTest("losing annotations...");
  42. JavaClass jc = getClassFrom(ajc.getSandboxDirectory(),"Program");
  43. Method[] meths = jc.getMethods();
  44. for (int i = 0; i < meths.length; i++) {
  45. Method method = meths[i];
  46. if (method.getName().equals("m1")) {
  47. assertTrue("Didn't have annotations - were they lost? method="+method.getName(),method.getAnnotations().length==1);
  48. }
  49. }
  50. }
  51. // helper methods.....
  52. public SyntheticRepository createRepos(File cpentry) {
  53. ClassPath cp = new ClassPath(cpentry+File.pathSeparator+System.getProperty("java.class.path"));
  54. return SyntheticRepository.getInstance(cp);
  55. }
  56. protected JavaClass getClassFrom(File where,String clazzname) throws ClassNotFoundException {
  57. SyntheticRepository repos = createRepos(where);
  58. return repos.loadClass(clazzname);
  59. }
  60. }