Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c#] handle abstract modifiers #5251

Merged
merged 1 commit into from
Jan 24, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ trait AstForDeclarationsCreator(implicit withSchemaValidation: ValidationMode) {
case "readonly" => newModifierNode(ModifierTypes.READONLY)
case "virtual" => newModifierNode(ModifierTypes.VIRTUAL)
case "const" => newModifierNode(CSharpModifiers.CONST)
case "abstract" => newModifierNode(ModifierTypes.ABSTRACT)
case x =>
logger.warn(s"Unhandled modifier name '$x'")
null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.joern.csharpsrc2cpg.querying.ast

import io.joern.csharpsrc2cpg.testfixtures.CSharpCode2CpgFixture
import io.shiftleft.codepropertygraph.generated.ModifierTypes
import io.shiftleft.semanticcpg.language.*

class ClassDeclarationTests extends CSharpCode2CpgFixture {

"empty abstract class" should {
val cpg = code("""
|abstract class C {}
|""".stripMargin)

"have correct modifiers" in {
cpg.typeDecl.nameExact("C").modifier.modifierType.sorted.l shouldBe List(
ModifierTypes.ABSTRACT,
ModifierTypes.INTERNAL
)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,19 @@ class MethodTests extends CSharpCode2CpgFixture {
}
}

"empty public abstract method" should {
val cpg = code("""
|abstract class C
|{
| public abstract void DoStuff();
|}
|""".stripMargin)

"have correct modifiers" in {
cpg.method.nameExact("DoStuff").modifier.modifierType.sorted.l shouldBe List(
ModifierTypes.ABSTRACT,
ModifierTypes.PUBLIC
)
}
}
}
Loading