Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@
public abstract class AbstractJctCompiler<A extends AbstractJctCompiler<A>>
implements JctCompiler<A, JctCompilationImpl> {

private final String name;
private final JavaCompiler jsr199Compiler;
private final JctFlagBuilder flagBuilder;
private final List<Processor> annotationProcessors;
private final List<String> annotationProcessorOptions;
private final List<String> compilerOptions;
private String name;
private boolean showWarnings;
private boolean showDeprecationWarnings;
private boolean failOnWarnings;
Expand All @@ -87,7 +87,7 @@ public abstract class AbstractJctCompiler<A extends AbstractJctCompiler<A>>
/**
* Initialize this compiler.
*
* @param name the friendly name of the compiler.
* @param name the friendly name of the compiler to default to.
* @param jsr199Compiler the JSR-199 compiler implementation to use.
* @param flagBuilder the flag builder to use.
*/
Expand Down Expand Up @@ -141,6 +141,17 @@ public final <E extends Exception> A configure(JctCompilerConfigurer<E> configur
return myself();
}

@Override
public String getName() {
return name;
}

@Override
public A name(String name) {
this.name = requireNonNull(name, "name");
return myself();
}

/**
* Get the flag builder to use.
*
Expand All @@ -159,15 +170,6 @@ public JavaCompiler getJsr199Compiler() {
return jsr199Compiler;
}

/**
* Get the friendly name of the compiler implementation.
*
* @return the friendly name.
*/
public String getName() {
return name;
}

@Override
public boolean isVerbose() {
return verbose;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ default R compile(Workspace workspace, String firstClassName, String... addition
*/
<E extends Exception> C configure(JctCompilerConfigurer<E> configurer) throws E;

/**
* Get the friendly printable name of this compiler object.
*
* @return the name of the compiler.
*/
String getName();

/**
* Set the friendly name of this compiler.
*
* @param name the name to set.
* @return this compiler object for further call chaining.
*/
C name(String name);

/**
* Get an <strong>immutable snapshot view</strong> of the current annotation processor options
* that are set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,48 @@ void configureReturnsTheCompiler() throws Throwable {
}
}

@DisplayName(".getName() returns the name")
@Test
void getNameReturnsName() {
// Then
assertThat(compiler.getName()).isEqualTo(name);
}

@DisplayName("AbstractJctCompiler#name tests")
@Nested
class NameTest {
@DisplayName(".name(...) sets the name")
@ValueSource(strings = {"foo", "bar baz", "bork"})
@ParameterizedTest(name = "for name = {0}")
void nameSetsTheName(String name) {
// When
compiler.name(name);

// Then
assertThatCompilerField("name").isEqualTo(name);
}

@DisplayName(".name(...) returns the compiler")
@Test
void nameReturnsTheCompiler() {
// When
var result = compiler.name("foo");

// Then
assertThat(result).isSameAs(compiler);
}

@DisplayName(".name(null) throws a NullPointerException")
@SuppressWarnings("DataFlowIssue")
@Test
void passingNullToNameThrowsNullPointerException() {
// Then
assertThatThrownBy(() -> compiler.name(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("name");
}
}

@DisplayName(".getFlagBuilder() returns the flag builder")
@Test
void getFlagBuilderReturnsFlagBuilder() {
Expand All @@ -466,13 +508,6 @@ void getJsr199CompilerReturnsTheCompiler() {
assertThat(compiler.getJsr199Compiler()).isSameAs(jsr199Compiler);
}

@DisplayName(".getName() returns the name")
@Test
void getNameReturnsName() {
// Then
assertThat(compiler.getName()).isSameAs(name);
}

@DisplayName(".isVerbose() returns the expected values")
@ValueSource(booleans = {true, false})
@ParameterizedTest(name = "for verbose = {0}")
Expand Down