Skip to content

Commit 41a9714

Browse files
authored
Merge pull request #39 from camporter/additional_identifier_validation
Add additional keyword replacement for 'native'.
2 parents cb01752 + 257e48e commit 41a9714

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

gen/src/main/java/com/softlayer/api/gen/MetaConverter.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class MetaConverter {
1818
keywordReplacements = new HashMap<String, String>(2);
1919
keywordReplacements.put("package", "pkg");
2020
keywordReplacements.put("private", "priv");
21+
keywordReplacements.put("native", "nat");
2122
keywords = new HashSet<String>(Arrays.asList(new String[] {
2223
"abstract", "continue", "for", "new", "switch",
2324
"assert", "default", "goto", "package", "synchronized",
@@ -57,7 +58,7 @@ public String getClassName(String typeName) {
5758
if (invalidClassNames.contains(name)) {
5859
name = pieces[pieces.length - 2] + name;
5960
}
60-
return name;
61+
return getValidJavaIdentifier(name);
6162
}
6263

6364
public String getMethodOrPropertyName(String className, String name) {
@@ -66,7 +67,7 @@ public String getMethodOrPropertyName(String className, String name) {
6667
name = Character.toLowerCase(className.charAt(0)) + className.substring(1) +
6768
Character.toUpperCase(name.charAt(0)) + name.substring(1);
6869
}
69-
return name;
70+
return getValidJavaIdentifier(name);
7071
}
7172

7273
public String getPackageName(String typeName) {
@@ -79,11 +80,27 @@ public String getPackageName(String typeName) {
7980
for (int i = 0; i < pieces.length - 1; i++) {
8081
String piece = pieces[i].toLowerCase();
8182
String replacement = keywordReplacements.get(piece);
82-
pkg.append('.').append(replacement != null ? replacement : piece);
83+
piece = replacement != null ? replacement : piece;
84+
pkg.append('.').append(getValidJavaIdentifier(piece));
8385
}
8486
return pkg.toString();
8587
}
8688

89+
/**
90+
* Provides a valid java identifier from the given name.
91+
* Currently only checks for a valid start character and adds 'z'
92+
* if the name has an invalid character at the start.
93+
*
94+
* @param name The identifier name to use.
95+
* @return The new name after validating.
96+
*/
97+
public String getValidJavaIdentifier(String name) {
98+
if (!Character.isJavaIdentifierStart(name.charAt(0))) {
99+
name = "z" + name;
100+
}
101+
return name;
102+
}
103+
87104
public TypeClass buildTypeClass() {
88105
imports.clear();
89106
String packageName = getPackageName(type.name);

src/main/java/com/softlayer/api/http/HttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ public interface HttpClient extends Closeable {
2222
/** Make asynchronous HTTP invocation. All errors (inability to connect or API errors) are in the future. */
2323
public Future<HttpResponse> invokeAsync(Callable<?> setupBody);
2424

25-
/** Callback-form of {@link #invokeAsync()} */
25+
/** Callback-form of {@link #invokeAsync(Callable)} */
2626
public Future<?> invokeAsync(Callable<?> setupBody, ResponseHandler<HttpResponse> callback);
2727
}

0 commit comments

Comments
 (0)