getAll() {
53 | return componentLifeTreeSet;
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/stitch-core/src/main/java/bamboo/component/lifecycle/ComponentPriority.java:
--------------------------------------------------------------------------------
1 | package bamboo.component.lifecycle;
2 |
3 |
4 | public interface ComponentPriority {
5 |
6 | /**
7 | * 组件在初始化时的层级:顶层
8 | */
9 | int LEVEL_HIGH = 10;
10 |
11 | /**
12 | * 组件在初始化时的层级:中层
13 | */
14 | int LEVEL_MID = 100;
15 |
16 | /**
17 | * 组件在初始化时的层级:低层
18 | */
19 | int LEVEL_LOW = 1000;
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/stitch-core/src/main/java/bamboo/component/lifecycle/IComponentLifeCycle.java:
--------------------------------------------------------------------------------
1 | package bamboo.component.lifecycle;
2 |
3 | import android.app.Application;
4 | import android.content.ComponentCallbacks2;
5 | import android.content.Context;
6 | import android.content.res.Configuration;
7 |
8 | public interface IComponentLifeCycle extends ComponentCallbacks2 {
9 |
10 | /**
11 | * 表示组件的优先级,组件初始化时以该方法的返回值进行排序
12 | * 优先级越高的越先进行初始化,
13 | * 我们将优先级默认分为3级:HIGH、MID、LOW
14 | * 数字越大,优先级越低,如果在3级无法满足的情况下,可适当调整该值。
15 | *
16 | * 举例:
17 | *
18 | * 因为Push组件需要获取Account的信息,所以Push组件必须要在Account组件初始化之后才能初始化
19 | * 我们可以设置Account组件的层级为{@link ComponentPriority#LEVEL_MID}
20 | * 设置PUSH组件的层级为{@link ComponentPriority#LEVEL_LOW}.
21 | *
22 | * 而我们的路由组件是所有其他组件都需要依赖的组件,所以我们设置为{@link ComponentPriority#LEVEL_HIGH}
23 | *
24 | * @return {@link ComponentPriority#LEVEL_HIGH ,ComponentPriority#LEVEL_MID ,ComponentPriority#LEVEL_LOW}
25 | */
26 | int level();
27 |
28 | /**
29 | * 在Application的onCreate生命周期方法中会调用该方法实现组件的生命周期调用
30 | *
31 | * 调用顺序依赖于{@link #level()}的值
32 | */
33 | void onCreate();
34 |
35 | /**
36 | * 某些组件初始化并不需要在Application初始化时进行,我们可以对其进行延后处理,来提升App的启动速度
37 | *
38 | */
39 | void onCreateDelay();
40 |
41 | /**
42 | * 在Application的attachBaseContext生命周期方法中会调用该方法实现组件的生命周期调用
43 | *
44 | * @param baseContext
45 | */
46 | void attachBaseContext(Context baseContext);
47 |
48 | /**
49 | * 获取APP的Application对象
50 | *
51 | * @return
52 | */
53 | Application getApplication();
54 |
55 |
56 | void onTrimMemory(int level);
57 |
58 | void onLowMemory();
59 |
60 | void onConfigurationChanged(Configuration newConfig);
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/stitch-core/src/main/java/bamboo/component/page/ActivityPage.java:
--------------------------------------------------------------------------------
1 | package bamboo.component.page;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.Intent;
6 |
7 | import java.io.Serializable;
8 |
9 | import bamboo.component.StitcherHelper;
10 |
11 | /**
12 | * 每一个对其他module公开的Activity都需要有一个与之对应的ActivityPage
13 | *
14 | * ActivityPage 相当于是注册表中的注册信息,
15 | * 该注册信息包含了页面名称、上下文、以及在启动时的额外配置
16 | *
17 | * 同时为了节约类的数量,ActivityPage本身也是参数传递的可序列化Bean类
18 | * 在定义自己的ActivityPage时,我们采用实现类的类名(simplename)作为参数的key
19 | *
20 | * 不想进行序列化的字段需要用transient进行描述,同时你也可以使用Parcelable的方式
21 | * 如果自定义的ActivityPage实现了Parcelable接口,框架会使用Parcelable方式进行数据传递,
22 | * 所以在接收数据时,需要自己注意这一块.
23 | */
24 | public abstract class ActivityPage implements Serializable {
25 |
26 | public transient final Context context;
27 |
28 | private transient Intent targetIntent;
29 |
30 | private int requestCode = -1;
31 |
32 | public ActivityPage(Context context) {
33 | this.context = context;
34 | }
35 |
36 | public ActivityPage(Context context, Intent targetIntent) {
37 | this.context = context;
38 | this.targetIntent = targetIntent;
39 | }
40 |
41 | public Intent getTargetIntent() {
42 | return targetIntent;
43 | }
44 |
45 | public ActivityPage setTargetIntent(Intent targetIntent) {
46 | this.targetIntent = targetIntent;
47 | return this;
48 | }
49 |
50 | public ActivityPage setRequestCode(int requestCode) {
51 | this.requestCode = requestCode;
52 | return this;
53 | }
54 |
55 | public int getRequestCode() {
56 | return this.requestCode;
57 | }
58 |
59 | public Intent pack() {
60 | return StitcherHelper.pack(this);
61 | }
62 |
63 | public void start() {
64 | StitcherHelper.start(this);
65 | }
66 |
67 | public void startForResult() {
68 | StitcherHelper.startActivityForResult(this, this.getRequestCode());
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/stitch-core/src/main/java/bamboo/component/page/ActivityRegistry.java:
--------------------------------------------------------------------------------
1 | package bamboo.component.page;
2 |
3 |
4 | import java.lang.reflect.Method;
5 | import java.util.HashMap;
6 |
7 | import bamboo.component.Asserts;
8 |
9 |
10 | public final class ActivityRegistry {
11 |
12 | final HashMap autoLinkMap = new HashMap<>();
13 | final HashMap receiveMethodMap = new HashMap<>();
14 |
15 | public synchronized String register(String linkBean, String activityClass) {
16 | Asserts.assertNotNull(linkBean, "linkBean must not be null");
17 | Asserts.assertNotNull(activityClass, "activityClass must not be null");
18 | if (autoLinkMap.containsKey(linkBean)) {
19 | return autoLinkMap.get(linkBean);
20 | } else {
21 | autoLinkMap.put(linkBean, activityClass);
22 | return activityClass;
23 | }
24 | }
25 |
26 | public synchronized Method register(String linkBean, Method method) {
27 | Asserts.assertNotNull(linkBean, "linkBean must not be null");
28 | Asserts.assertNotNull(method, "method must not be null");
29 | if (receiveMethodMap.containsKey(linkBean)) {
30 | return receiveMethodMap.get(linkBean);
31 | } else {
32 | receiveMethodMap.put(linkBean, method);
33 | return method;
34 | }
35 | }
36 |
37 | public synchronized String search(String linkBean) {
38 | Asserts.assertNotNull(linkBean, "linkBean must not be null");
39 | if (autoLinkMap.containsKey(linkBean)) {
40 | return autoLinkMap.get(linkBean);
41 | }
42 | return null;
43 | }
44 |
45 | public synchronized Method searchMethod(String linkBean) {
46 | Asserts.assertNotNull(linkBean, "linkBean must not be null");
47 | if (receiveMethodMap.containsKey(linkBean)) {
48 | return receiveMethodMap.get(linkBean);
49 | }
50 | return null;
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/stitch-core/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DataRouter
3 |
4 |
--------------------------------------------------------------------------------
/stitch-core/src/test/java/bamboo/component/StitcherHelperTest.java:
--------------------------------------------------------------------------------
1 | package bamboo.component;
2 |
3 | import android.content.res.Configuration;
4 |
5 | import org.junit.Before;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.mockito.Mock;
9 | import org.mockito.junit.MockitoJUnitRunner;
10 |
11 | import bamboo.component.lifecycle.ComponentLife;
12 | import bamboo.component.lifecycle.ComponentLifeRegistry;
13 | import bamboo.component.lifecycle.ComponentPriority;
14 |
15 | import static org.mockito.ArgumentMatchers.any;
16 | import static org.mockito.Mockito.times;
17 | import static org.mockito.Mockito.verify;
18 | import static org.mockito.Mockito.when;
19 |
20 | /**
21 | * Created by tangshuai on 2018/3/17.
22 | */
23 | @RunWith(MockitoJUnitRunner.class)
24 | public class StitcherHelperTest {
25 | @Mock
26 | public ComponentLife aApplication;
27 |
28 | @Mock
29 | public ComponentLife bApplication;
30 |
31 | @Mock
32 | public Configuration configuration;
33 |
34 | ComponentLifeRegistry componentLifeRegistry = new ComponentLifeRegistry();
35 |
36 | @Before
37 | public void _start() {
38 | }
39 |
40 |
41 | @Test
42 | public void lifeCycleInvoke() {
43 | componentLifeRegistry.register("aApplication", aApplication);
44 | componentLifeRegistry.register("aApplication", aApplication);
45 | componentLifeRegistry.register("aApplication", aApplication);
46 | componentLifeRegistry.register("bApplication", bApplication);
47 | StitcherHelper.setComponentLifeRegistry(componentLifeRegistry);
48 |
49 | StitcherHelper.onCreate();
50 | verify(aApplication, times(1)).onCreate();
51 | verify(bApplication, times(1)).onCreate();
52 |
53 | StitcherHelper.onConfigurationChanged(configuration);
54 | verify(aApplication, times(1)).onConfigurationChanged(configuration);
55 | verify(bApplication, times(1)).onConfigurationChanged(configuration);
56 |
57 | StitcherHelper.onCreateDelay();
58 | verify(aApplication, times(1)).onCreateDelay();
59 | verify(bApplication, times(1)).onCreateDelay();
60 |
61 | StitcherHelper.onLowMemory();
62 | verify(aApplication, times(1)).onLowMemory();
63 | verify(bApplication, times(1)).onLowMemory();
64 |
65 | StitcherHelper.onTrimMemory(1);
66 | verify(aApplication, times(1)).onTrimMemory(1);
67 | verify(bApplication, times(1)).onTrimMemory(1);
68 | }
69 |
70 | }
--------------------------------------------------------------------------------
/stitch-core/src/test/java/bamboo/component/lifecycle/ComponentLifeRegistryTest.java:
--------------------------------------------------------------------------------
1 | package bamboo.component.lifecycle;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.mockito.Mockito;
6 | import org.mockito.junit.MockitoJUnitRunner;
7 |
8 | import java.util.ArrayList;
9 | import java.util.Collection;
10 | import java.util.Iterator;
11 | import java.util.List;
12 |
13 | import static org.hamcrest.core.Is.is;
14 | import static org.junit.Assert.*;
15 |
16 | /**
17 | * Created by tangshuai on 2018/3/17.
18 | */
19 | @RunWith(MockitoJUnitRunner.class)
20 | public class ComponentLifeRegistryTest {
21 |
22 | MockComponentALife aApplication = new MockComponentALife();
23 | MockComponentBLife bApplication = new MockComponentBLife();
24 |
25 | ComponentLifeRegistry componentLifeRegistry = new ComponentLifeRegistry();
26 |
27 | /**
28 | * 验证顺序,MockComponentAApplication的level优先于MockComponentAApplication的level
29 | */
30 | @Test
31 | public void aisbeforB() {
32 | componentLifeRegistry.register("aApplication", aApplication);
33 | componentLifeRegistry.register("aApplication", aApplication);
34 | componentLifeRegistry.register("aApplication", aApplication);
35 | componentLifeRegistry.register("bApplication", bApplication);
36 | componentLifeRegistry.register("bApplication", bApplication);
37 | componentLifeRegistry.register("bApplication", bApplication);
38 | Iterable applications = componentLifeRegistry.getAll();
39 | Iterator iterator = applications.iterator();
40 | assertTrue(iterator.hasNext());
41 | assertEquals(iterator.next(), aApplication);
42 | assertEquals(iterator.next(), bApplication);
43 | assertTrue(!iterator.hasNext());
44 | }
45 |
46 | @Test
47 | public void lifeCycleInvoke() {
48 | aApplication = Mockito.mock(MockComponentALife.class);
49 | bApplication = Mockito.mock(MockComponentBLife.class);
50 | componentLifeRegistry.register("aApplication", aApplication);
51 | componentLifeRegistry.register("bApplication", bApplication);
52 | }
53 | }
--------------------------------------------------------------------------------
/stitch-core/src/test/java/bamboo/component/lifecycle/MockComponentALife.java:
--------------------------------------------------------------------------------
1 | package bamboo.component.lifecycle;
2 |
3 | /**
4 | * Created by tangshuai on 2018/3/17.
5 | */
6 |
7 | public class MockComponentALife extends ComponentLife {
8 |
9 | @Override
10 | public int level() {
11 | return ComponentPriority.LEVEL_HIGH;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/stitch-core/src/test/java/bamboo/component/lifecycle/MockComponentBLife.java:
--------------------------------------------------------------------------------
1 | package bamboo.component.lifecycle;
2 |
3 | /**
4 | * Created by tangshuai on 2018/3/17.
5 | */
6 |
7 | public class MockComponentBLife extends ComponentLife {
8 |
9 | @Override
10 | public int level() {
11 | return ComponentPriority.LEVEL_LOW;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/stitch-core/src/test/java/bamboo/component/service/ServiceRegistryTest.java:
--------------------------------------------------------------------------------
1 | package bamboo.component.service;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by tangshuai on 2018/3/17.
9 | */
10 | public class ServiceRegistryTest {
11 |
12 |
13 | public static class ComponentOutputA {
14 |
15 | }
16 |
17 | public static class ComponentOutputB {
18 |
19 | }
20 |
21 | private ServiceRegistry serviceRegistry = new ServiceRegistry();
22 |
23 | @Test
24 | public void registerComponentOutput() {
25 |
26 | serviceRegistry.register(ComponentOutputA.class, ComponentOutputA.class.getName());
27 | serviceRegistry.register(ComponentOutputB.class, ComponentOutputB.class.getName());
28 | serviceRegistry.register(ComponentOutputB.class, ComponentOutputB.class.getName());
29 | assertEquals(serviceRegistry.serviceMap.size(), 2);
30 |
31 | ComponentOutputA componentOutputA1 = serviceRegistry.search(ComponentOutputA.class);
32 | ComponentOutputA componentOutputA2 = serviceRegistry.search(ComponentOutputA.class);
33 |
34 | ComponentOutputB componentOutputB1 = serviceRegistry.search(ComponentOutputB.class);
35 | ComponentOutputB componentOutputB2 = serviceRegistry.search(ComponentOutputB.class);
36 |
37 | assertEquals(componentOutputA1, componentOutputA2);
38 | assertEquals(componentOutputB1, componentOutputB2);
39 |
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/stitch-core/src/test/java/com/bamboo/component/datarouter/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.bamboo.component.datarouter;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/stitch-gradle-plugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/stitch-gradle-plugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-gradle-plugin'
2 | apply plugin: 'groovy'
3 |
4 | group = "bamboo.components.stitch"
5 | version = rootProject.ext.stitchVersion
6 | dependencies {
7 | compileOnly gradleApi()
8 | compile localGroovy()
9 | compileOnly 'com.android.tools.build:gradle:3.0.1'
10 | implementation fileTree(dir: 'libs', include: ['*.jar'])
11 | }
12 |
13 | sourceCompatibility = "1.7"
14 | targetCompatibility = "1.7"
15 |
16 |
17 | apply from: "${rootProject.rootDir}/gradle/native_maven.gradle"
18 | //apply from: "${rootProject.rootDir}/gradle/java_publish.gradle"
19 |
--------------------------------------------------------------------------------
/stitch-gradle-plugin/src/main/resources/META-INF/gradle-plugins/stitch.plugin.properties:
--------------------------------------------------------------------------------
1 | implementation-class=bamboo.component.StitchPlugin
--------------------------------------------------------------------------------
/stitch-router-anno/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/stitch-router-anno/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 | group = "bamboo.components.stitch"
4 | version = rootProject.ext.stitchVersion
5 | dependencies {
6 | implementation fileTree(dir: 'libs', include: ['*.jar'])
7 | sourceCompatibility = "1.7"
8 | targetCompatibility = "1.7"
9 | }
10 |
11 |
12 | apply from: "${rootProject.rootDir}/gradle/native_maven.gradle"
13 | //apply from: "${rootProject.rootDir}/gradle/java_publish.gradle"
--------------------------------------------------------------------------------
/stitch-router-anno/src/main/java/bamboo/stitch/router/anno/Alias.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by tangshuai on 2018/4/1.
10 | */
11 |
12 | @Retention(RetentionPolicy.CLASS)
13 | @Target(ElementType.METHOD)
14 | public @interface Alias {
15 |
16 | String value();
17 | }
18 |
--------------------------------------------------------------------------------
/stitch-router-anno/src/main/java/bamboo/stitch/router/anno/Parameter.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by tangshuai on 2018/4/1.
10 | */
11 | @Retention(RetentionPolicy.CLASS)
12 | @Target({ElementType.METHOD, ElementType.FIELD})
13 | public @interface Parameter {
14 |
15 | String value() default "";
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/stitch-router-anno/src/main/java/bamboo/stitch/router/anno/Wrapper.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.anno;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by tangshuai on 2018/3/30.
10 | */
11 |
12 | @Retention(RetentionPolicy.CLASS)
13 | @Target(ElementType.TYPE)
14 | public @interface Wrapper {
15 | }
16 |
--------------------------------------------------------------------------------
/stitch-router-compiler/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/stitch-router-compiler/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 |
3 |
4 | group = "bamboo.components.stitch"
5 | version = rootProject.ext.stitchVersion
6 | dependencies {
7 | implementation fileTree(include: ['*.jar'], dir: 'libs')
8 | compile 'com.google.auto.service:auto-service:1.0-rc4'
9 | compile project(":stitch-router-anno")
10 | sourceCompatibility = JavaVersion.VERSION_1_7
11 | targetCompatibility = JavaVersion.VERSION_1_7
12 | }
13 |
14 | apply from: "${rootProject.rootDir}/gradle/native_maven.gradle"
15 | //apply from: "${rootProject.rootDir}/gradle/java_publish.gradle"
16 |
--------------------------------------------------------------------------------
/stitch-router-compiler/src/main/java/bamboo/stitch/router/compiler/ActivityDelegate.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.compiler;
2 |
3 | /**
4 | * Created by tangshuai on 2018/4/1.
5 | */
6 |
7 | public class ActivityDelegate {
8 |
9 | public static final String CLASS = "" +
10 | " public static class ActivityPageDelegate {\n" +
11 | " \n" +
12 | " T activityPage;\n" +
13 | " \n" +
14 | " public ActivityPageDelegate(T activityPage) {\n" +
15 | " this.activityPage = activityPage;\n" +
16 | " }\n" +
17 | " \n" +
18 | " public T getActivityPage() {\n" +
19 | " return activityPage;\n" +
20 | " }\n" +
21 | " \n" +
22 | " public ActivityPageDelegate setTargetIntent(Intent intent) {\n" +
23 | " activityPage.setTargetIntent(intent);\n" +
24 | " return this;\n" +
25 | " }\n" +
26 | " \n" +
27 | " public ActivityPageDelegate setRequestCode(int requestCode) {\n" +
28 | " activityPage.setRequestCode(requestCode);\n" +
29 | " return this;\n" +
30 | " }\n" +
31 | " \n" +
32 | " public Intent pack() {\n" +
33 | " return StitcherHelper.pack(activityPage);\n" +
34 | " }\n" +
35 | " \n" +
36 | " public void start() {\n" +
37 | " StitcherHelper.start(activityPage);\n" +
38 | " }\n" +
39 | " \n" +
40 | " public void startForResult() {\n" +
41 | " StitcherHelper.startActivityForResult(activityPage, activityPage.getRequestCode());\n" +
42 | " }\n" +
43 | " \n" +
44 | " }\n";
45 |
46 | public static String getActivityDelegateClassCode(String packageName) {
47 | return String.format(CLASS, packageName);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/stitch-router-compiler/src/main/java/bamboo/stitch/router/compiler/ActivityPageBinding.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.compiler;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | /**
9 | * Created by tangshuai on 2018/3/30.
10 | */
11 |
12 | public class ActivityPageBinding {
13 |
14 | String activityPageName;
15 |
16 | String activityPageClass;
17 |
18 | Map imports = new HashMap<>();
19 |
20 | List parameters = new ArrayList<>();
21 |
22 | List constructors = new ArrayList<>();
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/stitch-router-compiler/src/main/java/bamboo/stitch/router/compiler/ConstructorBinding.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.compiler;
2 |
3 | /**
4 | * Created by tangshuai on 2018/4/1.
5 | */
6 |
7 | public class ConstructorBinding {
8 |
9 | String className;
10 |
11 | String[] parametersType;
12 |
13 | String[] parametersName;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/stitch-router-compiler/src/main/java/bamboo/stitch/router/compiler/Name.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.compiler;
2 |
3 | /**
4 | * Created by tangshuai on 2018/3/21.
5 | */
6 |
7 | public class Name {
8 |
9 | public static String toUpperStart(String str) {
10 | if (str == null || "".equals(str.trim())) {
11 | return "";
12 | }
13 | String c = str.charAt(0) + "";
14 | return c.toUpperCase() + str.substring(1);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/stitch-router-compiler/src/main/java/bamboo/stitch/router/compiler/ParameterBinding.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.compiler;
2 |
3 | /**
4 | * Created by tangshuai on 2018/4/1.
5 | */
6 |
7 | public class ParameterBinding {
8 |
9 | //字段名称
10 | String name;
11 |
12 | //字段对应的method的参数
13 | String[] paramerTypes;
14 |
15 | String[] paramerNames;
16 |
17 | //字段对应的方法名称
18 | String methodName;
19 |
20 | //字段注入类型,0=field,1=method;
21 | int type = 0;
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/stitch-router-compiler/src/main/java/bamboo/stitch/router/compiler/ParameterChecks.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.compiler;
2 |
3 | import java.lang.annotation.ElementType;
4 |
5 | import javax.lang.model.element.Element;
6 | import javax.lang.model.element.Modifier;
7 | import javax.lang.model.element.TypeElement;
8 | import javax.lang.model.element.VariableElement;
9 |
10 | /**
11 | * Created by tangshuai on 2018/4/1.
12 | */
13 |
14 | public class ParameterChecks {
15 |
16 |
17 | static void checkModifier(Element element, Modifier modifier) {
18 | if (!element.getModifiers().contains(modifier)) {
19 | StringBuilder sb = new StringBuilder("@Wrapper error : ");
20 | sb.append(element.getSimpleName());
21 | sb.append(" must be ");
22 | sb.append(modifier.name());
23 | sb.append(";");
24 | throw new IllegalStateException(sb.toString());
25 | }
26 | }
27 |
28 | static void checkNoneModifier(Element element, Modifier modifier) {
29 | if (element.getModifiers().contains(modifier)) {
30 | StringBuilder sb = new StringBuilder("@Parameter error : ");
31 | sb.append(element.getSimpleName());
32 | sb.append(" can not be ");
33 | sb.append(modifier.name());
34 | sb.append(";");
35 | throw new IllegalStateException(sb.toString());
36 | }
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/stitch-router-compiler/src/main/java/bamboo/stitch/router/compiler/ServiceMethodBinding.java:
--------------------------------------------------------------------------------
1 | package bamboo.stitch.router.compiler;
2 |
3 | /**
4 | * Created by tangshuai on 2018/3/30.
5 | */
6 |
7 | public class ServiceMethodBinding {
8 |
9 | String serviceInterfaceClass;
10 | String defaultValue = "null";
11 | String methodName;
12 | String aliasName;
13 | String[] parametersType;
14 | String[] parametersName;
15 | String returnType;
16 | }
17 |
--------------------------------------------------------------------------------