diff options
author | Andy Clement <aclement@pivotal.io> | 2019-01-21 09:40:04 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2019-01-21 09:40:04 -0800 |
commit | c194226895d50a9620cfe272e4e269625fa4bfd3 (patch) | |
tree | e2da5c936caebe078b543e34390f88e52c18d272 /testing | |
parent | 98ea8917c608861bdd14042fdb435a15090b0907 (diff) | |
download | aspectj-c194226895d50a9620cfe272e4e269625fa4bfd3.tar.gz aspectj-c194226895d50a9620cfe272e4e269625fa4bfd3.zip |
new infra for accessing weaver state info attribute from tests
Diffstat (limited to 'testing')
-rw-r--r-- | testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java b/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java index fa47c98c4..13bbf844e 100644 --- a/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java +++ b/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java @@ -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. |