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