Skip to content

Commit

Permalink
Use version 0.4.1 of javassist gradle plugin via morpheus update.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanenicolas committed Oct 4, 2014
1 parent c73bfd5 commit 349122a
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions injectview-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ dependencies {
compile 'com.github.stephanenicolas.afterburner:afterburner-library:1.0.2'

//only needed to create a plugin
compile ("com.github.stephanenicolas.morpheus:morpheus-plugin:1.0.7")
compile ("com.github.stephanenicolas.morpheus:morpheus-commons:1.0.7")
compile ("com.github.stephanenicolas.morpheus:morpheus-plugin:1.0.8-SNAPSHOT")
compile ("com.github.stephanenicolas.morpheus:morpheus-commons:1.0.8-SNAPSHOT")
compile gradleApi()
compile localGroovy()

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0513a6cc0c32f91a88a26fba6b7ba91e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5622de20ceb4850c3c1e0ba4749dcaac6cc762ae
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.android.support</groupId>
<artifactId>support-annotations</artifactId>
<version>19.1.0</version>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26d94fad9edf7c187b0d7c51a4e70bd9
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2c182b967e6ab32e27afcd4b1ba1aa1158e12c0b
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.stephanenicolas.afterburner.exception.AfterBurnerImpossibleException;
import com.github.stephanenicolas.morpheus.commons.CtClassFilter;
import com.github.stephanenicolas.morpheus.commons.JavassistUtils;
import com.github.stephanenicolas.morpheus.commons.NullableUtils;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -269,6 +270,7 @@ private String injectFragmentStatements(List<CtField> fragments, String root) th
String getFragmentString =
isUsingId ? ".findFragmentById(" + id + ")" : ".findFragmentByTag(\"" + tag + "\")";
buffer.append(root + "." + getFragmentManagerString + getFragmentString + ";\n");
buffer.append(checkNullable(field));
}
return buffer.toString();
}
Expand Down Expand Up @@ -322,6 +324,7 @@ private String injectViewStatements(List<CtField> viewsToInject, CtClass targetC
isUsingId ? "findViewById(" + id + ")" : "findViewWithTag(\"" + tag + "\")";
}
buffer.append(root + "." + findViewString + ";\n");
buffer.append(checkNullable(field));
}
log.debug("Inserted :" + buffer.toString());
return buffer.toString();
Expand Down Expand Up @@ -377,6 +380,7 @@ private String injectViewStatementsForParam(List<CtField> viewsToInject, CtClass
isUsingId ? "findViewById(" + id + ")" : "findViewWithTag(\"" + tag + "\")";
}
buffer.append(root + "." + findViewString + ";\n");
buffer.append(checkNullable(field));
}
log.debug("Inserted :" + buffer.toString());
return buffer.toString();
Expand Down Expand Up @@ -451,6 +455,26 @@ private String createInjectedBodyWithParam(CtClass clazz, CtClass[] paramClasses
return string;
}

private String checkNullable(CtField field) throws NotFoundException {
String checkNullable = "";
String fieldName = field.getName();
try {
log.debug("Using pool in Nullable " + System.identityHashCode(field.getType().getClassPool()));
log.debug("Using pool in Nullable " + field.getType().getClassPool().get("android.support.annotation.Nullable"));
} catch (NotFoundException e) {
e.printStackTrace();
}

if (NullableUtils.isNotNullable(field)) {
checkNullable = "if ("
+ fieldName
+ " == null) {\n throw new RuntimeException(\"Field "
+ fieldName
+ " is null and is not @Nullable.\"); \n}\n";
}
return checkNullable;
}

private static class InjectViewCtClassFilter implements CtClassFilter {
@Override public boolean isValid(CtClass clazz) throws NotFoundException {
return isActivity(clazz) || isView(clazz) || isFragment(clazz) || isSupportFragment(clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ public void shouldInjectView_whenUsingAtContentView_withTag_withoutOnCreate() {
assertThat((Integer) root.getTag(), is(CONTENT_VIEW_ID));
}

@Test
public void shouldInjectView_withInheritance() {
TestActivityInherited activity = Robolectric.buildActivity(TestActivityInherited.class)
.create()
.get();
assertNotNull(activity.text1);
assertThat(activity.text1.getId(), is(VIEW_ID));
}


public static class TestActivityWithId extends Activity {
Expand Down Expand Up @@ -224,4 +232,7 @@ public static class TestActivityWithContentViewAndTagWithoutOnCreate extends Act
setContentView(linearLayout);
}
}

public static class TestActivityInherited extends TestActivityWithId {
}
}

0 comments on commit 349122a

Please sign in to comment.