The idea is that types that appear in generated source code use encode, which will
spell out a type like java.util.List<? extends java.lang.Number>, except that wherever a
class name appears it is replaced by a special token. So the spelling might actually be `java.util.List`<? extends `java.lang.Number`>. Then once the entire class has been generated,
#decode scans for these tokens to determine what classes need to be imported, and
replaces the tokens with the correct spelling given the imports. So here, java.util.List
would be imported, and the final spelling would be List<? extends Number> (knowing that
Number is implicitly imported). The special token `import` marks where the
imports should be, and decode replaces it with the correct list of imports.
The funky syntax for type annotations on qualified type names requires an adjustment to this
scheme. `«java.util.Map` stands for java.util. and `»java.util.Map`
stands for Map. If java.util.Map is imported, then `«java.util.Map` will
eventually be empty, but if java.util.Map is not imported (perhaps because there is
another Map in scope) then `«java.util.Map` will be java.util.. The end
result is that the code can contain `«java.util.Map`@`javax.annotation.Nullable`
`»java.util.Map`. That might decode to @Nullable Map or to java.util.@Nullable
Map or even to java.util.@javax.annotation.Nullable Map.
| Modifier and Type | Class and Description |
|---|---|
| private static class | TypeEncoder.
Like |
| private static class | TypeEncoder.
Converts a type into a string, using standard Java syntax, except that every class name is
wrapped in backquotes, like |
| private static class | TypeEncoder.
Like |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final TypeEncoder. | |
| private static final TypeEncoder. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static void | appendAnnotations(List<? extends javax.
|
| private static void | appendTypeParameterWithBounds(javax.
|
| private static String | |
| pack-priv static String | decode(String
the text to be decoded. text, javax.the package of the generated class. Other classes in the same package do not
need to be imported. packageName, javax.a class or interface that the generated class inherits from. Nested classes in
that type do not need to be imported, and if another class has the same name as one of
those nested classes then it will need to be qualified. baseTypeDecodes the given string, respelling class names appropriately. |
| pack-priv static String | |
| pack-priv static String | encode(javax.
Returns the encoding for the given type, where class names are marked by special tokens. |
| pack-priv static String | |
| pack-priv static String | encodeWithAnnotations(javax.
Encodes the given type and its type annotations. |
| pack-priv static String | encodeWithAnnotations(javax.
additional type annotations to include with the type extraAnnotationsEncodes the given type and its type annotations. |
| pack-priv static String | encodeWithAnnotations(javax.
additional type annotations to include with the type extraAnnotations,annotations not to include in the encoding. For example, if
excludedAnnotationTypescom.example.Nullable is in this set then the encoding will not include this
@Nullable annotation.Encodes the given type and its type annotations. |
| private static boolean | |
| pack-priv static String | typeParametersString(List<? extends javax.
Returns a string representing the given type parameters as they would appear in a class declaration. |
| ENCODING_TYPE_VISITOR | back to summary |
|---|---|
| private static final TypeEncoder. | |
| RAW_ENCODING_TYPE_VISITOR | back to summary |
|---|---|
| private static final TypeEncoder. | |
| TypeEncoder | back to summary |
|---|---|
| private TypeEncoder() | |
| appendAnnotations | back to summary |
|---|---|
| private static void appendAnnotations(List<? extends javax. | |
| appendTypeParameterWithBounds | back to summary |
|---|---|
| private static void appendTypeParameterWithBounds(javax. | |
| className | back to summary |
|---|---|
| private static String className(javax. | |
| decode | back to summary |
|---|---|
| pack-priv static String decode(String text, javax. Decodes the given string, respelling class names appropriately. The text is scanned for tokens
like
| |
| decode | back to summary |
|---|---|
| pack-priv static String decode(String text, javax. | |
| encode | back to summary |
|---|---|
| pack-priv static String encode(javax. Returns the encoding for the given type, where class names are marked by special tokens. The
encoding for | |
| encodeRaw | back to summary |
|---|---|
| pack-priv static String encodeRaw(javax. Like | |
| encodeWithAnnotations | back to summary |
|---|---|
| pack-priv static String encodeWithAnnotations(javax. Encodes the given type and its type annotations. The class comment for | |
| encodeWithAnnotations | back to summary |
|---|---|
| pack-priv static String encodeWithAnnotations(javax. Encodes the given type and its type annotations. The class comment for
| |
| encodeWithAnnotations | back to summary |
|---|---|
| pack-priv static String encodeWithAnnotations(javax. Encodes the given type and its type annotations. The class comment for
| |
| isUnannotatedJavaLangObject | back to summary |
|---|---|
| private static boolean isUnannotatedJavaLangObject(javax. | |
| typeParametersString | back to summary |
|---|---|
| pack-priv static String typeParametersString(List<? extends javax. Returns a string representing the given type parameters as they would appear in a class
declaration. For example, if we have The encoding is simply that classes in the "extends" part are marked, so the examples will
actually look something like this: | |
EncodingTypeVisitor except that annotations on the visited type are also included
in the resultant string. Class names in those annotations are also encoded using the `java.util.List` form.
| Modifier and Type | Field and Description |
|---|---|
| private final Set | |
| private final Function |
| Access | Constructor and Description |
|---|---|
| pack-priv | AnnotatedEncodingTypeVisitor(Set<javax.
|
| Modifier and Type | Method and Description |
|---|---|
| private void | appendAnnotationsWithExclusions(List<? extends javax.
|
| public StringBuilder | visitArray(javax.
Overrides com. The result respects the Java syntax, whereby |
| public StringBuilder | visitDeclared(javax.
Overrides com.
|
| public StringBuilder | |
| public StringBuilder |
| excludedAnnotationTypes | back to summary |
|---|---|
| private final Set<javax. | |
| getTypeAnnotations | back to summary |
|---|---|
| private final Function<javax. | |
| AnnotatedEncodingTypeVisitor | back to summary |
|---|---|
| pack-priv AnnotatedEncodingTypeVisitor(Set<javax. | |
| appendAnnotationsWithExclusions | back to summary |
|---|---|
| private void appendAnnotationsWithExclusions(List<? extends javax. | |
| visitArray | back to summary |
|---|---|
| public StringBuilder visitArray(javax. Overrides com. The result respects the Java syntax, whereby
| |
| visitDeclared | back to summary |
|---|---|
| public StringBuilder visitDeclared(javax. Overrides com.
| |
| visitPrimitive | back to summary |
|---|---|
public StringBuilder visitPrimitive(javax.
| |
| visitTypeVariable | back to summary |
|---|---|
public StringBuilder visitTypeVariable(javax.
| |
`java.util.List`.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void | |
| protected StringBuilder | |
| pack-priv StringBuilder | visit2(javax.
Equivalent to |
| public StringBuilder | |
| public StringBuilder | |
| public StringBuilder | |
| public StringBuilder |
| EncodingTypeVisitor | back to summary |
|---|---|
| private EncodingTypeVisitor() | |
| appendTypeArguments | back to summary |
|---|---|
| pack-priv void appendTypeArguments(javax. | |
| appendTypeName | back to summary |
|---|---|
| pack-priv void appendTypeName(javax. | |
| defaultAction | back to summary |
|---|---|
protected StringBuilder defaultAction(javax.
| |
| visit2 | back to summary |
|---|---|
| pack-priv StringBuilder visit2(javax. Equivalent to | |
| visitArray | back to summary |
|---|---|
public StringBuilder visitArray(javax.
| |
| visitDeclared | back to summary |
|---|---|
public StringBuilder visitDeclared(javax.
| |
| visitError | back to summary |
|---|---|
public StringBuilder visitError(javax.
| |
| visitWildcard | back to summary |
|---|---|
public StringBuilder visitWildcard(javax.
| |
EncodingTypeVisitor except that type parameters are omitted from the result.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | appendTypeArguments(javax.
Overrides com.
|
| RawEncodingTypeVisitor | back to summary |
|---|---|
| private RawEncodingTypeVisitor() | |
| appendTypeArguments | back to summary |
|---|---|
| pack-priv void appendTypeArguments(javax. Overrides com.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final javax. | |
| private final javax. | |
| private final String | |
| private final JavaScanner | |
| private final String | |
| private final int | |
| private final javax. |
| Access | Constructor and Description |
|---|---|
| pack-priv | TypeRewriter(String text, javax.
|
| Modifier and Type | Method and Description |
|---|---|
| private javax. | |
| private String | |
| private void | |
| private OptionalInt | |
| private Set | |
| pack-priv String |
| baseType | back to summary |
|---|---|
| private final javax. | |
| elementUtils | back to summary |
|---|---|
| private final javax. | |
| packageName | back to summary |
|---|---|
| private final String packageName | |
| scanner | back to summary |
|---|---|
| private final JavaScanner scanner | |
| text | back to summary |
|---|---|
| private final String text | |
| textLength | back to summary |
|---|---|
| private final int textLength | |
| typeUtils | back to summary |
|---|---|
| private final javax. | |
| TypeRewriter | back to summary |
|---|---|
| pack-priv TypeRewriter(String text, javax. | |
| classForName | back to summary |
|---|---|
| private javax. | |
| classNameAt | back to summary |
|---|---|
| private String classNameAt(int token) | |
| decode | back to summary |
|---|---|
| private void decode(StringBuilder output, TypeSimplifier typeSimplifier, int token) | |
| findImportMarker | back to summary |
|---|---|
| private OptionalInt findImportMarker() | |
| findReferencedClasses | back to summary |
|---|---|
| private Set | |
| rewrite | back to summary |
|---|---|
| pack-priv String rewrite() | |