Polishing
This commit is contained in:
parent
0b02a5e073
commit
f19433f2d8
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2012 the original author or authors.
|
* Copyright 2002-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -21,8 +21,8 @@ import org.springframework.instrument.classloading.LoadTimeWeaver;
|
||||||
/**
|
/**
|
||||||
* Interface to be implemented by
|
* Interface to be implemented by
|
||||||
* {@link org.springframework.context.annotation.Configuration @Configuration}
|
* {@link org.springframework.context.annotation.Configuration @Configuration}
|
||||||
* classes annotated with {@link EnableLoadTimeWeaving @EnableLoadTimeWeaving} that wish to
|
* classes annotated with {@link EnableLoadTimeWeaving @EnableLoadTimeWeaving}
|
||||||
* customize the {@link LoadTimeWeaver} instance to be used.
|
* that wish to customize the {@link LoadTimeWeaver} instance to be used.
|
||||||
*
|
*
|
||||||
* <p>See {@link org.springframework.scheduling.annotation.EnableAsync @EnableAsync}
|
* <p>See {@link org.springframework.scheduling.annotation.EnableAsync @EnableAsync}
|
||||||
* for usage examples and information on how a default {@code LoadTimeWeaver}
|
* for usage examples and information on how a default {@code LoadTimeWeaver}
|
||||||
|
|
@ -36,9 +36,9 @@ import org.springframework.instrument.classloading.LoadTimeWeaver;
|
||||||
public interface LoadTimeWeavingConfigurer {
|
public interface LoadTimeWeavingConfigurer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create, configure and return the {@code LoadTimeWeaver} instance to be used. Note
|
* Create, configure and return the {@code LoadTimeWeaver} instance to be used.
|
||||||
* that it is unnecessary to annotate this method with {@code @Bean}, because the
|
* Note that it is unnecessary to annotate this method with {@code @Bean}
|
||||||
* object returned will automatically be registered as a bean by
|
* because the object returned will automatically be registered as a bean by
|
||||||
* {@link LoadTimeWeavingConfiguration#loadTimeWeaver()}
|
* {@link LoadTimeWeavingConfiguration#loadTimeWeaver()}
|
||||||
*/
|
*/
|
||||||
LoadTimeWeaver getLoadTimeWeaver();
|
LoadTimeWeaver getLoadTimeWeaver();
|
||||||
|
|
|
||||||
|
|
@ -772,7 +772,8 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||||
|
|
||||||
// Detect a LoadTimeWeaver and prepare for weaving, if found in the meantime
|
// Detect a LoadTimeWeaver and prepare for weaving, if found in the meantime
|
||||||
// (e.g. through an @Bean method registered by ConfigurationClassPostProcessor)
|
// (e.g. through an @Bean method registered by ConfigurationClassPostProcessor)
|
||||||
if (!NativeDetector.inNativeImage() && beanFactory.getTempClassLoader() == null && beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) {
|
if (!NativeDetector.inNativeImage() && beanFactory.getTempClassLoader() == null &&
|
||||||
|
beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) {
|
||||||
beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory));
|
beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory));
|
||||||
beanFactory.setTempClassLoader(new ContextTypeMatchClassLoader(beanFactory.getBeanClassLoader()));
|
beanFactory.setTempClassLoader(new ContextTypeMatchClassLoader(beanFactory.getBeanClassLoader()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ class EnableLoadTimeWeavingTests {
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.DISABLED)
|
@EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.DISABLED)
|
||||||
static class EnableLTWConfig_withAjWeavingDisabled implements LoadTimeWeavingConfigurer {
|
static class EnableLTWConfig_withAjWeavingDisabled implements LoadTimeWeavingConfigurer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -88,8 +88,9 @@ class EnableLoadTimeWeavingTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.AUTODETECT)
|
@EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.AUTODETECT)
|
||||||
static class EnableLTWConfig_withAjWeavingAutodetect implements LoadTimeWeavingConfigurer {
|
static class EnableLTWConfig_withAjWeavingAutodetect implements LoadTimeWeavingConfigurer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -98,8 +99,9 @@ class EnableLoadTimeWeavingTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED)
|
@EnableLoadTimeWeaving(aspectjWeaving = AspectJWeaving.ENABLED)
|
||||||
static class EnableLTWConfig_withAjWeavingEnabled implements LoadTimeWeavingConfigurer {
|
static class EnableLTWConfig_withAjWeavingEnabled implements LoadTimeWeavingConfigurer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -85,16 +85,13 @@ public class ReflectiveLoadTimeWeaverTests {
|
||||||
|
|
||||||
private int numTimesAddTransformerCalled = 0;
|
private int numTimesAddTransformerCalled = 0;
|
||||||
|
|
||||||
|
|
||||||
public int getNumTimesGetThrowawayClassLoaderCalled() {
|
public int getNumTimesGetThrowawayClassLoaderCalled() {
|
||||||
return this.numTimesAddTransformerCalled;
|
return this.numTimesAddTransformerCalled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addTransformer(ClassFileTransformer transformer) {
|
public void addTransformer(ClassFileTransformer transformer) {
|
||||||
++this.numTimesAddTransformerCalled;
|
++this.numTimesAddTransformerCalled;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -102,18 +99,15 @@ public class ReflectiveLoadTimeWeaverTests {
|
||||||
|
|
||||||
private int numTimesGetThrowawayClassLoaderCalled = 0;
|
private int numTimesGetThrowawayClassLoaderCalled = 0;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNumTimesGetThrowawayClassLoaderCalled() {
|
public int getNumTimesGetThrowawayClassLoaderCalled() {
|
||||||
return this.numTimesGetThrowawayClassLoaderCalled;
|
return this.numTimesGetThrowawayClassLoaderCalled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ClassLoader getThrowawayClassLoader() {
|
public ClassLoader getThrowawayClassLoader() {
|
||||||
++this.numTimesGetThrowawayClassLoaderCalled;
|
++this.numTimesGetThrowawayClassLoaderCalled;
|
||||||
return getClass().getClassLoader();
|
return getClass().getClassLoader();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -507,16 +507,8 @@ public abstract class ReflectionUtils {
|
||||||
* @see java.lang.Object#equals(Object)
|
* @see java.lang.Object#equals(Object)
|
||||||
*/
|
*/
|
||||||
public static boolean isEqualsMethod(@Nullable Method method) {
|
public static boolean isEqualsMethod(@Nullable Method method) {
|
||||||
if (method == null) {
|
return (method != null && method.getParameterCount() == 1 && method.getName().equals("equals") &&
|
||||||
return false;
|
method.getParameterTypes()[0] == Object.class);
|
||||||
}
|
|
||||||
if (method.getParameterCount() != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!method.getName().equals("equals")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return method.getParameterTypes()[0] == Object.class;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -524,7 +516,7 @@ public abstract class ReflectionUtils {
|
||||||
* @see java.lang.Object#hashCode()
|
* @see java.lang.Object#hashCode()
|
||||||
*/
|
*/
|
||||||
public static boolean isHashCodeMethod(@Nullable Method method) {
|
public static boolean isHashCodeMethod(@Nullable Method method) {
|
||||||
return method != null && method.getParameterCount() == 0 && method.getName().equals("hashCode");
|
return (method != null && method.getParameterCount() == 0 && method.getName().equals("hashCode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue