Skip to content

Commit

Permalink
Merge pull request #22 from Fueled/fix-compiler-package
Browse files Browse the repository at this point in the history
fix(compiler): fix package computation from different package fragment
  • Loading branch information
Hussein Aladeen authored May 25, 2017
2 parents 5b4c247 + 495b4d0 commit b93dc0c
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
2 changes: 1 addition & 1 deletion extra/gradle/libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {

//library
libraryGroup = 'com.github.fueled'
libraryVersion = '1.2.2'
libraryVersion = '1.2.3'

//android libraries
supportVersion = '25.1.1'
Expand Down
4 changes: 4 additions & 0 deletions flowr-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':flowr-annotations')
compile libraries.javaPoet
testCompile testLibraries.hamcrest
testCompile testLibraries.junit
testCompile testLibraries.mockito
}


sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void generateDeepLinkHandler(String handlerPackage, MethodSpec.Builder c
* @param fragmentPathList list of the fragment that support deep link.
* @return The best package to generate FlowrDeepLinkHandlerImpl in.
*/
private String generateCanonicalName(List<String> fragmentPathList) {
protected String generateCanonicalName(List<String> fragmentPathList) {
String packagePath;
if (fragmentPathList.size() > 1) {
int commonPrefixLength = 0;
Expand All @@ -301,6 +301,6 @@ private String generateCanonicalName(List<String> fragmentPathList) {
} else {
packagePath = fragmentPathList.get(0).replaceFirst("\\.([A-Za-z]+)$", "");
}
return packagePath;
return packagePath.replaceAll("\\.$", "");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.fueled.flowr.compilers;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;

/**
* Created by julienFueled on 5/25/17.
*/
public class DeepLinkAnnotationCompilerTest {

private static final String TEST_PACKAGE = "com.fueled.flowr.sample";

DeepLinkAnnotationCompiler compiler;

@Before
public void setup() {
compiler = new DeepLinkAnnotationCompiler();
}

@Test
public void process() throws Exception {

}

@Test
public void generateCanonicalNameOneFragmentTest() throws Exception {
List<String> fragmentList = new ArrayList<>();
fragmentList.add("com.fueled.flowr.sample.DemoFragment");
String handlerPackage = compiler.generateCanonicalName(fragmentList);
assertEquals(handlerPackage, TEST_PACKAGE);
}

@Test
public void generateCanonicalNameTwoFragmentSamePackageTest() throws Exception {
List<String> fragmentList = new ArrayList<>();
fragmentList.add(TEST_PACKAGE + ".DemoFragment");
fragmentList.add(TEST_PACKAGE + ".TestFragment");
String handlerPackage = compiler.generateCanonicalName(fragmentList);
assertEquals(handlerPackage, TEST_PACKAGE);
}

@Test
public void generateCanonicalNameTwoFragmentDifferentPackageTest() throws Exception {
List<String> fragmentList = new ArrayList<>();
fragmentList.add(TEST_PACKAGE + ".demo.DemoFragment");
fragmentList.add(TEST_PACKAGE + ".TestFragment");
String handlerPackage = compiler.generateCanonicalName(fragmentList);
assertEquals(handlerPackage, TEST_PACKAGE);
}

@Test
public void generateCanonicalNameTwoFragmentDifferentPackage2Test() throws Exception {
List<String> fragmentList = new ArrayList<>();
fragmentList.add(TEST_PACKAGE + ".demo.DemoFragment");
fragmentList.add(TEST_PACKAGE + ".test.TestFragment");
String handlerPackage = compiler.generateCanonicalName(fragmentList);
assertEquals(handlerPackage, TEST_PACKAGE);
}

}

0 comments on commit b93dc0c

Please sign in to comment.