use of org.eclipse.ceylon.javax.tools.JavaFileObject 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.javax.tools.JavaFileObject 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.javax.tools.JavaFileObject in project ceylon by eclipse.
the class Main method compile.
/**
* Programmatic interface for main function.
* @param args The command line parameters.
*/
@Override
public Result compile(String[] args, String[] classNames, Context context, List<JavaFileObject> fileObjects, Iterable<? extends Processor> processors) {
context.put(Log.outKey, out);
log = CeylonLog.instance(context);
if (options == null) {
// creates a new one
options = Options.instance(context);
}
filenames = new LinkedHashSet<File>();
classnames = new ListBuffer<String>();
exitState = ExitState.cmderror();
JavaCompiler comp = null;
/* TODO: Logic below about what is an acceptable command line should be
* updated to take annotation processing semantics into account. */
try {
if (args.length == 0 && fileObjects.isEmpty()) {
// super.help();
this.exitState = ExitState.cmderror();
return CMDERR;
}
Collection<File> filenames = processArgs(CommandLine.parse(args), classNames);
if (filenames == null) {
// null signals an error in options, abort
this.exitState = ExitState.cmderror();
return CMDERR;
} else if (filenames.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) {
// or version info
if (options.get("-help") != null || options.get("-jhelp") != null || options.get("-X") != null || options.get("-version") != null || options.get("-fullversion") != null)
return OK;
error("err.no.source.files");
this.exitState = ExitState.cmderror();
return CMDERR;
}
// Set up the timer *after* we've processed to options
// because it needs to know if we need logging or not
timer = Timer.instance(context);
timer.init();
boolean forceStdOut = options.get("stdout") != null;
if (forceStdOut) {
out.flush();
out = new PrintWriter(System.out, true);
}
context.put(Log.outKey, out);
fileManager = context.get(JavaFileManager.class);
try {
comp = LanguageCompiler.instance(context);
} catch (Overrides.OverrideException e) {
CeylonLog.instance(context).error("ceylon.overrides", e.getMessage());
this.exitState = new ExitState(ERROR, CeylonState.ERROR, 0, e);
return CMDERR;
}
if (comp == null) {
this.exitState = ExitState.systemError(null, null);
return SYSERR;
}
if (!classnames.isEmpty()) {
this.filenames.addAll(addModuleFiles(filenames));
classnames.clear();
}
if (!this.filenames.isEmpty()) {
// add filenames to fileObjects
List<JavaFileObject> otherFiles = List.nil();
JavacFileManager dfm = (JavacFileManager) fileManager;
for (JavaFileObject fo : dfm.getJavaFileObjectsFromFiles(this.filenames)) {
otherFiles = otherFiles.append(fo);
}
fileObjects = fileObjects.prependList(otherFiles);
}
if (fileObjects.isEmpty()) {
error("err.no.source.files");
this.exitState = ExitState.cmderror();
return CMDERR;
}
comp.compile(fileObjects, classnames.toList(), processors);
int errorCount = comp.errorCount();
// ceylonBackendErrors = comp.log instanceof CeylonLog ? ((CeylonLog)comp.log).ceylonBackendErrors() : false;
if (errorCount != 0) {
this.exitState = ExitState.error(comp);
return ERROR;
}
} catch (IOException ex) {
ioMessage(ex);
this.exitState = ExitState.systemError(null, ex);
return SYSERR;
} catch (OutOfMemoryError ex) {
resourceMessage(ex);
this.exitState = ExitState.systemError(null, ex);
return SYSERR;
} catch (StackOverflowError ex) {
resourceMessage(ex);
this.exitState = ExitState.systemError(null, ex);
return SYSERR;
} catch (FatalError ex) {
this.exitState = ExitState.systemError(comp, ex);
if (this.exitState.javacExitCode == SYSERR) {
feMessage(ex);
}
return this.exitState.javacExitCode;
} catch (AnnotationProcessingError ex) {
apMessage(ex);
this.exitState = ExitState.systemError(null, ex);
return SYSERR;
} catch (ClientCodeException ex) {
// and javax.tools.JavaCompiler.CompilationTask#call
throw new RuntimeException(ex.getCause());
} catch (PropagatedException ex) {
throw ex.getCause();
} catch (RepositoryException ex) {
// this should have logged an error, if so fine. if not we will have a problematic error code
this.exitState = ExitState.abnormal(comp, ex, options);
return ABNORMAL;
} catch (Throwable ex) {
// exceptions.
if (comp == null || comp.errorCount() == 0 || options == null || options.get("dev") != null) {
bugMessage(ex);
}
this.exitState = ExitState.abnormal(comp, ex, options);
return ABNORMAL;
} finally {
if (comp != null)
comp.close();
filenames = null;
options = null;
if (timer != null) {
timer.end();
}
timer = null;
}
this.exitState = ExitState.ok();
return OK;
}
use of org.eclipse.ceylon.javax.tools.JavaFileObject 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.javax.tools.JavaFileObject in project ceylon by eclipse.
the class MemberEnter method finish.
/**
* Enter member fields and methods of a class
* @param env the environment current for the class block.
*/
private void finish(Env<AttrContext> env) {
JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
try {
JCClassDecl tree = (JCClassDecl) env.tree;
finishClass(tree, env);
} finally {
log.useSource(prev);
}
}
Aggregations