org.osgl.util.Generics Java Examples

The following examples show how to use org.osgl.util.Generics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 6 votes vote down vote up
private List<S.Pair> propertyListOf(Class<?> c, Set<Class<?>> circularReferenceDetector, Map<String, Class> typeImplLookup) {
    if (null == typeImplLookup) {
        typeImplLookup = Generics.buildTypeParamImplLookup(c);
    } else {
        typeImplLookup.putAll(Generics.buildTypeParamImplLookup(c));
    }
    if (circularReferenceDetector.contains(c)) {
        return C.list();
    }
    circularReferenceDetector.add(c);
    try {
        return buildPropertyList(c, circularReferenceDetector, typeImplLookup);
    } finally {
        circularReferenceDetector.remove(c);
    }
}
 
Example #2
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 6 votes vote down vote up
private void buildPropertyPath(String context, Method m, Class<?> c, List<S.Pair> repo, Set<Class<?>> circularReferenceDetector, Map<String, Class> typeImplLookup) {
    if (Modifier.isStatic(m.getModifiers())) {
        return;
    }
    if (m.getParameterTypes().length > 0) {
        return;
    }
    String name = m.getName();
    if ("getClass".equals(name)) {
        return;
    }
    String propName = "";
    if (name.startsWith("get")) {
        propName = getPropName(name);
    } else if (name.startsWith("is")) {
        propName = isPropName(name);
    }
    if (S.isEmpty(propName)) {
        return;
    }
    Class returnType = Generics.getReturnType(m, c);
    Label label = m.getAnnotation(Label.class);
    String labelString = null == label ? null : label.value();
    buildPropertyPath(returnType, m.getGenericReturnType(), labelString, context, propName, repo, circularReferenceDetector, typeImplLookup);
}
 
Example #3
Source File: DaoBase.java    From actframework with Apache License 2.0 6 votes vote down vote up
private void exploreTypes() {
    List<Type> types = Generics.typeParamImplementations(getClass(), DaoBase.class);
    int sz = types.size();
    if (sz < 1) {
        return;
    }
    if (sz > 2) {
        queryType = types.get(2);
        queryClass = Generics.classOf(queryType);
    }
    if (sz > 1) {
        modelType = types.get(1);
        modelClass = Generics.classOf(modelType);
    }
    idType = types.get(0);
    idClass = Generics.classOf(idType);
}
 
Example #4
Source File: GH43.java    From java-di with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    Genie genie = Genie.create();
    Method method = $.getMethod(Foo.class, "doIt", List.class);
    Map<String, Class> typeVarLookup = Generics.buildTypeParamImplLookup(IntFoo.class);
    Type type = method.getGenericParameterTypes()[0];
    Annotation[] anno = method.getParameterAnnotations()[0];
    BeanSpec spec = BeanSpec.of(type, anno, genie, typeVarLookup);
}
 
Example #5
Source File: Gh197.java    From java-tool with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    Map<String, Class> lookup = Generics.buildTypeParamImplLookup(Me.class);
    eq(String.class, lookup.get("K"));
    eq(Integer.class, lookup.get("V"));
    eq(Req.class, lookup.get("RQ"));
    eq(String.class, lookup.get("RQ.V"));
}
 
Example #6
Source File: DaoBase.java    From java-tool with Apache License 2.0 5 votes vote down vote up
private void exploreTypes() {
    List<Type> types = Generics.typeParamImplementations(getClass(), DaoBase.class);
    int sz = types.size();
    if (sz < 1) {
        return;
    }
    if (sz > 1) {
        modelType = types.get(1);
        modelClass = Generics.classOf(modelType);
    }
    idType = types.get(0);
    idClass = Generics.classOf(idType);
}
 
Example #7
Source File: Gh196.java    From java-tool with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    Map<String, Class> lookup = Generics.buildTypeParamImplLookup(Me.class);
    eq(String.class, lookup.get("K"));
    eq(Integer.class, lookup.get("V"));
    eq(TreeMap.class, lookup.get("M"));
}
 
