@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { checkShareableComponents(roundEnv); checkParameters(roundEnv); return false; }
/** * Check parameter annotations for being qualifiers. * @param round The round environment. */ private void checkParameters(RoundEnvironment round) { Set<? extends Element> params = round.getElementsAnnotatedWith(Parameter.class); note("processing %d parameter annotations", params.size()); for (Element param: params) { Qualifier q = param.getAnnotation(Qualifier.class); if (q == null) { warning(param, "parameter %s is not annotated as a qualifier", param); } AliasFor alias = param.getAnnotation(AliasFor.class); if (alias != null) { warning(param, "parameter %s is an alias (@Parameter should be on target)", param); } } } }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); note("LensKit Shareable linting active"); typeUtils = processingEnv.getTypeUtils(); elementUtils = processingEnv.getElementUtils(); }
@Override public synchronized void init(ProcessingEnvironment processingEnv) { super.init(processingEnv); note("LensKit Shareable linting active"); typeUtils = processingEnv.getTypeUtils(); elementUtils = processingEnv.getElementUtils(); }
/** * Check shareable components for serializability. * @param round The round environment. */ private void checkShareableComponents(RoundEnvironment round) { Set<? extends Element> elts = round.getElementsAnnotatedWith(Shareable.class); note("processing %d shareable elements", elts.size()); TypeMirror serializable = elementUtils.getTypeElement("java.io.Serializable").asType(); for (Element elt: elts) { note("examining %s", elt); if (elt instanceof TypeElement) { TypeMirror type = elt.asType(); if (typeUtils.isAssignable(type, serializable)) { note("shareable type %s is serializable", type); } else { warning(elt, "shareable type %s is not serializable", type); } } else { note("non-type element %s cannot be verified serializable", elt); } } }
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { checkShareableComponents(roundEnv); checkParameters(roundEnv); return false; }
private void error(String fmt, Object... args) { String msg = String.format(fmt, args); getLog().printMessage(Diagnostic.Kind.ERROR, msg); }
/** * Check parameter annotations for being qualifiers. * @param round The round environment. */ private void checkParameters(RoundEnvironment round) { Set<? extends Element> params = round.getElementsAnnotatedWith(Parameter.class); note("processing %d parameter annotations", params.size()); for (Element param: params) { Qualifier q = param.getAnnotation(Qualifier.class); if (q == null) { warning(param, "parameter %s is not annotated as a qualifier", param); } AliasFor alias = param.getAnnotation(AliasFor.class); if (alias != null) { warning(param, "parameter %s is an alias (@Parameter should be on target)", param); } } } }
/** * Check shareable components for serializability. * @param round The round environment. */ private void checkShareableComponents(RoundEnvironment round) { Set<? extends Element> elts = round.getElementsAnnotatedWith(Shareable.class); note("processing %d shareable elements", elts.size()); TypeMirror serializable = elementUtils.getTypeElement("java.io.Serializable").asType(); for (Element elt: elts) { note("examining %s", elt); if (elt instanceof TypeElement) { TypeMirror type = elt.asType(); if (typeUtils.isAssignable(type, serializable)) { note("shareable type %s is serializable", type); } else { warning(elt, "shareable type %s is not serializable", type); } } else { note("non-type element %s cannot be verified serializable", elt); } } }
private void error(String fmt, Object... args) { String msg = String.format(fmt, args); getLog().printMessage(Diagnostic.Kind.ERROR, msg); }