Search in sources :

Example 11 with BEASTObject

use of beast.core.BEASTObject 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);
}
Also used : Input(beast.core.Input) ArrayList(java.util.ArrayList) BEASTObject(beast.core.BEASTObject) Test(org.junit.Test)

Example 12 with BEASTObject

use of beast.core.BEASTObject 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);
}
Also used : Input(beast.core.Input) ArrayList(java.util.ArrayList) BEASTObject(beast.core.BEASTObject) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with BEASTObject

use of beast.core.BEASTObject in project beast2 by CompEvol.

the class DocMaker method getHTML.

// createBEASTObjectPage
public String getHTML(String beastObjectName, boolean useExternalStyleSheet) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
    StringBuffer buf = new StringBuffer();
    buf.append("<html>\n<head>\n<title>BEAST " + version.getVersionString() + " Documentation: " + beastObjectName + "</title>\n");
    if (useExternalStyleSheet) {
        buf.append("<link rel='StyleSheet' href='/tmp/styles.css' type='text/css'>\n");
    } else {
        buf.append("<style type='text/css'>\n");
        buf.append(getCSS());
        buf.append("</style>\n");
    }
    buf.append("</head>\n");
    buf.append("<body>\n");
    buf.append("<h1>BEAST " + version.getVersionString() + " Documentation: " + beastObjectName + "</h1>\n");
    BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
    // show all implementation of this plug-in
    String[] implementations = m_isa.get(beastObjectName);
    if (implementations == null) {
        // this class is not documented, perhaps outside ClassDiscover path?
        buf.append("No documentation available for " + beastObjectName + ". Perhaps it is not in the ClassDiscovery path\n");
        buf.append("</body>\n");
        buf.append("</html>\n");
        return buf.toString();
    }
    if (implementations.length > 0) {
        buf.append("<table border='1px'>\n");
        buf.append("<thead><tr><td>implemented by the following</td></tr></thead>\n");
        for (String imp : implementations) {
            buf.append("<tr><td><a href='" + imp + ".html'>" + imp + "</a></td></tr>\n");
        }
        buf.append("</table>\n");
    }
    // show descriptions of all plug-ins implemented by this plug in...
    buf.append("<p>" + m_descriptions.get(beastObjectName) + "</p>\n");
    // show citation (if any)
    for (Citation citation : beastObject.getCitationList()) {
        buf.append("<h2>Reference:</h2><p>" + citation.value() + "</p>\n");
        if (citation.DOI().length() > 0) {
            buf.append("<p><a href=\"http://dx.doi.org/" + citation.DOI() + "\">doi:" + citation.DOI() + "</a></p>\n");
        }
    }
    // show if this is Loggable
    if (m_sLoggables.contains(beastObjectName)) {
        buf.append("<p>Logable:");
        buf.append(" yes, this can be used in a log.");
        buf.append("</p>\n");
    // } else {
    // buf.append(" no, this cannot be used in a log.");
    }
    // show short list its inputs
    buf.append("<h2>Inputs:</h2>\n");
    buf.append("<p>");
    List<Input<?>> inputs = beastObject.listInputs();
    for (Input<?> input : inputs) {
        buf.append("<a href='#" + input.getName() + "'>" + input.getName() + "</a>, ");
    }
    buf.delete(buf.length() - 3, buf.length() - 1);
    buf.append("</p>\n");
    // list its inputs
    if (inputs.size() == 0) {
        buf.append("&lt;none&gt;");
    }
    for (Input<?> input : inputs) {
        buf.append("<p>&nbsp</p>");
        buf.append("<table id='" + input.getName() + "' border='1px' width='90%'>\n");
        buf.append("<caption>" + input.getName() + "</caption>\n");
        buf.append("<thead><tr bgcolor='#AAAAAA'><td>type: " + getType(beastObject, input.getName()) + "</td></tr></thead>\n");
        buf.append("<tr><td>" + input.getTipText() + "</td></tr>\n");
        buf.append("<tr><td>\n");
        switch(input.getRule()) {
            case OPTIONAL:
                buf.append("Optional input");
                if (input.defaultValue != null) {
                    if (input.defaultValue instanceof Integer || input.defaultValue instanceof Double || input.defaultValue instanceof Boolean || input.defaultValue instanceof String) {
                        buf.append(". Default: " + input.defaultValue.toString());
                    }
                }
                break;
            case REQUIRED:
                buf.append("Required input");
                break;
            case XOR:
                buf.append("Either this, or " + input.getOther().getName() + " needs to be specified");
                break;
            case FORBIDDEN:
                buf.append("Forbidden: must not be specified");
                break;
        }
        buf.append("</td></tr>\n");
        buf.append("</table>\n");
    }
    buf.append("</body>\n");
    buf.append("</html>\n");
    return buf.toString();
}
Also used : Input(beast.core.Input) BEASTObject(beast.core.BEASTObject) Citation(beast.core.Citation)

Example 14 with BEASTObject

use of beast.core.BEASTObject in project beast2 by CompEvol.

the class DocMaker method makeJavaDoc.

// c'tor
/**
 * print @Description and Input.description info so that it can
 * be inserted in the code before creating Javadoc documentation
 * for the Beast II SDK.
 */
void makeJavaDoc() {
    for (String beastObjectName : m_beastObjectNames) {
        try {
            BEASTObject beastObject = (BEASTObject) Class.forName(beastObjectName).newInstance();
            Log.info.println(beastObjectName + ":@description:" + beastObject.getDescription());
            for (Input<?> input : beastObject.listInputs()) {
                Log.info.println(beastObjectName + ":" + input.getName() + ":" + input.getTipText());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : BEASTObject(beast.core.BEASTObject) FileNotFoundException(java.io.FileNotFoundException)

Example 15 with BEASTObject

use of beast.core.BEASTObject in project beast2 by CompEvol.

the class BeautiBase method assertTraceLogEqual.

void assertTraceLogEqual(String... ids) {
    System.err.println("assertTraceLogEqual");
    Logger logger = (Logger) doc.pluginmap.get("tracelog");
    List<BEASTObject> logs = logger.loggersInput.get();
    asserListsEqual(logs, ids);
}
Also used : BEASTObject(beast.core.BEASTObject) Logger(beast.core.Logger)

Aggregations

BEASTObject (beast.core.BEASTObject)23 ArrayList (java.util.ArrayList)10 BEASTInterface (beast.core.BEASTInterface)7 Input (beast.core.Input)6 Test (org.junit.Test)5 RealParameter (beast.core.parameter.RealParameter)4 Distribution (beast.core.Distribution)3 Parameter (beast.core.parameter.Parameter)3 CompoundDistribution (beast.core.util.CompoundDistribution)3 XMLParserException (beast.util.XMLParserException)3 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 SAXException (org.xml.sax.SAXException)3 Function (beast.core.Function)2 Logger (beast.core.Logger)2 StateNode (beast.core.StateNode)2 Alignment (beast.evolution.alignment.Alignment)2