-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C#] Asts for method, class and member annotations (#4385)
Includes ast creation for member, class and method annotations. Resolves #4386
- Loading branch information
1 parent
7fe68a2
commit 1e81ceb
Showing
6 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
joern-cli/frontends/csharpsrc2cpg/src/main/resources/application.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
csharpsrc2cpg { | ||
dotnetastgen_version: "0.27.0" | ||
dotnetastgen_version: "0.28.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ds/csharpsrc2cpg/src/test/scala/io/joern/csharpsrc2cpg/querying/ast/AnnotationTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.joern.csharpsrc2cpg.querying.ast | ||
|
||
import io.joern.csharpsrc2cpg.testfixtures.CSharpCode2CpgFixture | ||
import io.shiftleft.semanticcpg.language.* | ||
|
||
class AnnotationTests extends CSharpCode2CpgFixture { | ||
"annotations for methods" should { | ||
"have correct attributes" in { | ||
val cpg = code(""" | ||
|using System; | ||
| | ||
|namespace Foo { | ||
| public class Bar { | ||
| [Obsolete("Dep Method", false)] | ||
| public static void Main() {} | ||
| } | ||
|} | ||
|""".stripMargin) | ||
|
||
inside(cpg.method("Main").annotation.l) { case obsolete :: Nil => | ||
obsolete.code shouldBe "Obsolete(\"Dep Method\", false)" | ||
obsolete.name shouldBe "Obsolete" | ||
obsolete.lineNumber shouldBe Some(5) | ||
obsolete.columnNumber shouldBe Some(4) | ||
obsolete.fullName shouldBe "System.ObsoleteAttribute" | ||
} | ||
} | ||
} | ||
|
||
"annotations for classes" should { | ||
"have correct attributes" in { | ||
val cpg = code(""" | ||
|using System; | ||
| | ||
|namespace Foo { | ||
| [Obsolete("Dep Class", false)] | ||
| public class Bar { | ||
| public static void Main() {} | ||
| } | ||
|} | ||
|""".stripMargin) | ||
|
||
inside(cpg.typeDecl("Bar").annotation.l) { case obsolete :: Nil => | ||
obsolete.code shouldBe "Obsolete(\"Dep Class\", false)" | ||
obsolete.name shouldBe "Obsolete" | ||
obsolete.lineNumber shouldBe Some(4) | ||
obsolete.columnNumber shouldBe Some(2) | ||
obsolete.fullName shouldBe "System.ObsoleteAttribute" | ||
} | ||
} | ||
} | ||
|
||
"annotations for members" should { | ||
"have correct attributes" in { | ||
val cpg = code(""" | ||
|using System; | ||
| | ||
|namespace Foo { | ||
| public class Bar { | ||
| [Serializable] public string firstName; | ||
| } | ||
|} | ||
|""".stripMargin) | ||
|
||
inside(cpg.member("firstName").annotation.l) { case serializable :: Nil => | ||
serializable.code shouldBe "Serializable" | ||
serializable.name shouldBe "Serializable" | ||
serializable.lineNumber shouldBe Some(5) | ||
serializable.columnNumber shouldBe Some(4) | ||
serializable.fullName shouldBe "System.SerializableAttribute" | ||
} | ||
} | ||
} | ||
} |