@Test public void fails_to_parse_because_no_link_type_annotation_is_present() { ExecutableElement method = methodElements.of( "fr.vidal.oss.jax_rs_linker.parser.UnparseableResource", "methodWithoutLinkTypes" ); Optional<Mapping> mapping = parser.parse(method); String errorMessage = "\n\tMethod should be annotated with exactly one annotation: @Self or @SubResource.\n" + "\tGiven method: <fr.vidal.oss.jax_rs_linker.parser.UnparseableResource#methodWithoutLinkTypes>"; assertThat(mapping.isPresent()).isFalse(); verify(messager).printMessage(ERROR, errorMessage, method); }
public Optional<Mapping> parse(Element element) { if (element.getKind() != ElementKind.METHOD) { return compilationError(element, CompilationError.NOT_A_METHOD.format(element)); } ExecutableElement method = (ExecutableElement) element; Optional<String> maybePath = pathVisitor.visitPath(method); if (!maybePath.isPresent()) { return compilationError(method, CompilationError.NO_PATH_FOUND.format(qualified(method))); } Optional<HttpVerb> maybeHttpVerb = httpVerbVisitor.visit(method); if (!maybeHttpVerb.isPresent()) { return compilationError(method, CompilationError.NO_HTTP_ANNOTATION_FOUND.format(qualified(method))); } boolean withSelf = byAnnotation(Self.class).test(method); boolean withSubResource = byAnnotation(SubResource.class).test(method); if (!(withSelf ^ withSubResource)) { return compilationError(method, CompilationError.ANNOTATION_MISUSE.format(qualified(method))); } Optional<ApiLink> link = link(method, withSelf); if (!link.isPresent()) { return compilationError(method, CompilationError.MISSING_ANNOTATIONS.format(qualified(method))); } Mapping mapping = mapping(method, link.get(), maybeHttpVerb.get(), maybePath.get()); Optional<CompilationError> maybeError = trackMandatoryParsing(link.get(), mapping); if (maybeError.isPresent()) { return compilationError(method, CompilationError.TOO_MANY_SELF.format(qualified(method))); } return Optional.of(mapping); }
ElementParser { public Optional<Mapping> parse(Element element) { if (element.getKind() != ElementKind.METHOD) { return compilationError(element, CompilationError.NOT_A_METHOD.format(element)); } ExecutableElement method = (ExecutableElement) element; Optional<String> maybePath = pathVisitor.visitPath(method); if (!maybePath.isPresent()) { return compilationError(method, CompilationError.NO_PATH_FOUND.format(qualified(method))); } Optional<HttpVerb> maybeHttpVerb = httpVerbVisitor.visit(method); if (!maybeHttpVerb.isPresent()) { return compilationError(method, CompilationError.NO_HTTP_ANNOTATION_FOUND.format(qualified(method))); } boolean withSelf = byAnnotation(Self.class).test(method); boolean withSubResource = byAnnotation(SubResource.class).test(method); if (!(withSelf ^ withSubResource)) { return compilationError(method, CompilationError.ANNOTATION_MISUSE.format(qualified(method))); } Optional<ApiLink> link = link(method, withSelf); if (!link.isPresent()) { return compilationError(method, CompilationError.MISSING_ANNOTATIONS.format(qualified(method))); } Mapping mapping = mapping(method, link.get(), maybeHttpVerb.get(), maybePath.get()); Optional<CompilationError> maybeError = trackMandatoryParsing(link.get(), mapping); if (maybeError.isPresent()) { return compilationError(method, CompilationError.TOO_MANY_SELF.format(qualified(method))); } return Optional.of(mapping); } }
ElementParser { public Optional<Mapping> parse(Element element) { if (element.getKind() != ElementKind.METHOD) { return compilationError(element, CompilationError.NOT_A_METHOD.format(element)); } ExecutableElement method = (ExecutableElement) element; Optional<String> maybePath = pathVisitor.visitPath(method); if (!maybePath.isPresent()) { return compilationError(method, CompilationError.NO_PATH_FOUND.format(qualified(method))); } Optional<HttpVerb> maybeHttpVerb = httpVerbVisitor.visit(method); if (!maybeHttpVerb.isPresent()) { return compilationError(method, CompilationError.NO_HTTP_ANNOTATION_FOUND.format(qualified(method))); } boolean withSelf = byAnnotation(Self.class).test(method); boolean withSubResource = byAnnotation(SubResource.class).test(method); if (!(withSelf ^ withSubResource)) { return compilationError(method, CompilationError.ANNOTATION_MISUSE.format(qualified(method))); } Optional<ApiLink> link = link(method, withSelf); if (!link.isPresent()) { return compilationError(method, CompilationError.MISSING_ANNOTATIONS.format(qualified(method))); } Mapping mapping = mapping(method, link.get(), maybeHttpVerb.get(), maybePath.get()); Optional<CompilationError> maybeError = trackMandatoryParsing(link.get(), mapping); if (maybeError.isPresent()) { return compilationError(method, CompilationError.TOO_MANY_SELF.format(qualified(method))); } return Optional.of(mapping); } ElementParser(Messager messager,
                         Types typeUtils); }
