Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@
* Generates serializer class for given {@code Message} class. The generated serializer follows the naming convention:
* {@code org.apache.ignite.internal.codegen.[MessageClassName]Serializer}.
*/
class MessageSerializerGenerator {
public class MessageSerializerGenerator {
/** */
private static final String EMPTY = "";

/** */
private static final String TAB = " ";
public static final String TAB = " ";

/** */
private static final String NL = System.lineSeparator();
public static final String NL = System.lineSeparator();

/** */
private static final String PKG_NAME = "org.apache.ignite.internal.codegen";
Expand All @@ -81,7 +81,7 @@ class MessageSerializerGenerator {
" */";

/** */
private static final String METHOD_JAVADOC = "/** */";
public static final String METHOD_JAVADOC = "/** */";

/** */
private static final String RETURN_FALSE_STMT = "return false;";
Expand Down Expand Up @@ -136,7 +136,7 @@ void generate(TypeElement type, List<VariableElement> fields) throws Exception {
// all Run commands to Maven. However, this significantly slows down test startup time.
// This hack checks whether the content of a generating file is identical to already existed file, and skips
// handling this class if it is.
if (!identicalFileIsAlreadyGenerated(serCode, serClsName)) {
if (!identicalFileIsAlreadyGenerated(env, serCode, PKG_NAME, serClsName)) {
env.getMessager().printMessage(
Diagnostic.Kind.ERROR,
"MessageSerializer " + serClsName + " is already generated. Try 'mvn clean install' to fix the issue.");
Expand Down Expand Up @@ -403,7 +403,7 @@ else if (assignableFrom(erasedType(type), type(Collection.class.getName()))) {
"MessageCollectionItemType." + messageCollectionItemType(typeArgs.get(0)));
}

else if (enumType(type)) {
else if (enumType(env, type)) {
Element element = env.getTypeUtils().asElement(type);
imports.add(element.toString());

Expand Down Expand Up @@ -609,8 +609,7 @@ else if (assignableFrom(erasedType(type), type(Collection.class.getName()))) {
returnFalseIfReadFailed(name, collectionReader,
"MessageCollectionItemType." + messageCollectionItemType(typeArgs.get(0)));
}

else if (enumType(type)) {
else if (enumType(env, type)) {
String fieldPrefix = typeNameToFieldName(env.getTypeUtils().asElement(type).getSimpleName().toString());

boolean hasCustMapperAnn = field.getAnnotation(CustomMapper.class) != null;
Expand Down Expand Up @@ -856,7 +855,7 @@ private boolean assignableFrom(TypeMirror type, TypeMirror superType) {
}

/** */
private boolean enumType(TypeMirror type) {
public static boolean enumType(ProcessingEnvironment env, TypeMirror type) {
Element element = env.getTypeUtils().asElement(type);

return element != null && element.getKind() == ElementKind.ENUM;
Expand All @@ -882,9 +881,9 @@ private String capitalizeOnlyFirst(String input) {
}

/** @return {@code true} if trying to generate file with the same content. */
private boolean identicalFileIsAlreadyGenerated(String srcCode, String clsName) {
public static boolean identicalFileIsAlreadyGenerated(ProcessingEnvironment env, String srcCode, String pkg, String clsName) {
try {
String fileName = PKG_NAME.replace('.', '/') + '/' + clsName + ".java";
String fileName = pkg.replace('.', '/') + '/' + clsName + ".java";
FileObject prevFile = env.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, "", fileName);

String prevFileContent;
Expand All @@ -904,7 +903,7 @@ private boolean identicalFileIsAlreadyGenerated(String srcCode, String clsName)
}

/** */
private String content(Reader reader) throws IOException {
private static String content(Reader reader) throws IOException {
BufferedReader br = new BufferedReader(reader);
StringBuilder sb = new StringBuilder();
String line;
Expand Down
Loading
Loading