private List<PostConstructInfo> processPostConstruct(TypeElement type) { List<PostConstructInfo> postConstructs = new ArrayList<>(); ElementFilter.methodsIn(type.getEnclosedElements()).stream() .filter(method -> MoreElements.isAnnotationPresent(method, PostConstruct.class)) .forEach(method -> { // verify method if (method.getModifiers().contains(Modifier.PRIVATE)) { abortWithError(method, "@%s method must not be private", PostConstruct.class.getSimpleName()); } if (method.getModifiers().contains(Modifier.STATIC)) { abortWithError(method, "@%s method must not be static", PostConstruct.class.getSimpleName()); } if (!method.getReturnType().equals(typeUtils.getNoType(TypeKind.VOID))) { abortWithError(method, "@%s method must return void", PostConstruct.class.getSimpleName()); } if (!method.getParameters().isEmpty()) { abortWithError(method, "@%s method must not have parameters", PostConstruct.class.getSimpleName()); } postConstructs.add(new PostConstructInfo(method.getSimpleName().toString())); }); if (postConstructs.size() > 1) { warning(type, "%d methods annotated with @%s found. Order is not guaranteed!", postConstructs.size(), PostConstruct.class.getSimpleName()); } return postConstructs; }
private List<PostConstructInfo> processPostConstruct(TypeElement type) { List<PostConstructInfo> postConstructs = new ArrayList<>(); ElementFilter.methodsIn(type.getEnclosedElements()).stream() .filter(method -> MoreElements.isAnnotationPresent(method, PostConstruct.class)) .forEach(method -> { // verify method if (method.getModifiers().contains(Modifier.PRIVATE)) { abortWithError(method, "@%s method must not be private", PostConstruct.class.getSimpleName()); } if (method.getModifiers().contains(Modifier.STATIC)) { abortWithError(method, "@%s method must not be static", PostConstruct.class.getSimpleName()); } if (!method.getReturnType().equals(typeUtils.getNoType(TypeKind.VOID))) { abortWithError(method, "@%s method must return void", PostConstruct.class.getSimpleName()); } if (!method.getParameters().isEmpty()) { abortWithError(method, "@%s method must not have parameters", PostConstruct.class.getSimpleName()); } postConstructs.add(new PostConstructInfo(method.getSimpleName().toString())); }); if (postConstructs.size() > 1) { warning(type, "%d methods annotated with @%s found. Order is not guaranteed!", postConstructs.size(), PostConstruct.class.getSimpleName()); } return postConstructs; }
private List<PostConstructInfo> processPostConstruct(TypeElement type) { List<PostConstructInfo> postConstructs = new ArrayList<>(); ElementFilter.methodsIn(type.getEnclosedElements()).stream() .filter(method -> MoreElements.isAnnotationPresent(method, PostConstruct.class)) .forEach(method -> { // verify method if (method.getModifiers().contains(Modifier.PRIVATE)) { abortWithError(method, "@%s method must not be private", PostConstruct.class.getSimpleName()); } if (method.getModifiers().contains(Modifier.STATIC)) { abortWithError(method, "@%s method must not be static", PostConstruct.class.getSimpleName()); } if (!method.getReturnType().equals(typeUtils.getNoType(TypeKind.VOID))) { abortWithError(method, "@%s method must return void", PostConstruct.class.getSimpleName()); } if (!method.getParameters().isEmpty()) { abortWithError(method, "@%s method must not have parameters", PostConstruct.class.getSimpleName()); } postConstructs.add(new PostConstructInfo(method.getSimpleName().toString())); }); if (postConstructs.size() > 1) { warning(type, "%d methods annotated with @%s found. Order is not guaranteed!", postConstructs.size(), PostConstruct.class.getSimpleName()); } return postConstructs; }