use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit in project ceylon by eclipse.
the class CeylonTransformer method makeJCCompilationUnitPlaceholder.
/**
* In this pass we only make an empty placeholder which we'll fill in the
* EnterCeylon phase later on
*/
public JCCompilationUnit makeJCCompilationUnitPlaceholder(Tree.CompilationUnit t, JavaFileObject file, String pkgName, PhasedUnit phasedUnit) {
JCExpression pkg = pkgName != null ? getPackage(pkgName) : null;
at(t);
List<JCTree> defs = makeDefs(t);
JCCompilationUnit topLev = new CeylonCompilationUnit(List.<JCTree.JCAnnotation>nil(), pkg, defs, null, null, null, null, t, phasedUnit);
topLev.lineMap = getMap();
topLev.sourcefile = file;
topLev.isCeylonProgram = true;
return topLev;
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit in project ceylon by eclipse.
the class CeylonTransformer method transformPackageInfo.
public List<JCCompilationUnit> transformPackageInfo(CeylonCompilationUnit ccu) {
final CeylonFileObject fo = (CeylonFileObject) ((CeylonPhasedUnit) ccu.phasedUnit).getFileObject();
ListBuffer<JCCompilationUnit> packageInfos = new ListBuffer<JCCompilationUnit>();
for (Tree.PackageDescriptor pack : ccu.ceylonTree.getPackageDescriptors()) {
List<JCAnnotation> packageAnnotations = expressionGen().transformAnnotations(OutputElement.PACKAGE, pack);
if (packageAnnotations.isEmpty()) {
continue;
}
JCCompilationUnit packageInfo = make().TopLevel(packageAnnotations, naming.makeQuotedFQIdent(pack.getScope().getQualifiedNameString()), List.<JCTree>nil());
// Enter.visitTopLevel(JCCompilationUnit) uses the tree.sourceFile
// to decide whether it's seeing a package-info.java
// So set up a fake one...
packageInfo.sourcefile = new JavaFileObject() {
@Override
public boolean isNameCompatible(String simpleName, Kind kind) {
return "package-info".equals(simpleName) && JavaFileObject.Kind.SOURCE == kind;
}
@Override
public URI toUri() {
return fo.toUri();
}
@Override
public String getName() {
return fo.getName();
}
@Override
public InputStream openInputStream() throws IOException {
return fo.openInputStream();
}
@Override
public OutputStream openOutputStream() throws IOException {
return fo.openOutputStream();
}
@Override
public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
return fo.openReader(ignoreEncodingErrors);
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return fo.getCharContent(ignoreEncodingErrors);
}
@Override
public Writer openWriter() throws IOException {
return fo.openWriter();
}
@Override
public long getLastModified() {
return fo.getLastModified();
}
@Override
public boolean delete() {
return fo.delete();
}
@Override
public Kind getKind() {
return fo.getKind();
}
@Override
public NestingKind getNestingKind() {
return fo.getNestingKind();
}
@Override
public Modifier getAccessLevel() {
return fo.getAccessLevel();
}
};
packageInfos.add(packageInfo);
}
return packageInfos.toList();
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit in project ceylon by eclipse.
the class CompilerTests method compareWithJavaSourceWithLines.
protected void compareWithJavaSourceWithLines(String name) {
// make a compiler task
// FIXME: runFileManager.setSourcePath(dir);
CeyloncTaskImpl task = getCompilerTask(new String[] { name + ".ceylon" });
// grab the CU after we've completed it
class Listener implements TaskListener {
JCCompilationUnit compilationUnit;
private String compilerSrc;
private JavaPositionsRetriever javaPositionsRetriever = new JavaPositionsRetriever();
@Override
public void started(TaskEvent e) {
}
@Override
public void finished(TaskEvent e) {
if (e.getKind() == Kind.ENTER) {
if (compilationUnit == null) {
compilationUnit = (JCCompilationUnit) e.getCompilationUnit();
// for some reason compilationUnit is full here in the listener, but empty as soon
// as the compile task is done. probably to clean up for the gc?
javaPositionsRetriever.retrieve(compilationUnit);
compilerSrc = normalizeLineEndings(javaPositionsRetriever.getJavaSourceCodeWithCeylonLines());
AbstractTransformer.trackNodePositions(null);
}
}
}
}
Listener listener = new Listener();
task.setTaskListener(listener);
// now compile it all the way
ExitState exitState = task.call2();
Assert.assertEquals("Compilation failed", exitState.ceylonState, CeylonState.OK);
// now look at what we expected
String expectedSrc = normalizeLineEndings(readFile(new File(getPackagePath(), name + ".src"))).trim();
String compiledSrc = listener.compilerSrc.trim();
Assert.assertEquals("Source code differs", expectedSrc, compiledSrc);
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit in project ceylon by eclipse.
the class CompilerTests method compareWithJavaSource.
protected void compareWithJavaSource(List<String> options, final int index, String java, String... ceylon) {
// make a compiler task
// FIXME: runFileManager.setSourcePath(dir);
ErrorCollector collector = new ErrorCollector();
CeyloncTaskImpl task = getCompilerTask(options, collector, ceylon);
// grab the CU after we've completed it
class Listener implements TaskListener {
JCCompilationUnit compilationUnit;
private String compilerSrc;
int count = 0;
@Override
public void started(TaskEvent e) {
}
@Override
public void finished(TaskEvent e) {
if (e.getKind() == Kind.ENTER) {
if (compilationUnit == null && index == count++) {
compilationUnit = (JCCompilationUnit) e.getCompilationUnit();
// for some reason compilationUnit is full here in the listener, but empty as soon
// as the compile task is done. probably to clean up for the gc?
compilerSrc = normalizeLineEndings(compilationUnit.toString());
}
}
}
}
Listener listener = new Listener();
task.setTaskListener(listener);
// now compile it all the way
assertCompilesOk(collector, task.call2());
// now look at what we expected
File expectedSrcFile = new File(getPackagePath(), java);
String expectedSrc = normalizeLineEndings(readFile(expectedSrcFile)).trim();
String compiledSrc = listener.compilerSrc.trim();
// THIS IS FOR INTERNAL USE ONLY!!!
// Can be used to do batch updating of known correct tests
// Uncomment only when you know what you're doing!
// if (expectedSrc != null && compiledSrc != null && !expectedSrc.equals(compiledSrc)) {
// writeFile(expectedSrcFile, compiledSrc);
// expectedSrc = compiledSrc;
// }
Assert.assertEquals("Source code differs", expectedSrc, compiledSrc);
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit in project ceylon by eclipse.
the class CompilerTests method compareWithJavaSourceWithPositions.
protected void compareWithJavaSourceWithPositions(String name) {
// make a compiler task
// FIXME: runFileManager.setSourcePath(dir);
CeyloncTaskImpl task = getCompilerTask(new String[] { name + ".ceylon" });
// grab the CU after we've completed it
class Listener implements TaskListener {
JCCompilationUnit compilationUnit;
private String compilerSrc;
private JavaPositionsRetriever javaPositionsRetriever = new JavaPositionsRetriever();
@Override
public void started(TaskEvent e) {
AbstractTransformer.trackNodePositions(javaPositionsRetriever);
}
@Override
public void finished(TaskEvent e) {
if (e.getKind() == Kind.ENTER) {
if (compilationUnit == null) {
compilationUnit = (JCCompilationUnit) e.getCompilationUnit();
// for some reason compilationUnit is full here in the listener, but empty as soon
// as the compile task is done. probably to clean up for the gc?
javaPositionsRetriever.retrieve(compilationUnit);
compilerSrc = normalizeLineEndings(javaPositionsRetriever.getJavaSourceCodeWithCeylonPositions());
AbstractTransformer.trackNodePositions(null);
}
}
}
}
Listener listener = new Listener();
task.setTaskListener(listener);
// now compile it all the way
ExitState exitState = task.call2();
Assert.assertEquals("Compilation failed", CeylonState.OK, exitState.ceylonState);
// now look at what we expected
String expectedSrc = normalizeLineEndings(readFile(new File(getPackagePath(), name + ".src"))).trim();
String compiledSrc = listener.compilerSrc.trim();
Assert.assertEquals("Source code differs", expectedSrc, compiledSrc);
}
Aggregations