Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src
root
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1768922402:/home/marlonsc/mozilla-rust-code-analisis/src/metrics/abc.rs:src
1768924638:/home/marlonsc/mozilla-rust-code-analisis/Cargo.toml:root
1768925046:/home/marlonsc/mozilla-rust-code-analisis/src/node.rs:src
1768925048:/home/marlonsc/mozilla-rust-code-analisis/src/langs.rs:src
1768925051:/home/marlonsc/mozilla-rust-code-analisis/src/tools.rs:src
1768925211:/home/marlonsc/mozilla-rust-code-analisis/src/macros.rs:src
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ serde = { version = "^1.0", features = ["derive"] }
termcolor = "^1.2"
walkdir = "^2.3"

tree-sitter = "=0.25.3"
tree-sitter = "=0.26.3"
tree-sitter-java = "=0.23.5"
tree-sitter-kotlin-ng = "1.1.0"
tree-sitter-kotlin-codanna = "0.3.9"
tree-sitter-typescript = "=0.23.2"
tree-sitter-javascript = "=0.23.1"
tree-sitter-python = "=0.23.6"
tree-sitter-rust = "=0.23.2"
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.3" }
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.3" }
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.4" }
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.3" }
tree-sitter-javascript = "=0.25.0"
tree-sitter-python = "=0.25.0"
tree-sitter-rust = "=0.24.0"
tree-sitter-preproc = { path = "./tree-sitter-preproc", version = "=0.20.4" }
tree-sitter-ccomment = { path = "./tree-sitter-ccomment", version = "=0.20.4" }
tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.5" }
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.20.4" }

[dev-dependencies]
insta = { version = "1.29.0", features = ["yaml", "json", "redactions"] }
Expand Down
18 changes: 9 additions & 9 deletions enums/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ edition = "2024"
clap = { version = "^4.0", features = ["derive"] }
askama = "^0.14"

tree-sitter = "=0.25.3"
tree-sitter = "=0.26.3"
tree-sitter-java = "=0.23.5"
tree-sitter-kotlin-ng = "1.1.0"
tree-sitter-kotlin-codanna = "0.3.9"
tree-sitter-typescript = "=0.23.2"
tree-sitter-javascript = "=0.23.1"
tree-sitter-python = "=0.23.6"
tree-sitter-rust = "=0.23.2"
tree-sitter-preproc = { path = "../tree-sitter-preproc", version = "=0.20.3" }
tree-sitter-ccomment = { path = "../tree-sitter-ccomment", version = "=0.20.3" }
tree-sitter-mozcpp = { path = "../tree-sitter-mozcpp", version = "=0.20.4" }
tree-sitter-mozjs = { path = "../tree-sitter-mozjs", version = "=0.20.3" }
tree-sitter-javascript = "=0.25.0"
tree-sitter-python = "=0.25.0"
tree-sitter-rust = "=0.24.0"
tree-sitter-preproc = { path = "../tree-sitter-preproc", version = "=0.20.4" }
tree-sitter-ccomment = { path = "../tree-sitter-ccomment", version = "=0.20.4" }
tree-sitter-mozcpp = { path = "../tree-sitter-mozcpp", version = "=0.20.5" }
tree-sitter-mozjs = { path = "../tree-sitter-mozjs", version = "=0.20.4" }

