Package com.kenai.constantine

Examples of com.kenai.constantine.Constant


                // define EAGAIN now, so that future EWOULDBLOCK will alias to it
                // see MRI's error.c and its explicit ordering of Errno definitions.
                createSysErr(Errno.EAGAIN.value(), Errno.EAGAIN.name());
               
                for (Errno e : Errno.values()) {
                    Constant c = (Constant) e;
                    if (Character.isUpperCase(c.name().charAt(0))) {
                        createSysErr(c.value(), c.name());
                    }
                }
            } catch (Exception e) {
                // dump the trace and continue
                // this is currently only here for Android, which seems to have
View Full Code Here


        constantGeneration++;
    }

    public <E extends Enum<E>> void loadConstantSet(RubyModule module, Class<E> enumClass) {
        for (E e : EnumSet.allOf(enumClass)) {
            Constant c = (Constant) e;
            if (Character.isUpperCase(c.name().charAt(0))) {
                module.fastSetConstant(c.name(), newFixnum(c.value()));
            }
        }
    }
View Full Code Here

        public String toString() {
            return name;
        }
    }
    private Constant getConstant(E e) {
        Constant c;
        if (cacheGuard != 0 && (c = cache[e.ordinal()]) != null) { // read volatile guard
            return c;
        }
        // fallthru to slow lookup+add
        return lookupAndCacheConstant(e);
View Full Code Here

        return lookupAndCacheConstant(e);
    }

    private Constant lookupAndCacheConstant(E e) {
        synchronized (modLock) {
            Constant c;
            // Recheck, in case another thread loaded the table
            if (cacheGuard != 0 && (c = cache[e.ordinal()]) != null) {
                return c;
            }
            EnumSet<E> enums = EnumSet.allOf(enumType);
            ConstantSet cset = getConstants();
            if (cache == null) {
                cache = new Constant[enums.size()];
            }
            long known = 0, unknown = 0;
            for (Enum v : enums) {
                c = cset.getConstant(v.name());
                if (c == null) {
                    if (bitmask) {
                        // Flag the value as unknown - real values will be
                        // inserted once all values are resolved, so there are
                        // no collisions
                        unknown |= (1L << v.ordinal());
                        c = new UnknownConstant(0, v.name());
                    } else {
                        c = new UnknownConstant(nextUnknown.getAndAdd(1), v.name());
                    }
                } else if (bitmask) {
                    known |= c.value();
                }
                cache[v.ordinal()] = c;
            }
            //
            // For bitmask constant sets, we generate bitmask values for missing
View Full Code Here

        }
        e = reverseLookupMap.get(value);
        if (e != null) {
            return e;
        }
        Constant c = getConstants().getConstant(value);
        if (c != null) {
            try {
                e = Enum.valueOf(enumType, c.name());
                reverseLookupMap.put(value, e);
                if (c.value() >= 0 && c.value() < 256) {
                    E[] values = valueCache;
                    if (values == null) {
                        values = (E[]) Array.newInstance(enumType, 256);
                    }
                    values[c.value()] = e;
                    valueCache = values;
                }
                return e;
            } catch (IllegalArgumentException ex) {}
        }
View Full Code Here

        ConstantSet lastErrors = ConstantSet.getConstantSet("LastError");

        // Fill the gaps by searching through every possible constantine Errno first
        // checking if it's defined on Windows, then falling back to the WSA prefixed
        // version if it exists
        Constant constant;
        for (Constant errno : Errno.values()) {
            String errnoName = errno.name();
            if ((constant = winErrnos.getConstant(errnoName)) != null
                || (constant = lastErrors.getConstant("WSA" + errnoName)) != null) {
                addCode(dict, errnoName, constant.value(), constant.toString());
            }
        }
        // Then provide the WSA names
        for (Constant lastError : lastErrors) {
            if (lastError.name().startsWith("WSA")) {
View Full Code Here

    public static PyString __doc__strerror = new PyString(
        "strerror(code) -> string\n\n" +
        "Translate an error code to a message string.");
    public static PyObject strerror(int code) {
        Constant errno = Errno.valueOf(code);
        if (errno == Errno.__UNKNOWN_CONSTANT__) {
            return new PyString("Unknown error: " + code);
        }
        if (errno.name() == errno.toString()) {
            // Fake constant or just lacks a description, fallback to Linux's
            // XXX: have constantine handle this fallback
            errno = Enum.valueOf(com.kenai.constantine.platform.linux.Errno.class,
                                 errno.name());
        }
        return new PyString(errno.toString());
    }
View Full Code Here

TOP

Related Classes of com.kenai.constantine.Constant

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.