// System.out.println("classVarTypeBinding = " + classVarTypeBinding);
if (classVarTypeBinding != null) { //In a class method
Environment declEnv = classVarTypeBinding.getClassDecl().getInstanceMembersEnv();
Environment innerEnv = seq.extendName(Environment.getEmptyEnvironment(), env).extend(declEnv);
seq.typecheck(env.extend(new NameBindingImpl("this", new ClassType(new Reference<>(innerEnv), new Reference<>(innerEnv), new LinkedList<>(), classVarTypeBinding.getClassDecl().getName()))), Optional.empty());
Environment environment = seq.extendType(declEnv, declEnv.extend(env));
environment = seq.extendName(environment, environment.extend(env));
Environment nnames = seq.extend(environment, environment);
Environment objTee = TypeDeclUtils.getTypeEquivalentEnvironment(nnames.extend(declEnv));
Type classVarType = new ClassType(new Reference<>(nnames.extend(declEnv)), new Reference<>(objTee), new LinkedList<>(), classVarTypeBinding.getClassDecl().getName());
if (!(classVarType instanceof ClassType)) {
// System.out.println("Type checking classVarType: " + classVarType + " and clsVar = " + clsVar);
ToolError.reportError(ErrorMessage.MUST_BE_LITERAL_CLASS, this, classVarType.toString());
}
// TODO SMELL: do I really need to store this? Can get it any time from the type
cls = classVarTypeBinding.getClassDecl();
ct = classVarType;
return classVarType;
} else { // Standalone
isGeneric = true;
Environment innerEnv = seq.extendType(Environment.getEmptyEnvironment(), env);
Environment savedInner = env.extend(innerEnv);
innerEnv = seq.extendName(innerEnv, savedInner);
Environment declEnv = env.extend(new NameBindingImpl("this", new ClassType(new Reference<>(innerEnv), new Reference<>(innerEnv), new LinkedList<>(), null)));
final Environment ideclEnv = StreamSupport.stream(seq.getDeclIterator().spliterator(), false).
reduce(declEnv, (oenv,decl)->(decl instanceof ClassDeclaration)?decl.extend(oenv, savedInner):oenv,(a,b)->a.extend(b));
seq.getDeclIterator().forEach(decl -> decl.typecheck(ideclEnv, Optional.<Type>empty()));
Environment mockEnv = Environment.getEmptyEnvironment();
LinkedList<Declaration> decls = new LinkedList<>();
mockEnv = getGenericDecls(env, mockEnv, decls);
Environment nnames = (seq.extendName(mockEnv,mockEnv.extend(env)));
ClassDeclaration classDeclaration = new ClassDeclaration("generic" + generic_num++, "", "", new DeclSequence(decls), mockEnv, new LinkedList<String>(), getLocation());
cls = classDeclaration;
Environment tee = TypeDeclUtils.getTypeEquivalentEnvironment(nnames.extend(mockEnv));
ct = new ClassType(new Reference<>(nnames.extend(mockEnv)), new Reference<>(tee), new LinkedList<String>(), null);
return ct;
}
}