Code review comment: Are we going to clean these stuffs up?

Code before review:
public BType readType() throws IOException {
byte tag = inputStream.readByte();
switch (tag) {
case TypeTags.INT:
return symTable.intType;
case TypeTags.BYTE:
return symTable.byteType;
case TypeTags.FLOAT:
return symTable.floatType;
case TypeTags.DECIMAL:
return symTable.decimalType;
case TypeTags.STRING:
return symTable.stringType;
case TypeTags.BOOLEAN:
return symTable.booleanType;
case TypeTags.JSON:
return symTable.jsonType;
case TypeTags.XML:
return symTable.xmlType;
case TypeTags.TABLE:
BTableType bTableType = new BTableType(TypeTags.TABLE, null, symTable.tableType.tsymbol);
bTableType.constraint = readType();
return bTableType;
case TypeTags.NIL:
return symTable.nilType;
case TypeTags.ANYDATA:
return symTable.anydataType;
case TypeTags.RECORD:
String name = getUTF8CPEntryValue(inputStream);
BRecordTypeSymbol recordSymbol = Symbols.createRecordSymbol(Flags.asMask(EnumSet.of(Flag.PUBLIC)),
names.fromString(name), env.pkgSymbol.pkgID, null, env.pkgSymbol);
recordSymbol.scope = new Scope(recordSymbol);
BRecordType recordType = new BRecordType(recordSymbol);
recordSymbol.type = recordType;
compositeStack.push(recordType);
recordType.sealed = inputStream.readBoolean();
recordType.restFieldType = readType();
int recordFields = inputStream.readInt();
for (int i = 0; i < recordFields; i++) {
String fieldName = getUTF8CPEntryValue(inputStream);
BType fieldType = readType();
BVarSymbol varSymbol = new BVarSymbol(0, names.fromString(fieldName),
recordSymbol.pkgID, fieldType, recordSymbol.scope.owner);
recordSymbol.scope.define(varSymbol.name, varSymbol);
}
getUTF8CPEntryValue(inputStream);
inputStream.readByte();
readType();
Object poppedRecordType = compositeStack.pop();
assert poppedRecordType == recordType;
return recordType;
case TypeTags.TYPEDESC:
return symTable.typeDesc;
case TypeTags.STREAM:
BStreamType bStreamType = new BStreamType(TypeTags.STREAM, null, symTable.streamType.tsymbol);
bStreamType.constraint = readType();
return bStreamType;
case TypeTags.MAP:
BMapType bMapType = new BMapType(TypeTags.MAP, null, symTable.mapType.tsymbol);
bMapType.constraint = readType();
return bMapType;
case TypeTags.INVOKABLE:
BTypeSymbol tsymbol = Symbols.createTypeSymbol(SymTag.FUNCTION_TYPE,
Flags.asMask(EnumSet.of(Flag.PUBLIC)), Names.EMPTY, env.pkgSymbol.pkgID, null,
env.pkgSymbol.owner);
BInvokableType bInvokableType = new BInvokableType(null, null, tsymbol);
int paramCount = inputStream.readInt();
List<BType> paramTypes = new ArrayList<>();
for (int i = 0; i < paramCount; i++) {
paramTypes.add(readType());
}
BType retType = readType();
bInvokableType.paramTypes = paramTypes;
bInvokableType.retType = retType;
return bInvokableType;
case TypeTags.ANY:
return symTable.anyType;
case TypeTags.ENDPOINT:
break;
case TypeTags.ARRAY:
byte state = inputStream.readByte();
int size = inputStream.readInt();
BTypeSymbol arrayTypeSymbol = Symbols.createTypeSymbol(SymTag.ARRAY_TYPE, Flags.asMask(EnumSet
.of(Flag.PUBLIC)), Names.EMPTY, env.pkgSymbol.pkgID, null, env.pkgSymbol.owner);
BArrayType bArrayType = new BArrayType(null, arrayTypeSymbol, size, BArrayState.valueOf(state));
bArrayType.eType = readType();
return bArrayType;
case TypeTags.UNION:
BTypeSymbol unionTypeSymbol = Symbols.createTypeSymbol(SymTag.UNION_TYPE, Flags.asMask(EnumSet
.of(Flag.PUBLIC)), Names.EMPTY, env.pkgSymbol.pkgID, null, env.pkgSymbol.owner);
BUnionType unionType = BUnionType.create(unionTypeSymbol,
new LinkedHashSet<>());
int unionMemberCount = inputStream.readInt();
for (int i = 0; i < unionMemberCount; i++) {
unionType.add(readType());
}
return unionType;
case TypeTags.PACKAGE:
break;
case TypeTags.NONE:
return symTable.noType;
case TypeTags.VOID:
break;
case TypeTags.XMLNS:
break;
case TypeTags.ANNOTATION:
break;
case TypeTags.SEMANTIC_ERROR:
break;
case TypeTags.ERROR:
BTypeSymbol errorSymbol = new BErrorTypeSymbol(SymTag.ERROR, Flags.PUBLIC, Names.EMPTY,
env.pkgSymbol.pkgID, null, env.pkgSymbol.owner);
BErrorType errorType = new BErrorType(errorSymbol);
compositeStack.push(errorType);
BType reasonType = readType();
BType detailsType = readType();
errorType.reasonType = reasonType;
errorType.detailType = detailsType;
errorSymbol.type = errorType;
Object poppedErrorType = compositeStack.pop();
assert poppedErrorType == errorType;
return errorType;
case TypeTags.ITERATOR:
break;
case TypeTags.TUPLE:
BTypeSymbol tupleTypeSymbol = Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, Flags.asMask(EnumSet
.of(Flag.PUBLIC)), Names.EMPTY, env.pkgSymbol.pkgID, null, env.pkgSymbol.owner);
BTupleType bTupleType = new BTupleType(tupleTypeSymbol, null);
int tupleMemberCount = inputStream.readInt();
List<BType> tupleMemberTypes = new ArrayList<>();
for (int i = 0; i < tupleMemberCount; i++) {
tupleMemberTypes.add(readType());
}
bTupleType.tupleTypes = tupleMemberTypes;
return bTupleType;
case TypeTags.FUTURE:
BFutureType bFutureType = new BFutureType(TypeTags.FUTURE, null, symTable.futureType.tsymbol);
bFutureType.constraint = readType();
return bFutureType;
case TypeTags.INTERMEDIATE_COLLECTION:
break;
case TypeTags.FINITE:
BTypeSymbol symbol = Symbols.createTypeSymbol(SymTag.FINITE_TYPE, 0, Names.EMPTY,
env.pkgSymbol.pkgID, null, env.pkgSymbol);
symbol.scope = new Scope(symbol);
BFiniteType finiteType = new BFiniteType(symbol);
symbol.type = finiteType;
int valueSpaceSize = inputStream.readInt();
for (int i = 0; i < valueSpaceSize; i++) {
defineValueSpace(inputStream, finiteType);
}
return finiteType;
case TypeTags.OBJECT:
boolean service = inputStream.readByte() == 1;
String objName = getUTF8CPEntryValue(inputStream);
int objFlags = (inputStream.readBoolean() ? Flags.ABSTRACT : 0) | Flags.PUBLIC;
BObjectTypeSymbol objectSymbol = (BObjectTypeSymbol) Symbols.createObjectSymbol(objFlags,
names.fromString(objName), env.pkgSymbol.pkgID, null, env.pkgSymbol);
objectSymbol.scope = new Scope(objectSymbol);
objectSymbol.methodScope = new Scope(objectSymbol);
BObjectType objectType;
if (service) {
objectType = new BServiceType(objectSymbol);
} else {
objectType = new BObjectType(objectSymbol);
}
objectSymbol.type = objectType;
compositeStack.push(objectType);
int fieldCount = inputStream.readInt();
for (int i = 0; i < fieldCount; i++) {
String fieldName = getUTF8CPEntryValue(inputStream);
int fieldFlags = 0;
fieldFlags = visibilityAsMask(fieldFlags, inputStream.readByte());
BType fieldType = readType();
BVarSymbol objectVarSymbol = new BVarSymbol(fieldFlags, names.fromString(fieldName),
objectSymbol.pkgID, fieldType, objectSymbol.scope.owner);
objectSymbol.scope.define(objectVarSymbol.name, objectVarSymbol);
}
int funcCount = inputStream.readInt();
for (int i = 0; i < funcCount; i++) {
String funcName = getUTF8CPEntryValue(inputStream);
int funcFlags = 0;
funcFlags = visibilityAsMask(funcFlags, inputStream.readByte());
BInvokableType funcType = (BInvokableType) readType();
BInvokableSymbol invokableSymbol = Symbols.createFunctionSymbol(funcFlags,
names.fromString(funcName), env.pkgSymbol.pkgID, funcType,
env.pkgSymbol, Symbols.isFlagOn(objFlags, Flags.NATIVE));
invokableSymbol.retType = funcType.retType;
BAttachedFunction attachedFunc =
new BAttachedFunction(names.fromString(funcName), invokableSymbol, funcType);
objectSymbol.attachedFuncs.add(attachedFunc);
if (Names.OBJECT_INIT_SUFFIX.value.equals(funcName)
|| funcName.equals(Names.INIT_FUNCTION_SUFFIX.value)) {
objectSymbol.initializerFunc = attachedFunc;
}
}
Object poppedObjType = compositeStack.pop();
assert poppedObjType == objectType;
return objectType;
case TypeTags.BYTE_ARRAY:
break;
case TypeTags.FUNCTION_POINTER:
break;
case TYPE_TAG_SELF:
int index = inputStream.readInt();
return (BType) compositeStack.get(index);
case SERVICE_TYPE_TAG:
return symTable.anyServiceType;
}
return null;
}


