Skip to content

Commit 495b4d0

Browse files
author
julien|fueled
committed
fix(compiler): fix package computation from different package fragment
1 parent 5b4c247 commit 495b4d0

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

extra/gradle/libraries.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ext {
99

1010
//library
1111
libraryGroup = 'com.github.fueled'
12-
libraryVersion = '1.2.2'
12+
libraryVersion = '1.2.3'
1313

1414
//android libraries
1515
supportVersion = '25.1.1'

flowr-compiler/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ dependencies {
88
compile fileTree(dir: 'libs', include: ['*.jar'])
99
compile project(path: ':flowr-annotations')
1010
compile libraries.javaPoet
11+
testCompile testLibraries.hamcrest
12+
testCompile testLibraries.junit
13+
testCompile testLibraries.mockito
1114
}
1215

1316

1417
sourceCompatibility = JavaVersion.VERSION_1_7
1518
targetCompatibility = JavaVersion.VERSION_1_7
19+

flowr-compiler/src/main/java/com/fueled/flowr/compilers/DeepLinkAnnotationCompiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ private void generateDeepLinkHandler(String handlerPackage, MethodSpec.Builder c
290290
* @param fragmentPathList list of the fragment that support deep link.
291291
* @return The best package to generate FlowrDeepLinkHandlerImpl in.
292292
*/
293-
private String generateCanonicalName(List<String> fragmentPathList) {
293+
protected String generateCanonicalName(List<String> fragmentPathList) {
294294
String packagePath;
295295
if (fragmentPathList.size() > 1) {
296296
int commonPrefixLength = 0;
@@ -301,6 +301,6 @@ private String generateCanonicalName(List<String> fragmentPathList) {
301301
} else {
302302
packagePath = fragmentPathList.get(0).replaceFirst("\\.([A-Za-z]+)$", "");
303303
}
304-
return packagePath;
304+
return packagePath.replaceAll("\\.$", "");
305305
}
306306
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.fueled.flowr.compilers;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import static org.junit.Assert.assertEquals;
10+
11+
/**
12+
* Created by julienFueled on 5/25/17.
13+
*/
14+
public class DeepLinkAnnotationCompilerTest {
15+
16+
private static final String TEST_PACKAGE = "com.fueled.flowr.sample";
17+
18+
DeepLinkAnnotationCompiler compiler;
19+
20+
@Before
21+
public void setup() {
22+
compiler = new DeepLinkAnnotationCompiler();
23+
}
24+
25+
@Test
26+
public void process() throws Exception {
27+
28+
}
29+
30+
@Test
31+
public void generateCanonicalNameOneFragmentTest() throws Exception {
32+
List<String> fragmentList = new ArrayList<>();
33+
fragmentList.add("com.fueled.flowr.sample.DemoFragment");
34+
String handlerPackage = compiler.generateCanonicalName(fragmentList);
35+
assertEquals(handlerPackage, TEST_PACKAGE);
36+
}
37+
38+
@Test
39+
public void generateCanonicalNameTwoFragmentSamePackageTest() throws Exception {
40+
List<String> fragmentList = new ArrayList<>();
41+
fragmentList.add(TEST_PACKAGE + ".DemoFragment");
42+
fragmentList.add(TEST_PACKAGE + ".TestFragment");
43+
String handlerPackage = compiler.generateCanonicalName(fragmentList);
44+
assertEquals(handlerPackage, TEST_PACKAGE);
45+
}
46+
47+
@Test
48+
public void generateCanonicalNameTwoFragmentDifferentPackageTest() throws Exception {
49+
List<String> fragmentList = new ArrayList<>();
50+
fragmentList.add(TEST_PACKAGE + ".demo.DemoFragment");
51+
fragmentList.add(TEST_PACKAGE + ".TestFragment");
52+
String handlerPackage = compiler.generateCanonicalName(fragmentList);
53+
assertEquals(handlerPackage, TEST_PACKAGE);
54+
}
55+
56+
@Test
57+
public void generateCanonicalNameTwoFragmentDifferentPackage2Test() throws Exception {
58+
List<String> fragmentList = new ArrayList<>();
59+
fragmentList.add(TEST_PACKAGE + ".demo.DemoFragment");
60+
fragmentList.add(TEST_PACKAGE + ".test.TestFragment");
61+
String handlerPackage = compiler.generateCanonicalName(fragmentList);
62+
assertEquals(handlerPackage, TEST_PACKAGE);
63+
}
64+
65+
}

0 commit comments

Comments
 (0)