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.compilers;
017
018import java.util.Collections;
019import java.util.EnumSet;
020import java.util.Set;
021
022/**
023 * An enum representing the various types of debugger info that can be included in compilations.
024 *
025 * <p>This corresponds to the {@code -g} flag in the OpenJDK Javac implementation.
026 *
027 * <p>Debugging info flags are designed to be combined using the helper methods on this class.
028 *
029 * @author Ashley Scopes
030 * @since 3.0.0
031 */
032public enum DebuggingInfo {
033
034  /**
035   * Include line numbers.
036   */
037  LINES,
038
039  /**
040   * Include local variable names.
041   */
042  VARS,
043
044  /**
045   * Include source code.
046   */
047  SOURCE;
048
049  /**
050   * Return a set of none of the debugger info flags.
051   *
052   * @return a set containing no debugger flags.
053   */
054  public static Set<DebuggingInfo> none() {
055    return EnumSet.noneOf(DebuggingInfo.class);
056  }
057
058  /**
059   * Return a set of the given debugger info flags.
060   *
061   * @param flags flags.
062   * @return the set of the debugger info flags.
063   */
064  public static Set<DebuggingInfo> just(DebuggingInfo... flags) {
065    var set = none();
066    Collections.addAll(set, flags);
067    return set;
068  }
069
070  /**
071   * Return a set of all the debugger info flags.
072   *
073   * @return a set containing all the debugger flags.
074   */
075  public static Set<DebuggingInfo> all() {
076    return EnumSet.allOf(DebuggingInfo.class);
077  }
078}