use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class JavaCompiler method generate.
public void generate(Queue<Pair<Env<AttrContext>, JCClassDecl>> queue, Queue<JavaFileObject> results) {
if (shouldStop(CompileState.GENERATE))
return;
boolean usePrintSource = (stubOutput || sourceOutput || printFlat);
for (Pair<Env<AttrContext>, JCClassDecl> x : queue) {
Env<AttrContext> env = x.fst;
JCClassDecl cdef = x.snd;
if (verboseCompilePolicy) {
printNote("[generate " + (usePrintSource ? " source" : "code") + " " + cdef.sym + "]");
}
if (!taskListener.isEmpty()) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
taskListener.started(e);
}
JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? env.enclClass.sym.sourcefile : env.toplevel.sourcefile);
try {
JavaFileObject file;
if (usePrintSource)
file = printSource(env, cdef);
else {
if (fileManager.hasLocation(StandardLocation.NATIVE_HEADER_OUTPUT) && jniWriter.needsHeader(cdef.sym)) {
jniWriter.write(cdef.sym);
}
file = genCode(env, cdef);
}
if (results != null && file != null)
results.add(file);
} catch (IOException ex) {
log.error(cdef.pos(), "class.cant.write", cdef.sym, ex.getMessage());
return;
} finally {
log.useSource(prev);
}
if (!taskListener.isEmpty()) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.GENERATE, env.toplevel, cdef.sym);
taskListener.finished(e);
}
}
}
use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class JavaCompiler method parseFiles.
/**
* Parses a list of files.
*/
public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) {
if (shouldStop(CompileState.PARSE))
return List.nil();
// parse all files
ListBuffer<JCCompilationUnit> trees = new ListBuffer<>();
Set<JavaFileObject> filesSoFar = new HashSet<JavaFileObject>();
for (JavaFileObject fileObject : fileObjects) {
if (!filesSoFar.contains(fileObject)) {
filesSoFar.add(fileObject);
trees.append(parse(fileObject));
}
}
return trees.toList();
}
use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class JavaCompiler method resolveIdent.
/**
* Resolve an identifier.
* @param name The identifier to resolve
*/
public Symbol resolveIdent(String name) {
if (name.equals(""))
return syms.errSymbol;
JavaFileObject prev = log.useSource(null);
try {
JCExpression tree = null;
for (String s : name.split("\\.", -1)) {
if (// TODO: check for keywords
!SourceVersion.isIdentifier(s))
return syms.errSymbol;
tree = (tree == null) ? make.Ident(names.fromString(s)) : make.Select(tree, names.fromString(s));
}
JCCompilationUnit toplevel = make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil());
toplevel.packge = syms.unnamedPackage;
return attr.attribIdent(tree, toplevel);
} finally {
log.useSource(prev);
}
}
use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class JavaCompiler method attribute.
/**
* Attribute a parse tree.
* @returns the attributed parse tree
*/
public Env<AttrContext> attribute(Env<AttrContext> env) {
if (compileStates.isDone(env, CompileState.ATTR))
return env;
if (verboseCompilePolicy)
printNote("[attribute " + env.enclClass.sym + "]");
if (verbose)
log.printVerbose("checking.attribution", env.enclClass.sym);
if (!taskListener.isEmpty()) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.ANALYZE, env.toplevel, env.enclClass.sym);
taskListener.started(e);
}
JavaFileObject prev = log.useSource(env.enclClass.sym.sourcefile != null ? env.enclClass.sym.sourcefile : env.toplevel.sourcefile);
try {
attr.attrib(env);
if (errorCount() > 0 && !shouldStop(CompileState.ATTR)) {
// if in fail-over mode, ensure that AST expression nodes
// are correctly initialized (e.g. they have a type/symbol)
attr.postAttr(env.tree);
}
compileStates.put(env, CompileState.ATTR);
if (rootClasses != null && rootClasses.contains(env.enclClass)) {
// This was a class that was explicitly supplied for compilation.
// If we want to capture the public api of this class,
// then now is a good time to do it.
reportPublicApi(env.enclClass.sym);
}
} finally {
log.useSource(prev);
}
return env;
}
use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class JavaCompiler method complete.
/**
* Complete compiling a source file that has been accessed
* by the class file reader.
* @param c The class the source file of which needs to be compiled.
*/
public void complete(ClassSymbol c) throws CompletionFailure {
// System.err.println("completing " + c);//DEBUG
if (completionFailureName == c.fullname) {
throw new CompletionFailure(c, "user-selected completion failure by class name");
}
JCCompilationUnit tree;
JavaFileObject filename = c.classfile;
JavaFileObject prev = log.useSource(filename);
try {
tree = parse(filename, filename.getCharContent(false));
} catch (IOException e) {
log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
tree = make.TopLevel(List.<JCTree.JCAnnotation>nil(), null, List.<JCTree>nil());
} finally {
log.useSource(prev);
}
if (!taskListener.isEmpty()) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
taskListener.started(e);
}
enter.complete(List.of(tree), c);
if (!taskListener.isEmpty()) {
TaskEvent e = new TaskEvent(TaskEvent.Kind.ENTER, tree);
taskListener.finished(e);
}
if (enter.getEnv(c) == null) {
boolean isPkgInfo = tree.sourcefile.isNameCompatible("package-info", JavaFileObject.Kind.SOURCE);
if (isPkgInfo) {
if (enter.getEnv(tree.packge) == null) {
JCDiagnostic diag = diagFactory.fragment("file.does.not.contain.package", c.location());
throw reader.new BadClassFile(c, filename, diag);
}
} else {
JCDiagnostic diag = diagFactory.fragment("file.doesnt.contain.class", c.getQualifiedName());
throw reader.new BadClassFile(c, filename, diag);
}
}
implicitSourceFilesRead = true;
}
Aggregations