@@ -4,6 +4,7 @@ use crate::{
4
4
error:: JavaError , CompileResult , JvmWrapper , TestCase , TestCaseStatus , TestMethod , TestRun ,
5
5
} ;
6
6
use j4rs:: InvocationArg ;
7
+ use serde:: { Deserialize , Serialize } ;
7
8
use std:: {
8
9
collections:: HashMap ,
9
10
convert:: TryFrom ,
@@ -13,8 +14,8 @@ use std::{
13
14
} ;
14
15
use tmc_langs_framework:: {
15
16
nom:: { bytes, character, combinator, error:: VerboseError , sequence, IResult } ,
16
- ExerciseDesc , Language , LanguagePlugin , RunResult , RunStatus , StyleValidationResult , TestDesc ,
17
- TestResult , TmcCommand ,
17
+ ExerciseDesc , Language , LanguagePlugin , RunResult , RunStatus , StyleValidationError ,
18
+ StyleValidationResult , StyleValidationStrategy , TestDesc , TestResult , TmcCommand ,
18
19
} ;
19
20
use tmc_langs_util:: { deserialize, file_util, parse_util} ;
20
21
use walkdir:: WalkDir ;
@@ -254,12 +255,12 @@ pub(crate) trait JavaPlugin: LanguagePlugin {
254
255
& [ InvocationArg :: from ( file) , InvocationArg :: from ( locale) ] ,
255
256
) ?;
256
257
let result = jvm. invoke ( & checkstyle_runner, "run" , InvocationArg :: empty ( ) ) ?;
257
- let result: StyleValidationResult = jvm. to_rust ( result) ?;
258
+ let result: JavaStyleValidationResult = jvm. to_rust ( result) ?;
258
259
Ok ( result)
259
260
} ) ?;
260
261
261
262
log:: debug!( "Validation result: {:?}" , result) ;
262
- Ok ( result)
263
+ Ok ( result. into ( ) )
263
264
}
264
265
265
266
/// Parses @Points("1.1") point annotations.
@@ -291,6 +292,67 @@ pub(crate) trait JavaPlugin: LanguagePlugin {
291
292
}
292
293
}
293
294
295
+ /// Determines how style errors are handled.
296
+ #[ derive( Debug , Deserialize , Serialize , PartialEq , Eq ) ]
297
+ #[ serde( rename_all = "UPPERCASE" ) ]
298
+ pub enum JavaStyleValidationStrategy {
299
+ Fail ,
300
+ Warn ,
301
+ Disabled ,
302
+ }
303
+
304
+ impl From < JavaStyleValidationStrategy > for StyleValidationStrategy {
305
+ fn from ( value : JavaStyleValidationStrategy ) -> Self {
306
+ match value {
307
+ JavaStyleValidationStrategy :: Fail => Self :: Fail ,
308
+ JavaStyleValidationStrategy :: Warn => Self :: Warn ,
309
+ JavaStyleValidationStrategy :: Disabled => Self :: Disabled ,
310
+ }
311
+ }
312
+ }
313
+
314
+ /// A style validation error.
315
+ #[ derive( Debug , Deserialize , Serialize , PartialEq , Eq ) ]
316
+ #[ serde( rename_all = "camelCase" ) ]
317
+ pub struct JavaStyleValidationError {
318
+ pub column : u32 ,
319
+ pub line : u32 ,
320
+ pub message : String ,
321
+ pub source_name : String ,
322
+ }
323
+
324
+ impl From < JavaStyleValidationError > for StyleValidationError {
325
+ fn from ( value : JavaStyleValidationError ) -> Self {
326
+ Self {
327
+ column : value. column ,
328
+ line : value. line ,
329
+ message : value. message ,
330
+ source_name : value. source_name ,
331
+ }
332
+ }
333
+ }
334
+
335
+ /// The result of a style check.
336
+ #[ derive( Debug , Deserialize , Serialize , PartialEq , Eq ) ]
337
+ #[ serde( rename_all = "camelCase" ) ]
338
+ pub struct JavaStyleValidationResult {
339
+ pub strategy : JavaStyleValidationStrategy ,
340
+ pub validation_errors : Option < HashMap < PathBuf , Vec < JavaStyleValidationError > > > ,
341
+ }
342
+
343
+ impl From < JavaStyleValidationResult > for StyleValidationResult {
344
+ fn from ( value : JavaStyleValidationResult ) -> Self {
345
+ Self {
346
+ strategy : value. strategy . into ( ) ,
347
+ validation_errors : value. validation_errors . map ( |hm| {
348
+ hm. into_iter ( )
349
+ . map ( |( k, v) | ( k, v. into_iter ( ) . map ( Into :: into) . collect ( ) ) )
350
+ . collect ( )
351
+ } ) ,
352
+ }
353
+ }
354
+ }
355
+
294
356
#[ cfg( test) ]
295
357
#[ allow( clippy:: unwrap_used) ]
296
358
mod test {
0 commit comments