Skip to content

Commit

Permalink
Make use of Nullable annotation instead of rolling own optional annot…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
emilsjolander committed Jun 29, 2015
1 parent 6d8a551 commit eaea76b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
Expand Down Expand Up @@ -162,7 +163,7 @@ private TypeSpec getBuilderSpec(Element annotatedElement) {
private void getAnnotatedFields(Element annotatedElement, List<Element> required, List<Element> optional) {
for (Element e : annotatedElement.getEnclosedElements()) {
if (e.getAnnotation(Extra.class) != null) {
if (e.getAnnotation(se.emilsjolander.intentbuilder.Optional.class) != null) {
if (hasAnnotation(e, "Nullable")) {
optional.add(e);
} else {
required.add(e);
Expand All @@ -178,4 +179,13 @@ private void getAnnotatedFields(Element annotatedElement, List<Element> required
}
}

private boolean hasAnnotation(Element e, String name) {
for (AnnotationMirror annotation : e.getAnnotationMirrors()) {
if (annotation.getAnnotationType().asElement().getSimpleName().toString().equals(name)) {
return true;
}
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package se.emilsjolander.intentbuilder.sample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import se.emilsjolander.intentbuilder.Extra;
import se.emilsjolander.intentbuilder.IntentBuilder;
import se.emilsjolander.intentbuilder.Optional;

@IntentBuilder
public class DetailActivity extends AppCompatActivity {
Expand All @@ -17,10 +17,10 @@ public class DetailActivity extends AppCompatActivity {
@Extra
String two;

@Extra @Optional
@Extra @Nullable
String three;

@Extra @Optional
@Extra @Nullable
String four;

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package se.emilsjolander.intentbuilder.sample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
import android.support.annotation.Nullable;

import se.emilsjolander.intentbuilder.Extra;
import se.emilsjolander.intentbuilder.IntentBuilder;
import se.emilsjolander.intentbuilder.Optional;

@IntentBuilder
public class MySubClass extends MySuperClass {

@Extra @Optional
@Extra @Nullable
String three;

@Extra @Optional
@Extra @Nullable
String four;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import se.emilsjolander.intentbuilder.Extra;
import se.emilsjolander.intentbuilder.IntentBuilder;
import se.emilsjolander.intentbuilder.Optional;

public class MySuperClass extends AppCompatActivity {

Expand Down

0 comments on commit eaea76b

Please sign in to comment.