Skip to content
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

[issues-1035] fix kotlion incrementalFilter createResource NPE #1037

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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 @@ -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