diff options
author | wisberg <wisberg> | 2003-08-07 20:24:04 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2003-08-07 20:24:04 +0000 |
commit | 1cf6391380ae594b165b32acd92222057545e7ad (patch) | |
tree | 72334711c03a45056557959ae7ee54a11d31fe85 | |
parent | 684c9c1c3dd084b43645f537774bea0b4a9c1222 (diff) | |
download | aspectj-1cf6391380ae594b165b32acd92222057545e7ad.tar.gz aspectj-1cf6391380ae594b165b32acd92222057545e7ad.zip |
BCException - not isolated, so no bug written
-rw-r--r-- | tests/ajcTestsFailing.xml | 83 | ||||
-rw-r--r-- | tests/new/pointcutLibrary/langlib/Pointcuts.java | 173 | ||||
-rw-r--r-- | tests/new/pointcutLibrary/langlib/PointcutsCW.java | 217 |
3 files changed, 473 insertions, 0 deletions
diff --git a/tests/ajcTestsFailing.xml b/tests/ajcTestsFailing.xml index 55278a25e..8b5d79788 100644 --- a/tests/ajcTestsFailing.xml +++ b/tests/ajcTestsFailing.xml @@ -41,5 +41,88 @@ <message kind="error" file="ClassClientCE.java" line="5"/> </compile> </ajc-test> + + <ajc-test dir="new/pointcutLibrary" title="libraries-pointcuts compiles" + comment="interim test just to show library compiles..."> + <compile files="langlib/Pointcuts.java"/> + </ajc-test> + + <ajc-test dir="new/pointcutLibrary" title="libraries-pointcuts sym" + comment="BCException: expected state: resolved got: symbolic at Pointcut.java:238,126" + > + <compile files="langlib/Pointcuts.java,langlib/PointcutsCW.java"> + <message kind="warning" line="67" text="anyMethodExecution"/> + <message kind="warning" line="67" text="anyPublicMethodExecution"/> + <message kind="warning" line="67" text="anyNonPrivateMethodExecution"/> + <message kind="warning" line="72" text="anyConstructorExecution"/> + <message kind="warning" line="74" text="anyConstructorExecution"/> + <message kind="warning" line="74" text="anyPublicConstructorExecution"/> + <message kind="warning" line="74" text="anyNonPrivateConstructorExecution"/> + <message kind="warning" line="76" text="anyConstructorExecution"/> + <message kind="warning" line="76" text="anyNonPrivateConstructorExecution"/> + <message kind="warning" line="78" text="anyNonPrivateFieldSet"/> + <message kind="warning" line="82" text="anyMethodExecution"/> + <message kind="warning" line="82" text="anyPublicMethodExecution"/> + <message kind="warning" line="82" text="anyNonPrivateMethodExecution"/> + <message kind="warning" line="83" text="toStringExecution "/> + <message kind="warning" line="87" text="anyMethodExecution"/> + <message kind="warning" line="89" text="anyMethodExecution, "/> + <message kind="warning" line="91" text="anyNonPrivateFieldSet"/> + <message kind="warning" line="91" text="withinSetter"/> + <message kind="warning" line="97" text="anyNonPrivateFieldGet"/> + <message kind="warning" line="97" text="withinGetter"/> + <message kind="warning" line="102" text="anyMethodExecution"/> + <message kind="warning" line="102" text="anyPublicMethodExecution"/> + <message kind="warning" line="102" text="anyNonPrivateMethodExecution"/> + <message kind="warning" line="103" text="runImplementationsInNonRunnable"/> + <message kind="warning" line="107" text="anyRunnableImplementation"/> + <message kind="warning" line="109" text="anyMethodExecution"/> + <message kind="warning" line="109" text="anyPublicMethodExecution"/> + <message kind="warning" line="109" text="anyNonPrivateMethodExecution"/> + <message kind="warning" line="114" text="anyMethodExecution"/> + <message kind="warning" line="114" text="anyPublicMethodExecution"/> + <message kind="warning" line="114" text="anyNonPrivateMethodExecution"/> + <message kind="warning" line="115" text="cloneImplementationsInNonCloneable"/> + <message kind="warning" line="121" text="anyMethodExecution"/> + <message kind="warning" line="121" text="anyPublicMethodExecution"/> + <message kind="warning" line="121" text="anyNonPrivateMethodExecution"/> + <message kind="warning" line="124" text="anyPublicFieldGet"/> + <message kind="warning" line="124" text="anyNonPrivateFieldGet"/> + <message kind="warning" line="126" text="anyPublicFieldGet"/> + <message kind="warning" line="126" text="anyNonPrivateFieldGet"/> + <message kind="warning" line="132" text="anyNonPrivateFieldGet"/> + <message kind="warning" line="134" text="anyNonPrivateFieldGet"/> + <message kind="warning" line="136" text="anyPublicFieldSet"/> + <message kind="warning" line="136" text="anyNonPrivateFieldSet"/> + <message kind="warning" line="138" text="anyPublicFieldSet"/> + <message kind="warning" line="138" text="anyNonPrivateFieldSet"/> + <message kind="warning" line="141" text="anyNonPublicFieldSetOutsideConstructorOrSetter"/> + <message kind="warning" line="143" text="anyNonPublicFieldSetOutsideConstructorOrSetter"/> + <message kind="warning" line="145" text="anyNonPublicFieldSetOutsideConstructorOrSetter"/> + <message kind="warning" line="147" text="anyNonPublicFieldSetOutsideConstructorOrSetter"/> + <message kind="warning" line="145" text="anyNonPrivateFieldSet"/> + <message kind="warning" line="147" text="anyNonPrivateFieldSet"/> + <message kind="warning" line="149" text="anyGetSystemErrOut"/> + <message kind="warning" line="149" text="anyNonPrivateFieldGet"/> + <message kind="warning" line="149" text="anyPublicFieldGet"/> + <message kind="warning" line="151" text="anyGetSystemErrOut"/> + <message kind="warning" line="151" text="anyNonPrivateFieldGet"/> + <message kind="warning" line="151" text="anyPublicFieldGet"/> + <message kind="warning" line="153" text="anyThreadConstruction"/> + <message kind="warning" line="155" text="anyJavaIOCalls"/> + <message kind="warning" line="157" text="anyJavaIOCalls"/> + <message kind="warning" line="159" text="anyJavaAWTOrSwingCalls"/> + <message kind="warning" line="161" text="anyJavaAWTOrSwingCalls"/> + <message kind="warning" line="163" text="anyJavaAWTOrSwingCalls"/> + <message kind="warning" line="165" text="anyJavaAWTOrSwingCalls"/> + <message kind="warning" line="169" text="anySystemClassLoadingCalls"/> + <message kind="warning" line="171" text="anySystemReflectiveCalls"/> + <message kind="warning" line="173" text="anySystemProcessSpawningCalls"/> + <message kind="warning" line="177" text="mostThrowableReadCalls"/> + <message kind="warning" line="179" text="mostThrowableReadCalls"/> + <message kind="warning" line="181" text="mostThrowableReadCalls"/> + </compile> + <run class="org.aspectj.langlib.PointcutsCW"/> + </ajc-test> </suite> diff --git a/tests/new/pointcutLibrary/langlib/Pointcuts.java b/tests/new/pointcutLibrary/langlib/Pointcuts.java new file mode 100644 index 000000000..706e8c687 --- /dev/null +++ b/tests/new/pointcutLibrary/langlib/Pointcuts.java @@ -0,0 +1,173 @@ +/* ******************************************************************* + * Copyright (c) 2003 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * Wes Isberg initial implementation + * ******************************************************************/ + +// START-SAMPLE library-pointcutIdioms Standard pointcut idioms +package langlib; + +import java.io.*; + +/** + * Library of pointcut idioms to use in combination with + * other pointcuts. + * + * @author Wes Isberg + */ +public class Pointcuts { + + // ------- not staticly-determinable + public pointcut adviceCflow() : cflow(adviceexecution()); + + public pointcut notInAdviceCflow() : !adviceCflow(); + + public pointcut cflowMainExecution() : + cflow(mainExecution()); + + // ------- staticly-determinable + + public pointcut mainExecution() : + execution(public static void main(String[])); + + /** staticly-determinable to never match any join point */ + public pointcut never() : if(false) + && execution(ThreadDeath *(ThreadDeath, ThreadDeath)); + + public pointcut anyMethodExecution() : + execution(* *(..)); + + public pointcut anyPublicMethodExecution() : + execution(public * *(..)); + + public pointcut anyNonPrivateMethodExecution() : + execution(!private * *(..)); + + public pointcut anyConstructorExecution() : + execution(new(..)); + + public pointcut anyPublicConstructorExecution() : + execution(public new(..)); + + public pointcut anyNonPrivateConstructorExecution() : + execution(!private new(..)); + + public pointcut anyPublicFieldGet() : + get(public * *); + + public pointcut anyNonPrivateFieldGet() : + get(!private * *); + + public pointcut anyPublicFieldSet() : + set(public * *); + + public pointcut anyNonPrivateFieldSet() : + set(!private * *); // also !transient? + + public pointcut withinSetter() : + withincode(* set*(..)); + + public pointcut withinGetter() : + withincode(Object+ get*(..)); + + public pointcut anyNonPublicFieldSetOutsideConstructorOrSetter() : + set(!public * *) && !withincode(new(..)) + && !withinSetter(); + + public pointcut anyRunnableImplementation() : + staticinitialization(Runnable+); + + public pointcut anyGetSystemErrOut() : + get(PrintStream System.err) || get(PrintStream System.out); + + public pointcut anySetSystemErrOut() : + call(void System.setOut(..)) || call(void System.setErr(..)); + + public pointcut withinAnyJavaCode() : + within(java..*) || within(javax..*); + + public pointcut notWithinJavaCode() : + !withinAnyJavaCode(); + + public pointcut toStringExecution() : + execution(String toString()) && !within(String); + + /** call or execution of any Thread constructor, including subclasses */ + public pointcut anyThreadConstruction() : + call(Thread+.new(..)) || execution(Thread+.new(..)); + + /** + * Any calls to java.io classes + * (but not methods declared only on their subclasses). + */ + public pointcut anyJavaIOCalls() : + call(* java.io..*.*(..)) || call(java.io..*.new(..)); + + /** + * Any calls to java.awt or javax.swing classes + * (but not methods declared only on their subclasses). + */ + public pointcut anyJavaAWTOrSwingCalls() : + call(* java.awt..*.*(..)) || call(java.awt..*.new(..)) + || call(* javax.swing..*.*(..)) || call(javax.swing..*.new(..)); + + public pointcut cloneImplementationsInNonCloneable() : + execution(Object !Cloneable+.clone()); + + public pointcut runImplementationsInNonRunnable() : + execution(void !Runnable+.run()); + + /** any calls to java.lang.reflect or Class.get* (except getName()) */ + public pointcut anySystemReflectiveCalls() : + call(* java.lang.reflect..*.*(..)) + || (!call(* Class.getName()) + && call(* Class.get*(..))); + + /** standard class-loading calls by Class and ClassLoader */ + public pointcut anySystemClassLoadingCalls() : + call(Class Class.forName(..)) + || call(Class ClassLoader.loadClass(..)); + + public pointcut anySystemProcessSpawningCalls() : + call(Process Runtime.exec(..)) + || call(Class ClassLoader.loadClass(..)); + + public pointcut mostThrowableReadCalls() : + call(* Throwable+.get*(..)) + || call(* Throwable+.print*(..)) + || call(String Throwable+.toString(..)); + + public pointcut exceptionWrappingCalls() : + (args(Throwable+,..) || args(.., Throwable+)) + && (set(Throwable+ Throwable+.*) + || (call(* Throwable+.*(..)) + || call(Throwable+.new(..)))); + + private Pointcuts() {} + +} +aspect A { + private static aspect PointcutsOnly { + /** require this library to only contain pointcuts */ + declare error : within(Pointcuts) && + (Pointcuts.anyMethodExecution() + || Pointcuts.anyNonPrivateConstructorExecution() + || set(* *)) : "only pointcuts permitted in Pointcuts"; + // does not pick out field definitions -- too costly + // set(* Pointcuts.*) || get(* Pointcuts.*) + } +} +// END-SAMPLE library-pointcutIdioms + +class PointcutQuestions { + public pointcut anyCodeThrowingException() : // XXX broken? + execution(* *(..) throws Exception+) + || execution(new(..) throws Exception+); + +} diff --git a/tests/new/pointcutLibrary/langlib/PointcutsCW.java b/tests/new/pointcutLibrary/langlib/PointcutsCW.java new file mode 100644 index 000000000..8d567ff95 --- /dev/null +++ b/tests/new/pointcutLibrary/langlib/PointcutsCW.java @@ -0,0 +1,217 @@ +package langlib; +import org.aspectj.testing.Tester; + +import java.awt.Button; +import java.awt.event.ActionEvent; +import java.beans.PropertyChangeListener; +import java.io.*; +import java.lang.reflect.Method; + +import javax.swing.*; +import javax.swing.Action; + +// DO NOT CHANGE LINEATION! WARNING NUMBERS DEPEND ON IT! See grep below + + + + + +/** + * todo yet untested: + * - dynamic calls + */ +public aspect PointcutsCW { + declare error: Pointcuts.never() : "never"; + declare error: within(PointcutsCW) && Pointcuts.never() : "never"; + + declare warning: Pointcuts.mainExecution() : "mainExecution"; + declare warning: Pointcuts.anyMethodExecution() : "anyMethodExecution"; + declare warning: Pointcuts.anyPublicMethodExecution() : "anyPublicMethodExecution"; + declare warning: Pointcuts.anyNonPrivateMethodExecution() : "anyNonPrivateMethodExecution"; + declare warning: Pointcuts.anyConstructorExecution() : "anyConstructorExecution"; + declare warning: Pointcuts.anyPublicConstructorExecution() : "anyPublicConstructorExecution"; + declare warning: Pointcuts.anyNonPrivateConstructorExecution() : "anyNonPrivateConstructorExecution"; + + declare warning: Pointcuts.anyPublicFieldGet() : "anyPublicFieldGet"; + declare warning: Pointcuts.anyNonPrivateFieldGet() : "anyNonPrivateFieldGet"; + declare warning: Pointcuts.anyPublicFieldSet() : "anyPublicFieldSet"; + declare warning: Pointcuts.anyNonPrivateFieldSet() : "anyNonPrivateFieldSet"; + declare warning: Pointcuts.withinSetter() : "withinSetter"; + declare warning: Pointcuts.withinGetter() : "withinGetter"; + declare warning: Pointcuts.anyNonPublicFieldSetOutsideConstructorOrSetter() : "anyNonPublicFieldSetOutsideConstructorOrSetter"; + + declare warning: Pointcuts.anyRunnableImplementation() : "anyRunnableImplementation"; + declare warning: Pointcuts.anyGetSystemErrOut() : "anyGetSystemErrOut"; + declare warning: Pointcuts.anySetSystemErrOut() : "anySetSystemErrOut"; + declare warning: Pointcuts.withinAnyJavaCode() : "withinAnyJavaCode"; // XXX + declare warning: Pointcuts.notWithinJavaCode() : "notWithinJavaCode"; // XXX + declare warning: Pointcuts.toStringExecution() : "toStringExecution"; + declare warning: Pointcuts.anyThreadConstruction() : "anyThreadConstruction"; + declare warning: Pointcuts.anyJavaIOCalls() : "anyJavaIOCalls"; + declare warning: Pointcuts.anyJavaAWTOrSwingCalls() : "anyJavaAWTOrSwingCalls"; + declare warning: Pointcuts.cloneImplementationsInNonCloneable() : "cloneImplementationsInNonCloneable"; + declare warning: Pointcuts.runImplementationsInNonRunnable() : "runImplementationsInNonRunnable"; + declare warning: Pointcuts.anySystemReflectiveCalls() : "anySystemReflectiveCalls"; + declare warning: Pointcuts.anySystemClassLoadingCalls() : "anySystemClassLoadingCalls"; + declare warning: Pointcuts.anySystemProcessSpawningCalls() : "anySystemProcessSpawningCalls"; + declare warning: Pointcuts.mostThrowableReadCalls() : "mostThrowableReadCalls"; + declare warning: Pointcuts.exceptionWrappingCalls() : "exceptionWrappingCalls"; + + public static int publicStaticInt; + public int publicInt; + private static int privateStaticInt; + private int privateInt; + static int defaultStaticInt; + int defaultInt; + + // CW anyMethodExecution, anyPublicMethodExecution, anyNonPrivateMethodExecution + public static void main(String[] list) { + new PointcutsCW().toString(); // RT cflowMainExecution + } + + private PointcutsCW() {} // CW anyConstructorExecution + + public PointcutsCW(int i) {} // CW anyConstructorExecution, anyPublicConstructorExecution, anyNonPrivateConstructorExecution + + PointcutsCW(String s) { // CW anyConstructorExecution, anyNonPrivateConstructorExecution + + defaultInt = 0; // CW anyNonPrivateFieldSet + + } + + // CW anyMethodExecution, anyPublicMethodExecution, anyNonPrivateMethodExecution + public String toString() {// CW toStringExecution + return ""; + } + + private int perrorCode() { } // CW anyMethodExecution + + private void setInt() { // CW anyMethodExecution, + + defaultInt = 0; // CW anyNonPrivateFieldSet, withinSetter + + } + + private int getInt() { + + return defaultInt; // CW anyNonPrivateFieldGet, withinGetter + + } + + static class NotRunnable { + // CW anyMethodExecution, anyPublicMethodExecution, anyNonPrivateMethodExecution + public void run() { // CW runImplementationsInNonRunnable + } + } + + static class R implements Runnable { // CW anyRunnableImplementation + + // CW anyMethodExecution, anyPublicMethodExecution, anyNonPrivateMethodExecution + public void run() { + + } + + // CW anyMethodExecution, anyPublicMethodExecution, anyNonPrivateMethodExecution + public Object clone() { // CW cloneImplementationsInNonCloneable + return null; + } + + } + + // CW anyMethodExecution, anyPublicMethodExecution, anyNonPrivateMethodExecution + public static void pserrorCode() throws IOException { + + i = publicStaticInt; // CW anyPublicFieldGet, anyNonPrivateFieldGet + + i = publicInt; // CW anyPublicFieldGet, anyNonPrivateFieldGet + + i = privateStaticInt; + + i = privateInt; + + i = defaultStaticInt; // CW anyNonPrivateFieldGet + + i = defaultInt; // CW anyNonPrivateFieldGet + + publicStaticInt = 1; // CW anyPublicFieldSet, anyNonPrivateFieldSet + + publicInt = 1; // CW anyPublicFieldSet, anyNonPrivateFieldSet + + // for these 4: CW anyNonPublicFieldSetOutsideConstructorOrSetter + privateStaticInt = 1; + + privateInt = 1; + + defaultStaticInt = 1; // CW anyNonPrivateFieldSet + + defaultInt = 1; // CW anyNonPrivateFieldSet + + System.out.println(""); // CW anyGetSystemErrOut, anyNonPrivateFieldGet, anyPublicFieldGet + + System.err.println(""); // CW anyGetSystemErrOut, anyNonPrivateFieldGet anyPublicFieldGet + + new Thread((Runnable)null); // CW anyThreadConstruction + + FileReader fr = new FileReader("none"); // CW anyJavaIOCalls + + int i = fr.read(); // CW anyJavaIOCalls + + DefaultListModel model = new DefaultListModel(); // CW anyJavaAWTOrSwingCalls + + model.addElement(null); // CW anyJavaAWTOrSwingCalls + + Button button = new Button(); // CW anyJavaAWTOrSwingCalls + + button.addActionListener(null); // CW anyJavaAWTOrSwingCalls + + String myName = PointcutsCW.class.getName(); + + Class me = Class.forName(myName); // CW anySystemClassLoadingCalls + + Method m = me.getDeclaredMethod("notFound", new Class[]{}); // CW anySystemReflectiveCalls + + Process p = Runtime.exec("ls"); // CW anySystemProcessSpawningCalls + + Error e = new Error("hello"); + + e.getMessage(); // CW mostThrowableReadCalls + + e.printStackTrace(); // CW mostThrowableReadCalls + + e.getClass(); // CW mostThrowableReadCalls + + } + +} + +aspect DynamicTests { + static { + Tester.expectEvent("mainExecution"); + Tester.expectEvent("cflowMainExecution"); + Tester.expectEvent("adviceCflow"); + Tester.expectEvent("notInAdviceCflow"); + } + after(PointcutsCE pointcutsCE) returning : target(pointcutsCE) + && Pointcuts.cflowMainExecution() && call(String toString()) { + String targ = pointcutsCE.toString(); + Tester.event("cflowMainExecution"); + Tester.event("adviceCflow"); + } + + after(PointcutsCE pointcutsCE) returning : target(pointcutsCE) + && notInAdviceCflow() && call(String toString()) { + Tester.event("notInAdviceCflow"); // should only get one of these + } + + after() returning : within(PointcutsCE) && Pointcuts.mainExecution() { + Tester.event("mainExecution"); // also cflowMainExecution + Tester.checkAllEvents(); + } + +} +/* + grep -n " CW" PointcutsCW.java \ + | sed 's|^\(.*\)\:.*\/\/*CW \(.*\)$|<message kind="warning" line="\1" text="\2"/>|' \ + > messages.txt + +*/
\ No newline at end of file |