Skip to content

Commit 3dc5bfc

Browse files
committed
Operator impl and assertions
1 parent a85c385 commit 3dc5bfc

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/getter.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ impl Getter for JavaCode {
549549
// Operand: vars and const
550550

551551
let typ = node.object().kind_id();
552+
552553
match typ.into() {
553554
// LPAREN | COMMA | STAR | GTGT | COLON | SEMI | Return | Break | Continue | If | Else
554555
// | Switch | Case | Default | For | While | New | Try | Catch | Throw | Throws
@@ -560,18 +561,32 @@ impl Getter for JavaCode {
560561
// Operator: control flow
561562
| If | Else | Switch | Case | Try | Catch | Throw | Throws | Throws2 | For | While | Continue | Break | Do | Finally
562563
// Operator: keywords
563-
| New | Return | Default | Abstract | Assert | Instanceof | Extends | Final | Implements | Transient | Synchronized | Super | This
564+
| New | Return | Default | Abstract | Assert | Instanceof | Extends | Final | Implements | Transient | Synchronized | Super | This | VoidType
564565
// Operator: brackets and comma and terminators (separators)
565566
| SEMI | COMMA | COLONCOLON | LBRACE | LBRACK | LPAREN | RBRACE | RBRACK | RPAREN | DOTDOTDOT | DOT
566567
// Operator: operators
567568
| EQ | LT | GT | BANG | TILDE | QMARK | COLON // no grammar for lambda operator ->
568569
| EQEQ | LTEQ | GTEQ | BANGEQ | AMPAMP | PIPEPIPE | PLUSPLUS | DASHDASH
569570
| PLUS | DASH | STAR | SLASH | AMP | PIPE | CARET | PERCENT| LTLT | GTGT | GTGTGT
570571
| PLUSEQ | DASHEQ | STAREQ | SLASHEQ | AMPEQ | PIPEEQ | CARETEQ | PERCENTEQ | LTLTEQ | GTGTEQ | GTGTGTEQ
571-
=> HalsteadType::Operator,
572+
// type identifier
573+
| TypeIdentifier
574+
// Literals
575+
| IntegralType | FloatingPointType | BooleanType | NullLiteral
576+
=> {
577+
println!("operator: {}", node.object().kind().to_string());
578+
HalsteadType::Operator
579+
},
580+
572581
// variables, constants
573-
Identifier | Literal => HalsteadType::Operand,
574-
_ => HalsteadType::Unknown,
582+
Identifier | Literal => {
583+
println!("operand: {} ", node.object().kind().to_string());
584+
HalsteadType::Operand
585+
},
586+
_ => {
587+
println!("unknown: {} ", node.object().kind().to_string());
588+
HalsteadType::Unknown
589+
},
575590
}
576591
}
577592

src/metrics/halstead.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,10 @@ mod tests {
540540
JavaParser,
541541
halstead,
542542
[
543-
(u_operators, 10, usize), // function, (), {}, var, =, +, /, ,, ., ;
544-
// (operators, 24, usize),
545-
// (u_operands, 11, usize), // main, a, b, c, avg, 3, 5, console.log, console, log, "{}"
546-
// (operands, 21, usize)
543+
(u_operators, 16, usize), // void ; ( String [ ] ) { , int = + / format . }
544+
(operators, 33, usize),
545+
(u_operands, 11, usize), // main, a, b, c, avg, 3, 5, MessageFormat.format, format, "{}"
546+
(operands, 21, usize)
547547
]
548548
);
549549
}

0 commit comments

Comments
 (0)