Example usage for com.google.gwt.core.ext.typeinfo JEnumType getEnumConstants

List of usage examples for com.google.gwt.core.ext.typeinfo JEnumType getEnumConstants

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JEnumType getEnumConstants.

Prototype


JEnumConstant[] getEnumConstants();

Source Link

Document

Returns the enumeration constants declared by this enumeration.

Usage

From source file:com.didactilab.gwt.phprpc.rebind.phpgen.PhpEnum.java

License:Apache License

@Override
protected void getContents(TreeLogger logger, StringBuffer buffer) throws UnableToCompleteException {
    JEnumType type = getJavaType().isEnum();
    buffer.append("/**\n");
    buffer.append(" * @gwtname ").append(type.getQualifiedBinaryName()).append("\n");
    if (type.getEnclosingType() != null) {
        buffer.append(" * @enclosing ").append(type.getEnclosingType().getQualifiedBinaryName()).append("\n");
    }/*w w  w .ja va2s .  c om*/
    buffer.append(" */\n");
    buffer.append("class ").append(PhpTools.typeToString(type, true)).append(" extends Enum {\n");
    for (JEnumConstant constant : type.getEnumConstants()) {
        buffer.append("\tconst ").append(constant.getName()).append(" = ").append(constant.getOrdinal())
                .append(";\n");
    }
    buffer.append("}\n");
}

From source file:com.google.web.bindery.autobean.gwt.rebind.model.AutoBeanFactoryModel.java

License:Apache License

public AutoBeanFactoryModel(TreeLogger logger, JClassType factoryType) throws UnableToCompleteException {
    this.logger = logger;
    oracle = factoryType.getOracle();//from  w w  w.jav a2s .c  om
    autoBeanInterface = oracle.findType(AutoBean.class.getCanonicalName()).isGenericType();
    autoBeanFactoryInterface = oracle.findType(AutoBeanFactory.class.getCanonicalName()).isInterface();

    /*
     * We want to allow the user to override some of the useful Object methods,
     * so we'll extract them here.
     */
    JClassType objectType = oracle.getJavaLangObject();
    objectMethods = Arrays.asList(objectType.findMethod("equals", new JType[] { objectType }),
            objectType.findMethod("hashCode", EMPTY_JTYPE), objectType.findMethod("toString", EMPTY_JTYPE));

    // Process annotations
    {
        Category categoryAnnotation = factoryType.getAnnotation(Category.class);
        if (categoryAnnotation != null) {
            categoryTypes = new ArrayList<JClassType>(categoryAnnotation.value().length);
            processClassArrayAnnotation(categoryAnnotation.value(), categoryTypes);
        } else {
            categoryTypes = null;
        }

        noWrapTypes = new ArrayList<JClassType>();
        noWrapTypes.add(oracle.findType(AutoBean.class.getCanonicalName()));
        NoWrap noWrapAnnotation = factoryType.getAnnotation(NoWrap.class);
        if (noWrapAnnotation != null) {
            processClassArrayAnnotation(noWrapAnnotation.value(), noWrapTypes);
        }

        ExtraEnums extraEnumsAnnotation = factoryType.getAnnotation(ExtraEnums.class);
        if (extraEnumsAnnotation != null) {
            for (Class<?> clazz : extraEnumsAnnotation.value()) {
                JEnumType asEnum = oracle.findType(clazz.getCanonicalName()).isEnum();
                assert asEnum != null;
                for (JEnumConstant value : asEnum.getEnumConstants()) {
                    allEnumConstants.put(value, AutoBeanMethod.getEnumName(value));
                }
            }
        }
    }

    for (JMethod method : factoryType.getOverridableMethods()) {
        if (method.getEnclosingType().equals(autoBeanFactoryInterface)) {
            // Ignore methods in AutoBeanFactory
            continue;
        }

        JClassType returnType = method.getReturnType().isInterface();
        if (returnType == null) {
            poison("The return type of method %s is a primitive type", method.getName());
            continue;
        }

        // AutoBean<FooIntf> blah() --> beanType = FooIntf
        JClassType beanType = ModelUtils.findParameterizationOf(autoBeanInterface, returnType)[0];
        if (beanType.isInterface() == null) {
            poison("The %s parameterization is not an interface", beanType.getQualifiedSourceName());
            continue;
        }

        // AutoBean<FooIntf> blah(FooIntfSub foo) --> toWrap = FooIntfSub
        JClassType toWrap;
        if (method.getParameters().length == 0) {
            toWrap = null;
        } else if (method.getParameters().length == 1) {
            toWrap = method.getParameters()[0].getType().isClassOrInterface();
            if (!beanType.isAssignableFrom(toWrap)) {
                poison("The %s parameterization %s is not assignable from the delegate" + " type %s",
                        autoBeanInterface.getSimpleSourceName(), toWrap.getQualifiedSourceName());
                continue;
            }
        } else {
            poison("Unexpecetd parameters in method %s", method.getName());
            continue;
        }

        AutoBeanType autoBeanType = getAutoBeanType(beanType);

        // Must wrap things that aren't simple interfaces
        if (!autoBeanType.isSimpleBean() && toWrap == null) {
            if (categoryTypes != null) {
                poison("The %s parameterization is not simple and the following"
                        + " methods did not have static implementations:", beanType.getQualifiedSourceName());
                for (AutoBeanMethod missing : autoBeanType.getMethods()) {
                    if (missing.getAction().equals(JBeanMethod.CALL) && missing.getStaticImpl() == null) {
                        poison(missing.getMethod().getReadableDeclaration());
                    }
                }
            } else {
                poison("The %s parameterization is not simple, but the %s method"
                        + " does not provide a delegate", beanType.getQualifiedSourceName(), method.getName());
            }
            continue;
        }

        AutoBeanFactoryMethod.Builder builder = new AutoBeanFactoryMethod.Builder();
        builder.setAutoBeanType(autoBeanType);
        builder.setMethod(method);
        methods.add(builder.build());
    }

    while (!toCalculate.isEmpty()) {
        Set<JClassType> examine = toCalculate;
        toCalculate = new LinkedHashSet<JClassType>();
        for (JClassType beanType : examine) {
            getAutoBeanType(beanType);
        }
    }

    if (poisoned) {
        die("Unable to complete due to previous errors");
    }
}

From source file:fr.onevu.gwt.uibinder.attributeparsers.EnumAttributeParser.java

License:Apache License

EnumAttributeParser(FieldReferenceConverter converter, JEnumType enumType, MortalLogger logger) {
    super(converter, logger, enumType);
    JEnumConstant[] constants = enumType.getEnumConstants();
    for (JEnumConstant c : constants) {
        values.put(c.getName(), c);// ww  w  .  j a v  a  2s  . c om
    }
}

From source file:org.cruxframework.crux.core.rebind.rest.CruxRestProxyCreatorFromServerMetadata.java

License:Apache License

private boolean isEnumTypesCompatibles(Class<?> class1, JEnumType jType) {
    if (class1.isEnum()) {
        Object[] values1 = class1.getEnumConstants();
        JEnumConstant[] values2 = jType.getEnumConstants();
        if (values1.length != values2.length) {
            return false;
        }/*from  w  ww  . jav  a2s . co  m*/
        for (JEnumConstant jEnumConstant : values2) {
            String name = jEnumConstant.getName();
            boolean found = false;
            for (Object enumConstant : values1) {
                if (name.equals(enumConstant.toString())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                return false;
            }
        }
        return true;
    } else if (String.class.isAssignableFrom(class1)) {
        return true;
    }
    return false;
}