diff --git a/src/main/java/org/bytedeco/javacpp/tools/DocTag.java b/src/main/java/org/bytedeco/javacpp/tools/DocTag.java new file mode 100644 index 000000000..557f82bfb --- /dev/null +++ b/src/main/java/org/bytedeco/javacpp/tools/DocTag.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2019 Samuel Audet, Hervé Guillemet + * + * Licensed either under the Apache License, Version 2.0, or (at your option) + * under the terms of the GNU General Public License as published by + * the Free Software Foundation (subject to the "Classpath" exception), + * either version 2, or any later version (collectively, the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.gnu.org/licenses/ + * http://www.gnu.org/software/classpath/license.html + * + * or as provided in the LICENSE.txt file that accompanied this code. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.bytedeco.javacpp.tools; + +import java.util.regex.Pattern; + +/** + * Documentation tags, where we keep only the ones that could be compatible between Javadoc and Doxygen. + * + * @author Hervé Guillemet + */ +class DocTag { + static String[][] docTagsStr = { + { "authors?\\b", "author" }, + { "deprecated\\b", "deprecated" }, + { "(?:exception|throws?)\\b", "throws" }, + { "param\\s*(\\[[a-z,\\s]+\\])\\s+(\\S+)", "param $2 $1 " }, + { "param\\b", "param" }, + { "(?:returns?|result)\\b", "return" }, + { "(?:see|sa)\\b", "see" }, + { "since\\b", "since" }, + { "version\\b", "version" } + /* "code", "docRoot", "inheritDoc", "link", "linkplain", "literal", "serial", "serialData", "serialField", "value" */ + }; + static DocTag[] docTags = new DocTag[docTagsStr.length]; + static { + for (int i=0; i s.length()) { @@ -1483,22 +1479,20 @@ String commentDoc(String s, int startIndex) { } sb.insert(index + 1, indent + "

"); } else if (c == '\\' || c == '@') { - String foundTag = null; - for (String tag : docTags) { - if (ss.startsWith(tag)) { - foundTag = tag; + boolean tagFound = false; + for (DocTag tag : DocTag.docTags) { + Matcher matcher = tag.pattern.matcher(ss); + if (matcher.lookingAt()) { + StringBuffer sbuf = new StringBuffer(); + matcher.appendReplacement(sbuf, tag.replacement); + sb.replace(index + 1+ matcher.start(), + index + 1 + matcher.end(), sbuf.toString()); + sb.setCharAt(index, '@'); + tagFound = true; break; } } - if (foundTag != null) { - sb.setCharAt(index, '@'); - int n = index + foundTag.length() + 1; - if (sb.charAt(n) == 's' && !foundTag.endsWith("s")) { - sb.deleteCharAt(n); - } else if (!Character.isWhitespace(sb.charAt(n))) { - sb.insert(n, ' '); - } - } else { + if (!tagFound) { // keep unmapped tags around as part of the comments sb.setCharAt(index, '\\'); }