use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.
the class CeylonLog method report.
@Override
public void report(JCDiagnostic diagnostic) {
String messageKey = diagnostic.getCode();
if (messageKey != null) {
if (messageKey.startsWith("compiler.err.ceylon.codegen.exception")) {
numCeylonCodegenException++;
} else if (messageKey.startsWith("compiler.err.ceylon.codegen.erroneous")) {
numCeylonCodegenErroneous++;
} else if (messageKey.startsWith("compiler.err.ceylon")) {
numCeylonAnalysisErrors++;
} else if (sourceLanguage.isCeylon()) {
numCeylonCodegenGarbage++;
} else {
numNonCeylonErrors++;
}
} else if (sourceLanguage.isCeylon()) {
numCeylonCodegenGarbage++;
} else {
numNonCeylonErrors++;
}
DiagnosticSource source = diagnostic.getDiagnosticSource();
if (source != null) {
JavaFileObject file = source.getFile();
if (file instanceof CeylonFileObject && diagnostic.getType() == DiagnosticType.ERROR) {
((CeylonFileObject) file).addError(diagnostic);
}
}
super.report(diagnostic);
}
use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.
the class CeyloncFileManager method getJavaFileObjectsFromFiles.
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
Iterable<? extends JavaFileObject> theCollection = super.getJavaFileObjectsFromFiles(files);
ArrayList<JavaFileObject> result = new ArrayList<JavaFileObject>();
for (JavaFileObject file : theCollection) {
if (file.getName().endsWith(".ceylon")) {
result.add(new CeylonFileObject(file));
} else {
result.add(file);
}
}
return result;
}
use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.
the class CeyloncFileManager method getJavaFileForInput.
@Override
public JavaFileObject getJavaFileForInput(Location location, String className, JavaFileObject.Kind kind) throws IOException {
nullCheck(location);
// validateClassName(className);
nullCheck(className);
nullCheck(kind);
if (!sourceOrClass.contains(kind))
throw new IllegalArgumentException("Invalid kind " + kind);
JavaFileObject file = getFileForInput(location, forClass(className, kind));
if (file != null && file.getName().endsWith(".ceylon")) {
return new CeylonFileObject(file);
} else {
return file;
}
}
use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.
the class CeyloncFileManager method list.
public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
Iterable<JavaFileObject> result = super.list(location, packageName, kinds, recurse);
ListBuffer<JavaFileObject> buf = new ListBuffer<JavaFileObject>();
for (JavaFileObject f : result) {
if (f.getName().endsWith(".ceylon")) {
buf.add(new CeylonFileObject(f));
} else {
buf.add(f);
}
}
return buf.toList();
}
use of com.redhat.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon-compiler by ceylon.
the class LanguageCompiler method genCodeUnlessError.
private JavaFileObject genCodeUnlessError(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
CeylonFileObject sourcefile = (CeylonFileObject) env.toplevel.sourcefile;
try {
// do not look at the global number of errors but only those for this file
if (super.gen.genClass(env, cdef)) {
String packageName = cdef.sym.packge().getQualifiedName().toString();
Package pkg = modelLoader.findPackage(packageName);
if (pkg == null)
throw new RuntimeException("Failed to find package: " + packageName);
Module module = pkg.getModule();
if (!module.isDefault()) {
String moduleName = module.getNameAsString();
CeylonFileObject moduleFileObject = moduleNamesToFileObjects.get(moduleName);
// if there's no module source file object it means the module descriptor had parse errors
if (moduleFileObject == null || moduleFileObject.hasError()) {
// we do not produce any class files for modules with errors
if (options.get(OptionName.VERBOSE) != null) {
Log.printLines(log.noticeWriter, "[Not writing class " + cdef.sym.className() + " because its module has errors: " + moduleName + "]");
}
return null;
}
}
return writer.writeClass(cdef.sym);
}
} catch (ClassWriter.PoolOverflow ex) {
log.error(cdef.pos(), "limit.pool");
} catch (ClassWriter.StringOverflow ex) {
log.error(cdef.pos(), "limit.string.overflow", ex.value.substring(0, 20));
} catch (CompletionFailure ex) {
chk.completionError(cdef.pos(), ex);
} catch (AssertionError e) {
throw new RuntimeException("Error generating bytecode for " + sourcefile.getName(), e);
}
return null;
}
Aggregations