[profile.release]
strip = "debuginfo"
2 changes: 1 addition & 1 deletion enums/src/languages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use tree_sitter::Language;
mk_langs!(
// 1) Name for enum
// 2) tree-sitter function to call to get a Language
(Kotlin, tree_sitter_kotlin_ng),
(Kotlin, tree_sitter_kotlin_codanna),
(Java, tree_sitter_java),
(Rust, tree_sitter_rust),
(Cpp, tree_sitter_cpp),
Expand Down
2 changes: 1 addition & 1 deletion enums/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ macro_rules! mk_get_language {
( $( ($camel:ident, $name:ident) ),* ) => {
pub fn get_language(lang: &Lang) -> Language {
match lang {
Lang::Kotlin => tree_sitter_kotlin_ng::LANGUAGE.into(),
Lang::Kotlin => tree_sitter_kotlin_codanna::language().into(),
Lang::Java => tree_sitter_java::LANGUAGE.into(),
Lang::Typescript => tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into(),
Lang::Tsx => tree_sitter_typescript::LANGUAGE_TSX.into(),
Expand Down
55 changes: 40 additions & 15 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,39 +663,64 @@ impl Checker for RustCode {
}

impl Checker for KotlinCode {
fn is_comment(_: &Node) -> bool {
false
fn is_comment(node: &Node) -> bool {
matches!(
node.kind_id().into(),
Kotlin::LineComment | Kotlin::MultilineComment
)
}

fn is_useful_comment(_: &Node, _: &[u8]) -> bool {
false
}

fn is_func_space(_: &Node) -> bool {
false
fn is_func_space(node: &Node) -> bool {
matches!(
node.kind_id().into(),
Kotlin::SourceFile | Kotlin::ClassDeclaration
)
}

fn is_func(_: &Node) -> bool {
false
fn is_func(node: &Node) -> bool {
node.kind_id() == Kotlin::FunctionDeclaration
}

fn is_closure(_: &Node) -> bool {
false
fn is_closure(node: &Node) -> bool {
node.kind_id() == Kotlin::LambdaLiteral
}

fn is_call(_: &Node) -> bool {
false
fn is_call(node: &Node) -> bool {
node.kind_id() == Kotlin::CallExpression
}

fn is_non_arg(_: &Node) -> bool {
false
fn is_non_arg(node: &Node) -> bool {
matches!(
node.kind_id().into(),
Kotlin::LPAREN
| Kotlin::COMMA
| Kotlin::RPAREN
| Kotlin::PIPEPIPE
| Kotlin::UnaryExpression
Comment on lines +702 to +703
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is_non_arg implementation includes PIPEPIPE (||) as a non-argument token, but this doesn't match the typical pattern from other language implementations which focus on delimiters and structural elements. The inclusion of UnaryExpression also seems unusual - other implementations typically only include punctuation tokens. This may cause issues with parameter counting in functions that use these operators.

Suggested change
| Kotlin::PIPEPIPE
| Kotlin::UnaryExpression

Copilot uses AI. Check for mistakes.
)
}

fn is_string(_: &Node) -> bool {
false
fn is_string(node: &Node) -> bool {
// StringLiteral covers both single-line and multi-line strings in this grammar
// StringContent captures the text content within strings
matches!(
node.kind_id().into(),
Kotlin::StringLiteral | Kotlin::StringContent
)
}

fn is_else_if(_: &Node) -> bool {
fn is_else_if(node: &Node) -> bool {
if node.kind_id() != Kotlin::IfExpression {
return false;
}
if let Some(parent) = node.parent() {
return parent.kind_id() == Kotlin::Else;
}

false
}

Expand Down
50 changes: 49 additions & 1 deletion src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,52 @@ impl Getter for JavaCode {
}
}

impl Getter for KotlinCode {}
impl Getter for KotlinCode {
fn get_space_kind(node: &Node) -> SpaceKind {
use Kotlin::*;

let typ = node.kind_id().into();
match typ {
ClassDeclaration => SpaceKind::Class,
FunctionDeclaration | Constructor | AnnotatedLambda => SpaceKind::Function,
SourceFile => SpaceKind::Unit,
_ => SpaceKind::Unknown,
}
}

fn get_op_type(node: &Node) -> HalsteadType {
use Kotlin::*;

let typ = node.kind_id();

match typ.into() {
// Operator: function calls
CallExpression
// Operator: control flow
| If | Else | When | Try | Catch | Throw | For | While | Continue | Break | Do | Finally
// Operator: keywords
| Return | Abstract | Final | Super | This
// Operator: brackets and comma and terminators (separators)
| SEMI | COMMA | COLONCOLON | LBRACE | LBRACK | LPAREN | RBRACE | RBRACK | RPAREN | DOTDOT | DOT
// Operator: operators
| EQ | LT | GT | BANG | QMARKCOLON | AsQMARK | COLON // no grammar for lambda operator ->
| EQEQ | LTEQ | GTEQ | BANGEQ | AMPAMP | PIPEPIPE | PLUSPLUS | DASHDASH
| PLUS | DASH | STAR | SLASH | PERCENT
| PLUSEQ | DASHEQ | STAREQ | SLASHEQ | PERCENTEQ => {
HalsteadType::Operator
}
// Operands: variables, constants, literals
// StringLiteral covers both line strings and multi-line strings in this grammar
RealLiteral | IntegerLiteral | HexLiteral | BinLiteral | CharacterLiteralToken1 | UniCharacterLiteralToken1
| LiteralConstant | StringLiteral | StringContent | LambdaLiteral | FunctionLiteral
| ObjectLiteral | UnsignedLiteral | LongLiteral | BooleanLiteral | CharacterLiteral => {
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Halstead operand classification appears to be missing the Identifier node type, which is present in other language implementations (Python, JavaScript, TypeScript, Rust, C++, Java). This means that variable names and function names won't be counted as operands in Halstead metrics calculations. Consider adding Identifier and SimpleIdentifier to the operand match pattern.

Suggested change
| ObjectLiteral | UnsignedLiteral | LongLiteral | BooleanLiteral | CharacterLiteral => {
| ObjectLiteral | UnsignedLiteral | LongLiteral | BooleanLiteral | CharacterLiteral
| Identifier | SimpleIdentifier => {

Copilot uses AI. Check for mistakes.
HalsteadType::Operand
},
_ => {
HalsteadType::Unknown
},
}
}

get_operator!(Kotlin);
}
2 changes: 1 addition & 1 deletion src/langs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mk_langs!(
"kotlin",
KotlinCode,
KotlinParser,
tree_sitter_kotlin_ng,
tree_sitter_kotlin_codanna,
[kt, kts],
["kotlin"]
),
Expand Down
Loading