[dependency-shot] r389 committed - Format code

0 views
Skip to first unread message

depende...@googlecode.com

unread,
Mar 17, 2011, 3:36:16 PM3/17/11
to depende...@googlegroups.com
Revision: 389
Author: mathieu.ancelin
Date: Thu Mar 17 12:21:00 2011
Log: Format code
http://code.google.com/p/dependency-shot/source/detail?r=389

Modified:

/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/CircularConstructorHandler.java

/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/ClassHandler.java

/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/ConstructorHandler.java

/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/FieldsHandler.java

/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/MethodHandler.java

=======================================
---
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/CircularConstructorHandler.java
Sat Mar 12 14:15:30 2011
+++
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/CircularConstructorHandler.java
Thu Mar 17 12:21:00 2011
@@ -14,7 +14,6 @@
* limitations under the License.
* under the License.
*/
-
package cx.ath.mancel01.dependencyshot.injection.handlers;

import cx.ath.mancel01.dependencyshot.exceptions.DSException;
@@ -40,7 +39,8 @@
/**
* Constructor.
*/
- public CircularConstructorHandler() {}
+ public CircularConstructorHandler() {
+ }

/**
* Return an instance of an object by constructor invocation.
@@ -55,44 +55,42 @@
*/
public <T> T getConstructedInstance(Class<T> c, Map<Class<?>, Object>
possibleInstances)
throws InstantiationException,
- IllegalAccessException,
- InvocationTargetException {
+ IllegalAccessException,
+ InvocationTargetException {
// get constructors defined in the class c
- Constructor<?>[] constructorsOfTheClass = c.getDeclaredConstructors();
- for(Constructor<?> constructor : constructorsOfTheClass) {
- Inject annotation = constructor.getAnnotation(Inject.class);
- Class<?>[] parameterTypes = constructor.getParameterTypes();
- Type[] genericParameterTypes = constructor.getGenericParameterTypes();
- boolean isDefaultConstructor = (
-
constructorsOfTheClass.length == 1 &&
- parameterTypes.length == 0
&&
-
Modifier.isPublic(constructor.getModifiers())
- );
+ Constructor<?>[] constructorsOfTheClass =
c.getDeclaredConstructors();
+ for (Constructor<?> constructor : constructorsOfTheClass) {
+ Inject annotation = constructor.getAnnotation(Inject.class);
+ Class<?>[] parameterTypes = constructor.getParameterTypes();
+ Type[] genericParameterTypes =
constructor.getGenericParameterTypes();
+ boolean isDefaultConstructor = (constructorsOfTheClass.length
== 1
+ && parameterTypes.length == 0
+ && Modifier.isPublic(constructor.getModifiers()));
// check if constructor is injectable or if it's a default
constructor
- if (annotation != null || isDefaultConstructor) {
- Object[] arguments = new Object[parameterTypes.length];
- Annotation[][] parameterAnnotations =
constructor.getParameterAnnotations();
+ if (annotation != null || isDefaultConstructor) {
+ Object[] arguments = new Object[parameterTypes.length];
+ Annotation[][] parameterAnnotations =
constructor.getParameterAnnotations();
// inject each parameters with a simple instance or a
provided one
- for (int j = 0; j < parameterTypes.length; j++) {
- arguments[j] = possibleInstances.get((Class<?>) parameterTypes[j]);
- }
- boolean accessible = constructor.isAccessible();
+ for (int j = 0; j < parameterTypes.length; j++) {
+ arguments[j] = possibleInstances.get((Class<?>)
parameterTypes[j]);
+ }
+ boolean accessible = constructor.isAccessible();
// if the constructor is private, then put it public for
newinstance creation
- if (!accessible) {
- constructor.setAccessible(true);
- }
+ if (!accessible) {
+ constructor.setAccessible(true);
+ }
// create new instance with the constructor
- try {
- return c.cast(constructor.newInstance(arguments));
- } finally {
+ try {
+ return c.cast(constructor.newInstance(arguments));
+ } finally {
// if constructor was private, then put it private back
- if (!accessible) {
- constructor.setAccessible(accessible);
- }
- }
- }
- }
- ExceptionManager.makeException("Could not find @Inject
constructor for " + c).throwManaged();
- throw new DSException("Could not find @Inject constructor for " + c);
- }
-}
+ if (!accessible) {
+ constructor.setAccessible(accessible);
+ }
+ }
+ }
+ }
+ ExceptionManager.makeException("Could not find @Inject constructor
for " + c).throwManaged();
+ throw new DSException("Could not find @Inject constructor for " +
c);
+ }
+}
=======================================
---
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/ClassHandler.java
Thu Aug 5 08:57:36 2010
+++
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/ClassHandler.java
Thu Mar 17 12:21:00 2011
@@ -14,7 +14,6 @@
* limitations under the License.
* under the License.
*/
-
package cx.ath.mancel01.dependencyshot.injection.handlers;

