use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.
the class BaseEvaluator method initImports.
private void initImports(Map<String, Object> params) {
Collection<String> listOfImports = (Collection<String>) params.get(DefaultJVMVariables.IMPORTS);
List<ImportPath> importPaths = new ArrayList<>();
if (listOfImports != null) {
for (String line : listOfImports) {
if (!line.trim().isEmpty()) {
importPaths.add(new ImportPath(line));
}
}
if (this.imports != null) {
importPaths.addAll(this.imports.getImportPaths());
}
}
this.imports = new Imports(importPaths);
}
use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.
the class ReplWithClassLoaderFactory method getImportString.
@NotNull
public static String getImportString(List<ImportPath> importPaths) {
StringBuilder javaSourceCode = new StringBuilder();
for (ImportPath i : importPaths) {
javaSourceCode.append("import ");
javaSourceCode.append(adjustImport(i));
javaSourceCode.append("\n");
}
return javaSourceCode.toString();
}
use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.
the class ImportMagicCommandTest method allowExtraWhitespaces.
@Test
public void allowExtraWhitespaces() {
String allCode = "%import com.twosigma.beakerx.widget.IntSlider";
Code code = CodeFactory.create(allCode, new Message(), kernel);
code.execute(kernel, 1);
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 ImportMagicCommandTest method removeImport.
@Test
public void removeImport() {
// given
String allCode = "%import com.twosigma.beakerx.widget.IntSlider\n";
Code code = CodeFactory.create(allCode, new Message(), kernel);
code.execute(kernel, 1);
assertThat(kernel.getImports().getImportPaths()).contains(new ImportPath("com.twosigma.beakerx.widget.IntSlider"));
// when
String allRemoveCode = "%unimport com.twosigma.beakerx.widget.IntSlider\n";
Code codeToRemove = CodeFactory.create(allRemoveCode, new Message(), kernel);
codeToRemove.execute(kernel, 2);
// then
assertThat(kernel.getImports().getImportPaths()).doesNotContain(new ImportPath("com.twosigma.beakerx.widget.IntSlider"));
}
use of com.twosigma.beakerx.kernel.ImportPath in project beakerx by twosigma.
the class AddStaticImportMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] parts = MagicCommandUtils.splitPath(command);
if (parts.length != 3) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, WRONG_FORMAT_MSG);
}
AddImportStatus status = this.kernel.addImport(new ImportPath(parts[1] + " " + parts[2]));
if (AddImportStatus.ERROR.equals(status)) {
return new MagicCommandOutput(ERROR, "Could not import static " + parts[2]);
}
return new MagicCommandOutput(MagicCommandOutput.Status.OK);
}
Aggregations