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.

SerializedOf.java 980B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import org.aspectj.testing.Tester;
  2. import java.io.*;
  3. public class SerializedOf {
  4. public static void main(String[] args) throws Exception {
  5. C c = new C();
  6. Tester.check(ASer.hasAspect(c), "ASer on original");
  7. Tester.check(ANoSer.hasAspect(c), "ANoSer on original");
  8. File tmp = File.createTempFile("cdata", "ser");
  9. FileOutputStream ostream = new FileOutputStream(tmp);
  10. ObjectOutputStream p = new ObjectOutputStream(ostream);
  11. p.writeObject(c);
  12. p.flush();
  13. ostream.close();
  14. FileInputStream istream = new FileInputStream(tmp);
  15. ObjectInputStream p1 = new ObjectInputStream(istream);
  16. C newC = (C)p1.readObject();
  17. istream.close();
  18. Tester.check(ASer.hasAspect(newC), "ASer after read");
  19. Tester.check(!ANoSer.hasAspect(newC), "no ANoSer after read");
  20. }
  21. }
  22. class C implements Serializable {
  23. int data = 42;
  24. }
  25. aspect ASer implements Serializable pertarget(target(C)) {
  26. int serData = 20;
  27. }
  28. aspect ANoSer pertarget(target(C+)) {
  29. int noSerData = 21;
  30. }