Beispiel #1
0
 // TODO: isFinal... maybe if the base class if final and all the parameter types are final?
 /**
  * Construct a ParameterizedTypeData during importing.
  */
 public ParameterizedTypeData(TypeData baseType, TypeData[] args = null)
     : this(baseType.getType().MakeGenericType(args.Select(arg => arg.getType()).ToArray()),
         baseType, args)
 {
 }
Beispiel #2
0
        public TypeData readType()
        {
            int typeId = readId();
            int nextTypeId = _types.Count;
            if (typeId < nextTypeId) {
            return _types[typeId];
            }

            // add the placeholder for this new type
            _types.Add(null);

            int flagsAndInfo = typeId - nextTypeId;
            // TODO: remove magic numbers
            string name;
            TypeData baseType;
            TypeData[] typeArgs;
            Type sysType;
            int typeKind = flagsAndInfo & 0x7;
            int flags = (flagsAndInfo >> 3) & 0x1;
            int args = (flagsAndInfo >> 4);

            TypeData type;
            switch (typeKind) {
            default:
            name = TypeMapper.convertTypeFromJava(readString());
            sysType = TypeUtil.getType(name);
            // TODO: different for unkown types? Right now IRTD handles both.
            if (sysType == null) {
                warn("Unknown type will be dropped: " + name);
            }
            bool isFinal = (flags & TypeDatas.IS_FINAL_FLAG) != 0;
            type = new ImportingReflectiveTypeData(sysType, isFinal);
            break;

            case 1:
            baseType = readType();
            // TODO: Assert that baseType is correct type
            GenericImportingBaseType giBase = (GenericImportingBaseType)baseType;
            args = giBase.args;
            typeArgs = new TypeData[args];
            for (int ii = 0; ii < args; ii++) {
                typeArgs[ii] = readType();
            }
            sysType = TypeUtil.getType(giBase.name + "`" + giBase.args)
                    .MakeGenericType(typeArgs.Select(t => t.getType()).ToArray());
            type = new GenericImportingReflectiveTypeData(sysType, baseType, typeArgs);
            break;

            case 3:
            name = TypeMapper.convertTypeFromJava(readString());
            type = new GenericImportingBaseType(name, args);
            break;

            case 2:
            baseType = readType();
            typeArgs = new TypeData[args];
            for (int ii = 0; ii < args; ii++) {
                typeArgs[ii] = readType();
            }
            //            this.logInfo("Read type",
            //                    "baseType", baseType.getType());
            type = new ParameterizedTypeData(baseType, typeArgs);
            break;

            case 4:
            name = TypeMapper.convertTypeFromJava(readString());
            sysType = TypeUtil.getType(name);
            if (sysType == null) {
                warn("Unknown enum type: " + name);
            } else if (!sysType.IsEnum) {
                warn("Type not enum: " + name);
                sysType = null;
            }
            type = new EnumTypeData(sysType);
            break;
            }

            // now that we've created the type, replace the placeholder slot
            _types[nextTypeId] = type;
            return type;
        }