@@ -3399,12 +3399,12 @@ interface Sink extends Closeable {
3399
3399
/**
3400
3400
* Stores the supplied binary representation of types in this sink.
3401
3401
*
3402
- * @param version The version of the multi-release jar file, which should at least be {@code 8} as previous
3402
+ * @param classFileVersion The version of the multi-release jar file, which should at least be {@code 8} as previous
3403
3403
* versions are not recognized by regular class loaders.
3404
3404
* @param binaryRepresentations The binary representations to store.
3405
3405
* @throws IOException If an I/O error occurs.
3406
3406
*/
3407
- void store (int version , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException ;
3407
+ void store (ClassFileVersion classFileVersion , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException ;
3408
3408
3409
3409
/**
3410
3410
* Retains the supplied element in its original form.
@@ -3447,9 +3447,13 @@ public void store(Map<TypeDescription, byte[]> binaryRepresentations) throws IOE
3447
3447
/**
3448
3448
* {@inheritDoc}
3449
3449
*/
3450
- public void store (int version , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException {
3450
+ public void store (ClassFileVersion classFileVersion , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException {
3451
3451
for (Map .Entry <TypeDescription , byte []> entry : binaryRepresentations .entrySet ()) {
3452
- outputStream .putNextEntry (new JarEntry (ClassFileLocator .META_INF_VERSIONS + version + "/" + entry .getKey ().getInternalName () + ClassFileLocator .CLASS_FILE_EXTENSION ));
3452
+ outputStream .putNextEntry (new JarEntry (ClassFileLocator .META_INF_VERSIONS
3453
+ + classFileVersion .getJavaVersion ()
3454
+ + "/"
3455
+ + entry .getKey ().getInternalName ()
3456
+ + ClassFileLocator .CLASS_FILE_EXTENSION ));
3453
3457
outputStream .write (entry .getValue ());
3454
3458
outputStream .closeEntry ();
3455
3459
}
@@ -3512,7 +3516,7 @@ public void store(Map<TypeDescription, byte[]> binaryRepresentations) {
3512
3516
/**
3513
3517
* {@inheritDoc}
3514
3518
*/
3515
- public void store (int version , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException {
3519
+ public void store (ClassFileVersion classFileVersion , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException {
3516
3520
/* do nothing */
3517
3521
}
3518
3522
@@ -3585,9 +3589,13 @@ public void store(Map<TypeDescription, byte[]> binaryRepresentations) {
3585
3589
/**
3586
3590
* {@inheritDoc}
3587
3591
*/
3588
- public void store (int version , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException {
3592
+ public void store (ClassFileVersion classFileVersion , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException {
3589
3593
for (Map .Entry <TypeDescription , byte []> entry : binaryRepresentations .entrySet ()) {
3590
- storage .put (ClassFileLocator .META_INF_VERSIONS + version + "/" + entry .getKey ().getInternalName () + ClassFileLocator .CLASS_FILE_EXTENSION , entry .getValue ());
3594
+ storage .put (ClassFileLocator .META_INF_VERSIONS
3595
+ + classFileVersion .getJavaVersion ()
3596
+ + "/"
3597
+ + entry .getKey ().getInternalName ()
3598
+ + ClassFileLocator .CLASS_FILE_EXTENSION , entry .getValue ());
3591
3599
}
3592
3600
}
3593
3601
@@ -3761,8 +3769,8 @@ public void store(Map<TypeDescription, byte[]> binaryRepresentations) throws IOE
3761
3769
/**
3762
3770
* {@inheritDoc}
3763
3771
*/
3764
- public void store (int version , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException {
3765
- doStore (new File (folder , ClassFileLocator .META_INF_VERSIONS + version ), binaryRepresentations );
3772
+ public void store (ClassFileVersion classFileVersion , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException {
3773
+ doStore (new File (folder , ClassFileLocator .META_INF_VERSIONS + classFileVersion . getJavaVersion () ), binaryRepresentations );
3766
3774
}
3767
3775
3768
3776
/**
@@ -3877,7 +3885,7 @@ interface Materializable {
3877
3885
void materialize (Target .Sink sink ,
3878
3886
List <TypeDescription > transformed ,
3879
3887
Map <TypeDescription ,
3880
- List <Throwable >> failed ,
3888
+ List <Throwable >> failed ,
3881
3889
List <String > unresolved ) throws IOException ;
3882
3890
3883
3891
/**
@@ -3886,9 +3894,10 @@ void materialize(Target.Sink sink,
3886
3894
class ForTransformedElement implements Materializable {
3887
3895
3888
3896
/**
3889
- * The multi-release Java version number or {@code 0} .
3897
+ * The multi-release class file version number or {@code null} if a regular class .
3890
3898
*/
3891
- private final int version ;
3899
+ @ MaybeNull
3900
+ private final ClassFileVersion classFileVersion ;
3892
3901
3893
3902
/**
3894
3903
* The type that has been transformed.
@@ -3898,11 +3907,11 @@ class ForTransformedElement implements Materializable {
3898
3907
/**
3899
3908
* Creates a new materializable for a successfully transformed type.
3900
3909
*
3901
- * @param version The multi-release Java version number or {@code 0} .
3902
- * @param dynamicType The type that has been transformed.
3910
+ * @param classFileVersion The multi-release class file version number or {@code null} if a regular class .
3911
+ * @param dynamicType The type that has been transformed.
3903
3912
*/
3904
- protected ForTransformedElement (int version , DynamicType dynamicType ) {
3905
- this .version = version ;
3913
+ protected ForTransformedElement (@ MaybeNull ClassFileVersion classFileVersion , DynamicType dynamicType ) {
3914
+ this .classFileVersion = classFileVersion ;
3906
3915
this .dynamicType = dynamicType ;
3907
3916
}
3908
3917
@@ -3912,12 +3921,12 @@ protected ForTransformedElement(int version, DynamicType dynamicType) {
3912
3921
public void materialize (Target .Sink sink ,
3913
3922
List <TypeDescription > transformed ,
3914
3923
Map <TypeDescription ,
3915
- List <Throwable >> failed ,
3924
+ List <Throwable >> failed ,
3916
3925
List <String > unresolved ) throws IOException {
3917
- if (version == 0 ) {
3926
+ if (classFileVersion == null ) {
3918
3927
sink .store (dynamicType .getAllTypes ());
3919
3928
} else {
3920
- sink .store (version , dynamicType .getAllTypes ());
3929
+ sink .store (classFileVersion , dynamicType .getAllTypes ());
3921
3930
}
3922
3931
transformed .add (dynamicType .getTypeDescription ());
3923
3932
}
@@ -3948,7 +3957,7 @@ protected ForRetainedElement(Source.Element element) {
3948
3957
public void materialize (Target .Sink sink ,
3949
3958
List <TypeDescription > transformed ,
3950
3959
Map <TypeDescription ,
3951
- List <Throwable >> failed ,
3960
+ List <Throwable >> failed ,
3952
3961
List <String > unresolved ) throws IOException {
3953
3962
sink .retain (element );
3954
3963
}
@@ -3993,7 +4002,7 @@ protected ForFailedElement(Source.Element element, TypeDescription typeDescripti
3993
4002
public void materialize (Target .Sink sink ,
3994
4003
List <TypeDescription > transformed ,
3995
4004
Map <TypeDescription ,
3996
- List <Throwable >> failed ,
4005
+ List <Throwable >> failed ,
3997
4006
List <String > unresolved ) throws IOException {
3998
4007
sink .retain (element );
3999
4008
failed .put (typeDescription , errored );
@@ -4032,7 +4041,7 @@ protected ForUnresolvedElement(Source.Element element, String typeName) {
4032
4041
public void materialize (Target .Sink sink ,
4033
4042
List <TypeDescription > transformed ,
4034
4043
Map <TypeDescription ,
4035
- List <Throwable >> failed ,
4044
+ List <Throwable >> failed ,
4036
4045
List <String > unresolved ) throws IOException {
4037
4046
sink .retain (element );
4038
4047
unresolved .add (typeName );
@@ -4951,20 +4960,20 @@ public Summary apply(Source source, Target target, List<? extends Plugin.Factory
4951
4960
&& !name .endsWith (PACKAGE_INFO )
4952
4961
&& !name .endsWith (MODULE_INFO )) {
4953
4962
try {
4954
- int version = name .startsWith (ClassFileLocator .META_INF_VERSIONS )
4955
- ? Math . max ( 7 , Integer .parseInt (name .substring (ClassFileLocator .META_INF_VERSIONS .length (), name .indexOf ('/' , ClassFileLocator .META_INF_VERSIONS .length ()))))
4956
- : 0 ;
4957
- if (version == 0 || version > 7
4958
- && classFileVersion != null
4959
- && classFileVersion .isAtLeast (ClassFileVersion .JAVA_V9 )
4960
- && version <= classFileVersion .getJavaVersion ( )) {
4963
+ ClassFileVersion classFileVersion = name .startsWith (ClassFileLocator .META_INF_VERSIONS )
4964
+ ? ClassFileVersion . ofJavaVersion ( Integer .parseInt (name .substring (ClassFileLocator .META_INF_VERSIONS .length (), name .indexOf ('/' , ClassFileLocator .META_INF_VERSIONS .length ()))))
4965
+ : null ;
4966
+ if (classFileVersion == null || classFileVersion . isAtLeast ( ClassFileVersion . JAVA_V8 )
4967
+ && this . classFileVersion != null
4968
+ && this . classFileVersion .isAtLeast (ClassFileVersion .JAVA_V9 )
4969
+ && classFileVersion .isAtMost ( this . classFileVersion )) {
4961
4970
String typeName = name .substring (name .startsWith (ClassFileLocator .META_INF_VERSIONS )
4962
4971
? name .indexOf ('/' , ClassFileLocator .META_INF_VERSIONS .length ()) + 1
4963
4972
: 0 , name .length () - ClassFileLocator .CLASS_FILE_EXTENSION .length ()).replace ('/' , '.' );
4964
4973
dispatcher .accept (new Preprocessor (element ,
4965
4974
typeName ,
4966
- version ,
4967
4975
new SourceEntryPrependingClassFileLocator (typeName , element , classFileLocator ),
4976
+ classFileVersion ,
4968
4977
typePool ,
4969
4978
listener ,
4970
4979
plugins ,
@@ -5096,14 +5105,16 @@ private class Preprocessor implements Callable<Callable<? extends Dispatcher.Mat
5096
5105
private final String typeName ;
5097
5106
5098
5107
/**
5099
- * The multi-release Java version number or {@code 0} .
5108
+ * The class file locator to use .
5100
5109
*/
5101
- private final int version ;
5110
+ private final ClassFileLocator classFileLocator ;
5102
5111
5103
5112
/**
5104
- * The class file locator to use .
5113
+ * The multi-release class file version or {@code null} for a regular class .
5105
5114
*/
5106
- private final ClassFileLocator classFileLocator ;
5115
+ @ MaybeNull
5116
+ @ HashCodeAndEqualsPlugin .ValueHandling (HashCodeAndEqualsPlugin .ValueHandling .Sort .REVERSE_NULLABILITY )
5117
+ private final ClassFileVersion classFileVersion ;
5107
5118
5108
5119
/**
5109
5120
* The type pool to use.
@@ -5130,25 +5141,25 @@ private class Preprocessor implements Callable<Callable<? extends Dispatcher.Mat
5130
5141
*
5131
5142
* @param element The processed element.
5132
5143
* @param typeName The name of the processed type.
5133
- * @param version The multi-release Java version number or {@code 0}.
5134
5144
* @param classFileLocator The class file locator to use.
5145
+ * @param classFileVersion The multi-release class file version or {@code null} for a regular class.
5135
5146
* @param typePool The type pool to use.
5136
5147
* @param listener The listener to notify.
5137
5148
* @param plugins The plugins to apply.
5138
5149
* @param preprocessors The plugins with preprocessors to preprocess.
5139
5150
*/
5140
5151
private Preprocessor (Source .Element element ,
5141
5152
String typeName ,
5142
- int version ,
5143
5153
ClassFileLocator classFileLocator ,
5154
+ @ MaybeNull ClassFileVersion classFileVersion ,
5144
5155
TypePool typePool ,
5145
5156
Listener listener ,
5146
5157
List <Plugin > plugins ,
5147
5158
List <WithPreprocessor > preprocessors ) {
5148
5159
this .element = element ;
5149
5160
this .typeName = typeName ;
5150
- this .version = version ;
5151
5161
this .classFileLocator = classFileLocator ;
5162
+ this .classFileVersion = classFileVersion ;
5152
5163
this .typePool = typePool ;
5153
5164
this .listener = listener ;
5154
5165
this .plugins = plugins ;
@@ -5168,7 +5179,7 @@ public Callable<Dispatcher.Materializable> call() throws Exception {
5168
5179
for (WithPreprocessor preprocessor : preprocessors ) {
5169
5180
preprocessor .onPreprocess (typeDescription , classFileLocator );
5170
5181
}
5171
- return new Resolved (version , typeDescription );
5182
+ return new Resolved (classFileVersion , typeDescription );
5172
5183
} else {
5173
5184
return new Ignored (typeDescription );
5174
5185
}
@@ -5193,9 +5204,10 @@ public Callable<Dispatcher.Materializable> call() throws Exception {
5193
5204
private class Resolved implements Callable <Dispatcher .Materializable > {
5194
5205
5195
5206
/**
5196
- * The multi-release Java version number or {@code 0} .
5207
+ * The multi-release Java version number or {@code null} if a regular class .
5197
5208
*/
5198
- private final int version ;
5209
+ @ MaybeNull
5210
+ private final ClassFileVersion classFileVersion ;
5199
5211
5200
5212
/**
5201
5213
* A description of the resolved type.
@@ -5205,11 +5217,11 @@ private class Resolved implements Callable<Dispatcher.Materializable> {
5205
5217
/**
5206
5218
* Creates a new resolved materializable.
5207
5219
*
5208
- * @param version The multi-release Java version number or {@code 0} .
5209
- * @param typeDescription A description of the resolved type.
5220
+ * @param classFileVersion The multi-release Java version number or {@code null} if a regular class .
5221
+ * @param typeDescription A description of the resolved type.
5210
5222
*/
5211
- private Resolved (int version , TypeDescription typeDescription ) {
5212
- this .version = version ;
5223
+ private Resolved (@ MaybeNull ClassFileVersion classFileVersion , TypeDescription typeDescription ) {
5224
+ this .classFileVersion = classFileVersion ;
5213
5225
this .typeDescription = typeDescription ;
5214
5226
}
5215
5227
@@ -5248,7 +5260,7 @@ public Dispatcher.Materializable call() {
5248
5260
listener .onLiveInitializer (typeDescription , entry .getKey ());
5249
5261
}
5250
5262
}
5251
- return new Dispatcher .Materializable .ForTransformedElement (version , dynamicType );
5263
+ return new Dispatcher .Materializable .ForTransformedElement (classFileVersion , dynamicType );
5252
5264
} catch (Throwable throwable ) {
5253
5265
errored .add (throwable );
5254
5266
listener .onError (typeDescription , errored );
0 commit comments