use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.
the class UnImportMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] parts = MagicCommandUtils.splitPath(command);
if (parts.length != 2) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, WRONG_FORMAT_MSG);
}
this.kernel.removeImport(new ImportPath(parts[1]));
return new MagicCommandOutput(MagicCommandOutput.Status.OK);
}
use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.
the class AddImportMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] parts = MagicCommandUtils.splitPath(command);
if (parts.length != 2) {
return new MagicCommandOutput(ERROR, WRONG_FORMAT_MSG + IMPORT);
}
ImportPath anImport = new ImportPath(parts[1]);
AddImportStatus status = this.kernel.addImport(anImport);
if (AddImportStatus.ERROR.equals(status)) {
return new MagicCommandOutput(ERROR, "Could not import " + parts[1]);
}
return new MagicCommandOutput(OK);
}
use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.
the class ClojureEvaluator method doResetEnvironment.
@Override
protected void doResetEnvironment() {
init();
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(loader);
for (ImportPath s : imports.getImportPaths()) {
addImportPathToShell(s);
}
for (String s : requirements) {
if (s != null && !s.isEmpty())
try {
clojureLoadString.invoke(String.format("(require '%s)", s));
} catch (Exception e) {
logger.error(e.getMessage());
}
}
Thread.currentThread().setContextClassLoader(oldLoader);
executorService.shutdown();
executorService = Executors.newSingleThreadExecutor();
}
use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.
the class ImportMagicCommandTest method addImport.
@Test
public void addImport() {
// given
String allCode = "%import com.twosigma.beakerx.widget.IntSlider\n" + "w = new IntSlider()";
Code code = CodeFactory.create(allCode, new Message(), kernel);
// when
code.execute(kernel, 1);
// then
PlainCode actual = (PlainCode) code.getCodeFrames().get(1);
assertThat(actual.getPlainCode()).isEqualTo("w = new IntSlider()");
assertThat(kernel.getImports().getImportPaths()).contains(new ImportPath("com.twosigma.beakerx.widget.IntSlider"));
}
use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.
the class Codev method configurePackage.
private String configurePackage() {
String pname = javaEvaluator.getPackageId();
Codev.CodeLine codeLine = getNotBlankLine();
Pattern p = Pattern.compile("\\s*package\\s+((?:[a-zA-Z]\\w*)(?:\\.[a-zA-Z]\\w*)*);.*");
Matcher m = p.matcher(codeLine.getLine());
if (m.matches()) {
pname = m.group(1);
lineNumbersMapping.put(1, codeLine.getIndex());
moveToNextLine();
}
javaSourceCode.append("package ");
javaSourceCode.append(pname);
javaSourceCode.append(";\n");
for (ImportPath i : javaEvaluator.getImports().getImportPaths()) {
javaSourceCode.append("import ");
javaSourceCode.append(i.asString());
javaSourceCode.append(";\n");
}
return pname;
}
Aggregations