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.processing;
import static com.sun.codemodel.JMod.FINAL;
import static com.sun.codemodel.JMod.PRIVATE;
import static com.sun.codemodel.JMod.PUBLIC;
public class EReceiverProcessor extends AnnotationHelper implements ElementProcessor {
	public EReceiverProcessor(ProcessingEnvironment processingEnv) {
		super(processingEnv);
	}
	public Class<? extends AnnotationgetTarget() {
		return EReceiver.class;
	}
	public void process(Element elementJCodeModel codeModelEBeansHolder activitiesHolderthrows Exception {
		EBeanHolder holder = activitiesHolder.create(element);
		TypeElement typeElement = (TypeElementelement;
		String annotatedComponentQualifiedName = typeElement.getQualifiedName().toString();
		String generatedComponentQualifiedName = annotatedComponentQualifiedName + .;
		holder.eBean = codeModel._class( | generatedComponentQualifiedName.);
		JClass annotatedComponent = codeModel.directClass(annotatedComponentQualifiedName);
		holder.eBean._extends(annotatedComponent);
		JClass contextClass = holder.refClass("android.content.Context");
		JFieldVar contextField = holder.eBean.field(contextClass"context_");
		holder.contextRef = contextField;
		holder.init = holder.eBean.method(codeModel.VOID"init_");
		{
			// onReceive
			JClass intentClass = holder.refClass("android.content.Intent");
			JMethod onReceive = holder.eBean.method(codeModel.VOID"onReceive");
			JVar contextParam = onReceive.param(contextClass"context");
			JVar intentParam = onReceive.param(intentClass"intent");
			onReceive.annotate(Override.class);
			JBlock onReceiveBody = onReceive.body();
			onReceiveBody.assign(contextFieldcontextParam);
			onReceiveBody.invoke(holder.init);
			onReceiveBody.invoke(JExpr._super(), onReceive).arg(contextParam).arg(intentParam);
		}
		{
			/*
			 * Setting to null shouldn't be a problem as long as we don't allow
			 * @App and @Extra on this component
			 */
			holder.initIfActivityBody = null;
			holder.initActivityRef = null;
		}
	}
New to GrepCode? Check out our FAQ X