import cx.ath.mancel01.dependencyshot.injection.InjectorImpl;
@@ -35,8 +34,9 @@
private static final Logger logger =
Logger.getLogger(ClassHandler.class.getSimpleName());

private FieldsHandler fieldsHandler;
-
+
private MethodHandler methodHandler;
+
/**
* Constructor.
*/
@@ -64,20 +64,20 @@
List<Method> maybeOverrides,
boolean staticInjection,
InjectorImpl injector) throws IllegalAccessException,
- InvocationTargetException {
- Class<?> superclass = c.getSuperclass();
+ InvocationTargetException {
+ Class<?> superclass = c.getSuperclass();
// check if c has a superclass and if we can inject static stuff
- if (superclass != null && !staticInjection) {
+ if (superclass != null && !staticInjection) {
// get possible overridden method
- List<Method> overideMethodOfTheClass = new
ArrayList<Method>(maybeOverrides);
+ List<Method> overideMethodOfTheClass = new
ArrayList<Method>(maybeOverrides);
// and add methods of the class
- overideMethodOfTheClass.addAll(Arrays.asList(c.getDeclaredMethods()));
+
overideMethodOfTheClass.addAll(Arrays.asList(c.getDeclaredMethods()));
// inject the superclass stuff in the instance
- classInjection(instance, superclass, overideMethodOfTheClass,
staticInjection, injector);
- }
+ classInjection(instance, superclass, overideMethodOfTheClass,
staticInjection, injector);
+ }
// inject fields of the instance
- fieldsHandler.fieldsInjection(instance, c, staticInjection, injector);
+ fieldsHandler.fieldsInjection(instance, c, staticInjection,
injector);
// inject methods of the instance
- methodHandler.methodsInjection(instance, c, maybeOverrides,
staticInjection, injector);
- }
-}
+ methodHandler.methodsInjection(instance, c, maybeOverrides,
staticInjection, injector);
+ }
+}
=======================================
---
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/ConstructorHandler.java
Sat Mar 12 14:15:30 2011
+++
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/ConstructorHandler.java
Thu Mar 17 12:21:00 2011
@@ -14,7 +14,6 @@
* limitations under the License.
* under the License.
*/
-
package cx.ath.mancel01.dependencyshot.injection.handlers;

import cx.ath.mancel01.dependencyshot.exceptions.DSException;
@@ -40,7 +39,8 @@
/**
* Constructor.
*/
- public ConstructorHandler() {}
+ public ConstructorHandler() {
+ }

