Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.

Commit 56806a7

Browse files
author
Brian Pfretzschner
committed
Run cargo fmt
1 parent 6897691 commit 56806a7

File tree

11 files changed

+52
-42
lines changed

11 files changed

+52
-42
lines changed

loader/src/classfile_loader.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use anyhow::{anyhow, Result};
22
use glob::glob;
3+
use log::debug;
34
use model::api::Parser;
45
use model::class::JvmClass;
56
use std::collections::HashMap;
67
use std::fs::File;
78
use std::io::BufReader;
89
use std::path::{Path, PathBuf};
9-
use log::debug;
1010

1111
use model::api::Classloader;
1212

@@ -28,8 +28,12 @@ impl ClassfileLoader {
2828

2929
debug!("Parsing classfile {}", file_path.display());
3030

31-
parser.parse(&mut reader).map(|class| (classpath, class))
32-
.map_err(|err| anyhow!("Failed to parse classfile {}: {}", file_path.display(), err))
31+
parser
32+
.parse(&mut reader)
33+
.map(|class| (classpath, class))
34+
.map_err(|err| {
35+
anyhow!("Failed to parse classfile {}: {}", file_path.display(), err)
36+
})
3337
})
3438
.collect::<Result<_>>()?;
3539

loader/src/jarfile_loader.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use anyhow::Result;
21
use anyhow::anyhow;
2+
use anyhow::Result;
33
use model::api::Classloader;
44
use model::api::Parser;
55
use model::class::JvmClass;
@@ -59,7 +59,9 @@ fn parse_classfiles(
5959
Some((path, parser.parse(&mut file)))
6060
})
6161
.map(|(path, class_result)| {
62-
class_result.map(|class| (path, class)).map_err(|err| anyhow!(err))
62+
class_result
63+
.map(|class| (path, class))
64+
.map_err(|err| anyhow!(err))
6365
})
6466
.collect()
6567
}

model/src/class.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,33 +96,33 @@ pub enum ClassConstant {
9696
pub enum FieldAccessFlag {
9797
/// Declared public; may be accesse from outside its package.
9898
Public,
99-
99+
100100
/// Declared private; usable only within the defining class.
101-
Private,
101+
Private,
102102

103103
/// Declared protected; may be accessed within subclasses.
104-
Protected,
104+
Protected,
105105

106106
/// Declared static.
107-
Static,
107+
Static,
108108

109109
/// Declared final; never directly assigned to after object construction.
110-
Final,
110+
Final,
111111

112112
/// Declared volatile; cannot be cached.
113-
Volatile,
113+
Volatile,
114114

115115
/// Declared transient; not written or read by a persistent object manager.
116-
Transient,
116+
Transient,
117117

118118
/// Declared synthetic; not present in the source code.
119-
Synthetic,
119+
Synthetic,
120120

121121
/// Declared as an annotation type.
122122
Annotation,
123123

124124
/// Declared as an element of an enum.
125-
Enum,
125+
Enum,
126126
}
127127

128128
pub type ClassFields = Vec<ClassField>;

model/src/class_impl.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ impl ClassConstants {
2424
))?;
2525
match constant {
2626
&ClassConstant::Class(ref string) => Ok(string),
27-
it => bail!(
28-
"Expected Class but found {:?} at index {}",
29-
it,
30-
index
31-
),
27+
it => bail!("Expected Class but found {:?} at index {}", it, index),
3228
}
3329
}
3430
}

parser/src/attributes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ pub fn map(classfile: &ClassFile, _constants: &ClassConstants) -> Result<ClassAt
66
classfile
77
.attributes
88
.iter()
9-
.map(|attribute| {
10-
Ok(ClassAttribute::NotImplemented)
11-
})
9+
.map(|attribute| Ok(ClassAttribute::NotImplemented))
1210
.collect()
1311
}

