Add thread attribute to the functions which need it.
[SquirrelJME.git] / tools / c-source-writer / src / test / java / cc / squirreljme / c / __Spool__.java
blobf22ef992178e030401239b6471b3fcecd72fdd89
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;
19 /**
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)}.
23 * @since 2023/06/19
25 final class __Spool__
26 extends CFileProxy
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;
35 /**
36 * Initializes the spool.
38 * @param __result The resultant list where tokens go.
39 * @param __cFile The file we are wrting to.
40 * @since 2023/08/08
42 public __Spool__(List<String> __result, CFile __cFile)
44 super(__cFile);
46 this._list = __result;
47 this._cFile = __cFile;
50 /**
51 * {@inheritDoc}
52 * @since 2023/06/19
54 @Override
55 public void close()
56 throws IOException
58 this._cFile.close();
61 /**
62 * Returns the written tokens.
64 * @return The tokens written.
65 * @since 2023/06/19
67 public String[] tokens()
69 Collection<String> list = this._list;
70 return list.toArray(new String[list.size()]);
73 /**
74 * Initializes the spool.
76 * @param __whitespace Is whitespace important for this?
77 * @since 2023/08/08
79 static __Spool__ __init(boolean __whitespace)
81 // Setup output
82 ArrayList<String> result = new ArrayList<>();
83 StringCollectionCTokenOutput output =
84 new StringCollectionCTokenOutput(result, __whitespace);
86 // Setup CFile
87 CFile cFile = new CFile(output);
89 // Pass everything to the spool
90 return new __Spool__(result, cFile);