Skip to content

Commit

Permalink
nested packages
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan committed Oct 5, 2023
1 parent 125447d commit 9805e78
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package io.avaje.http.generator.core;

import static io.avaje.http.generator.core.ProcessingContext.*;
import static io.avaje.http.generator.core.ProcessingContext.doc;
import static io.avaje.http.generator.core.ProcessingContext.elements;
import static io.avaje.http.generator.core.ProcessingContext.isOpenApiAvailable;
import static io.avaje.http.generator.core.ProcessingContext.logError;
import static io.avaje.http.generator.core.ProcessingContext.typeElement;
import static java.util.stream.Collectors.toMap;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
Expand All @@ -21,7 +29,7 @@ public abstract class BaseProcessor extends AbstractProcessor {

String contextPathString;

Map<String, String> packagePaths= new HashMap<>();
Map<String, String> packagePaths= new TreeMap<>();

@Override
public SourceVersion getSupportedSourceVersion() {
Expand Down Expand Up @@ -119,11 +127,16 @@ private void writeOpenAPI() {

private void writeAdapter(Element controller) {
if (controller instanceof TypeElement) {

var packageFQN = elements().getPackageOf(controller).getQualifiedName().toString();
var contextPath =
Util.combinePath(
contextPathString,
packagePaths.get(
elements().getPackageOf(controller).getQualifiedName().toString()));
packagePaths.entrySet().stream()
.filter(k -> packageFQN.contains(k.getKey()))
.map(Entry::getValue)
.reduce(Util::combinePath)
.orElse(null));

final ControllerReader reader = new ControllerReader((TypeElement) controller, contextPath);
reader.read(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.example.path.nest;

import io.avaje.http.api.Controller;
import io.avaje.http.api.Get;
import io.avaje.http.api.Path;
import io.avaje.http.api.Produces;

@Path("test")
@Controller
public class PathNestController {

@Produces("text/plain")
@Get
String hello() {
return "hi";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

@Path("nested")
package org.example.path.nest;

import io.avaje.http.api.Path;

0 comments on commit 9805e78

Please sign in to comment.