use of abs.backend.java.codegeneration.JavaCode in project abstools by abstools.
the class JavaJob method generateJavaCode.
/**
* Generates .java files (no .class files).
* If 'product' is set, will flatten accordingly.
* @param monitor - must not be null
* @param path - where to add the modules / java-files
* @param project - the ABS project
* @throws IOException, if unable to create java files
* @throws AbsJobException, if unable to generate java files
* @throws JavaCodeGenerationException, if unable to generate java files
* @throws CoreException
* @throws NoModelException
*/
private void generateJavaCode(IProgressMonitor monitor, Path path, IProject project) throws AbsJobException, IOException, JavaCodeGenerationException, CoreException, NoModelException {
assert monitor != null;
monitor.subTask("Creating java source files");
AbsNature nat = UtilityFunctions.getAbsNature(project);
synchronized (nat.modelLock) {
Model model = nat.getCompleteModel();
if (model == null)
throw new NoModelException();
JavaCode javaCode = new JavaCode(path.toFile());
if (product != null) {
/* [stolz] Flattening for a product will mangle the model according to [ramus]...
*/
// work on a copy:
model = model.treeCopyNoTransform();
model.flushTreeCache();
String productN = product.getName();
try {
model.flattenForProduct(productN);
model.flushCache();
if (model.hasErrors() || model.hasTypeErrors()) {
nat.createMarkers(model);
throw new AbsJobException("An ABS file in the project has type errors after applying deltas");
}
} catch (WrongProgramArgumentException e) {
throw new AbsJobException(e);
} catch (DeltaModellingException e) {
throw new AbsJobException(e);
}
}
// TODO: the second parameter toggles listener code creation (3
// Java method calls per ABS statement); make this configurable
model.generateJavaCode(javaCode, true);
int countUnits = model.getNumCompilationUnit();
if (countUnits == 0)
throw new AbsJobException("No compilation unit found");
}
}
use of abs.backend.java.codegeneration.JavaCode in project abstools by abstools.
the class JavaBackendTest method assertValidJavaExecution.
void assertValidJavaExecution(boolean withStdLib, String... codeLines) throws Exception {
StringBuilder absCode = new StringBuilder();
for (String line : codeLines) {
absCode.append(line);
absCode.append("\n");
}
JavaCode javaCode = getJavaCode(absCode.toString(), withStdLib ? Config.WITH_STD_LIB : null);
try {
String genDir = javaCode.getSrcDir().getAbsolutePath() + "/gen/test";
javaCode.compile("-classpath", "bin", "-d", genDir);
final ABSRuntime r = makeAbsRuntime();
r.enableDebugging(true);
final boolean[] finished = new boolean[] { false };
final List<ABSException> exceptions = Collections.synchronizedList(new ArrayList<ABSException>());
r.addSystemObserver(new SystemObserver() {
@Override
public void systemStarted() {
}
@Override
public void systemFinished() {
synchronized (finished) {
finished[0] = true;
finished.notifyAll();
}
}
@Override
public void systemError(ABSException e) {
exceptions.add(e);
}
@Override
public void newCOGCreated(COGView cog, ObjectView initialObject) {
}
});
r.start(new File(genDir), "Test.Main");
while (!finished[0]) {
synchronized (finished) {
finished.wait(100);
}
}
r.shutdown();
for (ABSException e : exceptions) {
throw e;
}
} catch (Exception e) {
System.out.println(javaCode);
throw e;
} finally {
javaCode.deleteCode();
}
}
use of abs.backend.java.codegeneration.JavaCode in project abstools by abstools.
the class JavaBackendTest method assertEvalEquals.
public void assertEvalEquals(String absCode, boolean value) throws Exception {
JavaCode javaCode = getJavaCode(absCode, Config.WITH_STD_LIB);
if (DEBUG)
System.err.println(javaCode);
boolean res = runJavaAndTestResult(javaCode, false);
if (value != res) {
// System.out.println(javaCode);
}
assertEquals(value, res);
}
use of abs.backend.java.codegeneration.JavaCode in project abstools by abstools.
the class JavaDebuggingTest method assertOutputContains.
private void assertOutputContains(String absCode, String expectedOutput) throws Exception {
JavaCode code = getJavaCode("module JavaTest;" + absCode, Config.WITH_STD_LIB);
// System.out.println(java);
String output = runJava(code, "-Dabs.debugger=" + TestDebugger.class.getName()).toString().trim();
Assert.assertTrue("Expected to find " + expectedOutput + ", but output was:\n" + output, output.contains(expectedOutput));
}
use of abs.backend.java.codegeneration.JavaCode in project abstools by abstools.
the class JavaObservationTest method assertOutputContains.
private void assertOutputContains(String absCode, String expectedOutput) throws Exception {
JavaCode code = getJavaCode("module JavaTest;" + STDDATA + absCode, Config.WITH_STD_LIB);
// System.out.println(java);
String output = runJava(code, "-Dabs.systemobserver=" + TestSystemObserver.class.getName()).toString().trim();
Assert.assertTrue("Expected to find " + expectedOutput + ", but output was:\n" + output, output.contains(expectedOutput));
}
Aggregations