Code after addressing the review:
public BType readType() throws IOException {
byte tag = inputStream.readByte();
switch (tag) {
case TypeTags.INT:
return symTable.intType;
case TypeTags.BYTE:
return symTable.byteType;
case TypeTags.FLOAT:
return symTable.floatType;
case TypeTags.DECIMAL:
return symTable.decimalType;
case TypeTags.STRING:
return symTable.stringType;
case TypeTags.BOOLEAN:
return symTable.booleanType;
case TypeTags.JSON:
return symTable.jsonType;
case TypeTags.XML:
return symTable.xmlType;
case TypeTags.TABLE:
BTableType bTableType = new BTableType(TypeTags.TABLE, null, symTable.tableType.tsymbol);
bTableType.constraint = readType();
return bTableType;
case TypeTags.NIL:
return symTable.nilType;
case TypeTags.ANYDATA:
return symTable.anydataType;
case TypeTags.RECORD:
String name = getUTF8CPEntryValue(inputStream);
BRecordTypeSymbol recordSymbol = Symbols.createRecordSymbol(Flags.asMask(EnumSet.of(Flag.PUBLIC)),
names.fromString(name), env.pkgSymbol.pkgID, null, env.pkgSymbol);
recordSymbol.scope = new Scope(recordSymbol);
BRecordType recordType = new BRecordType(recordSymbol);
recordSymbol.type = recordType;
compositeStack.push(recordType);
recordType.sealed = inputStream.readBoolean();
recordType.restFieldType = readType();
int recordFields = inputStream.readInt();
for (int i = 0; i < recordFields; i++) {
String fieldName = getUTF8CPEntryValue(inputStream);
BType fieldType = readType();
BVarSymbol varSymbol = new BVarSymbol(0, names.fromString(fieldName),
recordSymbol.pkgID, fieldType, recordSymbol.scope.owner);
recordSymbol.scope.define(varSymbol.name, varSymbol);
}
getUTF8CPEntryValue(inputStream);
inputStream.readByte();
readType();
Object poppedRecordType = compositeStack.pop();
assert poppedRecordType == recordType;
return recordType;
case TypeTags.TYPEDESC:
return symTable.typeDesc;
case TypeTags.STREAM:
BStreamType bStreamType = new BStreamType(TypeTags.STREAM, null, symTable.streamType.tsymbol);
bStreamType.constraint = readType();
return bStreamType;
case TypeTags.MAP:
BMapType bMapType = new BMapType(TypeTags.MAP, null, symTable.mapType.tsymbol);
bMapType.constraint = readType();
return bMapType;
case TypeTags.INVOKABLE:
BTypeSymbol tsymbol = Symbols.createTypeSymbol(SymTag.FUNCTION_TYPE,
Flags.asMask(EnumSet.of(Flag.PUBLIC)), Names.EMPTY, env.pkgSymbol.pkgID, null,
env.pkgSymbol.owner);
BInvokableType bInvokableType = new BInvokableType(null, null, tsymbol);
int paramCount = inputStream.readInt();
List<BType> paramTypes = new ArrayList<>();
for (int i = 0; i < paramCount; i++) {
paramTypes.add(readType());
}
BType retType = readType();
bInvokableType.paramTypes = paramTypes;
bInvokableType.retType = retType;
return bInvokableType;
case TypeTags.ANY:
return symTable.anyType;
case TypeTags.ENDPOINT:
break;
case TypeTags.ARRAY:
byte state = inputStream.readByte();
int size = inputStream.readInt();
BTypeSymbol arrayTypeSymbol = Symbols.createTypeSymbol(SymTag.ARRAY_TYPE, Flags.asMask(EnumSet
.of(Flag.PUBLIC)), Names.EMPTY, env.pkgSymbol.pkgID, null, env.pkgSymbol.owner);
BArrayType bArrayType = new BArrayType(null, arrayTypeSymbol, size, BArrayState.valueOf(state));
bArrayType.eType = readType();
return bArrayType;
case TypeTags.UNION:
BTypeSymbol unionTypeSymbol = Symbols.createTypeSymbol(SymTag.UNION_TYPE, Flags.asMask(EnumSet
.of(Flag.PUBLIC)), Names.EMPTY, env.pkgSymbol.pkgID, null, env.pkgSymbol.owner);
BUnionType unionType = BUnionType.create(unionTypeSymbol,
new LinkedHashSet<>());
int unionMemberCount = inputStream.readInt();
for (int i = 0; i < unionMemberCount; i++) {
unionType.add(readType());
}
return unionType;
case TypeTags.PACKAGE:
break;
case TypeTags.NONE:
return symTable.noType;
case TypeTags.VOID:
break;
case TypeTags.XMLNS:
break;
case TypeTags.ANNOTATION:
break;
case TypeTags.SEMANTIC_ERROR:
break;
case TypeTags.ERROR:
BTypeSymbol errorSymbol = new BErrorTypeSymbol(SymTag.ERROR, Flags.PUBLIC, Names.EMPTY,
env.pkgSymbol.pkgID, null, env.pkgSymbol.owner);
BErrorType errorType = new BErrorType(errorSymbol);
compositeStack.push(errorType);
BType reasonType = readType();
BType detailsType = readType();
errorType.reasonType = reasonType;
errorType.detailType = detailsType;
errorSymbol.type = errorType;
Object poppedErrorType = compositeStack.pop();
assert poppedErrorType == errorType;
return errorType;
case TypeTags.ITERATOR:
break;
case TypeTags.TUPLE:
BTypeSymbol tupleTypeSymbol = Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, Flags.asMask(EnumSet
.of(Flag.PUBLIC)), Names.EMPTY, env.pkgSymbol.pkgID, null, env.pkgSymbol.owner);
BTupleType bTupleType = new BTupleType(tupleTypeSymbol, null);
int tupleMemberCount = inputStream.readInt();
List<BType> tupleMemberTypes = new ArrayList<>();
for (int i = 0; i < tupleMemberCount; i++) {
tupleMemberTypes.add(readType());
}
bTupleType.tupleTypes = tupleMemberTypes;
return bTupleType;
case TypeTags.FUTURE:
BFutureType bFutureType = new BFutureType(TypeTags.FUTURE, null, symTable.futureType.tsymbol);
bFutureType.constraint = readType();
return bFutureType;
case TypeTags.INTERMEDIATE_COLLECTION:
break;
case TypeTags.FINITE:
BTypeSymbol symbol = Symbols.createTypeSymbol(SymTag.FINITE_TYPE, 0, Names.EMPTY,
env.pkgSymbol.pkgID, null, env.pkgSymbol);
symbol.scope = new Scope(symbol);
BFiniteType finiteType = new BFiniteType(symbol);
symbol.type = finiteType;
int valueSpaceSize = inputStream.readInt();
for (int i = 0; i < valueSpaceSize; i++) {
defineValueSpace(inputStream, finiteType);
}
return finiteType;
case TypeTags.OBJECT:
boolean service = inputStream.readByte() == 1;
String objName = getUTF8CPEntryValue(inputStream);
int objFlags = (inputStream.readBoolean() ? Flags.ABSTRACT : 0) | Flags.PUBLIC;
BObjectTypeSymbol objectSymbol = (BObjectTypeSymbol) Symbols.createObjectSymbol(objFlags,
names.fromString(objName), env.pkgSymbol.pkgID, null, env.pkgSymbol);
objectSymbol.scope = new Scope(objectSymbol);
objectSymbol.methodScope = new Scope(objectSymbol);
BObjectType objectType;
if (service) {
objectType = new BServiceType(objectSymbol);
} else {
objectType = new BObjectType(objectSymbol);
}
objectSymbol.type = objectType;
compositeStack.push(objectType);
int fieldCount = inputStream.readInt();
for (int i = 0; i < fieldCount; i++) {
String fieldName = getUTF8CPEntryValue(inputStream);
int fieldFlags = 0;
fieldFlags = visibilityAsMask(fieldFlags, inputStream.readByte());
BType fieldType = readType();
BVarSymbol objectVarSymbol = new BVarSymbol(fieldFlags, names.fromString(fieldName),
objectSymbol.pkgID, fieldType, objectSymbol.scope.owner);
objectSymbol.scope.define(objectVarSymbol.name, objectVarSymbol);
}
int funcCount = inputStream.readInt();
for (int i = 0; i < funcCount; i++) {
String funcName = getUTF8CPEntryValue(inputStream);
int funcFlags = 0;
funcFlags = visibilityAsMask(funcFlags, inputStream.readByte());
BInvokableType funcType = (BInvokableType) readType();
BInvokableSymbol invokableSymbol = Symbols.createFunctionSymbol(funcFlags,
names.fromString(funcName), env.pkgSymbol.pkgID, funcType,
env.pkgSymbol, Symbols.isFlagOn(objFlags, Flags.NATIVE));
invokableSymbol.retType = funcType.retType;
BAttachedFunction attachedFunc =
new BAttachedFunction(names.fromString(funcName), invokableSymbol, funcType);
objectSymbol.attachedFuncs.add(attachedFunc);
if (Names.OBJECT_INIT_SUFFIX.value.equals(funcName)
|| funcName.equals(Names.INIT_FUNCTION_SUFFIX.value)) {
objectSymbol.initializerFunc = attachedFunc;
}
}
Object poppedObjType = compositeStack.pop();
assert poppedObjType == objectType;
return objectType;
case TypeTags.BYTE_ARRAY:
break;
case TypeTags.FUNCTION_POINTER:
break;
case TYPE_TAG_SELF:
int index = inputStream.readInt();
return (BType) compositeStack.get(index);
case SERVICE_TYPE_TAG:
return symTable.anyServiceType;
}
return null;
}