protected void checkConstantType(VariableElement elem, TypeInfo type, TypeMirror typeMirror, boolean allowAnyJavaType) { if (isLegalNonCallableReturnType(type, allowAnyJavaType)) { return; } throw new GenException(elem, "type " + type + " is not legal for use for a constant type in code generation"); }
@Override protected void checkReturnType(ExecutableElement elem, TypeInfo type, TypeMirror typeMirror, boolean allowAnyJavaType) { if (elem.getModifiers().contains(Modifier.STATIC)) { // Ignore static methods - we won't use them anyway return; } if (type.isVoid()) { return; } throw new GenException(elem, "Proxy methods must have void or Fluent returns"); }
@Override protected void checkMethod(MethodInfo methodInfo) { // We don't allow overloaded methods in proxies List<MethodInfo> methodsByName = methodMap.get(methodInfo.getName()); if (methodsByName != null) { throw new GenException(this.modelElt, "Overloaded methods are not allowed in ProxyGen interfaces " + methodInfo.getName()); } }
public boolean process() { if (!processed) { if (modelElt.getKind() == ElementKind.INTERFACE || modelElt.getKind() == ElementKind.CLASS) { traverse(); processTypeAnnotations(); processImportedTypes(); processed = true; return true; } else { throw new GenException(modelElt, "Data object " + modelElt + " must be an interface or a class"); } } return false; }
static void checkUnderModule(Model model, String annotation) { if (model.getModule() == null) { throw new GenException(model.getElement(), "Declaration annotated with " + annotation + " must be under a package annotated" + "with @ModuleGen. Check that the package '" + model.getFqn() + "' or a parent package contains a 'package-info.java' using the @ModuleGen annotation"); } }
@Override protected MethodInfo createMethodInfo(Set<ClassTypeInfo> ownerTypes, String methodName, String comment, Doc doc, TypeInfo returnType, Text returnDescription, boolean isFluent, boolean isCacheReturn, List<ParamInfo> mParams, ExecutableElement methodElt, boolean isStatic, boolean isDefault, ArrayList<TypeParamInfo.Method> typeParams, TypeElement declaringElt, boolean methodDeprecated, Text methodDeprecatedDesc) { AnnotationMirror proxyIgnoreAnnotation = Helper.resolveMethodAnnotation(ProxyIgnore.class, elementUtils, typeUtils, declaringElt, methodElt); boolean isProxyIgnore = proxyIgnoreAnnotation != null; AnnotationMirror proxyCloseAnnotation = Helper.resolveMethodAnnotation(ProxyClose.class, elementUtils, typeUtils, declaringElt, methodElt); boolean isProxyClose = proxyCloseAnnotation != null; ProxyMethodInfo proxyMeth = new ProxyMethodInfo(ownerTypes, methodName, returnType, returnDescription, isFluent, isCacheReturn, mParams, comment, doc, isStatic, isDefault, typeParams, isProxyIgnore, isProxyClose, methodDeprecated, methodDeprecatedDesc); if (isProxyClose && mParams.size() > 0) { if (mParams.size() > 1) { throw new GenException(this.modelElt, "@ProxyClose methods can't have more than one parameter"); } if (proxyMeth.getKind() != MethodKind.FUTURE) { throw new GenException(this.modelElt, "@ProxyClose parameter must be Handler<AsyncResult<Void>>"); } TypeInfo type = mParams.get(0).getType(); TypeInfo arg = ((ParameterizedTypeInfo) ((ParameterizedTypeInfo) type).getArgs().get(0)).getArgs().get(0); if (arg.getKind() != ClassKind.VOID) { throw new GenException(this.modelElt, "@ProxyClose parameter must be " + "Handler<AsyncResult<Void>> instead of " + type); } } return proxyMeth; }
public ModuleModel getModuleModel(String modulePackage) { PackageElement element = modules.get(modulePackage); ModuleGen annotation = element.getAnnotation(ModuleGen.class); String moduleName = annotation.name(); if (moduleName.isEmpty()) { throw new GenException(element, "A module name cannot be empty"); } try { Case.KEBAB.parse(moduleName); } catch (IllegalArgumentException e) { throw new GenException(element, "Module name '" + moduleName + "' does not follow the snake case format (dash separated name)"); } String groupPackage = annotation.groupPackage(); if (groupPackage.equals("")) { groupPackage = modulePackage; } else if (!modulePackage.startsWith(groupPackage)) { throw new GenException(element, "A module package (" + modulePackage + ") must be prefixed by the group package (" + groupPackage + ")"); } try { Case.QUALIFIED.parse(groupPackage); } catch (Exception e) { throw new GenException(element, "Invalid group package name " + groupPackage); } ModuleInfo info = new ModuleInfo(modulePackage, moduleName, groupPackage); AnnotationValueInfoFactory annotationFactory = new AnnotationValueInfoFactory(new TypeMirrorFactory(elementUtils,typeUtils)); List<AnnotationValueInfo> annotationValueInfos = element.getAnnotationMirrors().stream().map(annotationFactory::processAnnotation).collect(Collectors.toList()); return new ModuleModel(element, info, annotationValueInfos); }
if ("add".equals(prefix)) { if (name.endsWith("s")) { throw new GenException(methodElt, "Option adder name must not terminate with 's' char"); } else { name += "s";
String generate() { Collections.sort(this, (o1, o2) -> o1.model.getElement().getSimpleName().toString().compareTo( o2.model.getElement().getSimpleName().toString())); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < size(); i++) { ModelProcessing processing = get(i); try { String part = processing.generator.render(processing.model, i, size(), session); if (part != null) { buffer.append(part); } } catch (GenException e) { throw e; } catch (Exception e) { GenException genException = new GenException(processing.model.getElement(), e.getMessage()); genException.initCause(e); throw genException; } } return buffer.toString(); } }
return; throw new GenException(elem, "type " + typeInfo + " does not have a valid 'public JsonObject toJson()' method."); throw new GenException(elem, "Handler<AsyncResult<T>> must be the last parameter if present in a proxied method"); throw new GenException(elem, "type " + typeInfo + " is not legal for use for a parameter in proxy");
typeInfo = typeFactory.create(typeUse, type); } catch (Exception e) { GenException ex = new GenException(param, e.getMessage()); ex.setStackTrace(e.getStackTrace()); throw ex; unresolvedTypeInfo = typeFactory.create(typeUse, methodType2.getParameterTypes().get(i)); } catch (Exception e) { throw new GenException(param, e.getMessage());
this.type = (ClassTypeInfo) typeFactory.create(modelElt.asType()); } catch (ClassCastException e) { throw new GenException(modelElt, "Data object must be a plain java class with no type parameters"); ); if (getModule() == null) { throw new GenException(modelElt, "Data object must have an ancestor package annotated with @ModuleGen"); throw new GenException(modelElt, "Data object " + modelElt + " class does not have a constructor " + modelElt.getSimpleName() + "(" + JsonObject.class.getSimpleName() + ")");
public boolean process() { if (!processed) { if (modelElt.getKind() != ElementKind.ENUM) { throw new GenException(modelElt, "@VertxGen can only be used with interfaces or enums" + modelElt.asType().toString()); collect(Collectors.toList()); if (values.isEmpty()) { throw new GenException(modelElt, "No empty enums");
protected void checkReturnType(ExecutableElement elem, TypeInfo type, TypeMirror typeMirror, boolean allowAnyJavaType) { if (type.isVoid()) { return; } if (isLegalNonCallableReturnType(type, allowAnyJavaType)) { return; } if (isLegalHandlerType(type, allowAnyJavaType)) { return; } if (isLegalHandlerAsyncResultType(type, allowAnyJavaType)) { return; } throw new GenException(elem, "type " + type + " is not legal for use for a return type in code generation"); }
throw new GenException(getterElt, name + " getter " + getterKind + " does not match the setter " + propKind); throw new GenException(getterElt, name + " getter type " + getterType + " does not match the setter type " + propType); if (propTypeMirror != null) { if (propKind != PropertyKind.LIST && propKind != PropertyKind.SET) { throw new GenException(adderElt, name + "adder does not correspond to non list/set"); throw new GenException(adderElt, name + " adder type " + adderType + " does not match the property type " + propType); if (propTypeMirror != null) { if (propKind != PropertyKind.MAP) { throw new GenException(adderElt, name + "adder does not correspond to non map"); throw new GenException(adderElt, name + " adder type " + adderType + " does not match the property type " + propType);
case ENUM: case CLASS: { throw new GenException(elem, "@VertxGen can only be used with interfaces or enums in " + elem.asType().toString()); throw new GenException(elem, "Can only have one interface per file"); TypeVariable varTypeArg = (TypeVariable) typeArg; if (!isObjectBound(varTypeArg.getUpperBound())) { throw new GenException(elem, "Type variable bounds not supported " + varTypeArg.getUpperBound()); superTypeInfo = typeFactory.create(tmSuper); } catch (IllegalArgumentException e) { throw new GenException(elem, e.getMessage()); if (concrete) { if (concreteSuperType != null) { throw new GenException(elem, "A concrete interface cannot extend more than one concrete interfaces"); throw new GenException(elem, "A abstract interface cannot extend a concrete interface"); throw new GenException(elem, e.getMessage()); throw new GenException(elem, "@VertxGen can only declare methods and not " + elem.asType().toString()); MethodOverloadChecker.INSTANCE.checkAmbiguous(meths.stream().filter(m -> !anyJavaTypeMethods.containsValue(m))); } catch (RuntimeException e) { throw new GenException(elem, e.getMessage()); for (MethodInfo method : meths) {
protected void checkMethod(MethodInfo methodInfo) { List<MethodInfo> methodsByName = methodMap.get(methodInfo.getName()); if (methodsByName != null) { // Overloaded methods must have same return type for (MethodInfo meth: methodsByName) { if (!meth.isContainingAnyJavaType() && !meth.getReturnType().equals(methodInfo.getReturnType())) { throw new GenException(this.modelElt, "Overloaded method " + methodInfo.getName() + " must have the same return type " + meth.getReturnType() + " != " + methodInfo.getReturnType()); } } } }
protected void checkParamType(ExecutableElement elem, TypeMirror type, TypeInfo typeInfo, int pos, int numParams, boolean allowAnyJavaType) { if (isLegalNonCallableParam(typeInfo, allowAnyJavaType)) { return; } if (isLegalClassTypeParam(elem, typeInfo)) { return; } if (isLegalHandlerType(typeInfo, allowAnyJavaType)) { return; } if (isLegalHandlerAsyncResultType(typeInfo, allowAnyJavaType)) { return; } if (isLegalFunctionType(typeInfo, allowAnyJavaType)) { return; } throw new GenException(elem, "type " + typeInfo + " is not legal for use for a parameter in code generation"); }
boolean isStatic = mods.contains(Modifier.STATIC); if (isStatic && !concrete) { throw new GenException(modelMethod, "Abstract interface cannot declare static methods"); for (TypeMirror bound : typeParam.getBounds()) { if (!isObjectBound(bound)) { throw new GenException(modelMethod, "Type parameter bound not supported " + bound); TypeMirror fluentType = modelMethod.getReturnType(); if (!typeUtils.isAssignable(fluentType, modelElt.asType())) { throw new GenException(modelMethod, "Methods marked with @Fluent must have a return type that extends the type"); returnType = typeFactory.create(returnTypeUse, methodType.getReturnType()); } catch (Exception e) { GenException genEx = new GenException(modelMethod, e.getMessage()); genEx.initCause(e); throw genEx; throw new GenException(modelMethod, "void method can't be marked with @CacheReturn"); checkReturnType(modelMethod, returnType, methodType.getReturnType(), allowAnyJavaType); } else if (returnType.isNullable()) { throw new GenException(modelMethod, "Fluent return type cannot be nullable");