Android Open Source - kvs-schema Env Parser






From Project

Back to project page kvs-schema.

License

The source code is released under:

MIT License

If you think the Android project kvs-schema listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rejasupotaro.android.kvs.internal;
/*www. j  ava2s  . co m*/
import com.rejasupotaro.android.kvs.internal.exceptions.TableNameDuplicateException;
import com.rejasupotaro.android.kvs.internal.exceptions.TableNameIsNotDefinedException;
import com.rejaupotaro.android.kvs.annotations.Table;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;

public final class EnvParser {
    public static List<SchemaModel> parse(RoundEnvironment env, Elements elementUtils) {
        ArrayList<SchemaModel> models = new ArrayList<>();
        ArrayList<Element> elements = new ArrayList<>(env.getElementsAnnotatedWith(Table.class));
        for (Element element : elements) {
            SchemaModel model = new SchemaModel((TypeElement) element, elementUtils);
            models.add(model);
        }
        validateSchemaModel(models);
        return models;
    }

    public static void validateSchemaModel(List<SchemaModel> models) {
        List<String> tableNames = new ArrayList<>();
        for (SchemaModel model : models) {
            String tableName = model.getTableName();

            if (tableName == null || tableName.equals("")) {
                String originalClassName = model.getOriginalClassName();
                throw new TableNameIsNotDefinedException(originalClassName + " should define table name");
            }

            if (tableNames.contains(tableName)) {
                throw new TableNameDuplicateException("table name \"" + tableName + "\" is already defined");
            }

            tableNames.add(tableName);
        }
    }
}




Java Source Code List

com.example.android.kvs.ApplicationTest.java
com.example.android.kvs.ExamplePrefsSchema.java
com.example.android.kvs.MainActivity.java
com.rejasupotaro.android.kvs.ApplicationTest.java
com.rejasupotaro.android.kvs.PrefSchema.java
com.rejasupotaro.android.kvs.Schema.java
com.rejasupotaro.android.kvs.internal.Classes.java
com.rejasupotaro.android.kvs.internal.EnvParser.java
com.rejasupotaro.android.kvs.internal.SchemaModel.java
com.rejasupotaro.android.kvs.internal.SchemaProcessor.java
com.rejasupotaro.android.kvs.internal.SchemaWriter.java
com.rejasupotaro.android.kvs.internal.StringUtils.java
com.rejasupotaro.android.kvs.internal.exceptions.TableNameDuplicateException.java
com.rejasupotaro.android.kvs.internal.exceptions.TableNameIsInvalidException.java
com.rejasupotaro.android.kvs.internal.exceptions.TableNameIsNotDefinedException.java
com.rejaupotaro.android.kvs.annotations.Key.java
com.rejaupotaro.android.kvs.annotations.Table.java