-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't use ObjectiveC-based handling of reserved keywords for Java #187
Conversation
RicoYao
commented
Mar 18, 2019
- Java has its own set of different reserved keywords.
- Also use a "uid" property name for "id" (ObjC uses "identifier). This is pinterest-specific and we may have to add in a custom override for this instead later.
9b03435
to
c9c5b4c
Compare
Sources/Core/StringExtensions.swift
Outdated
extension String { | ||
func indent() -> String { | ||
// We indent with tabs and in a post process the tabs are changed to a specific number of spaces | ||
return "\t" + self | ||
} | ||
|
||
/// All components separated by _ will be capitalized including the first one | ||
func snakeCaseToCamelCase() -> String { | ||
func snakeCaseToCamelCase(_ language: Languages = Languages.objectiveC) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some idea: What if we would create a "Language" Enum / Struct that knows that language Self
is, e.g. either Objective-C, Java or some other language and that would contain the logic around reserved word replacement and capabilities such as creating snakeCaseToCamelCase
, snakeCaseToPropertyName
, snakeCaseToPropertyName
. We could have one instance of language and passing this around and so we don't have to have this if else branching in a String extension as well as you don't have to pass in .java
, .objectiveC
everywhere as parameter. You would just call snakeCaseToCamelCase
on the Language object you have in the Renderer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Moved to Languages
enum.
Sources/Core/StringExtensions.swift
Outdated
@@ -137,35 +137,119 @@ let objectiveCReservedWords = Set<String>([ | |||
"while", | |||
]) | |||
|
|||
// TODO: "id" is technically allowed. It's possible not everyone wants this replacement. | |||
let javaReservedWordReplacements = [ | |||
"id": "uid", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason for this? The mapping for ObjC is largely because “id” is a reserved word
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in a separate comment this is pinterest-specific.
Sources/Core/StringExtensions.swift
Outdated
var str: String = self | ||
|
||
if let replacementString = objectiveCReservedWordReplacements[self.lowercased()] as String? { | ||
str = replacementString | ||
if language == .objectiveC { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a switch over if/else and if the language type is .flow we should do nothing
The benefit is exhaustive switching will raise errors as new languages are added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Sources/Core/StringExtensions.swift
Outdated
|
||
// https://en.wikipedia.org/wiki/List_of_Java_keywords | ||
let javaReservedWords = Set<String>([ | ||
"abstract", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should move these new functions as extensions on the language enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Why is this necessary? Just lots of code that would need to be updated if this was changed? |
In addition to code changes, there's a lot of institutional behavior around |
- Java has its own set of different reserved keywords. - Also use a "uid" property name for "id" (ObjC uses "identifier). This is pinterest-specific and we may have to add in a custom override for this instead later.
c9c5b4c
to
1b81b68
Compare
… stragglers. make format/lint.
"while", | ||
]) | ||
|
||
// TODO: "id" is technically allowed. It's possible not everyone wants this replacement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you file an issue to revisit this? I don't want to necessarily block internal progress but I think this warrants a further discussion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -90,7 +90,7 @@ extension JavaFileRenderer { | |||
fatalError("Bad reference found in schema for class: \(className)") | |||
} | |||
case .oneOf(types: _): | |||
return "\(className)\(param.snakeCaseToCamelCase())" | |||
return "\(className)\(Languages.java.snakeCaseToCamelCase(param))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you file a ticket for abstracting the language type here ? I think the context of java / objc render should be able to influence which snakeCaseToCamelCase
logic is used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rahul-malik Do you happen to know what I else I need to change to get the |
@RicoYao - Did you run Please file a ticket to improve this since it's not obvious, I'll take care of making this a part of the |
@RicoYao - I just looked at the failure log, run that make command and commit the changes and this should be fixed. sorry for the confusion! |
Thanks @rahul-malik that did the trick! FYI, I also had to run |