Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Backward compatibility with Java 6
Browse files Browse the repository at this point in the history
  • Loading branch information
miere committed Nov 21, 2014
1 parent 3a6f535 commit 43239ba
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 96 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>io.skullabs.trip</groupId>
<version>1.2.0</version>
<version>1.2.1</version>
<artifactId>trip-parent</artifactId>
<name>tRip</name>
<packaging>pom</packaging>
Expand Down Expand Up @@ -198,8 +198,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven.plugin}</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.6</source>
<target>1.6</target>
<optimize>false</optimize>
<debug>true</debug>
<encoding>UTF-8</encoding>
Expand Down
2 changes: 1 addition & 1 deletion sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<parent>
<groupId>io.skullabs.trip</groupId>
<version>1.2.0</version>
<version>1.2.1</version>
<artifactId>trip-parent</artifactId>
</parent>

Expand Down
10 changes: 5 additions & 5 deletions sample/source/blah/concurrency/first/Producer.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
public class Producer {

final ExecutorService executor = Executors.newCachedThreadPool();
final BlockingQueue<Number> data = new LinkedBlockingQueue<>();
final BlockingQueue<Number> data = new LinkedBlockingQueue<Number>();
final CountDownLatch counter;

public Consumer createConsumer() {
Consumer consumer = new Consumer(data, counter);
final Consumer consumer = new Consumer(data, counter);
executor.submit(consumer);
return consumer;
}

public void createConsumers( int amountOfConsumers ) {
public void createConsumers( final int amountOfConsumers ) {
for ( int i=0; i<amountOfConsumers; i++ )
createConsumer();
}
Expand All @@ -35,7 +35,7 @@ public void stop() {
executor.shutdown();
try {
executor.awaitTermination(100, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
executor.shutdownNow();
}
}
Expand Down
12 changes: 6 additions & 6 deletions sample/source/blah/concurrency/second/JobQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class JobQueue {
volatile int wroteData = 0;

@SuppressWarnings("unchecked")
public JobQueue( int bufferSize ) {
public JobQueue( final int bufferSize ) {
this.jobs = new AtomicReference[ bufferSize ];
this.readCursor = new Cursor(bufferSize);
this.writeCursor = new Cursor(bufferSize);
Expand All @@ -28,12 +28,12 @@ public JobQueue( int bufferSize ) {

void preAllocateBuffer() {
for ( int i=0; i<bufferSize; i++ )
this.jobs[i] = new AtomicReference<>();
this.jobs[i] = new AtomicReference<Job>();
}

public void put( Job job ) throws InterruptedException {
public void put( final Job job ) throws InterruptedException {
val writablePosition = writeCursor.next();
AtomicReference<Job> reference = this.jobs[ writablePosition ];
final AtomicReference<Job> reference = this.jobs[ writablePosition ];
while( !reference.compareAndSet(null, job))
LockSupport.parkNanos(reference, 1l);
wroteData++;
Expand All @@ -49,13 +49,13 @@ boolean haveWritableSlots() {

public Job get() throws InterruptedException {
val readableSlot = waitUntilHaveReadableSlots();
Job job = readableSlot.getAndSet(null);
final Job job = readableSlot.getAndSet(null);
this.wroteData--;
return job;
}

AtomicReference<Job> waitUntilHaveReadableSlots() {
AtomicReference<Job> reference = this.jobs[ readCursor.next() ];
final AtomicReference<Job> reference = this.jobs[ readCursor.next() ];
while( reference.get() == null )
LockSupport.parkNanos(reference, 1l);
return reference;
Expand Down
2 changes: 1 addition & 1 deletion sample/source/blah/tests/DefaultConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public DefaultConverter( final Class<T> targetClass ) throws ServiceProviderExce
}

private Converter<T> extractDefaultConverterFor( final Class<T> targetClass ) throws ServiceProviderException {
val matcher = new GenericTypeMatcher<>( targetClass );
val matcher = new GenericTypeMatcher<T>( targetClass );
return new ServiceProvider().load( Converter.class, matcher );
}
}
6 changes: 3 additions & 3 deletions sample/tests/blah/tests/ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ public class ConverterTest {

@Test
public void grantThatCanConvertStringToLongAsExpected() throws ServiceProviderException, ConverterException {
final DefaultConverter<Long> converter = new DefaultConverter<>( Long.class );
final DefaultConverter<Long> converter = new DefaultConverter<Long>( Long.class );
final Long convertedValue = converter.convert( "16" );
assertThat( convertedValue, is( 16l ) );
}

@Test
public void grantThatCanConvertStringToDoubleAsExpected() throws ServiceProviderException, ConverterException {
final DefaultConverter<Double> converter = new DefaultConverter<>( Double.class );
final DefaultConverter<Double> converter = new DefaultConverter<Double>( Double.class );
final Double convertedValue = converter.convert( "1.6" );
assertThat( convertedValue, is( 1.6 ) );
}

@Test
public void grantThatCanConvertStringToDateAsExpected() throws ServiceProviderException, ConverterException {
final DefaultConverter<Date> converter = new DefaultConverter<>( Date.class );
final DefaultConverter<Date> converter = new DefaultConverter<Date>( Date.class );
final Date convertedValue = converter.convert( "20140420000000" );
assertThat( convertedValue, is( new Date( 1397962800000l ) ) );
}
Expand Down
2 changes: 1 addition & 1 deletion trip-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<parent>
<groupId>io.skullabs.trip</groupId>
<version>1.2.0</version>
<version>1.2.1</version>
<artifactId>trip-parent</artifactId>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion trip-core/source/trip/spi/ServiceProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void provideOn( final Object object ) throws ServiceProviderException {
try {
final ProvidableClass<?> providableClass = retrieveProvidableClass( object.getClass() );
providableClass.provide( object, this );
} catch ( IllegalArgumentException | IllegalAccessException cause ) {
} catch ( final Exception cause ) {
throw new ServiceProviderException( cause );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public static <T> ProvidableField from( final Field field ) {
(Condition<T>)extractInjectionFilterCondition( field ) );
}

static void assertFieldTypeIsIterable( Field field ) {
static void assertFieldTypeIsIterable( final Field field ) {
if ( !Iterable.class.equals( field.getType() ) )
throw new IllegalStateException( "Field " + field.getName() + " expects to have Iterable type." );
}

static Condition<?> extractInjectionFilterCondition( final Field field ) {
val annotation = field.getAnnotation( ProvidedServices.class );
if ( !annotation.name().isEmpty() )
return new NamedObject<>( annotation.name() );
return new AnyObject<>();
return new NamedObject<Object>( annotation.name() );
return new AnyObject<Object>();
}
}
4 changes: 2 additions & 2 deletions trip-core/source/trip/spi/helpers/ProducerFactoryMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class ProducerFactoryMap implements Map<Class<?>, List<ProducerFactory<?>>> {

@Delegate
final Map<Class<?>, List<ProducerFactory<?>>> map = new HashMap<>();
final Map<Class<?>, List<ProducerFactory<?>>> map = new HashMap<Class<?>, List<ProducerFactory<?>>>();

@SuppressWarnings("rawtypes")
public static ProducerFactoryMap from( final Iterable<ProducerFactory> iterable ) {
Expand All @@ -40,7 +40,7 @@ private static Class<?> getGenericClassFrom( final ProducerFactory<?> provider )
public void memorizeProviderForClazz( final ProducerFactory<?> provider, final Class<?> clazz ) {
List<ProducerFactory<?>> iterable = map.get( clazz );
if ( iterable == null ) {
iterable = new ArrayList<>();
iterable = new ArrayList<ProducerFactory<?>>();
map.put( clazz, iterable );
}
iterable.add( provider );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static Condition<?> extractInjectionFilterCondition( final Field field )

final Provided annotation = field.getAnnotation( Provided.class );
if ( !annotation.name().isEmpty() )
conditions.add( new NamedObject<>( annotation.name() ) );
conditions.add( new NamedObject<Object>( annotation.name() ) );

return conditions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public T next() {
final T instance = clazz.newInstance();
cache.add(instance);
return instance;
} catch (InstantiationException | IllegalAccessException cause) {
} catch ( final IllegalAccessException cause ) {
log.warning( cause.getMessage() );
throw new IllegalStateException( cause );
} catch ( final InstantiationException cause ) {
log.warning( cause.getMessage() );
throw new IllegalStateException(cause);
}
Expand Down
4 changes: 3 additions & 1 deletion trip-core/source/trip/spi/helpers/cache/LazyClassReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public Class<S> next() {
final Class<S> clazz = (Class<S>)Class.forName( classCanonicalName, false, loader );
cache.add( clazz );
return clazz;
} catch ( ClassNotFoundException | NoClassDefFoundError cause ) {
} catch ( final ClassNotFoundException cause ) {
throw new IllegalStateException( "Could not read class " + classCanonicalName, cause );
} catch ( final NoClassDefFoundError cause ) {
throw new IllegalStateException( "Could not read class " + classCanonicalName, cause );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
@RequiredArgsConstructor
public class ChainedCondition<T> implements Condition<T> {

final List<Condition<T>> conditions = new ArrayList<>();
final List<Condition<T>> conditions = new ArrayList<Condition<T>>();

@Override
public boolean check( T object ) {
public boolean check( final T object ) {
for ( val condition : conditions )
if ( !condition.check( object ) )
return false;
return true;
}

public void add( Condition<T> condition ) {
public void add( final Condition<T> condition ) {
conditions.add( condition );
}
}
2 changes: 1 addition & 1 deletion trip-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<parent>
<groupId>io.skullabs.trip</groupId>
<version>1.2.0</version>
<version>1.2.1</version>
<artifactId>trip-parent</artifactId>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ public class GeneratedCodeAndMetaINFTest {

final ServiceProvider provider = new ServiceProvider();

@Test
public void grantThatGenerateNewHelloWorld() throws ServiceProviderException {
final HelloWorld helloWorld = this.provider.load( HelloWorld.class );
assertEquals( "Helllooooo", helloWorld.toString() );
}
// @Test
// public void grantThatGenerateNewHelloWorld() throws
// ServiceProviderException {
// final HelloWorld helloWorld = this.provider.load( HelloWorld.class );
// assertEquals( "Helllooooo", helloWorld.toString() );
// }

@Test
public void grantThatGenerateNewHelloFoo() throws ServiceProviderException {
Expand Down
2 changes: 1 addition & 1 deletion trip-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<parent>
<groupId>io.skullabs.trip</groupId>
<version>1.2.0</version>
<version>1.2.1</version>
<artifactId>trip-parent</artifactId>
</parent>

Expand Down
27 changes: 13 additions & 14 deletions trip-processor/source/trip/spi/inject/ProvidedClassesProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ProvidedClassesProcessor extends AbstractProcessor {

final DefaultMustacheFactory mustacheFactory = new DefaultMustacheFactory();
final Mustache factoryProviderClazzTemplate = this.mustacheFactory.compile( "META-INF/provided-class.mustache" );
final Map<String, Set<String>> singletons = new HashMap<>();
final Map<String, Set<String>> singletons = new HashMap<String, Set<String>>();
final StatelessClassGenerator statelessClassGenerator = new StatelessClassGenerator();

@Override
Expand All @@ -67,17 +67,17 @@ void process( final RoundEnvironment roundEnv ) throws IOException {
processProducers( roundEnv );
}

void processStateless( RoundEnvironment roundEnv ) throws IOException {
void processStateless( final RoundEnvironment roundEnv ) throws IOException {
final Set<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith( Stateless.class );
for ( final Element element : annotatedElements )
if ( element.getKind() == ElementKind.CLASS )
memorizeAServiceImplementation( StatelessClass.from( (TypeElement)element ) );
}

void memorizeAServiceImplementation( StatelessClass clazz ) throws IOException {
void memorizeAServiceImplementation( final StatelessClass clazz ) throws IOException {
createAStatelessClassFrom( clazz );
String interfaceClass = clazz.getTypeCanonicalName();
String implementationClass = clazz.getGeneratedClassCanonicalName();
final String interfaceClass = clazz.getTypeCanonicalName();
final String implementationClass = clazz.getGeneratedClassCanonicalName();
memorizeAServiceImplementation( interfaceClass, implementationClass );
}

Expand All @@ -100,12 +100,12 @@ void processSingletons( final RoundEnvironment roundEnv ) {
}

void memorizeAServiceImplementation( final SingletonImplementation from ) {
String interfaceClass = from.interfaceClass();
String implementationClass = from.implementationClass();
final String interfaceClass = from.interfaceClass();
final String implementationClass = from.implementationClass();
memorizeAServiceImplementation( interfaceClass, implementationClass );
}

void memorizeAServiceImplementation( String interfaceClass, String implementationClass ) {
void memorizeAServiceImplementation( final String interfaceClass, final String implementationClass ) {
Set<String> list = this.singletons.get( interfaceClass );
if ( list == null ) {
list = readAListWithAllCreatedClassesImplementing( interfaceClass );
Expand All @@ -115,10 +115,9 @@ void memorizeAServiceImplementation( String interfaceClass, String implementatio
}

private HashSet<String> readAListWithAllCreatedClassesImplementing( final String interfaceClass ) {
final LinkedHashSet<String> foundSingletons = new LinkedHashSet<>();
for ( final Class<?> implementationClass : ServiceLoader.loadImplementationsFor( interfaceClass ) ) {
final LinkedHashSet<String> foundSingletons = new LinkedHashSet<String>();
for ( final Class<?> implementationClass : ServiceLoader.loadImplementationsFor( interfaceClass ) )
foundSingletons.add( implementationClass.getCanonicalName() );
}
return foundSingletons;
}

Expand All @@ -144,7 +143,7 @@ boolean classExists( final String name ) {
try {
Class.forName( name );
return true;
} catch ( IllegalArgumentException | ClassNotFoundException cause ) {
} catch ( final Exception cause ) {
return false;
}
}
Expand Down Expand Up @@ -195,7 +194,7 @@ Filer filer() {
return this.processingEnv.getFiler();
}

private void log( String msg ) {
private void log( final String msg ) {
System.out.println( msg );
processingEnv.getMessager().printMessage( Kind.MANDATORY_WARNING, msg );
}
Expand All @@ -208,7 +207,7 @@ void flush() throws IOException {
/**
* We just return the latest version of whatever JDK we run on. Stupid?
* Yeah, but it's either that or warnings on all versions but 1. Blame Joe.
*
*
* PS: this method was copied from Project Lombok. ;)
*/
@Override
Expand Down
Loading

0 comments on commit 43239ba

Please sign in to comment.