From 37bf039a090aef638950cd2070493d2f2a4253e0 Mon Sep 17 00:00:00 2001 From: WonderCsabo Date: Sun, 11 Oct 2015 12:12:15 +0200 Subject: [PATCH 1/2] Add @Patch to list of annotations in validator --- .../rest/spring/helper/RestSpringValidatorHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java index 67305834ff..fa3672d42a 100644 --- a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java +++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java @@ -55,6 +55,7 @@ import org.androidannotations.rest.spring.annotations.Head; import org.androidannotations.rest.spring.annotations.Options; import org.androidannotations.rest.spring.annotations.Part; +import org.androidannotations.rest.spring.annotations.Patch; import org.androidannotations.rest.spring.annotations.Path; import org.androidannotations.rest.spring.annotations.Post; import org.androidannotations.rest.spring.annotations.Put; @@ -68,7 +69,7 @@ public class RestSpringValidatorHelper extends ValidatorHelper { private static final List VALID_REST_INTERFACES = asList(RestClientHeaders.class.getName(), RestClientErrorHandling.class.getName(), RestClientRootUrl.class.getName(), RestClientSupport.class.getName()); - private static final List> REST_ANNOTATION_CLASSES = Arrays.asList(Get.class, Head.class, Options.class, Post.class, Put.class, Delete.class); + private static final List> REST_ANNOTATION_CLASSES = Arrays.asList(Get.class, Head.class, Options.class, Post.class, Put.class, Patch.class, Delete.class); private static final String METHOD_NAME_SET_ROOT_URL = "setRootUrl"; private static final String METHOD_NAME_SET_AUTHENTICATION = "setAuthentication"; From d28e4480c780973ded935962231068fbc1fe69c4 Mon Sep 17 00:00:00 2001 From: WonderCsabo Date: Sun, 11 Oct 2015 12:21:35 +0200 Subject: [PATCH 2/2] Fix checking Spring Android 2 is on the classpath --- .../helper/RestSpringValidatorHelper.java | 2 +- .../rest/spring/ClientWithPatch.java | 28 +++++++++++++++++++ .../rest/spring/RestTest.java | 8 ++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithPatch.java diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java index fa3672d42a..a19ffc3588 100644 --- a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java +++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/main/java/org/androidannotations/rest/spring/helper/RestSpringValidatorHelper.java @@ -570,7 +570,7 @@ public void elementHasOneOfRestMethodAnnotations(Element element, ElementValidat } public void usesSpringAndroid2(Element element, ElementValidation validation) { - if (environment().getProcessingEnvironment().getElementUtils().getTypeElement(RestSpringClasses.PARAMETERIZED_TYPE_REFERENCE) != null) { + if (environment().getProcessingEnvironment().getElementUtils().getTypeElement(RestSpringClasses.PARAMETERIZED_TYPE_REFERENCE) == null) { validation.addError(element, "To use %s annotated method you must add Spring Android Rest Template 2.0 to your classpath"); } } diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithPatch.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithPatch.java new file mode 100644 index 0000000000..710d8c0c37 --- /dev/null +++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/ClientWithPatch.java @@ -0,0 +1,28 @@ +/** + * Copyright (C) 2010-2015 eBusiness Information, Excilys Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.androidannotations.rest.spring; + + +import org.androidannotations.rest.spring.annotations.Patch; +import org.androidannotations.rest.spring.annotations.Rest; +import org.springframework.http.converter.StringHttpMessageConverter; + +@Rest(converters = StringHttpMessageConverter.class) +public interface ClientWithPatch { + + @Patch("/") + void patchMethod(String entity); +} diff --git a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/RestTest.java b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/RestTest.java index 9287e8df53..bf4e8576fd 100644 --- a/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/RestTest.java +++ b/AndroidAnnotations/androidannotations-rest-spring/rest-spring/src/test/java/org/androidannotations/rest/spring/RestTest.java @@ -155,4 +155,12 @@ public void clientWithAllInterfaces() throws IOException { CompileResult result = compileFiles(ClientWithAllInterfaces.class); assertCompilationSuccessful(result); } + + @Test + public void patchWithoutSpring2DoesNotCompile() throws IOException { + CompileResult result = compileFiles(ClientWithPatch.class); + + assertCompilationErrorOn(ClientWithPatch.class, "@Patch(\"/\")", result); + assertCompilationErrorCount(1, result); + } }