1
1
package io .papermc .typewriter .context ;
2
2
3
+ import com .google .common .base .Preconditions ;
3
4
import org .checkerframework .checker .nullness .qual .NonNull ;
4
5
import org .checkerframework .framework .qual .DefaultQualifier ;
5
6
import org .jetbrains .annotations .Contract ;
14
15
*
15
16
* @param importLayout the import layout used
16
17
* @param indentUnit the default indent unit used if no one is found in the source file
18
+ * @param classpath the targeted classpath to resolve class reference during import parsing
19
+ * @param javaVersion the version of java the generated code must be compliant to
17
20
*/
18
21
@ DefaultQualifier (NonNull .class )
19
- public record SourcesMetadata (ImportLayout importLayout , IndentUnit indentUnit , Set <Path > classpath ) {
22
+ public record SourcesMetadata (ImportLayout importLayout , IndentUnit indentUnit , Set <Path > classpath , int javaVersion ) {
20
23
21
24
/**
22
25
* Constructs a file metadata with the default import layout and
@@ -33,11 +36,16 @@ public static SourcesMetadata of(IndentUnit indentUnit) {
33
36
return of (indentUnit , UnaryOperator .identity ());
34
37
}
35
38
39
+ public boolean canSkipMarkdownDocComments () {
40
+ return Boolean .getBoolean ("typewriter.lexer.ignoreMarkdownDocComments" ) || this .javaVersion < 23 ;
41
+ }
42
+
36
43
public static class Builder {
37
44
38
45
private final IndentUnit indentUnit ;
39
46
private ImportLayout layout = ImportLayout .DEFAULT ;
40
47
private Set <Path > classpath = Collections .emptySet ();
48
+ private int javaVersion = Runtime .version ().feature ();
41
49
42
50
Builder (IndentUnit indentUnit ) {
43
51
this .indentUnit = indentUnit ;
@@ -55,11 +63,19 @@ public Builder classpath(Set<Path> classpath) {
55
63
return this ;
56
64
}
57
65
66
+ @ Contract (value = "_ -> this" , mutates = "this" )
67
+ public Builder javaVersion (int featureVersion ) {
68
+ Preconditions .checkArgument (featureVersion >= 0 , "Feature version must be non-negative" );
69
+ this .javaVersion = featureVersion ;
70
+ return this ;
71
+ }
72
+
58
73
SourcesMetadata complete () {
59
74
return new SourcesMetadata (
60
75
this .layout ,
61
76
this .indentUnit ,
62
- this .classpath
77
+ this .classpath ,
78
+ this .javaVersion
63
79
);
64
80
}
65
81
}
0 commit comments