Search in sources :

Example 1 with ErlRecordDef

use of org.erlide.engine.internal.model.erlang.ErlRecordDef in project erlide_eclipse by erlang.

the class ErlParser method addRecordDef.

private IErlRecordDef addRecordDef(final IErlModule module, final OtpErlangObject pos, final OtpErlangObject val, final OtpErlangObject extra) {
    if (val instanceof OtpErlangTuple) {
        final OtpErlangTuple recordTuple = (OtpErlangTuple) val;
        if (recordTuple.elementAt(0) instanceof OtpErlangAtom) {
            final String s = extra instanceof OtpErlangString ? ((OtpErlangString) extra).stringValue() : null;
            final OtpErlangList fields = (OtpErlangList) recordTuple.elementAt(1);
            final ErlRecordDef r = new ErlRecordDef(module, null, s);
            setPos(r, pos);
            if (fields != null) {
                final List<ErlRecordField> children = Lists.newArrayListWithCapacity(fields.arity());
                for (final OtpErlangObject o : fields) {
                    if (o instanceof OtpErlangTuple) {
                        final OtpErlangTuple fieldTuple = (OtpErlangTuple) o;
                        final OtpErlangAtom fieldNameAtom = (OtpErlangAtom) fieldTuple.elementAt(0);
                        final String fieldName = fieldNameAtom.atomValue();
                        final ErlRecordField field = new ErlRecordField(r, fieldName);
                        final OtpErlangTuple posTuple = (OtpErlangTuple) fieldTuple.elementAt(1);
                        if (fieldTuple.arity() > 2) {
                            final OtpErlangObject fieldExtra = fieldTuple.elementAt(2);
                            field.setExtra(Util.stringValue(fieldExtra));
                        }
                        setPos(field, posTuple);
                        children.add(field);
                    } else {
                        ErlLogger.error("bad record def: %s", o);
                    }
                }
                r.setChildren(children);
            } else {
                r.setChildren(new ArrayList<>());
            }
            return r;
        }
    }
    if (val instanceof OtpErlangAtom) {
        final String s = extra instanceof OtpErlangString ? ((OtpErlangString) extra).stringValue() : null;
        final ErlRecordDef r = new ErlRecordDef(module, null, s);
        setPos(r, pos);
        return r;
    }
    return null;
}
Also used : OtpErlangList(com.ericsson.otp.erlang.OtpErlangList) ErlRecordField(org.erlide.engine.internal.model.erlang.ErlRecordField) OtpErlangObject(com.ericsson.otp.erlang.OtpErlangObject) OtpErlangTuple(com.ericsson.otp.erlang.OtpErlangTuple) OtpErlangAtom(com.ericsson.otp.erlang.OtpErlangAtom) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString) ErlRecordDef(org.erlide.engine.internal.model.erlang.ErlRecordDef) IErlRecordDef(org.erlide.engine.model.erlang.IErlRecordDef) OtpErlangString(com.ericsson.otp.erlang.OtpErlangString)

Aggregations

OtpErlangAtom (com.ericsson.otp.erlang.OtpErlangAtom)1 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)1 ErlRecordDef (org.erlide.engine.internal.model.erlang.ErlRecordDef)1 ErlRecordField (org.erlide.engine.internal.model.erlang.ErlRecordField)1 IErlRecordDef (org.erlide.engine.model.erlang.IErlRecordDef)1