diff --git a/toothpick-compiler/src/main/java/toothpick/compiler/registry/generators/RegistryGenerator.java b/toothpick-compiler/src/main/java/toothpick/compiler/registry/generators/RegistryGenerator.java index 892efb26..9f671a74 100644 --- a/toothpick-compiler/src/main/java/toothpick/compiler/registry/generators/RegistryGenerator.java +++ b/toothpick-compiler/src/main/java/toothpick/compiler/registry/generators/RegistryGenerator.java @@ -74,9 +74,7 @@ private void emitGetterMethods(TypeSpec.Builder registryTypeSpec) { .addParameter(ParameterizedTypeName.get(ClassName.get(Class.class), t), "clazz") .returns(ParameterizedTypeName.get(ClassName.get(registryInjectionTarget.type), t)); - //the ultimate part of the switch is about converting $ to . - //this is a bad hack, but the easiest workaroung to injectionTarget.getQualifiedName() using only . and not $ for FQN... - getMethod.addStatement("String className = clazz.getName().replace('$$','.')"); + getMethod.addStatement("String className = clazz.getName()"); int numOfBuckets = getNumberOfBuckets(registryInjectionTarget.injectionTargetList); getMethod.addStatement("int bucket = (className.hashCode() & $L)", numOfBuckets - 1); CodeBlock.Builder switchBlockBuilder = CodeBlock.builder().beginControlFlow("switch(bucket)"); @@ -115,7 +113,7 @@ private MethodSpec generateGetterMethod(List getterMethodBucket, in String typeSimpleName = registryInjectionTarget.type.getSimpleName(); for (TypeElement injectionTarget : getterMethodBucket) { - switchBlockBuilder.add("case ($S):" + LINE_SEPARATOR, injectionTarget.getQualifiedName().toString()); + switchBlockBuilder.add("case ($S):" + LINE_SEPARATOR, getGeneratedFQNClassName(injectionTarget)); switchBlockBuilder.addStatement("return ($L) new $L$$$$$L()", typeSimpleName, getGeneratedFQNClassName(injectionTarget), typeSimpleName); } @@ -131,7 +129,7 @@ private Map> getGetterMethodBuckets(List Map> getterMethodBuckets = new HashMap<>(); for (TypeElement injectionTarget : injectionTargetList) { - int index = injectionTarget.getQualifiedName().toString().hashCode() & (numOfBuckets - 1); + int index = getGeneratedFQNClassName(injectionTarget).hashCode() & (numOfBuckets - 1); List methodBucket = getterMethodBuckets.get(index); if (methodBucket == null) { methodBucket = new ArrayList<>(); diff --git a/toothpick-compiler/src/test/java/toothpick/compiler/factory/FactoryRegistryTest.java b/toothpick-compiler/src/test/java/toothpick/compiler/factory/FactoryRegistryTest.java index 09a5a9a5..dbcfe375 100644 --- a/toothpick-compiler/src/test/java/toothpick/compiler/factory/FactoryRegistryTest.java +++ b/toothpick-compiler/src/test/java/toothpick/compiler/factory/FactoryRegistryTest.java @@ -33,7 +33,7 @@ public class FactoryRegistryTest { " }", // "", // " public Factory getFactory(Class clazz) {", // - " String className = clazz.getName().replace('$','.');", // + " String className = clazz.getName();", // " int bucket = (className.hashCode() & 0);", // " switch(bucket) {", // " case (0):", // @@ -85,7 +85,7 @@ public class FactoryRegistryTest { " }", // "", // " public Factory getFactory(Class clazz) {", // - " String className = clazz.getName().replace('$','.');", // + " String className = clazz.getName();", // " int bucket = (className.hashCode() & 0);", // " switch(bucket) {", // " case (0):", // @@ -134,7 +134,7 @@ public class FactoryRegistryTest { " }", // "", // " public Factory getFactory(Class clazz) {", // - " String className = clazz.getName().replace('$','.');", // + " String className = clazz.getName();", // " int bucket = (className.hashCode() & -1);", // " switch(bucket) {", // " default:", // @@ -165,9 +165,9 @@ public class FactoryRegistryTest { " public static class InnerClass2 {", // " @Inject public InnerClass2() {", // " }", // - " }", // - " public static class InnerClass3 {", // - " @Inject public InnerClass3() {", // + " public static class InnerClass3 {", // + " @Inject public InnerClass3() {", // + " }", // " }", // " }", // "}" // @@ -185,7 +185,7 @@ public class FactoryRegistryTest { " }", // "", // " public Factory getFactory(Class clazz) {", // - " String className = clazz.getName().replace('$','.');", // + " String className = clazz.getName();", // " int bucket = (className.hashCode() & 3);", // " switch(bucket) {", // " case (0):", // @@ -203,6 +203,8 @@ public class FactoryRegistryTest { "", // " private Factory getFactoryBucket0(Class clazz, String className) {", // " switch(className) {", // + " case (\"test.TestARegistryWithMoreThanOneBucket$InnerClass2\"):", // + " return (Factory) new test.TestARegistryWithMoreThanOneBucket$InnerClass2$$Factory();", // " case (\"test.TestARegistryWithMoreThanOneBucket\"):", // " return (Factory) new test.TestARegistryWithMoreThanOneBucket$$Factory();", // " default:", // @@ -212,8 +214,8 @@ public class FactoryRegistryTest { "", // " private Factory getFactoryBucket1(Class clazz, String className) {", // " switch(className) {", // - " case (\"test.TestARegistryWithMoreThanOneBucket.InnerClass1\"):", // - " return (Factory) new test.TestARegistryWithMoreThanOneBucket$InnerClass1$$Factory();", // + " case (\"test.TestARegistryWithMoreThanOneBucket$InnerClass2$InnerClass3\"):", // + " return (Factory) new test.TestARegistryWithMoreThanOneBucket$InnerClass2$InnerClass3$$Factory();", // " default:", // " return getFactoryInChildrenRegistries(clazz);", // " }", // @@ -221,8 +223,6 @@ public class FactoryRegistryTest { "", // " private Factory getFactoryBucket2(Class clazz, String className) {", // " switch(className) {", // - " case (\"test.TestARegistryWithMoreThanOneBucket.InnerClass2\"):", // - " return (Factory) new test.TestARegistryWithMoreThanOneBucket$InnerClass2$$Factory();", // " default:", // " return getFactoryInChildrenRegistries(clazz);", // " }", // @@ -230,8 +230,8 @@ public class FactoryRegistryTest { "", // " private Factory getFactoryBucket3(Class clazz, String className) {", // " switch(className) {", // - " case (\"test.TestARegistryWithMoreThanOneBucket.InnerClass3\"):", // - " return (Factory) new test.TestARegistryWithMoreThanOneBucket$InnerClass3$$Factory();", // + " case (\"test.TestARegistryWithMoreThanOneBucket$InnerClass1\"):", // + " return (Factory) new test.TestARegistryWithMoreThanOneBucket$InnerClass1$$Factory();", // " default:", // " return getFactoryInChildrenRegistries(clazz);", // " }", // diff --git a/toothpick-compiler/src/test/java/toothpick/compiler/memberinjector/MemberInjectorRegistryTest.java b/toothpick-compiler/src/test/java/toothpick/compiler/memberinjector/MemberInjectorRegistryTest.java index 15823d3c..f5de5ff4 100644 --- a/toothpick-compiler/src/test/java/toothpick/compiler/memberinjector/MemberInjectorRegistryTest.java +++ b/toothpick-compiler/src/test/java/toothpick/compiler/memberinjector/MemberInjectorRegistryTest.java @@ -34,7 +34,7 @@ public void testASimpleRegistry() { " }", // "", // " public MemberInjector getMemberInjector(Class clazz) {", // - " String className = clazz.getName().replace('$','.');", // + " String className = clazz.getName();", // " int bucket = (className.hashCode() & 0);", // " switch(bucket) {", // " case (0):", // @@ -87,7 +87,7 @@ public void testARegistry_withDependencies() { " }", // "", // " public MemberInjector getMemberInjector(Class clazz) {", // - " String className = clazz.getName().replace('$','.');", // + " String className = clazz.getName();", // " int bucket = (className.hashCode() & 0);", // " switch(bucket) {", // " case (0):", // @@ -136,7 +136,7 @@ public void testARegistry_withDependencies() { " }", // "", // " public MemberInjector getMemberInjector(Class clazz) {", // - " String className = clazz.getName().replace('$','.');", // + " String className = clazz.getName();", // " int bucket = (className.hashCode() & -1);", // " switch(bucket) {", // " default:", // @@ -165,9 +165,9 @@ public void testARegistry_withDependencies() { " }", // " public static class InnerClass2 {", // " @Inject String s;", // - " }", // - " public static class InnerClass3 {", // - " @Inject String s;", // + " public static class InnerClass3 {", // + " @Inject String s;", // + " }", // " }", // "}" // )); @@ -184,7 +184,7 @@ public void testARegistry_withDependencies() { " }", // "", // " public MemberInjector getMemberInjector(Class clazz) {", // - " String className = clazz.getName().replace('$','.');", // + " String className = clazz.getName();", // " int bucket = (className.hashCode() & 3);", // " switch(bucket) {", // " case (0):", // @@ -204,6 +204,8 @@ public void testARegistry_withDependencies() { " switch(className) {", // " case (\"test.TestARegistryWithMoreThanOneBucket\"):", // " return (MemberInjector) new test.TestARegistryWithMoreThanOneBucket$$MemberInjector();", // + " case (\"test.TestARegistryWithMoreThanOneBucket$InnerClass2\"):", // + " return (MemberInjector) new test.TestARegistryWithMoreThanOneBucket$InnerClass2$$MemberInjector();", // " default:", // " return getMemberInjectorInChildrenRegistries(clazz);", // " }", // @@ -211,8 +213,8 @@ public void testARegistry_withDependencies() { "", // " private MemberInjector getMemberInjectorBucket1(Class clazz, String className) {", // " switch(className) {", // - " case (\"test.TestARegistryWithMoreThanOneBucket.InnerClass1\"):", // - " return (MemberInjector) new test.TestARegistryWithMoreThanOneBucket$InnerClass1$$MemberInjector();", // + " case (\"test.TestARegistryWithMoreThanOneBucket$InnerClass2$InnerClass3\"):", // + " return (MemberInjector) new test.TestARegistryWithMoreThanOneBucket$InnerClass2$InnerClass3$$MemberInjector();", // " default:", // " return getMemberInjectorInChildrenRegistries(clazz);", // " }", // @@ -220,8 +222,6 @@ public void testARegistry_withDependencies() { "", // " private MemberInjector getMemberInjectorBucket2(Class clazz, String className) {", // " switch(className) {", // - " case (\"test.TestARegistryWithMoreThanOneBucket.InnerClass2\"):", // - " return (MemberInjector) new test.TestARegistryWithMoreThanOneBucket$InnerClass2$$MemberInjector();", // " default:", // " return getMemberInjectorInChildrenRegistries(clazz);", // " }", // @@ -229,8 +229,8 @@ public void testARegistry_withDependencies() { "", // " private MemberInjector getMemberInjectorBucket3(Class clazz, String className) {", // " switch(className) {", // - " case (\"test.TestARegistryWithMoreThanOneBucket.InnerClass3\"):", // - " return (MemberInjector) new test.TestARegistryWithMoreThanOneBucket$InnerClass3$$MemberInjector();", // + " case (\"test.TestARegistryWithMoreThanOneBucket$InnerClass1\"):", // + " return (MemberInjector) new test.TestARegistryWithMoreThanOneBucket$InnerClass1$$MemberInjector();", // " default:", // " return getMemberInjectorInChildrenRegistries(clazz);", // " }", //