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 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.generation;
public class SourceCodewriter extends CodeWriter {
	private final Filer filer;
	private final Messager message;
	private static final VoidOutputStream VOID_OUTPUT_STREAM = new VoidOutputStream();
	private static class VoidOutputStream extends OutputStream {
		public void write(int arg0throws IOException {
			// Do nothing
	public SourceCodewriter(Filer filerMessager message) {
		this. = filer;
		this. = message;
	public OutputStream openBinary(JPackage pkgString fileNamethrows IOException {
		String qualifiedClassName = toQualifiedClassName(pkgfileName);
		.printMessage(."Generating source file: " + qualifiedClassName);
		try {
			JavaFileObject sourceFile = .createSourceFile(qualifiedClassName);
			return sourceFile.openOutputStream();
catch (FilerException e) {
			.printMessage(."Could not generate source file for " + qualifiedClassName + ", message: " + e.getMessage());
			 * This exception is expected, when some files are created twice. We
			 * cannot delete existing files, unless using a dirty hack. Files a
			 * created twice when the same file is created from different
			 * annotation rounds. Happens when renaming classes, and for
			 * Background executor. It also probably means I didn't fully
			 * understand how annotation processing works. If anyone can point
			 * me out...
	private String toQualifiedClassName(JPackage pkgString fileName) {
		int suffixPosition = fileName.lastIndexOf('.');
		String className = fileName.substring(0, suffixPosition);
		String qualifiedClassName = + "." + className;
		return qualifiedClassName;
	public void close() throws IOException {
New to GrepCode? Check out our FAQ X