use of beast.core.Input in project beast2 by CompEvol.
the class DocumentationTest method testInputTipText.
// testDescriptions
/**
* Check all inputs of plug-ins have a proper tip text, again
* to facilitate proper documentation. *
*/
@Test
public void testInputTipText() {
final List<String> pluginNames = PackageManager.find(beast.core.BEASTObject.class, PackageManager.IMPLEMENTATION_DIR);
final List<String> undocumentedInputs = new ArrayList<String>();
for (final String beastObjectName : pluginNames) {
try {
final BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
final List<Input<?>> inputs = beastObject.listInputs();
for (final Input<?> input : inputs) {
boolean hasSatisfactoryDescription = false;
final String tipText = input.getTipText();
if (isProperDocString(tipText)) {
hasSatisfactoryDescription = true;
}
if (!hasSatisfactoryDescription) {
undocumentedInputs.add(beastObjectName + ":" + input.getName());
}
}
} catch (Exception e) {
}
}
assertTrue("No proper input tip text (at least " + N_WORDS + " words and " + N_CHARS + " characters) for: " + undocumentedInputs.toString(), undocumentedInputs.size() == 0);
}
use of beast.core.Input in project beast2 by CompEvol.
the class XMLElementNameTest method test_NameUniqueness.
/**
* test that Inputs have a unique name
* It can happen that a derived class uses the same Input name as one of its ancestors
*/
@Test
public void test_NameUniqueness() {
List<String> pluginNames = PackageManager.find(beast.core.BEASTObject.class, PackageManager.IMPLEMENTATION_DIR);
List<String> improperInputs = new ArrayList<String>();
for (String beastObjectName : pluginNames) {
try {
BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
List<Input<?>> inputs = beastObject.listInputs();
Set<String> names = new HashSet<String>();
for (Input<?> input : inputs) {
String name = input.getName();
if (names.contains(name)) {
improperInputs.add(beastObjectName + "." + name);
break;
}
names.add(name);
}
} catch (InstantiationException e) {
// ignore
} catch (Exception e) {
// ignore
}
}
if (improperInputs.size() > 0) {
String str = improperInputs.toString();
str = str.replaceAll(",", "\n");
System.err.println("Input names are not unique:\n" + str);
}
// not activated till problem with naming is solved
assertTrue("Input names are not unique: " + improperInputs.toString(), improperInputs.size() == 0);
}
use of beast.core.Input in project beast2 by CompEvol.
the class Document method process.
void process(BEASTObjectShape shape, int depth) throws IllegalArgumentException, IllegalAccessException, InstantiationException, ClassNotFoundException {
BEASTInterface beastObject = shape.m_beastObject;
List<Input<?>> inputs = beastObject.listInputs();
for (Input<?> input_ : inputs) {
Object o = input_.get();
if (o != null) {
if (o instanceof List<?>) {
for (Object o2 : (List<?>) o) {
addInput(shape, o2, depth + 1, input_.getName());
}
} else if (o instanceof BEASTInterface) {
addInput(shape, o, depth + 1, input_.getName());
// } else {
// it is a primitive type
}
}
}
}
use of beast.core.Input in project beast2 by CompEvol.
the class StateNodeInitialiserListInputEditor method addPluginItem.
@Override
protected InputEditor addPluginItem(Box itemBox, BEASTInterface beastObject) {
final StateNodeInitialiser currentInitialiser = (StateNodeInitialiser) beastObject;
Input initialInput = beastObject.getInput("initial");
List<BeautiSubTemplate> sAvailablePlugins = doc.getInputEditorFactory().getAvailableTemplates(initialInput, (BEASTInterface) beastObject, null, doc);
JComboBox<?> comboBox = null;
if (sAvailablePlugins.size() > 0) {
sAvailablePlugins.remove(sAvailablePlugins.size() - 1);
comboBox = new JComboBox<>(sAvailablePlugins.toArray());
String sID = beastObject.getID();
try {
sID = sID.substring(0, sID.indexOf('.'));
} catch (Exception e) {
throw new RuntimeException("Improperly formatted ID: " + sID);
}
for (BeautiSubTemplate template : sAvailablePlugins) {
if (template.matchesName(sID)) {
comboBox.setSelectedItem(template);
}
}
comboBox.setName("Initialiser");
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JComboBox<?> currentComboBox = (JComboBox<?>) e.getSource();
BeautiSubTemplate template = (BeautiSubTemplate) currentComboBox.getSelectedItem();
PartitionContext partitionContext;
partitionContext = doc.getContextFor(beastObject);
try {
Object o = template.createSubNet(partitionContext, true);
StateNodeInitialiser newInitialiser = (StateNodeInitialiser) o;
List<StateNodeInitialiser> inits = (List<StateNodeInitialiser>) m_input.get();
int i = inits.indexOf(currentInitialiser);
inits.set(i, newInitialiser);
System.out.println(inits.size());
} catch (Exception ex) {
ex.printStackTrace();
}
sync();
refreshPanel();
}
});
}
});
}
String name = beastObject.getID();
Object o = beastObject.getInput("initial").get();
if (o instanceof BEASTInterface) {
name = ((BEASTInterface) o).getID();
}
if (name == null || name.length() == 0) {
name = beastObject.getClass().getName();
name = name.substring(name.lastIndexOf('.') + 1);
}
JLabel label = new JLabel("Initial " + name + ":");
itemBox.add(Box.createRigidArea(new Dimension(5, 1)));
itemBox.add(label);
if (comboBox != null) {
itemBox.add(comboBox);
}
itemBox.add(Box.createHorizontalGlue());
return this;
}
use of beast.core.Input in project beast2 by CompEvol.
the class MRCAPriorInputEditor method disableTipSampling.
// remove TipDatesRandomWalker from list of operators
private static void disableTipSampling(BEASTInterface m_beastObject, BeautiDoc doc) {
// First, find the operator
TipDatesRandomWalker operator = null;
MRCAPrior prior = (MRCAPrior) m_beastObject;
TaxonSet taxonset = prior.taxonsetInput.get();
// However, if there is an TipDatesRandomWalker with taxonset as input, we want to remove it.
for (BEASTInterface o : taxonset.getOutputs()) {
if (o instanceof TipDatesRandomWalker) {
operator = (TipDatesRandomWalker) o;
}
}
if (operator == null) {
// should never happen
return;
}
// remove from list of operators
Object o = doc.mcmc.get().getInput("operator");
if (o instanceof Input<?>) {
Input<List<Operator>> operatorInput = (Input<List<Operator>>) o;
List<Operator> operators = operatorInput.get();
operators.remove(operator);
}
}
Aggregations