Skip to content

Commit 94d3216

Browse files
committed
Add ability to override debugger info flags/parameter info flags
Add the ability to set the debugger info flags explicitly, and default to enabling said flags by default to improve the diagnostic capabilities of generated class files. Adds the ability to override the default parameter info inclusion setting on the compiler, and defaults to including by default to enrich further reflection assertions.
1 parent c6cdf86 commit 94d3216

File tree

8 files changed

+428
-61
lines changed

8 files changed

+428
-61
lines changed

java-compiler-testing/src/main/java/io/github/ascopes/jct/compilers/AbstractJctCompiler.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Collection;
3333
import java.util.List;
3434
import java.util.Locale;
35+
import java.util.Set;
3536
import javax.annotation.processing.Processor;
3637
import org.apiguardian.api.API;
3738
import org.apiguardian.api.API.Status;
@@ -79,6 +80,8 @@ public abstract class AbstractJctCompiler implements JctCompiler {
7980
private boolean inheritSystemModulePath;
8081
private LoggingMode fileManagerLoggingMode;
8182
private AnnotationProcessorDiscovery annotationProcessorDiscovery;
83+
private Set<DebuggingInfo> debuggingInfo;
84+
private boolean parameterInfoEnabled;
8285

8386
/**
8487
* Initialize this compiler.
@@ -108,6 +111,8 @@ protected AbstractJctCompiler(String defaultName) {
108111
inheritSystemModulePath = JctCompiler.DEFAULT_INHERIT_SYSTEM_MODULE_PATH;
109112
fileManagerLoggingMode = JctCompiler.DEFAULT_FILE_MANAGER_LOGGING_MODE;
110113
annotationProcessorDiscovery = JctCompiler.DEFAULT_ANNOTATION_PROCESSOR_DISCOVERY;
114+
debuggingInfo = DEFAULT_DEBUGGING_INFO;
115+
parameterInfoEnabled = DEFAULT_PARAMETER_INFO_ENABLED;
111116
}
112117

113118
@Override
@@ -417,6 +422,29 @@ public AbstractJctCompiler annotationProcessorDiscovery(
417422
return this;
418423
}
419424

425+
@Override
426+
public Set<DebuggingInfo> getDebuggingInfo() {
427+
return debuggingInfo;
428+
}
429+
430+
@Override
431+
public JctCompiler debuggingInfo(Set<DebuggingInfo> debuggingInfo) {
432+
requireNonNullValues(debuggingInfo, "debuggingInfo");
433+
this.debuggingInfo = Set.copyOf(debuggingInfo);
434+
return this;
435+
}
436+
437+
@Override
438+
public boolean isParameterInfoEnabled() {
439+
return parameterInfoEnabled;
440+
}
441+
442+
@Override
443+
public JctCompiler parameterInfoEnabled(boolean parameterInfoEnabled) {
444+
this.parameterInfoEnabled = parameterInfoEnabled;
445+
return this;
446+
}
447+
420448
/**
421449
* Get the string representation of the compiler.
422450
*
@@ -504,6 +532,8 @@ protected List<String> buildFlags(JctFlagBuilder flagBuilder) {
504532
.target(target)
505533
.verbose(verbose)
506534
.showWarnings(showWarnings)
535+
.debuggingInfo(debuggingInfo)
536+
.parameterInfoEnabled(parameterInfoEnabled)
507537
.build();
508538
}
509539

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2022 - 2023, the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.github.ascopes.jct.compilers;
17+
18+
import java.util.EnumSet;
19+
import java.util.Set;
20+
import org.apiguardian.api.API;
21+
import org.apiguardian.api.API.Status;
22+
23+
/**
24+
* An enum representing the various types of debugger info that can be included in compilations.
25+
*
26+
* <p>This corresponds to the {@code -g} flag in the OpenJDK Javac implementation.
27+
*
28+
* @author Ashley Scopes
29+
* @since 3.0.0
30+
*/
31+
@API(since = "3.0.0", status = Status.STABLE)
32+
public enum DebuggingInfo {
33+
LINES,
34+
VARS,
35+
SOURCE;
36+
37+
/**
38+
* Return a set of none of the debugger info flags.
39+
*
40+
* @return a set containing no debugger flags.
41+
*/
42+
public static Set<DebuggingInfo> none() {
43+
return EnumSet.noneOf(DebuggingInfo.class);
44+
}
45+
46+
/**
47+
* Return a set of the given debugger info flags.
48+
*
49+
* @param flag the first flag.
50+
* @param flags additional flags.
51+
* @return the set of the debugger info flags.
52+
*/
53+
public static Set<DebuggingInfo> just(DebuggingInfo flag, DebuggingInfo... flags) {
54+
return EnumSet.of(flag, flags);
55+
}
56+
57+
/**
58+
* Return a set of all the debugger info flags.
59+
*
60+
* @return a set containing all the debugger flags.
61+
*/
62+
public static Set<DebuggingInfo> all() {
63+
return EnumSet.allOf(DebuggingInfo.class);
64+
}
65+
}

0 commit comments

Comments
 (0)