#33 Fixing CheckStyle issues

This commit is contained in:
Gunnar Morling 2013-06-01 18:09:03 +02:00
parent 42ac8f3f1a
commit fd286e17ab
28 changed files with 103 additions and 54 deletions

View File

@ -25,7 +25,10 @@ package org.mapstruct;
*/ */
public class Mappers { public class Mappers {
private final static String IMPLEMENTATION_SUFFIX = "Impl"; private static final String IMPLEMENTATION_SUFFIX = "Impl";
private Mappers() {
}
/** /**
* Returns an instance of the given mapper type. * Returns an instance of the given mapper type.

View File

@ -18,12 +18,16 @@
*/ */
package org.mapstruct; package org.mapstruct;
import org.mapstruct.test.model.Foo; import org.mapstruct.test.model.Foo;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Assertions.assertThat;
/**
* Unit test for {@link Mappers}.
*
* @author Gunnar Morling
*/
public class MappersTest { public class MappersTest {
@Test @Test

View File

@ -26,7 +26,7 @@ import org.mapstruct.Mappings;
@Mapper @Mapper
public interface SourceTargetMapper { public interface SourceTargetMapper {
public static SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
@Mappings({ @Mappings({
@Mapping(source = "qax", target = "baz"), @Mapping(source = "qax", target = "baz"),

View File

@ -62,7 +62,7 @@ import static javax.lang.model.util.ElementFilter.methodsIn;
public class MapperGenerationVisitor extends ElementKindVisitor6<Void, Void> { public class MapperGenerationVisitor extends ElementKindVisitor6<Void, Void> {
private final static String IMPLEMENTATION_SUFFIX = "Impl"; private static final String IMPLEMENTATION_SUFFIX = "Impl";
private final ProcessingEnvironment processingEnvironment; private final ProcessingEnvironment processingEnvironment;
private final Types typeUtils; private final Types typeUtils;
@ -235,7 +235,9 @@ public class MapperGenerationVisitor extends ElementKindVisitor6<Void, Void> {
return mappings; return mappings;
} }
private void reportErrorIfPropertyCanNotBeMapped(Method method, Method reverseMethod, MappedProperty property, Method propertyMappingMethod, Method reversePropertyMappingMethod, Conversion conversion) { private void reportErrorIfPropertyCanNotBeMapped(Method method, Method reverseMethod, MappedProperty property,
Method propertyMappingMethod, Method reversePropertyMappingMethod,
Conversion conversion) {
if ( property.getSourceType().equals( property.getTargetType() ) ) { if ( property.getSourceType().equals( property.getTargetType() ) ) {
return; return;
} }
@ -282,7 +284,8 @@ public class MapperGenerationVisitor extends ElementKindVisitor6<Void, Void> {
} }
} }
private String getIterableConversionString(Conversions conversions, Type sourceElementType, Type targetElementType, boolean isToConversion) { private String getIterableConversionString(Conversions conversions, Type sourceElementType, Type targetElementType,
boolean isToConversion) {
Conversion conversion = conversions.getConversion( sourceElementType, targetElementType ); Conversion conversion = conversions.getConversion( sourceElementType, targetElementType );
if ( conversion == null ) { if ( conversion == null ) {
@ -435,7 +438,8 @@ public class MapperGenerationVisitor extends ElementKindVisitor6<Void, Void> {
String sourcePropertyName = Executables.getPropertyName( getterMethod ); String sourcePropertyName = Executables.getPropertyName( getterMethod );
Mapping mapping = mappings.get( sourcePropertyName ); Mapping mapping = mappings.get( sourcePropertyName );
for ( ExecutableElement setterMethod : Filters.setterMethodsIn( returnTypeElement.getEnclosedElements() ) ) { for ( ExecutableElement setterMethod :Filters.setterMethodsIn( returnTypeElement
.getEnclosedElements() ) ) {
String targetPropertyName = Executables.getPropertyName( setterMethod ); String targetPropertyName = Executables.getPropertyName( setterMethod );

View File

@ -43,6 +43,7 @@ public class PrimitiveToStringConversion implements Conversion {
@Override @Override
public String from(String targetPropertyAccessor, Type type) { public String from(String targetPropertyAccessor, Type type) {
return wrapperType.getSimpleName() + ".parse" + Strings.capitalize( sourceType.getSimpleName() ) + "( " + targetPropertyAccessor + " )"; return wrapperType.getSimpleName() + ".parse" + Strings.capitalize( sourceType.getSimpleName() ) + "( " +
targetPropertyAccessor + " )";
} }
} }

View File

@ -43,6 +43,7 @@ public class WrapperToStringConversion implements Conversion {
@Override @Override
public String from(String targetPropertyAccessor, Type type) { public String from(String targetPropertyAccessor, Type type) {
return sourceType.getSimpleName() + ".parse" + Strings.capitalize( primitiveType.getSimpleName() ) + "( " + targetPropertyAccessor + " )"; return sourceType.getSimpleName() + ".parse" + Strings.capitalize( primitiveType.getSimpleName() ) + "( " +
targetPropertyAccessor + " )";
} }
} }

View File

@ -31,7 +31,8 @@ public class BeanMapping {
private final String toConversion; private final String toConversion;
private final String fromConversion; private final String fromConversion;
public BeanMapping(Type sourceType, Type targetType, List<PropertyMapping> propertyMappings, MappingMethod mappingMethod, public BeanMapping(Type sourceType, Type targetType, List<PropertyMapping> propertyMappings,
MappingMethod mappingMethod,
MappingMethod reverseMappingMethod, String toConversion, String fromConversion) { MappingMethod reverseMappingMethod, String toConversion, String fromConversion) {
this.sourceType = sourceType; this.sourceType = sourceType;
this.targetType = targetType; this.targetType = targetType;

View File

@ -35,7 +35,8 @@ public class Mapper {
private final SortedSet<Type> importedTypes; private final SortedSet<Type> importedTypes;
public Mapper(String packageName, String interfaceName, public Mapper(String packageName, String interfaceName,
String implementationName, List<BeanMapping> beanMappings, List<Type> usedMapperTypes, Options options) { String implementationName, List<BeanMapping> beanMappings, List<Type> usedMapperTypes,
Options options) {
this.packageName = packageName; this.packageName = packageName;
this.interfaceName = interfaceName; this.interfaceName = interfaceName;
this.implementationName = implementationName; this.implementationName = implementationName;

View File

@ -40,7 +40,10 @@ public class PropertyMapping {
private final String toConversion; private final String toConversion;
private final String fromConversion; private final String fromConversion;
public PropertyMapping(String sourceReadAccessorName, String sourceWriteAccessorName, Type sourceType, String targetReadAccessorName, String targetWriteAccessorName, Type targetType, MappingMethod mappingMethod, MappingMethod reverseMappingMethod, String toConversion, String fromConversion) { public PropertyMapping(String sourceReadAccessorName, String sourceWriteAccessorName, Type sourceType,
String targetReadAccessorName, String targetWriteAccessorName, Type targetType,
MappingMethod mappingMethod, MappingMethod reverseMappingMethod, String toConversion,
String fromConversion) {
this.sourceReadAccessorName = sourceReadAccessorName; this.sourceReadAccessorName = sourceReadAccessorName;
this.sourceWriteAccessorName = sourceWriteAccessorName; this.sourceWriteAccessorName = sourceWriteAccessorName;
this.sourceType = sourceType; this.sourceType = sourceType;

View File

@ -34,20 +34,22 @@ import java.util.concurrent.ConcurrentMap;
*/ */
public class Type implements Comparable<Type> { public class Type implements Comparable<Type> {
private final static Set<String> primitiveTypeNames = new HashSet<String>( private static final Set<String> PRIMITIVE_TYPE_NAMES = new HashSet<String>(
Arrays.asList( "boolean", "char", "byte", "short", "int", "long", "float", "double" ) Arrays.asList( "boolean", "char", "byte", "short", "int", "long", "float", "double" )
); );
private final static ConcurrentMap<String, Type> defaultIterableImplementationTypes = new ConcurrentHashMap<String, Type>(); private static final ConcurrentMap<String, Type> DEFAULT_ITERABLE_IMPLEMENTATION_TYPES =
private final static ConcurrentMap<String, Type> defaultCollectionImplementationTypes = new ConcurrentHashMap<String, Type>(); new ConcurrentHashMap<String, Type>();
private static final ConcurrentMap<String, Type> DEFAULT_COLLECTION_IMPLEMENTATION_TYPES =
new ConcurrentHashMap<String, Type>();
static { static {
defaultCollectionImplementationTypes.put( List.class.getName(), forClass( ArrayList.class ) ); DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( List.class.getName(), forClass( ArrayList.class ) );
defaultCollectionImplementationTypes.put( Set.class.getName(), forClass( HashSet.class ) ); DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( Set.class.getName(), forClass( HashSet.class ) );
defaultCollectionImplementationTypes.put( Collection.class.getName(), forClass( ArrayList.class ) ); DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.put( Collection.class.getName(), forClass( ArrayList.class ) );
defaultIterableImplementationTypes.put( Iterable.class.getName(), forClass( ArrayList.class ) ); DEFAULT_ITERABLE_IMPLEMENTATION_TYPES.put( Iterable.class.getName(), forClass( ArrayList.class ) );
defaultIterableImplementationTypes.putAll( defaultCollectionImplementationTypes ); DEFAULT_ITERABLE_IMPLEMENTATION_TYPES.putAll( DEFAULT_COLLECTION_IMPLEMENTATION_TYPES );
} }
private final String packageName; private final String packageName;
@ -81,7 +83,8 @@ public class Type implements Comparable<Type> {
this( null, name, null, false, false, false ); this( null, name, null, false, false, false );
} }
public Type(String packageName, String name, Type elementType, boolean isEnumType, boolean isCollectionType, boolean isIterableType) { public Type(String packageName, String name, Type elementType, boolean isEnumType, boolean isCollectionType,
boolean isIterableType) {
this.packageName = packageName; this.packageName = packageName;
this.name = name; this.name = name;
this.elementType = elementType; this.elementType = elementType;
@ -90,14 +93,14 @@ public class Type implements Comparable<Type> {
this.isIterableType = isIterableType; this.isIterableType = isIterableType;
if ( isCollectionType ) { if ( isCollectionType ) {
collectionImplementationType = defaultCollectionImplementationTypes.get( packageName + "." + name ); collectionImplementationType = DEFAULT_COLLECTION_IMPLEMENTATION_TYPES.get( packageName + "." + name );
} }
else { else {
collectionImplementationType = null; collectionImplementationType = null;
} }
if ( isIterableType ) { if ( isIterableType ) {
iterableImplementationType = defaultIterableImplementationTypes.get( packageName + "." + name ); iterableImplementationType = DEFAULT_ITERABLE_IMPLEMENTATION_TYPES.get( packageName + "." + name );
} }
else { else {
iterableImplementationType = null; iterableImplementationType = null;
@ -117,7 +120,7 @@ public class Type implements Comparable<Type> {
} }
public boolean isPrimitive() { public boolean isPrimitive() {
return packageName == null && primitiveTypeNames.contains( name ); return packageName == null && PRIMITIVE_TYPE_NAMES.contains( name );
} }
public boolean isEnumType() { public boolean isEnumType() {

View File

@ -32,7 +32,8 @@ public class MappedProperty {
private final Type targetType; private final Type targetType;
public MappedProperty(String sourceName, String sourceReadAccessorName, String sourceWriteAccessorName, public MappedProperty(String sourceName, String sourceReadAccessorName, String sourceWriteAccessorName,
Type sourceType, String targetName, String targetReadAccessorName, String targetWriteAccessorName, Type sourceType, String targetName, String targetReadAccessorName,
String targetWriteAccessorName,
Type targetType) { Type targetType) {
this.sourceName = sourceName; this.sourceName = sourceName;
this.sourceReadAccessorName = sourceReadAccessorName; this.sourceReadAccessorName = sourceReadAccessorName;

View File

@ -33,7 +33,8 @@ public class Method {
private final Type targetType; private final Type targetType;
private final List<MappedProperty> mappedProperties; private final List<MappedProperty> mappedProperties;
public Method(Type declaringMapper, ExecutableElement executable, String parameterName, Type sourceType, Type targetType, List<MappedProperty> mappedProperties) { public Method(Type declaringMapper, ExecutableElement executable, String parameterName, Type sourceType,
Type targetType, List<MappedProperty> mappedProperties) {
this.declaringMapper = declaringMapper; this.declaringMapper = declaringMapper;
this.executable = executable; this.executable = executable;
this.parameterName = parameterName; this.parameterName = parameterName;

View File

@ -30,6 +30,9 @@ import javax.lang.model.type.TypeKind;
*/ */
public class Executables { public class Executables {
private Executables() {
}
public static boolean isGetterMethod(ExecutableElement method) { public static boolean isGetterMethod(ExecutableElement method) {
return isNonBooleanGetterMethod( method ) || isBooleanGetterMethod( method ); return isNonBooleanGetterMethod( method ) || isBooleanGetterMethod( method );
} }

View File

@ -32,6 +32,9 @@ import static javax.lang.model.util.ElementFilter.methodsIn;
*/ */
public class Filters { public class Filters {
private Filters() {
}
public static List<ExecutableElement> getterMethodsIn(Iterable<? extends Element> elements) { public static List<ExecutableElement> getterMethodsIn(Iterable<? extends Element> elements) {
List<ExecutableElement> getterMethods = new LinkedList<ExecutableElement>(); List<ExecutableElement> getterMethods = new LinkedList<ExecutableElement>();

View File

@ -30,8 +30,11 @@ import java.util.Map;
*/ */
public class NativeTypes { public class NativeTypes {
private final static Map<Class<?>, Class<?>> wrapperToPrimitiveTypes; private static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE_TYPES;
private final static Map<Class<?>, Class<?>> primitiveToWrapperTypes; private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_TYPES;
private NativeTypes() {
}
static { static {
Map<Class<?>, Class<?>> tmp = new HashMap<Class<?>, Class<?>>(); Map<Class<?>, Class<?>> tmp = new HashMap<Class<?>, Class<?>>();
@ -44,7 +47,7 @@ public class NativeTypes {
tmp.put( Boolean.class, boolean.class ); tmp.put( Boolean.class, boolean.class );
tmp.put( Character.class, char.class ); tmp.put( Character.class, char.class );
wrapperToPrimitiveTypes = Collections.unmodifiableMap( tmp ); WRAPPER_TO_PRIMITIVE_TYPES = Collections.unmodifiableMap( tmp );
tmp = new HashMap<Class<?>, Class<?>>(); tmp = new HashMap<Class<?>, Class<?>>();
tmp.put( byte.class, Byte.class ); tmp.put( byte.class, Byte.class );
@ -56,7 +59,7 @@ public class NativeTypes {
tmp.put( boolean.class, Boolean.class ); tmp.put( boolean.class, Boolean.class );
tmp.put( char.class, Character.class ); tmp.put( char.class, Character.class );
primitiveToWrapperTypes = Collections.unmodifiableMap( tmp ); PRIMITIVE_TO_WRAPPER_TYPES = Collections.unmodifiableMap( tmp );
} }
public static Class<?> getWrapperType(Class<?> clazz) { public static Class<?> getWrapperType(Class<?> clazz) {
@ -64,7 +67,7 @@ public class NativeTypes {
throw new IllegalArgumentException( clazz + " is no primitive type." ); throw new IllegalArgumentException( clazz + " is no primitive type." );
} }
return primitiveToWrapperTypes.get( clazz ); return PRIMITIVE_TO_WRAPPER_TYPES.get( clazz );
} }
public static Class<?> getPrimitiveType(Class<?> clazz) { public static Class<?> getPrimitiveType(Class<?> clazz) {
@ -72,6 +75,6 @@ public class NativeTypes {
throw new IllegalArgumentException( clazz + " is no wrapper type." ); throw new IllegalArgumentException( clazz + " is no wrapper type." );
} }
return wrapperToPrimitiveTypes.get( clazz ); return WRAPPER_TO_PRIMITIVE_TYPES.get( clazz );
} }
} }

View File

@ -20,8 +20,10 @@ package org.mapstruct.ap.util;
public class Strings { public class Strings {
private Strings() {
}
public static String capitalize(String name) { public static String capitalize(String name) {
return name == null ? null : name.substring( 0, 1 ).toUpperCase() + name.substring( 1 ); return name == null ? null : name.substring( 0, 1 ).toUpperCase() + name.substring( 1 );
} }
} }

View File

@ -25,16 +25,26 @@ import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper; import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template; import freemarker.template.Template;
/**
* Writes Java source files based on given mapper models, using a FreeMarker
* template.
*
* @author Gunnar Morling
*/
public class ModelWriter { public class ModelWriter {
private static final Configuration configuration; /**
* FreeMarker configuration. As per the documentation, thread-safe if not
* altered after original initialization
*/
private static final Configuration CONFIGURATION;
private final String templateName; private final String templateName;
static { static {
configuration = new Configuration(); CONFIGURATION = new Configuration();
configuration.setClassForTemplateLoading( ModelWriter.class, "/" ); CONFIGURATION.setClassForTemplateLoading( ModelWriter.class, "/" );
configuration.setObjectWrapper( new DefaultObjectWrapper() ); CONFIGURATION.setObjectWrapper( new DefaultObjectWrapper() );
} }
public ModelWriter(String templateName) { public ModelWriter(String templateName) {
@ -46,7 +56,7 @@ public class ModelWriter {
try { try {
BufferedWriter writer = new BufferedWriter( sourceFile.openWriter() ); BufferedWriter writer = new BufferedWriter( sourceFile.openWriter() );
Template template = configuration.getTemplate( templateName ); Template template = CONFIGURATION.getTemplate( templateName );
template.process( model, writer ); template.process( model, writer );
writer.flush(); writer.flush();
writer.close(); writer.close();

View File

@ -28,7 +28,7 @@ import org.mapstruct.Mappings;
@Mapper @Mapper
public interface SourceTargetMapper { public interface SourceTargetMapper {
public static SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
@Mappings({ @Mappings({
@Mapping(source = "integerList", target = "integerCollection"), @Mapping(source = "integerList", target = "integerCollection"),

View File

@ -28,7 +28,7 @@ import org.mapstruct.Mappers;
@Mapper @Mapper
public interface SourceTargetMapper { public interface SourceTargetMapper {
public static SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
Target sourceToTarget(Source source); Target sourceToTarget(Source source);

View File

@ -24,7 +24,7 @@ import org.mapstruct.Mappers;
@Mapper(uses = StringListMapper.class) @Mapper(uses = StringListMapper.class)
public interface SourceTargetMapper { public interface SourceTargetMapper {
public static SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
Target sourceToTarget(Source source); Target sourceToTarget(Source source);

View File

@ -26,7 +26,7 @@ import org.mapstruct.Mappings;
@Mapper @Mapper
public interface SourceTargetMapper { public interface SourceTargetMapper {
public static SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
@Mappings({ @Mappings({
@Mapping(source = "qax", target = "baz"), @Mapping(source = "qax", target = "baz"),

View File

@ -24,7 +24,7 @@ import org.mapstruct.Mappers;
@Mapper @Mapper
public interface BooleanMapper { public interface BooleanMapper {
public static BooleanMapper INSTANCE = Mappers.getMapper( BooleanMapper.class ); BooleanMapper INSTANCE = Mappers.getMapper( BooleanMapper.class );
BooleanTarget sourceToTarget(BooleanSource source); BooleanTarget sourceToTarget(BooleanSource source);

View File

@ -24,7 +24,7 @@ import org.mapstruct.Mappers;
@Mapper @Mapper
public interface CharMapper { public interface CharMapper {
public static CharMapper INSTANCE = Mappers.getMapper( CharMapper.class ); CharMapper INSTANCE = Mappers.getMapper( CharMapper.class );
CharTarget sourceToTarget(CharSource source); CharTarget sourceToTarget(CharSource source);

View File

@ -24,7 +24,7 @@ import org.mapstruct.Mappers;
@Mapper @Mapper
public interface SourceTargetMapper { public interface SourceTargetMapper {
public static SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
ByteTarget sourceToTarget(ByteSource source); ByteTarget sourceToTarget(ByteSource source);

View File

@ -24,7 +24,7 @@ import org.mapstruct.Mappers;
@Mapper(uses = IntegerStringMapper.class) @Mapper(uses = IntegerStringMapper.class)
public interface SourceTargetMapper { public interface SourceTargetMapper {
public static SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
Target sourceToTarget(Source source); Target sourceToTarget(Source source);

View File

@ -24,7 +24,7 @@ import org.mapstruct.Mappers;
@Mapper @Mapper
public interface SourceTargetMapper { public interface SourceTargetMapper {
public static SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class );
Target sourceToTarget(Source source); Target sourceToTarget(Source source);

View File

@ -22,11 +22,11 @@ import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.tools.Diagnostic;
import javax.tools.Diagnostic.Kind; import javax.tools.Diagnostic.Kind;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult;
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
/** /**
@ -45,7 +45,8 @@ public class CompilationOutcomeDescriptor {
this.diagnostics = diagnostics; this.diagnostics = diagnostics;
} }
public static CompilationOutcomeDescriptor forExpectedCompilationResult(ExpectedCompilationOutcome expectedCompilationResult) { public static CompilationOutcomeDescriptor forExpectedCompilationResult(
ExpectedCompilationOutcome expectedCompilationResult) {
if ( expectedCompilationResult == null ) { if ( expectedCompilationResult == null ) {
return new CompilationOutcomeDescriptor( return new CompilationOutcomeDescriptor(
CompilationResult.SUCCEEDED, CompilationResult.SUCCEEDED,
@ -54,7 +55,8 @@ public class CompilationOutcomeDescriptor {
} }
else { else {
Set<DiagnosticDescriptor> diagnosticDescriptors = new HashSet<DiagnosticDescriptor>(); Set<DiagnosticDescriptor> diagnosticDescriptors = new HashSet<DiagnosticDescriptor>();
for ( Diagnostic diagnostic : expectedCompilationResult.diagnostics() ) { for ( org.mapstruct.ap.testutil.compilation.annotation.Diagnostic diagnostic :
expectedCompilationResult.diagnostics() ) {
diagnosticDescriptors.add( DiagnosticDescriptor.forDiagnostic( diagnostic ) ); diagnosticDescriptors.add( DiagnosticDescriptor.forDiagnostic( diagnostic ) );
} }
@ -62,11 +64,13 @@ public class CompilationOutcomeDescriptor {
} }
} }
public static CompilationOutcomeDescriptor forResult(String sourceDir, boolean compilationSuccessful, List<javax.tools.Diagnostic<? extends JavaFileObject>> diagnostics) { public static CompilationOutcomeDescriptor forResult(String sourceDir, boolean compilationSuccessful,
CompilationResult compilationResult = compilationSuccessful ? CompilationResult.SUCCEEDED : CompilationResult.FAILED; List<Diagnostic<? extends JavaFileObject>> diagnostics) {
CompilationResult compilationResult =
compilationSuccessful ? CompilationResult.SUCCEEDED : CompilationResult.FAILED;
Set<DiagnosticDescriptor> diagnosticDescriptors = new HashSet<DiagnosticDescriptor>(); Set<DiagnosticDescriptor> diagnosticDescriptors = new HashSet<DiagnosticDescriptor>();
for ( javax.tools.Diagnostic<? extends JavaFileObject> diagnostic : diagnostics ) { for ( Diagnostic<? extends JavaFileObject> diagnostic : diagnostics ) {
//ignore notes created by the compiler //ignore notes created by the compiler
if ( diagnostic.getKind() != Kind.NOTE ) { if ( diagnostic.getKind() != Kind.NOTE ) {
diagnosticDescriptors.add( DiagnosticDescriptor.forDiagnostic( sourceDir, diagnostic ) ); diagnosticDescriptors.add( DiagnosticDescriptor.forDiagnostic( sourceDir, diagnostic ) );

View File

@ -49,7 +49,8 @@ public class DiagnosticDescriptor {
return new DiagnosticDescriptor( soureFileName, diagnostic.kind(), diagnostic.line(), "" ); return new DiagnosticDescriptor( soureFileName, diagnostic.kind(), diagnostic.line(), "" );
} }
public static DiagnosticDescriptor forDiagnostic(String sourceDir, javax.tools.Diagnostic<? extends JavaFileObject> diagnostic) { public static DiagnosticDescriptor forDiagnostic(String sourceDir,
javax.tools.Diagnostic<? extends JavaFileObject> diagnostic) {
return new DiagnosticDescriptor( return new DiagnosticDescriptor(
getSourceName( sourceDir, diagnostic ), getSourceName( sourceDir, diagnostic ),
diagnostic.getKind(), diagnostic.getKind(),