public Writer openSource(JPackage pkg, String fileName) throws IOException { String name; if(pkg.isUnnamed()) name = fileName; else name = pkg.name()+'.'+fileName; name = name.substring(0,name.length()-5); // strip ".java" return filer.createSourceFile(name); }
public Writer openSource(JPackage pkg, String fileName) throws IOException { String name; if(pkg.isUnnamed()) name = fileName; else name = pkg.name()+'.'+fileName; name = name.substring(0,name.length()-5); // strip ".java" return filer.createSourceFile(name); }
/** * Get the writer for the specified java source file. * * @return the writer for the specified java source file. */ public PrintWriter getWriter() throws MissingParameterException, IOException { if (name == null) { throw new MissingParameterException("name"); } AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment(); return env.getFiler().createSourceFile(name); }
private PrintWriter openClassFile( String type ) { final String codepackage = "com.google.code.facebookapi"; final String mainClassName = "Facebook" + type + "RestClient"; final String baseClassName = mainClassName + "Base"; final String mainClass = codepackage + "." + mainClassName; final String baseClass = codepackage + "." + baseClassName; try { PrintWriter out = processingEnv.getFiler().createSourceFile( mainClass ); out.println( String.format( "package %s;", codepackage ) ); out.println(); if ( type.equals( "Jaxb" ) ) { out.println( "@SuppressWarnings(\"unchecked\")" ); } out.println( String.format( "public class %s extends %s {", mainClassName, baseClassName ) ); out.println(); CopyConstructorVisitor copyConstructors = new CopyConstructorVisitor( type, out ); ClassDeclaration clientBase = (ClassDeclaration) processingEnv.getTypeDeclaration( baseClass ); for ( ConstructorDeclaration cd : clientBase.getConstructors() ) { cd.accept( copyConstructors ); } return out; } catch ( IOException ex ) { System.err.println( "Ignoring IOException during: " + type + "; " + ex ); return null; } }