From 82f217fa97084beaa1c4c88ec2e96e4cf83e8aad Mon Sep 17 00:00:00 2001 From: aclement Date: Wed, 5 Jul 2006 08:22:55 +0000 Subject: [PATCH] test and fix for 148693 --- .../compiler/ast/AspectDeclaration.java | 5 ++ .../systemtest/ajc153/Ajc153Tests.java | 68 ++------------- tests/src/org/aspectj/testing/Utils.java | 83 +++++++++++++++++++ 3 files changed, 93 insertions(+), 63 deletions(-) create mode 100644 tests/src/org/aspectj/testing/Utils.java diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java index 24aae7c37..5d3595273 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java @@ -434,7 +434,12 @@ public class AspectDeclaration extends TypeDeclaration { gen.generate(codeStream); // body ends here if (codeStream.pcToSourceMapSize==0) codeStream.recordPositionsFrom(0,1); + boolean b = codeStream.generateLocalVariableTableAttributes; // pr148693 + if (codeStream.maxLocals==0) + codeStream.generateLocalVariableTableAttributes=false; classFile.completeCodeAttribute(codeAttributeOffset); + codeStream.generateLocalVariableTableAttributes=b; + attributeNumber++; classFile.completeMethodInfo(methodAttributeOffset, attributeNumber); } diff --git a/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java b/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java index e6fc85777..b9e03ed25 100644 --- a/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java @@ -14,14 +14,7 @@ import java.io.File; import junit.framework.Test; -import org.aspectj.apache.bcel.Repository; -import org.aspectj.apache.bcel.classfile.JavaClass; -import org.aspectj.apache.bcel.classfile.Method; -import org.aspectj.apache.bcel.util.ClassPath; -import org.aspectj.apache.bcel.util.SyntheticRepository; -import org.aspectj.apache.bcel.verifier.VerificationResult; -import org.aspectj.apache.bcel.verifier.Verifier; -import org.aspectj.apache.bcel.verifier.VerifierFactory; +import org.aspectj.testing.Utils; import org.aspectj.testing.XMLBasedAjcTestCase; public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase { @@ -32,62 +25,11 @@ public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void testAtajInheritance_pr149305_1() { runTest("ataj inheritance - 1");} public void testAtajInheritance_pr149305_2() { runTest("ataj inheritance - 2");} public void testAtajInheritance_pr149305_3() { runTest("ataj inheritance - 3");} + public void testVerificationFailureForAspectOf_pr148693() { + runTest("verification problem"); // build the code + Utils.verifyClass(ajc,"mypackage.MyAspect"); // verify it <<< BRAND NEW VERIFY UTILITY FOR EVERYONE TO TRY ;) + } - - // work in progress - -// public void testVerificationFailureForAspectOf_pr148693() throws ClassNotFoundException { -// runTest("verification problem"); -// verifyClass("mypackage.MyAspect"); -// } - - - // TODO refactor into a util class - /** - * Performs verification of a class - the supplied class is expected to exist in the sandbox - * directory so typically this is called after a small compile step has been invoked to build it. - */ - public void verifyClass(String clazzname) { - JavaClass jc = null; - try { - jc = getClassFrom(ajc.getSandboxDirectory().getAbsolutePath(),clazzname); - } catch (ClassNotFoundException cnfe) { - fail("Could not find "+clazzname+" in the sandbox: "+ajc.getSandboxDirectory()); - } - assertTrue("Could not find class",jc!=null); - Repository.setRepository(jc.getRepository()); - Verifier v = VerifierFactory.getVerifier("mypackage.MyAspect"); - VerificationResult vr = v.doPass1(); - System.err.println(vr); - - assertTrue("Verification: "+vr,vr.getStatus()==VerificationResult.VERIFIED_OK); - vr = v.doPass2(); - System.err.println(vr); - assertTrue("Verification: "+vr,vr.getStatus()==VerificationResult.VERIFIED_OK); - Method[] ms = jc.getMethods(); - for (int i = 0; i < ms.length; i++) { - System.err.println("Pass3a for "+ms[i]); - vr = v.doPass3a(i); - System.err.println(vr); - assertTrue("Verification: "+vr,vr.getStatus()==VerificationResult.VERIFIED_OK); - System.err.println("Pass3b for "+ms[i]); - vr = v.doPass3b(i); - System.err.println(vr); - assertTrue("Verification: "+vr,vr.getStatus()==VerificationResult.VERIFIED_OK); - } - } - - protected JavaClass getClassFrom(String frompath,String clazzname) throws ClassNotFoundException { - SyntheticRepository repos = createRepos(frompath); - return repos.loadClass(clazzname); - } - - public SyntheticRepository createRepos(String cpentry) { - ClassPath cp = new ClassPath( - cpentry+File.pathSeparator+ - System.getProperty("java.class.path")); - return SyntheticRepository.getInstance(cp); - } ///////////////////////////////////////// public static Test suite() { diff --git a/tests/src/org/aspectj/testing/Utils.java b/tests/src/org/aspectj/testing/Utils.java new file mode 100644 index 000000000..81b84f8b9 --- /dev/null +++ b/tests/src/org/aspectj/testing/Utils.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andy Clement - initial API and implementation + *******************************************************************************/ +package org.aspectj.testing; + +import java.io.File; + +import org.aspectj.apache.bcel.Repository; +import org.aspectj.apache.bcel.classfile.JavaClass; +import org.aspectj.apache.bcel.classfile.Method; +import org.aspectj.apache.bcel.util.ClassPath; +import org.aspectj.apache.bcel.util.SyntheticRepository; +import org.aspectj.apache.bcel.verifier.VerificationResult; +import org.aspectj.apache.bcel.verifier.Verifier; +import org.aspectj.apache.bcel.verifier.VerifierFactory; +import org.aspectj.tools.ajc.Ajc; + +/** + * Not quite the right place for this class.. + */ +public class Utils { + + private final static boolean debugVerification=false; + + /** + * Performs verification of a class - the supplied class is expected to exist in the sandbox + * directory so typically this is called after a small compile step has been invoked to build it. + * @param ajc + */ + public static String verifyClass(Ajc ajc, String clazzname) { + JavaClass jc = null; + try { + jc = getClassFrom(ajc.getSandboxDirectory().getAbsolutePath(),clazzname); + } catch (ClassNotFoundException cnfe) { + return "Could not find "+clazzname+" in the sandbox: "+ajc.getSandboxDirectory(); + } + if (jc==null) return "Could not find class "+clazzname; + Repository.setRepository(jc.getRepository()); + Verifier v = VerifierFactory.getVerifier("mypackage.MyAspect"); + VerificationResult vr = v.doPass1(); + if (debugVerification) System.err.println(vr); + + if (vr.getStatus()!=VerificationResult.VERIFIED_OK) + return "Verification not ok: "+vr; + vr = v.doPass2(); + if (debugVerification) System.err.println(vr); + if (vr.getStatus()!=VerificationResult.VERIFIED_OK) + return "Verification not ok: "+vr; + Method[] ms = jc.getMethods(); + for (int i = 0; i < ms.length; i++) { + if (debugVerification) System.err.println("Pass3a for "+ms[i]); + vr = v.doPass3a(i); + if (debugVerification) System.err.println(vr); + if (vr.getStatus()!=VerificationResult.VERIFIED_OK) + return "Verification not ok: "+vr; + if (debugVerification) System.err.println("Pass3b for "+ms[i]); + vr = v.doPass3b(i); + if (debugVerification) System.err.println(vr); + if (vr.getStatus()!=VerificationResult.VERIFIED_OK) + return "Verification not ok: "+vr; + } + return null; + } + + protected static JavaClass getClassFrom(String frompath,String clazzname) throws ClassNotFoundException { + SyntheticRepository repos = createRepos(frompath); + return repos.loadClass(clazzname); + } + + public static SyntheticRepository createRepos(String cpentry) { + ClassPath cp = new ClassPath( + cpentry+File.pathSeparator+ + System.getProperty("java.class.path")); + return SyntheticRepository.getInstance(cp); + } +} -- 2.39.5