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;
 
 import java.util.Map;
 import java.util.Set;
 
 
		App.class//
		BeforeCreate.class//
		EViewGroup.class//
		AfterViews.class//
		RoboGuice.class//
		ViewById.class//
		Click.class//
		LongClick.class//
		ItemClick.class//
		ItemLongClick.class//
		Touch.class//
		ItemSelect.class//
		UiThreadDelayed.class//
		UiThread.class//
		Transactional.class//
		Background.class//
		Extra.class//
		SystemService.class//
		SharedPref.class//
		Pref.class//
		StringRes.class//
		ColorRes.class//
		AnimationRes.class//
		BooleanRes.class//
		DimensionRes.class//
		DrawableRes.class//
		IntArrayRes.class//
		IntegerRes.class//
		LayoutRes.class//
		MovieRes.class//
		TextRes.class//
		TextArrayRes.class//
		StringArrayRes.class//
		Rest.class//
		Get.class//
		Head.class//
		Options.class//
		Post.class//
		Put.class//
		Delete.class//
		Accept.class//
		FromHtml.class//
		OptionsMenu.class//
		OptionsItem.class//
		HtmlRes.class//
		NoTitle.class//
		Fullscreen.class//
		RestService.class//
		Trace.class //
})
We do not need multiple round processing, since the generated classes do not need to be processed.
	private boolean alreadyProcessed = false;
	private final TimeStats timeStats = new TimeStats();
	public synchronized void init(ProcessingEnvironment processingEnv) {
		super.init(processingEnv);
		Messager messager = processingEnv.getMessager();
		messager.printMessage(.."Starting AndroidAnnotations annotation processing");
	}
	public boolean process(Set<? extends TypeElementannotationsRoundEnvironment roundEnv) {
		.start("Whole Processing");
		try {
			processThrowing(annotationsroundEnv);
catch (Exception e) {
			handleException(annotationsroundEnve);
		}
		.stop("Whole Processing");
		return true;
	}
	private void processThrowing(Set<? extends TypeElementannotationsRoundEnvironment roundEnvthrows IOException {
		if (nothingToDo(annotationsroundEnv)) {
			return;
		}
		AnnotationElementsHolder extractedModel = extractAnnotations(annotationsroundEnv);
		IRClass rClass = findRClasses(androidManifest);
		AndroidSystemServices androidSystemServices = new AndroidSystemServices();
		AnnotationElements validatedModel = validateAnnotations(extractedModelrClassandroidSystemServicesandroidManifest);
		JCodeModel codeModel = processAnnotations(validatedModelrClassandroidSystemServicesandroidManifest);
		generateSources(codeModel);
	}
	private boolean nothingToDo(Set<? extends TypeElementannotationsRoundEnvironment roundEnv) {
		return roundEnv.processingOver() || annotations.size() == 0 || ;
	}
	private AnnotationElementsHolder extractAnnotations(Set<? extends TypeElementannotationsRoundEnvironment roundEnv) {
		.start("Extract Annotations");
		ModelExtractor modelExtractor = new ModelExtractor();
		AnnotationElementsHolder extractedModel = modelExtractor.extract(annotationsroundEnv);
		.stop("Extract Annotations");
		return extractedModel;
	}
		.start("Extract Manifest");
		.stop("Extract Manifest");
		return manifest;
	}
	private IRClass findRClasses(AndroidManifest androidManifestthrows IOException {
		.start("Find R Classes");
		IRClass rClass = rClassFinder.find(androidManifest);
		IRClass androidRClass = androidRClassFinder.find();
		CoumpoundRClass coumpoundRClass = new CoumpoundRClass(rClassandroidRClass);
		.stop("Find R Classes");
		return coumpoundRClass;
	}
	private AnnotationElements validateAnnotations(AnnotationElementsHolder extractedModelIRClass rClassAndroidSystemServices androidSystemServicesAndroidManifest androidManifest) {
		.start("Validate Annotations");
		AnnotationElements validatedAnnotations;
		if (rClass != null) {
			ModelValidator modelValidator = buildModelValidator(rClassandroidSystemServicesandroidManifest);
			validatedAnnotations = modelValidator.validate(extractedModel);
else {
			validatedAnnotations = .;
		}
		.stop("Validate Annotations");
		return validatedAnnotations;
	}
	private ModelValidator buildModelValidator(IRClass rClassAndroidSystemServices androidSystemServicesAndroidManifest androidManifest) {
		ModelValidator modelValidator = new ModelValidator();
		modelValidator.register(new EActivityValidator(rClassandroidManifest));
		modelValidator.register(new EViewGroupValidator(rClass));
		modelValidator.register(new ViewByIdValidator(rClass));
		modelValidator.register(new FromHtmlValidator(rClass));
		modelValidator.register(new ClickValidator(rClass));
		modelValidator.register(new LongClickValidator(rClass));
		modelValidator.register(new TouchValidator(rClass));
		modelValidator.register(new ItemClickValidator(rClass));
		modelValidator.register(new ItemSelectedValidator(rClass));
		modelValidator.register(new ItemLongClickValidator(rClass));
		for (AndroidRes androidRes : AndroidRes.values()) {
			modelValidator.register(new ResValidator(androidResrClass));
		}
		modelValidator.register(new ExtraValidator());
		modelValidator.register(new SystemServiceValidator(androidSystemServices));
		modelValidator.register(new PrefValidator());
		modelValidator.register(new RestValidator());
		modelValidator.register(new DeleteValidator());
		modelValidator.register(new GetValidator());
		modelValidator.register(new HeadValidator());
		modelValidator.register(new PostValidator());
		modelValidator.register(new PutValidator());
		modelValidator.register(new AcceptValidator());
		modelValidator.register(new AppValidator(androidManifest));
		modelValidator.register(new OptionsMenuValidator(rClass));
		modelValidator.register(new OptionsItemValidator(rClass));
		modelValidator.register(new RunnableValidator(UiThread.class));
		modelValidator.register(new RunnableValidator(Background.class));
		if (traceActivated()) {
			modelValidator.register(new TraceValidator());
		}
		return modelValidator;
	}
	private boolean traceActivated() {
		if (options.containsKey("trace")) {
			String trace = options.get("trace");
			return !"false".equals(trace);
else {
			return true;
		}
	}
	private JCodeModel processAnnotations(AnnotationElements validatedModelIRClass rClassAndroidSystemServices androidSystemServicesAndroidManifest androidManifest) {
		.start("Process Annotations");
		ModelProcessor modelProcessor = buildModelProcessor(rClassandroidSystemServicesandroidManifest);
		JCodeModel codeModel = modelProcessor.process(validatedModel);
		.stop("Process Annotations");
		return codeModel;
	}
	private ModelProcessor buildModelProcessor(IRClass rClassAndroidSystemServices androidSystemServicesAndroidManifest androidManifest) {
		ModelProcessor modelProcessor = new ModelProcessor();
		modelProcessor.register(new EActivityProcessor(rClass));
		modelProcessor.register(new EViewGroupProcessor(rClass));
		modelProcessor.register(new PrefProcessor());
		modelProcessor.register(new RoboGuiceProcessor());
		modelProcessor.register(new ViewByIdProcessor(rClass));
		modelProcessor.register(new FromHtmlProcessor(rClass));
		modelProcessor.register(new ClickProcessor(rClass));
		modelProcessor.register(new LongClickProcessor(rClass));
		modelProcessor.register(new TouchProcessor(rClass));
		modelProcessor.register(new ItemClickProcessor(rClass));
		modelProcessor.register(new ItemSelectedProcessor(rClass));
		modelProcessor.register(new ItemLongClickProcessor(rClass));
		for (AndroidRes androidRes : AndroidRes.values()) {
			modelProcessor.register(new ResProcessor(androidResrClass));
		}
		modelProcessor.register(new TransactionalProcessor());
		modelProcessor.register(new ExtraProcessor());
		modelProcessor.register(new SystemServiceProcessor(androidSystemServices));
		modelProcessor.register(new BeforeCreateProcessor());
		modelProcessor.register(new AfterViewsProcessor());
		RestImplementationsHolder restImplementationHolder = new RestImplementationsHolder();
		modelProcessor.register(new RestProcessor(restImplementationHolder));
		modelProcessor.register(new GetProcessor(restImplementationHolder));
		modelProcessor.register(new PostProcessor(restImplementationHolder));
		modelProcessor.register(new PutProcessor(restImplementationHolder));
		modelProcessor.register(new DeleteProcessor(restImplementationHolder));
		modelProcessor.register(new HeadProcessor(restImplementationHolder));
		modelProcessor.register(new OptionsProcessor(restImplementationHolder));
		modelProcessor.register(new AppProcessor());
		modelProcessor.register(new OptionsMenuProcessor(rClass));
		modelProcessor.register(new OptionsItemProcessor(rClass));
		modelProcessor.register(new NoTitleProcessor());
		modelProcessor.register(new FullscreenProcessor());
		modelProcessor.register(new RestServiceProcessor());
		modelProcessor.register(new TraceProcessor());
		modelProcessor.register(new UiThreadProcessor());
		modelProcessor.register(new UiThreadDelayedProcessor());
		modelProcessor.register(new BackgroundProcessor());
		return modelProcessor;
	}
	private void generateSources(JCodeModel modelthrows IOException {
		.start("Generate Sources");
		messager.printMessage(.."Number of files generated by AndroidAnnotations: " + model.countArtifacts());
		CodeModelGenerator modelGenerator = new CodeModelGenerator(.getFiler(), messager);
		modelGenerator.generate(model);
		.stop("Generate Sources");
	}
	private void handleException(Set<? extends TypeElementannotationsRoundEnvironment roundEnvException e) {
		String errorMessage = "Unexpected error. Please report an issue on AndroidAnnotations, with the following content: " + stackTraceToString(e);
		messager.printMessage(..errorMessage);
		/*
		 * Printing exception as an error on a random element. The exception is
		 * not related to this element, but otherwise it wouldn't show up in
		 * eclipse.
		 */
		Element element = roundEnv.getElementsAnnotatedWith(annotations.iterator().next()).iterator().next();
		messager.printMessage(..errorMessageelement);
	}
		StringWriter writer = new StringWriter();
		PrintWriter pw = new PrintWriter(writer);
		return writer.toString();
	}
New to GrepCode? Check out our FAQ X