Java 类io.realm.annotations.RealmClass 实例源码

项目:Ruqus    文件:RuqusProcessor.java   
@Override
public Set<String> getSupportedAnnotationTypes() {
    Set<String> types = new LinkedHashSet<>();

    // Our annotations.
    types.add(Queryable.class.getCanonicalName());
    types.add(Hide.class.getCanonicalName());
    types.add(VisibleAs.class.getCanonicalName());
    types.add(Transformer.class.getCanonicalName());
    // Realm annotations.
    types.add(RealmClass.class.getCanonicalName());
    types.add(Ignore.class.getCanonicalName());

    return types;
}
项目:Ruqus    文件:ClassDataBuilder.java   
/**
 * Process all classes which are annotated with {@link RealmClass} and get information needed to generate the class
 * data and various field data files.
 */
void buildClassAndFieldData(RoundEnvironment roundEnv) {
    for (Element element : roundEnv.getElementsAnnotatedWith(RealmClass.class)) {
        if (!SuperficialValidation.validateElement(element)) continue;
        if (element.getKind() != ElementKind.CLASS) {
            // Really this shouldn't be an issue since Realm's annotation processor will do real checks, but still.
            error(element, "@RealmClass annotations can only be applied to classes!");
            continue;
        }
        TypeElement typeElement = MoreElements.asType(element);
        if (!isValidRealmClass(typeElement)) continue;

        // Get ClassName object, we'll store this so that we can write out a real type later.
        ClassName className = ClassName.get(typeElement);
        // Get real class name.
        String realName = className.simpleName();
        // Check that the real name of the class isn't already in use.
        if (realClassNames.contains(realName)) {
            error(element, "Failed while processing \"%s\" because there is already a realm object class called " +
                            "\"%s\"; Ruqus currently cannot handle multiple classes with the same name.",
                    className.toString(), realName);
            continue;
        }
        // Check class for queryable and visible name annotations to try and figure out visible name.
        String visibleName = null;
        boolean isQueryable = false;
        if (MoreElements.isAnnotationPresent(typeElement, Queryable.class)) {
            Queryable qAnnot = typeElement.getAnnotation(Queryable.class);
            visibleName = qAnnot.name();
            isQueryable = true;
        }
        if ((visibleName == null || visibleName.isEmpty()) &&
                MoreElements.isAnnotationPresent(typeElement, VisibleAs.class)) {
            VisibleAs vaAnnot = typeElement.getAnnotation(VisibleAs.class);
            visibleName = vaAnnot.string();
        }
        if (visibleName == null || visibleName.isEmpty()) {
            // Generate a name from TitleCase.
            visibleName = Utils.makeVisName(realName);
        }
        // Check that visible name hasn't already been used.
        if (visibleNames.values().contains(visibleName)) {
            error(element, "Failed while processing \"%s\" because there is already a realm object class which " +
                    "has the visible name \"%s\"; Ruqus currently cannot handle having multiple classes with the " +
                    "same visible name.", className.toString(), visibleName);
            continue;
        }

        // Get field information for all fields in this class.
        FieldDataBuilder fdBuilder = new FieldDataBuilder(realName);
        processFields(typeElement, fdBuilder);

        // Store these locally until we write out the whole class data file.
        realClassNames.add(realName);
        if (isQueryable) queryable.add(realName);
        classMap.put(realName, className);
        visibleNames.put(realName, visibleName);
        fieldData.put(realName, fdBuilder);
    }
}