Ops check for Halstead (#849)
This commit is contained in:
Родитель
0a841ae432
Коммит
f7a1295f86
|
@ -494,6 +494,7 @@ impl Getter for CppCode {
|
|||
|
||||
impl Getter for PreprocCode {}
|
||||
impl Getter for CcommentCode {}
|
||||
|
||||
impl Getter for JavaCode {
|
||||
fn get_space_kind(node: &Node) -> SpaceKind {
|
||||
use Java::*;
|
||||
|
@ -514,26 +515,27 @@ impl Getter for JavaCode {
|
|||
// https://www.geeksforgeeks.org/software-engineering-halsteads-software-metrics/?msclkid=5e181114abef11ecbb03527e95a34828
|
||||
match node.kind_id().into() {
|
||||
// Operator: function calls
|
||||
MethodInvocation
|
||||
//MethodInvocation
|
||||
// Operator: control flow
|
||||
| If | Else | Switch | Case | Try | Catch | Throw | Throws | Throws2 | For | While | Continue | Break | Do | Finally
|
||||
// Operator: keywords
|
||||
| New | Return | Default | Abstract | Assert | Instanceof | Extends | Final | Implements | Transient | Synchronized | Super | This | VoidType
|
||||
// Operator: brackets and comma and terminators (separators)
|
||||
| SEMI | COMMA | COLONCOLON | LBRACE | LBRACK | LPAREN | RBRACE | RBRACK | RPAREN | DOTDOTDOT | DOT
|
||||
| SEMI | COMMA | COLONCOLON | LBRACE | LBRACK | LPAREN // | RBRACE | RBRACK | RPAREN | DOTDOTDOT | DOT
|
||||
// Operator: operators
|
||||
| EQ | LT | GT | BANG | TILDE | QMARK | COLON // no grammar for lambda operator ->
|
||||
| EQEQ | LTEQ | GTEQ | BANGEQ | AMPAMP | PIPEPIPE | PLUSPLUS | DASHDASH
|
||||
| PLUS | DASH | STAR | SLASH | AMP | PIPE | CARET | PERCENT| LTLT | GTGT | GTGTGT
|
||||
| PLUSEQ | DASHEQ | STAREQ | SLASHEQ | AMPEQ | PIPEEQ | CARETEQ | PERCENTEQ | LTLTEQ | GTGTEQ | GTGTGTEQ
|
||||
// type identifier
|
||||
| TypeIdentifier | IntegralType | FloatingPointType | BooleanType
|
||||
//| TypeIdentifier | BooleanType| IntegralType | FloatingPointType
|
||||
// primitive types
|
||||
| Int | Float
|
||||
=> {
|
||||
HalsteadType::Operator
|
||||
},
|
||||
// Operands: variables, constants, literals
|
||||
Identifier | NullLiteral | ClassLiteral | StringLiteral | CharacterLiteral | HexIntegerLiteral | OctalIntegerLiteral
|
||||
| BinaryIntegerLiteral | DecimalIntegerLiteral | HexFloatingPointLiteral | DecimalFloatingPointLiteral => {
|
||||
Identifier | NullLiteral | ClassLiteral | StringLiteral | CharacterLiteral | HexIntegerLiteral | OctalIntegerLiteral | BinaryIntegerLiteral | DecimalIntegerLiteral | HexFloatingPointLiteral | DecimalFloatingPointLiteral => {
|
||||
HalsteadType::Operand
|
||||
},
|
||||
_ => {
|
||||
|
@ -542,7 +544,17 @@ impl Getter for JavaCode {
|
|||
}
|
||||
}
|
||||
|
||||
get_operator!(Java);
|
||||
fn get_operator_id_as_str(id: u16) -> &'static str {
|
||||
let typ = id.into();
|
||||
match typ {
|
||||
Java::LPAREN => "()",
|
||||
Java::LBRACK => "[]",
|
||||
Java::LBRACE => "{}",
|
||||
Java::VoidType => "void",
|
||||
_ => typ.into(),
|
||||
}
|
||||
}
|
||||
//get_operator!(Java);
|
||||
}
|
||||
|
||||
impl Getter for KotlinCode {}
|
||||
|
|
|
@ -665,7 +665,7 @@ mod tests {
|
|||
fn java_operators_and_operands() {
|
||||
check_metrics::<JavaParser>(
|
||||
"public class Main {
|
||||
public static void main(String args[]) {
|
||||
public static void main(string args[]) {
|
||||
int a, b, c, avg;
|
||||
a = 5; b = 5; c = 5;
|
||||
avg = (a + b + c) / 3;
|
||||
|
@ -680,20 +680,20 @@ mod tests {
|
|||
metric.halstead,
|
||||
@r###"
|
||||
{
|
||||
"n1": 16.0,
|
||||
"N1": 34.0,
|
||||
"n1": 10.0,
|
||||
"N1": 25.0,
|
||||
"n2": 12.0,
|
||||
"N2": 22.0,
|
||||
"length": 56.0,
|
||||
"estimated_program_length": 107.01955000865388,
|
||||
"purity_ratio": 1.9110633930116765,
|
||||
"vocabulary": 28.0,
|
||||
"volume": 269.2118756352258,
|
||||
"difficulty": 14.666666666666666,
|
||||
"level": 0.06818181818181819,
|
||||
"effort": 3948.440842649978,
|
||||
"time": 219.35782459166546,
|
||||
"bugs": 0.08327139413010551
|
||||
"length": 47.0,
|
||||
"estimated_program_length": 76.2388309575275,
|
||||
"purity_ratio": 1.6221027863303723,
|
||||
"vocabulary": 22.0,
|
||||
"volume": 209.59328607595296,
|
||||
"difficulty": 9.166666666666666,
|
||||
"level": 0.1090909090909091,
|
||||
"effort": 1921.2717890295687,
|
||||
"time": 106.73732161275382,
|
||||
"bugs": 0.05151550353617788
|
||||
}"###
|
||||
);
|
||||
},
|
||||
|
|
31
src/ops.rs
31
src/ops.rs
|
@ -648,4 +648,35 @@ mod tests {
|
|||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn java_ops() {
|
||||
check_ops(
|
||||
LANG::Java,
|
||||
"public class Main {
|
||||
public static void main(string args[]) {
|
||||
int a, b, c, avg;
|
||||
a = 5; b = 5; c = 5;
|
||||
avg = (a + b + c) / 3;
|
||||
MessageFormat.format(\"{0}\", avg);
|
||||
}
|
||||
}",
|
||||
"foo.java",
|
||||
&mut ["{}", "void", "()", "[]", ",", ";", "int", "=", "+", "/"],
|
||||
&mut [
|
||||
"Main",
|
||||
"main",
|
||||
"args",
|
||||
"a",
|
||||
"b",
|
||||
"c",
|
||||
"avg",
|
||||
"5",
|
||||
"3",
|
||||
"MessageFormat",
|
||||
"format",
|
||||
"\"{0}\"",
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче