use of org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl 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.compiler.java.tools.CeyloncTaskImpl 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.compiler.java.tools.CeyloncTaskImpl 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);
}
use of org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon by eclipse.
the class CompilerTests method compileErrorTest.
protected ErrorCollector compileErrorTest(String[] ceylonFiles, List<String> options, Throwable expectedException, boolean includeWarnings, boolean expectedToFail) {
// make a compiler task
// FIXME: runFileManager.setSourcePath(dir);
ErrorCollector collector = new ErrorCollector();
CeyloncTaskImpl task = getCompilerTask(options, collector, ceylonFiles);
// now compile it all the way
Throwable ex = null;
ExitState exitState = task.call2();
switch(exitState.ceylonState) {
case OK:
if (expectedToFail) {
Assert.fail("Compilation successful (it should have failed!)");
}
break;
case BUG:
if (expectedException == null) {
throw new AssertionError("Compiler bug", exitState.abortingException);
}
ex = exitState.abortingException;
break;
case ERROR:
if (!expectedToFail) {
Assert.fail("Compilation failed (it should have been successful!)");
}
break;
case SYS:
Assert.fail("System error");
break;
default:
Assert.fail("Unknown exit state");
}
if (ex != null) {
if (expectedException == null) {
throw new AssertionError("Compilation terminated with unexpected error", ex);
} else if (expectedException.getClass() != ex.getClass() || !eq(expectedException.getMessage(), ex.getMessage())) {
throw new AssertionError("Compilation terminated with a different error than the expected " + expectedException, ex);
}
} else if (expectedException != null) {
Assert.fail("Expected compiler exception " + expectedException);
}
return collector;
}
use of org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl in project ceylon by eclipse.
the class CarGenerationTests method testCarResourceFilesSub.
private void testCarResourceFilesSub(boolean alternative) throws IOException {
List<String> options = new LinkedList<String>();
options.add("-src");
options.add(getPackagePath() + "resmodules/files/source");
options.add("-res");
options.add(getPackagePath() + "resmodules/files/resource");
options.addAll(defaultOptions);
CeyloncTaskImpl task;
if (alternative) {
task = getCompilerTask(options, // "resmodules/files/source/test/files/module.ceylon",
"resmodules/files/resource/test/files/extrafile");
} else {
task = getCompilerTask(options, "resmodules/files/source/test/files/module.ceylon", "resmodules/files/resource/test/files/README.txt");
}
Boolean ret = task.call();
assertTrue(ret);
File carFile = getModuleArchive("test.files", "1.0");
assertTrue(carFile.exists());
JarFile car = new JarFile(carFile);
ZipEntry moduleClass = car.getEntry("test/files/README.txt");
assertNotNull(moduleClass);
moduleClass = car.getEntry("test/files/extrafile");
if (alternative) {
assertNotNull(moduleClass);
} else {
assertNull(moduleClass);
}
moduleClass = car.getEntry("test/files/$module_.class");
assertNotNull(moduleClass);
car.close();
}
Aggregations