aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.matcher
diff options
context:
space:
mode:
authorAndy Clement <aclement@pivotal.io>2018-01-31 17:21:15 -0800
committerAndy Clement <aclement@pivotal.io>2018-01-31 17:21:15 -0800
commitd6378eeec8c1928462f8561d23fafda5012b790c (patch)
treeb284fae6130eeb739939a7fe7d8ff505241b7c99 /org.aspectj.matcher
parent7f0dc0dd21115bfcc9d0ba830e57cc369054d3d5 (diff)
parent381ccd8684cc181451d44fda4e3044098367fb52 (diff)
downloadaspectj-d6378eeec8c1928462f8561d23fafda5012b790c.tar.gz
aspectj-d6378eeec8c1928462f8561d23fafda5012b790c.zip
merged
Diffstat (limited to 'org.aspectj.matcher')
-rw-r--r--org.aspectj.matcher/org.aspectj.matcher.mf.txt1
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/AjcMemberMaker.java2
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/Lint.java2
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java10
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java30
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/World.java3
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/patterns/HasMemberTypePattern.java9
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/reflect/AnnotationFinder.java16
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java105
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionWorld.java61
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/tools/PointcutParser.java41
11 files changed, 163 insertions, 117 deletions
diff --git a/org.aspectj.matcher/org.aspectj.matcher.mf.txt b/org.aspectj.matcher/org.aspectj.matcher.mf.txt
index f3fe07179..ae8d8d8d0 100644
--- a/org.aspectj.matcher/org.aspectj.matcher.mf.txt
+++ b/org.aspectj.matcher/org.aspectj.matcher.mf.txt
@@ -1,4 +1,5 @@
Manifest-Version: 1.0
+Automatic-Module-Name: org.aspectj.matcher
Name: org/aspectj/matcher/
Specification-Title: AspectJ Matcher Classes
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/AjcMemberMaker.java b/org.aspectj.matcher/src/org/aspectj/weaver/AjcMemberMaker.java
index 62459bdb8..1870eb501 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/AjcMemberMaker.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/AjcMemberMaker.java
@@ -74,7 +74,7 @@ public class AjcMemberMaker {
}
public static ResolvedMember perSingletonField(UnresolvedType declaringType) {
- return new ResolvedMemberImpl(Member.FIELD, declaringType, PUBLIC_STATIC_FINAL, NameMangler.PERSINGLETON_FIELD_NAME,
+ return new ResolvedMemberImpl(Member.FIELD, declaringType, PUBLIC_STATIC, NameMangler.PERSINGLETON_FIELD_NAME,
declaringType.getSignature());
}
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/Lint.java b/org.aspectj.matcher/src/org/aspectj/weaver/Lint.java
index 36d647512..aab34b8f6 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/Lint.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/Lint.java
@@ -114,7 +114,7 @@ public class Lint {
"calculated SerialVersionUID for type {0} to be {1}");
public final Kind nonReweavableTypeEncountered = new Kind("nonReweavableTypeEncountered",
- "class '{0}' is already woven and has not been built in reweavable mode");
+ "class {0} is already woven and has not been built in reweavable mode");
// there are a lot of messages in the cant find type family - I'm defining an umbrella lint warning that
// allows a user to control their severity (for e.g. ltw or binary weaving)
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java
index 65fdf3a95..7dc162a16 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java
@@ -376,10 +376,16 @@ public class ReferenceType extends ResolvedType {
if (this.isFinal() || other.isFinal()) {
return false;
}
+
+ // 20170927: What is the block of code for? It mentions jls5.5 which isn't on this topic (old version of jls?)
+ // Some possible references: http://docs.oracle.com/javase/specs/jls/se9/jls9.pdf 5.1.6 (narrowing reference conversion)
+ // On Java 9 the test GenericsTests.testAfterReturningWithWildcardVar will fail because this code below
+ // used to find Set and List were the same, but now finds they are not. (so it doesn't put out the unchecked
+ // conversion message). However the code "List l = (List)someSet;" still compiles on 9 - so is this code bogus?
+
// ??? needs to be Methods, not just declared methods? JLS 5.5 unclear
ResolvedMember[] a = getDeclaredMethods();
- ResolvedMember[] b = other.getDeclaredMethods(); // ??? is this cast
- // always safe
+ ResolvedMember[] b = other.getDeclaredMethods();
for (int ai = 0, alen = a.length; ai < alen; ai++) {
for (int bi = 0, blen = b.length; bi < blen; bi++) {
if (!b[bi].isCompatibleWith(a[ai])) {
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java
index 5985e4b6d..daccec105 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/ResolvedType.java
@@ -966,12 +966,38 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl
}
TypeVariable[] tvs = getGenericType().getTypeVariables();
Map<String, UnresolvedType> parameterizationMap = new HashMap<String, UnresolvedType>();
- for (int i = 0; i < tvs.length; i++) {
- parameterizationMap.put(tvs[i].getName(), typeParameters[i]);
+ if (tvs.length != typeParameters.length) {
+ world.getMessageHandler()
+ .handleMessage(
+ new Message("Mismatch when building parameterization map. For type '" + this.signature +
+ "' expecting "+tvs.length+":["+toString(tvs)+"] type parameters but found "+typeParameters.length+
+ ":["+toString(typeParameters)+"]", "",
+ IMessage.ERROR, getSourceLocation(), null,
+ new ISourceLocation[] { getSourceLocation() }));
+ } else {
+ for (int i = 0; i < tvs.length; i++) {
+ parameterizationMap.put(tvs[i].getName(), typeParameters[i]);
+ }
}
return parameterizationMap;
}
+ private String toString(UnresolvedType[] typeParameters) {
+ StringBuilder s = new StringBuilder();
+ for (UnresolvedType tv: typeParameters) {
+ s.append(tv.getSignature()).append(" ");
+ }
+ return s.toString().trim();
+ }
+
+ private String toString(TypeVariable[] tvs) {
+ StringBuilder s = new StringBuilder();
+ for (TypeVariable tv: tvs) {
+ s.append(tv.getName()).append(" ");
+ }
+ return s.toString().trim();
+ }
+
public List<ShadowMunger> getDeclaredAdvice() {
List<ShadowMunger> l = new ArrayList<ShadowMunger>();
ResolvedMember[] methods = getDeclaredMethods();
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/World.java b/org.aspectj.matcher/src/org/aspectj/weaver/World.java
index 6bba2d551..19d61f5be 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/World.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/World.java
@@ -462,6 +462,9 @@ public abstract class World implements Dump.INode {
} else if (ty.isGenericType()) {
// ======= generic types ======================
ResolvedType rt = resolveGenericTypeFor(ty, false);
+ if (rt.isMissing()) {
+ return rt;
+ }
ReferenceType genericType = (ReferenceType) rt;
if (rt.isMissing()) {
return rt;
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/HasMemberTypePattern.java b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/HasMemberTypePattern.java
index 6aa55a45a..2b1f28fd4 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/patterns/HasMemberTypePattern.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/patterns/HasMemberTypePattern.java
@@ -87,11 +87,18 @@ public class HasMemberTypePattern extends TypePattern {
continue;
}
if (signaturePattern.matches(method, type.getWorld(), false)) {
- if (method.getDeclaringType().resolve(world) != type) {
+ ResolvedType declaringType = method.getDeclaringType().resolve(world);
+ if (declaringType != type) {
if (Modifier.isPrivate(method.getModifiers())) {
continue;
}
}
+ // J9: Object.finalize() is marked Deprecated it seems... triggers unhelpful messages
+ if (method.getName().equals("finalize") && declaringType.equals(ResolvedType.OBJECT)
+ && (signaturePattern.getAnnotationPattern() instanceof ExactAnnotationTypePattern)
+ && ((ExactAnnotationTypePattern)signaturePattern.getAnnotationPattern()).getAnnotationType().getSignature().equals("Ljava/lang/Deprecated;")) {
+ continue;
+ }
return true;
}
}
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/AnnotationFinder.java b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/AnnotationFinder.java
index 7efeac9ae..90ce368d9 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/AnnotationFinder.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/AnnotationFinder.java
@@ -1,18 +1,16 @@
/* *******************************************************************
- * Copyright (c) 2005 Contributors.
+ * Copyright (c) 2005, 2017 Contributors.
+ *
* 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://eclipse.org/legal/epl-v10.html
*
- * Contributors:
- * Adrian Colyer Initial implementation
* ******************************************************************/
package org.aspectj.weaver.reflect;
import java.lang.reflect.Member;
-import java.util.Set;
import org.aspectj.weaver.AnnotationAJ;
import org.aspectj.weaver.ResolvedType;
@@ -20,7 +18,8 @@ import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
/**
- * @author colyer Used in 1.4 code to access annotations safely
+ * @author Adrian Colyer
+ * @author Andy Clement
*/
public interface AnnotationFinder {
@@ -32,14 +31,13 @@ public interface AnnotationFinder {
Object getAnnotationFromMember(ResolvedType annotationType, Member aMember);
- public AnnotationAJ getAnnotationOfType(UnresolvedType ofType,
- Member onMember);
+ public AnnotationAJ getAnnotationOfType(UnresolvedType ofType, Member onMember);
public String getAnnotationDefaultValue(Member onMember);
- Object getAnnotationFromClass(ResolvedType annotationType, Class aClass);
+ Object getAnnotationFromClass(ResolvedType annotationType, Class<?> aClass);
- Set/* ResolvedType */getAnnotations(Member onMember);
+ ResolvedType[] getAnnotations(Member onMember, boolean runtimeAnnotationsOnly);
ResolvedType[][] getParameterAnnotationTypes(Member onMember);
}
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java
index 28c8aacf6..ba8f1330e 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java
@@ -1,18 +1,15 @@
/* *******************************************************************
- * Copyright (c) 2005 Contributors.
+ * Copyright (c) 2005, 2017 Contributors.
* 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://eclipse.org/legal/epl-v10.html
*
- * Contributors:
- * Adrian Colyer Initial implementation
* ******************************************************************/
package org.aspectj.weaver.reflect;
import java.lang.reflect.Member;
-import java.util.Set;
import org.aspectj.weaver.AnnotationAJ;
import org.aspectj.weaver.MemberKind;
@@ -24,37 +21,29 @@ import org.aspectj.weaver.UnresolvedType;
/**
* Subtype of ResolvedMemberImpl used in reflection world. Knows how to get annotations from a java.lang.reflect.Member
*
+ * @author Adrian Colyer
+ * @author Andy Clement
*/
public class ReflectionBasedResolvedMemberImpl extends ResolvedMemberImpl {
private AnnotationFinder annotationFinder = null;
private GenericSignatureInformationProvider gsigInfoProvider = new Java14GenericSignatureInformationProvider();
+
+ /**
+ * If true then only runtime visible annotations have been resolved via reflection. If class retention
+ * annotations are also required (later) then the cache will have to be rebuilt using a more detailed
+ * dig into the class file.
+ */
+ private boolean onlyRuntimeAnnotationsCached;
private Member reflectMember;
- /**
- * @param kind
- * @param declaringType
- * @param modifiers
- * @param returnType
- * @param name
- * @param parameterTypes
- */
public ReflectionBasedResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers,
UnresolvedType returnType, String name, UnresolvedType[] parameterTypes, Member reflectMember) {
super(kind, declaringType, modifiers, returnType, name, parameterTypes);
this.reflectMember = reflectMember;
}
- /**
- * @param kind
- * @param declaringType
- * @param modifiers
- * @param returnType
- * @param name
- * @param parameterTypes
- * @param checkedExceptions
- */
public ReflectionBasedResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers,
UnresolvedType returnType, String name, UnresolvedType[] parameterTypes, UnresolvedType[] checkedExceptions,
Member reflectMember) {
@@ -62,16 +51,6 @@ public class ReflectionBasedResolvedMemberImpl extends ResolvedMemberImpl {
this.reflectMember = reflectMember;
}
- /**
- * @param kind
- * @param declaringType
- * @param modifiers
- * @param returnType
- * @param name
- * @param parameterTypes
- * @param checkedExceptions
- * @param backingGenericMember
- */
public ReflectionBasedResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers,
UnresolvedType returnType, String name, UnresolvedType[] parameterTypes, UnresolvedType[] checkedExceptions,
ResolvedMember backingGenericMember, Member reflectMember) {
@@ -79,13 +58,6 @@ public class ReflectionBasedResolvedMemberImpl extends ResolvedMemberImpl {
this.reflectMember = reflectMember;
}
- /**
- * @param kind
- * @param declaringType
- * @param modifiers
- * @param name
- * @param signature
- */
public ReflectionBasedResolvedMemberImpl(MemberKind kind, UnresolvedType declaringType, int modifiers, String name,
String signature, Member reflectMember) {
super(kind, declaringType, modifiers, name, signature);
@@ -96,89 +68,64 @@ public class ReflectionBasedResolvedMemberImpl extends ResolvedMemberImpl {
return this.reflectMember;
}
- // generic signature support
-
public void setGenericSignatureInformationProvider(GenericSignatureInformationProvider gsigProvider) {
this.gsigInfoProvider = gsigProvider;
}
- /*
- * (non-Javadoc)
- *
- * @see org.aspectj.weaver.ResolvedMemberImpl#getGenericParameterTypes()
- */
@Override
public UnresolvedType[] getGenericParameterTypes() {
return this.gsigInfoProvider.getGenericParameterTypes(this);
}
- /*
- * (non-Javadoc)
- *
- * @see org.aspectj.weaver.ResolvedMemberImpl#getGenericReturnType()
- */
@Override
public UnresolvedType getGenericReturnType() {
return this.gsigInfoProvider.getGenericReturnType(this);
}
- /*
- * (non-Javadoc)
- *
- * @see org.aspectj.weaver.ResolvedMemberImpl#isSynthetic()
- */
@Override
public boolean isSynthetic() {
return this.gsigInfoProvider.isSynthetic(this);
}
- /*
- * (non-Javadoc)
- *
- * @see org.aspectj.weaver.ResolvedMemberImpl#isVarargsMethod()
- */
@Override
public boolean isVarargsMethod() {
return this.gsigInfoProvider.isVarArgs(this);
}
- /*
- * (non-Javadoc)
- *
- * @see org.aspectj.weaver.ResolvedMemberImpl#isBridgeMethod()
- */
@Override
public boolean isBridgeMethod() {
return this.gsigInfoProvider.isBridge(this);
}
- // annotation support
-
public void setAnnotationFinder(AnnotationFinder finder) {
this.annotationFinder = finder;
}
@Override
public boolean hasAnnotation(UnresolvedType ofType) {
- unpackAnnotations();
+ boolean areRuntimeRetentionAnnotationsSufficient = false;
+ if (ofType instanceof ResolvedType) {
+ areRuntimeRetentionAnnotationsSufficient = ((ResolvedType)ofType).isAnnotationWithRuntimeRetention();
+ }
+ unpackAnnotations(areRuntimeRetentionAnnotationsSufficient);
return super.hasAnnotation(ofType);
}
@Override
public boolean hasAnnotations() {
- unpackAnnotations();
+ unpackAnnotations(false);
return super.hasAnnotations();
}
@Override
public ResolvedType[] getAnnotationTypes() {
- unpackAnnotations();
+ unpackAnnotations(false);
return super.getAnnotationTypes();
}
@Override
public AnnotationAJ getAnnotationOfType(UnresolvedType ofType) {
- unpackAnnotations();
+ unpackAnnotations(false);
if (annotationFinder == null || annotationTypes == null) {
return null;
}
@@ -206,18 +153,10 @@ public class ReflectionBasedResolvedMemberImpl extends ResolvedMemberImpl {
return parameterAnnotationTypes;
}
- private void unpackAnnotations() {
- if (annotationTypes == null && annotationFinder != null) {
- Set<?> s = annotationFinder.getAnnotations(reflectMember);
- if (s.size() == 0) {
- annotationTypes = ResolvedType.EMPTY_ARRAY;
- } else {
- annotationTypes = new ResolvedType[s.size()];
- int i = 0;
- for (Object o : s) {
- annotationTypes[i++] = (ResolvedType) o;
- }
- }
+ private void unpackAnnotations(boolean areRuntimeRetentionAnnotationsSufficient) {
+ if (annotationFinder != null && (annotationTypes == null || (!areRuntimeRetentionAnnotationsSufficient && onlyRuntimeAnnotationsCached))) {
+ annotationTypes = annotationFinder.getAnnotations(reflectMember, areRuntimeRetentionAnnotationsSufficient);
+ onlyRuntimeAnnotationsCached = areRuntimeRetentionAnnotationsSufficient;
}
}
}
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionWorld.java b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionWorld.java
index 98e800222..c784ff288 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionWorld.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ReflectionWorld.java
@@ -1,17 +1,16 @@
/* *******************************************************************
- * Copyright (c) 2005 Contributors.
+ * Copyright (c) 2005-2017 Contributors.
* 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://eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Adrian Colyer Initial implementation
* ******************************************************************/
package org.aspectj.weaver.reflect;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import org.aspectj.bridge.AbortException;
@@ -31,14 +30,55 @@ import org.aspectj.weaver.World;
* A ReflectionWorld is used solely for purposes of type resolution based on the runtime classpath (java.lang.reflect). It does not
* support weaving operations (creation of mungers etc..).
*
+ * @author Adrian Colyer
+ * @author Andy Clement
*/
public class ReflectionWorld extends World implements IReflectionWorld {
+ private static Map<WeakClassLoaderReference, ReflectionWorld> rworlds = Collections.synchronizedMap(new HashMap<WeakClassLoaderReference, ReflectionWorld>());
+
private WeakClassLoaderReference classLoaderReference;
private AnnotationFinder annotationFinder;
private boolean mustUseOneFourDelegates = false; // for testing
private Map<String,Class<?>> inProgressResolutionClasses = new HashMap<String,Class<?>>();
-
+
+ public static ReflectionWorld getReflectionWorldFor(WeakClassLoaderReference classLoaderReference) {
+
+ // Temporarily do as before. Although the cache makes things faster it needs a bit more thought because
+ // if the world has pointcutdesignators registered then someone may inadvertently register additional
+ // ones on reusing a world (when they would be expecting a clean world). We can't automatically
+ // clear them because we don't know when they are finished with.
+ return new ReflectionWorld(classLoaderReference);
+
+ /*
+ synchronized (rworlds) {
+ // Tidyup any no longer relevant entries...
+ for (Iterator<Map.Entry<WeakClassLoaderReference, ReflectionWorld>> it = rworlds.entrySet().iterator();
+ it.hasNext();) {
+ Map.Entry<WeakClassLoaderReference, ReflectionWorld> entry = it.next();
+ if (entry.getKey().getClassLoader() == null) {
+ it.remove();
+ }
+ }
+ ReflectionWorld rworld = null;
+ if (classLoaderReference.getClassLoader() != null) {
+ rworld = rworlds.get(classLoaderReference);
+ if (rworld == null) {
+ rworld = new ReflectionWorld(classLoaderReference);
+ rworlds.put(classLoaderReference, rworld);
+ }
+ }
+ return rworld;
+ }
+ */
+ }
+
+ public static void cleanUpWorlds() {
+ synchronized (rworlds) {
+ rworlds.clear();
+ }
+ }
+
private ReflectionWorld() {
// super();
// this.setMessageHandler(new ExceptionBasedMessageHandler());
@@ -49,6 +89,13 @@ public class ReflectionWorld extends World implements IReflectionWorld {
// makeAnnotationFinderIfAny(classLoaderReference.getClassLoader(),
// this);
}
+
+ public ReflectionWorld(WeakClassLoaderReference classloaderRef) {
+ this.setMessageHandler(new ExceptionBasedMessageHandler());
+ setBehaveInJava5Way(LangUtil.is15VMOrGreater());
+ classLoaderReference = classloaderRef;
+ annotationFinder = makeAnnotationFinderIfAny(classLoaderReference.getClassLoader(), this);
+ }
public ReflectionWorld(ClassLoader aClassLoader) {
super();
@@ -71,7 +118,7 @@ public class ReflectionWorld extends World implements IReflectionWorld {
AnnotationFinder annotationFinder = null;
try {
if (LangUtil.is15VMOrGreater()) {
- Class java15AnnotationFinder = Class.forName("org.aspectj.weaver.reflect.Java15AnnotationFinder");
+ Class<?> java15AnnotationFinder = Class.forName("org.aspectj.weaver.reflect.Java15AnnotationFinder");
annotationFinder = (AnnotationFinder) java15AnnotationFinder.newInstance();
annotationFinder.setClassLoader(loader);
annotationFinder.setWorld(world);
@@ -99,7 +146,7 @@ public class ReflectionWorld extends World implements IReflectionWorld {
return resolve(this, aClass);
}
- public static ResolvedType resolve(World world, Class aClass) {
+ public static ResolvedType resolve(World world, Class<?> aClass) {
// classes that represent arrays return a class name that is the
// signature of the array type, ho-hum...
String className = aClass.getName();
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/tools/PointcutParser.java b/org.aspectj.matcher/src/org/aspectj/weaver/tools/PointcutParser.java
index 649aa0ba9..4e3b2bd59 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/tools/PointcutParser.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/tools/PointcutParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
+ * Copyright (c) 2004, 2017 Contributors
* 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
@@ -51,6 +51,9 @@ import org.aspectj.weaver.reflect.ReflectionWorld;
/**
* A PointcutParser can be used to build PointcutExpressions for a user-defined subset of AspectJ's pointcut language
+ *
+ * @author Adrian Colyer
+ * @author Andy Clement
*/
public class PointcutParser {
@@ -123,7 +126,7 @@ public class PointcutParser {
* @throws UnsupportedOperationException if the set contains if, cflow, or cflow below
*/
public static PointcutParser getPointcutParserSupportingSpecifiedPrimitivesAndUsingContextClassloaderForResolution(
- Set supportedPointcutKinds) {
+ Set<PointcutPrimitive> supportedPointcutKinds) {
PointcutParser p = new PointcutParser(supportedPointcutKinds);
p.setClassLoader(Thread.currentThread().getContextClassLoader());
return p;
@@ -163,7 +166,7 @@ public class PointcutParser {
* @throws UnsupportedOperationException if the set contains if, cflow, or cflow below
*/
public static PointcutParser getPointcutParserSupportingSpecifiedPrimitivesAndUsingSpecifiedClassLoaderForResolution(
- Set supportedPointcutKinds, ClassLoader classLoader) {
+ Set<PointcutPrimitive> supportedPointcutKinds, ClassLoader classLoader) {
PointcutParser p = new PointcutParser(supportedPointcutKinds);
p.setClassLoader(classLoader);
return p;
@@ -216,7 +219,22 @@ public class PointcutParser {
*/
protected void setClassLoader(ClassLoader aLoader) {
this.classLoaderReference = new WeakClassLoaderReference(aLoader);
- world = new ReflectionWorld(this.classLoaderReference.getClassLoader());
+ world = ReflectionWorld.getReflectionWorldFor(this.classLoaderReference);
+ }
+
+ /**
+ * Set the classloader that this parser should use for type resolution.
+ *
+ * @param aLoader
+ * @param shareWorlds if true then two PointcutParsers operating using the same classloader will share a ReflectionWorld
+ */
+ protected void setClassLoader(ClassLoader aLoader, boolean shareWorlds) {
+ this.classLoaderReference = new WeakClassLoaderReference(aLoader);
+ if (shareWorlds) {
+ world = ReflectionWorld.getReflectionWorldFor(this.classLoaderReference);
+ } else {
+ world = new ReflectionWorld(classLoaderReference);
+ }
}
/**
@@ -261,7 +279,7 @@ public class PointcutParser {
* @param type
* @return
*/
- public PointcutParameter createPointcutParameter(String name, Class type) {
+ public PointcutParameter createPointcutParameter(String name, Class<?> type) {
return new PointcutParameterImpl(name, type);
}
@@ -287,7 +305,7 @@ public class PointcutParser {
* supported by this PointcutParser.
* @throws IllegalArgumentException if the expression is not a well-formed pointcut expression
*/
- public PointcutExpression parsePointcutExpression(String expression, Class inScope, PointcutParameter[] formalParameters)
+ public PointcutExpression parsePointcutExpression(String expression, Class<?> inScope, PointcutParameter[] formalParameters)
throws UnsupportedPointcutPrimitiveException, IllegalArgumentException {
PointcutExpressionImpl pcExpr = null;
try {
@@ -303,7 +321,7 @@ public class PointcutParser {
return pcExpr;
}
- protected Pointcut resolvePointcutExpression(String expression, Class inScope, PointcutParameter[] formalParameters) {
+ protected Pointcut resolvePointcutExpression(String expression, Class<?> inScope, PointcutParameter[] formalParameters) {
try {
PatternParser parser = new PatternParser(expression);
parser.setPointcutDesignatorHandlers(pointcutDesignators, world);
@@ -317,7 +335,7 @@ public class PointcutParser {
}
}
- protected Pointcut concretizePointcutExpression(Pointcut pc, Class inScope, PointcutParameter[] formalParameters) {
+ protected Pointcut concretizePointcutExpression(Pointcut pc, Class<?> inScope, PointcutParameter[] formalParameters) {
ResolvedType declaringTypeForResolution = null;
if (inScope != null) {
declaringTypeForResolution = getWorld().resolve(inScope.getName());
@@ -355,7 +373,7 @@ public class PointcutParser {
}
/* for testing */
- Set getSupportedPrimitives() {
+ Set<PointcutPrimitive> getSupportedPrimitives() {
return supportedPrimitives;
}
@@ -366,7 +384,7 @@ public class PointcutParser {
return current;
}
- private IScope buildResolutionScope(Class inScope, PointcutParameter[] formalParameters) {
+ private IScope buildResolutionScope(Class<?> inScope, PointcutParameter[] formalParameters) {
if (formalParameters == null) {
formalParameters = new PointcutParameter[0];
}
@@ -398,7 +416,7 @@ public class PointcutParser {
}
}
- private UnresolvedType toUnresolvedType(Class clazz) {
+ private UnresolvedType toUnresolvedType(Class<?> clazz) {
if (clazz.isArray()) {
return UnresolvedType.forSignature(clazz.getName().replace('.', '/'));
} else {
@@ -560,4 +578,5 @@ public class PointcutParser {
msg.append("\n");
return msg.toString();
}
+
}