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;
 import static javax.lang.model.element.ElementKind.CONSTRUCTOR;
 
 import java.util.List;
 
 
 
 public class EViewGroupProcessor extends AnnotationHelper implements ElementProcessor {
 
 	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 activitiesHolderthrows Exception {
 
 		EBeanHolder holder = activitiesHolder.create(element);
 
 		TypeElement typeElement = (TypeElementelement;
 
 		String annotatedActivityQualifiedName = typeElement.getQualifiedName().toString();
 
 		String subActivityQualifiedName = annotatedActivityQualifiedName + .;
 
 		int modifiers;
 		if (element.getModifiers().contains(.)) {
 			modifiers = . | .;
 		} else {
 			modifiers = . | .;
 		}
 
 		holder.eBean = codeModel._class(modifierssubActivityQualifiedName.);
 
 		JClass annotatedActivity = codeModel.directClass(annotatedActivityQualifiedName);
 
 		holder.eBean._extends(annotatedActivity);
 
 		holder.bundleClass = holder.refClass("android.os.Bundle");
 
 		// afterSetContentView
 		holder.afterSetContentView = holder.eBean.method(codeModel.VOID"afterSetContentView_");
 
 		// onFinishInflate
 		JMethod onFinishInflate = holder.eBean.method(codeModel.VOID"onFinishInflate");
 		onFinishInflate.annotate(Override.class);
 
 		// 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);
			onFinishInflate.body().invoke("inflate").arg(JExpr.invoke("getContext")).arg(contentViewId).arg(JExpr._this());
		}
		// finally
		onFinishInflate.body().invoke(holder.afterSetContentView);
		onFinishInflate.body().invoke(JExpr._super(), "onFinishInflate");
		copyConstructors(elementholderonFinishInflate);
	}
	private void copyConstructors(Element elementEBeanHolder holderJMethod setContentViewMethod) {
		for (Element e : element.getEnclosedElements()) {
			if (e.getKind() == ) {
				constructors.add((ExecutableElemente);
			}
		}
		for (ExecutableElement userConstructor : constructors) {
			JMethod copy = holder.eBean.constructor();
			JInvocation superCall = copy.body().invoke("super");
			for (VariableElement param : userConstructor.getParameters()) {
				String paramName = param.getSimpleName().toString();
				String paramType = param.asType().toString();
				copy.param(holder.refClass(paramType), paramName);
				superCall.arg(JExpr.ref(paramName));
			}
		}
	}
New to GrepCode? Check out our FAQ X