Example #8
Source File: SimpleTypeArrayActionParameterBindingTestBase.java    From actframework with Apache License 2.0 5 votes vote down vote up
public SimpleTypeArrayActionParameterBindingTestBase() {
    this.pathWrap = wrapperArrayPath();
    this.pathList = listPath();
    this.pathSet = setPath();
    this.targetType = (Class<T>) Generics.typeParamImplementations(getClass(), SimpleTypeArrayActionParameterBindingTestBase.class).get(0);
    this.isNumber = Number.class.isAssignableFrom(this.targetType);
}
 
Example #9
Source File: ActProvider.java    From actframework with Apache License 2.0 5 votes vote down vote up
private Class<T> exploreTypeInfo() {
    List<Type> types = Generics.typeParamImplementations(getClass(), ActProvider.class);
    int sz = types.size();
    E.illegalStateIf(1 != sz, "generic type number not match");
    Type type = types.get(0);
    E.illegalArgumentIf(!(type instanceof Class), "generic type is not a class: %s", type);
    return (Class) type;
}
 
Example #10
Source File: ModelBase.java    From actframework with Apache License 2.0 5 votes vote down vote up
private void exploreTypes() {
    List<Type> types = Generics.typeParamImplementations(getClass(), ModelBase.class);
    int sz = types.size();
    if (sz < 1) {
        return;
    }
    if (sz > 1) {
        modelType = types.get(1);
    }
    idType = types.get(0);
}
 
Example #11
Source File: SampleDataProvider.java    From actframework with Apache License 2.0 5 votes vote down vote up
private void exploreType() {
    List<Type> types = Generics.typeParamImplementations(getClass(), SampleDataProvider.class);
    if (types.size() != 1) {
        warnTargetTypeNotDetermined();
    } else {
        Type type = types.get(0);
        if (! (type instanceof Class)) {
            warnTargetTypeNotDetermined();
        } else {
            targetType = (Class<T>) type;
        }
    }
}
 
Example #12
Source File: SimpleRestfulServiceBase.java    From actframework with Apache License 2.0 5 votes vote down vote up
private void exploreTypes() {
    Map<String, Class> typeParamLookup = Generics.buildTypeParamImplLookup(getClass());
    List<Type> types = Generics.typeParamImplementations(getClass(), SimpleRestfulServiceBase.class);
    int sz = types.size();
    if (sz < 3) {
        throw new IllegalArgumentException("Cannot determine DAO type");
    }
    Type daoType = types.get(2);
    BeanSpec spec = BeanSpec.of(daoType, Act.injector(), typeParamLookup);
    DaoLoader loader = Act.getInstance(DaoLoader.class);
    dao = $.cast(loader.load(spec));
}
 
Example #13
Source File: DaoBase.java    From java-di with Apache License 2.0 5 votes vote down vote up
private void exploreTypes() {
    List<Type> types = Generics.typeParamImplementations(getClass(), DaoBase.class);
    int sz = types.size();
    if (sz < 1) {
        return;
    }
    if (sz > 1) {
        modelType = types.get(1);
        modelClass = Generics.classOf(modelType);
    }
    idType = types.get(0);
    idClass = Generics.classOf(idType);
}
 
Example #14
Source File: DaoBase.java    From actframework with Apache License 2.0 4 votes vote down vote up
public DaoBase(Class<ID_TYPE> idType, Class<MODEL_TYPE> modelType) {
    this.idType = $.requireNotNull(idType);
    this.idClass = Generics.classOf(idType);
    this.modelType = $.requireNotNull(modelType);
    this.modelClass = Generics.classOf(modelType);
}
 
Example #15
Source File: ModelBase.java    From actframework with Apache License 2.0 4 votes vote down vote up
protected Class<MODEL_TYPE> modelType() {
    return Generics.classOf(modelType);
}
 
Example #16
Source File: ModelBase.java    From actframework with Apache License 2.0 4 votes vote down vote up
protected Class<ID_TYPE> idType() {
    return Generics.classOf(idType);
}
 
Example #17
Source File: ClassMetaInfoManager.java    From actframework with Apache License 2.0 4 votes vote down vote up
private void exploreTypes() {
    List<Type> types = Generics.typeParamImplementations(getClass(), ClassMetaInfoManager.class);
    infoType = Generics.classOf(types.get(0));
}