org.aspectj.weaver.tools.ShadowMatch Java Examples
The following examples show how to use
org.aspectj.weaver.tools.ShadowMatch.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AspectJExpressionPointcut.java From spring-analysis-note with MIT License | 6 votes |
private ShadowMatch getTargetShadowMatch(Method method, Class<?> targetClass) { Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass); if (targetMethod.getDeclaringClass().isInterface()) { // Try to build the most specific interface possible for inherited methods to be // considered for sub-interface matches as well, in particular for proxy classes. // Note: AspectJ is only going to take Method.getDeclaringClass() into account. Set<Class<?>> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass); if (ifcs.size() > 1) { try { Class<?> compositeInterface = ClassUtils.createCompositeInterface( ClassUtils.toClassArray(ifcs), targetClass.getClassLoader()); targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface); } catch (IllegalArgumentException ex) { // Implemented interfaces probably expose conflicting method signatures... // Proceed with original target method. } } } return getShadowMatch(targetMethod, method); }
Example #2
Source File: AspectJExpressionPointcut.java From java-technology-stack with MIT License | 6 votes |
private ShadowMatch getTargetShadowMatch(Method method, Class<?> targetClass) { Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass); if (targetMethod.getDeclaringClass().isInterface()) { // Try to build the most specific interface possible for inherited methods to be // considered for sub-interface matches as well, in particular for proxy classes. // Note: AspectJ is only going to take Method.getDeclaringClass() into account. Set<Class<?>> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass); if (ifcs.size() > 1) { try { Class<?> compositeInterface = ClassUtils.createCompositeInterface( ClassUtils.toClassArray(ifcs), targetClass.getClassLoader()); targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface); } catch (IllegalArgumentException ex) { // Implemented interfaces probably expose conflicting method signatures... // Proceed with original target method. } } } return getShadowMatch(targetMethod, method); }
Example #3
Source File: AspectJExpressionPointcut.java From toy-spring with Apache License 2.0 | 6 votes |
/** * 使用 AspectJ Expression 匹配方法 * @param method * @param targetClass * @return 成功匹配返回 true,否则返回 false */ @Override public Boolean matchers(Method method, Class targetClass) { checkReadyToMatche(); ShadowMatch shadowMatch = pointcutExpression.matchesMethodExecution(method); // Special handling for this, target, @this, @target, @annotation // in Spring - we can optimize since we know we have exactly this class, // and there will never be matching subclass at runtime. // https://github.com/spring-projects/spring-framework/blob/master/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java if (shadowMatch.alwaysMatches()) { return true; } else if (shadowMatch.neverMatches()) { return false; } return false; }
Example #4
Source File: AspectJExpressionPointcut.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public boolean matches(Method method, Class<?> targetClass, boolean beanHasIntroductions) { checkReadyToMatch(); Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass); ShadowMatch shadowMatch = getShadowMatch(targetMethod, method); // Special handling for this, target, @this, @target, @annotation // in Spring - we can optimize since we know we have exactly this class, // and there will never be matching subclass at runtime. if (shadowMatch.alwaysMatches()) { return true; } else if (shadowMatch.neverMatches()) { return false; } else { // the maybe case if (beanHasIntroductions) { return true; } // A match test returned maybe - if there are any subtype sensitive variables // involved in the test (this, target, at_this, at_target, at_annotation) then // we say this is not a match as in Spring there will never be a different // runtime subtype. RuntimeTestWalker walker = getRuntimeTestWalker(shadowMatch); return (!walker.testsSubtypeSensitiveVars() || walker.testTargetInstanceOfResidue(targetClass)); } }
Example #5
Source File: AspectJExpressionPointcut.java From tiny-spring with Apache License 2.0 | 5 votes |
@Override public boolean matches(Method method, Class targetClass) { checkReadyToMatch(); ShadowMatch shadowMatch = pointcutExpression.matchesMethodExecution(method); if (shadowMatch.alwaysMatches()) { return true; } else if (shadowMatch.neverMatches()) { return false; } // TODO:其他情况不判断了!见org.springframework.aop.aspectj.RuntimeTestWalker return false; }
Example #6
Source File: AspectJExpressionPointcut.java From tiny-spring with Apache License 2.0 | 5 votes |
@Override public boolean matches(Method method, Class targetClass) { checkReadyToMatch(); ShadowMatch shadowMatch = pointcutExpression.matchesMethodExecution(method); if (shadowMatch.alwaysMatches()) { return true; } else if (shadowMatch.neverMatches()) { return false; } // TODO:其他情况不判断了!见org.springframework.aop.aspectj.RuntimeTestWalker return false; }
Example #7
Source File: AspectJExpressionPointcut.java From tiny-spring with Apache License 2.0 | 5 votes |
@Override public boolean matches(Method method, Class targetClass) { checkReadyToMatch(); ShadowMatch shadowMatch = pointcutExpression.matchesMethodExecution(method); if (shadowMatch.alwaysMatches()) { return true; } else if (shadowMatch.neverMatches()) { return false; } // TODO:其他情况不判断了!见org.springframework.aop.aspectj.RuntimeTestWalker return false; }
Example #8
Source File: RuntimeTestWalker.java From spring4-understanding with Apache License 2.0 | 5 votes |
public RuntimeTestWalker(ShadowMatch shadowMatch) { try { ReflectionUtils.makeAccessible(residualTestField); this.runtimeTest = (Test) residualTestField.get(shadowMatch); } catch (IllegalAccessException ex) { throw new IllegalStateException(ex); } }
Example #9
Source File: AspectJExpressionPointcut.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { // Rely on default serialization, just initialize state after deserialization. ois.defaultReadObject(); // Initialize transient fields. // pointcutExpression will be initialized lazily by checkReadyToMatch() this.shadowMatchCache = new ConcurrentHashMap<Method, ShadowMatch>(32); }
Example #10
Source File: AspectJExpressionPointcut.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public boolean matches(Method method, Class<?> targetClass, boolean beanHasIntroductions) { checkReadyToMatch(); Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass); ShadowMatch shadowMatch = getShadowMatch(targetMethod, method); // Special handling for this, target, @this, @target, @annotation // in Spring - we can optimize since we know we have exactly this class, // and there will never be matching subclass at runtime. if (shadowMatch.alwaysMatches()) { return true; } else if (shadowMatch.neverMatches()) { return false; } else { // the maybe case if (beanHasIntroductions) { return true; } // A match test returned maybe - if there are any subtype sensitive variables // involved in the test (this, target, at_this, at_target, at_annotation) then // we say this is not a match as in Spring there will never be a different // runtime subtype. RuntimeTestWalker walker = getRuntimeTestWalker(shadowMatch); return (!walker.testsSubtypeSensitiveVars() || walker.testTargetInstanceOfResidue(targetClass)); } }
Example #11
Source File: RuntimeTestWalker.java From lams with GNU General Public License v2.0 | 5 votes |
public RuntimeTestWalker(ShadowMatch shadowMatch) { try { ReflectionUtils.makeAccessible(residualTestField); this.runtimeTest = (Test) residualTestField.get(shadowMatch); } catch (IllegalAccessException ex) { throw new IllegalStateException(ex); } }
Example #12
Source File: AspectJExpressionPointcut.java From lams with GNU General Public License v2.0 | 5 votes |
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { // Rely on default serialization, just initialize state after deserialization. ois.defaultReadObject(); // Initialize transient fields. // pointcutExpression will be initialized lazily by checkReadyToMatch() this.shadowMatchCache = new ConcurrentHashMap<Method, ShadowMatch>(32); }
Example #13
Source File: AspectJExpressionPointcut.java From spring-analysis-note with MIT License | 5 votes |
@Override public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) { obtainPointcutExpression(); ShadowMatch shadowMatch = getTargetShadowMatch(method, targetClass); // Special handling for this, target, @this, @target, @annotation // in Spring - we can optimize since we know we have exactly this class, // and there will never be matching subclass at runtime. if (shadowMatch.alwaysMatches()) { return true; } else if (shadowMatch.neverMatches()) { return false; } else { // the maybe case if (hasIntroductions) { return true; } // A match test returned maybe - if there are any subtype sensitive variables // involved in the test (this, target, at_this, at_target, at_annotation) then // we say this is not a match as in Spring there will never be a different // runtime subtype. RuntimeTestWalker walker = getRuntimeTestWalker(shadowMatch); return (!walker.testsSubtypeSensitiveVars() || walker.testTargetInstanceOfResidue(targetClass)); } }
Example #14
Source File: ExpressionMatcher.java From defender with Apache License 2.0 | 5 votes |
@Override public boolean match(Caller caller, String pattern) { if(! pattern.startsWith("execution")) { pattern = "execution(" + pattern + ")"; } PointcutExpression pe = cache.get(pattern); if(pe == null) { PointcutParser pp = PointcutParser.getPointcutParserSupportingAllPrimitivesAndUsingContextClassloaderForResolution(); pe = pp.parsePointcutExpression(pattern); cache.set(pattern, pe); } ShadowMatch sm = pe.matchesMethodExecution(caller.getTargetMethod()); return sm.alwaysMatches(); }
Example #15
Source File: ProxyPointcut.java From doodle with Apache License 2.0 | 5 votes |
/** * Method是否匹配切点表达式 * * @param method 目标方法 * @return 是否匹配 */ public boolean matches(Method method) { checkReadyToMatch(); ShadowMatch shadowMatch = pointcutExpression.matchesMethodExecution(method); if (shadowMatch.alwaysMatches()) { return true; } else if (shadowMatch.neverMatches()) { return false; } return false; }
Example #16
Source File: RuntimeTestWalker.java From java-technology-stack with MIT License | 5 votes |
public RuntimeTestWalker(ShadowMatch shadowMatch) { try { ReflectionUtils.makeAccessible(residualTestField); this.runtimeTest = (Test) residualTestField.get(shadowMatch); } catch (IllegalAccessException ex) { throw new IllegalStateException(ex); } }
Example #17
Source File: AspectJExpressionPointcut.java From java-technology-stack with MIT License | 5 votes |
@Override public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) { obtainPointcutExpression(); ShadowMatch shadowMatch = getTargetShadowMatch(method, targetClass); // Special handling for this, target, @this, @target, @annotation // in Spring - we can optimize since we know we have exactly this class, // and there will never be matching subclass at runtime. if (shadowMatch.alwaysMatches()) { return true; } else if (shadowMatch.neverMatches()) { return false; } else { // the maybe case if (hasIntroductions) { return true; } // A match test returned maybe - if there are any subtype sensitive variables // involved in the test (this, target, at_this, at_target, at_annotation) then // we say this is not a match as in Spring there will never be a different // runtime subtype. RuntimeTestWalker walker = getRuntimeTestWalker(shadowMatch); return (!walker.testsSubtypeSensitiveVars() || walker.testTargetInstanceOfResidue(targetClass)); } }
Example #18
Source File: RuntimeTestWalker.java From spring-analysis-note with MIT License | 5 votes |
public RuntimeTestWalker(ShadowMatch shadowMatch) { try { ReflectionUtils.makeAccessible(residualTestField); this.runtimeTest = (Test) residualTestField.get(shadowMatch); } catch (IllegalAccessException ex) { throw new IllegalStateException(ex); } }
Example #19
Source File: AspectJExpressionPointcut.java From lams with GNU General Public License v2.0 | 4 votes |
private RuntimeTestWalker getRuntimeTestWalker(ShadowMatch shadowMatch) { if (shadowMatch instanceof DefensiveShadowMatch) { return new RuntimeTestWalker(((DefensiveShadowMatch) shadowMatch).primary); } return new RuntimeTestWalker(shadowMatch); }
Example #20
Source File: AspectJExpressionPointcut.java From lams with GNU General Public License v2.0 | 4 votes |
public DefensiveShadowMatch(ShadowMatch primary, ShadowMatch other) { this.primary = primary; this.other = other; }
Example #21
Source File: AspectJExpressionPointcut.java From java-technology-stack with MIT License | 4 votes |
public DefensiveShadowMatch(ShadowMatch primary, ShadowMatch other) { this.primary = primary; this.other = other; }
Example #22
Source File: AspectJExpressionPointcut.java From spring4-understanding with Apache License 2.0 | 4 votes |
private RuntimeTestWalker getRuntimeTestWalker(ShadowMatch shadowMatch) { if (shadowMatch instanceof DefensiveShadowMatch) { return new RuntimeTestWalker(((DefensiveShadowMatch) shadowMatch).primary); } return new RuntimeTestWalker(shadowMatch); }
Example #23
Source File: AspectJExpressionPointcut.java From java-technology-stack with MIT License | 4 votes |
private RuntimeTestWalker getRuntimeTestWalker(ShadowMatch shadowMatch) { if (shadowMatch instanceof DefensiveShadowMatch) { return new RuntimeTestWalker(((DefensiveShadowMatch) shadowMatch).primary); } return new RuntimeTestWalker(shadowMatch); }
Example #24
Source File: AspectJExpressionPointcut.java From spring4-understanding with Apache License 2.0 | 4 votes |
public DefensiveShadowMatch(ShadowMatch primary, ShadowMatch other) { this.primary = primary; this.other = other; }
Example #25
Source File: AspectJExpressionPointcut.java From spring-analysis-note with MIT License | 4 votes |
public DefensiveShadowMatch(ShadowMatch primary, ShadowMatch other) { this.primary = primary; this.other = other; }
Example #26
Source File: AspectJExpressionPointcut.java From spring-analysis-note with MIT License | 4 votes |
private RuntimeTestWalker getRuntimeTestWalker(ShadowMatch shadowMatch) { if (shadowMatch instanceof DefensiveShadowMatch) { return new RuntimeTestWalker(((DefensiveShadowMatch) shadowMatch).primary); } return new RuntimeTestWalker(shadowMatch); }