Skip to content
Open
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
12 changes: 12 additions & 0 deletions Generator/Sources/NeedleFramework/Parsing/BaseVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ class BaseVisitor: SyntaxVisitor {
info("\(currentEntityName) (\(propertyName): \(propertyType)) property is private/fileprivate, therefore inaccessible on DI graph.")
return nil
} else {
// See if this property has a code block associated with it (this skips the protocol memebers)
if let block = pattern.children.first(where: { $0.is(CodeBlockSyntax.self) }), let fullBody = block.as(CodeBlockSyntax.self) {
// Make sure that the code block is a one-liner
if let statement = fullBody.statements.first, fullBody.statements.count == 1 {
let trimmed = statement.description.trimmingCharacters(in: .whitespacesAndNewlines)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a trimmed convenience method for this. You can do .description.trimmed directly

let lookFor1 = "return dependency.\(propertyName)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trimmed will never be equal to lookFor1.

let lookFor2 = "dependency.\(propertyName)"
if trimmed == lookFor1 || trimmed == lookFor2 {
return nil
}
}
}
return Property(name: propertyName, type: propertyType)
}
}
Expand Down