mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#252 Formatting
This commit is contained in:
parent
32eeceb0cf
commit
4d408d5560
@ -25,7 +25,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
@ -406,12 +405,12 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private SourceMethod getReverseMappingMethod(List<SourceMethod> rawMethods, SourceMethod method) {
|
||||
|
||||
SourceMethod result = null;
|
||||
InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn(
|
||||
method.getExecutable()
|
||||
);
|
||||
|
||||
InheritInverseConfigurationPrism reversePrism = InheritInverseConfigurationPrism.getInstanceOn( method.getExecutable() );
|
||||
if ( reversePrism != null ) {
|
||||
|
||||
// method is configured as being reverse method, collect candidates
|
||||
@ -458,25 +457,32 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
}
|
||||
|
||||
if ( result != null ) {
|
||||
reportErrorIfForwardMethodHasInheritInverseConfigurationAnnotation( result, method, reversePrism );
|
||||
reportErrorIfInverseMethodHasInheritAnnotation( result, method, reversePrism );
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void reportErrorIfForwardMethodHasInheritInverseConfigurationAnnotation( SourceMethod candidate,
|
||||
SourceMethod method, InheritInverseConfigurationPrism reversePrism ) {
|
||||
private void reportErrorIfInverseMethodHasInheritAnnotation(SourceMethod candidate,
|
||||
SourceMethod method,
|
||||
InheritInverseConfigurationPrism reversePrism) {
|
||||
|
||||
InheritInverseConfigurationPrism candidatePrism = InheritInverseConfigurationPrism.getInstanceOn(
|
||||
candidate.getExecutable()
|
||||
);
|
||||
|
||||
InheritInverseConfigurationPrism candidatePrism = InheritInverseConfigurationPrism.getInstanceOn( candidate.getExecutable() );
|
||||
if ( candidatePrism != null ) {
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "Resolved inverse mapping method %s() should not carry the "
|
||||
messager.printMessage(
|
||||
Diagnostic.Kind.ERROR,
|
||||
String.format(
|
||||
"Resolved inverse mapping method %s() should not carry the "
|
||||
+ "@InheritInverseConfiguration annotation itself.",
|
||||
candidate.getName()
|
||||
),
|
||||
method.getExecutable(),
|
||||
reversePrism.mirror );
|
||||
reversePrism.mirror
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -490,42 +496,54 @@ public class MapperCreationProcessor implements ModelElementProcessor<List<Sourc
|
||||
|
||||
String name = reversePrism.name();
|
||||
if ( name.isEmpty() ) {
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "Several matching inverse methods exist: %s(). Specify a name explicitly.",
|
||||
messager.printMessage(
|
||||
Diagnostic.Kind.ERROR,
|
||||
String.format(
|
||||
"Several matching inverse methods exist: %s(). Specify a name explicitly.",
|
||||
Strings.join( candidateNames, "(), " )
|
||||
),
|
||||
method.getExecutable(),
|
||||
reversePrism.mirror );
|
||||
reversePrism.mirror
|
||||
);
|
||||
}
|
||||
else {
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "None of the candidates %s() matches given name: \"%s\".",
|
||||
messager.printMessage(
|
||||
Diagnostic.Kind.ERROR,
|
||||
String.format(
|
||||
"None of the candidates %s() matches given name: \"%s\".",
|
||||
Strings.join( candidateNames, "(), " ), name
|
||||
),
|
||||
method.getExecutable(),
|
||||
reversePrism.mirror );
|
||||
reversePrism.mirror
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void reportErrorWhenSeveralNamesMatch(List<SourceMethod> candidates, SourceMethod method,
|
||||
InheritInverseConfigurationPrism reversePrism) {
|
||||
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "Given name \"%s\" matches several candidate methods: %s().",
|
||||
messager.printMessage(
|
||||
Diagnostic.Kind.ERROR,
|
||||
String.format(
|
||||
"Given name \"%s\" matches several candidate methods: %s().",
|
||||
reversePrism.name(), Strings.join( candidates, "(), " )
|
||||
),
|
||||
method.getExecutable(),
|
||||
reversePrism.mirror );
|
||||
reversePrism.mirror
|
||||
);
|
||||
}
|
||||
|
||||
private void reportErrorWhenNonMatchingName(SourceMethod onlyCandidate, SourceMethod method,
|
||||
InheritInverseConfigurationPrism reversePrism) {
|
||||
|
||||
messager.printMessage( Diagnostic.Kind.ERROR,
|
||||
String.format( "Given name \"%s\" does not match the only candidate. Did you mean: \"%s\".",
|
||||
messager.printMessage(
|
||||
Diagnostic.Kind.ERROR,
|
||||
String.format(
|
||||
"Given name \"%s\" does not match the only candidate. Did you mean: \"%s\".",
|
||||
reversePrism.name(), onlyCandidate.getName()
|
||||
),
|
||||
method.getExecutable(),
|
||||
reversePrism.mirror );
|
||||
reversePrism.mirror
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,6 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
import org.junit.Test;
|
||||
@ -31,9 +29,10 @@ import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic;
|
||||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome;
|
||||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||
|
||||
import static org.fest.assertions.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Sjaak Derksen
|
||||
*
|
||||
*/
|
||||
@IssueKey("252")
|
||||
@WithClasses({ Source.class, Target.class })
|
||||
@ -70,12 +69,12 @@ public class InheritInverseConfigurationTest {
|
||||
diagnostics = {
|
||||
@Diagnostic(type = SourceTargetMapperAmbiguous1.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 51,
|
||||
line = 49,
|
||||
messageRegExp = "Several matching inverse methods exist: forward\\(\\), "
|
||||
+ "forwardNotToReverse\\(\\). Specify a name explicitly."),
|
||||
@Diagnostic(type = SourceTargetMapperAmbiguous1.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 56,
|
||||
line = 54,
|
||||
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"")
|
||||
}
|
||||
)
|
||||
@ -89,12 +88,12 @@ public class InheritInverseConfigurationTest {
|
||||
diagnostics = {
|
||||
@Diagnostic(type = SourceTargetMapperAmbiguous2.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 51,
|
||||
line = 49,
|
||||
messageRegExp = "None of the candidates forward\\(\\), forwardNotToReverse\\(\\) matches given "
|
||||
+ "name: \"blah\"."),
|
||||
@Diagnostic(type = SourceTargetMapperAmbiguous2.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 56,
|
||||
line = 54,
|
||||
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"")
|
||||
}
|
||||
)
|
||||
@ -108,12 +107,12 @@ public class InheritInverseConfigurationTest {
|
||||
diagnostics = {
|
||||
@Diagnostic(type = SourceTargetMapperAmbiguous3.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 52,
|
||||
line = 50,
|
||||
messageRegExp = "Given name \"forward\" matches several candidate methods: .*forward.*\\(\\), "
|
||||
+ ".*forward.*\\(\\)"),
|
||||
@Diagnostic(type = SourceTargetMapperAmbiguous3.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 57,
|
||||
line = 55,
|
||||
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"")
|
||||
}
|
||||
)
|
||||
@ -127,7 +126,7 @@ public class InheritInverseConfigurationTest {
|
||||
diagnostics = {
|
||||
@Diagnostic(type = SourceTargetMapperErroneouslyAnnotated.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 51,
|
||||
line = 49,
|
||||
messageRegExp = "Resolved inverse mapping method reverse\\(\\) should not carry the "
|
||||
+ "@InheritInverseConfiguration annotation itself.")
|
||||
}
|
||||
@ -142,12 +141,12 @@ public class InheritInverseConfigurationTest {
|
||||
diagnostics = {
|
||||
@Diagnostic(type = SourceTargetMapperNonMatchingName.class,
|
||||
kind = Kind.ERROR,
|
||||
line = 44,
|
||||
line = 42,
|
||||
messageRegExp = "Given name \"blah\" does not match the only candidate. Did you mean: "
|
||||
+ "\"forward\"."),
|
||||
@Diagnostic(type = SourceTargetMapperNonMatchingName.class,
|
||||
kind = Kind.WARNING,
|
||||
line = 49,
|
||||
line = 47,
|
||||
messageRegExp = "Unmapped target properties: \"stringPropX, integerPropX\"")
|
||||
}
|
||||
)
|
||||
|
@ -19,7 +19,6 @@
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Source {
|
||||
|
@ -25,10 +25,8 @@ import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SourceTargetMapper {
|
||||
|
||||
|
@ -18,17 +18,15 @@
|
||||
*/
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SourceTargetMapperAmbiguous1 {
|
||||
|
||||
|
@ -25,10 +25,8 @@ import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SourceTargetMapperAmbiguous2 {
|
||||
|
||||
|
@ -26,10 +26,8 @@ import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SourceTargetMapperAmbiguous3 {
|
||||
|
||||
|
@ -25,10 +25,8 @@ import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SourceTargetMapperErroneouslyAnnotated {
|
||||
|
||||
|
@ -25,10 +25,8 @@ import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface SourceTargetMapperNonMatchingName {
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
package org.mapstruct.ap.test.reverse;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sjaak Derksen
|
||||
*/
|
||||
public class Target {
|
||||
|
Loading…
x
Reference in New Issue
Block a user