cleaning up .testsuite

This commit is contained in:
Chris Beams
2008-12-17 23:20:57 +00:00
parent 92b1b73f32
commit 2be8114c63
16 changed files with 226 additions and 380 deletions

View File

@@ -1,109 +0,0 @@
/*
* Copyright 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj.annotation;
import java.lang.reflect.Method;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.util.ObjectUtils;
/**
* Add a DeclareParents field in concrete subclasses, to identify
* the type pattern to apply the introduction to.
*
* @author Rod Johnson
* @since 2.0
*/
@Aspect
public abstract class AbstractMakeModifiable {
public interface MutableModifable extends Modifiable {
void markDirty();
}
public static class ModifiableImpl implements MutableModifable {
private boolean modified;
public void acceptChanges() {
modified = false;
}
public boolean isModified() {
return modified;
}
public void markDirty() {
this.modified = true;
}
}
@Before(value="execution(void set*(*)) && this(modifiable) && args(newValue)",
argNames="modifiable,newValue")
public void recordModificationIfSetterArgumentDiffersFromOldValue(JoinPoint jp,
MutableModifable mixin, Object newValue) {
/*
* We use the mixin to check and, if necessary, change,
* modification status. We need the JoinPoint to get the
* setter method. We use newValue for comparison.
* We try to invoke the getter if possible.
*/
if (mixin.isModified()) {
// Already changed, don't need to change again
//System.out.println("changed");
return;
}
// Find the current raw value, by invoking the corresponding setter
Method correspondingGetter = getGetterFromSetter(((MethodSignature) jp.getSignature()).getMethod());
boolean modified = true;
if (correspondingGetter != null) {
try {
Object oldValue = correspondingGetter.invoke(jp.getTarget());
//System.out.println("Old value=" + oldValue + "; new=" + newValue);
modified = !ObjectUtils.nullSafeEquals(oldValue, newValue);
}
catch (Exception ex) {
ex.printStackTrace();
// Don't sweat on exceptions; assume value was modified
}
}
else {
//System.out.println("cannot get getter for " + jp);
}
if (modified) {
mixin.markDirty();
}
}
private Method getGetterFromSetter(Method setter) {
String getterName = setter.getName().replaceFirst("set", "get");
try {
return setter.getDeclaringClass().getMethod(getterName, (Class[]) null);
}
catch (NoSuchMethodException ex) {
// must be write only
return null;
}
}
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2002-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj.annotation;
import org.springframework.aop.framework.Lockable;
/**
*
*
* @author Rod Johnson
*
*/
public class CannotBeUnlocked implements Lockable, Comparable {
public void lock() {
}
public void unlock() {
throw new UnsupportedOperationException();
}
public boolean locked() {
return true;
}
public int compareTo(Object arg0) {
throw new UnsupportedOperationException();
}
}

View File

@@ -1,28 +0,0 @@
/*
* Copyright 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj.annotation;
import org.aspectj.lang.annotation.Aspect;
/**
* @author Rob Harrop
* @since 2.o
*/
@Aspect
public class FooAspect {
}

View File

@@ -1,34 +0,0 @@
/*
* Copyright 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj.annotation;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareParents;
/**
* Adds a declare parents pointcut.
* @author Rod Johnson
* @since 2.0
*/
@Aspect
public class MakeITestBeanModifiable extends AbstractMakeModifiable {
@DeclareParents(value = "org.springframework.beans.ITestBean+",
defaultImpl=ModifiableImpl.class)
public static MutableModifable mixin;
}

View File

@@ -1,73 +0,0 @@
/*
* Copyright 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj.annotation;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.DeclareParents;
import org.springframework.aop.framework.DefaultLockable;
import org.springframework.aop.framework.Lockable;
/**
* Demonstrates introductions, AspectJ annotation style.
* <p>
* @author Rod Johnson
* @since 2.0
*/
@Aspect
public class MakeLockable {
@DeclareParents(value = "org.springframework..*",
defaultImpl=DefaultLockable.class)
public static Lockable mixin;
@Before(value="execution(void set*(*)) && this(mixin)", argNames="mixin")
public void checkNotLocked(
Lockable mixin) // Bind to arg
{
// Can also obtain the mixin (this) this way
//Lockable mixin = (Lockable) jp.getThis();
if (mixin.locked()) {
throw new IllegalStateException();
}
}
}
/*
*
* public aspect MakeLockable {
*
* declare parents org....* implements Lockable;
*
* private boolean Lockable.locked;
* public void Lockable.lock() {
this.locked = true;
}
* public void Lockable.unlock() {
this.locked = false;
}
* public boolean Lockable.locked() {
return this.locked;
}
*
*
* }
*/

View File

@@ -1,30 +0,0 @@
/*
* Copyright 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj.annotation;
/**
* Used as a mixin.
*
* @author Rod Johnson
*/
public interface Modifiable {
boolean isModified();
void acceptChanges();
}

View File

@@ -1,39 +0,0 @@
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj.annotation;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
/**
* @author Adrian Colyer
*/
@Aspect
public class NamedPointcutWithArgs {
@Pointcut("execution(* *(..)) && args(s,..)")
public void pointcutWithArgs(String s) {}
@Around("pointcutWithArgs(aString)")
public Object doAround(ProceedingJoinPoint pjp, String aString) throws Throwable {
System.out.println("got '" + aString + "' at '" + pjp + "'");
throw new IllegalArgumentException(aString);
}
}

View File

@@ -1,15 +0,0 @@
package org.springframework.aop.aspectj.annotation;
public class NotLockable {
private int intValue;
public int getIntValue() {
return intValue;
}
public void setIntValue(int intValue) {
this.intValue = intValue;
}
}

View File

@@ -14,7 +14,9 @@
* limitations under the License.
*/
package org.springframework.aop;
package org.springframework.aop.framework.adapter;
import org.springframework.aop.BeforeAdvice;
/**
* Simple BeforeAdvice for testing.

View File

@@ -14,13 +14,14 @@
* limitations under the License.
*/
package org.springframework.aop;
package org.springframework.aop.framework.adapter;
import java.io.Serializable;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.adapter.AdvisorAdapter;
/**

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.aop;
package org.springframework.aop.framework.adapter;
/**
* @author Dmitriy Kopylenko

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.aop;
package org.springframework.aop.framework.adapter;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

View File

@@ -5,7 +5,7 @@
<bean id="testBeanTarget" class="org.springframework.beans.TestBean"/>
<bean id="simpleBeforeAdvice" class="org.springframework.aop.SimpleBeforeAdviceImpl"/>
<bean id="simpleBeforeAdvice" class="org.springframework.aop.framework.adapter.SimpleBeforeAdviceImpl"/>
<bean id="simpleBeforeAdviceAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<constructor-arg><ref local="simpleBeforeAdvice"/></constructor-arg>
@@ -16,7 +16,7 @@
<property name="interceptorNames"><value>simpleBeforeAdviceAdvisor,testBeanTarget</value></property>
</bean>
<bean id="testAdvisorAdapter" class="org.springframework.aop.SimpleBeforeAdviceAdapter"/>
<bean id="testAdvisorAdapter" class="org.springframework.aop.framework.adapter.SimpleBeforeAdviceAdapter"/>
<bean id="adapterRegistrationManager" class="org.springframework.aop.framework.adapter.AdvisorAdapterRegistrationManager"/>

View File

@@ -5,7 +5,7 @@
<bean id="testBeanTarget" class="org.springframework.beans.TestBean"/>
<bean id="simpleBeforeAdvice" class="org.springframework.aop.SimpleBeforeAdviceImpl"/>
<bean id="simpleBeforeAdvice" class="org.springframework.aop.framework.adapter.SimpleBeforeAdviceImpl"/>
<bean id="simpleBeforeAdviceAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<constructor-arg><ref local="simpleBeforeAdvice"/></constructor-arg>
@@ -16,6 +16,6 @@
<property name="interceptorNames"><value>simpleBeforeAdviceAdvisor,testBeanTarget</value></property>
</bean>
<bean id="testAdvisorAdapter" class="org.springframework.aop.SimpleBeforeAdviceAdapter"/>
<bean id="testAdvisorAdapter" class="org.springframework.aop.framework.adapter.SimpleBeforeAdviceAdapter"/>
</beans>