mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#1633 Add support for an alternative line in the diagnostics report
* This should be used as a last resort when the compilers report the diagnostic on a wrong line * The NullValuePropertyMappingTest uses repeatable annotations that reports errors on wrong lines in javac JDK-8042710
This commit is contained in:
parent
288813fc3c
commit
2acbe0f5e8
@ -8,7 +8,6 @@ package org.mapstruct.ap.test.nullvaluepropertymapping;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
@ -104,7 +103,6 @@ public class NullValuePropertyMappingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // test gives different results for JDK and JDT
|
||||
@WithClasses(ErroneousCustomerMapper1.class)
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
@ -112,6 +110,7 @@ public class NullValuePropertyMappingTest {
|
||||
@Diagnostic(type = ErroneousCustomerMapper1.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 20,
|
||||
alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710
|
||||
messageRegExp = "Default value and nullValuePropertyMappingStrategy are both defined in @Mapping, " +
|
||||
"either define a defaultValue or an nullValuePropertyMappingStrategy.")
|
||||
}
|
||||
@ -120,7 +119,6 @@ public class NullValuePropertyMappingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // test gives different results for JDK and JDT
|
||||
@WithClasses(ErroneousCustomerMapper2.class)
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
@ -128,6 +126,7 @@ public class NullValuePropertyMappingTest {
|
||||
@Diagnostic(type = ErroneousCustomerMapper2.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 20,
|
||||
alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710
|
||||
messageRegExp = "Expression and nullValuePropertyMappingStrategy are both defined in @Mapping, " +
|
||||
"either define an expression or an nullValuePropertyMappingStrategy.")
|
||||
}
|
||||
@ -136,7 +135,6 @@ public class NullValuePropertyMappingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // test gives different results for JDK and JDT
|
||||
@WithClasses(ErroneousCustomerMapper3.class)
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
@ -144,6 +142,7 @@ public class NullValuePropertyMappingTest {
|
||||
@Diagnostic(type = ErroneousCustomerMapper3.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 20,
|
||||
alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710
|
||||
messageRegExp = "DefaultExpression and nullValuePropertyMappingStrategy are both defined in " +
|
||||
"@Mapping, either define a defaultExpression or an nullValuePropertyMappingStrategy.")
|
||||
}
|
||||
@ -152,7 +151,6 @@ public class NullValuePropertyMappingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // test gives different results for JDK and JDT
|
||||
@WithClasses(ErroneousCustomerMapper4.class)
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
@ -160,6 +158,7 @@ public class NullValuePropertyMappingTest {
|
||||
@Diagnostic(type = ErroneousCustomerMapper4.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 20,
|
||||
alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710
|
||||
messageRegExp = "Constant and nullValuePropertyMappingStrategy are both defined in @Mapping, " +
|
||||
"either define a constant or an nullValuePropertyMappingStrategy.")
|
||||
}
|
||||
@ -168,7 +167,6 @@ public class NullValuePropertyMappingTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // test gives different results for JDK and JDT
|
||||
@WithClasses(ErroneousCustomerMapper5.class)
|
||||
@ExpectedCompilationOutcome(
|
||||
value = CompilationResult.FAILED,
|
||||
@ -176,6 +174,7 @@ public class NullValuePropertyMappingTest {
|
||||
@Diagnostic(type = ErroneousCustomerMapper5.class,
|
||||
kind = javax.tools.Diagnostic.Kind.ERROR,
|
||||
line = 20,
|
||||
alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710
|
||||
messageRegExp = "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, " +
|
||||
"either define ignore or an nullValuePropertyMappingStrategy.")
|
||||
}
|
||||
|
@ -35,6 +35,16 @@ public @interface Diagnostic {
|
||||
*/
|
||||
long line() default -1;
|
||||
|
||||
/**
|
||||
* In case compilers report diagnostics on different lines this can be used as the alternative expected line number
|
||||
* of the diagnostic.
|
||||
* <p>
|
||||
* This should be used as a last resort when the compilers report the diagnostic on a wrong line.
|
||||
*
|
||||
* @return The alternative line number of the diagnostic.
|
||||
*/
|
||||
long alternativeLine() default -1;
|
||||
|
||||
/**
|
||||
* A regular expression matching the expected message of the diagnostic.
|
||||
* Wild-cards matching any character (".*") will be added to the beginning
|
||||
|
@ -26,12 +26,18 @@ public class DiagnosticDescriptor {
|
||||
private final String sourceFileName;
|
||||
private final Kind kind;
|
||||
private final Long line;
|
||||
private final Long alternativeLine;
|
||||
private final String message;
|
||||
|
||||
private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, String message) {
|
||||
this( sourceFileName, kind, line, null, message );
|
||||
}
|
||||
|
||||
private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, Long alternativeLine, String message) {
|
||||
this.sourceFileName = sourceFileName;
|
||||
this.kind = kind;
|
||||
this.line = line;
|
||||
this.alternativeLine = alternativeLine;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@ -43,6 +49,7 @@ public class DiagnosticDescriptor {
|
||||
soureFileName,
|
||||
diagnostic.kind(),
|
||||
diagnostic.line() != -1 ? diagnostic.line() : null,
|
||||
diagnostic.alternativeLine() != -1 ? diagnostic.alternativeLine() : null,
|
||||
diagnostic.messageRegExp()
|
||||
);
|
||||
}
|
||||
@ -135,6 +142,10 @@ public class DiagnosticDescriptor {
|
||||
return line;
|
||||
}
|
||||
|
||||
public Long getAlternativeLine() {
|
||||
return alternativeLine;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
@ -269,7 +269,10 @@ abstract class CompilingStatement extends Statement {
|
||||
if ( expected.getSourceFileName() != null ) {
|
||||
assertThat( actual.getSourceFileName() ).isEqualTo( expected.getSourceFileName() );
|
||||
}
|
||||
if ( expected.getLine() != null ) {
|
||||
if ( expected.getLine() != null && expected.getAlternativeLine() != null ) {
|
||||
assertThat( actual.getLine() ).isIn( expected.getLine(), expected.getAlternativeLine() );
|
||||
}
|
||||
else if ( expected.getLine() != null ) {
|
||||
assertThat( actual.getLine() ).isEqualTo( expected.getLine() );
|
||||
}
|
||||
assertThat( actual.getKind() ).isEqualTo( expected.getKind() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user