Java Code Examples for io.vertx.codegen.type.TypeInfo#getKind()
The following examples show how to use
io.vertx.codegen.type.TypeInfo#getKind() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParamInfo.java From vertx-codegen with Apache License 2.0 | 6 votes |
/** * @return true when the param callback value is nullable: when the parameter type is an * handler or an async result handler it returns the nullable boolean of the corresponding * parameter, otherwise it returns null */ public Boolean isNullableCallback() { switch (type.getKind()) { case HANDLER: TypeInfo handler = ((ParameterizedTypeInfo)type).getArg(0); switch (handler.getKind()) { case ASYNC_RESULT: TypeInfo asyncResult = ((ParameterizedTypeInfo)handler).getArg(0); return asyncResult.isNullable(); default: return handler.isNullable(); } default: return null; } }
Example 2
Source File: RxJava2Generator.java From vertx-rx with Apache License 2.0 | 6 votes |
private void genToXXXEr(TypeInfo streamType, String rxType, String rxName, PrintWriter writer) { writer.format(" public synchronized WriteStream%s<%s> to%s() {%n", rxType, genTranslatedTypeName(streamType), rxType); writer.format(" if (%s == null) {%n", rxName); if (streamType.getKind() == ClassKind.API) { writer.format(" Function<%s, %s> conv = %s::getDelegate;%n", genTranslatedTypeName(streamType.getRaw()), streamType.getName(), genTranslatedTypeName(streamType)); writer.format(" %s = RxHelper.to%s(getDelegate(), conv);%n", rxName, rxType); } else if (streamType.isVariable()) { String typeVar = streamType.getSimpleName(); writer.format(" Function<%s, %s> conv = (Function<%s, %s>) __typeArg_0.unwrap;%n", typeVar, typeVar, typeVar, typeVar); writer.format(" %s = RxHelper.to%s(getDelegate(), conv);%n", rxName, rxType); } else { writer.format(" %s = RxHelper.to%s(getDelegate());%n", rxName, rxType); } writer.println(" }"); writer.format(" return %s;%n", rxName); writer.println(" }"); writer.println(); }
Example 3
Source File: RxJava2Generator.java From vertx-rx with Apache License 2.0 | 6 votes |
private MethodInfo genFutureMethod(MethodInfo method) { String futMethodName = genFutureMethodName(method); List<ParamInfo> futParams = new ArrayList<>(); int count = 0; int size = method.getParams().size() - 1; while (count < size) { ParamInfo param = method.getParam(count); /* Transform ReadStream -> Flowable */ futParams.add(param); count = count + 1; } ParamInfo futParam = method.getParam(size); TypeInfo futType = ((ParameterizedTypeInfo) ((ParameterizedTypeInfo) futParam.getType()).getArg(0)).getArg(0); TypeInfo futUnresolvedType = ((ParameterizedTypeInfo) ((ParameterizedTypeInfo) futParam.getUnresolvedType()).getArg(0)).getArg(0); TypeInfo futReturnType; if (futUnresolvedType.getKind() == VOID) { futReturnType = io.vertx.codegen.type.TypeReflectionFactory.create(io.reactivex.Completable.class); } else if (futUnresolvedType.isNullable()) { futReturnType = new io.vertx.codegen.type.ParameterizedTypeInfo(io.vertx.codegen.type.TypeReflectionFactory.create(io.reactivex.Maybe.class).getRaw(), false, Collections.singletonList(futType)); } else { futReturnType = new io.vertx.codegen.type.ParameterizedTypeInfo(io.vertx.codegen.type.TypeReflectionFactory.create(io.reactivex.Single.class).getRaw(), false, Collections.singletonList(futType)); } return method.copy().setName(futMethodName).setReturnType(futReturnType).setParams(futParams); }
Example 4
Source File: ExpressionModel.java From vertx-codetrans with Apache License 2.0 | 6 votes |
public ExpressionModel as(TypeInfo type) { switch (type.getKind()) { case API: return builder.api(this); case JSON_OBJECT: return new JsonObjectModel(builder, this); case JSON_ARRAY: return new JsonArrayModel(builder, this); case OTHER: if (type.isDataObjectHolder()) { return new DataObjectModel(builder, this); } else { return this; } case MAP: return new MapModel(builder, this); case LIST: return new ListModel(builder, this); default: return this; } }
Example 5
Source File: JsonObjectLiteralModel.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public ExpressionModel as(TypeInfo type) { if (type.getKind() != ClassKind.JSON_OBJECT) { throw new UnsupportedOperationException(); } return this; }
Example 6
Source File: MethodInfo.java From vertx-codegen with Apache License 2.0 | 5 votes |
private static boolean containsAnyJavaType(TypeInfo type) { if (type instanceof ParameterizedTypeInfo) { return containsAnyJavaType(type.getRaw()) || ((ParameterizedTypeInfo) type).getArgs().stream().anyMatch(MethodInfo::containsAnyJavaType); } else { return type.getKind() == ClassKind.OTHER; } }
Example 7
Source File: MethodInfo.java From vertx-codegen with Apache License 2.0 | 5 votes |
public MethodKind getKind() { int lastParamIndex = params.size() - 1; if (lastParamIndex >= 0 && (returnType.isVoid() || fluent)) { TypeInfo lastParamType = params.get(lastParamIndex).type; if (lastParamType.getKind() == ClassKind.HANDLER) { TypeInfo typeArg = ((ParameterizedTypeInfo) lastParamType).getArgs().get(0); if (typeArg.getKind() == ClassKind.ASYNC_RESULT) { return MethodKind.FUTURE; } else { return MethodKind.HANDLER; } } } return MethodKind.OTHER; }
Example 8
Source File: TypeValidator.java From vertx-codegen with Apache License 2.0 | 5 votes |
private static boolean isValidVertxGenInterface(TypeInfo type, boolean allowParameterized, boolean allowAnyJavaType) { if (type.getKind() == ClassKind.API) { if (type.isParameterized()) { ParameterizedTypeInfo parameterized = (ParameterizedTypeInfo) type; return allowParameterized && parameterized .getArgs() .stream() .noneMatch(arg -> !isValidVertxGenTypeArgument(arg, allowAnyJavaType) || arg.isNullable()); } else { return true; } } return false; }
Example 9
Source File: TypeValidator.java From vertx-codegen with Apache License 2.0 | 5 votes |
private static boolean isValidContainer(TypeInfo type, boolean allowAnyJavaType) { TypeInfo argument = null; if (rawTypeIs(type, List.class, Set.class, Map.class)) { ParameterizedTypeInfo parameterizedType = (ParameterizedTypeInfo) type; if (type.getKind() != ClassKind.MAP) { argument = parameterizedType.getArgs().get(0); } else if (parameterizedType.getArgs().get(0).getKind() == ClassKind.STRING) { // Only allow Map's with String's for keys argument= parameterizedType.getArgs().get(1); } } return argument != null && isValidContainerComponent(argument, allowAnyJavaType); }
Example 10
Source File: TypeValidator.java From vertx-codegen with Apache License 2.0 | 5 votes |
private static boolean isValidClassTypeParam(ExecutableElement elt, TypeInfo type) { if (type.getKind() == ClassKind.CLASS_TYPE && type.isParameterized()) { ParameterizedTypeInfo parameterized = (ParameterizedTypeInfo) type; TypeInfo arg = parameterized.getArg(0); if (arg.isVariable()) { TypeVariableInfo variable = (TypeVariableInfo) arg; for (TypeParameterElement typeParamElt : elt.getTypeParameters()) { if (typeParamElt.getSimpleName().toString().equals(variable.getName())) { return true; } } } } return false; }
Example 11
Source File: TypeValidator.java From vertx-codegen with Apache License 2.0 | 5 votes |
private static boolean isValidNonCallableType(TypeInfo type, boolean isParam, boolean isReturn, boolean allowParameterized, boolean allowAnyJavaType) { if (isValidDataObjectType(type, isParam, isReturn)) { return true; } if (type.getKind() == ClassKind.VOID) { return true; } if (type.getKind().basic) { return true; } if (type.getKind().json) { return true; } if (isValidEnum(type)) { return true; } if (type.getKind() == ClassKind.THROWABLE) { return true; } if (type.isVariable()) { return true; } if (type.getKind() == ClassKind.OBJECT) { return true; } if (isValidVertxGenInterface(type, allowParameterized, allowAnyJavaType)) { return true; } if (isValidOtherType(type, allowAnyJavaType)) { return true; } if (allowParameterized && isValidContainer(type, allowAnyJavaType)) { return true; } return false; }
Example 12
Source File: RowMapperGen.java From vertx-sql-client with Apache License 2.0 | 5 votes |
private static Function<String, String> getter_(TypeInfo type, boolean isArray) { String getter = getter(type); if (getter != null) { return col -> "row." + getter + (isArray ? "Array" : "") + "(\"" + col + "\")"; } if (type.getKind() == ClassKind.ENUM || type instanceof ClassTypeInfo) { if (isArray) { return col -> "row.get(" + type.getName() + "[].class, \"" + col + "\")"; } else { return col -> "row.get(" + type.getName() + ".class, \"" + col + "\")"; } } return null; }
Example 13
Source File: JsonArrayLiteralModel.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public ExpressionModel as(TypeInfo type) { if (type.getKind() != ClassKind.JSON_ARRAY) { throw new UnsupportedOperationException(); } return this; }
Example 14
Source File: TypeValidator.java From vertx-codegen with Apache License 2.0 | 4 votes |
private static boolean isValidEnum(TypeInfo info) { return info.getKind() == ClassKind.ENUM; }
Example 15
Source File: ScalaApiModel.java From vertx-codetrans with Apache License 2.0 | 4 votes |
private boolean methodAcceptsAsyncResultHandler(TypeInfo last) { return last.getKind() == ClassKind.HANDLER && ((ParameterizedTypeInfo) last).getArg(0).getKind() == ClassKind.ASYNC_RESULT; }
Example 16
Source File: TypeValidator.java From vertx-codegen with Apache License 2.0 | 4 votes |
private static boolean isValidOtherType(TypeInfo type, boolean allowAnyJavaType) { return allowAnyJavaType && type.getKind() == ClassKind.OTHER; }
Example 17
Source File: RxJava2Generator.java From vertx-rx with Apache License 2.0 | 4 votes |
private void genToXXXAble(TypeInfo streamType, String rxType, String rxName, PrintWriter writer) { writer.print(" public synchronized "); writer.print(rxType); writer.print("<"); writer.print(genTranslatedTypeName(streamType)); writer.print("> to"); writer.print(rxType); writer.println("() {"); writer.print(" "); writer.print("if ("); writer.print(rxName); writer.println(" == null) {"); if (streamType.getKind() == ClassKind.API) { writer.print(" Function<"); writer.print(streamType.getName()); writer.print(", "); writer.print(genTranslatedTypeName(streamType)); writer.print("> conv = "); writer.print(genTranslatedTypeName(streamType.getRaw())); writer.println("::newInstance;"); writer.print(" "); writer.print(rxName); writer.print(" = "); writer.print(rxType); writer.print("Helper.to"); writer.print(rxType); writer.println("(delegate, conv);"); } else if (streamType.isVariable()) { String typeVar = streamType.getSimpleName(); writer.print(" Function<"); writer.print(typeVar); writer.print(", "); writer.print(typeVar); writer.print("> conv = (Function<"); writer.print(typeVar); writer.print(", "); writer.print(typeVar); writer.println(">) __typeArg_0.wrap;"); writer.print(" "); writer.print(rxName); writer.print(" = "); writer.print(rxType); writer.print("Helper.to"); writer.print(rxType); writer.println("(delegate, conv);"); } else { writer.print(" "); writer.print(rxName); writer.print(" = "); writer.print(rxType); writer.print("Helper.to"); writer.print(rxType); writer.println("(this.getDelegate());"); } writer.println(" }"); writer.print(" return "); writer.print(rxName); writer.println(";"); writer.println(" }"); writer.println(); }
Example 18
Source File: DataObjectCheatsheetGen.java From vertx-codegen with Apache License 2.0 | 4 votes |
private String getDataType(TypeInfo type) { ClassKind kind = type.getKind(); if (kind.basic) { if (kind == ClassKind.STRING) { return "String"; } String typeName = type.getName(); switch (typeName) { case "java.lang.Boolean": case "boolean": return "Boolean"; case "java.lang.Character": case "char": return "Char"; case "java.lang.Byte": case "byte": case "java.lang.Short": case "short": case "java.lang.Integer": case "int": case "java.lang.Long": case "long": case "java.lang.Float": case "float": case "java.lang.Double": case "double": return "Number (" + type.getSimpleName() + ")"; } } else { switch (kind) { case JSON_OBJECT: return "Json object"; case JSON_ARRAY: return "Json array"; // case DATA_OBJECT: // return "link:dataobjects.html#" + type.getRaw().getSimpleName() + '[' + type.getRaw().getSimpleName() + ']'; case ENUM: return "link:enums.html#" + type.getRaw().getSimpleName() + '[' + type.getRaw().getSimpleName() + ']'; case API: if (type.getName().equals("io.vertx.core.buffer.Buffer")) { return "Buffer"; } break; case OTHER: if (type.getName().equals(Instant.class.getName())) { return "Instant"; } break; } } System.out.println("unhandled type " + type); return null; }
Example 19
Source File: RxJavaGenerator.java From vertx-rx with Apache License 2.0 | 4 votes |
@Override protected void genToObservable(TypeInfo streamType, PrintWriter writer) { writer.print(" private Observable<"); writer.print(genTranslatedTypeName(streamType)); writer.println("> observable;"); writer.println(); writer.print(" public synchronized Observable<"); writer.print(genTranslatedTypeName(streamType)); writer.println("> toObservable() {"); writer.print(" "); writer.println("if (observable == null) {"); if (streamType.getKind() == ClassKind.API) { writer.print(" Function<"); writer.print(streamType.getName()); writer.print(", "); writer.print(genTranslatedTypeName(streamType)); writer.print("> conv = "); writer.print(genTranslatedTypeName(streamType.getRaw())); writer.println("::newInstance;"); writer.println(" observable = RxHelper.toObservable(delegate, conv);"); } else if (streamType.isVariable()) { String typeVar = streamType.getSimpleName(); writer.print(" Function<"); writer.print(typeVar); writer.print(", "); writer.print(typeVar); writer.print("> conv = (Function<"); writer.print(typeVar); writer.print(", "); writer.print(typeVar); writer.println(">) __typeArg_0.wrap;"); writer.println(" observable = RxHelper.toObservable(delegate, conv);"); } else { writer.println(" observable = RxHelper.toObservable(this.getDelegate());"); } writer.println(" }"); writer.println(" return observable;"); writer.println(" }"); writer.println(); }
Example 20
Source File: RowMapperGen.java From vertx-sql-client with Apache License 2.0 | 4 votes |
private static String getter(TypeInfo type) { switch (type.getKind()) { case PRIMITIVE: PrimitiveTypeInfo pt = (PrimitiveTypeInfo) type; return getter(pt.getBoxed()); case BOXED_PRIMITIVE: return "get" + type.getSimpleName(); case STRING: return "getString"; case JSON_OBJECT: return "getJsonObject"; case JSON_ARRAY: return "getJsonArray"; } if (type instanceof ClassTypeInfo) { DataObjectInfo dataObject = type.getDataObject(); if (dataObject != null) { return getter(dataObject.getJsonType()); } ClassTypeInfo ct = (ClassTypeInfo) type; switch (ct.getName()) { case "java.time.LocalDateTime": return "getLocalDateTime"; case "java.time.LocalDate": return "getLocalDate"; case "java.time.LocalTime": return "getLocalTime"; case "java.time.OffsetTime": return "getOffsetTime"; case "java.time.OffsetDateTime": return "getOffsetDateTime"; case "java.time.temporal.Temporal": return "getTemporal"; case "java.util.UUID": return "getUUID"; case "io.vertx.core.buffer.Buffer": return "getBuffer"; } } return null; }