Skip to content

Commit

Permalink
* Add to Java enums an intern() method and use it in toString()
Browse files Browse the repository at this point in the history
…to return non-null strings
  • Loading branch information
saudet committed May 16, 2018
1 parent a8179ee commit d20de9b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Add to Java enums an `intern()` method and use it in `toString()` to return non-null strings
* Add `PointerScope` to manage more easily the resources of a group of `Pointer` objects
* Fix `Parser` failing on `const void*&` or similar function arguments, and on constructors of class templates
* Add `Info.skipDefaults` to have the `Parser` ignore default function arguments and prevent method overloading
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3226,12 +3226,14 @@ boolean enumeration(Context context, DeclarationList declList) throws ParserExce
} else if (context.namespace != null && context.javaName == null) {
annotations += "@Namespace(\"" + context.namespace + "\") ";
}
decl.text += enumSpacing + annotations + "public static enum " + javaName + " {"
decl.text += enumSpacing + annotations + "public enum " + javaName + " {"
+ enumerators2 + token.expect(';').spacing + ";"
+ (comment.length() > 0 && comment.charAt(0) == ' ' ? comment.substring(1) : comment) + "\n\n"
+ enumSpacing2 + " public final " + javaType + " value;\n"
+ enumSpacing2 + " private " + javaName + "(" + javaType + " v) { this.value = v; }\n"
+ enumSpacing2 + " private " + javaName + "(" + javaName + " e) { this.value = e.value; }\n"
+ enumSpacing2 + " public " + javaName + " intern() { for (" + javaName + " e : values()) if (e.value == value) return e; return this; }\n"
+ enumSpacing2 + " @Override public String toString() { return intern().name(); }\n"
+ enumSpacing2 + "}";
Info info2 = new Info(infoMap.getFirst(cppType)).cppNames(cppName);
info2.valueTypes = Arrays.copyOf(info2.valueTypes, info2.valueTypes.length + 1);
Expand Down

0 comments on commit d20de9b

Please sign in to comment.