]> source.dussan.org Git - aspectj.git/commitdiff
new infra for accessing weaver state info attribute from tests
authorAndy Clement <aclement@pivotal.io>
Mon, 21 Jan 2019 17:40:04 +0000 (09:40 -0800)
committerAndy Clement <aclement@pivotal.io>
Mon, 21 Jan 2019 17:40:04 +0000 (09:40 -0800)
testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java

index fa47c98c445129748f822c4d00255cb4c45b0cdc..13bbf844edaa4e4b7b2bff38cd059cb05d80e604 100644 (file)
@@ -12,6 +12,8 @@
 package org.aspectj.testing;
 
 import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FilenameFilter;
@@ -35,8 +37,13 @@ import org.aspectj.apache.bcel.util.SyntheticRepository;
 import org.aspectj.tools.ajc.AjcTestCase;
 import org.aspectj.tools.ajc.CompilationResult;
 import org.aspectj.util.FileUtil;
+import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.WeaverStateInfo;
+import org.aspectj.weaver.AjAttribute.WeaverState;
+import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
+import org.aspectj.weaver.bcel.BcelConstantPoolReader;
 
 import junit.extensions.TestSetup;
 import junit.framework.Test;
@@ -112,6 +119,33 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase {
                return testMap;
        }
 
+       protected WeaverStateInfo getWeaverStateInfo(JavaClass jc) {
+               WeaverStateInfo wsi = null;
+               try {
+                       for (Attribute attribute : jc.getAttributes()) {
+                               if (attribute.getName().equals("org.aspectj.weaver.WeaverState")) {
+                                       if (wsi != null) {
+                                               fail("Found two WeaverState attributes");
+                                       }
+                                       ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                                       attribute.dump(new DataOutputStream(baos));
+                                       baos.close();
+                                       byte[] byteArray = baos.toByteArray();
+                                       byte[] newbytes = new byte[byteArray.length-6];
+                                       System.arraycopy(byteArray, 6, newbytes, 0, newbytes.length);
+                                       WeaverState read = (WeaverState)
+                                                       AjAttribute.read(new WeaverVersionInfo(), WeaverState.AttributeName,
+                                                                       newbytes, null, null,
+                                                                       new BcelConstantPoolReader(jc.getConstantPool()));
+                                       wsi = read.reify();
+                               }
+                       }
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+               return wsi;
+       }
+
        /**
         * This helper method runs the test with the given title in the suite spec file. All tests steps in given ajc-test execute in
         * the same sandbox.