parser/src/class_info.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
use anyhow::{bail, Result};
22
use classfile_parser::{types::ClassFile, ClassAccessFlags};
33
use enumset::EnumSet;
4-
use model::class::{ClassConstants, ClassAccessFlag};
5-
6-
pub fn map(classfile: &ClassFile, constants: &ClassConstants) -> Result<(EnumSet<ClassAccessFlag>, String, Option<String>, Vec<String>)> {
4+
use model::class::{ClassAccessFlag, ClassConstants};
5+
6+
pub fn map(
7+
classfile: &ClassFile,
8+
constants: &ClassConstants,
9+
) -> Result<(
10+
EnumSet<ClassAccessFlag>,
11+
String,
12+
Option<String>,
13+
Vec<String>,
14+
)> {
715
let access_flags = Wrap(classfile.access_flags).try_into()?;
816
let this_class = constants.get_class(classfile.this_class)?.into();
917

@@ -13,9 +21,11 @@ pub fn map(classfile: &ClassFile, constants: &ClassConstants) -> Result<(EnumSet
1321
None
1422
};
1523

16-
let interfaces: Vec<_> = classfile.interfaces.iter().map(|index|
17-
constants.get_class(*index).map(|s| s.to_owned())
18-
).collect::<Result<_>>()?;
24+
let interfaces: Vec<_> = classfile
25+
.interfaces
26+
.iter()
27+
.map(|index| constants.get_class(*index).map(|s| s.to_owned()))
28+
.collect::<Result<_>>()?;
1929

2030
Ok((access_flags, this_class, super_class, interfaces))
2131
}

parser/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use anyhow::{bail, Result};
22
use model::class::{ClassVersion, JvmClass};
33
use std::io::Read;
44

5-
mod type_signature;
65
mod method_signature;
6+
mod type_signature;
77

8+
mod attributes;
89
mod class_info;
910
mod constants;
1011
mod fields;
1112
mod methods;
12-
mod attributes;
1313

1414
pub struct ClassfileParser {}
1515

parser/src/methods.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use anyhow::{Result, bail};
1+
use anyhow::{bail, Result};
2+
use classfile_parser::{method_info::MethodAccessFlags, types::ClassFile};
23
use enumset::EnumSet;
3-
use model::class::{ClassConstants, ClassMethods, ClassMethod, MethodAccessFlag};
4-
use classfile_parser::{types::ClassFile, method_info::MethodAccessFlags};
4+
use model::class::{ClassConstants, ClassMethod, ClassMethods, MethodAccessFlag};
55

66
use crate::method_signature::parse_method_signature;
77

parser/src/type_signature.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::str::Chars;
21
use std::iter::Peekable;
2+
use std::str::Chars;
33

4-
use anyhow::{Result, anyhow, bail};
4+
use anyhow::{anyhow, bail, Result};
55
use model::class::TypeSignature;
66

77
pub fn parse_type_signature(spec: &String) -> Result<TypeSignature> {
@@ -27,4 +27,4 @@ pub(crate) fn parse_type(iterator: &mut Peekable<Chars>) -> Result<TypeSignature
2727

2828
fn read_class_path(iterator: &mut Peekable<Chars>) -> String {
2929
iterator.take_while(|c| *c != ';').collect::<String>()
30-
}
30+
}

parser/tests/class_with_fields_only.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use enumset::EnumSet;
2-
use model::class::{TypeSignature, ClassAccessFlag, FieldAccessFlag};
2+
use model::class::{ClassAccessFlag, FieldAccessFlag, TypeSignature};
33

44
mod test_utils;
55

@@ -24,10 +24,7 @@ fn validate_against_javap() {
2424
assert_eq!("testdata/ClassOnlyWithFields", class.this_class);
2525

2626
// super_class: #11 // java/lang/Object
27-
assert_eq!(
28-
Some("java/lang/Object".to_string()),
29-
class.super_class
30-
);
27+
assert_eq!(Some("java/lang/Object".to_string()), class.super_class);
3128

3229
// interfaces: 0, fields: 5, methods: 2, attributes: 1
3330
assert_eq!(0, class.interfaces.len());

0 commit comments

Comments
 (0)