From: Andy Clement Date: Mon, 21 Jan 2019 17:40:04 +0000 (-0800) Subject: new infra for accessing weaver state info attribute from tests X-Git-Tag: V1_9_3RC1~106 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c194226895d50a9620cfe272e4e269625fa4bfd3;p=aspectj.git new infra for accessing weaver state info attribute from tests --- 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.