Skip to content

Commit

Permalink
[Bug] Annotations aren't being extracted from initializers (#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
liamnichols committed Mar 27, 2024
1 parent b2d484c commit 2f9cf2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ public struct AnnotationsParser {
if prefix.isEmpty {
shouldUsePositionBeforeTrailing = true
(prefix, sourceLine) = findPrefix(positionBeforeTrailingTrivia, shouldUsePositionBeforeTrailing)
if shouldUsePositionBeforeTrailing {
if shouldUsePositionBeforeTrailing && !prefix.isEmpty {
position = positionBeforeTrailingTrivia
} else {
shouldUsePositionBeforeTrailing = false
}
}
guard !prefix.isEmpty else { return ([:], shouldUsePositionBeforeTrailing) }
Expand Down
14 changes: 14 additions & 0 deletions SourceryTests/Parsing/FileParser_MethodsSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,20 @@ class FileParserMethodsSpec: QuickSpec {
]))
}

it("extracts method annotations from initializers") {
expect(parse("""
class Foo {
// sourcery: annotation
init() {
}
}
""")).to(equal([
Class(name: "Foo", methods: [
Method(name: "init()", selectorName: "init", returnTypeName: TypeName(name: "Foo"), isStatic: true, annotations: ["annotation": NSNumber(value: true)], definedInTypeName: TypeName(name: "Foo"))
])
]))
}

it("extracts method inline annotations") {
expect(parse("class Foo {\n /* sourcery: annotation */func foo() {} }")).to(equal([
Class(name: "Foo", methods: [
Expand Down

0 comments on commit 2f9cf2c

Please sign in to comment.