use of javax.annotation.processing.FilerException in project hibernate-orm by hibernate.
the class ClassWriter method writeFile.
public static void writeFile(MetaEntity entity, Context context) {
try {
String metaModelPackage = entity.getPackageName();
// need to generate the body first, since this will also update the required imports which need to
// be written out first
String body = generateBody(entity, context).toString();
FileObject fo = context.getProcessingEnvironment().getFiler().createSourceFile(getFullyQualifiedClassName(entity, metaModelPackage));
OutputStream os = fo.openOutputStream();
PrintWriter pw = new PrintWriter(os);
if (!metaModelPackage.isEmpty()) {
pw.println("package " + metaModelPackage + ";");
pw.println();
}
pw.println(entity.generateImports());
pw.println(body);
pw.flush();
pw.close();
} catch (FilerException filerEx) {
context.logMessage(Diagnostic.Kind.ERROR, "Problem with Filer: " + filerEx.getMessage());
} catch (IOException ioEx) {
context.logMessage(Diagnostic.Kind.ERROR, "Problem opening file to write MetaModel for " + entity.getSimpleName() + ioEx.getMessage());
}
}
use of javax.annotation.processing.FilerException in project service-proxy by membrane.
the class BlueprintParsers method writeParserDefinitior.
public void writeParserDefinitior(Model m) throws IOException {
for (MainInfo main : m.getMains()) {
List<Element> sources = new ArrayList<Element>();
sources.addAll(main.getInterceptorElements());
sources.add(main.getElement());
try {
FileObject o = processingEnv.getFiler().createSourceFile(main.getAnnotation().outputPackage() + ".blueprint" + ".BlueprintNamespaceParser", sources.toArray(new Element[0]));
BufferedWriter bw = new BufferedWriter(o.openWriter());
try {
bw.write("/* Copyright 2014 predic8 GmbH, www.predic8.com\r\n" + "\r\n" + " Licensed under the Apache License, Version 2.0 (the \"License\");\r\n" + " you may not use this file except in compliance with the License.\r\n" + " You may obtain a copy of the License at\r\n" + "\r\n" + " http://www.apache.org/licenses/LICENSE-2.0\r\n" + "\r\n" + " Unless required by applicable law or agreed to in writing, software\r\n" + " distributed under the License is distributed on an \"AS IS\" BASIS,\r\n" + " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n" + " See the License for the specific language governing permissions and\r\n" + " limitations under the License. */\r\n" + "\r\n" + "package " + main.getAnnotation().outputPackage() + ".blueprint;\r\n" + "\r\n" + "/**\r\n" + " * Automatically generated by " + BlueprintParsers.class.getName() + ".\r\n" + " */\r\n" + "public class BlueprintNamespaceParser extends com.predic8.membrane.annot.parser.BlueprintNamespaceParser {\r\n" + "\r\n" + " public void init() {\r\n");
for (ElementInfo i : main.getIis()) {
if (i.getAnnotation().topLevel()) {
bw.write(" registerGlobalBeanDefinitionParser(\"" + i.getAnnotation().name() + "\", new " + i.getParserClassSimpleName() + "());\r\n");
} else {
for (ChildElementDeclarationInfo cedi : i.getUsedBy()) {
for (ChildElementInfo cei : cedi.getUsedBy()) {
TypeElement element = cei.getEi().getElement();
String clazz = AnnotUtils.getRuntimeClassName(element);
bw.write(" registerLocalBeanDefinitionParser(\"" + clazz + "\", \"" + i.getAnnotation().name() + "\", new " + i.getParserClassSimpleName() + "());\r\n");
}
}
}
}
bw.write(" }\r\n" + "}\r\n" + "");
} finally {
bw.close();
}
} catch (FilerException e) {
if (e.getMessage().contains("Source file already created"))
return;
throw e;
}
}
}
use of javax.annotation.processing.FilerException in project service-proxy by membrane.
the class Parsers method writeParserDefinitior.
public void writeParserDefinitior(Model m) throws IOException {
for (MainInfo main : m.getMains()) {
List<Element> sources = new ArrayList<Element>();
sources.addAll(main.getInterceptorElements());
sources.add(main.getElement());
try {
FileObject o = processingEnv.getFiler().createSourceFile(main.getAnnotation().outputPackage() + ".NamespaceHandlerAutoGenerated", sources.toArray(new Element[0]));
BufferedWriter bw = new BufferedWriter(o.openWriter());
try {
bw.write("/* Copyright 2012,2013 predic8 GmbH, www.predic8.com\r\n" + "\r\n" + " Licensed under the Apache License, Version 2.0 (the \"License\");\r\n" + " you may not use this file except in compliance with the License.\r\n" + " You may obtain a copy of the License at\r\n" + "\r\n" + " http://www.apache.org/licenses/LICENSE-2.0\r\n" + "\r\n" + " Unless required by applicable law or agreed to in writing, software\r\n" + " distributed under the License is distributed on an \"AS IS\" BASIS,\r\n" + " WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n" + " See the License for the specific language governing permissions and\r\n" + " limitations under the License. */\r\n" + "\r\n" + "package " + main.getAnnotation().outputPackage() + ";\r\n" + "\r\n" + "/**\r\n" + " * Automatically generated by " + Parsers.class.getName() + ".\r\n" + " */\r\n" + "public class NamespaceHandlerAutoGenerated {\r\n" + "\r\n" + " public static void registerBeanDefinitionParsers(NamespaceHandler nh) {\r\n");
for (ElementInfo i : main.getIis()) {
if (i.getAnnotation().topLevel()) {
bw.write(" nh.registerGlobalBeanDefinitionParser(\"" + i.getAnnotation().name() + "\", new " + i.getParserClassSimpleName() + "());\r\n");
} else {
for (ChildElementDeclarationInfo cedi : i.getUsedBy()) {
for (ChildElementInfo cei : cedi.getUsedBy()) {
TypeElement element = cei.getEi().getElement();
String clazz = AnnotUtils.getRuntimeClassName(element);
bw.write(" nh.registerLocalBeanDefinitionParser(\"" + clazz + "\", \"" + i.getAnnotation().name() + "\", new " + i.getParserClassSimpleName() + "());\r\n");
}
}
}
}
bw.write(" }\r\n" + "}\r\n" + "");
} finally {
bw.close();
}
} catch (FilerException e) {
if (e.getMessage().contains("Source file already created"))
return;
throw e;
}
}
}
use of javax.annotation.processing.FilerException in project service-proxy by membrane.
the class Schemas method writeXSD.
public void writeXSD(Model m) throws IOException {
try {
for (MainInfo main : m.getMains()) {
List<Element> sources = new ArrayList<Element>();
sources.add(main.getElement());
sources.addAll(main.getInterceptorElements());
FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, main.getAnnotation().outputPackage(), main.getAnnotation().outputName(), sources.toArray(new Element[0]));
BufferedWriter bw = new BufferedWriter(o.openWriter());
try {
assembleXSD(bw, m, main);
} finally {
bw.close();
}
}
} catch (FilerException e) {
if (e.getMessage().contains("Source file already created"))
return;
throw e;
}
}
use of javax.annotation.processing.FilerException in project androidannotations by androidannotations.
the class SourceCodeWriter method openBinary.
@Override
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
String qualifiedClassName = toQualifiedClassName(pkg, fileName);
LOGGER.debug("Generating class: {}", qualifiedClassName);
Element[] classOriginatingElements = originatingElements.getClassOriginatingElements(qualifiedClassName);
try {
JavaFileObject sourceFile;
if (classOriginatingElements.length == 0) {
LOGGER.info("Generating class with no originating element: {}", qualifiedClassName);
}
sourceFile = filer.createSourceFile(qualifiedClassName, classOriginatingElements);
return sourceFile.openOutputStream();
} catch (FilerException e) {
LOGGER.error("Could not generate source file for {} due to error: {}", qualifiedClassName, 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...
*/
return VOID_OUTPUT_STREAM;
}
}
Aggregations