Browse Source

Deprecate outdated abstractions/delegates in core/util

Issue: SPR-15159
pull/1316/head
Juergen Hoeller 9 years ago
parent
commit
e2d06eaae5
  1. 29
      spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java
  2. 14
      spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java
  3. 4
      spring-core/src/main/java/org/springframework/core/ControlFlow.java
  4. 16
      spring-core/src/main/java/org/springframework/core/ControlFlowFactory.java
  5. 4
      spring-core/src/main/java/org/springframework/core/ErrorCoded.java
  6. 4
      spring-core/src/main/java/org/springframework/util/WeakReferenceMonitor.java
  7. 6
      spring-core/src/test/java/org/springframework/core/ControlFlowTests.java

29
spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2017 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.
@ -22,8 +22,6 @@ import java.lang.reflect.Method;
import org.springframework.aop.ClassFilter; import org.springframework.aop.ClassFilter;
import org.springframework.aop.MethodMatcher; import org.springframework.aop.MethodMatcher;
import org.springframework.aop.Pointcut; import org.springframework.aop.Pointcut;
import org.springframework.core.ControlFlow;
import org.springframework.core.ControlFlowFactory;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
@ -34,7 +32,7 @@ import org.springframework.util.ObjectUtils;
* *
* @author Rod Johnson * @author Rod Johnson
* @author Rob Harrop * @author Rob Harrop
* @see org.springframework.core.ControlFlow * @author Juergen Hoeller
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher, Serializable { public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher, Serializable {
@ -43,7 +41,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
private String methodName; private String methodName;
private int evaluations; private volatile int evaluations;
/** /**
@ -55,11 +53,11 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
} }
/** /**
* Construct a new pointcut that matches all calls below the * Construct a new pointcut that matches all calls below the given method
* given method in the given class. If the method name is null, * in the given class. If no method name is given, matches all control flows
* matches all control flows below that class. * below the given class.
* @param clazz the clazz * @param clazz the clazz
* @param methodName the name of the method * @param methodName the name of the method (may be {@code null})
*/ */
public ControlFlowPointcut(Class<?> clazz, String methodName) { public ControlFlowPointcut(Class<?> clazz, String methodName) {
Assert.notNull(clazz, "Class must not be null"); Assert.notNull(clazz, "Class must not be null");
@ -93,8 +91,14 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
@Override @Override
public boolean matches(Method method, Class<?> targetClass, Object... args) { public boolean matches(Method method, Class<?> targetClass, Object... args) {
this.evaluations++; this.evaluations++;
ControlFlow cflow = ControlFlowFactory.createControlFlow();
return (this.methodName != null ? cflow.under(this.clazz, this.methodName) : cflow.under(this.clazz)); for (StackTraceElement element : new Throwable().getStackTrace()) {
if (element.getClassName().equals(this.clazz.getName()) &&
(this.methodName == null || element.getMethodName().equals(this.methodName))) {
return true;
}
}
return false;
} }
/** /**
@ -130,8 +134,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
@Override @Override
public int hashCode() { public int hashCode() {
int code = 17; int code = this.clazz.hashCode();
code = 37 * code + this.clazz.hashCode();
if (this.methodName != null) { if (this.methodName != null) {
code = 37 * code + this.methodName.hashCode(); code = 37 * code + this.methodName.hashCode();
} }

14
spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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.
@ -18,8 +18,6 @@ package org.springframework.beans;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import org.springframework.core.ErrorCoded;
/** /**
* Superclass for exceptions related to a property access, * Superclass for exceptions related to a property access,
* such as type mismatch or invocation target exception. * such as type mismatch or invocation target exception.
@ -27,8 +25,8 @@ import org.springframework.core.ErrorCoded;
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
@SuppressWarnings("serial") @SuppressWarnings({"serial", "deprecation"})
public abstract class PropertyAccessException extends BeansException implements ErrorCoded { public abstract class PropertyAccessException extends BeansException implements org.springframework.core.ErrorCoded {
private transient PropertyChangeEvent propertyChangeEvent; private transient PropertyChangeEvent propertyChangeEvent;
@ -77,4 +75,10 @@ public abstract class PropertyAccessException extends BeansException implements
return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getNewValue() : null); return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getNewValue() : null);
} }
/**
* Return a corresponding error code for this type of exception.
*/
@Override
public abstract String getErrorCode();
} }

4
spring-core/src/main/java/org/springframework/core/ControlFlow.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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.
@ -23,7 +23,9 @@ package org.springframework.core;
* *
* @author Rod Johnson * @author Rod Johnson
* @since 02.02.2004 * @since 02.02.2004
* @deprecated as of Spring Framework 4.3.6
*/ */
@Deprecated
public interface ControlFlow { public interface ControlFlow {
/** /**

16
spring-core/src/main/java/org/springframework/core/ControlFlowFactory.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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.
@ -31,7 +31,9 @@ import org.springframework.util.Assert;
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 02.02.2004 * @since 02.02.2004
* @deprecated as of Spring Framework 4.3.6
*/ */
@Deprecated
public abstract class ControlFlowFactory { public abstract class ControlFlowFactory {
/** /**
@ -65,8 +67,8 @@ public abstract class ControlFlowFactory {
public boolean under(Class<?> clazz) { public boolean under(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null"); Assert.notNull(clazz, "Class must not be null");
String className = clazz.getName(); String className = clazz.getName();
for (int i = 0; i < stack.length; i++) { for (StackTraceElement element : this.stack) {
if (this.stack[i].getClassName().equals(className)) { if (element.getClassName().equals(className)) {
return true; return true;
} }
} }
@ -82,9 +84,9 @@ public abstract class ControlFlowFactory {
Assert.notNull(clazz, "Class must not be null"); Assert.notNull(clazz, "Class must not be null");
Assert.notNull(methodName, "Method name must not be null"); Assert.notNull(methodName, "Method name must not be null");
String className = clazz.getName(); String className = clazz.getName();
for (int i = 0; i < this.stack.length; i++) { for (StackTraceElement element : this.stack) {
if (this.stack[i].getClassName().equals(className) && if (element.getClassName().equals(className) &&
this.stack[i].getMethodName().equals(methodName)) { element.getMethodName().equals(methodName)) {
return true; return true;
} }
} }
@ -103,7 +105,7 @@ public abstract class ControlFlowFactory {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
new Throwable().printStackTrace(new PrintWriter(sw)); new Throwable().printStackTrace(new PrintWriter(sw));
String stackTrace = sw.toString(); String stackTrace = sw.toString();
return stackTrace.indexOf(token) != -1; return stackTrace.contains(token);
} }
@Override @Override

4
spring-core/src/main/java/org/springframework/core/ErrorCoded.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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.
@ -25,7 +25,9 @@ package org.springframework.core;
* *
* @author Rod Johnson * @author Rod Johnson
* @see org.springframework.context.MessageSource * @see org.springframework.context.MessageSource
* @deprecated as of Spring Framework 4.3.6
*/ */
@Deprecated
public interface ErrorCoded { public interface ErrorCoded {
/** /**

4
spring-core/src/main/java/org/springframework/util/WeakReferenceMonitor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2017 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.
@ -44,7 +44,9 @@ import org.apache.commons.logging.LogFactory;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 1.2 * @since 1.2
* @see #monitor * @see #monitor
* @deprecated as of Spring Framework 4.3.6
*/ */
@Deprecated
public class WeakReferenceMonitor { public class WeakReferenceMonitor {
private static final Log logger = LogFactory.getLog(WeakReferenceMonitor.class); private static final Log logger = LogFactory.getLog(WeakReferenceMonitor.class);

6
spring-core/src/test/java/org/springframework/core/ControlFlowTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2017 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.
@ -24,6 +24,7 @@ import static org.junit.Assert.*;
* @author Rod Johnson * @author Rod Johnson
* @author Sam Brannen * @author Sam Brannen
*/ */
@SuppressWarnings("deprecation")
public class ControlFlowTests { public class ControlFlowTests {
@Test @Test
@ -33,6 +34,7 @@ public class ControlFlowTests {
new Three().test(); new Three().test();
} }
static class One { static class One {
void test() { void test() {
@ -45,6 +47,7 @@ public class ControlFlowTests {
} }
} }
static class Two { static class Two {
void testing() { void testing() {
@ -57,6 +60,7 @@ public class ControlFlowTests {
} }
} }
static class Three { static class Three {
void test() { void test() {

Loading…
Cancel
Save