Skip to content

Format, javadoc, remove duplicate code #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2023
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
2 changes: 0 additions & 2 deletions http-client/src/main/java/io/avaje/http/client/DHttpApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ void init() {
for (final HttpApiProvider apiProvider : ServiceLoader.load(HttpApiProvider.class)) {
addProvider(apiProvider);
}

for (final GeneratedComponent apiProvider : ServiceLoader.load(GeneratedComponent.class)) {
apiProvider.register(providerMap);
}

log.log(DEBUG, "providers for {0}", providerMap.keySet());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ interface Metrics extends HttpClientContext.Metrics {
@FunctionalInterface
interface GeneratedComponent {

/**
* Register the HttpApiProviders to the given providerMap.
*/
void register(Map<Class<?>, HttpApiProvider<?>> providerMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
round.getElementsAnnotatedWith(typeElement(ClientPrism.PRISM_TYPE))) {
writeClient(controller);
}
for (final var importedElement :
round.getElementsAnnotatedWith(typeElement(ImportPrism.PRISM_TYPE))) {
for (final var importedElement : round.getElementsAnnotatedWith(typeElement(ImportPrism.PRISM_TYPE))) {
writeForImported(importedElement);
}

writeComponent(round.processingOver());

setPlatform(platform);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void setFullName(String fullName) {

String fullName() {
if (fullName == null) {

String topPackage = TopPackage.of(generatedClients);
if (!topPackage.endsWith(".httpclient")) {
topPackage += ".httpclient";
Expand Down Expand Up @@ -59,13 +58,11 @@ Collection<String> allImports() {
return packageImports;
}

public static String removeLast(String s, String search) {
final int pos = s.lastIndexOf(search);

public static String removeLast(String className, String search) {
final int pos = className.lastIndexOf(search);
if (pos > -1) {
return s.substring(0, pos) + s.substring(pos + search.length());
return className.substring(0, pos) + className.substring(pos + search.length());
}

return s;
return className;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ final class SimpleComponentWriter {
}

void init() throws IOException {

if (fullName == null) {
this.fullName = metaData.fullName();
}

if (fileObject == null) {
fileObject = createWriter(metaData.fullName());
}
Expand Down Expand Up @@ -65,12 +63,9 @@ private void writeRegister() {
writer.append(" public void register(Map<Class<?>, HttpApiProvider<?>> providerMap) {").eol();

for (final String clientFullName : metaData.all()) {

final String clientShortName = Util.shortName(clientFullName);
final var clientInterface = removeLast(clientShortName, "HttpClient");
writer
.append(" providerMap.put(%s.class, %s::new);", clientInterface, clientShortName)
.eol();
final var clientInterface = ComponentMetaData.removeLast(clientShortName, "HttpClient");
writer.append(" providerMap.put(%s.class, %s::new);", clientInterface, clientShortName).eol();
}
writer.append(" }").eol().eol();
}
Expand All @@ -82,15 +77,11 @@ private void writeClassEnd() {
private void writeClassStart() {
final String shortName = Util.shortName(fullName);
writer.append(AT_GENERATED).eol();

writer.append("@MetaData({");
final List<String> all = metaData.all();
writeMetaDataEntry(all);
writer.append("})").eol();
writer
.append("public class %s implements HttpClient.GeneratedComponent {", shortName)
.eol()
.eol();
writer.append("public class %s implements HttpClient.GeneratedComponent {", shortName).eol().eol();
}

private void writeMetaDataEntry(List<String> entries) {
Expand All @@ -117,19 +108,9 @@ private void writeImports() {
writer.eol();
}

public static String removeLast(String s, String search) {
final int pos = s.lastIndexOf(search);

if (pos > -1) {
return s.substring(0, pos) + s.substring(pos + search.length());
}

return s;
}

private void writePackage() {
final String packageName = TopPackage.packageOf(fullName);
if (packageName != null && !packageName.isEmpty()) {
if (!packageName.isEmpty()) {
writer.append("package %s;", packageName).eol().eol();
}
}
Expand Down