[jboss-cvs] JBossAS SVN: r63902 - in projects/aop/trunk/aop/src/main/org/jboss/aop: advice/annotation and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Jul 7 19:58:08 EDT 2007
Author: flavia.rainone at jboss.com
Date: 2007-07-07 19:58:08 -0400 (Sat, 07 Jul 2007)
New Revision: 63902
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceMethodProperties.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/assignability/VariableHierarchy.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByConJoinPointGenerator.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByMethodJoinPointGenerator.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionJoinPointGenerator.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorJoinPointGenerator.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldJoinPointGenerator.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByConJoinPointGenerator.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByMethodJoinPointGenerator.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java
Log:
[JBAOP-415] Algorithm integrated
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceMethodProperties.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceMethodProperties.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AdviceMethodProperties.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -22,6 +22,7 @@
package org.jboss.aop.advice;
import java.lang.reflect.Method;
+import java.lang.reflect.Type;
import javassist.CtClass;
import javassist.NotFoundException;
@@ -52,11 +53,12 @@
private String adviceName;
private Class joinPointBeanType;
private Class invocationType;
- private Class target;
- private Class caller;
- private Class joinpointReturnType;
- private Class[] joinpointParameters;
- private Class[] joinpointExceptions;
+ private Type target;
+ private Type caller;
+ private Type joinpointReturnType;
+ private Type[] joinpointParameters;
+ private Class<?>[] joinpointParameterClassTypes;
+ private Type[] joinpointExceptions;
private OptionalParameters optionalParameters;
private boolean targetAvailable;
private boolean callerAvailable;
@@ -70,10 +72,11 @@
String adviceName,
Class joinPointBeanType,
Class invocationType,
- Class joinpointReturnType,
- Class[] joinpointParameters,
- Class[] joinpointExceptions,
- Class target,
+ Type joinpointReturnType,
+ Type[] joinpointParameters,
+ Class[] joinpointParameterClassTypes,
+ Type[] joinpointExceptions,
+ Type target,
boolean targetAvailable)
{
this.aspectClass = aspectClass;
@@ -82,6 +85,7 @@
this.invocationType = invocationType;
this.joinpointReturnType = joinpointReturnType;
this.joinpointParameters = joinpointParameters;
+ this.joinpointParameterClassTypes = joinpointParameterClassTypes;
this.joinpointExceptions = joinpointExceptions;
this.target = target;
this.targetAvailable = targetAvailable;
@@ -93,16 +97,18 @@
String adviceName,
Class joinPointBeanType,
Class invocationType,
- Class joinpointReturnType,
- Class[] joinpointParameters,
- Class[] joinpointExceptions,
- Class target,
+ Type joinpointReturnType,
+ Type[] joinpointParameters,
+ Class<?>[] joinpointParameterClassTypes,
+ Type[] joinpointExceptions,
+ Type target,
boolean targetAvailable,
- Class caller,
+ Type caller,
boolean callerAvailable)
{
this (aspectClass, adviceName, joinPointBeanType, invocationType, joinpointReturnType,
- joinpointParameters, joinpointExceptions, target, targetAvailable);
+ joinpointParameters, joinpointParameterClassTypes, joinpointExceptions, target,
+ targetAvailable);
this.caller = caller;
this.callerAvailable = callerAvailable;
this.optionalParameters = OptionalParameters.TARGET_CALLER;
@@ -138,19 +144,23 @@
}
- public Class[] getJoinpointExceptions()
+ public Type[] getJoinpointExceptions()
{
return joinpointExceptions;
}
- public Class[] getJoinpointParameters()
+ public Type[] getJoinpointParameters()
{
return joinpointParameters;
}
+ public Class<?>[] getJoinpointParameterClassTypes()
+ {
+ return joinpointParameterClassTypes;
+ }
- public Class<?> getJoinpointReturnType()
+ public Type getJoinpointReturnType()
{
return joinpointReturnType;
}
@@ -170,7 +180,7 @@
return args;
}
- public Class getTargetType()
+ public Type getTargetType()
{
return this.target;
}
@@ -180,7 +190,7 @@
return this.targetAvailable;
}
- public Class getCallerType()
+ public Type getCallerType()
{
return this.caller;
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -2,10 +2,13 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.lang.reflect.Type;
import org.jboss.aop.AspectManager;
import org.jboss.aop.advice.AdviceMethodProperties;
import org.jboss.aop.advice.annotation.AdviceMethodFactory.ReturnType;
+import org.jboss.aop.advice.annotation.assignability.AssignabilityAlgorithm;
+import org.jboss.aop.advice.annotation.assignability.VariableHierarchy;
/**
* Information about an advice method whose parameters should annotated according to
@@ -25,6 +28,8 @@
// the following elements are the annotations whose use is compulsory given
// that precondition is present among the annotated parameters
private int[][] compulsory;
+ // hierarchy of variable types
+ private VariableHierarchy hierarchy;
/**
* Creates an annotated parameter advice info.
@@ -54,6 +59,7 @@
this.contextParamTypes = createParameterAnnotationTypes(contextRules);
this.mutuallyExclusive = mutuallyExclusive;
this.compulsory = compulsory;
+ this.hierarchy = new VariableHierarchy();
this.applyRules(properties);
}
@@ -85,8 +91,9 @@
case NOT_VOID:
if (properties.getJoinpointReturnType() != void.class &&
method.getReturnType() != Object.class &&
- !properties.getJoinpointReturnType().
- isAssignableFrom(method.getReturnType()))
+ !AssignabilityAlgorithm.FROM_VARIABLE.isAssignable(
+ properties.getJoinpointReturnType(),
+ method.getGenericReturnType(), hierarchy))
{
if (AspectManager.verbose)
{
@@ -493,8 +500,9 @@
public final boolean internalValidate(AdviceMethodProperties properties)
{
- if (index != -1 && !method.getParameterTypes()[index].isAssignableFrom(
- (Class)rule.getAssignableFrom(properties)))
+ if (index != -1 && !AssignabilityAlgorithm.VARIABLE_TARGET.isAssignable(
+ method.getGenericParameterTypes()[index],
+ (Type)rule.getAssignableFrom(properties), hierarchy))
{
if (AspectManager.verbose)
{
@@ -520,8 +528,8 @@
return -1;
}
return DEGREE.getAssignabilityDegree(
- method.getParameterTypes()[this.index],
- (Class) rule.getAssignableFrom(properties));
+ method.getGenericParameterTypes()[this.index],
+ (Type) rule.getAssignableFrom(properties));
}
public final void assignParameterInfo(int[] args)
@@ -572,8 +580,8 @@
public final boolean internalValidate(AdviceMethodProperties properties)
{
- Class<?>[] expectedTypes = (Class<?>[]) rule.getAssignableFrom(properties);
- Class<?>[] adviceTypes = method.getParameterTypes();
+ Type[] expectedTypes = (Type[]) rule.getAssignableFrom(properties);
+ Type[] adviceTypes = method.getGenericParameterTypes();
boolean[] taken = new boolean[expectedTypes.length];
for (int i = 0; i < indexesLength; i++)
{
@@ -603,19 +611,20 @@
return false;
}
// wrong type
- if (!adviceTypes[indexes[i][0]].isAssignableFrom(
- expectedTypes[indexes[i][1]]))
+ if (!AssignabilityAlgorithm.VARIABLE_TARGET.isAssignable(
+ adviceTypes[indexes[i][0]], expectedTypes[indexes[i][1]],
+ hierarchy))
{
if (AspectManager.verbose)
{
AdviceMethodFactory.adviceMatchingMessage.append("\n[warn] - Advice parameter ");
AdviceMethodFactory.adviceMatchingMessage.append(indexes[i][0]);
AdviceMethodFactory.adviceMatchingMessage.append(", of type ");
- AdviceMethodFactory.adviceMatchingMessage.append(adviceTypes[indexes[i][0]].getName());
+ AdviceMethodFactory.adviceMatchingMessage.append(adviceTypes[indexes[i][0]]);
AdviceMethodFactory.adviceMatchingMessage.append(", cannot be assigned to the value of joinpoint parameter with index ");
AdviceMethodFactory.adviceMatchingMessage.append(indexes[i][1]);
AdviceMethodFactory.adviceMatchingMessage.append(", whose type is ");
- AdviceMethodFactory.adviceMatchingMessage.append(expectedTypes[indexes[i][1]].getName());
+ AdviceMethodFactory.adviceMatchingMessage.append(expectedTypes[indexes[i][1]]);
}
return false;
}
@@ -657,7 +666,8 @@
{
for (int j = 0; j < expectedTypes.length; j++)
{
- if (adviceTypes[indexes[i][0]].isAssignableFrom(expectedTypes[j]) &&
+ if (AssignabilityAlgorithm.VARIABLE_TARGET.isAssignable(
+ adviceTypes[indexes[i][0]], expectedTypes[j], hierarchy) &&
!taken[j])
{
indexes[i][1] = j;
@@ -702,11 +712,12 @@
{
return -1;
}
- Class[] expectedTypes = (Class[]) rule.getAssignableFrom(properties);
+ Type[] expectedTypes = (Type[]) rule.getAssignableFrom(properties);
short level = 0;
for (int i = 0; i < indexesLength; i++)
{
- level += DEGREE.getAssignabilityDegree(method.getParameterTypes()[this.indexes[i][0]],
+ level += DEGREE.getAssignabilityDegree(
+ method.getGenericParameterTypes()[this.indexes[i][0]],
expectedTypes[this.indexes[i][1]]);
}
return level;
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/assignability/VariableHierarchy.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/assignability/VariableHierarchy.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/assignability/VariableHierarchy.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -42,6 +42,13 @@
this.map = new HashMap<String, VariableNode>();
}
+ public void reset()
+ {
+ this.map.clear();
+ this.boundComparation = 0;
+ this.realBoundComparation = 0;
+ }
+
VariableNode getVariableNode(TypeVariable typeVariable)
{
String key = typeVariable.getName();
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByConJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByConJoinPointGenerator.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByConJoinPointGenerator.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -114,7 +114,7 @@
return false;
}
- protected Class getReturnType()
+ protected Class getReturnClassType()
{
return (Class)returnType.get();
}
@@ -129,8 +129,9 @@
JOINPOINT_TYPE,
INVOCATION_TYPE,
ctor.getDeclaringClass(),
+ ctor.getGenericParameterTypes(),
ctor.getParameterTypes(),
- ctor.getExceptionTypes(),
+ ctor.getGenericExceptionTypes(),
call.getCalledClass(), false,
call.getCallingClass(),
true);
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByMethodJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByMethodJoinPointGenerator.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByMethodJoinPointGenerator.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -123,7 +123,7 @@
return false;
}
- protected Class getReturnType()
+ protected Class getReturnClassType()
{
return (Class)returnType.get();
}
@@ -138,8 +138,9 @@
JOINPOINT_TYPE,
INVOCATION_TYPE,
ctor.getDeclaringClass(),
+ ctor.getGenericParameterTypes(),
ctor.getParameterTypes(),
- ctor.getExceptionTypes(),
+ ctor.getGenericExceptionTypes(),
call.getCalledClass(),
false,
call.getCallingClass(),
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionJoinPointGenerator.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionJoinPointGenerator.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -104,7 +104,7 @@
return true;
}
- protected Class getReturnType()
+ protected Class getReturnClassType()
{
return null;
}
@@ -118,8 +118,9 @@
JOINPOINT_TYPE,
INVOCATION_TYPE,
ctor.getDeclaringClass(),
+ ctor.getGenericParameterTypes(),
ctor.getParameterTypes(),
- ctor.getExceptionTypes(),
+ ctor.getGenericExceptionTypes(),
ctor.getDeclaringClass(),
true);
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorJoinPointGenerator.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorJoinPointGenerator.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -107,7 +107,7 @@
return false;
}
- protected Class getReturnType()
+ protected Class getReturnClassType()
{
return (Class)returnType.get();
}
@@ -121,8 +121,9 @@
JOINPOINT_TYPE,
INVOCATION_TYPE,
ctor.getDeclaringClass(),
+ ctor.getGenericParameterTypes(),
ctor.getParameterTypes(),
- ctor.getExceptionTypes(),
+ ctor.getGenericExceptionTypes(),
ctor.getDeclaringClass(),
false);
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldJoinPointGenerator.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldJoinPointGenerator.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -24,6 +24,7 @@
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
import javassist.CannotCompileException;
import javassist.CtClass;
@@ -74,7 +75,8 @@
}
}
- WeakReference returnType;
+ WeakReference<Class<?>> returnClassType;
+ WeakReference<Type> returnType;
boolean read;
boolean hasTargetObject;
@@ -86,7 +88,8 @@
if (((FieldInfo)info).isRead())
{
read = true;
- returnType = new WeakReference(((FieldInfo)info).getField().getType());
+ returnClassType = new WeakReference(((FieldInfo)info).getField().getType());
+ returnType = new WeakReference(((FieldInfo)info).getField().getGenericType());
}
hasTargetObject = !Modifier.isStatic(((FieldInfo)info).getField().getModifiers());
}
@@ -120,11 +123,11 @@
return !read;
}
- protected Class getReturnType()
+ protected Class<?> getReturnClassType()
{
- if (returnType != null)
+ if (returnClassType != null)
{
- return (Class)returnType.get();
+ return returnClassType.get();
}
return null;
}
@@ -138,7 +141,8 @@
setup.getAdviceName(),
JOINPOINT_TYPE,
(fieldAccess.isRead()) ? READ_INVOCATION_TYPE : WRITE_INVOCATION_TYPE,
- (fieldAccess.isRead()) ? getReturnType() : Void.TYPE,
+ (fieldAccess.isRead()) ? field.getGenericType() : Void.TYPE,
+ (fieldAccess.isRead()) ? new Type[] {} : new Type[] {field.getGenericType()},
(fieldAccess.isRead()) ? new Class[] {} : new Class[] {field.getType()},
null,
field.getDeclaringClass(),
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -434,7 +434,7 @@
}
protected abstract boolean isVoid();
- protected abstract Class getReturnType();
+ protected abstract Class getReturnClassType();
protected abstract AdviceMethodProperties getAdviceMethodProperties(JoinPointBean info, AdviceSetup setup);
protected boolean isCaller()
@@ -660,7 +660,7 @@
if (!isVoid())
{
String ret = null;
- Class retType = getReturnType();
+ Class retType = getReturnClassType();
if (retType.isPrimitive())
{
if (retType.equals(Boolean.TYPE)) ret = "false";
@@ -672,7 +672,7 @@
else if (retType.equals(Float.TYPE)) ret = "0.0f";
else if (retType.equals(Double.TYPE)) ret = "0.0d";
}
- code.append(" " + ClassExpression.simpleType(getReturnType()) + " " + RETURN_VALUE + " = " + ret + ";");
+ code.append(" " + ClassExpression.simpleType(getReturnClassType()) + " " + RETURN_VALUE + " = " + ret + ";");
}
// declare the throwable in an outer variable (this is needed for finally)
@@ -1744,7 +1744,8 @@
if (inconsistentTypeArgs.contains(arg))
{
beforeCall.append("$").append(argIndex).append(" = ");
- beforeCall.append(ReflectToJavassist.castInvocationValueToTypeString(properties.getJoinpointParameters()[arg], ARGUMENTS + '[' + arg + ']'));
+ beforeCall.append(ReflectToJavassist.castInvocationValueToTypeString(
+ properties.getJoinpointParameterClassTypes()[arg], ARGUMENTS + '[' + arg + ']'));
beforeCall.append(';');
inconsistentTypeArgs.remove(arg);
}
@@ -1940,7 +1941,7 @@
return "";
}
return " " + RETURN_VALUE + " = (" +
- generator.getReturnType().getName() + ")";
+ generator.getReturnClassType().getName() + ")";
}
public boolean appendAdviceCall(AdviceSetup setup, String key,
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByConJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByConJoinPointGenerator.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByConJoinPointGenerator.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -118,10 +118,10 @@
protected boolean isVoid()
{
- return getReturnType() == null;
+ return getReturnClassType() == null;
}
- protected Class getReturnType()
+ protected Class getReturnClassType()
{
if (returnType == null)
{
@@ -138,9 +138,10 @@
setup.getAdviceName(),
JOINPOINT_TYPE,
INVOCATION_TYPE,
- method.getReturnType(),
+ method.getGenericReturnType(),
+ method.getGenericParameterTypes(),
method.getParameterTypes(),
- method.getExceptionTypes(),
+ method.getGenericExceptionTypes(),
method.getDeclaringClass(),
hasTargetObject(),
((MethodCallByConstructor) joinPoint).getCallingClass(),
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByMethodJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByMethodJoinPointGenerator.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByMethodJoinPointGenerator.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -127,10 +127,10 @@
protected boolean isVoid()
{
- return getReturnType() == null;
+ return getReturnClassType() == null;
}
- protected Class getReturnType()
+ protected Class getReturnClassType()
{
if (returnType == null)
{
@@ -147,9 +147,10 @@
setup.getAdviceName(),
JOINPOINT_TYPE,
INVOCATION_TYPE,
- method.getReturnType(),
+ method.getGenericReturnType(),
+ method.getGenericParameterTypes(),
method.getParameterTypes(),
- method.getExceptionTypes(),
+ method.getGenericExceptionTypes(),
method.getDeclaringClass(),
hasTargetObject(),
((MethodCallByMethod) joinPoint).getCallingClass(),
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java 2007-07-07 11:53:33 UTC (rev 63901)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java 2007-07-07 23:58:08 UTC (rev 63902)
@@ -113,10 +113,10 @@
protected boolean isVoid()
{
- return getReturnType() == null;
+ return getReturnClassType() == null;
}
- protected Class getReturnType()
+ protected Class getReturnClassType()
{
if (returnType == null)
{
@@ -133,9 +133,10 @@
setup.getAdviceName(),
JOINPOINT_TYPE,
INVOCATION_TYPE,
- method.getReturnType(),
- method.getParameterTypes(),
- method.getExceptionTypes(),
+ method.getGenericReturnType(),
+ method.getGenericParameterTypes(),
+ method.getParameterTypes(),
+ method.getGenericExceptionTypes(),
method.getDeclaringClass(),
hasTargetObject());
}
More information about the jboss-cvs-commits
mailing list