Unify method visibility of private classes

Apply checkstyle rule to ensure that private and package private
classes do not have unnecessary public methods. Test classes have
also been unified as much as possible to use default scoped
inner-classes.

Closes gh-7316
This commit is contained in:
Phillip Webb
2019-07-01 12:29:51 -07:00
parent 0a02a3a19c
commit a66c4d3096
910 changed files with 3754 additions and 3945 deletions

View File

@@ -59,7 +59,7 @@ class ResourceMatcher {
this.excludes = getOptions(excludes, DEFAULT_EXCLUDES);
}
public List<MatchedResource> find(List<File> roots) throws IOException {
List<MatchedResource> find(List<File> roots) throws IOException {
List<MatchedResource> matchedResources = new ArrayList<>();
for (File root : roots) {
if (root.isFile()) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,15 +35,15 @@ final class Dependency {
this.description = description;
}
public String getId() {
String getId() {
return this.id;
}
public String getName() {
String getName() {
return this.name;
}
public String getDescription() {
String getDescription() {
return this.description;
}

View File

@@ -196,10 +196,8 @@ public class InitCommand extends OptionParsingCommand {
}
protected ProjectGenerationRequest createProjectGenerationRequest(OptionSet options) {
List<?> nonOptionArguments = new ArrayList<Object>(options.nonOptionArguments());
Assert.isTrue(nonOptionArguments.size() <= 1, "Only the target location may be specified");
ProjectGenerationRequest request = new ProjectGenerationRequest();
request.setServiceUrl(options.valueOf(this.target));
if (options.has(this.bootVersion)) {

View File

@@ -84,7 +84,7 @@ class InitializrService {
* @return an entity defining the project
* @throws IOException if generation fails
*/
public ProjectGenerationResponse generate(ProjectGenerationRequest request) throws IOException {
ProjectGenerationResponse generate(ProjectGenerationRequest request) throws IOException {
Log.info("Using service at " + request.getServiceUrl());
InitializrServiceMetadata metadata = loadMetadata(request.getServiceUrl());
URI url = request.generateUrl(metadata);
@@ -100,7 +100,7 @@ class InitializrService {
* @return the metadata describing the service
* @throws IOException if the service's metadata cannot be loaded
*/
public InitializrServiceMetadata loadMetadata(String serviceUrl) throws IOException {
InitializrServiceMetadata loadMetadata(String serviceUrl) throws IOException {
CloseableHttpResponse httpResponse = executeInitializrMetadataRetrieval(serviceUrl);
validateResponse(httpResponse, serviceUrl);
return parseJsonMetadata(httpResponse.getEntity());
@@ -115,7 +115,7 @@ class InitializrService {
* {@link InitializrServiceMetadata} describing the service
* @throws IOException if the service capabilities cannot be loaded
*/
public Object loadServiceCapabilities(String serviceUrl) throws IOException {
Object loadServiceCapabilities(String serviceUrl) throws IOException {
HttpGet request = new HttpGet(serviceUrl);
request.setHeader(new BasicHeader(HttpHeaders.ACCEPT, ACCEPT_SERVICE_CAPABILITIES));
CloseableHttpResponse httpResponse = execute(request, serviceUrl, "retrieve help");

View File

@@ -78,7 +78,7 @@ class InitializrServiceMetadata {
* Return the dependencies supported by the service.
* @return the supported dependencies
*/
public Collection<Dependency> getDependencies() {
Collection<Dependency> getDependencies() {
return this.dependencies.values();
}
@@ -88,7 +88,7 @@ class InitializrServiceMetadata {
* @param id the id
* @return the dependency or {@code null}
*/
public Dependency getDependency(String id) {
Dependency getDependency(String id) {
return this.dependencies.get(id);
}
@@ -96,7 +96,7 @@ class InitializrServiceMetadata {
* Return the project types supported by the service.
* @return the supported project types
*/
public Map<String, ProjectType> getProjectTypes() {
Map<String, ProjectType> getProjectTypes() {
return this.projectTypes.getContent();
}
@@ -105,7 +105,7 @@ class InitializrServiceMetadata {
* default.
* @return the default project type or {@code null}
*/
public ProjectType getDefaultType() {
ProjectType getDefaultType() {
if (this.projectTypes.getDefaultItem() != null) {
return this.projectTypes.getDefaultItem();
}
@@ -120,7 +120,7 @@ class InitializrServiceMetadata {
* Returns the defaults applicable to the service.
* @return the defaults of the service
*/
public Map<String, String> getDefaults() {
Map<String, String> getDefaults() {
return this.defaults;
}
@@ -229,15 +229,15 @@ class InitializrServiceMetadata {
this.content = new HashMap<>();
}
public Map<K, T> getContent() {
Map<K, T> getContent() {
return this.content;
}
public T getDefaultItem() {
T getDefaultItem() {
return this.defaultItem;
}
public void setDefaultItem(T defaultItem) {
void setDefaultItem(T defaultItem) {
this.defaultItem = defaultItem;
}

View File

@@ -78,11 +78,11 @@ class ProjectGenerationRequest {
* @return the service URL
* @see #DEFAULT_SERVICE_URL
*/
public String getServiceUrl() {
String getServiceUrl() {
return this.serviceUrl;
}
public void setServiceUrl(String serviceUrl) {
void setServiceUrl(String serviceUrl) {
this.serviceUrl = serviceUrl;
}
@@ -90,11 +90,11 @@ class ProjectGenerationRequest {
* The location of the generated project.
* @return the location of the generated project
*/
public String getOutput() {
String getOutput() {
return this.output;
}
public void setOutput(String output) {
void setOutput(String output) {
if (output != null && output.endsWith("/")) {
this.output = output.substring(0, output.length() - 1);
this.extract = true;
@@ -110,11 +110,11 @@ class ProjectGenerationRequest {
* automatically.
* @return {@code true} if the archive should be extracted, otherwise {@code false}
*/
public boolean isExtract() {
boolean isExtract() {
return this.extract;
}
public void setExtract(boolean extract) {
void setExtract(boolean extract) {
this.extract = extract;
}
@@ -122,11 +122,11 @@ class ProjectGenerationRequest {
* The groupId to use or {@code null} if it should not be customized.
* @return the groupId or {@code null}
*/
public String getGroupId() {
String getGroupId() {
return this.groupId;
}
public void setGroupId(String groupId) {
void setGroupId(String groupId) {
this.groupId = groupId;
}
@@ -134,11 +134,11 @@ class ProjectGenerationRequest {
* The artifactId to use or {@code null} if it should not be customized.
* @return the artifactId or {@code null}
*/
public String getArtifactId() {
String getArtifactId() {
return this.artifactId;
}
public void setArtifactId(String artifactId) {
void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
@@ -146,11 +146,11 @@ class ProjectGenerationRequest {
* The artifact version to use or {@code null} if it should not be customized.
* @return the artifact version or {@code null}
*/
public String getVersion() {
String getVersion() {
return this.version;
}
public void setVersion(String version) {
void setVersion(String version) {
this.version = version;
}
@@ -158,11 +158,11 @@ class ProjectGenerationRequest {
* The name to use or {@code null} if it should not be customized.
* @return the name or {@code null}
*/
public String getName() {
String getName() {
return this.name;
}
public void setName(String name) {
void setName(String name) {
this.name = name;
}
@@ -170,11 +170,11 @@ class ProjectGenerationRequest {
* The description to use or {@code null} if it should not be customized.
* @return the description or {@code null}
*/
public String getDescription() {
String getDescription() {
return this.description;
}
public void setDescription(String description) {
void setDescription(String description) {
this.description = description;
}
@@ -182,11 +182,11 @@ class ProjectGenerationRequest {
* Return the package name or {@code null} if it should not be customized.
* @return the package name or {@code null}
*/
public String getPackageName() {
String getPackageName() {
return this.packageName;
}
public void setPackageName(String packageName) {
void setPackageName(String packageName) {
this.packageName = packageName;
}
@@ -195,11 +195,11 @@ class ProjectGenerationRequest {
* service supports. If not set, the default is retrieved from the service metadata.
* @return the project type
*/
public String getType() {
String getType() {
return this.type;
}
public void setType(String type) {
void setType(String type) {
this.type = type;
}
@@ -207,11 +207,11 @@ class ProjectGenerationRequest {
* The packaging type or {@code null} if it should not be customized.
* @return the packaging type or {@code null}
*/
public String getPackaging() {
String getPackaging() {
return this.packaging;
}
public void setPackaging(String packaging) {
void setPackaging(String packaging) {
this.packaging = packaging;
}
@@ -220,11 +220,11 @@ class ProjectGenerationRequest {
* {@link #getFormat() format} to identify the type to use.
* @return the build type
*/
public String getBuild() {
String getBuild() {
return this.build;
}
public void setBuild(String build) {
void setBuild(String build) {
this.build = build;
}
@@ -233,11 +233,11 @@ class ProjectGenerationRequest {
* {@link #getBuild() build} to identify the type to use.
* @return the project format
*/
public String getFormat() {
String getFormat() {
return this.format;
}
public void setFormat(String format) {
void setFormat(String format) {
this.format = format;
}
@@ -245,11 +245,11 @@ class ProjectGenerationRequest {
* Whether or not the type should be detected based on the build and format value.
* @return {@code true} if type detection will be performed, otherwise {@code false}
*/
public boolean isDetectType() {
boolean isDetectType() {
return this.detectType;
}
public void setDetectType(boolean detectType) {
void setDetectType(boolean detectType) {
this.detectType = detectType;
}
@@ -257,11 +257,11 @@ class ProjectGenerationRequest {
* The Java version to use or {@code null} if it should not be customized.
* @return the Java version or {@code null}
*/
public String getJavaVersion() {
String getJavaVersion() {
return this.javaVersion;
}
public void setJavaVersion(String javaVersion) {
void setJavaVersion(String javaVersion) {
this.javaVersion = javaVersion;
}
@@ -269,11 +269,11 @@ class ProjectGenerationRequest {
* The programming language to use or {@code null} if it should not be customized.
* @return the programming language or {@code null}
*/
public String getLanguage() {
String getLanguage() {
return this.language;
}
public void setLanguage(String language) {
void setLanguage(String language) {
this.language = language;
}
@@ -281,11 +281,11 @@ class ProjectGenerationRequest {
* The Spring Boot version to use or {@code null} if it should not be customized.
* @return the Spring Boot version or {@code null}
*/
public String getBootVersion() {
String getBootVersion() {
return this.bootVersion;
}
public void setBootVersion(String bootVersion) {
void setBootVersion(String bootVersion) {
this.bootVersion = bootVersion;
}
@@ -293,7 +293,7 @@ class ProjectGenerationRequest {
* The identifiers of the dependencies to include in the project.
* @return the dependency identifiers
*/
public List<String> getDependencies() {
List<String> getDependencies() {
return this.dependencies;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@ class ProjectGenerationResponse {
* Return the {@link ContentType} of this instance.
* @return the content type
*/
public ContentType getContentType() {
ContentType getContentType() {
return this.contentType;
}
@@ -47,11 +47,11 @@ class ProjectGenerationResponse {
* The generated project archive or file.
* @return the content
*/
public byte[] getContent() {
byte[] getContent() {
return this.content;
}
public void setContent(byte[] content) {
void setContent(byte[] content) {
this.content = content;
}
@@ -60,11 +60,11 @@ class ProjectGenerationResponse {
* preferred value has been set.
* @return the file name, or {@code null}
*/
public String getFileName() {
String getFileName() {
return this.fileName;
}
public void setFileName(String fileName) {
void setFileName(String fileName) {
this.fileName = fileName;
}

View File

@@ -42,7 +42,7 @@ class ProjectGenerator {
this.initializrService = initializrService;
}
public void generateProject(ProjectGenerationRequest request, boolean force) throws IOException {
void generateProject(ProjectGenerationRequest request, boolean force) throws IOException {
ProjectGenerationResponse response = this.initializrService.generate(request);
String fileName = (request.getOutput() != null) ? request.getOutput() : response.getFileName();
if (shouldExtract(request, response)) {

View File

@@ -47,23 +47,23 @@ class ProjectType {
}
}
public String getId() {
String getId() {
return this.id;
}
public String getName() {
String getName() {
return this.name;
}
public String getAction() {
String getAction() {
return this.action;
}
public boolean isDefaultType() {
boolean isDefaultType() {
return this.defaultType;
}
public Map<String, String> getTags() {
Map<String, String> getTags() {
return Collections.unmodifiableMap(this.tags);
}

View File

@@ -54,7 +54,7 @@ class ServiceCapabilitiesReportGenerator {
* @return the report that describes the service
* @throws IOException if the report cannot be generated
*/
public String generate(String url) throws IOException {
String generate(String url) throws IOException {
Object content = this.initializrService.loadServiceCapabilities(url);
if (content instanceof InitializrServiceMetadata) {
return generateHelp(url, (InitializrServiceMetadata) content);

View File

@@ -83,7 +83,7 @@ class Installer {
}
}
public void install(List<String> artifactIdentifiers) throws Exception {
void install(List<String> artifactIdentifiers) throws Exception {
File extDirectory = getDefaultExtDirectory();
extDirectory.mkdirs();
Log.info("Installing into: " + extDirectory);
@@ -115,7 +115,7 @@ class Installer {
}
}
public void uninstall(List<String> artifactIdentifiers) throws Exception {
void uninstall(List<String> artifactIdentifiers) throws Exception {
File extDirectory = getDefaultExtDirectory();
Log.info("Uninstalling from: " + extDirectory);
List<File> artifactFiles = this.dependencyResolver.resolve(artifactIdentifiers);
@@ -129,7 +129,7 @@ class Installer {
saveInstallCounts();
}
public void uninstallAll() throws Exception {
void uninstallAll() throws Exception {
File extDirectory = getDefaultExtDirectory();
Log.info("Uninstalling from: " + extDirectory);
for (String name : this.installCounts.stringPropertyNames()) {

View File

@@ -143,7 +143,7 @@ public class OptionHandler {
return "";
}
public Collection<OptionHelp> getOptionHelp() {
Collection<OptionHelp> getOptionHelp() {
return Collections.unmodifiableList(this.help);
}

View File

@@ -79,7 +79,7 @@ public class RunCommand extends OptionParsingCommand {
this.quietOption = option(Arrays.asList("quiet", "q"), "Quiet logging");
}
public void stop() {
void stop() {
synchronized (this.monitor) {
if (this.runner != null) {
this.runner.stop();

View File

@@ -176,7 +176,7 @@ public class SpringApplicationRunner {
/**
* Shutdown the thread, closing any previously opened application context.
*/
public void shutdown() {
void shutdown() {
synchronized (this.monitor) {
if (this.applicationContext != null) {
try {

View File

@@ -130,11 +130,11 @@ public class CommandCompleter extends StringsCompleter {
this.usage = optionHelp.getUsageHelp();
}
public String getOptions() {
String getOptions() {
return this.options;
}
public String getUsage() {
String getUsage() {
return this.usage;
}

View File

@@ -67,7 +67,7 @@ class EscapeAwareWhiteSpaceArgumentDelimiter extends WhitespaceArgumentDelimiter
return -1;
}
public String[] parseArguments(String line) {
String[] parseArguments(String line) {
ArgumentList delimit = delimit(line, 0);
return cleanArguments(delimit.getArguments());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ class RunProcessCommand extends AbstractCommand {
}
}
public boolean handleSigInt() {
boolean handleSigInt() {
return this.process.handleSigInt();
}

View File

@@ -193,7 +193,7 @@ public class Shell {
super(null);
}
public void addAliases(String command, String... aliases) {
void addAliases(String command, String... aliases) {
for (String alias : aliases) {
this.aliases.put(alias, command);
}
@@ -219,7 +219,7 @@ public class Shell {
protected void afterRun(Command command) {
}
public boolean handleSigInt() {
boolean handleSigInt() {
Command command = this.lastCommand;
if (command != null && command instanceof RunProcessCommand) {
return ((RunProcessCommand) command).handleSigInt();

View File

@@ -294,11 +294,11 @@ public class GroovyCompiler {
private static class MainClass {
public static ClassNode get(CompilationUnit source) {
static ClassNode get(CompilationUnit source) {
return get(source.getAST().getClasses());
}
public static ClassNode get(List<ClassNode> classes) {
static ClassNode get(List<ClassNode> classes) {
for (ClassNode node : classes) {
if (AstUtils.hasAtLeastOneAnnotation(node, "Enable*AutoConfiguration")) {
return null; // No need to enhance this

View File

@@ -92,7 +92,7 @@ class SpringApplicationLauncherTests {
return classLoader.classes;
}
private static class TestClassLoader extends ClassLoader {
static class TestClassLoader extends ClassLoader {
private Set<String> classes = new HashSet<>();

View File

@@ -37,7 +37,7 @@ class OptionParsingCommandTests {
assertThat(command.getHelp()).contains("--bar");
}
private static class TestOptionParsingCommand extends OptionParsingCommand {
static class TestOptionParsingCommand extends OptionParsingCommand {
TestOptionParsingCommand(String name, String description, OptionHandler handler) {
super(name, description, handler);

View File

@@ -153,7 +153,7 @@ public abstract class AbstractHttpClientMockTests {
return json.toString();
}
protected static class MockHttpProjectGenerationRequest {
static class MockHttpProjectGenerationRequest {
String contentType;
@@ -161,11 +161,11 @@ public abstract class AbstractHttpClientMockTests {
byte[] content = new byte[] { 0, 0, 0, 0 };
public MockHttpProjectGenerationRequest(String contentType, String fileName) {
MockHttpProjectGenerationRequest(String contentType, String fileName) {
this(contentType, fileName, new byte[] { 0, 0, 0, 0 });
}
public MockHttpProjectGenerationRequest(String contentType, String fileName, byte[] content) {
MockHttpProjectGenerationRequest(String contentType, String fileName, byte[] content) {
this.contentType = contentType;
this.fileName = fileName;
this.content = content;
@@ -173,7 +173,7 @@ public abstract class AbstractHttpClientMockTests {
}
private static class HasAcceptHeader implements ArgumentMatcher<HttpGet> {
static class HasAcceptHeader implements ArgumentMatcher<HttpGet> {
private final String value;

View File

@@ -361,7 +361,7 @@ class InitCommandTests extends AbstractHttpClientMockTests {
}
}
private static class TestableInitCommandOptionHandler extends InitCommand.InitOptionHandler {
static class TestableInitCommandOptionHandler extends InitCommand.InitOptionHandler {
private boolean disableProjectGeneration;

View File

@@ -218,7 +218,7 @@ class ProjectGenerationRequestTests {
return createUrl("/starter.zip" + param);
}
public void setBuildAndFormat(String build, String format) {
void setBuildAndFormat(String build, String format) {
this.request.setBuild((build != null) ? build : "maven");
this.request.setFormat((format != null) ? format : "project");
this.request.setDetectType(true);

View File

@@ -121,7 +121,7 @@ class GroovyGrabDependencyResolverTests {
"hamcrest-core-2.1.jar", "hamcrest-2.1.jar");
}
public Set<String> getNames(Collection<File> files) {
Set<String> getNames(Collection<File> files) {
Set<String> names = new HashSet<>(files.size());
for (File file : files) {
names.add(file.getName());