Skip to content

Commit

Permalink
A go at @cdk.ioopionts
Browse files Browse the repository at this point in the history
Change-Id: I2bc951328de7bbb551271b24a59b71db91ba6c5c
  • Loading branch information
egonw committed Aug 6, 2012
1 parent 0015e6f commit d8a5504
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions javadoc.xml
Expand Up @@ -77,6 +77,7 @@
<taglet name="net.sf.cdk.tools.doclets.CDKThreadSafeTaglet" path="jar/xom-1.1.jar:src/main" />
<taglet name="net.sf.cdk.tools.doclets.CDKThreadNonSafeTaglet" path="jar/xom-1.1.jar:src/main" />
<taglet name="net.sf.cdk.tools.doclets.CDKGitTaglet" path="jar/xom-1.1.jar:src/main" />
<taglet name="net.sf.cdk.tools.doclets.CDKIOOptionsTaglet" path="jar/xom-1.1.jar:src/main" />
<packageset dir="${src}/main" defaultexcludes="yes">
<include name="org/openscience/cdk/**" />
</packageset>
Expand Down
124 changes: 124 additions & 0 deletions src/main/net/sf/cdk/tools/doclets/CDKIOOptionsTaglet.java
@@ -0,0 +1,124 @@
/* Copyright (C) 2012 Egon Willighagen <egonw@users.sf.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.sf.cdk.tools.doclets;

import java.util.Map;

import org.openscience.cdk.io.IChemObjectIO;
import org.openscience.cdk.io.setting.IOSetting;

import com.sun.javadoc.SourcePosition;
import com.sun.javadoc.Tag;
import com.sun.tools.doclets.Taglet;

/**
* Source for the cdk.iooptions JavaDoc tag. When a class is tagged with this
* tag, the JavaDoc will an overview of the IO options.
*
* <p>The syntax must be as follows:
* <pre>
* @cdk.iooptions
* </pre>
*/
public class CDKIOOptionsTaglet implements Taglet {

private static final String NAME = "cdk.iooptions";

public String getName() {
return NAME;
}

public boolean inField() {
return false;
}

public boolean inConstructor() {
return false;
}

public boolean inMethod() {
return false;
}

public boolean inOverview() {
return false;
}

public boolean inPackage() {
return false;
}

public boolean inType() {
return true;
}

public boolean isInlineTag() {
return false;
}

public static void register(Map<String, CDKIOOptionsTaglet> tagletMap) {
CDKIOOptionsTaglet tag = new CDKIOOptionsTaglet();
Taglet t = (Taglet) tagletMap.get(tag.getName());
if (t != null) {
tagletMap.remove(tag.getName());
}
tagletMap.put(tag.getName(), tag);
}

public String toString(Tag tag) {
return "<DT><B>IO options: </B><DD>"
+ expand(tag) + "</DD>\n";
}

public String toString(Tag[] tags) {
if (tags.length == 0) {
return null;
} else {
return toString(tags[0]);
}
}

private String expand(Tag tag) {
// create a table with IOOptions
StringBuffer tableContent = new StringBuffer();
SourcePosition file = tag.position();
String pathAndFile = file.file().toString();
pathAndFile = pathAndFile.replaceAll("/", ".");
pathAndFile = pathAndFile.substring(pathAndFile.indexOf("src.main") + 9);
pathAndFile = pathAndFile.substring(0, pathAndFile.indexOf(".java"));
try {
Class ioClass = Class.forName(pathAndFile);
Object ioInstance = ioClass.newInstance();
if (ioInstance instanceof IChemObjectIO) {
IChemObjectIO objectIO = (IChemObjectIO)ioInstance;
tableContent.append("<table>");
for (IOSetting setting : objectIO.getIOSettings()) {
tableContent.append("<tr>");
tableContent.append("<td>" + setting.getName() + "</td>");
tableContent.append("<td></td>");
tableContent.append("</tr>");
}
tableContent.append("</table>");
}
} catch (Exception e) {
e.printStackTrace();
return "";
}
return tableContent.toString();
}

}
1 change: 1 addition & 0 deletions src/main/org/openscience/cdk/io/CMLWriter.java
Expand Up @@ -101,6 +101,7 @@
* @cdk.depends jumbo50.jar
* @cdk.require java1.5+
* @cdk.bug 1565563
* @cdk.iooptions
*
* @see java.io.FileWriter
* @see java.io.StringWriter
Expand Down

0 comments on commit d8a5504

Please sign in to comment.