Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.TypeElement;
Expand Down Expand Up @@ -110,6 +111,12 @@ public ProcessResult process(AnnotationElements validatedModel) throws Exception
enclosingElement = annotatedElement;
} else {
enclosingElement = annotatedElement.getEnclosingElement();
/*
* we are processing a method parameter
*/
if (enclosingElement instanceof ExecutableElement) {
enclosingElement = enclosingElement.getEnclosingElement();
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
* from a method parameter. The annotation value should be the name of the
* form-encoded parameter, if not specified, the method parameter name will be
* used as the name of the form-encoded parameter. This annotation only can be
* used with POST requests, hence the method must be annotated with {@link Post}
* . To use this annotation, you must add <code>FormHttpMessageConverter</code>
* to the list of converters.
* used with a method which be annotated with {@link Post}, {@link Put} or
* {@link Patch}. To use this annotation, you must add
* <code>FormHttpMessageConverter</code> to the list of converters.
*
* <blockquote>
*
Expand All @@ -46,6 +46,8 @@
*
* @see Rest
* @see Post
* @see Put
* @see Patch
* @see Part
*/
@Retention(RetentionPolicy.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import java.lang.annotation.Target;

/**
* This annotation can be used to add a multi-part parameter to the POST request
* from a method parameter. The annotation value should be the name of the
* multi-part parameter, if not specified, the method parameter name will be
* used as the name of the multi-part parameter. This annotation only can be
* used with POST requests, hence the method must be annotated with {@link Post}
* . To use this annotation, you must add <code>FormHttpMessageConverter</code>
* to the list of converters.
* This annotation can be used to add a multi-part parameter to the POST, PUT or
* PATCH request from a method parameter. The annotation value should be the
* name of the multi-part parameter, if not specified, the method parameter name
* will be used as the name of the multi-part parameter. This annotation only
* can be used with a method which be annotated with {@link Post}, {@link Put}
* or {@link Patch}. To use this annotation, you must add
* <code>FormHttpMessageConverter</code> to the list of converters.
*
* <blockquote>
*
Expand All @@ -44,9 +44,11 @@
*
* </blockquote>
*
* @see Post
* @see Part
* @see Rest
* @see Post
* @see Put
* @see Patch
* @see Field
*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.PARAMETER)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* 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.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* <p>
* Use on methods in {@link Rest} annotated class to add a new rest service of
* type PATCH.
* </p>
* <p>
* This annotation as the EXACT same constraints as {@link Post}.
* </p>
* <blockquote>
*
* <b>Example :</b>
*
* <pre>
* &#064;Rest(rootUrl = &quot;http://myserver&quot;, converters = MappingJacksonHttpMessageConverter.class)
* public interface MyRestClient {
*
* &#064;Patch(&quot;/events/update/last&quot;)
* Event updateEvent();
*
* &#064;Patch(&quot;/events/update/<b>{id}</b>&quot;)
* void updateEvent(Event <i>event</i>, int <b>id</b>);
* }
* </pre>
*
* </blockquote>
*
* @see Rest
* @see Put
* @see Get
* @see Post
* @see Delete
* @see Head
* @see Options
*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface Patch {

/**
* The URI or the full URL of the web service.
*
* @return the address of the web service
*/
String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import org.androidannotations.handler.AnnotationHandler;
import org.androidannotations.plugin.AndroidAnnotationsPlugin;
import org.androidannotations.rest.spring.handler.DeleteHandler;
import org.androidannotations.rest.spring.handler.FieldHandler;
import org.androidannotations.rest.spring.handler.GetHandler;
import org.androidannotations.rest.spring.handler.HeadHandler;
import org.androidannotations.rest.spring.handler.HeaderHandler;
import org.androidannotations.rest.spring.handler.HeadersHandler;
import org.androidannotations.rest.spring.handler.OptionsHandler;
import org.androidannotations.rest.spring.handler.PartHandler;
import org.androidannotations.rest.spring.handler.PatchHandler;
import org.androidannotations.rest.spring.handler.PathHandler;
import org.androidannotations.rest.spring.handler.PostHandler;
import org.androidannotations.rest.spring.handler.PutHandler;
Expand All @@ -46,9 +49,12 @@ public String getName() {
public List<AnnotationHandler<?>> getHandlers(AndroidAnnotationsEnvironment androidAnnotationEnv) {
List<AnnotationHandler<?>> annotationHandlers = new ArrayList<>();
annotationHandlers.add(new RestHandler(androidAnnotationEnv));
annotationHandlers.add(new FieldHandler(androidAnnotationEnv));
annotationHandlers.add(new PartHandler(androidAnnotationEnv));
annotationHandlers.add(new GetHandler(androidAnnotationEnv));
annotationHandlers.add(new PostHandler(androidAnnotationEnv));
annotationHandlers.add(new PutHandler(androidAnnotationEnv));
annotationHandlers.add(new PatchHandler(androidAnnotationEnv));
annotationHandlers.add(new DeleteHandler(androidAnnotationEnv));
annotationHandlers.add(new HeadHandler(androidAnnotationEnv));
annotationHandlers.add(new OptionsHandler(androidAnnotationEnv));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* 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.handler;

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.List;

import javax.lang.model.element.Element;

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.handler.BaseAnnotationHandler;
import org.androidannotations.holder.GeneratedClassHolder;
import org.androidannotations.rest.spring.annotations.Patch;
import org.androidannotations.rest.spring.annotations.Post;
import org.androidannotations.rest.spring.annotations.Put;
import org.androidannotations.rest.spring.helper.RestSpringValidatorHelper;

abstract class AbstractParamHandler extends BaseAnnotationHandler<GeneratedClassHolder> {

public static final List<Class<? extends Annotation>> REST_METHOD_ANNOTATIONS_WITH_PARAM = Arrays.asList(Post.class, Put.class, Patch.class);

protected final RestSpringValidatorHelper restSpringValidatorHelper;

AbstractParamHandler(Class<?> targetClass, AndroidAnnotationsEnvironment environment) {
super(targetClass, environment);
restSpringValidatorHelper = new RestSpringValidatorHelper(environment, getTarget());
}

@Override
protected void validate(Element element, ElementValidation validation) {
validatorHelper.enclosingElementHasOneOfAnnotations(element, REST_METHOD_ANNOTATIONS_WITH_PARAM, validation);

restSpringValidatorHelper.doesNotHavePathAnnotation(element, validation);

restSpringValidatorHelper.restInterfaceHasFormConverter(element, validation);
}

@Override
public void process(Element element, GeneratedClassHolder holder) throws Exception {
// Don't do anything here.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* 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.handler;

import java.util.Map;
import java.util.SortedMap;

import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.rest.spring.helper.RestSpringClasses;
import org.androidannotations.rest.spring.holder.RestHolder;

import com.helger.jcodemodel.AbstractJClass;
import com.helger.jcodemodel.IJExpression;
import com.helger.jcodemodel.JBlock;
import com.helger.jcodemodel.JExpr;
import com.helger.jcodemodel.JVar;

public abstract class AbstractRestMethodWithParameterHandler extends RestMethodHandler {

public AbstractRestMethodWithParameterHandler(Class<?> targetClass, AndroidAnnotationsEnvironment environment) {
super(targetClass, environment);
}

@Override
public void validate(Element element, ElementValidation validation) {
super.validate(element, validation);

validatorHelper.doesNotReturnPrimitive((ExecutableElement) element, validation);

restSpringValidatorHelper.urlVariableNamesExistInParametersAndHasOnlyOneEntityParameterOrOneOrMoreParameter((ExecutableElement) element, validation);

restSpringValidatorHelper.doesNotMixPartAndFieldAnnotations((ExecutableElement) element, validation);
}

@Override
protected IJExpression getRequestEntity(ExecutableElement element, RestHolder holder, JBlock methodBody, SortedMap<String, JVar> params) {
JVar httpHeaders = restAnnotationHelper.declareHttpHeaders(element, holder, methodBody);
JVar entitySentToServer = restAnnotationHelper.getEntitySentToServer(element, params);

if (entitySentToServer == null) {
Map<String, String> parameters = restAnnotationHelper.extractFieldAndPartParameters(element);

if (parameters != null) {
AbstractJClass hashMapClass = getJClass(RestSpringClasses.LINKED_MULTI_VALUE_MAP).narrow(String.class, Object.class);
entitySentToServer = methodBody.decl(hashMapClass, "parameters", JExpr._new(hashMapClass));

for (Map.Entry<String, String> parameter : parameters.entrySet()) {
methodBody.add(entitySentToServer.invoke("add").arg(JExpr.lit(parameter.getKey())).arg(params.get(parameter.getValue())));
}
}
}

return restAnnotationHelper.declareHttpEntity(methodBody, entitySentToServer, httpHeaders);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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.handler;

import javax.lang.model.element.Element;

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.rest.spring.annotations.Field;

public class FieldHandler extends AbstractParamHandler {

public FieldHandler(AndroidAnnotationsEnvironment environment) {
super(Field.class, environment);
}

@Override
protected void validate(Element element, ElementValidation validation) {
super.validate(element, validation);

restSpringValidatorHelper.doesNotHavePartAnnotation(element, validation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* 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.handler;

import javax.lang.model.element.Element;

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.rest.spring.annotations.Part;

public class PartHandler extends AbstractParamHandler {

public PartHandler(AndroidAnnotationsEnvironment environment) {
super(Part.class, environment);
}

@Override
protected void validate(Element element, ElementValidation validation) {
super.validate(element, validation);

restSpringValidatorHelper.doesNotHaveFieldAnnotation(element, validation);
}
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.