io.vertx.codegen.type.TypeInfo Java Examples
The following examples show how to use
io.vertx.codegen.type.TypeInfo.
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: RowMapperGen.java From vertx-sql-client with Apache License 2.0 | 6 votes |
private static String wrapExpr(TypeInfo type, String expr) { DataObjectInfo dataObject = type.getDataObject(); if (dataObject != null) { MapperInfo deserializer = dataObject.getDeserializer(); if (deserializer != null) { if (deserializer.getKind() == MapperKind.SELF) { return "new " + type.getName() + "(" + expr + ")"; } else { return deserializer.getQualifiedName() + "." + String.join(".", deserializer .getSelectors()) + "(" + expr + ")"; } } throw new UnsupportedOperationException(); } else { return expr; } }
Example #3
Source File: ConsoleModel.java From vertx-codetrans with Apache License 2.0 | 6 votes |
@Override public ExpressionModel onMethodInvocation(TypeInfo receiverType, MethodSignature method, TypeInfo returnType, List<TypeArg> typeArguments, List<ExpressionModel> argumentModels, List<TypeInfo> argumentTypes) { if (method.getName().equals("println") && method.getParameterTypes().size() == 1) { return new ExpressionModel(builder) { @Override public void render(CodeWriter writer) { if (out) { writer.renderSystemOutPrintln(argumentModels.get(0)); } else { writer.renderSystemErrPrintln(argumentModels.get(0)); } } }; } throw new UnsupportedOperationException("Cannot invoke method " + method + " on System.out"); }
Example #4
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 #5
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 #6
Source File: RxJavaGenerator.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 -> Observable */ futParams.add(param); count = count + 1; } ParamInfo futParam = method.getParam(size); TypeInfo futType = ((ParameterizedTypeInfo) ((ParameterizedTypeInfo) futParam.getType()).getArg(0)).getArg(0); ParameterizedTypeInfo futReturnType = new io.vertx.codegen.type.ParameterizedTypeInfo(io.vertx.codegen.type.TypeReflectionFactory.create(rx.Single.class).getRaw(), false, java.util.Collections.singletonList(futType)); return method.copy().setName(futMethodName).setParams(futParams).setReturnType(futReturnType); }
Example #7
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 #8
Source File: MethodInvocationModel.java From vertx-codetrans with Apache License 2.0 | 5 votes |
public MethodInvocationModel(CodeBuilder builder, ExpressionModel expression, TypeInfo receiverType, MethodSignature method, TypeInfo returnType, List<TypeArg> typeArguments, List<ExpressionModel> argumentModels, List<TypeInfo> argumentTypes) { super(builder); this.expression = expression; this.receiverType = receiverType; this.method = method; this.returnType = returnType; this.typeArguments = typeArguments; this.argumentModels = argumentModels; this.argumentTypes = argumentTypes; }
Example #9
Source File: PropertyInfo.java From vertx-codegen with Apache License 2.0 | 5 votes |
public PropertyInfo(boolean declared, String name, Doc doc, TypeInfo type, String setterMethod, String adderMethod, String getterMethod, List<AnnotationValueInfo> annotations, PropertyKind kind, boolean jsonifiable, boolean deprecated, Text deprecatedDesc) { this.kind = kind; this.declared = declared; this.name = name; this.doc = doc; this.type = type; this.annotations = annotations.stream().collect(HashMap::new, (m, a) -> m.put(a.getName(), a), HashMap::putAll); this.adderMethod = adderMethod; this.setterMethod = setterMethod; this.getterMethod = getterMethod; this.jsonifiable = jsonifiable; this.deprecated = deprecated; this.deprecatedDesc = deprecatedDesc; }
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: 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 #12
Source File: AsyncResultModel.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public ExpressionModel onMethodInvocation(TypeInfo receiverType, MethodSignature method, TypeInfo returnType, List<TypeArg> typeArguments, List<ExpressionModel> argumentModels, List<TypeInfo> argumentTypes) { switch (method.getName()) { case "succeeded": return new Succeeded(builder); case "failed": return new Failed(builder); case "cause": return new Cause(builder); // Need to cast to throwable with "as" case "result": return new Value(builder).as(type); default: throw new UnsupportedOperationException(); } }
Example #13
Source File: ParamInfo.java From vertx-codegen with Apache License 2.0 | 5 votes |
public ParamInfo(int index, String name, Text description, TypeInfo type, TypeInfo unresolvedType) { this.index = index; this.name = name; this.description = description; this.type = type; this.unresolvedType = unresolvedType; }
Example #14
Source File: ArraysModel.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public ExpressionModel onMethodInvocation(TypeInfo receiverType, MethodSignature method, TypeInfo returnType, List<TypeArg> typeArguments, List<ExpressionModel> arguments, List<TypeInfo> argumentTypes) { if (method.getName().equals("asList")) { return builder.render(writer -> { writer.renderListLiteral(arguments); }); } return super.onMethodInvocation(receiverType, method, returnType, typeArguments, arguments, argumentTypes); }
Example #15
Source File: ExpressionModel.java From vertx-codetrans with Apache License 2.0 | 5 votes |
public ExpressionModel onMethodInvocation(TypeInfo receiverType, MethodSignature method, TypeInfo returnType, List<TypeArg> typeArguments, List<ExpressionModel> argumentModels, List<TypeInfo> argumentTypes) { if (method.getName().equals("equals") && method.getParameterTypes().size() == 1) { return builder.render(writer -> { writer.renderEquals(ExpressionModel.this, argumentModels.get(0)); }); } else { return new MethodInvocationModel(builder, ExpressionModel.this, receiverType, method, returnType, typeArguments, argumentModels, argumentTypes); } }
Example #16
Source File: KotlinCodeBuilder.java From vertx-codetrans with Apache License 2.0 | 5 votes |
private void renderType(TypeInfo type, KotlinCodeWriter renderer) { if (type instanceof ApiTypeInfo) { renderer.renderApiType((ApiTypeInfo) type); } else if (type instanceof ClassTypeInfo) { renderer.renderJavaType((ClassTypeInfo) type); } else if (type instanceof PrimitiveTypeInfo) { renderer.renderBasicType(type); } else { renderer.append(type.getName()); } }
Example #17
Source File: LambdaExpressionModel.java From vertx-codetrans with Apache License 2.0 | 5 votes |
public LambdaExpressionModel(CodeBuilder builder, LambdaExpressionTree.BodyKind bodyKind, List<TypeInfo> parameterTypes, List<String> parameterNames, CodeModel body) { super(builder); this.bodyKind = bodyKind; this.parameterTypes = parameterTypes; this.parameterNames = parameterNames; this.body = body; }
Example #18
Source File: KotlinCodeBuilder.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public StatementModel variableDecl(VariableScope scope, TypeInfo type, String name, ExpressionModel initializer) { return StatementModel.render(renderer -> { switch (scope) { case PARAMETER: break; case VARIABLE: case FIELD: case GLOBAL: renderer.append("var "); break; } renderer.append(name); if (initializer != null) { if (initializer instanceof NullLiteralModel) { renderer.append(": "); renderType(type, (KotlinCodeWriter) renderer); renderer.append("? = null"); } else { renderer.append(" = "); initializer.render(renderer); } } else { renderer.append(": "); renderType(type, (KotlinCodeWriter) renderer); } }); }
Example #19
Source File: TypeValidator.java From vertx-codegen with Apache License 2.0 | 5 votes |
static void validateParamType(ExecutableElement elem, TypeInfo typeInfo, boolean allowAnyJavaType) { if (isValidNonCallableType(typeInfo, true, false, true, allowAnyJavaType)) { return; } if (isValidClassTypeParam(elem, typeInfo)) { return; } if (isValidHandlerType(typeInfo, allowAnyJavaType)) { return; } if (isValidFunctionType(typeInfo, allowAnyJavaType)) { return; } throw new GenException(elem, "type " + typeInfo + " is not legal for use for a parameter in code generation"); }
Example #20
Source File: Helper.java From vertx-codetrans with Apache License 2.0 | 5 votes |
public static boolean isHandler(TypeInfo type) { if (type instanceof ParameterizedTypeInfo) { ParameterizedTypeInfo parameterizedType = (ParameterizedTypeInfo) type; return parameterizedType.getRaw().getName().equals(Handler.class.getName()); } return false; }
Example #21
Source File: KotlinCodeWriter.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public void renderMethodInvocation(ExpressionModel expression, TypeInfo receiverType, MethodSignature method, TypeInfo returnType, List<TypeArg> typeArguments, List<ExpressionModel> argumentModels, List<TypeInfo> argumentTypes) { if (!(expression instanceof ThisModel)) { expression.render(this); append('.'); } renderIdentifier(method.getName(), VariableScope.FIELD); if (typeArguments.size() > 0) { boolean needed = typeArguments.stream().filter(typeArg -> typeArg == null || !typeArg.resolved).count() > 0; if (needed) { append('<'); append(typeArguments.stream().map(ti -> { if (ti != null) { return ti.value.getSimpleName(); } else { return "Any"; } }).collect(Collectors.joining(", "))); append('>'); } } append('('); for (int i = 0; i < argumentModels.size(); i++) { if (i > 0) { append(", "); } argumentModels.get(i).render(this); } append(')'); }
Example #22
Source File: KotlinCodeWriter.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public void renderNew(ExpressionModel expression, TypeInfo type, List<ExpressionModel> argumentModels) { expression.render(this); append('('); for (int i = 0; i < argumentModels.size(); i++) { if (i > 0) { append(", "); } argumentModels.get(i).render(this); } append(')'); }
Example #23
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 #24
Source File: TypeValidator.java From vertx-codegen with Apache License 2.0 | 5 votes |
private static boolean isValidFunctionType(TypeInfo typeInfo, boolean allowAnyJavaType) { if (typeInfo.getErased().getKind() == ClassKind.FUNCTION) { TypeInfo paramType = ((ParameterizedTypeInfo) typeInfo).getArgs().get(0); if (isValidCallbackValueType(paramType, allowAnyJavaType)) { TypeInfo returnType = ((ParameterizedTypeInfo) typeInfo).getArgs().get(1); return isValidNonCallableType(returnType, true, false, true, allowAnyJavaType); } } return false; }
Example #25
Source File: GroovyWriter.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public void renderNew(ExpressionModel expression, TypeInfo type, List<ExpressionModel> argumentModels) { append("new "); expression.render(this); append('('); for (int i = 0; i < argumentModels.size(); i++) { if (i > 0) { append(", "); } argumentModels.get(i).render(this); } append(')'); }
Example #26
Source File: EnumTest.java From vertx-codegen with Apache License 2.0 | 5 votes |
@Test public void testEnumListingFromApi() throws Exception { ClassModel model = new GeneratorHelper().generateClass(EnumAsParam.class); assertTrue(model.getReferencedEnumTypes().size() > 0); TypeInfo typeInfo = (TypeInfo) model.getReferencedEnumTypes().toArray()[0]; assertTrue(typeInfo instanceof EnumTypeInfo); assertEquals("ValidEnum", typeInfo.getSimpleName()); }
Example #27
Source File: Helper.java From vertx-codetrans with Apache License 2.0 | 5 votes |
public static boolean isInstanceOfHandler(TypeInfo type) { if (type instanceof ApiTypeInfo) { ApiTypeInfo apiType = (ApiTypeInfo) type; return apiType.isHandler(); } return false; }
Example #28
Source File: ScalaApiModel.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public ExpressionModel onMethodInvocation(TypeInfo receiverType, MethodSignature method, TypeInfo returnType, List<TypeArg> typeArguments, List<ExpressionModel> argumentModels, List<TypeInfo> argumentTypes) { if (argumentTypes.size() > 0) { TypeInfo last = argumentTypes.get(argumentTypes.size() - 1); if (methodAcceptsAsyncResultHandler(last)) { // Return an ExpressionModel that the composition of two MethodInvocationModel that // the first one calls the method that returns the future // the second one does the onComplete call int lastIndex = (method.getParameterTypes().size() - 1 < 0) ? 0 : method.getParameterTypes().size(); MethodSignature futureMethodSignature = new MethodSignature(method.getName() + "Future", method.getParameterTypes().subList(0, lastIndex), false, returnType); MethodInvocationModel futureModel = createMethodWithoutLastParameter(receiverType, returnType, argumentModels, argumentTypes, futureMethodSignature); MethodInvocationModel completeMethod = createInvocationModelForReturnedFuture(receiverType, method, returnType, argumentModels, argumentTypes); return new ExpressionModel(builder) { @Override public void render(CodeWriter writer) { futureModel.render(writer); completeMethod.render(writer); } }; } } return super.onMethodInvocation(receiverType, method, returnType, typeArguments, argumentModels, argumentTypes); }
Example #29
Source File: ScalaCodeBuilder.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public StatementModel variableDecl(VariableScope scope, TypeInfo type, String name, ExpressionModel initializer) { return StatementModel.render(renderer -> { renderer.append("var ").append(name); if (initializer != null) { renderer.append(" = "); initializer.render(renderer); } else { renderer.append(" = null.asInstanceOf[").append(type.getName()).append(']'); } }); }
Example #30
Source File: GroovyCodeBuilder.java From vertx-codetrans with Apache License 2.0 | 5 votes |
@Override public StatementModel variableDecl(VariableScope scope, TypeInfo type, String name, ExpressionModel initializer) { return StatementModel.render(renderer -> { renderer.append("def ").append(name); if (initializer != null) { renderer.append(" = "); initializer.render(renderer); } }); }