classes) {
/**
* Let some plugins route themself
+ *
* @param request
+ * the current request
*/
public void routeRequest(Request request) {
}
+ /**
+ * @param modelClass
+ * class of the model
+ * @return the Model factory
+ */
public Model.Factory modelFactory(Class extends Model> modelClass) {
return null;
}
@@ -320,6 +430,11 @@ public void afterFixtureLoad() {
/**
* Inter-plugin communication.
+ *
+ * @param message
+ * the message to post
+ * @param context
+ * an object
*/
public static void postEvent(String message, Object context) {
Play.pluginCollection.onEvent(message, context);
@@ -362,14 +477,14 @@ public Object willBeValidated(Object value) {
}
/**
- * Implement to add some classes that should be considered unit tests but do not extend
- * {@link org.junit.Assert} to tests that can be executed by test runner (will be visible in test UI).
+ * Implement to add some classes that should be considered unit tests but do not extend {@link org.junit.Assert} to
+ * tests that can be executed by test runner (will be visible in test UI).
*
* Note:You probably will also need to override {@link PlayPlugin#runTest(java.lang.Class)} method
* to handle unsupported tests execution properly.
*
- * Keep in mind that this method can only add tests to currently loaded ones.
- * You cannot disable tests this way. You should also make sure you do not duplicate already loaded tests.
+ * Keep in mind that this method can only add tests to currently loaded ones. You cannot disable tests this way. You
+ * should also make sure you do not duplicate already loaded tests.
*
* @return list of plugin supported unit test classes (empty list in default implementation)
*/
@@ -384,8 +499,8 @@ public Collection getUnitTests() {
* Note:You probably will also need to override {@link PlayPlugin#runTest(java.lang.Class)} method
* to handle unsupported tests execution properly.
*
- * Keep in mind that this method can only add tests to currently loaded ones.
- * You cannot disable tests this way. You should also make sure you do not duplicate already loaded tests.
+ * Keep in mind that this method can only add tests to currently loaded ones. You cannot disable tests this way. You
+ * should also make sure you do not duplicate already loaded tests.
*
* @return list of plugin supported functional test classes (empty list in default implementation)
*/
@@ -393,78 +508,82 @@ public Collection getFunctionalTests() {
return emptyList();
}
- /**
- * Class that define a filter. A filter is a class that wrap a certain behavior around an action.
- * You can access your Request and Response object within the filter. See the JPA plugin for an example.
- * The JPA plugin wraps a transaction around an action. The filter applies a transaction to the current Action.
+ /**
+ * Class that define a filter. A filter is a class that wrap a certain behavior around an action. You can access
+ * your Request and Response object within the filter. See the JPA plugin for an example. The JPA plugin wraps a
+ * transaction around an action. The filter applies a transaction to the current Action.
*/
- public abstract static class Filter
- {
+ public abstract static class Filter {
String name;
public Filter(String name) {
this.name = name;
}
-
+
public abstract T withinFilter(play.libs.F.Function0 fct) throws Throwable;
/**
- * Surround innerFilter with this. (innerFilter after this)
- * @param innerFilter filter to be wrapped.
- * @return a new Filter object. newFilter.withinFilter(x) is outerFilter.withinFilter(innerFilter.withinFilter(x))
+ * Surround innerFilter with this. (innerFilter after this)
+ *
+ * @param innerFilter
+ * filter to be wrapped.
+ * @return a new Filter object. newFilter.withinFilter(x) is
+ * outerFilter.withinFilter(innerFilter.withinFilter(x))
*/
public Filter decorate(final Filter innerFilter) {
- final Filter outerFilter = this;
- return new Filter(this.name) {
- @Override
- public T withinFilter(F.Function0 fct) throws Throwable {
- return compose(outerFilter.asFunction(), innerFilter.asFunction()).apply(fct);
- }
- };
+ final Filter outerFilter = this;
+ return new Filter(this.name) {
+ @Override
+ public T withinFilter(F.Function0 fct) throws Throwable {
+ return compose(outerFilter.asFunction(), innerFilter.asFunction()).apply(fct);
+ }
+ };
}
/**
* Compose two second order functions whose input is a zero param function that returns type T...
- * @param outer Function that will wrap inner -- ("outer after inner")
- * @param inner Function to be wrapped by outer function -- ("outer after inner")
- * @return A function that computes outer(inner(x)) on application.
+ *
+ * @param outer
+ * Function that will wrap inner -- ("outer after inner")
+ * @param inner
+ * Function to be wrapped by outer function -- ("outer after inner")
+ * @return A function that computes outer(inner(x)) on application.
*/
- private static Function1, T> compose(final Function1, T> outer, final Function1, T> inner) {
-
- return
- new Function1, T>() {
- @Override
- public T apply(final F.Function0 arg) throws Throwable {
- return outer.apply(new F.Function0() {
- @Override
- public T apply() throws Throwable {
- return inner.apply(arg);
- }
- });
- }
- };
+ private static Function1, T> compose(final Function1, T> outer,
+ final Function1, T> inner) {
+
+ return new Function1, T>() {
+ @Override
+ public T apply(final F.Function0 arg) throws Throwable {
+ return outer.apply(new F.Function0() {
+ @Override
+ public T apply() throws Throwable {
+ return inner.apply(arg);
+ }
+ });
+ }
+ };
}
-
private final Function1, T> _asFunction = new Function1, T>() {
- @Override
- public T apply(F.Function0 arg) throws Throwable {
- return withinFilter(arg);
- }
+ @Override
+ public T apply(F.Function0 arg) throws Throwable {
+ return withinFilter(arg);
+ }
};
public Function1, T> asFunction() {
- return _asFunction;
+ return _asFunction;
}
public String getName() {
return name;
}
- //I don't want to add any additional dependencies to the project or use JDK 8 features
- //so I'm just rolling my own 1 arg function interface... there must be a better way to do this...
+ // I don't want to add any additional dependencies to the project or use JDK 8 features
+ // so I'm just rolling my own 1 arg function interface... there must be a better way to do this...
public static interface Function1 {
- public O apply(I arg) throws Throwable;
+ public O apply(I arg) throws Throwable;
}
}
@@ -473,11 +592,12 @@ public final boolean hasFilter() {
}
/**
- * Return the filter implementation for this plugin.
- */
+ * Return the filter implementation for this plugin.
+ *
+ * @return filter object of this plugin
+ */
public Filter getFilter() {
return null;
}
-
}
diff --git a/framework/src/play/classloading/ApplicationClasses.java b/framework/src/play/classloading/ApplicationClasses.java
index cc3cd9b03b..966961243a 100644
--- a/framework/src/play/classloading/ApplicationClasses.java
+++ b/framework/src/play/classloading/ApplicationClasses.java
@@ -123,6 +123,9 @@ public List all() {
/**
* Put a new class to the cache.
+ *
+ * @param applicationClass
+ * The class to add
*/
public void add(ApplicationClass applicationClass) {
classes.put(applicationClass.name, applicationClass);
@@ -130,11 +133,20 @@ public void add(ApplicationClass applicationClass) {
/**
* Remove a class from cache
+ *
+ * @param applicationClass
+ * The class to remove
*/
public void remove(ApplicationClass applicationClass) {
classes.remove(applicationClass.name);
}
+ /**
+ * Remove a class from cache
+ *
+ * @param applicationClass
+ * The class name to remove
+ */
public void remove(String applicationClass) {
classes.remove(applicationClass);
}
@@ -144,6 +156,7 @@ public void remove(String applicationClass) {
*
* @param name
* The fully qualified class name
+ * @return true if the class is loaded
*/
public boolean hasClass(String name) {
return classes.containsKey(name);
diff --git a/framework/src/play/classloading/ApplicationClassloader.java b/framework/src/play/classloading/ApplicationClassloader.java
index 6e2657a965..f9f686ba66 100644
--- a/framework/src/play/classloading/ApplicationClassloader.java
+++ b/framework/src/play/classloading/ApplicationClassloader.java
@@ -1,17 +1,8 @@
package play.classloading;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-
-import play.Logger;
-import play.Play;
-import play.cache.Cache;
-import play.classloading.ApplicationClasses.ApplicationClass;
-import play.classloading.hash.ClassStateHashCreator;
-import play.exceptions.RestartNeededException;
-import play.exceptions.UnexpectedException;
-import play.libs.IO;
-import play.vfs.VirtualFile;
+import static java.util.Collections.unmodifiableList;
+import static java.util.Collections.unmodifiableMap;
+import static org.apache.commons.io.IOUtils.closeQuietly;
import java.io.File;
import java.io.IOException;
@@ -25,24 +16,40 @@
import java.security.Permissions;
import java.security.ProtectionDomain;
import java.security.cert.Certificate;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
-import static java.util.Collections.unmodifiableList;
-import static java.util.Collections.unmodifiableMap;
-import static org.apache.commons.io.IOUtils.closeQuietly;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+
+import play.Logger;
+import play.Play;
+import play.cache.Cache;
+import play.classloading.ApplicationClasses.ApplicationClass;
+import play.classloading.hash.ClassStateHashCreator;
+import play.exceptions.RestartNeededException;
+import play.exceptions.UnexpectedException;
+import play.libs.IO;
+import play.vfs.VirtualFile;
/**
- * The application classLoader.
- * Load the classes from the application Java sources files.
+ * The application classLoader. Load the classes from the application Java sources files.
*/
public class ApplicationClassloader extends ClassLoader {
-
private final ClassStateHashCreator classStateHashCreator = new ClassStateHashCreator();
/**
- * A representation of the current state of the ApplicationClassloader.
- * It gets a new value each time the state of the classloader changes.
+ * A representation of the current state of the ApplicationClassloader. It gets a new value each time the state of
+ * the classloader changes.
*/
public ApplicationClassloaderState currentState = new ApplicationClassloaderState();
@@ -51,7 +58,7 @@ public class ApplicationClassloader extends ClassLoader {
*/
public ProtectionDomain protectionDomain;
- private final Object lock = new Object();
+ private final Object lock = new Object();
public ApplicationClassloader() {
super(ApplicationClassloader.class.getClassLoader());
@@ -78,8 +85,8 @@ protected Class> loadClass(String name, boolean resolve) throws ClassNotFoundE
return c;
}
- synchronized( lock ) {
- // First check if it's an application Class
+ synchronized (lock) {
+ // First check if it's an application Class
Class> applicationClass = loadApplicationClass(name);
if (applicationClass != null) {
if (resolve) {
@@ -96,7 +103,7 @@ public Class> loadApplicationClass(String name) {
if (ApplicationClass.isClass(name)) {
Class maybeAlreadyLoaded = findLoadedClass(name);
- if(maybeAlreadyLoaded != null) {
+ if (maybeAlreadyLoaded != null) {
return maybeAlreadyLoaded;
}
}
@@ -149,7 +156,8 @@ public Class> loadApplicationClass(String name) {
}
if (bc != null) {
applicationClass.enhancedByteCode = bc;
- applicationClass.javaClass = defineClass(applicationClass.name, applicationClass.enhancedByteCode, 0, applicationClass.enhancedByteCode.length, protectionDomain);
+ applicationClass.javaClass = defineClass(applicationClass.name, applicationClass.enhancedByteCode, 0,
+ applicationClass.enhancedByteCode.length, protectionDomain);
resolveClass(applicationClass.javaClass);
if (!applicationClass.isClass()) {
applicationClass.javaPackage = applicationClass.javaClass.getPackage();
@@ -163,7 +171,8 @@ public Class> loadApplicationClass(String name) {
}
if (applicationClass.javaByteCode != null || applicationClass.compile() != null) {
applicationClass.enhance();
- applicationClass.javaClass = defineClass(applicationClass.name, applicationClass.enhancedByteCode, 0, applicationClass.enhancedByteCode.length, protectionDomain);
+ applicationClass.javaClass = defineClass(applicationClass.name, applicationClass.enhancedByteCode, 0,
+ applicationClass.enhancedByteCode.length, protectionDomain);
BytecodeCache.cacheBytecode(applicationClass.enhancedByteCode, name, applicationClass.javaSource);
resolveClass(applicationClass.javaClass);
if (!applicationClass.isClass()) {
@@ -296,6 +305,9 @@ public URL nextElement() {
/**
* Detect Java changes
+ *
+ * @throws play.exceptions.RestartNeededException
+ * Thrown if the application need to be restarted
*/
public void detectChanges() throws RestartNeededException {
// Now check for file modification
@@ -316,7 +328,7 @@ public void detectChanges() throws RestartNeededException {
for (ApplicationClass applicationClass : modifiedWithDependencies) {
if (applicationClass.compile() == null) {
Play.classes.classes.remove(applicationClass.name);
- currentState = new ApplicationClassloaderState();//show others that we have changed..
+ currentState = new ApplicationClassloaderState();// show others that we have changed..
} else {
int sigChecksum = applicationClass.sigChecksum;
applicationClass.enhance();
@@ -325,10 +337,10 @@ public void detectChanges() throws RestartNeededException {
}
BytecodeCache.cacheBytecode(applicationClass.enhancedByteCode, applicationClass.name, applicationClass.javaSource);
newDefinitions.add(new ClassDefinition(applicationClass.javaClass, applicationClass.enhancedByteCode));
- currentState = new ApplicationClassloaderState();//show others that we have changed..
+ currentState = new ApplicationClassloaderState();// show others that we have changed..
}
}
-
+
if (!newDefinitions.isEmpty()) {
Cache.clear();
if (HotswapAgent.enabled) {
@@ -353,11 +365,11 @@ public void detectChanges() throws RestartNeededException {
for (ApplicationClass applicationClass : Play.classes.all()) {
if (!applicationClass.javaFile.exists()) {
Play.classes.classes.remove(applicationClass.name);
- currentState = new ApplicationClassloaderState();//show others that we have changed..
+ currentState = new ApplicationClassloaderState();// show others that we have changed..
}
if (applicationClass.name.contains("$")) {
Play.classes.classes.remove(applicationClass.name);
- currentState = new ApplicationClassloaderState();//show others that we have changed..
+ currentState = new ApplicationClassloaderState();// show others that we have changed..
// Ok we have to remove all classes from the same file ...
VirtualFile vf = applicationClass.javaFile;
for (ApplicationClass ac : Play.classes.all()) {
@@ -370,7 +382,7 @@ public void detectChanges() throws RestartNeededException {
throw new RestartNeededException("Path has changed");
}
}
-
+
/**
* Used to track change of the application sources path
*/
@@ -382,6 +394,7 @@ private int computePathHash() {
/**
* Try to load all .java files found.
+ *
* @return The list of well defined Class
*/
public List getAllClasses() {
@@ -450,13 +463,15 @@ public int compare(Class o1, Class o2) {
}
return allClasses;
}
-
+
private List allClasses;
private Map allClassesByNormalizedName;
/**
* Retrieve all application classes assignable to this class.
- * @param clazz The superclass, or the interface.
+ *
+ * @param clazz
+ * The superclass, or the interface.
* @return A list of class
*/
public List getAssignableClasses(Class clazz) {
@@ -483,7 +498,9 @@ public List getAssignableClasses(Class clazz) {
/**
* Find a class in a case insensitive way
- * @param name The class name.
+ *
+ * @param name
+ * The class name.
* @return a class
*/
public Class getClassIgnoreCase(String name) {
@@ -501,7 +518,9 @@ public Class getClassIgnoreCase(String name) {
/**
* Retrieve all application classes with a specific annotation.
- * @param clazz The annotation class.
+ *
+ * @param clazz
+ * The annotation class.
* @return A list of class
*/
public List getAnnotatedClasses(Class extends Annotation> clazz) {
@@ -520,7 +539,7 @@ public List getAnnotatedClasses(Class[] clazz) {
}
return results;
}
-
+
private List getAllClasses(VirtualFile path) {
return getAllClasses(path, "");
}
diff --git a/framework/src/play/classloading/ApplicationCompiler.java b/framework/src/play/classloading/ApplicationCompiler.java
index 48acb3c7e8..5b0e608f30 100644
--- a/framework/src/play/classloading/ApplicationCompiler.java
+++ b/framework/src/play/classloading/ApplicationCompiler.java
@@ -36,9 +36,12 @@ public class ApplicationCompiler {
Map packagesCache = new HashMap<>();
ApplicationClasses applicationClasses;
Map settings;
-
+
/**
* Try to guess the magic configuration options
+ *
+ * @param applicationClasses
+ * The application classes container
*/
public ApplicationCompiler(ApplicationClasses applicationClasses) {
this.applicationClasses = applicationClasses;
@@ -67,7 +70,6 @@ public ApplicationCompiler(ApplicationClasses applicationClasses) {
this.settings.put(CompilerOptions.OPTION_Compliance, javaVersion);
this.settings.put(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE);
}
-
/**
* Something to compile
@@ -120,17 +122,18 @@ public char[][] getPackageName() {
@Override
public boolean ignoreOptionalProblems() {
- // TODO Auto-generated method stub
return false;
}
}
/**
* Please compile this className
+ *
+ * @param classNames
+ * Arrays of the class name to compile
*/
@SuppressWarnings("deprecation")
public void compile(String[] classNames) {
-
ICompilationUnit[] compilationUnits = new CompilationUnit[classNames.length];
for (int i = 0; i < classNames.length; i++) {
compilationUnits[i] = new CompilationUnit(classNames[i]);
diff --git a/framework/src/play/classloading/enhancers/Enhancer.java b/framework/src/play/classloading/enhancers/Enhancer.java
index d650c69301..d2c3abd69b 100644
--- a/framework/src/play/classloading/enhancers/Enhancer.java
+++ b/framework/src/play/classloading/enhancers/Enhancer.java
@@ -1,15 +1,16 @@
package play.classloading.enhancers;
-import java.io.File;
import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.FileInputStream;
import java.lang.annotation.Annotation;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
+
import javassist.ClassPath;
import javassist.ClassPool;
import javassist.CtClass;
@@ -19,8 +20,8 @@
import javassist.NotFoundException;
import javassist.bytecode.AnnotationsAttribute;
import javassist.bytecode.annotation.MemberValue;
-import play.Play;
import play.Logger;
+import play.Play;
import play.classloading.ApplicationClasses.ApplicationClass;
/**
@@ -33,7 +34,7 @@ public abstract class Enhancer {
public Enhancer() {
this.classPool = newClassPool();
}
-
+
public static ClassPool newClassPool() {
ClassPool classPool = new ClassPool();
classPool.appendSystemPath();
@@ -44,6 +45,12 @@ public static ClassPool newClassPool() {
/**
* Construct a javassist CtClass from an application class.
+ *
+ * @param applicationClass
+ * The application class to construct
+ * @return The javassist CtClass construct from the application class
+ * @throws IOException
+ * if problem occurred during construction
*/
public CtClass makeClass(ApplicationClass applicationClass) throws IOException {
return classPool.makeClass(new ByteArrayInputStream(applicationClass.enhancedByteCode));
@@ -51,6 +58,11 @@ public CtClass makeClass(ApplicationClass applicationClass) throws IOException {
/**
* The magic happen here...
+ *
+ * @param applicationClass
+ * The application class to construct
+ * @throws Exception
+ * if problem occurred during construction
*/
public abstract void enhanceThisClass(ApplicationClass applicationClass) throws Exception;
@@ -62,17 +74,17 @@ public static class ApplicationClassesClasspath implements ClassPath {
@Override
public InputStream openClassfile(String className) throws NotFoundException {
- if(Play.usePrecompiled) {
+ if (Play.usePrecompiled) {
try {
File file = Play.getFile("precompiled/java/" + className.replace(".", "/") + ".class");
return new FileInputStream(file);
- } catch(Exception e) {
+ } catch (Exception e) {
Logger.error("Missing class %s", className);
}
}
ApplicationClass appClass = Play.classes.getApplicationClass(className);
- if ( appClass.enhancedByteCode == null) {
+ if (appClass.enhancedByteCode == null) {
throw new RuntimeException("Trying to visit uncompiled class while enhancing. Uncompiled class: " + className);
}
@@ -98,11 +110,15 @@ public void close() {
}
/**
- * Test if a class has the provided annotation
- * @param ctClass the javassist class representation
- * @param annotation fully qualified name of the annotation class eg."javax.persistence.Entity"
+ * Test if a class has the provided annotation
+ *
+ * @param ctClass
+ * the javassist class representation
+ * @param annotation
+ * fully qualified name of the annotation class eg."javax.persistence.Entity"
* @return true if class has the annotation
* @throws java.lang.ClassNotFoundException
+ * if class not found
*/
protected boolean hasAnnotation(CtClass ctClass, String annotation) throws ClassNotFoundException {
for (Object object : ctClass.getAvailableAnnotations()) {
@@ -115,12 +131,16 @@ protected boolean hasAnnotation(CtClass ctClass, String annotation) throws Class
}
/**
- * Test if a field has the provided annotation
- * @param ctField the javassist field representation
- * @param annotation fully qualified name of the annotation class eg."javax.persistence.Entity"
+ * Test if a field has the provided annotation
+ *
+ * @param ctField
+ * the javassist field representation
+ * @param annotation
+ * fully qualified name of the annotation class eg."javax.persistence.Entity"
* @return true if field has the annotation
* @throws java.lang.ClassNotFoundException
- */
+ * if class not found
+ */
protected boolean hasAnnotation(CtField ctField, String annotation) throws ClassNotFoundException {
for (Object object : ctField.getAvailableAnnotations()) {
Annotation ann = (Annotation) object;
@@ -130,13 +150,17 @@ protected boolean hasAnnotation(CtField ctField, String annotation) throws Class
}
return false;
}
-
+
/**
* Test if a method has the provided annotation
- * @param ctMethod the javassist method representation
- * @param annotation fully qualified name of the annotation class eg."javax.persistence.Entity"
+ *
+ * @param ctMethod
+ * the javassist method representation
+ * @param annotation
+ * fully qualified name of the annotation class eg."javax.persistence.Entity"
* @return true if field has the annotation
* @throws java.lang.ClassNotFoundException
+ * if class not found
*/
protected boolean hasAnnotation(CtMethod ctMethod, String annotation) throws ClassNotFoundException {
for (Object object : ctMethod.getAvailableAnnotations()) {
@@ -150,9 +174,18 @@ protected boolean hasAnnotation(CtMethod ctMethod, String annotation) throws Cla
/**
* Create a new annotation to be dynamically inserted in the byte code.
+ *
+ * @param attribute
+ * annotation attribute
+ * @param annotationType
+ * Annotation
+ * @param members
+ * Member of the annotation
*/
- protected static void createAnnotation(AnnotationsAttribute attribute, Class extends Annotation> annotationType, Map members) {
- javassist.bytecode.annotation.Annotation annotation = new javassist.bytecode.annotation.Annotation(annotationType.getName(), attribute.getConstPool());
+ protected static void createAnnotation(AnnotationsAttribute attribute, Class extends Annotation> annotationType,
+ Map members) {
+ javassist.bytecode.annotation.Annotation annotation = new javassist.bytecode.annotation.Annotation(annotationType.getName(),
+ attribute.getConstPool());
for (Map.Entry member : members.entrySet()) {
annotation.addMemberValue(member.getKey(), member.getValue());
}
@@ -161,16 +194,26 @@ protected static void createAnnotation(AnnotationsAttribute attribute, Class e
/**
* Create a new annotation to be dynamically inserted in the byte code.
- */
+ *
+ * @param attribute
+ * annotation attribute
+ * @param annotationType
+ * Annotation
+ */
protected static void createAnnotation(AnnotationsAttribute attribute, Class extends Annotation> annotationType) {
createAnnotation(attribute, annotationType, new HashMap());
}
/**
* Retrieve all class annotations.
+ *
+ * @param ctClass
+ * The given class
+ * @return All class annotations
*/
protected static AnnotationsAttribute getAnnotations(CtClass ctClass) {
- AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) ctClass.getClassFile().getAttribute(AnnotationsAttribute.visibleTag);
+ AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) ctClass.getClassFile()
+ .getAttribute(AnnotationsAttribute.visibleTag);
if (annotationsAttribute == null) {
annotationsAttribute = new AnnotationsAttribute(ctClass.getClassFile().getConstPool(), AnnotationsAttribute.visibleTag);
ctClass.getClassFile().addAttribute(annotationsAttribute);
@@ -180,9 +223,14 @@ protected static AnnotationsAttribute getAnnotations(CtClass ctClass) {
/**
* Retrieve all field annotations.
- */
+ *
+ * @param ctField
+ * The given field
+ * @return All field annotations.
+ */
protected static AnnotationsAttribute getAnnotations(CtField ctField) {
- AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) ctField.getFieldInfo().getAttribute(AnnotationsAttribute.visibleTag);
+ AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) ctField.getFieldInfo()
+ .getAttribute(AnnotationsAttribute.visibleTag);
if (annotationsAttribute == null) {
annotationsAttribute = new AnnotationsAttribute(ctField.getFieldInfo().getConstPool(), AnnotationsAttribute.visibleTag);
ctField.getFieldInfo().addAttribute(annotationsAttribute);
@@ -192,9 +240,14 @@ protected static AnnotationsAttribute getAnnotations(CtField ctField) {
/**
* Retrieve all method annotations.
- */
+ *
+ * @param ctMethod
+ * The given methods
+ * @return all method annotations.
+ */
protected static AnnotationsAttribute getAnnotations(CtMethod ctMethod) {
- AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) ctMethod.getMethodInfo().getAttribute(AnnotationsAttribute.visibleTag);
+ AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) ctMethod.getMethodInfo()
+ .getAttribute(AnnotationsAttribute.visibleTag);
if (annotationsAttribute == null) {
annotationsAttribute = new AnnotationsAttribute(ctMethod.getMethodInfo().getConstPool(), AnnotationsAttribute.visibleTag);
ctMethod.getMethodInfo().addAttribute(annotationsAttribute);
@@ -203,8 +256,8 @@ protected static AnnotationsAttribute getAnnotations(CtMethod ctMethod) {
}
boolean isScalaObject(CtClass ctClass) throws Exception {
- for(CtClass i : ctClass.getInterfaces()) {
- if(i.getName().equals("scala.ScalaObject")) {
+ for (CtClass i : ctClass.getInterfaces()) {
+ if (i.getName().equals("scala.ScalaObject")) {
return true;
}
}
@@ -218,5 +271,4 @@ boolean isScala(ApplicationClass app) {
boolean isAnon(ApplicationClass app) {
return app.name.contains("$anonfun$") || app.name.contains("$anon$");
}
-
-}
+}
\ No newline at end of file
diff --git a/framework/src/play/classloading/enhancers/LocalvariablesNamesEnhancer.java b/framework/src/play/classloading/enhancers/LocalvariablesNamesEnhancer.java
index b277ed44de..48d1b88df7 100644
--- a/framework/src/play/classloading/enhancers/LocalvariablesNamesEnhancer.java
+++ b/framework/src/play/classloading/enhancers/LocalvariablesNamesEnhancer.java
@@ -1,14 +1,22 @@
package play.classloading.enhancers;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
import javassist.CtClass;
import javassist.CtMethod;
-import javassist.bytecode.*;
+import javassist.bytecode.Bytecode;
+import javassist.bytecode.CodeAttribute;
+import javassist.bytecode.CodeIterator;
+import javassist.bytecode.LocalVariableAttribute;
+import javassist.bytecode.Opcode;
import play.Logger;
import play.classloading.ApplicationClasses.ApplicationClass;
-import java.lang.reflect.Field;
-import java.util.*;
-
/**
* Track names of local variables ...
*/
@@ -21,7 +29,8 @@ public void enhanceThisClass(ApplicationClass applicationClass) throws Exception
}
CtClass ctClass = makeClass(applicationClass);
- if (!ctClass.subtypeOf(classPool.get(LocalVariablesSupport.class.getName())) && !ctClass.getName().matches("^controllers\\..*\\$class$")) {
+ if (!ctClass.subtypeOf(classPool.get(LocalVariablesSupport.class.getName()))
+ && !ctClass.getName().matches("^controllers\\..*\\$class$")) {
return;
}
@@ -71,7 +80,7 @@ public void enhanceThisClass(ApplicationClass applicationClass) throws Exception
CodeIterator codeIterator = codeAttribute.iterator();
codeIterator.move(pc);
pc = codeIterator.next();
-
+
Bytecode b = makeBytecodeForLVStore(method, localVariableAttribute.signature(i), name, localVariableAttribute.index(i));
codeIterator.insert(pc, b.get());
codeAttribute.setMaxStack(codeAttribute.computeMaxStack());
@@ -95,9 +104,12 @@ public void enhanceThisClass(ApplicationClass applicationClass) throws Exception
// Si c'est un store de la variable en cours d'examination
// et que c'est dans la frame d'utilisation de cette variable on trace l'affectation.
- // (en fait la frame commence à localVariableAttribute.startPc(i)-1 qui est la première affectation
- // mais aussi l'initialisation de la variable qui est deja tracé plus haut, donc on commence à localVariableAttribute.startPc(i))
- if (varNumber == localVariableAttribute.index(i) && index < localVariableAttribute.startPc(i) + localVariableAttribute.codeLength(i)) {
+ // (en fait la frame commence à localVariableAttribute.startPc(i)-1 qui est la première
+ // affectation
+ // mais aussi l'initialisation de la variable qui est deja tracé plus haut, donc on commence à
+ // localVariableAttribute.startPc(i))
+ if (varNumber == localVariableAttribute.index(i)
+ && index < localVariableAttribute.startPc(i) + localVariableAttribute.codeLength(i)) {
b = makeBytecodeForLVStore(method, localVariableAttribute.signature(i), aliasedName, varNumber);
codeIterator.insertEx(b.get());
codeAttribute.setMaxStack(codeAttribute.computeMaxStack());
@@ -120,30 +132,31 @@ public void enhanceThisClass(ApplicationClass applicationClass) throws Exception
ctClass.defrost();
}
-
+
static Bytecode makeBytecodeForLVStore(CtMethod method, String sig, String name, int slot) {
Bytecode b = new Bytecode(method.getMethodInfo().getConstPool());
b.addLdc(name);
- if("I".equals(sig) || "B".equals(sig) || "C".equals(sig) || "S".equals(sig) || "Z".equals(sig))
+ if ("I".equals(sig) || "B".equals(sig) || "C".equals(sig) || "S".equals(sig) || "Z".equals(sig))
b.addIload(slot);
- else if("F".equals(sig))
+ else if ("F".equals(sig))
b.addFload(slot);
- else if("J".equals(sig))
+ else if ("J".equals(sig))
b.addLload(slot);
- else if("D".equals(sig))
+ else if ("D".equals(sig))
b.addDload(slot);
else
b.addAload(slot);
-
+
String localVarDescriptor = sig;
- if(!"B".equals(sig) && !"C".equals(sig) && !"D".equals(sig) && !"F".equals(sig) &&
- !"I".equals(sig) && !"J".equals(sig) && !"S".equals(sig) && !"Z".equals(sig))
+ if (!"B".equals(sig) && !"C".equals(sig) && !"D".equals(sig) && !"F".equals(sig) && !"I".equals(sig) && !"J".equals(sig)
+ && !"S".equals(sig) && !"Z".equals(sig))
localVarDescriptor = "Ljava/lang/Object;";
Logger.trace("for variable '%s' in slot=%s, sig was '%s' and is now '%s'", name, slot, sig, localVarDescriptor);
- b.addInvokestatic("play.classloading.enhancers.LocalvariablesNamesEnhancer$LocalVariablesNamesTracer", "addVariable", "(Ljava/lang/String;"+localVarDescriptor+")V");
-
+ b.addInvokestatic("play.classloading.enhancers.LocalvariablesNamesEnhancer$LocalVariablesNamesTracer", "addVariable",
+ "(Ljava/lang/String;" + localVarDescriptor + ")V");
+
return b;
}
@@ -252,19 +265,20 @@ public static Object getLocalVariable(String variable) {
public static Stack