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 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.processing;
import static com.sun.codemodel.JExpr._new;
import static com.sun.codemodel.JExpr._null;
import static com.sun.codemodel.JExpr.invoke;

Author(s):
Mathieu Boniface
Pierre-Yves
public class ClickProcessor implements ElementProcessor {
	private final IdAnnotationHelper helper;
	public ClickProcessor(ProcessingEnvironment processingEnvIRClass rClass) {
		 = new IdAnnotationHelper(processingEnvgetTarget(), rClass);
	}
	public Class<? extends AnnotationgetTarget() {
		return Click.class;
	}
	public void process(Element elementJCodeModel codeModelEBeansHolder activitiesHolder) {
		EBeanHolder holder = activitiesHolder.getEnclosingEBeanHolder(element);
		Classes classes = holder.classes();
		String methodName = element.getSimpleName().toString();
		ExecutableElement executableElement = (ExecutableElementelement;
		List<? extends VariableElementparameters = executableElement.getParameters();
		boolean hasViewParameter = parameters.size() == 1;
		Click annotation = element.getAnnotation(Click.class);
		List<JFieldRefidsRefs = .extractFieldRefsFromAnnotationValues(elementannotation.value(), "Clicked"holder);
		JDefinedClass onClickListenerClass = codeModel.anonymousClass(classes.VIEW_ON_CLICK_LISTENER);
		JMethod onClickMethod = onClickListenerClass.method(.codeModel.VOID"onClick");
		onClickMethod.annotate(Override.class);
		JVar onClickViewParam = onClickMethod.param(classes.VIEW"view");
		JExpression activityRef = holder.eBean.staticRef("this");
		JInvocation clickCall = onClickMethod.body().invoke(activityRefmethodName);
		if (hasViewParameter) {
			clickCall.arg(onClickViewParam);
		}
		for (JFieldRef idRef : idsRefs) {
			JBlock block = holder.afterSetContentView.body().block();
			JInvocation findViewById = invoke("findViewById");
			JVar view = block.decl(classes.VIEW"view"findViewById.arg(idRef));
			block._if(view.ne(_null()))._then().invoke(view"setOnClickListener").arg(_new(onClickListenerClass));
		}
	}
New to GrepCode? Check out our FAQ X