use of org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon by eclipse.
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 org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon by eclipse.
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 org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon by eclipse.
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 org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon by eclipse.
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.isDefaultModule()) {
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(Option.VERBOSE) != null) {
log.printRawLines(WriterKind.NOTICE, "[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;
}
use of org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject in project ceylon by eclipse.
the class LanguageCompiler method loadCompiledModules.
private List<JCCompilationUnit> loadCompiledModules(List<JCCompilationUnit> trees, LinkedList<JCCompilationUnit> moduleTrees) {
compilerDelegate.visitModules(phasedUnits);
Modules modules = ceylonContext.getModules();
// now make sure the phase units have their modules and packages set correctly
for (PhasedUnit pu : phasedUnits.getPhasedUnits()) {
Package pkg = pu.getPackage();
loadModuleFromSource(pkg, modules, moduleTrees, trees);
}
// also make sure we have packages and modules set up for every Java file we compile
for (JCCompilationUnit cu : trees) {
// skip Ceylon CUs
if (cu instanceof CeylonCompilationUnit)
continue;
String packageName = "";
if (cu.pid != null)
packageName = TreeInfo.fullName(cu.pid).toString();
/*
* Stef: see javadoc for findOrCreateModulelessPackage() for why this is here.
*/
Package pkg = modelLoader.findOrCreateModulelessPackage(packageName);
loadModuleFromSource(pkg, modules, moduleTrees, trees);
}
for (PhasedUnit phasedUnit : phasedUnits.getPhasedUnits()) {
if (!phasedUnit.getCompilationUnit().getModuleDescriptors().isEmpty()) {
String name = phasedUnit.getPackage().getNameAsString();
CeylonPhasedUnit cpu = (CeylonPhasedUnit) phasedUnit;
CeylonFileObject cfo = (CeylonFileObject) cpu.getFileObject();
moduleNamesToFileObjects.put(name, cfo);
}
}
if (addModuleTrees) {
for (JCCompilationUnit moduleTree : moduleTrees) {
trees = trees.append(moduleTree);
}
}
return trees;
}
Aggregations