/**
* Return an instance of an object by constructor invocation.
@@ -53,47 +53,45 @@
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
- public <T> T getConstructedInstance(Class<T> c, InjectorImpl injector)
+ public <T> T getConstructedInstance(Class<T> c, InjectorImpl injector)
throws InstantiationException,
- IllegalAccessException,
- InvocationTargetException {
+ IllegalAccessException,
+ InvocationTargetException {
// get constructors defined in the class c
- Constructor<?>[] constructorsOfTheClass = c.getDeclaredConstructors();
- for(Constructor<?> constructor : constructorsOfTheClass) {
- Inject annotation = constructor.getAnnotation(Inject.class);
- Class<?>[] parameterTypes = constructor.getParameterTypes();
- Type[] genericParameterTypes = constructor.getGenericParameterTypes();
- boolean isDefaultConstructor = (
-
constructorsOfTheClass.length == 1 &&
- parameterTypes.length == 0
&&
-
Modifier.isPublic(constructor.getModifiers())
- );
+ Constructor<?>[] constructorsOfTheClass =
c.getDeclaredConstructors();
+ for (Constructor<?> constructor : constructorsOfTheClass) {
+ Inject annotation = constructor.getAnnotation(Inject.class);
+ Class<?>[] parameterTypes = constructor.getParameterTypes();
+ Type[] genericParameterTypes =
constructor.getGenericParameterTypes();
+ boolean isDefaultConstructor = (constructorsOfTheClass.length
== 1
+ && parameterTypes.length == 0
+ && Modifier.isPublic(constructor.getModifiers()));
// check if constructor is injectable or if it's a default
constructor
- if (annotation != null || isDefaultConstructor) {
- Object[] arguments = new Object[parameterTypes.length];
- Annotation[][] parameterAnnotations =
constructor.getParameterAnnotations();
+ if (annotation != null || isDefaultConstructor) {
+ Object[] arguments = new Object[parameterTypes.length];
+ Annotation[][] parameterAnnotations =
constructor.getParameterAnnotations();
// inject each parameters with a simple instance or a
provided one
- for (int j = 0; j < parameterTypes.length; j++) {
- arguments[j] = injector.getProviderOrInstance((Class<?>)
parameterTypes[j], genericParameterTypes[j],
- parameterAnnotations[j], constructor);
- }
- boolean accessible = constructor.isAccessible();
+ for (int j = 0; j < parameterTypes.length; j++) {
+ arguments[j] =
injector.getProviderOrInstance((Class<?>) parameterTypes[j],
genericParameterTypes[j],
+ parameterAnnotations[j], constructor);
+ }
+ boolean accessible = constructor.isAccessible();
// if the constructor is private, then put it public for
newinstance creation
- if (!accessible) {
- constructor.setAccessible(true);
- }
+ if (!accessible) {
+ constructor.setAccessible(true);
+ }
// create new instance with the constructor
- try {
- return c.cast(constructor.newInstance(arguments));
- } finally {
+ try {
+ return c.cast(constructor.newInstance(arguments));
+ } finally {
// if constructor was private, then put it private back
- if (!accessible) {
- constructor.setAccessible(accessible);
- }
- }
- }
- }
- ExceptionManager.makeException("Could not find @Inject
constructor for " + c).throwManaged();
- throw new DSException("Could not find @Inject constructor for " + c);
- }
-}
+ if (!accessible) {
+ constructor.setAccessible(accessible);
+ }
+ }
+ }
+ }
+ ExceptionManager.makeException("Could not find @Inject constructor
for " + c).throwManaged();
+ throw new DSException("Could not find @Inject constructor for " +
c);
+ }
+}
=======================================
---
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/FieldsHandler.java
Thu Aug 5 08:57:36 2010
+++
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/FieldsHandler.java
Thu Mar 17 12:21:00 2011
@@ -14,7 +14,6 @@
* limitations under the License.
* under the License.
*/
-
package cx.ath.mancel01.dependencyshot.injection.handlers;

import cx.ath.mancel01.dependencyshot.exceptions.DSIllegalStateException;
@@ -37,7 +36,9 @@
/**
* Constructor.
*/
- public FieldsHandler() {}
+ public FieldsHandler() {
+ }
+
/**
* Inject every fields of an object.
*
@@ -51,36 +52,36 @@
public <T> void fieldsInjection(T instance, Class<?> c,
boolean staticInjection,
InjectorImpl injector) throws IllegalAccessException {
- Field[] fieldsOfTheClass = c.getDeclaredFields();
+ Field[] fieldsOfTheClass = c.getDeclaredFields();
// for each declared fields
- for(Field field : fieldsOfTheClass) {
- Inject annotation = field.getAnnotation(Inject.class);
+ for (Field field : fieldsOfTheClass) {
+ Inject annotation = field.getAnnotation(Inject.class);
// check if field is injectable and if you can inject static
fields
- if (annotation != null &&
- (staticInjection ==
Modifier.isStatic(field.getModifiers()))) {
+ if (annotation != null
+ && (staticInjection ==
Modifier.isStatic(field.getModifiers()))) {
// check if the field is not final
- if (Modifier.isFinal(field.getModifiers())) {
- throw new DSIllegalStateException("Cannot inject final field: " +
field);
- }
- Class<?> type = field.getType();
- Type genericType = field.getGenericType();
+ if (Modifier.isFinal(field.getModifiers())) {
+ throw new DSIllegalStateException("Cannot inject final
field: " + field);
+ }
+ Class<?> type = field.getType();
+ Type genericType = field.getGenericType();
// get an instance of the field (simple instance or
provided one
- Object injectedObject = injector.getProviderOrInstance(type,
genericType,
+ Object injectedObject =
injector.getProviderOrInstance(type, genericType,
field.getAnnotations(), field);
- boolean accessible = field.isAccessible();
+ boolean accessible = field.isAccessible();
// if field is private then put it private for
injectedObject setting
- if (!accessible) {
- field.setAccessible(true);
- }
- try {
- field.set(instance, injectedObject);
- } finally {
+ if (!accessible) {
+ field.setAccessible(true);
+ }
+ try {
+ field.set(instance, injectedObject);
+ } finally {
// if the field was private, then put it private back
- if (!accessible) {
- field.setAccessible(accessible);
- }
- }
- }
- }
- }
-}
+ if (!accessible) {
+ field.setAccessible(accessible);
+ }
+ }
+ }
+ }
+ }
+}
=======================================
---
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/MethodHandler.java
Thu Aug 5 08:57:36 2010
+++
/trunk/dependency-shot-core/src/main/java/cx/ath/mancel01/dependencyshot/injection/handlers/MethodHandler.java
Thu Mar 17 12:21:00 2011
@@ -38,7 +38,9 @@
/**
* Constructor.
*/
- public MethodHandler() {}
+ public MethodHandler() {
+ }
+
/**
* Inject all injectable methods of an object.
*
@@ -56,11 +58,11 @@
List<Method> maybeOverrides,
boolean staticInjection,
InjectorImpl injector) throws IllegalAccessException,
- InvocationTargetException {
-
+ InvocationTargetException {
+
Method[] methodsOfTheClass = c.getDeclaredMethods();
// for each method of the class
- for(Method method : methodsOfTheClass) {
+ for (Method method : methodsOfTheClass) {
Inject annotation = method.getAnnotation(Inject.class);
// check if method is injectable and if you can inject static
methods and if method is overriden
if (annotation != null && (staticInjection ==
Modifier.isStatic(method.getModifiers()))
@@ -102,13 +104,13 @@
* @return if the method is overridden.
*/
private static boolean isOverridden(Method method, List<Method>
maybeOverrides) {
- for (Method candidate : maybeOverrides) {
- if (isOverridden(method, candidate)) {
- return true;
- }
- }
- return false;
- }
+ for (Method candidate : maybeOverrides) {
+ if (isOverridden(method, candidate)) {
+ return true;
+ }
+ }
+ return false;
+ }

