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