001/*
002 * Copyright (C) 2022 - 2025, the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.github.ascopes.jct.assertions;
017
018import io.github.ascopes.jct.compilers.JctCompilation;
019import io.github.ascopes.jct.containers.ModuleContainerGroup;
020import io.github.ascopes.jct.containers.OutputContainerGroup;
021import io.github.ascopes.jct.containers.PackageContainerGroup;
022import io.github.ascopes.jct.diagnostics.TraceDiagnostic;
023import io.github.ascopes.jct.filemanagers.PathFileObject;
024import java.util.List;
025import javax.tools.Diagnostic;
026import javax.tools.JavaFileManager.Location;
027import javax.tools.JavaFileObject;
028import org.jspecify.annotations.Nullable;
029
030/**
031 * Helper class to provide fluent creation of assertions for compilations.
032 *
033 * @author Ashley Scopes
034 * @since 0.0.1
035 */
036@SuppressWarnings("unused")
037public final class JctAssertions {
038
039  private JctAssertions() {
040    // Disallow initialisation.
041  }
042
043  /**
044   * Perform an assertion on a compilation.
045   *
046   * <p>This is a shorthand alias for {@link #assertThatCompilation(JctCompilation)}. If you are
047   * using AssertJ assertions in your tests with static imports, you may wish to use that instead to
048   * prevent name conflicts.
049   *
050   * @param compilation the compilation to assert on.
051   * @return the assertion.
052   */
053  public static JctCompilationAssert assertThat(@Nullable JctCompilation compilation) {
054    return assertThatCompilation(compilation);
055  }
056
057  /**
058   * Perform an assertion on a module container group.
059   *
060   * <p>This is a shorthand alias for {@link #assertThatContainerGroup(ModuleContainerGroup)}. If
061   * you are using AssertJ assertions in your tests with static imports, you may wish to use that
062   * instead to prevent name conflicts.
063   *
064   * @param moduleContainerGroup the module container group to assert on.
065   * @return the assertion.
066   */
067  public static ModuleContainerGroupAssert assertThat(
068      @Nullable ModuleContainerGroup moduleContainerGroup
069  ) {
070    return assertThatContainerGroup(moduleContainerGroup);
071  }
072
073  /**
074   * Perform an assertion on an output container group.
075   *
076   * <p>This is a shorthand alias for {@link #assertThatContainerGroup(OutputContainerGroup)}. If
077   * you are using AssertJ assertions in your tests with static imports, you may wish to use that
078   * instead to prevent name conflicts.
079   *
080   * @param outputContainerGroup the output container group to assert on.
081   * @return the assertion.
082   */
083  public static OutputContainerGroupAssert assertThat(
084      @Nullable OutputContainerGroup outputContainerGroup
085  ) {
086    return assertThatContainerGroup(outputContainerGroup);
087  }
088
089  /**
090   * Perform an assertion on a package container group.
091   *
092   * <p>This is a shorthand alias for {@link #assertThatContainerGroup(PackageContainerGroup)}. If
093   * you are using AssertJ assertions in your tests with static imports, you may wish to use that
094   * instead to prevent name conflicts.
095   *
096   * @param packageContainerGroup the package container group to assert on.
097   * @return the assertion.
098   */
099  public static PackageContainerGroupAssert assertThat(
100      @Nullable PackageContainerGroup packageContainerGroup
101  ) {
102    return assertThatContainerGroup(packageContainerGroup);
103  }
104
105  /**
106   * Perform an assertion on a diagnostic.
107   *
108   * <p>This is a shorthand alias for {@link #assertThatDiagnostic(TraceDiagnostic)}. If
109   * you are using AssertJ assertions in your tests with static imports, you may wish to use that
110   * instead to prevent name conflicts.
111   *
112   * @param diagnostic the diagnostic to assert on.
113   * @return the assertion.
114   */
115  public static TraceDiagnosticAssert assertThat(
116      @Nullable TraceDiagnostic<? extends JavaFileObject> diagnostic
117  ) {
118    return assertThatDiagnostic(diagnostic);
119  }
120
121  /**
122   * Perform an assertion on a Java file object.
123   *
124   * <p>This is a shorthand alias for {@link #assertThatFileObject(JavaFileObject)}. If you are
125   * using AssertJ assertions in your tests with static imports, you may wish to use that instead to
126   * prevent name conflicts.
127   *
128   * @param fileObject the file object to assert on.
129   * @return the assertion.
130   */
131  public static JavaFileObjectAssert assertThat(@Nullable JavaFileObject fileObject) {
132    return assertThatFileObject(fileObject);
133  }
134
135  /**
136   * Perform an assertion on a Path-based Java file object.
137   *
138   * <p>This is a shorthand alias for {@link #assertThatFileObject(PathFileObject)}. If you are
139   * using AssertJ assertions in your tests with static imports, you may wish to use that instead to
140   * prevent name conflicts.
141   *
142   * @param fileObject the file object to assert on.
143   * @return the assertion.
144   */
145  public static PathFileObjectAssert assertThat(@Nullable PathFileObject fileObject) {
146    return assertThatFileObject(fileObject);
147  }
148
149  /**
150   * Perform an assertion on a diagnostic kind.
151   *
152   * <p>This is a shorthand alias for {@link #assertThatKind(Diagnostic.Kind)}. If you are using
153   * AssertJ assertions in your tests with static imports, you may wish to use that instead to
154   * prevent name conflicts.
155   *
156   * @param kind the diagnostic kind to assert on.
157   * @return the assertion.
158   */
159  public static DiagnosticKindAssert assertThat(Diagnostic.@Nullable Kind kind) {
160    return assertThatKind(kind);
161  }
162
163  /**
164   * Perform an assertion on a Java file object kind.
165   *
166   * <p>This is a shorthand alias for {@link #assertThatKind(JavaFileObject.Kind)}. If you are
167   * using AssertJ assertions in your tests with static imports, you may wish to use that instead to
168   * prevent name conflicts.
169   *
170   * @param kind the Java file object kind to assert on.
171   * @return the assertion.
172   */
173  public static JavaFileObjectKindAssert assertThat(JavaFileObject.@Nullable Kind kind) {
174    return assertThatKind(kind);
175  }
176
177  /**
178   * Perform an assertion on a location.
179   *
180   * <p>This is a shorthand alias for {@link #assertThatLocation(Location)}. If you are using
181   * AssertJ assertions in your tests with static imports, you may wish to use that instead to
182   * prevent name conflicts.
183   *
184   * @param location the location to assert on.
185   * @return the assertion.
186   */
187  public static LocationAssert assertThat(@Nullable Location location) {
188    return assertThatLocation(location);
189  }
190
191  /**
192   * Perform an assertion on a compilation.
193   *
194   * @param compilation the compilation to assert on.
195   * @return the assertion.
196   */
197  public static JctCompilationAssert assertThatCompilation(@Nullable JctCompilation compilation) {
198    return new JctCompilationAssert(compilation);
199  }
200
201  /**
202   * Perform an assertion on a module container group.
203   *
204   * @param moduleContainerGroup the module container group to assert on.
205   * @return the assertion.
206   */
207  public static ModuleContainerGroupAssert assertThatContainerGroup(
208      @Nullable ModuleContainerGroup moduleContainerGroup
209  ) {
210    return new ModuleContainerGroupAssert(moduleContainerGroup);
211  }
212
213  /**
214   * Perform an assertion on an output container group.
215   *
216   * @param outputContainerGroup the output container group to assert on.
217   * @return the assertion.
218   */
219  public static OutputContainerGroupAssert assertThatContainerGroup(
220      @Nullable OutputContainerGroup outputContainerGroup
221  ) {
222    return new OutputContainerGroupAssert(outputContainerGroup);
223  }
224
225  /**
226   * Perform an assertion on a package container group.
227   *
228   * @param packageContainerGroup the package container group to assert on.
229   * @return the assertion.
230   */
231  public static PackageContainerGroupAssert assertThatContainerGroup(
232      @Nullable PackageContainerGroup packageContainerGroup
233  ) {
234    return new PackageContainerGroupAssert(packageContainerGroup);
235  }
236
237  /**
238   * Perform an assertion on a diagnostic.
239   *
240   * @param diagnostic the diagnostic to assert on.
241   * @return the assertion.
242   */
243  public static TraceDiagnosticAssert assertThatDiagnostic(
244      @Nullable TraceDiagnostic<? extends JavaFileObject> diagnostic
245  ) {
246    return new TraceDiagnosticAssert(diagnostic);
247  }
248
249  /**
250   * Perform an assertion on a list of diagnostics.
251   *
252   * @param diagnostics the diagnostics to assert on.
253   * @return the assertion.
254   */
255  public static TraceDiagnosticListAssert assertThatDiagnostics(
256      @Nullable List<? extends TraceDiagnostic<? extends JavaFileObject>> diagnostics
257  ) {
258    return new TraceDiagnosticListAssert(diagnostics);
259  }
260
261  /**
262   * Perform an assertion on a Java file object.
263   *
264   * @param fileObject the file object to assert on.
265   * @return the assertion.
266   */
267  public static JavaFileObjectAssert assertThatFileObject(@Nullable JavaFileObject fileObject) {
268    return new JavaFileObjectAssert(fileObject);
269  }
270
271  /**
272   * Perform an assertion on a Path-based Java file object.
273   *
274   * @param fileObject the file object to assert on.
275   * @return the assertion.
276   */
277  public static PathFileObjectAssert assertThatFileObject(@Nullable PathFileObject fileObject) {
278    return new PathFileObjectAssert(fileObject);
279  }
280
281  /**
282   * Perform an assertion on a diagnostic kind.
283   *
284   * @param kind the diagnostic kind to assert on.
285   * @return the assertion.
286   */
287  public static DiagnosticKindAssert assertThatKind(Diagnostic.@Nullable Kind kind) {
288    return new DiagnosticKindAssert(kind);
289  }
290
291  /**
292   * Perform an assertion on a Java file object kind.
293   *
294   * @param kind the Java file object kind to assert on.
295   * @return the assertion.
296   */
297  public static JavaFileObjectKindAssert assertThatKind(JavaFileObject.@Nullable Kind kind) {
298    return new JavaFileObjectKindAssert(kind);
299  }
300
301  /**
302   * Perform an assertion on a location.
303   *
304   * @param location the location to assert on.
305   * @return the assertion.
306   */
307  public static LocationAssert assertThatLocation(@Nullable Location location) {
308    return new LocationAssert(location);
309  }
310}
311