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
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2010-2013 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.annotations.rest;

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

@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface RequiresAuthentication {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2010-2013 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.annotations.rest;

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

@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface RequiresCookie {
public String[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2010-2013 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.annotations.rest;

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

@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface RequiresCookieInUrl {
public String[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2010-2013 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.annotations.rest;

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

@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface RequiresHeader {
String[] value();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2010-2013 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.annotations.rest;

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

@Retention(RetentionPolicy.CLASS)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface SetsCookie {

public String[] value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;

import org.androidannotations.processing.rest.MethodProcessor;
import org.androidannotations.validation.IsValid;

public class RestAnnotationHelper extends TargetAnnotationHelper {
Expand All @@ -43,6 +44,13 @@ public void urlVariableNamesExistInParameters(ExecutableElement element, Set<Str
parametersName.add(parameter.getSimpleName().toString());
}

String[] cookiesToUrl = MethodProcessor.retrieveRequiredUrlCookieNames(element);
if (cookiesToUrl != null) {
for (String cookie : cookiesToUrl) {
parametersName.add(cookie);
}
}

for (String variableName : variableNames) {
if (!parametersName.contains(variableName)) {
valid.invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public class ValidatorHelper {
private static final List<String> ANDROID_FRAGMENT_QUALIFIED_NAMES = asList(CanonicalNameConstants.FRAGMENT, CanonicalNameConstants.SUPPORT_V4_FRAGMENT);

private static final String METHOD_NAME_SET_ROOT_URL = "setRootUrl";
private static final String METHOD_NAME_SET_AUTHENTICATION = "setAuthentication";
private static final String METHOD_NAME_GET_COOKIE = "getCookie";
private static final String METHOD_NAME_GET_HEADER = "getHeader";

private static final String METHOD_NAME_GET_ROOT_URL = "getRootUrl";

Expand Down Expand Up @@ -781,7 +784,10 @@ public void unannotatedMethodReturnsRestTemplate(TypeElement typeElement, IsVali
List<? extends Element> enclosedElements = typeElement.getEnclosedElements();
boolean foundGetRestTemplateMethod = false;
boolean foundSetRestTemplateMethod = false;
boolean foundSetAuthenticationMethod = false;
boolean foundSetRootUrlMethod = false;
boolean foundGetCookieMethod = false;
boolean foundGetHeaderMethod = false;
boolean foundGetRootUrlMethod = false;

for (Element enclosedElement : enclosedElements) {
Expand Down Expand Up @@ -847,15 +853,46 @@ public void unannotatedMethodReturnsRestTemplate(TypeElement typeElement, IsVali
}
} else if (executableElement.getSimpleName().toString().equals(METHOD_NAME_SET_ROOT_URL) && !foundSetRootUrlMethod) {
foundSetRootUrlMethod = true;
} else if (executableElement.getSimpleName().toString().equals(METHOD_NAME_SET_AUTHENTICATION) && !foundSetAuthenticationMethod) {
foundSetAuthenticationMethod = true;
} else {
valid.invalidate();
annotationHelper.printError(enclosedElement, "The method to set a RestTemplate should have only one RestTemplate parameter on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface");

}
} else if (parameters.size() == 2) {
VariableElement firstParameter = parameters.get(0);
VariableElement secondParameter = parameters.get(1);
if (!(firstParameter.asType().toString().equals(CanonicalNameConstants.STRING) && secondParameter.asType().toString().equals(CanonicalNameConstants.STRING))) {
valid.invalidate();
annotationHelper.printError(enclosedElement, "The method to set headers, cookies, or HTTP Basic Auth should have only String parameters on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface");
}
} else {
valid.invalidate();
annotationHelper.printError(enclosedElement, "The method to set a RestTemplate should have only one RestTemplate parameter on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface");
}
} else if (returnType.toString().equals(CanonicalNameConstants.STRING)) {
List<? extends VariableElement> parameters = executableElement.getParameters();
if (parameters.size() == 1) {
VariableElement firstParameter = parameters.get(0);
if (firstParameter.asType().toString().equals(CanonicalNameConstants.STRING)) {
if (executableElement.getSimpleName().toString().equals(METHOD_NAME_GET_COOKIE) && !foundGetCookieMethod) {
foundGetCookieMethod = true;
} else if (executableElement.getSimpleName().toString().equals(METHOD_NAME_GET_HEADER) && !foundGetHeaderMethod) {
foundGetHeaderMethod = true;
} else {
valid.invalidate();
annotationHelper.printError(enclosedElement, "Only one getCookie(String) and one getHeader(String) method are allowed on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface");
}
} else {
valid.invalidate();
annotationHelper.printError(enclosedElement, "Only getCookie(String) and getHeader(String) can return a String on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface");
}

} else {
valid.invalidate();
annotationHelper.printError(enclosedElement, "The only methods that can return a String on a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface are getCookie(String) and getHeader(String)");
}
} else {
valid.invalidate();
annotationHelper.printError(enclosedElement, "All methods should be annotated in a " + TargetAnnotationHelper.annotationName(Rest.class) + " annotated interface, except the ones that returns or set a RestTemplate");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JExpression;
import com.sun.codemodel.JInvocation;
import com.sun.codemodel.JPackage;

Expand Down Expand Up @@ -267,7 +268,7 @@ protected JInvocation addResponseEntityArg(JInvocation restCall, MethodProcessor
}

@Override
protected JInvocation addResultCallMethod(JInvocation restCall, MethodProcessorHolder methodHolder) {
protected JExpression addResultCallMethod(JExpression restCall, MethodProcessorHolder methodHolder) {
JClass generatedReturnType = methodHolder.getMethodReturnClass();
if (generatedReturnType == null) {
return restCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected JExpression generateHttpEntityVar(MethodProcessorHolder methodHolder)
JClass httpEntity = holder.refClass(CanonicalNameConstants.HTTP_ENTITY);

JBlock body = methodHolder.getBody();
JVar httpHeadersVar = generateHttpHeadersVar(holder, body, executableElement);
JVar httpHeadersVar = generateHttpHeadersVar(methodHolder, holder, body, executableElement);

boolean hasHeaders = httpHeadersVar != null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.sun.codemodel.JClass;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JInvocation;
import com.sun.codemodel.JExpression;

public class HeadProcessor extends MethodProcessor {

Expand Down Expand Up @@ -55,7 +55,7 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) t
}

@Override
protected JInvocation addResultCallMethod(JInvocation restCall, MethodProcessorHolder methodHolder) {
protected JExpression addResultCallMethod(JExpression restCall, MethodProcessorHolder methodHolder) {
return JExpr.invoke(restCall, "getHeaders");
}

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.