ElementParser { public Optional<Mapping> parse(Element element) { if (element.getKind() != ElementKind.METHOD) { return compilationError(element, CompilationError.NOT_A_METHOD.format(element)); } ExecutableElement method = (ExecutableElement) element; Optional<String> maybePath = pathVisitor.visitPath(method); if (!maybePath.isPresent()) { return compilationError(method, CompilationError.NO_PATH_FOUND.format(qualified(method))); } Optional<HttpVerb> maybeHttpVerb = httpVerbVisitor.visit(method); if (!maybeHttpVerb.isPresent()) { return compilationError(method, CompilationError.NO_HTTP_ANNOTATION_FOUND.format(qualified(method))); } boolean withSelf = byAnnotation(Self.class).test(method); boolean withSubResource = byAnnotation(SubResource.class).test(method); if (!(withSelf ^ withSubResource)) { return compilationError(method, CompilationError.ANNOTATION_MISUSE.format(qualified(method))); } Optional<ApiLink> link = link(method, withSelf); if (!link.isPresent()) { return compilationError(method, CompilationError.MISSING_ANNOTATIONS.format(qualified(method))); } Mapping mapping = mapping(method, link.get(), maybeHttpVerb.get(), maybePath.get()); Optional<CompilationError> maybeError = trackMandatoryParsing(link.get(), mapping); if (maybeError.isPresent()) { return compilationError(method, CompilationError.TOO_MANY_SELF.format(qualified(method))); } return Optional.of(mapping); } ElementParser(Messager messager,
                         Types typeUtils); Optional<Mapping> parse(Element element); }
ElementParser { public Optional<Mapping> parse(Element element) { if (element.getKind() != ElementKind.METHOD) { return compilationError(element, CompilationError.NOT_A_METHOD.format(element)); } ExecutableElement method = (ExecutableElement) element; Optional<String> maybePath = pathVisitor.visitPath(method); if (!maybePath.isPresent()) { return compilationError(method, CompilationError.NO_PATH_FOUND.format(qualified(method))); } Optional<HttpVerb> maybeHttpVerb = httpVerbVisitor.visit(method); if (!maybeHttpVerb.isPresent()) { return compilationError(method, CompilationError.NO_HTTP_ANNOTATION_FOUND.format(qualified(method))); } boolean withSelf = byAnnotation(Self.class).test(method); boolean withSubResource = byAnnotation(SubResource.class).test(method); if (!(withSelf ^ withSubResource)) { return compilationError(method, CompilationError.ANNOTATION_MISUSE.format(qualified(method))); } Optional<ApiLink> link = link(method, withSelf); if (!link.isPresent()) { return compilationError(method, CompilationError.MISSING_ANNOTATIONS.format(qualified(method))); } Mapping mapping = mapping(method, link.get(), maybeHttpVerb.get(), maybePath.get()); Optional<CompilationError> maybeError = trackMandatoryParsing(link.get(), mapping); if (maybeError.isPresent()) { return compilationError(method, CompilationError.TOO_MANY_SELF.format(qualified(method))); } return Optional.of(mapping); } ElementParser(Messager messager,
                         Types typeUtils); Optional<Mapping> parse(Element element);  }