Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile at JDK 1.6 #17 #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
###########
# PROJECT #
###########
*.settings/
*.project
*.classpath
*log
**/target/
*.iml

########
# IDEA #
########
/.idea/*
33 changes: 23 additions & 10 deletions feather/src/main/java/org/codejargon/feather/Feather.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package org.codejargon.feather;

import javax.inject.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.*;
import java.util.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Qualifier;
import javax.inject.Singleton;

public class Feather {
private final Map<Key, Provider<?>> providers = new ConcurrentHashMap<>();
private final Map<Key, Object> singletons = new ConcurrentHashMap<>();
private final Map<Class, Object[][]> injectFields = new ConcurrentHashMap<>(0);
private final Map<Key, Provider<?>> providers = new ConcurrentHashMap<Key, Provider<?>>();
private final Map<Key, Object> singletons = new ConcurrentHashMap<Key, Object>();
private final Map<Class, Object[][]> injectFields = new ConcurrentHashMap<Class, Object[][]>(0);

/**
* Constructs Feather with configuration modules
Expand Down Expand Up @@ -82,7 +95,7 @@ public void injectFields(Object target) {
Field field = (Field) f[0];
Key key = (Key) f[2];
try {
field.set(target, (boolean) f[1] ? provider(key) : instance(key));
field.set(target, ((Boolean) f[1]).booleanValue() ? provider(key) : instance(key));
} catch (Exception e) {
throw new FeatherException(String.format("Can't inject field %s in %s", field.getName(), target.getClass().getName()));
}
Expand Down Expand Up @@ -202,7 +215,7 @@ private static Object[] params(Provider<?>[] paramProviders) {

private static Set<Key> append(Set<Key> set, Key newKey) {
if (set != null && !set.isEmpty()) {
Set<Key> appended = new LinkedHashSet<>(set);
Set<Key> appended = new LinkedHashSet<Key>(set);
appended.add(newKey);
return appended;
} else {
Expand All @@ -229,7 +242,7 @@ private static Object[][] injectFields(Class<?> target) {

private static Set<Field> fields(Class<?> type) {
Class<?> current = type;
Set<Field> fields = new HashSet<>();
Set<Field> fields = new HashSet<Field>();
while (!current.equals(Object.class)) {
for (Field field : current.getDeclaredFields()) {
if (field.isAnnotationPresent(Inject.class)) {
Expand Down Expand Up @@ -275,7 +288,7 @@ private static Constructor constructor(Key key) {

private static Set<Method> providers(Class<?> type) {
Class<?> current = type;
Set<Method> providers = new HashSet<>();
Set<Method> providers = new HashSet<Method>();
while (!current.equals(Object.class)) {
for (Method method : current.getDeclaredMethods()) {
if (method.isAnnotationPresent(Provides.class) && (type.equals(current) || !providerInSubClass(method, providers))) {
Expand Down
9 changes: 5 additions & 4 deletions feather/src/main/java/org/codejargon/feather/Key.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.codejargon.feather;

import javax.inject.Named;
import java.lang.annotation.Annotation;

import javax.inject.Named;

public class Key<T> {
final Class<T> type;
final Class<? extends Annotation> qualifier;
Expand All @@ -18,21 +19,21 @@ private Key(Class<T> type, Class<? extends Annotation> qualifier, String name) {
* @return Key for a given type
*/
public static <T> Key<T> of(Class<T> type) {
return new Key<>(type, null, null);
return new Key<T>(type, null, null);
}

/**
* @return Key for a given type and qualifier annotation type
*/
public static <T> Key<T> of(Class<T> type, Class<? extends Annotation> qualifier) {
return new Key<>(type, qualifier, null);
return new Key<T>(type, qualifier, null);
}

/**
* @return Key for a given type and name (@Named value)
*/
public static <T> Key<T> of(Class<T> type, String name) {
return new Key<>(type, Named.class, name);
return new Key<T>(type, Named.class, name);
}

static <T> Key<T> of(Class<T> type, Annotation qualifier) {
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
</developers>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<scm>
<connection>scm:git:https://github.com/zsoltherpai/feather.git</connection>
Expand Down Expand Up @@ -124,8 +124,8 @@
<configuration>
<optimize>true</optimize>
<debug>false</debug>
<source>1.7</source>
<target>1.7</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
Expand All @@ -139,8 +139,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
Expand Down