Skip to content
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 1 commit
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
Prev Previous commit
Next Next commit
Extract Field and Part handlers
  • Loading branch information
simopete committed Oct 10, 2015
commit 184c5eea578ff35742ff44191d7653a788449578
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
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.PathHandler;
import org.androidannotations.rest.spring.handler.PostHandler;
import org.androidannotations.rest.spring.handler.PutHandler;
Expand All @@ -46,6 +48,8 @@ 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));
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,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package org.androidannotations.rest.spring.handler;

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

Expand All @@ -24,12 +23,6 @@

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.handler.AnnotationHandler;
import org.androidannotations.handler.BaseAnnotationHandler;
import org.androidannotations.handler.HasParameterHandlers;
import org.androidannotations.holder.GeneratedClassHolder;
import org.androidannotations.rest.spring.annotations.Field;
import org.androidannotations.rest.spring.annotations.Part;
import org.androidannotations.rest.spring.annotations.Post;
import org.androidannotations.rest.spring.helper.RestSpringClasses;
import org.androidannotations.rest.spring.holder.RestHolder;
Expand All @@ -40,20 +33,10 @@
import com.helger.jcodemodel.JExpr;
import com.helger.jcodemodel.JVar;

public class PostHandler extends RestMethodHandler implements HasParameterHandlers<RestHolder> {

private FieldHandler fieldHandler;
private PartHandler partHandler;
public class PostHandler extends RestMethodHandler {

public PostHandler(AndroidAnnotationsEnvironment environment) {
super(Post.class, environment);
fieldHandler = new FieldHandler(environment);
partHandler = new PartHandler(environment);
}

@Override
public Iterable<AnnotationHandler> getParameterHandlers() {
return Arrays.<AnnotationHandler> asList(fieldHandler, partHandler);
}

@Override
Expand Down Expand Up @@ -93,53 +76,4 @@ protected IJExpression getRequestEntity(ExecutableElement element, RestHolder ho

return restAnnotationHelper.declareHttpEntity(methodBody, entitySentToServer, httpHeaders);
}

private abstract class AbstractPostParamHandler extends BaseAnnotationHandler<GeneratedClassHolder> {

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

@Override
protected void validate(Element element, ElementValidation validation) {
validatorHelper.enclosingElementHasAnnotation(Post.class, element, validation);

restSpringValidatorHelper.doesNotHavePathAnnotation(element, validation);

restSpringValidatorHelper.restInterfaceHasFormConverter(element, validation);
}

@Override
public void process(Element element, GeneratedClassHolder holder) throws Exception {
// Don't do anything here.
}
}

public class FieldHandler extends AbstractPostParamHandler {

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

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

restSpringValidatorHelper.doesNotHavePartAnnotation(element, validation);
}
}

public class PartHandler extends AbstractPostParamHandler {

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

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

restSpringValidatorHelper.doesNotHaveFieldAnnotation(element, validation);
}
}
}