Skip to content
Merged
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
25 changes: 25 additions & 0 deletions cpp/libclang/integration_test/cases/method_modifier_final/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")

cc_library(
name = "method_modifier_final",
srcs = ["final_sample.cpp"],
visibility = ["//cpp/libclang:__subpackages__"],
)

cpp_parser_integration_test(
name = "test_method_modifier_final",
expected_output = ["expected.json"],
target = ":method_modifier_final",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"types": {
"FinalMethodBase": {
"id": "FinalMethodBase",
"name": "FinalMethodBase",
"enclosing_namespace_id": null,
"stereotypes": [],
"entity_type": "Class",
"type_aliases": [],
"variables": [],
"methods": [
{
"name": "sealedHere",
"return_type": "void",
"visibility": "public",
"parameters": [],
"template_parameters": null,
"modifiers": [
"Virtual",
"Final"
],
"source_location": {
"file": "cpp/libclang/integration_test/cases/method_modifier_final/final_sample.cpp",
"line": 16
}
},
{
"name": "overridable",
"return_type": "void",
"visibility": "public",
"parameters": [],
"template_parameters": null,
"modifiers": [
"Virtual"
],
"source_location": {
"file": "cpp/libclang/integration_test/cases/method_modifier_final/final_sample.cpp",
"line": 17
}
}
],
"template_parameters": null,
"enum_literals": [],
"relationships": [],
"source_location": {
"file": "cpp/libclang/integration_test/cases/method_modifier_final/final_sample.cpp",
"line": 14
}
},
"FinalMethodDerived": {
"id": "FinalMethodDerived",
"name": "FinalMethodDerived",
"enclosing_namespace_id": null,
"stereotypes": [],
"entity_type": "Class",
"type_aliases": [],
"variables": [],
"methods": [
{
"name": "overridable",
"return_type": "void",
"visibility": "public",
"parameters": [],
"template_parameters": null,
"modifiers": [
"Virtual",
"Override",
"Final"
],
"source_location": {
"file": "cpp/libclang/integration_test/cases/method_modifier_final/final_sample.cpp",
"line": 22
}
}
],
"template_parameters": null,
"enum_literals": [],
"relationships": [
{
"source": "FinalMethodDerived",
"target": "FinalMethodBase",
"relation_type": "Inheritance",
"source_multiplicity": null,
"target_multiplicity": null,
"source_location": {
"file": "cpp/libclang/integration_test/cases/method_modifier_final/final_sample.cpp",
"line": 20
}
}
],
"source_location": {
"file": "cpp/libclang/integration_test/cases/method_modifier_final/final_sample.cpp",
"line": 20
}
}
},
"functions": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/********************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

class FinalMethodBase {
public:
virtual void sealedHere() final;
virtual void overridable();
};

class FinalMethodDerived : public FinalMethodBase {
public:
void overridable() override final;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// *******************************************************************************
// Copyright (c) 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache License Version 2.0 which is available at
// <https://www.apache.org/licenses/LICENSE-2.0>
//
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

use test_framework::run_parser_case;

#[test]
fn test_method_modifier_final() {
run_parser_case();
}
5 changes: 5 additions & 0 deletions cpp/libclang/src/visitor/src/class_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ fn parse_method(entity: &Entity, parsed_method_type: &ParsedMethodType) -> Optio
.get_overridden_methods()
.map(|methods| !methods.is_empty())
.unwrap_or(false);
let is_final_method = entity
.get_children()
.into_iter()
.any(|child| child.get_kind() == EntityKind::FinalAttr);

// Only the bare `noexcept` specifier is modeled (mirrors the PlantUML grammar, which has
// no support for the conditional `noexcept(expr)` form). Requiring `BasicNoexcept` filters
Expand Down Expand Up @@ -326,6 +330,7 @@ fn parse_method(entity: &Entity, parsed_method_type: &ParsedMethodType) -> Optio
(is_noexcept_method, MethodModifier::Noexcept),
(kind == EntityKind::Constructor, MethodModifier::Constructor),
(kind == EntityKind::Destructor, MethodModifier::Destructor),
(is_final_method, MethodModifier::Final),
]),
source_location: parse_source_location(entity),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,8 @@ impl ClassParseSession<'_> {
| Rule::override_modifier
| Rule::const_method_qualifier
| Rule::noexcept_method_qualifier
| Rule::trailing_override_qualifier => {
method.modifiers.push(p.as_str().to_string())
}
| Rule::trailing_override_qualifier
| Rule::final_method_qualifier => method.modifiers.push(p.as_str().to_string()),
Rule::friend_specifier => method.is_friend = true,
Rule::pure_virtual_suffix => ensure_abstract_modifier(&mut method),
Rule::class_visibility => vis = Some(p),
Expand Down Expand Up @@ -524,6 +523,8 @@ impl ClassParseSession<'_> {
}
Rule::class_body => {
for inner in pair.into_inner() {
// Intentionally visit only Rule::class_member; mock_method_invocation pairs
// are modeled as absent from the class diagram, not as real methods.
if let Rule::class_member = inner.as_rule() {
for member in inner.into_inner() {
self.parse_class_member_into(member, def)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ fn test_method_modifier_placement() {
run_class_diagram_parser_case("method_modifier_placement");
}

#[test]
fn test_mock_method_variants_ignored() {
run_class_diagram_parser_case("mock_method_variants_ignored");
}

#[test]
fn test_mock_method_interleaved_members_survive() {
run_class_diagram_parser_case("mock_method_interleaved_members_survive");
}

#[test]
fn test_multiline_note() {
run_class_diagram_parser_case("multiline_note");
Expand Down
Loading
Loading