Skip to content

Commit aec8b64

Browse files
author
Hussein Aladeen
committed
feat(DeepLinkHandler): Add the ablity to specify custom names
1 parent 4996bfc commit aec8b64

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

flowr-annotations/src/main/java/com/fueled/flowr/annotations/DeepLinkHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,13 @@
1212
@Retention(RetentionPolicy.SOURCE)
1313
@Target(ElementType.TYPE)
1414
public @interface DeepLinkHandler {
15+
16+
/**
17+
* The name of the generated deep link handler class, by default this will be the name
18+
* of the class annotated with "Impl" appended at the end.
19+
*
20+
* @return the name to be used for the generated class.
21+
*/
22+
String value() default "";
23+
1524
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
6161
for (Element element : roundEnv.getElementsAnnotatedWith(DeepLinkHandler.class)) {
6262
String packageName = processingEnv.getElementUtils().getPackageOf(element)
6363
.getQualifiedName().toString();
64-
String className = element.getSimpleName().toString();
64+
65+
String className = element.getAnnotation(DeepLinkHandler.class).value();
66+
67+
if (className.isEmpty()) {
68+
className = element.getSimpleName().toString() + HANDLER_FILE_NAME_POST_FIX;
69+
}
6570

6671
generateDeepLinkHandler(packageName, className, constructorBuilder);
6772
}
@@ -72,12 +77,11 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
7277
/**
7378
* Create the JavaPoet Type builder for an AbstractFlowrDeepLinkHandler implementation class.
7479
*
75-
* @param className the name to be used for the implementation class appended
76-
* by {@link #HANDLER_FILE_NAME_POST_FIX}
80+
* @param className the name to be used for the implementation class.
7781
* @return The builder for the implementation class.
7882
*/
7983
private static TypeSpec.Builder getClassObject(String className) {
80-
return TypeSpec.classBuilder(className + HANDLER_FILE_NAME_POST_FIX)
84+
return TypeSpec.classBuilder(className)
8185
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
8286
.superclass(ClassName.get(FLOWR_INTERNAL_PACKAGE_NAME, ABSTRACT_HANDLER_CLASS_NAME));
8387
}
@@ -97,8 +101,7 @@ private static MethodSpec.Builder generateConstructor() {
97101
* class name and the constructor body.
98102
*
99103
* @param packageName the name of the package to use for the generated class.
100-
* @param className the name to be used for the implementation class appended
101-
* by {@link #HANDLER_FILE_NAME_POST_FIX}
104+
* @param className the name to be used for the implementation class.
102105
* @param constructorBuilder the constructor body builder for the class.
103106
*/
104107
private void generateDeepLinkHandler(String packageName, String className,

sample/src/main/java/com/fueled/flowr/sample/MainActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
import com.fueled.flowr.Flowr;
1515
import com.fueled.flowr.NavigationIconType;
1616
import com.fueled.flowr.ToolbarHandler;
17+
import com.fueled.flowr.annotations.DeepLinkHandler;
1718
import com.fueled.flowr.sample.core.AbstractActivity;
1819
import com.fueled.flowr.sample.core.AbstractFragment;
1920
import com.fueled.flowr.sample.core.FragmentResultPublisherImpl;
2021
import com.fueled.flowr.sample.databinding.ActivityMainBinding;
2122
import com.fueled.flowr.sample.library.LibraryDeepLinkHandlerImpl;
2223

24+
@DeepLinkHandler("MainDeepLinkHandlerImpl")
2325
public class MainActivity extends AbstractActivity implements ToolbarHandler, DrawerHandler {
2426

2527
private Flowr flowr;

sample/src/main/java/com/fueled/flowr/sample/MainDeepLinkHandler.java

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

0 commit comments

Comments
 (0)