Skip to content

Commit

Permalink
[issues-1035] fix kotlion incrementalFilter createResource NPE : http…
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwei11 committed Feb 24, 2023
1 parent 60e6b63 commit 8c836ab
Showing 1 changed file with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
@AutoService(Processor.class)
@SupportedAnnotationTypes({ANNOTATION_TYPE_ROUTE, ANNOTATION_TYPE_AUTOWIRED})
public class RouteProcessor extends BaseProcessor {
private Map<String, Set<RouteMeta>> groupMap = new HashMap<>(); // ModuleName and routeMeta.
private Map<String, String> rootMap = new TreeMap<>(); // Map of root metas, used for generate class file in order.
private final Map<String, Set<RouteMeta>> groupMap = new HashMap<>(); // ModuleName and routeMeta.
private final Map<String, String> rootMap = new TreeMap<>(); // Map of root metas, used for generate class file in order.

private TypeMirror iProvider = null;
private Writer docWriter; // Writer used for write doc
Expand All @@ -81,23 +81,27 @@ public class RouteProcessor extends BaseProcessor {
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);

if (generateDoc) {
try {
docWriter = mFiler.createResource(
StandardLocation.SOURCE_OUTPUT,
PACKAGE_OF_GENERATE_DOCS,
"arouter-map-of-" + moduleName + ".json"
).openWriter();
} catch (IOException e) {
logger.error("Create doc writer failed, because " + e.getMessage());
}
}

iProvider = elementUtils.getTypeElement(Consts.IPROVIDER).asType();

logger.info(">>> RouteProcessor init. <<<");
}

private synchronized Writer getOrCreateDocWriter() {
if (docWriter != null) {
return docWriter;
}
try {
docWriter = mFiler.createResource(
StandardLocation.SOURCE_OUTPUT,
PACKAGE_OF_GENERATE_DOCS,
"arouter-map-of-" + moduleName + ".json"
).openWriter();
} catch (IOException e) {
logger.error("Create doc writer failed, because " + e.getMessage());
}
return docWriter;
}

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -336,9 +340,12 @@ private void parseRoutes(Set<? extends Element> routeElements) throws IOExceptio

// Output route doc
if (generateDoc) {
docWriter.append(JSON.toJSONString(docSource, SerializerFeature.PrettyFormat));
docWriter.flush();
docWriter.close();
Writer docWriter = getOrCreateDocWriter();
if (docWriter != null) {
docWriter.append(JSON.toJSONString(docSource, SerializerFeature.PrettyFormat));
docWriter.flush();
docWriter.close();
}
}

// Write provider into disk
Expand Down

0 comments on commit 8c836ab

Please sign in to comment.