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.PRIVATE;
 import static com.sun.codemodel.JMod.PUBLIC;
 
 
 
 
 public class EViewGroupProcessor extends AnnotationHelper implements ElementProcessor {
 
 	private static final String ALREADY_INFLATED_COMMENT = "" // +
 			+ "The mAlreadyInflated_ hack is needed because of an Android bug\n" // +
 			+ "which leads to infinite calls of onFinishInflate()\n" //
 			+ "when inflating a layout with a parent and using\n" //
 			+ "the <merge /> tag." //
 	;
 
 	private static final String SUPPRESS_WARNING_COMMENT = "" //
 			+ "We use @SuppressWarning here because our java code\n" //
 			+ "generator doesn't know that there is no need\n" //
 			+ "to import OnXXXListeners from View as we already\n" //
 			+ "are in a View." //
 	;
 
 	private final IRClass rClass;
 
 
 	public EViewGroupProcessor(ProcessingEnvironment processingEnvIRClass rClass) {
 		super(processingEnv);
 		this. = rClass;
 	}
 
 	public Class<? extends AnnotationgetTarget() {
 		return EViewGroup.class;
 	}
 
 	public void process(Element elementJCodeModel codeModelEBeansHolder eBeansHolderthrows Exception {
 
 		EBeanHolder holder = eBeansHolder.create(element);
 
 		TypeElement typeElement = (TypeElementelement;
 
 		String eBeanQualifiedName = typeElement.getQualifiedName().toString();
 
 		String generatedBeanQualifiedName = eBeanQualifiedName + .;
 
 		int modifiers;
 		if (element.getModifiers().contains(.)) {
 			modifiers = . | .;
 		} else {
 			modifiers = . | .;
 		}
 
 		holder.eBean = codeModel._class(modifiersgeneratedBeanQualifiedName.);
 		JClass eBeanClass = codeModel.directClass(eBeanQualifiedName);
 
 		holder.eBean._extends(eBeanClass);
		holder.eBean.annotate(SuppressWarnings.class).param("value""unused");
		{
			JClass contextClass = holder.refClass("android.content.Context");
			holder.contextRef = holder.eBean.field(contextClass"context_");
		}
		{
			// init
			holder.init = holder.eBean.method(codeModel.VOID"init_");
			holder.init.body().assign((JFieldVarholder.contextRef, JExpr.invoke("getContext"));
		}
		{
			// afterSetContentView
			holder.afterSetContentView = holder.eBean.method(codeModel.VOID"afterSetContentView_");
		}
		JFieldVar mAlreadyInflated_ = holder.eBean.field(, JType.parse(codeModel"boolean"), "mAlreadyInflated_".);
		// onFinishInflate
		JMethod onFinishInflate = holder.eBean.method(codeModel.VOID"onFinishInflate");
		onFinishInflate.annotate(Override.class);
		JBlock ifNotInflated = onFinishInflate.body()._if(JExpr.ref("mAlreadyInflated_").not())._then();
		ifNotInflated.assign(mAlreadyInflated_.);
		// inflate layout if ID is given on annotation
		EViewGroup layoutAnnotation = element.getAnnotation(EViewGroup.class);
		int layoutIdValue = layoutAnnotation.value();
		JFieldRef contentViewId;
		if (layoutIdValue != .) {
			IRInnerClass rInnerClass = .get(.);
			contentViewId = rInnerClass.getIdStaticRef(layoutIdValueholder);
			ifNotInflated.invoke("inflate").arg(JExpr.invoke("getContext")).arg(contentViewId).arg(JExpr._this());
		}
		ifNotInflated.invoke(holder.afterSetContentView);
		// finally
		onFinishInflate.body().invoke(JExpr._super(), "onFinishInflate");
		.copyConstructorsAndAddStaticEViewBuilders(elementcodeModeleBeanClassholderonFinishInflate);
		{
			// init if activity
			holder.initIfActivityBody = helper.ifContextInstanceOfActivity(holderholder.init.body());
			holder.initActivityRef = helper.castContextToActivity(holderholder.initIfActivityBody);
		}
	}
New to GrepCode? Check out our FAQ X