/**
* Check if a method is overriden by another one.
@@ -117,46 +119,46 @@
* @param candidate method to check against.
* @return if the method is overridden.
*/
- private static boolean isOverridden(Method method, Method candidate) {
+ private static boolean isOverridden(Method method, Method candidate) {
// check f names are the same
- if (!method.getName().equals(candidate.getName())) {
- return false;
- }
- int modifiers = candidate.getModifiers();
+ if (!method.getName().equals(candidate.getName())) {
+ return false;
+ }
+ int modifiers = candidate.getModifiers();
// check if candidate is private
- boolean isPrivate = Modifier.isPrivate(modifiers);
- if (isPrivate) {
- return false;
- }
+ boolean isPrivate = Modifier.isPrivate(modifiers);
+ if (isPrivate) {
+ return false;
+ }
// check if candidate is static
- boolean isStatic = Modifier.isStatic(modifiers);
- if (isStatic) {
- return false;
- }
- boolean isDefault = !isPrivate &&
- !Modifier.isPublic(modifiers) &&
- !Modifier.isProtected(modifiers);
- boolean samePackage =
- method.getDeclaringClass().getPackage() ==
- candidate.getDeclaringClass().getPackage();
- if (isDefault && !samePackage) {
- return false;
- }
+ boolean isStatic = Modifier.isStatic(modifiers);
+ if (isStatic) {
+ return false;
+ }
+ boolean isDefault = !isPrivate
+ && !Modifier.isPublic(modifiers)
+ && !Modifier.isProtected(modifiers);
+ boolean samePackage =
+ method.getDeclaringClass().getPackage()
+ == candidate.getDeclaringClass().getPackage();
+ if (isDefault && !samePackage) {
+ return false;
+ }
// check if parameters are the same
- Class<?>[] methodParameters = method.getParameterTypes();
- Class<?>[] candidateParameters = candidate.getParameterTypes();
+ Class<?>[] methodParameters = method.getParameterTypes();
+ Class<?>[] candidateParameters = candidate.getParameterTypes();
// check numbers of parameters
- if (methodParameters.length != candidateParameters.length) {
- return false;
- }
+ if (methodParameters.length != candidateParameters.length) {
+ return false;
+ }
// check types of parameters
- for (int i = 0; i < methodParameters.length; i++) {
- Class<?> class1 = methodParameters[i];
- Class<?> class2 = candidateParameters[i];
- if (!class1.equals(class2)) {
- return false;
- }
- }
- return true;
- }
-}
+ for (int i = 0; i < methodParameters.length; i++) {
+ Class<?> class1 = methodParameters[i];
+ Class<?> class2 = candidateParameters[i];
+ if (!class1.equals(class2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}

Reply all
Reply to author
Forward
0 new messages