public EnumModel(ProcessingEnvironment env, TypeElement modelElt) { this.typeUtils = env.getTypeUtils(); this.elementUtils = env.getElementUtils(); this.docFactory = new Doc.Factory(env.getMessager(), elementUtils, typeUtils, new TypeMirrorFactory(elementUtils, typeUtils), modelElt); this.modelElt = modelElt; this.annotationValueInfoFactory = new AnnotationValueInfoFactory(new TypeMirrorFactory(elementUtils, typeUtils)); this.deprecated = modelElt.getAnnotation(Deprecated.class) != null; }
public TypeInfo create(DeclaredType type) { return create(null, type); }
private void doTest(Class<?> container, Consumer<Map<String, TypeInfo>> assertion) throws Exception { Map<String, TypeInfo> reflectedMap = Stream.of(container.getDeclaredMethods()).filter(m -> Modifier.isPublic(m.getModifiers())). collect(Collectors.toMap(Method::getName, m -> TypeReflectionFactory.create(m.getGenericReturnType()))); assertion.accept(reflectedMap); Utils.assertProcess((proc, env) -> { TypeMirrorFactory factory = new TypeMirrorFactory(proc.getElementUtils(), proc.getTypeUtils()); TypeElement modelMap = proc.getElementUtils().getTypeElement(container.getName()); Map<String, TypeInfo> collect = modelMap.getEnclosedElements().stream(). flatMap(Helper.FILTER_METHOD). filter(elt -> elt.getModifiers().contains(javax.lang.model.element.Modifier.PUBLIC)). collect(Collectors.toMap(m -> m.getSimpleName().toString(), m -> factory.create(m.getReturnType()))); assertion.accept(collect); }); }
List<TypeParamInfo.Class> typeParams = createTypeParams(type); if (kind == ClassKind.API) { VertxGen genAnn = elt.getAnnotation(VertxGen.class); return create(resolved); for (int i = 0; i < typeArgs.size(); i++) { TypeUse argUse = use != null ? use.getArg(fqcn, i) : null; TypeInfo typeArgDesc = create(argUse, typeArgs.get(i));
); type = (EnumTypeInfo) new TypeMirrorFactory(elementUtils, typeUtils).create(modelElt.asType()); Helper.checkUnderModule(this, "@VertxGen"); values = elementUtils.
public TypeInfo create(TypeMirror type) { return create(null, type); }
TypeMirrorFactory typeFactory = new TypeMirrorFactory(elementUtils, typeUtils); return token -> { if (token.isInlineTag()) { tag.getValue(), resolvedElt, typeFactory.create(resolvedType), tag.getValue().substring(matcher.end())); token = new Token.InlineTag(token.getValue(), tagLink);
@Override public void init(ProcessingEnvironment processingEnvironment) { factory = new TypeMirrorFactory(processingEnvironment.getElementUtils(), processingEnvironment.getTypeUtils()); translator = new CodeTranslator(processingEnvironment); env = processingEnvironment; }
@Override public String resolveLabel(Element elt, String defaultLabel) { if (elt.getKind() == ElementKind.METHOD) { TypeInfo type = factory.create(elt.getEnclosingElement().asType()); if (type.getKind() == ClassKind.DATA_OBJECT) { String name = elt.getSimpleName().toString(); if (name.startsWith("set") && name.length() > 3 && Character.isUpperCase(name.charAt(3))) { name = java.beans.Introspector.decapitalize(name.substring(3)); } return name; } } return defaultLabel; }
@Override public void init(ProcessingEnvironment processingEnv) { factory = new TypeMirrorFactory(processingEnv.getElementUtils(), processingEnv.getTypeUtils()); translator = new CodeTranslator(processingEnv); env = processingEnv; }
@Override public String resolveLabel(Element elt, String defaultLabel) { if (elt.getKind().equals(ElementKind.METHOD)) { TypeInfo type = factory.create(elt.getEnclosingElement().asType()); if (type.getKind().equals(ClassKind.DATA_OBJECT)) { String name = elt.getSimpleName().toString(); if (name.startsWith("set") && name.length() > 3 && Character.isUpperCase(name.charAt(3))) name = java.beans.Introspector.decapitalize(name.substring(3)); return name; } } return defaultLabel; } }
public ClassModel(ProcessingEnvironment env, TypeElement modelElt) { this.elementUtils = env.getElementUtils(); this.typeUtils = env.getTypeUtils(); this.env = env; this.typeFactory = new TypeMirrorFactory(elementUtils, typeUtils); this.docFactory = new Doc.Factory(env.getMessager(), elementUtils, typeUtils, typeFactory, modelElt); this.messager = env.getMessager(); this.modelElt = modelElt; this.annotationValueInfoFactory = new AnnotationValueInfoFactory(typeFactory); this.deprecated = modelElt.getAnnotation(Deprecated.class) != null; }
public TypeInfo create(TypeUse use, TypeMirror type) { switch (type.getKind()) { case VOID: return VoidTypeInfo.INSTANCE; case ERROR: case DECLARED: return create(use, (DeclaredType) type); case DOUBLE: case LONG: case FLOAT: case CHAR: case BYTE: case SHORT: case BOOLEAN: case INT: if (use != null && use.isNullable()) { throw new IllegalArgumentException("Primitive types cannot be annotated with @Nullable"); } return PrimitiveTypeInfo.PRIMITIVES.get(type.getKind().name().toLowerCase()); case TYPEVAR: return create(use, (TypeVariable) type); case ARRAY: return create(use, (ArrayType) type); default: throw new IllegalArgumentException("Illegal type " + type + " of kind " + type.getKind()); } }
public DataObjectModel(ProcessingEnvironment env, TypeElement modelElt) { this.elementUtils = env.getElementUtils(); this.typeUtils = env.getTypeUtils(); this.typeFactory = new TypeMirrorFactory(elementUtils, typeUtils); this.docFactory = new Doc.Factory(env.getMessager(), elementUtils, typeUtils, typeFactory, modelElt); this.modelElt = modelElt; this.annotationValueInfoFactory = new AnnotationValueInfoFactory(typeFactory); this.deprecated = modelElt.getAnnotation(Deprecated.class) != null; }
@SuppressWarnings("unchecked") private Object processAnnotationMemberValue(AnnotationValue value) { Object realValue = value.getValue(); if (realValue instanceof VariableElement) { realValue = ((VariableElement) realValue).getSimpleName().toString(); } else if (realValue instanceof AnnotationMirror) { realValue = processAnnotation((AnnotationMirror) realValue); } else if (realValue instanceof TypeMirror) { realValue = typeFactory.create((TypeMirror) realValue); } else if (realValue instanceof List) { realValue = ((List<AnnotationValue>) realValue).stream().map(AnnotationValue::getValue).collect(Collectors.toList()); if (((List) realValue).isEmpty()) { realValue = Collections.emptyList(); } else if (((List) realValue).get(0) instanceof AnnotationMirror) { realValue = ((List<AnnotationMirror>) realValue).stream().map(this::processAnnotation).collect(Collectors.toList()); } else if (((List) realValue).get(0) instanceof TypeMirror) { realValue = ((List<TypeMirror>) realValue).stream().map(typeFactory::create).collect(Collectors.toList()); } else if (((List) realValue).get(0) instanceof VariableElement) { realValue = ((List<VariableElement>) realValue).stream().map(v -> v.getSimpleName().toString()).collect(Collectors.toList()); } } return realValue; }
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); }
private void processConstructor(ExecutableElement constrElt) { if (constrElt.getModifiers().contains(Modifier.PUBLIC)) { Element ownerElt = constrElt.getEnclosingElement(); if (ownerElt.equals(modelElt)) { List<? extends VariableElement> parameters = constrElt.getParameters(); int size = parameters.size(); if (size == 1) { TypeInfo ti = typeFactory.create(parameters.get(0).asType()); if (ti instanceof ClassTypeInfo) { ClassTypeInfo cl = (ClassTypeInfo) ti; if (cl.getKind() == ClassKind.JSON_OBJECT) { constructors |= 2; } } } else if (size == 0) { constructors |= 1; } } } }
private ConstantInfo fieldMethod(VariableElement modelField, boolean allowAnyJavaType) { Set<Modifier> mods = modelField.getModifiers(); if (!mods.contains(Modifier.PUBLIC)) { return null; } TypeInfo type = typeFactory.create(modelField.asType()); checkConstantType(modelField, type, modelField.asType(),allowAnyJavaType); Doc doc = docFactory.createDoc(modelField); return new ConstantInfo(doc, modelField.getSimpleName().toString(), type); }
public ArrayTypeInfo create(TypeUse use, ArrayType type) { TypeMirror componentType = type.getComponentType(); return new ArrayTypeInfo(create(componentType), use != null && use.isNullable()); }
TypeUse typeUse = TypeUse.createParamTypeUse(env, modelMethods.toArray(new ExecutableElement[modelMethods.size()]), i); try { typeInfo = typeFactory.create(typeUse, type); } catch (Exception e) { GenException ex = new GenException(param, e.getMessage()); TypeInfo unresolvedTypeInfo; try { unresolvedTypeInfo = typeFactory.create(typeUse, methodType2.getParameterTypes().get(i)); } catch (Exception e) { throw new GenException(param, e.getMessage());