Skip to content

Commit 90eadde

Browse files
committed
refactored: classNameSeparator is now a constant in binding generator and runtime
changed tests so they can work with the new changes
1 parent a6ee7ea commit 90eadde

File tree

8 files changed

+22
-15
lines changed

8 files changed

+22
-15
lines changed

binding-generator/Generator/src/com/tns/bindings/Dump.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
public class Dump
1414
{
15+
public static final char CLASS_NAME_LOCATION_SEPARATOR = '_';
16+
1517
private static final String callJsMethodSignatureCtor = "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;Z[Ljava/lang/Object;";
1618
private static final String callJsMethodSignatureMethod = "Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;[Ljava/lang/Object;";
1719
private static final String LCOM_TNS = "Lcom/tns/gen/";
@@ -228,7 +230,7 @@ public void generateProxy(ApplicationWriter aw, String proxyName, Class<?> class
228230
//String methodSignature = org.objectweb.asm.Type.getMethodDescriptor(Object.class.getMethods()[0]);
229231
String tnsClassSignature = LCOM_TNS +
230232
classSignature.substring(1, classSignature.length() - 1).replace("$", "_")
231-
+ "-" + proxyName + ";";
233+
+ CLASS_NAME_LOCATION_SEPARATOR + proxyName + ";";
232234

233235
ClassVisitor cv = generateClass(aw, classTo, classSignature, tnsClassSignature);
234236
Method[] methods = getSupportedMethods(classTo, methodOverrides);

binding-generator/Generator/src/com/tns/bindings/ProxyGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public String generateProxy(String proxyName, Class<?> classToProxy, HashSet<Str
5353
aw.visitEnd();
5454
byte[] generatedBytes = aw.toByteArray();
5555

56-
String proxyFileName = classToProxy.getName().replace('$', '_') + "-" + proxyName;
56+
String proxyFileName = classToProxy.getName().replace('$', '_') + Dump.CLASS_NAME_LOCATION_SEPARATOR + proxyName;
5757
if (proxyThumb != null)
5858
{
5959
proxyFileName += "-" + proxyThumb;

src/jni/Constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Constants
88

99
const static int PRIMITIVE_TYPE_OFFSET = 1;
1010

11+
const static char CLASS_NAME_LOCATION_SEPARATOR = '_';
12+
1113
private:
1214
Constants() {}
1315
};

src/jni/MetadataNode.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ void MetadataNode::InterfaceConstructorCallback(const v8::FunctionCallbackInfo<v
734734
SetInstanceMetadata(info.GetIsolate(), implementationObject, node);
735735

736736
//@@@ Refactor
737-
auto fullName = className + "-" + extendNameAndLocation;
737+
auto fullName = className + Constants::CLASS_NAME_LOCATION_SEPARATOR + extendNameAndLocation;
738738
thiz->SetHiddenValue(ConvertToV8String("implClassName"), ConvertToV8String(fullName));
739739
//
740740

@@ -1073,7 +1073,7 @@ void MetadataNode::ExtendCallMethodHandler(const v8::FunctionCallbackInfo<v8::Va
10731073
DEBUG_WRITE("ExtendsCallMethodHandler: called with %s", ConvertToString(extendName).c_str());
10741074

10751075
auto extendNameAndLocation = extendLocation + ConvertToString(extendName);
1076-
auto fullClassName = node->m_name + '-' + extendNameAndLocation; //ConvertToString(extendName);
1076+
auto fullClassName = node->m_name + Constants::CLASS_NAME_LOCATION_SEPARATOR + extendNameAndLocation; //ConvertToString(extendName);
10771077
auto fullExtendedName = TNS_PREFIX + fullClassName;
10781078
DEBUG_WRITE("ExtendsCallMethodHandler: extend full name %s", fullClassName.c_str());
10791079

@@ -1162,8 +1162,8 @@ bool MetadataNode::GetExtendLocation(string& extendLocation)
11621162
}
11631163

11641164
string srcFileName = ConvertToString(scriptName);
1165-
std::replace(srcFileName.begin(), srcFileName.end(), '/', '-');
1166-
std::replace(srcFileName.begin(), srcFileName.end(), '.', '-');
1165+
std::replace(srcFileName.begin(), srcFileName.end(), '/', '_');
1166+
std::replace(srcFileName.begin(), srcFileName.end(), '.', '_');
11671167
int lineNumber = frame->GetLineNumber();
11681168
if (lineNumber < 0)
11691169
{
@@ -1186,7 +1186,7 @@ bool MetadataNode::GetExtendLocation(string& extendLocation)
11861186
}
11871187

11881188

1189-
extendLocationStream << "f" << srcFileName.c_str() << "-l" << lineNumber << "-c" << column << "--";
1189+
extendLocationStream << "f" << srcFileName.c_str() << "_l" << lineNumber << "_c" << column << "__";
11901190
//DEBUG_WRITE("EXTEND_LOCATION %s", extendLocationStream.str().c_str());
11911191
}
11921192
}

src/jni/NativeScriptRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ jobject NativeScriptRuntime::CreateJavaInstance(int objectID, const std::string&
565565
int NativeScriptRuntime::GetCachedConstructorId(JEnv& env, const FunctionCallbackInfo<Value>& args, const string& name, const string& className, jobjectArray javaArgs, const Handle<Object>& implementationObject)
566566
{
567567
int ctorId = -1;
568-
string fullClassName = className + '-' + name;
568+
string fullClassName = className + Constants::CLASS_NAME_LOCATION_SEPARATOR + name;
569569
string encodedCtorArgs = MethodCache::EncodeSignature(fullClassName, "<init>", args, false);
570570
auto itFound = s_constructorCache.find(encodedCtorArgs);
571571

src/src/com/tns/DexFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
public class DexFactory
2828
{
2929
private static final String SECONDARY_DEX_FOLDER_NAME = "code_cache" + File.separator + "secondary-dexes";
30+
private static final char CLASS_NAME_LOCATION_SEPARATOR = '_';
3031

3132
private String dexPath;
3233
private String odexPath;
@@ -75,15 +76,15 @@ public Class<?> resolveClass(String name, String className, String[] methodOverr
7576
return NativeScriptActivity.class;
7677
}
7778

78-
String fullClassName = className.replace("$", "_") + "-" + name;
79+
String fullClassName = className.replace("$", "_") + CLASS_NAME_LOCATION_SEPARATOR + name;
7980
Class<?> existingClass = this.injectedDexClasses.get(fullClassName);
8081
if(existingClass != null)
8182
{
8283
return existingClass;
8384
}
8485

8586
String classToProxy = this.getClassToProxyName(className);
86-
String dexFilePath = classToProxy + "-" + name;
87+
String dexFilePath = classToProxy + CLASS_NAME_LOCATION_SEPARATOR + name;
8788
File dexFile = this.getDexFile(dexFilePath);
8889

8990
if (dexFile == null)
@@ -136,6 +137,7 @@ public Class<?> resolveClass(String name, String className, String[] methodOverr
136137
public Class<?> findClass(String className) throws ClassNotFoundException
137138
{
138139
String canonicalName = className.replace('/', '.');
140+
Log.d("TNS_NATIVE", canonicalName);
139141
Class<?> existingClass = this.injectedDexClasses.get(canonicalName);
140142
if(existingClass != null)
141143
{

test-app/assets/app/tests/tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ describe("Tests ", function () {
394394
var button1 = new MyButton();
395395
var button1Label = button1.toString();
396396

397-
expect(button1Label.indexOf("com.tns.tests.Button1-")).not.toEqual(-1);
397+
expect(button1Label.indexOf("com.tns.tests.Button1_")).not.toEqual(-1);
398398
expect(button1Label.indexOf("MyButton")).not.toEqual(-1);
399399
expect(button1Label.indexOf("success")).not.toEqual(-1);
400400

test-app/assets/app/tests/testsForTypescript.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ describe("Tests typescript", function () {
112112

113113
var button = new MyButton2();
114114
var button1Label = button.superToString();
115-
expect(button1Label.indexOf("com.tns.tests.Button1-")).not.toEqual(-1);
116-
expect(button1Label.indexOf("-MyButton2")).not.toEqual(-1);
115+
116+
expect(button1Label.indexOf("com.tns.tests.Button1_")).not.toEqual(-1);
117+
expect(button1Label.indexOf("_MyButton2")).not.toEqual(-1);
117118
});
118119

119120
it("When_creating_a_pure_typescript_inheritance_chain_it_should_work", function () {
@@ -289,8 +290,8 @@ describe("Tests typescript", function () {
289290

290291
var button = new MyButton5();
291292
var button1Label = button.toString();
292-
expect(button1Label.indexOf("com.tns.tests.Button1-")).not.toEqual(-1);
293-
expect(button1Label.indexOf("-MyButton5")).not.toEqual(-1);
293+
expect(button1Label.indexOf("com.tns.tests.Button1_")).not.toEqual(-1);
294+
expect(button1Label.indexOf("_MyButton5")).not.toEqual(-1);
294295
});
295296

296297
it("When_extending_an_already_extended_object_it_should_throw_an_error", function () {

0 commit comments

Comments
 (0)