Generics make code more type-safe and allows removing ugly type-casts.tags/V1_9_8
ResolvedMember sig = ResolvedMemberImpl.readResolvedMember(s, context); | ResolvedMember sig = ResolvedMemberImpl.readResolvedMember(s, context); | ||||
ResolvedMember syntheticCtor = ResolvedMemberImpl.readResolvedMember(s, context); | ResolvedMember syntheticCtor = ResolvedMemberImpl.readResolvedMember(s, context); | ||||
ResolvedMember explicitCtor = ResolvedMemberImpl.readResolvedMember(s, context); | ResolvedMember explicitCtor = ResolvedMemberImpl.readResolvedMember(s, context); | ||||
Set superMethodsCalled = readSuperMethodsCalled(s); | |||||
Set<ResolvedMember> superMethodsCalled = readSuperMethodsCalled(s); | |||||
sloc = readSourceLocation(s); | sloc = readSourceLocation(s); | ||||
List typeVarAliases = readInTypeAliases(s); | |||||
List<String> typeVarAliases = readInTypeAliases(s); | |||||
ResolvedTypeMunger munger = new NewConstructorTypeMunger(sig, syntheticCtor, explicitCtor, superMethodsCalled, | ResolvedTypeMunger munger = new NewConstructorTypeMunger(sig, syntheticCtor, explicitCtor, superMethodsCalled, | ||||
typeVarAliases); | typeVarAliases); | ||||
if (sloc != null) { | if (sloc != null) { |
public static ResolvedTypeMunger readField(VersionedDataInputStream s, ISourceContext context) throws IOException { | public static ResolvedTypeMunger readField(VersionedDataInputStream s, ISourceContext context) throws IOException { | ||||
ISourceLocation sloc = null; | ISourceLocation sloc = null; | ||||
ResolvedMember fieldSignature = ResolvedMemberImpl.readResolvedMember(s, context); | ResolvedMember fieldSignature = ResolvedMemberImpl.readResolvedMember(s, context); | ||||
Set superMethodsCalled = readSuperMethodsCalled(s); | |||||
Set<ResolvedMember> superMethodsCalled = readSuperMethodsCalled(s); | |||||
sloc = readSourceLocation(s); | sloc = readSourceLocation(s); | ||||
List aliases = readInTypeAliases(s); | |||||
List<String> aliases = readInTypeAliases(s); | |||||
NewFieldTypeMunger munger = new NewFieldTypeMunger(fieldSignature, superMethodsCalled, aliases); | NewFieldTypeMunger munger = new NewFieldTypeMunger(fieldSignature, superMethodsCalled, aliases); | ||||
if (sloc != null) { | if (sloc != null) { | ||||
munger.setSourceLocation(sloc); | munger.setSourceLocation(sloc); |
if (isParameterized && (typeVariables.length != typeParameters.length)) { | if (isParameterized && (typeVariables.length != typeParameters.length)) { | ||||
throw new IllegalStateException("Wrong number of type parameters supplied"); | throw new IllegalStateException("Wrong number of type parameters supplied"); | ||||
} | } | ||||
Map typeMap = new HashMap(); | |||||
Map<String, UnresolvedType> typeMap = new HashMap<>(); | |||||
boolean typeParametersSupplied = typeParameters != null && typeParameters.length > 0; | boolean typeParametersSupplied = typeParameters != null && typeParameters.length > 0; | ||||
if (typeVariables != null) { | if (typeVariables != null) { | ||||
// If no 'replacements' were supplied in the typeParameters array then collapse | // If no 'replacements' were supplied in the typeParameters array then collapse |
private void sortMungers() { | private void sortMungers() { | ||||
List sorted = PartialOrder.sort(mungers); | |||||
List<ShadowMunger> sorted = PartialOrder.sort(mungers); | |||||
// Bunch of code to work out whether to report xlints for advice that isn't ordered at this Joinpoint | // Bunch of code to work out whether to report xlints for advice that isn't ordered at this Joinpoint | ||||
possiblyReportUnorderedAdvice(sorted); | possiblyReportUnorderedAdvice(sorted); | ||||
} | } | ||||
// not quite optimal... but the xlint is ignore by default | // not quite optimal... but the xlint is ignore by default | ||||
private void possiblyReportUnorderedAdvice(List sorted) { | |||||
private void possiblyReportUnorderedAdvice(List<ShadowMunger> sorted) { | |||||
if (sorted != null && getIWorld().getLint().unorderedAdviceAtShadow.isEnabled() && mungers.size() > 1) { | if (sorted != null && getIWorld().getLint().unorderedAdviceAtShadow.isEnabled() && mungers.size() > 1) { | ||||
// Stores a set of strings of the form 'aspect1:aspect2' which indicates there is no | // Stores a set of strings of the form 'aspect1:aspect2' which indicates there is no |
protected final int hashcode; | protected final int hashcode; | ||||
private final WeakReference loaderRef; | |||||
private final WeakReference<ClassLoader> loaderRef; | |||||
public WeakClassLoaderReference(ClassLoader loader) { | public WeakClassLoaderReference(ClassLoader loader) { | ||||
loaderRef = new WeakReference(loader); | |||||
loaderRef = new WeakReference<>(loader); | |||||
if(loader == null){ | if(loader == null){ | ||||
// Bug: 363962 | // Bug: 363962 | ||||
// Check that ClassLoader is not null, for instance when loaded from BootStrapClassLoader | // Check that ClassLoader is not null, for instance when loaded from BootStrapClassLoader |
public static class Handler implements Member { | public static class Handler implements Member { | ||||
private Class decClass; | |||||
private Class exType; | |||||
private Class<?> decClass; | |||||
private Class<?> exType; | |||||
public Handler(Class decClass, Class exType) { | public Handler(Class decClass, Class exType) { | ||||
this.decClass = decClass; | this.decClass = decClass; |
public static class Handler implements Member { | public static class Handler implements Member { | ||||
private Class decClass; | |||||
private Class exType; | |||||
private Class<?> decClass; | |||||
private Class<?> exType; | |||||
public Handler(Class decClass, Class exType) { | public Handler(Class decClass, Class exType) { | ||||
this.decClass = decClass; | this.decClass = decClass; |
if (rMember.isAnnotatedElsewhere()) { | if (rMember.isAnnotatedElsewhere()) { | ||||
if (kind == Shadow.FieldGet || kind == Shadow.FieldSet) { | if (kind == Shadow.FieldGet || kind == Shadow.FieldSet) { | ||||
// FIXME asc should include supers with getInterTypeMungersIncludingSupers ? | // FIXME asc should include supers with getInterTypeMungersIncludingSupers ? | ||||
List mungers = rMember.getDeclaringType().resolve(shadow.getIWorld()).getInterTypeMungers(); | |||||
List<ConcreteTypeMunger> mungers = rMember.getDeclaringType().resolve(shadow.getIWorld()).getInterTypeMungers(); | |||||
for (Object munger : mungers) { | for (Object munger : mungers) { | ||||
ConcreteTypeMunger typeMunger = (ConcreteTypeMunger) munger; | ConcreteTypeMunger typeMunger = (ConcreteTypeMunger) munger; | ||||
if (typeMunger.getMunger() instanceof NewFieldTypeMunger) { | if (typeMunger.getMunger() instanceof NewFieldTypeMunger) { |
private boolean hasField(ResolvedType type) { | private boolean hasField(ResolvedType type) { | ||||
// TODO what about ITDs | // TODO what about ITDs | ||||
World world = type.getWorld(); | World world = type.getWorld(); | ||||
for (Iterator iter = type.getFields(); iter.hasNext();) { | |||||
for (Iterator<ResolvedMember> iter = type.getFields(); iter.hasNext();) { | |||||
Member field = (Member) iter.next(); | Member field = (Member) iter.next(); | ||||
if (field.getName().startsWith(declareAtPrefix)) { | if (field.getName().startsWith(declareAtPrefix)) { | ||||
continue; | continue; |
ResolvedPointcutDefinition def = bindings.peekEnclosingDefinition(); | ResolvedPointcutDefinition def = bindings.peekEnclosingDefinition(); | ||||
if (def != null) { | if (def != null) { | ||||
ResolvedType aspect = inAspect.getWorld().resolve(def.getDeclaringType()); | ResolvedType aspect = inAspect.getWorld().resolve(def.getDeclaringType()); | ||||
for (Iterator memberIter = aspect.getMethods(true, true); memberIter.hasNext();) { | |||||
for (Iterator<ResolvedMember> memberIter = aspect.getMethods(true, true); memberIter.hasNext();) { | |||||
ResolvedMember method = (ResolvedMember) memberIter.next(); | ResolvedMember method = (ResolvedMember) memberIter.next(); | ||||
if (def.getName().equals(method.getName()) | if (def.getName().equals(method.getName()) | ||||
&& def.getParameterTypes().length == method.getParameterTypes().length) { | && def.getParameterTypes().length == method.getParameterTypes().length) { |
public static ReflectionBasedReferenceTypeDelegate createDelegate(ReferenceType forReferenceType, World inWorld, | public static ReflectionBasedReferenceTypeDelegate createDelegate(ReferenceType forReferenceType, World inWorld, | ||||
ClassLoader usingClassLoader) { | ClassLoader usingClassLoader) { | ||||
try { | try { | ||||
Class c = Class.forName(forReferenceType.getName(), false, usingClassLoader); | |||||
Class<?> c = Class.forName(forReferenceType.getName(), false, usingClassLoader); | |||||
ReflectionBasedReferenceTypeDelegate rbrtd = create15Delegate(forReferenceType, c, usingClassLoader, inWorld); | ReflectionBasedReferenceTypeDelegate rbrtd = create15Delegate(forReferenceType, c, usingClassLoader, inWorld); | ||||
if (rbrtd != null) { | if (rbrtd != null) { | ||||
return rbrtd; // can be null if we didn't find the class the delegate logic loads | return rbrtd; // can be null if we didn't find the class the delegate logic loads | ||||
public static ReflectionBasedReferenceTypeDelegate create14Delegate(ReferenceType forReferenceType, World inWorld, | public static ReflectionBasedReferenceTypeDelegate create14Delegate(ReferenceType forReferenceType, World inWorld, | ||||
ClassLoader usingClassLoader) { | ClassLoader usingClassLoader) { | ||||
try { | try { | ||||
Class c = Class.forName(forReferenceType.getName(), false, usingClassLoader); | |||||
Class<?> c = Class.forName(forReferenceType.getName(), false, usingClassLoader); | |||||
return new ReflectionBasedReferenceTypeDelegate(c, usingClassLoader, inWorld, forReferenceType); | return new ReflectionBasedReferenceTypeDelegate(c, usingClassLoader, inWorld, forReferenceType); | ||||
} catch (ClassNotFoundException cnfEx) { | } catch (ClassNotFoundException cnfEx) { | ||||
return null; | return null; | ||||
private static ReflectionBasedReferenceTypeDelegate create15Delegate(ReferenceType forReferenceType, Class forClass, | private static ReflectionBasedReferenceTypeDelegate create15Delegate(ReferenceType forReferenceType, Class forClass, | ||||
ClassLoader usingClassLoader, World inWorld) { | ClassLoader usingClassLoader, World inWorld) { | ||||
try { | try { | ||||
Class delegateClass = Class.forName("org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate"); | |||||
Class<?> delegateClass = Class.forName("org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate"); | |||||
ReflectionBasedReferenceTypeDelegate ret = (ReflectionBasedReferenceTypeDelegate) delegateClass.getDeclaredConstructor().newInstance(); | ReflectionBasedReferenceTypeDelegate ret = (ReflectionBasedReferenceTypeDelegate) delegateClass.getDeclaredConstructor().newInstance(); | ||||
ret.initialize(forReferenceType, forClass, usingClassLoader, inWorld); | ret.initialize(forReferenceType, forClass, usingClassLoader, inWorld); | ||||
return ret; | return ret; | ||||
private static GenericSignatureInformationProvider createGenericSignatureProvider(World inWorld) { | private static GenericSignatureInformationProvider createGenericSignatureProvider(World inWorld) { | ||||
try { | try { | ||||
Class providerClass = Class.forName("org.aspectj.weaver.reflect.Java15GenericSignatureInformationProvider"); | |||||
Constructor cons = providerClass.getConstructor(new Class[] { World.class }); | |||||
Class<?> providerClass = Class.forName("org.aspectj.weaver.reflect.Java15GenericSignatureInformationProvider"); | |||||
Constructor<?> cons = providerClass.getConstructor(new Class[] { World.class }); | |||||
GenericSignatureInformationProvider ret = (GenericSignatureInformationProvider) cons | GenericSignatureInformationProvider ret = (GenericSignatureInformationProvider) cons | ||||
.newInstance(new Object[] { inWorld }); | .newInstance(new Object[] { inWorld }); | ||||
return ret; | return ret; | ||||
} | } | ||||
} | } | ||||
private static ResolvedType toResolvedType(Class aClass, IReflectionWorld aWorld) { | |||||
private static ResolvedType toResolvedType(Class<?> aClass, IReflectionWorld aWorld) { | |||||
return aWorld.resolve(aClass); | return aWorld.resolve(aClass); | ||||
} | } | ||||
private Var[] argsVars = null; | private Var[] argsVars = null; | ||||
private Var atThisVar = null; | private Var atThisVar = null; | ||||
private Var atTargetVar = null; | private Var atTargetVar = null; | ||||
private Map atArgsVars = new HashMap(); | |||||
private Map withinAnnotationVar = new HashMap(); | |||||
private Map withinCodeAnnotationVar = new HashMap(); | |||||
private Map annotationVar = new HashMap(); | |||||
private Map<ResolvedType, Var[]> atArgsVars = new HashMap<>(); | |||||
private Map<ResolvedType, Var> withinAnnotationVar = new HashMap<>(); | |||||
private Map<ResolvedType, Var> withinCodeAnnotationVar = new HashMap<>(); | |||||
private Map<ResolvedType, Var> annotationVar = new HashMap<>(); | |||||
private AnnotationFinder annotationFinder; | private AnnotationFinder annotationFinder; | ||||
public static Shadow makeExecutionShadow(World inWorld, java.lang.reflect.Member forMethod, MatchingContext withContext) { | public static Shadow makeExecutionShadow(World inWorld, java.lang.reflect.Member forMethod, MatchingContext withContext) { |
private Var[] argsVars = null; | private Var[] argsVars = null; | ||||
private Var atThisVar = null; | private Var atThisVar = null; | ||||
private Var atTargetVar = null; | private Var atTargetVar = null; | ||||
private Map atArgsVars = new HashMap(); | |||||
private Map withinAnnotationVar = new HashMap(); | |||||
private Map withinCodeAnnotationVar = new HashMap(); | |||||
private Map annotationVar = new HashMap(); | |||||
private Map<ResolvedType, Var[]> atArgsVars = new HashMap<>(); | |||||
private Map<ResolvedType, Var> withinAnnotationVar = new HashMap<>(); | |||||
private Map<ResolvedType, Var> withinCodeAnnotationVar = new HashMap<>(); | |||||
private Map<ResolvedType, Var> annotationVar = new HashMap<>(); | |||||
private AnnotationFinder annotationFinder; | private AnnotationFinder annotationFinder; | ||||
public static Shadow makeExecutionShadow(World inWorld, java.lang.reflect.Member forMethod, MatchingContext withContext) { | public static Shadow makeExecutionShadow(World inWorld, java.lang.reflect.Member forMethod, MatchingContext withContext) { |
*/ | */ | ||||
public class DefaultMatchingContext implements MatchingContext { | public class DefaultMatchingContext implements MatchingContext { | ||||
private Map contextMap = new HashMap(); | |||||
private Map<String, Object> contextMap = new HashMap<>(); | |||||
/* (non-Javadoc) | /* (non-Javadoc) | ||||
* @see org.aspectj.weaver.tools.MatchingContext#hasContextParameter(java.lang.String) | * @see org.aspectj.weaver.tools.MatchingContext#hasContextParameter(java.lang.String) |
* @param supportedPointcutKinds a set of PointcutPrimitives this parser should support | * @param supportedPointcutKinds a set of PointcutPrimitives this parser should support | ||||
* @throws UnsupportedOperationException if the set contains if, cflow, or cflow below | * @throws UnsupportedOperationException if the set contains if, cflow, or cflow below | ||||
*/ | */ | ||||
private StandardPointcutParser(Set/* <PointcutPrimitives> */supportedPointcutKinds, World world) { | |||||
private StandardPointcutParser(Set<PointcutPrimitive> supportedPointcutKinds, World world) { | |||||
supportedPrimitives = supportedPointcutKinds; | supportedPrimitives = supportedPointcutKinds; | ||||
for (Object supportedPointcutKind : supportedPointcutKinds) { | for (Object supportedPointcutKind : supportedPointcutKinds) { | ||||
PointcutPrimitive element = (PointcutPrimitive) supportedPointcutKind; | PointcutPrimitive element = (PointcutPrimitive) supportedPointcutKind; | ||||
return current; | return current; | ||||
} | } | ||||
private IScope buildResolutionScope(Class inScope, PointcutParameter[] formalParameters) { | |||||
private IScope buildResolutionScope(Class<?> inScope, PointcutParameter[] formalParameters) { | |||||
if (formalParameters == null) { | if (formalParameters == null) { | ||||
formalParameters = new PointcutParameter[0]; | formalParameters = new PointcutParameter[0]; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
private UnresolvedType toUnresolvedType(Class clazz) { | |||||
private UnresolvedType toUnresolvedType(Class<?> clazz) { | |||||
if (clazz.isArray()) { | if (clazz.isArray()) { | ||||
return UnresolvedType.forSignature(clazz.getName().replace('.', '/')); | return UnresolvedType.forSignature(clazz.getName().replace('.', '/')); | ||||
} else { | } else { |
instance = new DefaultTraceFactory(); | instance = new DefaultTraceFactory(); | ||||
} | } | ||||
else { | else { | ||||
Class factoryClass = Class.forName(factoryName); | |||||
Class<?> factoryClass = Class.forName(factoryName); | |||||
instance = (TraceFactory)factoryClass.getDeclaredConstructor().newInstance(); | instance = (TraceFactory)factoryClass.getDeclaredConstructor().newInstance(); | ||||
} | } | ||||
} | } | ||||
*/ | */ | ||||
if (instance == null) try { | if (instance == null) try { | ||||
{ | { | ||||
Class factoryClass = Class.forName("org.aspectj.weaver.tools.Jdk14TraceFactory"); | |||||
Class<?> factoryClass = Class.forName("org.aspectj.weaver.tools.Jdk14TraceFactory"); | |||||
instance = (TraceFactory)factoryClass.getDeclaredConstructor().newInstance(); | instance = (TraceFactory)factoryClass.getDeclaredConstructor().newInstance(); | ||||
} | } | ||||
} | } |