From d0acda31e866040d8dbf8e72f983b78bafcb243a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 21 Jan 2014 02:06:21 +0100 Subject: GlueGen: Add 'MethodJavadoc comment-line..' configuration element, allowing to add custom API doc lines per method for the JavaMethodBindingEmitter --- src/java/com/jogamp/gluegen/JavaConfiguration.java | 101 ++++++++++++++------- .../jogamp/gluegen/JavaMethodBindingEmitter.java | 22 ++++- 2 files changed, 85 insertions(+), 38 deletions(-) diff --git a/src/java/com/jogamp/gluegen/JavaConfiguration.java b/src/java/com/jogamp/gluegen/JavaConfiguration.java index 23db7b4..ca7eccf 100644 --- a/src/java/com/jogamp/gluegen/JavaConfiguration.java +++ b/src/java/com/jogamp/gluegen/JavaConfiguration.java @@ -73,6 +73,8 @@ public class JavaConfiguration { protected static final Logger LOG = Logger.getLogger(JavaConfiguration.class.getPackage().getName()); + public static String NEWLINE = System.getProperty("line.separator"); + /** * Root directory for the hierarchy of generated java classes. Default is * working directory. @@ -114,7 +116,7 @@ public class JavaConfiguration { /** * List of imports to emit at the head of the output files. */ - private List imports = new ArrayList(); + private final List imports = new ArrayList(); /** * The package in which the generated glue code expects to find its @@ -130,47 +132,48 @@ public class JavaConfiguration { private String runtimeExceptionType = "RuntimeException"; private String unsupportedExceptionType = "UnsupportedOperationException"; - private Map accessControl = new HashMap(); - private Map typeInfoMap = new HashMap(); - private Set returnsString = new HashSet(); - private Map returnedArrayLengths = new HashMap(); + private final Map accessControl = new HashMap(); + private final Map typeInfoMap = new HashMap(); + private final Set returnsString = new HashSet(); + private final Map returnedArrayLengths = new HashMap(); /** * Key is function that has some byte[] or short[] arguments that should be * converted to String args; value is List of Integer argument indices */ - private Map> argumentsAreString = new HashMap>(); - private Set extendedIntfSymbolsIgnore = new HashSet(); - private Set extendedIntfSymbolsOnly = new HashSet(); - private Set extendedImplSymbolsIgnore = new HashSet(); - private Set extendedImplSymbolsOnly = new HashSet(); - private Set ignores = new HashSet(); - private Map ignoreMap = new HashMap(); - private Set ignoreNots = new HashSet(); - private Set unignores = new HashSet(); - private Set unimplemented = new HashSet(); + private final Map> argumentsAreString = new HashMap>(); + private final Set extendedIntfSymbolsIgnore = new HashSet(); + private final Set extendedIntfSymbolsOnly = new HashSet(); + private final Set extendedImplSymbolsIgnore = new HashSet(); + private final Set extendedImplSymbolsOnly = new HashSet(); + private final Set ignores = new HashSet(); + private final Map ignoreMap = new HashMap(); + private final Set ignoreNots = new HashSet(); + private final Set unignores = new HashSet(); + private final Set unimplemented = new HashSet(); private boolean forceUseNIOOnly4All = false; - private Set useNIOOnly = new HashSet(); + private final Set useNIOOnly = new HashSet(); private boolean forceUseNIODirectOnly4All = false; - private Set useNIODirectOnly = new HashSet(); - private Set manuallyImplement = new HashSet(); - private Map> customJavaCode = new HashMap>(); - private Map> classJavadoc = new HashMap>(); - private Map structPackages = new HashMap(); - private List customCCode = new ArrayList(); - private List forcedStructs = new ArrayList(); - private Map returnValueCapacities = new HashMap(); - private Map returnValueLengths = new HashMap(); - private Map> temporaryCVariableDeclarations = new HashMap>(); - private Map> temporaryCVariableAssignments = new HashMap>(); - private Map> extendedInterfaces = new HashMap>(); - private Map> implementedInterfaces = new HashMap>(); - private Map parentClass = new HashMap(); - private Map javaTypeRenames = new HashMap(); - private Map javaSymbolRenames = new HashMap(); - private Map> javaRenamedSymbols = new HashMap>(); - private Map> javaPrologues = new HashMap>(); - private Map> javaEpilogues = new HashMap>(); + private final Set useNIODirectOnly = new HashSet(); + private final Set manuallyImplement = new HashSet(); + private final Map> customJavaCode = new HashMap>(); + private final Map> classJavadoc = new HashMap>(); + private final Map> methodJavadoc = new HashMap>(); + private final Map structPackages = new HashMap(); + private final List customCCode = new ArrayList(); + private final List forcedStructs = new ArrayList(); + private final Map returnValueCapacities = new HashMap(); + private final Map returnValueLengths = new HashMap(); + private final Map> temporaryCVariableDeclarations = new HashMap>(); + private final Map> temporaryCVariableAssignments = new HashMap>(); + private final Map> extendedInterfaces = new HashMap>(); + private final Map> implementedInterfaces = new HashMap>(); + private final Map parentClass = new HashMap(); + private final Map javaTypeRenames = new HashMap(); + private final Map javaSymbolRenames = new HashMap(); + private final Map> javaRenamedSymbols = new HashMap>(); + private final Map> javaPrologues = new HashMap>(); + private final Map> javaEpilogues = new HashMap>(); /** Reads the configuration file. @param filename path to file that should be read @@ -547,6 +550,15 @@ public class JavaConfiguration { return res; } + public List javadocForMethod(String methodName) { + List res = methodJavadoc.get(methodName); + if (res == null) { + res = new ArrayList(); + methodJavadoc.put(methodName, res); + } + return res; + } + /** Returns a list of Strings containing Javadoc documentation for the given Java type name (not fully-qualified, only the class name); returns either null or an empty list if there is no @@ -979,6 +991,10 @@ public class JavaConfiguration { readCustomCCode(tok, filename, lineNo); // Warning: make sure delimiters are reset at the top of this loop // because readCustomCCode changes them. + } else if (cmd.equalsIgnoreCase("MethodJavadoc")) { + readMethodJavadoc(tok, filename, lineNo); + // Warning: make sure delimiters are reset at the top of this loop + // because readMethodJavadoc changes them. } else if (cmd.equalsIgnoreCase("ClassJavadoc")) { readClassJavadoc(tok, filename, lineNo); // Warning: make sure delimiters are reset at the top of this loop @@ -1297,6 +1313,21 @@ public class JavaConfiguration { } } + protected void readMethodJavadoc(StringTokenizer tok, String filename, int lineNo) { + try { + String tokenClassName = tok.nextToken(); + String restOfLine = tok.nextToken("\n\r\f"); + addMethodJavadoc(tokenClassName, restOfLine); + } catch (NoSuchElementException e) { + throw new RuntimeException("Error parsing \"MethodJavadoc\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + protected void addMethodJavadoc(String methodName, String code) { + List codeList = javadocForMethod(methodName); + codeList.add(code); + } + protected void readClassJavadoc(StringTokenizer tok, String filename, int lineNo) { try { String tokenClassName = tok.nextToken(); diff --git a/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java b/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java index 46ecab2..8c9f8bf 100644 --- a/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java +++ b/src/java/com/jogamp/gluegen/JavaMethodBindingEmitter.java @@ -48,6 +48,7 @@ import com.jogamp.gluegen.cgram.types.Type; import java.io.PrintWriter; import java.text.MessageFormat; +import java.util.Iterator; import java.util.List; /** @@ -67,8 +68,8 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { protected final CommentEmitter defaultInterfaceCommentEmitter = new InterfaceCommentEmitter(); // Exception type raised in the generated code if runtime checks fail - private String runtimeExceptionType; - private String unsupportedExceptionType; + private final String runtimeExceptionType; + private final String unsupportedExceptionType; protected boolean emitBody; protected boolean eraseBufferAndArrayTypes; @@ -98,7 +99,7 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { private static final String COMPOUND_ARRAY_SUFFIX = "_buf_array_copy"; // Only present to provide more clear comments - private JavaConfiguration cfg; + private final JavaConfiguration cfg; public JavaMethodBindingEmitter(MethodBinding binding, PrintWriter output, @@ -796,6 +797,21 @@ public class JavaMethodBindingEmitter extends FunctionEmitter { @Override protected String getCommentStartString() { return "/** "; } + @Override + protected String getCommentEndString() { + final StringBuilder sb = new StringBuilder(); + final String methodName = binding.getName(); + final List methodDocs = cfg.javadocForMethod(methodName); + for (Iterator iter = methodDocs.iterator(); iter.hasNext(); ) { + sb.append(JavaConfiguration.NEWLINE).append(getBaseIndentString()).append(iter.next()); + } + if( methodDocs.size() > 0 ) { + sb.append(JavaConfiguration.NEWLINE).append(getBaseIndentString()); + } + sb.append(" */"); + return sb.toString(); + } + @Override protected String getBaseIndentString() { return " "; } -- cgit v1.2.3