+ var name = self.to_snake_case
+
+ # Strip the '_' prefix
+ while name.has_prefix("_") do name = name.substring(1, name.length-1)
+
+ # Escape Nit keywords
+ if nit_keywords.has(name) then name += "_"
+
+ # If the name starts by something other than a letter, prefix with `java_`
+ if not name.chars.first.is_letter then name = "java_" + name
+
+ name = name.replace("$", "_")
+
+ return name
+ end
+end
+
+redef class JavaClass
+ # Property names used in this class
+ private var used_names = new HashSet[String] is serialize
+
+ # Get an available property name for the Java property with `name` and parameters
+ #
+ # If `use_parameters_name` then expect that there will be conflicts,
+ # so use the types of `parameters` to build the name.
+ private fun nit_name_for(name: String, parameters: Array[JavaType], use_parameters_name: Bool, is_static: Bool, local_only: nullable Bool): String
+ do
+ # Append the name of each parameter
+ if use_parameters_name then
+ for param in parameters do
+ var id = param.id
+ id += "Array"*param.array_dimension
+ name += "_" + id
+ end
+ end
+
+ # Set of sets of property names, local or top-level
+ var local_used_names
+ var used_names
+ if is_static then
+ # Top-level methods
+ local_used_names = sys.top_level_used_names
+ used_names = sys.top_level_used_names
+ else if local_only == true then
+ # Local only: constructors
+ local_used_names = self.used_names
+ used_names = self.used_names