I'm trying to use Reflections library to get all classes annotated with a specific Java annotation.
I included Reflections library in .gradle file:
compile 'org.reflections:reflections:0.9.10'
However, the library does not work for me on Android. I'm not getting any hits from neither getSubTypesOf
nor getTypesAnnotatedWith
.
Is there anything wrong with my implementation?
package sample.anotherapp;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.scanners.TypeAnnotationsScanner;
import java.util.Set;
@Deprecated
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Reflections reflections = new Reflections("sample.anotherapp", new SubTypesScanner(false), new TypeAnnotationsScanner());
Set<Class<? extends AppCompatActivity>> subTypesOf = reflections. getSubTypesOf(AppCompatActivity.class);
int size = subTypesOf.size();
Set<Class<?>> annotated = reflections. getTypesAnnotatedWith(Deprecated.class);
size = annotated.size();
}
}
Aucun commentaire:
Enregistrer un commentaire