|
28 | 28 | import java.util.ArrayList;
|
29 | 29 | import java.util.BitSet;
|
30 | 30 | import java.util.Collection;
|
31 |
| -import java.util.HashSet; |
32 | 31 | import java.util.List;
|
33 | 32 | import java.util.Map;
|
34 | 33 | import java.util.Set;
|
| 34 | +import java.util.TreeSet; |
35 | 35 | import java.util.UUID;
|
36 | 36 | import javax.annotation.processing.FilerException;
|
37 | 37 | import javax.annotation.processing.ProcessingEnvironment;
|
| 38 | +import javax.lang.model.element.Element; |
38 | 39 | import javax.lang.model.element.QualifiedNameable;
|
39 | 40 | import javax.lang.model.element.TypeElement;
|
40 | 41 | import javax.lang.model.element.VariableElement;
|
|
48 | 49 | import javax.tools.FileObject;
|
49 | 50 | import javax.tools.JavaFileObject;
|
50 | 51 | import javax.tools.StandardLocation;
|
51 |
| - |
52 | 52 | import org.apache.ignite.internal.util.typedef.F;
|
53 | 53 | import org.apache.ignite.internal.util.typedef.internal.SB;
|
54 | 54 | import org.jetbrains.annotations.Nullable;
|
@@ -83,13 +83,13 @@ class MessageSerializerGenerator {
|
83 | 83 | private static final String METHOD_JAVADOC = "/** */";
|
84 | 84 |
|
85 | 85 | /** Collection of lines for {@code writeTo} method. */
|
86 |
| - private final Collection<String> write = new ArrayList<>(); |
| 86 | + private final List<String> write = new ArrayList<>(); |
87 | 87 |
|
88 | 88 | /** Collection of lines for {@code readFrom} method. */
|
89 |
| - private final Collection<String> read = new ArrayList<>(); |
| 89 | + private final List<String> read = new ArrayList<>(); |
90 | 90 |
|
91 | 91 | /** Collection of message-specific imports. */
|
92 |
| - private final Set<String> imports = new HashSet<>(); |
| 92 | + private final Set<String> imports = new TreeSet<>(); |
93 | 93 |
|
94 | 94 | /** */
|
95 | 95 | private final ProcessingEnvironment env;
|
@@ -155,6 +155,8 @@ private String generateSerializerCode(String serClsName) throws IOException {
|
155 | 155 |
|
156 | 156 | writer.write("}");
|
157 | 157 |
|
| 158 | + writer.write(NL); |
| 159 | + |
158 | 160 | return writer.toString();
|
159 | 161 | }
|
160 | 162 | }
|
@@ -404,7 +406,7 @@ else if (assignableFrom(erasedType(type), type(Collection.class.getName()))) {
|
404 | 406 | * </pre>
|
405 | 407 | */
|
406 | 408 | private void returnFalseIfWriteFailed(Collection<String> code, String accessor, @Nullable String... args) {
|
407 |
| - String argsStr = String.join(",", args); |
| 409 | + String argsStr = String.join(", ", args); |
408 | 410 |
|
409 | 411 | code.add(line("if (!%s(msg.%s))", accessor, argsStr));
|
410 | 412 |
|
@@ -460,12 +462,20 @@ private void returnFalseIfReadFailed(VariableElement field) throws Exception {
|
460 | 462 | }
|
461 | 463 |
|
462 | 464 | if (componentType.getKind() == TypeKind.DECLARED) {
|
463 |
| - String cls = ((DeclaredType)arrType.getComponentType()).asElement().getSimpleName().toString(); |
| 465 | + Element componentElement = ((DeclaredType)componentType).asElement(); |
| 466 | + |
| 467 | + String cls = componentElement.getSimpleName().toString(); |
464 | 468 |
|
465 | 469 | returnFalseIfReadFailed(name, "reader.readObjectArray",
|
466 | 470 | "MessageCollectionItemType." + messageCollectionItemType(componentType),
|
467 | 471 | cls + ".class");
|
468 | 472 |
|
| 473 | + if (!"java.lang".equals(env.getElementUtils().getPackageOf(componentElement).getQualifiedName().toString())) { |
| 474 | + String importCls = ((QualifiedNameable)componentElement).getQualifiedName().toString(); |
| 475 | + |
| 476 | + imports.add(importCls); |
| 477 | + } |
| 478 | + |
469 | 479 | return;
|
470 | 480 | }
|
471 | 481 | }
|
@@ -583,10 +593,6 @@ private String messageCollectionItemType(TypeMirror type) throws Exception {
|
583 | 593 | if (!assignableFrom(type, type(MESSAGE_INTERFACE)))
|
584 | 594 | throw new Exception("Do not support type: " + type);
|
585 | 595 |
|
586 |
| - String cls = ((QualifiedNameable)env.getTypeUtils().asElement(type)).getQualifiedName().toString(); |
587 |
| - |
588 |
| - imports.add(cls); |
589 |
| - |
590 | 596 | return "MSG";
|
591 | 597 | }
|
592 | 598 |
|
@@ -635,7 +641,11 @@ private void returnFalseIfReadFailed(String var, String mtd, String... args) {
|
635 | 641 | }
|
636 | 642 |
|
637 | 643 | /** */
|
638 |
| - private void finish(Collection<String> code) { |
| 644 | + private void finish(List<String> code) { |
| 645 | + // Remove the last empty line for the last "case". |
| 646 | + String removed = code.remove(code.size() - 1); |
| 647 | + assert EMPTY.equals(removed) : removed; |
| 648 | + |
639 | 649 | code.add(line("}"));
|
640 | 650 | code.add(EMPTY);
|
641 | 651 |
|
@@ -673,11 +683,12 @@ private void writeClassHeader(Writer writer, String pkgName, String serClsName)
|
673 | 683 |
|
674 | 684 | writer.write(NL);
|
675 | 685 | writer.write("package " + pkgName + ";" + NL + NL);
|
676 |
| - writer.write("import java.nio.ByteBuffer;" + NL); |
677 |
| - writer.write("import org.apache.ignite.plugin.extensions.communication.Message;" + NL); |
678 |
| - writer.write("import org.apache.ignite.plugin.extensions.communication.MessageSerializer;" + NL); |
679 |
| - writer.write("import org.apache.ignite.plugin.extensions.communication.MessageWriter;" + NL); |
680 |
| - writer.write("import org.apache.ignite.plugin.extensions.communication.MessageReader;" + NL); |
| 686 | + |
| 687 | + imports.add("java.nio.ByteBuffer"); |
| 688 | + imports.add("org.apache.ignite.plugin.extensions.communication.Message"); |
| 689 | + imports.add("org.apache.ignite.plugin.extensions.communication.MessageSerializer"); |
| 690 | + imports.add("org.apache.ignite.plugin.extensions.communication.MessageWriter"); |
| 691 | + imports.add("org.apache.ignite.plugin.extensions.communication.MessageReader"); |
681 | 692 |
|
682 | 693 | for (String i: imports)
|
683 | 694 | writer.write("import " + i + ";" + NL);
|
|
0 commit comments