diff --git a/CHANGELOG.md b/CHANGELOG.md index f8cbea17..cf8c0e6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ + * Improve `Parser` capabilities for `operator` and function templates ([pull #732](https://github.com/bytedeco/javacpp/pull/732)) * Fix `Parser` failing on nested initializer lists and on attributes found inside `enum` declarations * Fix `Parser` for basic containers like `std::optional >` ([issue #718](https://github.com/bytedeco/javacpp/issues/718)) * Add support for `std::basic_string` basic container ([issue bytedeco/javacpp-presets#1311](https://github.com/bytedeco/javacpp-presets/issues/1311)) diff --git a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java index a6e5b9be..a380b167 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java +++ b/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java @@ -47,7 +47,6 @@ public class InfoMap extends HashMap> { "std::function", "std::basic_string")) .put(new Info("basic/types").cppTypes("signed", "unsigned", "char", "short", "int", "long", "bool", "float", "double", "__int8", "__int16", "__int32", "__int64", "_Bool", "_Complex", "_Imaginary", "complex", "imaginary")) - .put(new Info("deprecated").annotations("@Deprecated")) .put(new Info("noexcept").annotations("@NoException(true)")) .put(new Info("__COUNTER__").cppText("#define __COUNTER__ 0")) @@ -192,10 +191,13 @@ String normalize(String name, boolean unconst, boolean untemplate) { String lastComp = comps.get(paramsIdx - 1); comps.set(paramsIdx - 1, Templates.strip(lastComp)); name = comps.get(0); - for (int i = 1; i < paramsIdx; i++) + for (int i = 1; i < paramsIdx; i++) { name += "::" + comps.get(i); + } name += comps.get(paramsIdx); - if (name.isEmpty()) return name; + if (name.isEmpty()) { + return name; + } } boolean foundConst = false, simpleType = true; String prefix = null; diff --git a/src/main/java/org/bytedeco/javacpp/tools/TemplateMap.java b/src/main/java/org/bytedeco/javacpp/tools/TemplateMap.java index 600e96b9..825cb5c7 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/TemplateMap.java +++ b/src/main/java/org/bytedeco/javacpp/tools/TemplateMap.java @@ -71,16 +71,17 @@ Type get(String key) { @Override public String toString() { - String res = "<"; - for (Map.Entry e: entrySet()) { - if (res.length() > 1) res += ","; + String s = "<"; + for (Map.Entry e : entrySet()) { + if (s.length() > 1) { + s += ","; + } Type t = e.getValue(); - if (t == null) - res += e.getKey(); - else - res += t.cppName; + s += t != null ? t.cppName : e.getKey(); + } + if (s.endsWith(">")) { + s += " "; } - if (res.charAt(res.length()-1) == '>') res += " "; - return res + ">"; + return s + ">"; } } diff --git a/src/main/java/org/bytedeco/javacpp/tools/Templates.java b/src/main/java/org/bytedeco/javacpp/tools/Templates.java index c9584375..ee5e1c97 100644 --- a/src/main/java/org/bytedeco/javacpp/tools/Templates.java +++ b/src/main/java/org/bytedeco/javacpp/tools/Templates.java @@ -47,6 +47,7 @@ static boolean notExists(String s) { return strip(s).length() == s.length(); } + /** Returns {@code splitNamespace(s, false)}. */ static List splitNamespace(String s) { return splitNamespace(s, false); } @@ -75,10 +76,13 @@ static List splitNamespace(String s, boolean returnParams) { int count = 1; for (pIndex--; pIndex >= 0; pIndex--) { char c = sTemplatesMasked.charAt(pIndex); - if (c == ')') count++; - else if (c == '(') { + if (c == ')') { + count++; + } else if (c == '(') { count--; - if (count == 0) break; + if (count == 0) { + break; + } } } } @@ -100,7 +104,9 @@ else if (c == '(') { comps.add(s.substring(start)); params = ""; } - if (returnParams) comps.add(params); + if (returnParams) { + comps.add(params); + } return comps; } }