Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions compiler/src/java_plugin/cpp/java_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,23 @@ static std::set<std::string> java_keywords = {
"false",
};

// Methods on java.lang.Object that take no arguments.
static std::set<std::string> java_object_methods = {
"clone",
"finalize",
"getClass",
"hashCode",
"notify",
"notifyAll",
"toString",
"wait",
};

// Adjust a method name prefix identifier to follow the JavaBean spec:
// - decapitalize the first letter
// - remove embedded underscores & capitalize the following letter
// Finally, if the result is a reserved java keyword, append an underscore.
// Finally, if the result is a reserved java keyword or an Object method,
// append an underscore.
static std::string MixedLower(std::string word) {
std::string w;
w += tolower(word[0]);
Expand All @@ -159,7 +172,8 @@ static std::string MixedLower(std::string word) {
after_underscore = false;
}
}
if (java_keywords.find(w) != java_keywords.end()) {
if (java_keywords.find(w) != java_keywords.end() ||
java_object_methods.find(w) != java_object_methods.end()) {
return w + "_";
}
return w;
Expand Down