Skip to content

Commit

Permalink
javasrc2cpg: Annotation Column Numbers (#2318)
Browse files Browse the repository at this point in the history
Probably should have done this when I added line numbers, but added column numbers for annotations.
  • Loading branch information
DavidBakerEffendi authored Feb 27, 2023
1 parent c86ad75 commit de24046
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ class AstCreator(filename: String, javaParserAst: CompilationUnit, global: Globa
.name(annotationExpr.getName.getIdentifier)
.fullName(expressionReturnTypeFullName(annotationExpr).getOrElse(fallbackType))
.lineNumber(line(annotationExpr))
.columnNumber(column(annotationExpr))
}

private def astForAnnotationExpr(annotationExpr: AnnotationExpr): Ast = {
Expand Down Expand Up @@ -2698,6 +2699,7 @@ class AstCreator(filename: String, javaParserAst: CompilationUnit, global: Globa
.evaluationStrategy(evalStrat)
.typeFullName(typeFullName)
.lineNumber(line(expr))
.columnNumber(column(expr))
typeInfoCalc.registerType(typeFullName)
paramNode
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class AnnotationTests extends JavaSrcCode2CpgFixture {
annotationNode.name shouldBe "NormalAnnotation"
annotationNode.fullName shouldBe "some.NormalAnnotation"
annotationNode.lineNumber shouldBe Some(5)
annotationNode.columnNumber shouldBe Some(3)
}

"test annotation node parameter assignment child" in {
Expand Down Expand Up @@ -63,6 +64,7 @@ class AnnotationTests extends JavaSrcCode2CpgFixture {
annotationNode.name shouldBe "SingleAnnotation"
annotationNode.fullName shouldBe "some.SingleAnnotation"
annotationNode.lineNumber shouldBe Some(5)
annotationNode.columnNumber shouldBe Some(3)
}

"test annotation node parameter assignment child" in {
Expand Down Expand Up @@ -102,6 +104,7 @@ class AnnotationTests extends JavaSrcCode2CpgFixture {
annotationNode.name shouldBe "MarkerAnnotation"
annotationNode.fullName shouldBe "some.MarkerAnnotation"
annotationNode.lineNumber shouldBe Some(5)
annotationNode.columnNumber shouldBe Some(3)
}

"test annotation node parameter assignment child" in {
Expand All @@ -127,6 +130,7 @@ class AnnotationTests extends JavaSrcCode2CpgFixture {
annotationNode.name shouldBe "MarkerAnnotation"
annotationNode.fullName shouldBe "some.MarkerAnnotation"
annotationNode.lineNumber shouldBe Some(5)
annotationNode.columnNumber shouldBe Some(3)
}

"test annotation node parameter assignment child" in {
Expand All @@ -150,6 +154,7 @@ class AnnotationTests extends JavaSrcCode2CpgFixture {
annotationNode.name shouldBe "MarkerAnnotation"
annotationNode.fullName shouldBe "some.MarkerAnnotation"
annotationNode.lineNumber shouldBe Some(5)
annotationNode.columnNumber shouldBe Some(17)
}
}

Expand All @@ -167,6 +172,7 @@ class AnnotationTests extends JavaSrcCode2CpgFixture {
annotationNode.name shouldBe "MarkerAnnotation"
annotationNode.fullName shouldBe "some.MarkerAnnotation"
annotationNode.lineNumber shouldBe Some(4)
annotationNode.columnNumber shouldBe Some(3)
}
}

Expand All @@ -187,6 +193,7 @@ class AnnotationTests extends JavaSrcCode2CpgFixture {
annotationNode.name shouldBe "NormalAnnotation"
annotationNode.fullName shouldBe "some.NormalAnnotation"
annotationNode.lineNumber shouldBe Some(5)
annotationNode.columnNumber shouldBe Some(3)
}

"test annotation node parameter value" in {
Expand Down Expand Up @@ -214,6 +221,7 @@ class AnnotationTests extends JavaSrcCode2CpgFixture {
annotationNode.name shouldBe "NormalAnnotation"
annotationNode.fullName shouldBe "some.NormalAnnotation"
annotationNode.lineNumber shouldBe Some(5)
annotationNode.columnNumber shouldBe Some(3)
}

"test annotation node parameter assignment child" in {
Expand Down Expand Up @@ -263,6 +271,7 @@ class AnnotationTests extends JavaSrcCode2CpgFixture {
annotationNode.name shouldBe "NormalAnnotation"
annotationNode.fullName shouldBe "some.NormalAnnotation"
annotationNode.lineNumber shouldBe Some(6)
annotationNode.columnNumber shouldBe Some(3)
}

"test annotation node parameter value" in {
Expand Down

0 comments on commit de24046

Please sign in to comment.