Search in sources :

Example 1 with JDirectClass

use of com.helger.jcodemodel.JDirectClass in project androidannotations by androidannotations.

the class RInnerClass method extractIdStaticRef.

public static JFieldRef extractIdStaticRef(AndroidAnnotationsEnvironment environment, String layoutFieldQualifiedName) {
    if (layoutFieldQualifiedName != null) {
        int fieldSuffix = layoutFieldQualifiedName.lastIndexOf('.');
        String fieldName = layoutFieldQualifiedName.substring(fieldSuffix + 1);
        String rInnerClassName = layoutFieldQualifiedName.substring(0, fieldSuffix);
        int innerClassSuffix = rInnerClassName.lastIndexOf('.');
        String rClassQualifiedName = rInnerClassName.substring(0, innerClassSuffix);
        String innerClassSimpleName = rInnerClassName.substring(innerClassSuffix + 1);
        JDirectClass rClass = (JDirectClass) environment.getJClass(rClassQualifiedName);
        AbstractJClass innerClass = null;
        for (JDirectClass clazz : rClass.classes()) {
            if (clazz.name().equals(innerClassSimpleName)) {
                innerClass = clazz;
                break;
            }
        }
        if (innerClass == null) {
            try {
                innerClass = rClass._class(innerClassSimpleName);
            } catch (JClassAlreadyExistsException e) {
            // never happens, since we already checked the inner class does not exist
            }
        }
        return innerClass.staticRef(fieldName);
    } else {
        return null;
    }
}
Also used : JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) JDirectClass(com.helger.jcodemodel.JDirectClass) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Aggregations

AbstractJClass (com.helger.jcodemodel.AbstractJClass)1 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)1 JDirectClass (com.helger.jcodemodel.JDirectClass)1