Skip to content

Commit ca571c9

Browse files
authored
Merge pull request #23 from NativeScript/pete/blacklist-gps-internals
Blacklist Google Play Services internal members
2 parents cd32109 + be8f549 commit ca571c9

File tree

4 files changed

+31
-34
lines changed

4 files changed

+31
-34
lines changed

dts-generator/src/main/java/com/telerik/dts/DtsApi.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public String generateDtsContent(List<JavaClass> javaClasses) {
6060
JavaClass currClass = javaClasses.get(i);
6161
currentFileClassname = currClass.getClassName();
6262

63+
String simpleClassName = getSimpleClassname(currClass);
64+
6365
if (currentFileClassname.startsWith("java.util.function") ||
6466
currentFileClassname.startsWith("android.support.v4.media.routing.MediaRouterJellybeanMr1") ||
6567
currentFileClassname.startsWith("android.support.v4.media.routing.MediaRouterJellybeanMr2") ||
@@ -84,13 +86,15 @@ public String generateDtsContent(List<JavaClass> javaClasses) {
8486
List<JavaClass> interfaces = getInterfaces(currClass);
8587
String extendsLine = getExtendsLine(superClass, interfaces);
8688

87-
if (getSimpleClassname(currClass).equals("AccessibilityDelegate")) {
89+
if (simpleClassName.equals("AccessibilityDelegate")) {
8890
sbContent.appendln(tabs + "export class " + getFullClassNameConcatenated(currClass) + extendsLine + " {");
8991
} else {
90-
sbContent.appendln(tabs + "export" + (isAbstract && !isInterface ? " abstract " : " ") + "class " + getSimpleClassname(currClass) + extendsLine + " {");
92+
sbContent.appendln(tabs + "export" + (isAbstract && !isInterface ? " abstract " : " ") + "class " + simpleClassName + extendsLine + " {");
9193
}
9294
// process member scope
9395

96+
mapNameMethod = new HashMap<String, Method>();
97+
9498
// process constructors for interfaces
9599
if (isInterface) {
96100
List<JavaClass> allInterfaces = getAllInterfaces(currClass);
@@ -175,7 +179,7 @@ private String getExtendsLine(JavaClass superClass, List<JavaClass> interfaces)
175179

176180
for (JavaClass clazz : interfaces) {
177181
String implementedInterface = clazz.getClassName().replaceAll("\\$", "\\.");
178-
if(!typeBelongsInCurrentTopLevelNamespace(implementedInterface)) {
182+
if (!typeBelongsInCurrentTopLevelNamespace(implementedInterface)) {
179183
implementedInterface = getAliasedClassName(implementedInterface);
180184
}
181185

@@ -187,7 +191,7 @@ private String getExtendsLine(JavaClass superClass, List<JavaClass> interfaces)
187191
}
188192

189193
String extendedClass = superClass.getClassName().replaceAll("\\$", "\\.");
190-
if(!typeBelongsInCurrentTopLevelNamespace(extendedClass)) {
194+
if (!typeBelongsInCurrentTopLevelNamespace(extendedClass)) {
191195
extendedClass = getAliasedClassName(extendedClass);
192196
}
193197

@@ -441,6 +445,8 @@ private Set<Field> getAllInterfacesFields(List<JavaClass> interfaces) {
441445
private void processMethod(Method m, JavaClass clazz, boolean isInterface, Set<String> methodsSet) {
442446
String name = m.getName();
443447

448+
if (isPrivateGoogleApiMember(name)) return;
449+
444450
if (m.isSynthetic() || (!m.isPublic() && !m.isProtected())) {
445451
return;
446452
}
@@ -498,10 +504,9 @@ private void writeMethods(Set<String> methodsSet) {
498504
}
499505

500506
private void cacheMethodBySignature(Method m) {
501-
mapNameMethod = new HashMap<String, Method>();
502-
String currMethodSig = getMethodFullSignature(m);
503-
if (!mapNameMethod.containsKey(currMethodSig)) {
504-
mapNameMethod.put(currMethodSig, m);
507+
String methodName = m.getName();
508+
if (!mapNameMethod.containsKey(methodName)) {
509+
mapNameMethod.put(methodName, m);
505510
}
506511
}
507512

@@ -613,6 +618,10 @@ private String getMethodParamSignature(JavaClass clazz, Method m) {
613618

614619
//field related
615620
private void processField(Field f, JavaClass clazz) {
621+
String fieldName = f.getName();
622+
623+
if (isPrivateGoogleApiMember(fieldName)) return;
624+
616625
String tabs = getTabs(this.indent + 1);
617626
sbContent.append(tabs + "public ");
618627
if (f.isStatic()) {
@@ -652,7 +661,7 @@ private String getTypeScriptTypeFromJavaType(JavaClass clazz, Type type) {
652661
convertToTypeScriptType(type, sb);
653662
tsType = sb.toString();
654663

655-
if (tsType.startsWith("java.util.function")) {
664+
if (tsType.startsWith("java.util.function") || isPrivateGoogleApiClass(tsType)) {
656665
tsType = "any /* " + tsType + "*/";
657666
}
658667
}
@@ -691,7 +700,7 @@ private void convertToTypeScriptType(Type type, StringBuilder tsType) {
691700
typeName = typeName.replaceAll("\\$", "\\.");
692701
}
693702

694-
if (!typeBelongsInCurrentTopLevelNamespace(typeName) && !typeName.startsWith("java.util.function.")) {
703+
if (!typeBelongsInCurrentTopLevelNamespace(typeName) && !typeName.startsWith("java.util.function.") && !isPrivateGoogleApiClass(typeName)) {
695704
tsType.append(getAliasedClassName(typeName));
696705
} else {
697706
tsType.append(typeName);
@@ -763,6 +772,15 @@ private String getTabs(int count) {
763772
return tabs;
764773
}
765774

775+
private boolean isPrivateGoogleApiMember(String memberName) {
776+
return memberName.startsWith("zz");
777+
}
778+
779+
private boolean isPrivateGoogleApiClass(String name) {
780+
String[] classNameParts = name.replace('$', '.').split("\\.");
781+
return classNameParts.length > 0 && classNameParts[classNameParts.length - 1].startsWith("zz");
782+
}
783+
766784
private void overrideFieldComparator() {
767785
BCELComparator cmp = Field.getComparator();
768786

dts-generator/src/main/java/com/telerik/dts/FileWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class FileWriter {
2222

2323
public FileWriter(File outDir, boolean writeMultipleFiles) {
2424
this.writeMultipleFiles = writeMultipleFiles;
25-
this.defaultDtsFileName = DEFAULT_DTS_FILE_NAME;
25+
this.defaultDtsFileName = DEFAULT_DTS_FILE_NAME + java.util.UUID.randomUUID().toString();
2626
this.outDir = outDir;
2727
}
2828

@@ -37,7 +37,7 @@ public void write(String content, String fileName) {
3737
String outFile = this.outDir.getAbsolutePath() + File.separator + this.defaultDtsFileName + ".d.ts";
3838
this.ps = new PrintStream(new FileOutputStream(outFile, /*append*/true));
3939

40-
//add helpers reference to the top of the file
40+
// add helpers reference to the top of the file
4141
if(this.isFirstRun) {
4242
ps.println("/// <reference path=\"./_helpers.d.ts\" />");
4343
this.isFirstRun = false;

dts-generator/src/main/java/com/telerik/dts/Generator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private void writeHelperTypings() {
4949
"}\n");
5050

5151
boolean append = false;
52-
52+
5353
for (String helper : helperTypings) {
5454
this.fw.writeHelperTypings(helper, append);
5555
append = true;

generate.win.bat

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)