Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2010-2011 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 com.googlecode.androidannotations.helper;
 
 import java.util.List;
 
 
 
 public class RestAnnotationHelper extends TargetAnnotationHelper {
 
 	public RestAnnotationHelper(ProcessingEnvironment processingEnvClass<? extends Annotationtarget) {
 		super(processingEnvtarget);
 	}
 
 	public void urlVariableNamesExistInParameters(ExecutableElement elementList<StringvariableNamesIsValid valid) {
 
 		List<? extends VariableElementparameters = element.getParameters();
 
 		List<StringparametersName = new ArrayList<String>();
 		for (VariableElement parameter : parameters) {
 			parametersName.add(parameter.getSimpleName().toString());
 		}
 
 		for (String variableName : variableNames) {
 			if (!parametersName.contains(variableName)) {
 				valid.invalidate();
 				printAnnotationError(element"%s annotated method has an url variable which name could not be found in the method parameters: " + variableName);
 				return;
 			}
 		}
 	}
 
 		if (valid.isValid()) {
 			List<StringvariableNames = extractUrlVariableNames(element);
 			urlVariableNamesExistInParameters(elementvariableNamesvalid);
 			if (valid.isValid()) {
 				List<? extends VariableElementparameters = element.getParameters();
 
 				if (parameters.size() > variableNames.size()) {
 					valid.invalidate();
 					printAnnotationError(element"%s annotated method has only url variables in the method parameters");
 				}
 			}
 		}
 	}
 	
 		if (valid.isValid()) {
 			List<StringvariableNames = extractUrlVariableNames(element);
 			urlVariableNamesExistInParameters(elementvariableNamesvalid);
 			if (valid.isValid()) {
 				List<? extends VariableElementparameters = element.getParameters();
 
 				if (parameters.size() > variableNames.size() + 1) {
 					valid.invalidate();
 					printAnnotationError(element"%s annotated method has more than one entity parameter");
 				}
 			}
 		}
 	}

Captures URI template variable names.
 
 	private static final Pattern NAMES_PATTERN = Pattern.compile("\\{([^/]+?)\\}");
 
 
 		// extract variables name from root url isn't really useful
 
 		// Element enclosingElement = element.getEnclosingElement();
 		// String urlPrefix =
 		// enclosingElement.getAnnotation(Rest.class).value();
 		// String urlSuffix = extractAnnotationValue(element);
 		// String uriTemplate = urlPrefix + urlSuffix;
 
 		List<StringvariableNames = new ArrayList<String>();
 		String uriTemplate = extractAnnotationValue(element);
 
		boolean hasValueInAnnotation = uriTemplate != null;
		if (hasValueInAnnotation) {
			Matcher m = .matcher(uriTemplate);
			while (m.find()) {
				variableNames.add(m.group(1));
			}
		}
		return variableNames;
	}
New to GrepCode? Check out our FAQ X