Browse Source

Polishing

pull/1100/head
Juergen Hoeller 10 years ago
parent
commit
102dc8a4dd
  1. 5
      spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvoker.java
  2. 4
      spring-core/src/main/java/org/springframework/util/UpdateMessageDigestInputStream.java
  3. 9
      spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java
  4. 144
      spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java
  5. 12
      spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java
  6. 11
      spring-web/src/main/java/org/springframework/http/client/ClientHttpRequestExecution.java
  7. 10
      spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java
  8. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerInterceptorAdapter.java
  9. 10
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java
  10. 4
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformer.java

5
spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvoker.java vendored

@ -31,9 +31,8 @@ package org.springframework.cache.interceptor;
public interface CacheOperationInvoker { public interface CacheOperationInvoker {
/** /**
* Invoke the cache operation defined by this instance. Wraps any * Invoke the cache operation defined by this instance. Wraps any exception
* exception that is thrown during the invocation in a * that is thrown during the invocation in a {@link ThrowableWrapper}.
* {@link ThrowableWrapper}.
* @return the result of the operation * @return the result of the operation
* @throws ThrowableWrapper if an error occurred while invoking the operation * @throws ThrowableWrapper if an error occurred while invoking the operation
*/ */

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

@ -33,7 +33,7 @@ abstract class UpdateMessageDigestInputStream extends InputStream {
* Update the message digest with the rest of the bytes in this stream. * Update the message digest with the rest of the bytes in this stream.
* <p>Using this method is more optimized since it avoids creating new * <p>Using this method is more optimized since it avoids creating new
* byte arrays for each call. * byte arrays for each call.
* @param messageDigest The message digest to update * @param messageDigest the message digest to update
* @throws IOException when propagated from {@link #read()} * @throws IOException when propagated from {@link #read()}
*/ */
public void updateMessageDigest(MessageDigest messageDigest) throws IOException { public void updateMessageDigest(MessageDigest messageDigest) throws IOException {
@ -47,7 +47,7 @@ abstract class UpdateMessageDigestInputStream extends InputStream {
* Update the message digest with the next len bytes in this stream. * Update the message digest with the next len bytes in this stream.
* <p>Using this method is more optimized since it avoids creating new * <p>Using this method is more optimized since it avoids creating new
* byte arrays for each call. * byte arrays for each call.
* @param messageDigest The message digest to update * @param messageDigest the message digest to update
* @param len how many bytes to read from this stream and use to update the message digest * @param len how many bytes to read from this stream and use to update the message digest
* @throws IOException when propagated from {@link #read()} * @throws IOException when propagated from {@link #read()}
*/ */

9
spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 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,10 +24,9 @@ import java.util.concurrent.TimeoutException;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Abstract class that adapts a {@link Future} parameterized over S into a {@code * Abstract class that adapts a {@link Future} parameterized over S into a {@code Future}
* Future} parameterized over T. All methods are delegated to the adaptee, where {@link * parameterized over T. All methods are delegated to the adaptee, where {@link #get()}
* #get()} and {@link #get(long, TimeUnit)} call {@link #adapt(Object)} on the adaptee's * and {@link #get(long, TimeUnit)} call {@link #adapt(Object)} on the adaptee's result.
* result.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 4.0 * @since 4.0

144
spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java

@ -147,6 +147,67 @@ public class CodeFlow implements Opcodes {
} }
} }
/**
* Called after the main expression evaluation method has been generated, this
* method will callback any registered FieldAdders or ClinitAdders to add any
* extra information to the class representing the compiled expression.
*/
public void finish() {
if (this.fieldAdders != null) {
for (FieldAdder fieldAdder : this.fieldAdders) {
fieldAdder.generateField(cw,this);
}
}
if (this.clinitAdders != null) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
mv.visitCode();
this.nextFreeVariableId = 0; // To 0 because there is no 'this' in a clinit
for (ClinitAdder clinitAdder : this.clinitAdders) {
clinitAdder.generateCode(mv, this);
}
mv.visitInsn(RETURN);
mv.visitMaxs(0,0); // not supplied due to COMPUTE_MAXS
mv.visitEnd();
}
}
/**
* Register a FieldAdder which will add a new field to the generated
* class to support the code produced by an ast nodes primary
* generateCode() method.
*/
public void registerNewField(FieldAdder fieldAdder) {
if (this.fieldAdders == null) {
this.fieldAdders = new ArrayList<>();
}
this.fieldAdders.add(fieldAdder);
}
/**
* Register a ClinitAdder which will add code to the static
* initializer in the generated class to support the code
* produced by an ast nodes primary generateCode() method.
*/
public void registerNewClinit(ClinitAdder clinitAdder) {
if (this.clinitAdders == null) {
this.clinitAdders = new ArrayList<>();
}
this.clinitAdders.add(clinitAdder);
}
public int nextFieldId() {
return this.nextFieldId++;
}
public int nextFreeVariableId() {
return this.nextFreeVariableId++;
}
public String getClassName() {
return this.clazzName;
}
/** /**
* Insert any necessary cast and value call to convert from a boxed type to a * Insert any necessary cast and value call to convert from a boxed type to a
* primitive value * primitive value
@ -778,76 +839,6 @@ public class CodeFlow implements Opcodes {
return descriptors; return descriptors;
} }
/**
* Called after the main expression evaluation method has been generated, this
* method will callback any registered FieldAdders or ClinitAdders to add any
* extra information to the class representing the compiled expression.
*/
public void finish() {
if (fieldAdders != null) {
for (FieldAdder fieldAdder: fieldAdders) {
fieldAdder.generateField(cw,this);
}
}
if (clinitAdders != null) {
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
mv.visitCode();
nextFreeVariableId = 0; // To 0 because there is no 'this' in a clinit
for (ClinitAdder clinitAdder: clinitAdders) {
clinitAdder.generateCode(mv, this);
}
mv.visitInsn(RETURN);
mv.visitMaxs(0,0); // not supplied due to COMPUTE_MAXS
mv.visitEnd();
}
}
/**
* Register a FieldAdder which will add a new field to the generated
* class to support the code produced by an ast nodes primary
* generateCode() method.
*/
public void registerNewField(FieldAdder fieldAdder) {
if (fieldAdders == null) {
fieldAdders = new ArrayList<>();
}
fieldAdders.add(fieldAdder);
}
/**
* Register a ClinitAdder which will add code to the static
* initializer in the generated class to support the code
* produced by an ast nodes primary generateCode() method.
*/
public void registerNewClinit(ClinitAdder clinitAdder) {
if (clinitAdders == null) {
clinitAdders = new ArrayList<>();
}
clinitAdders.add(clinitAdder);
}
public int nextFieldId() {
return nextFieldId++;
}
public int nextFreeVariableId() {
return nextFreeVariableId++;
}
public String getClassname() {
return clazzName;
}
@FunctionalInterface
public interface FieldAdder {
void generateField(ClassWriter cw, CodeFlow codeflow);
}
@FunctionalInterface
public interface ClinitAdder {
void generateCode(MethodVisitor mv, CodeFlow codeflow);
}
/** /**
* Create the optimal instruction for loading a number on the stack. * Create the optimal instruction for loading a number on the stack.
* @param mv where to insert the bytecode * @param mv where to insert the bytecode
@ -979,4 +970,17 @@ public class CodeFlow implements Opcodes {
} }
@FunctionalInterface
public interface FieldAdder {
void generateField(ClassWriter cw, CodeFlow codeflow);
}
@FunctionalInterface
public interface ClinitAdder {
void generateCode(MethodVisitor mv, CodeFlow codeflow);
}
} }

12
spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java

@ -132,8 +132,8 @@ public class InlineList extends SpelNodeImpl {
@Override @Override
public void generateCode(MethodVisitor mv, CodeFlow codeflow) { public void generateCode(MethodVisitor mv, CodeFlow codeflow) {
final String constantFieldName = "inlineList$"+codeflow.nextFieldId(); final String constantFieldName = "inlineList$" + codeflow.nextFieldId();
final String clazzname = codeflow.getClassname(); final String className = codeflow.getClassName();
codeflow.registerNewField(new CodeFlow.FieldAdder() { codeflow.registerNewField(new CodeFlow.FieldAdder() {
public void generateField(ClassWriter cw, CodeFlow codeflow) { public void generateField(ClassWriter cw, CodeFlow codeflow) {
@ -143,11 +143,11 @@ public class InlineList extends SpelNodeImpl {
codeflow.registerNewClinit(new CodeFlow.ClinitAdder() { codeflow.registerNewClinit(new CodeFlow.ClinitAdder() {
public void generateCode(MethodVisitor mv, CodeFlow codeflow) { public void generateCode(MethodVisitor mv, CodeFlow codeflow) {
generateClinitCode(clazzname,constantFieldName, mv,codeflow,false); generateClinitCode(className, constantFieldName, mv, codeflow, false);
} }
}); });
mv.visitFieldInsn(GETSTATIC, clazzname, constantFieldName, "Ljava/util/List;"); mv.visitFieldInsn(GETSTATIC, className, constantFieldName, "Ljava/util/List;");
codeflow.pushDescriptor("Ljava/util/List"); codeflow.pushDescriptor("Ljava/util/List");
} }
@ -158,8 +158,8 @@ public class InlineList extends SpelNodeImpl {
if (!nested) { if (!nested) {
mv.visitFieldInsn(PUTSTATIC, clazzname, constantFieldName, "Ljava/util/List;"); mv.visitFieldInsn(PUTSTATIC, clazzname, constantFieldName, "Ljava/util/List;");
} }
int childcount = getChildCount(); int childCount = getChildCount();
for (int c=0; c < childcount; c++) { for (int c = 0; c < childCount; c++) {
if (!nested) { if (!nested) {
mv.visitFieldInsn(GETSTATIC, clazzname, constantFieldName, "Ljava/util/List;"); mv.visitFieldInsn(GETSTATIC, clazzname, constantFieldName, "Ljava/util/List;");
} }

11
spring-web/src/main/java/org/springframework/http/client/ClientHttpRequestExecution.java

@ -23,23 +23,24 @@ import org.springframework.http.HttpRequest;
/** /**
* Represents the context of a client-side HTTP request execution. * Represents the context of a client-side HTTP request execution.
* *
* <p>Used to invoke the next interceptor in the interceptor chain, or - if the calling interceptor is last - execute * <p>Used to invoke the next interceptor in the interceptor chain,
* the request itself. * or - if the calling interceptor is last - execute the request itself.
* *
* @author Arjen Poutsma * @author Arjen Poutsma
* @see ClientHttpRequestInterceptor
* @since 3.1 * @since 3.1
* @see ClientHttpRequestInterceptor
*/ */
@FunctionalInterface @FunctionalInterface
public interface ClientHttpRequestExecution { public interface ClientHttpRequestExecution {
/** /**
* Execute the request with the given request attributes and body, and return the response. * Execute the request with the given request attributes and body,
* * and return the response.
* @param request the request, containing method, URI, and headers * @param request the request, containing method, URI, and headers
* @param body the body of the request to execute * @param body the body of the request to execute
* @return the response * @return the response
* @throws IOException in case of I/O errors * @throws IOException in case of I/O errors
*/ */
ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException; ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException;
} }

10
spring-webmvc/src/main/java/org/springframework/web/servlet/LocaleResolver.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2016 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.
@ -51,8 +51,8 @@ import javax.servlet.http.HttpServletResponse;
public interface LocaleResolver { public interface LocaleResolver {
/** /**
* Resolve the current locale via the given request. Can return a default locale as * Resolve the current locale via the given request.
* fallback in any case. * Can return a default locale as fallback in any case.
* @param request the request to resolve the locale for * @param request the request to resolve the locale for
* @return the current locale (never {@code null}) * @return the current locale (never {@code null})
*/ */
@ -63,8 +63,8 @@ public interface LocaleResolver {
* @param request the request to be used for locale modification * @param request the request to be used for locale modification
* @param response the response to be used for locale modification * @param response the response to be used for locale modification
* @param locale the new locale, or {@code null} to clear the locale * @param locale the new locale, or {@code null} to clear the locale
* @throws UnsupportedOperationException if the LocaleResolver implementation does not * @throws UnsupportedOperationException if the LocaleResolver
* support dynamic changing of the locale * implementation does not support dynamic changing of the locale
*/ */
void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale); void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale);

7
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerInterceptorAdapter.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2016 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,7 @@ import org.springframework.web.servlet.AsyncHandlerInterceptor;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
/** /**
* Abstract adapter class for the HandlerInterceptor interface, * Abstract adapter class for the {@link AsyncHandlerInterceptor} interface,
* for simplified implementation of pre-only/post-only interceptors. * for simplified implementation of pre-only/post-only interceptors.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
@ -36,7 +36,8 @@ public abstract class HandlerInterceptorAdapter implements AsyncHandlerIntercept
*/ */
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception { throws Exception {
return true; return true;
} }

10
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java

@ -123,8 +123,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
private boolean hasScheme(String link) { private boolean hasScheme(String link) {
int schemeIndex = link.indexOf(":"); int schemeIndex = link.indexOf(":");
return (schemeIndex > 0 && !link.substring(0, schemeIndex).contains("/")) return (schemeIndex > 0 && !link.substring(0, schemeIndex).contains("/")) || link.indexOf("//") == 0;
|| link.indexOf("//") == 0;
} }
@ -132,9 +131,9 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
protected interface CssLinkParser { protected interface CssLinkParser {
void parseLink(String content, Set<CssLinkInfo> linkInfos); void parseLink(String content, Set<CssLinkInfo> linkInfos);
} }
protected static abstract class AbstractCssLinkParser implements CssLinkParser { protected static abstract class AbstractCssLinkParser implements CssLinkParser {
/** /**
@ -190,6 +189,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
} }
private static class ImportStatementCssLinkParser extends AbstractCssLinkParser { private static class ImportStatementCssLinkParser extends AbstractCssLinkParser {
@Override @Override
@ -209,6 +209,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
} }
} }
private static class UrlFunctionCssLinkParser extends AbstractCssLinkParser { private static class UrlFunctionCssLinkParser extends AbstractCssLinkParser {
@Override @Override
@ -230,8 +231,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
private final int end; private final int end;
public CssLinkInfo(int start, int end) {
private CssLinkInfo(int start, int end) {
this.start = start; this.start = start;
this.end = end; this.end = end;
} }

4
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceTransformer.java

@ -36,10 +36,10 @@ public interface ResourceTransformer {
* @param request the current request * @param request the current request
* @param resource the resource to transform * @param resource the resource to transform
* @param transformerChain the chain of remaining transformers to delegate to * @param transformerChain the chain of remaining transformers to delegate to
* @return the transformed resource, never {@code null} * @return the transformed resource (never {@code null})
* @throws IOException if the transformation fails * @throws IOException if the transformation fails
*/ */
Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain)
throws IOException; throws IOException;
} }

Loading…
Cancel
Save