Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2010-2012 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 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.processing;
import static com.sun.codemodel.JExpr.invoke;
import static com.sun.codemodel.JExpr.ref;
public class ResProcessor implements ElementProcessor {
	private final IRClass rClass;
	private final AndroidRes androidValue;
	public ResProcessor(AndroidRes androidValueIRClass rClass) {
		this. = rClass;
		this. = androidValue;
	public Class<? extends AnnotationgetTarget() {
	public void process(Element elementJCodeModel codeModelEBeansHolder eBeansHolder) {
		EBeanHolder holder = eBeansHolder.getEnclosingEBeanHolder(element);
		Classes classes = holder.classes();
		String fieldName = element.getSimpleName().toString();
		int idValue = .idFromElement(element);
		Res resInnerClass = .getRInnerClass();
		IRInnerClass rInnerClass = .get(resInnerClass);
		JFieldRef idRef;
		if (idValue == .) {
			idRef = rInnerClass.getIdStaticRef(fieldNameholder);
else {
			idRef = rInnerClass.getIdStaticRef(idValueholder);
		JBlock methodBody = holder.init.body();
		TypeMirror fieldTypeMirror = element.asType();
		String fieldType = fieldTypeMirror.toString();
		// Special case for loading animations
			methodBody.assign(ref(fieldName), classes.ANIMATION_UTILS.staticInvoke("loadAnimation").arg(holder.contextRef).arg(idRef));
else {
			if (holder.resources == null) {
				holder.resources = methodBody.decl(classes.RESOURCES"resources_"holder.contextRef.invoke("getResources"));
			String resourceMethodName = .getResourceMethodName();
			// Special case for @HtmlRes
			if (element.getAnnotation(HtmlRes.class) != null) {
				methodBody.assign(ref(fieldName), classes.HTML.staticInvoke("fromHtml").arg(invoke(holder.resourcesresourceMethodName).arg(idRef)));
else {
				methodBody.assign(ref(fieldName), invoke(holder.resourcesresourceMethodName).arg(idRef));
New to GrepCode? Check out our FAQ X