1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.c
;
12 import cc
.squirreljme
.c
.out
.StringCollectionCTokenOutput
;
13 import java
.io
.IOException
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Collection
;
16 import java
.util
.List
;
17 import net
.multiphasicapps
.tac
.TestRunnable
;
20 * Token spool, used for testing, this makes it easier to collect all the
21 * tokens and shove them into {@link TestRunnable#secondary(String, Object)}.
27 implements AutoCloseable
29 /** The CFile we are writing to. */
30 private final CFile _cFile
;
32 /** The resultant list. */
33 private final Collection
<String
> _list
;
36 * Initializes the spool.
38 * @param __result The resultant list where tokens go.
39 * @param __cFile The file we are wrting to.
42 public __Spool__(List
<String
> __result
, CFile __cFile
)
46 this._list
= __result
;
47 this._cFile
= __cFile
;
62 * Returns the written tokens.
64 * @return The tokens written.
67 public String
[] tokens()
69 Collection
<String
> list
= this._list
;
70 return list
.toArray(new String
[list
.size()]);
74 * Initializes the spool.
76 * @param __whitespace Is whitespace important for this?
79 static __Spool__
__init(boolean __whitespace
)
82 ArrayList
<String
> result
= new ArrayList
<>();
83 StringCollectionCTokenOutput output
=
84 new StringCollectionCTokenOutput(result
, __whitespace
);
87 CFile cFile
= new CFile(output
);
89 // Pass everything to the spool
90 return new __Spool__(result
, cFile
);