Skip to content

Commit

Permalink
#166: Workarounds for bugs in Eclipse compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille committed Aug 6, 2016
1 parent 2e8e87d commit 4f65943
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 38 deletions.
56 changes: 24 additions & 32 deletions core/src/main/java/net/sf/mmm/util/value/api/ValueConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.sf.mmm.util.reflect.api.GenericType;

/**
* This is the interface for a converter that {@link #convert(Object, Object, GenericType) converts} a value
* from a {@link #getSourceType() source-type} to a specific {@link #getTargetType() target-type}. <br>
* This is the interface for a converter that {@link #convert(Object, Object, GenericType) converts} a value from a
* {@link #getSourceType() source-type} to a specific {@link #getTargetType() target-type}. <br>
* <b>ATTENTION:</b><br>
* An implementation of this interface should be stateless and thread-safe.
*
Expand All @@ -22,53 +22,45 @@
public interface ValueConverter<SOURCE, TARGET> extends SimpleValueConverter<SOURCE, TARGET> {

/**
* This the type of the value accepted by this converter. Use {@link Object} if you want to accept any
* value. A very common {@link #getSourceType() source-type} is {@link String}.
* This the type of the value accepted by this converter. Use {@link Object} if you want to accept any value. A very
* common {@link #getSourceType() source-type} is {@link String}.
*
* @return the source-type.
*/
Class<SOURCE> getSourceType();

/**
* Is the guaranteed return-type of the {@link #convert(Object, Object, GenericType) conversion}. This
* information is used externally to choose the most specific {@link ValueConverter} that is
* {@link Class#isAssignableFrom(Class) appropriate} for the conversion. <br>
* E.g. a generic converter can have {@link Object} as {@link #getTargetType() target-type} while a specific
* converter may have {@link java.util.Collection} as {@link #getTargetType() target-type}. Now if an object
* (compliant with the {@link #getSourceType() source-type}) needs to be converted to a
* {@link java.util.Collection} or {@link java.util.List}, the specific converter is used while for other
* objects the generic converter is chosen. <br>
* Is the guaranteed return-type of the {@link #convert(Object, Object, GenericType) conversion}. This information is
* used externally to choose the most specific {@link ValueConverter} that is {@link Class#isAssignableFrom(Class)
* appropriate} for the conversion. <br>
* E.g. a generic converter can have {@link Object} as {@link #getTargetType() target-type} while a specific converter
* may have {@link java.util.Collection} as {@link #getTargetType() target-type}. Now if an object (compliant with the
* {@link #getSourceType() source-type}) needs to be converted to a {@link java.util.Collection} or
* {@link java.util.List}, the specific converter is used while for other objects the generic converter is chosen.
* <br>
* Please note that the {@link #getTargetType() target-type} is often more general than the actual
* {@link #convert(Object, Object, GenericType) returned result}. So a {@link ValueConverter} that converts
* a comma-separated {@link String} to an {@link java.util.ArrayList} will typically declare
* {@link java.util.List} as {@link #getTargetType() target-type}.
* {@link #convert(Object, Object, GenericType) returned result}. So a {@link ValueConverter} that converts a
* comma-separated {@link String} to an {@link java.util.ArrayList} will typically declare {@link java.util.List} as
* {@link #getTargetType() target-type}.
*
* @return the target-type.
*/
Class<TARGET> getTargetType();

/**
* {@inheritDoc}
*
* @see #convert(Object, Object, GenericType)
*/
@Override
<T extends TARGET> T convert(SOURCE value, Object valueSource, Class<T> targetClass) throws ValueException;

/**
* This method converts the given {@code pojo} to the {@literal <TARGET>}-type.
*
* @param <T> is the generic type of {@code targetClass}.
* @param value is the value to convert.
* @param valueSource describes the source of the value. This may be the filename where the value was read
* from, an XPath where the value was located in an XML document, etc. It is used in exceptions
* thrown if something goes wrong. This will help to find the problem easier.
* @param targetType is the {@link GenericType} to convert the {@code value} to. It is potentially generic
* and therefore contains more detailed information than a {@link Class}. E.g. the {@code targetType}
* could be <code>java.util.List&lt;Long&gt;</code>. This could help e.g. if the {@code value} is a
* string like {@code "2, 47, 4252525"}.
* @return the converted {@code value} or {@code null} if the conversion is NOT possible. The returned value
* has to be an {@link Class#isInstance(Object) instance} of the given {@code targetType}.
* @param valueSource describes the source of the value. This may be the filename where the value was read from, an
* XPath where the value was located in an XML document, etc. It is used in exceptions thrown if something goes
* wrong. This will help to find the problem easier.
* @param targetType is the {@link GenericType} to convert the {@code value} to. It is potentially generic and
* therefore contains more detailed information than a {@link Class}. E.g. the {@code targetType} could be
* <code>java.util.List&lt;Long&gt;</code>. This could help e.g. if the {@code value} is a string like
* {@code "2, 47, 4252525"}.
* @return the converted {@code value} or {@code null} if the conversion is NOT possible. The returned value has to be
* an {@link Class#isInstance(Object) instance} of the given {@code targetType}.
* @throws ValueException if the conversion failed (e.g. the given {@code value} is illegal for the given
* {@code targetClass}).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void testGetByPackage() {
/**
* @param clazz the {@link Class} to test via {@link ClasspathScanner}.
*/
@SuppressWarnings({ "unchecked", "rawtypes" }) // Workaround for bug in Eclipse compiler
protected void checkClass(Class<?> clazz) {

ClasspathScanner scanner = getClasspathScanner();
Expand All @@ -135,8 +136,7 @@ protected void checkClass(Class<?> clazz) {
assertThat(packageResource.isData()).isFalse();
assertThat(packageResource.getPath()).isEqualTo(clazz.getPackage().getName().replace('.', '/'));
assertThat(packageResource.isAvailable()).isFalse();
assertThat(packageResource.getChildResources()).contains(scanner.getClasspathResource(clazz.getName().replace('.', '/') + ".class"));

assertThat((Iterable) packageResource.getChildResources()).contains(scanner.getClasspathResource(clazz.getName().replace('.', '/') + ".class"));
}

/** Test of {@link ClasspathScanner#getClasspathResourceFiles()}. */
Expand All @@ -149,7 +149,8 @@ public void testClasspathScanner() {
Iterable<? extends BrowsableResource> files = scanner.getClasspathResourceFiles();
// then
assertThat(files).isInstanceOf(List.class);
List<? extends BrowsableResource> fileList = (List<? extends BrowsableResource>) files;
@SuppressWarnings("unchecked") // Workaround for bug in Eclipse compiler
List<BrowsableResource> fileList = (List<BrowsableResource>) files;
assertThat(fileList.size()).isBetween(Integer.valueOf(600), Integer.valueOf(1200));
assertThat(fileList).contains(scanner.getClasspathResource(CLASSPATH_HYPHENATION_XML), scanner.getClasspathResource(CLASSPATH_NLS_BUNDLES));
}
Expand Down
3 changes: 0 additions & 3 deletions io/src/test/java/net/sf/mmm/util/io/base/StreamUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ public int read() throws IOException {
transferrer.get();
fail("expected " + ExecutionException.class);
} catch (ExecutionException e) {
if (error != e.getCause()) {
e.printStackTrace();
}
ExceptionHelper.assertCause(e, error);
}
assertThat(outStream.size()).isZero();
Expand Down

0 comments on commit 4f65943

Please sign in to comment.