[
  {
    "path": ".codecov.yml",
    "content": "comment: off\ncoverage:\n  status:\n    project:\n      default:\n        target: 0\n        threshold: null\n        base: auto\n    patch:\n      default:\n        target: 0\n        threshold: null\n        base: auto\n"
  },
  {
    "path": ".contributebot",
    "content": "{\n  \"issue_title_pattern\": \"^.*$\",\n  \"pull_request_title_response\": \"Please edit the title of this pull request with the name of the affected component, or \\\"all\\\", followed by a colon, followed by a short summary of the change.\"\n}\n"
  },
  {
    "path": ".gitattributes",
    "content": "* text eol=lf\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.md",
    "content": "---\nname: Bug report\nabout: Create a report to help us improve Wire\n\n---\n\nYou can use `go bug` to have a cool, automatically filled out bug template, or\nfill out the template below.\n\n### Describe the bug\n\nA clear and concise description of what the bug is.\n\n### To Reproduce\n\nSteps to reproduce the behavior.\n\n## Expected behavior\n\nA clear and concise description of what you expected to happen.\n\n### Version\n\nWhich version of Wire are you seeing the bug with?\n\n### Additional context\n\nAdd any other context about the problem here.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "content": "---\nname: Feature request\nabout: Suggest an idea for this project\n\n---\n\n### Is your feature request related to a problem? Please describe.\n\nA clear and concise description of what the problem is. Ex. I'm always\nfrustrated when [...]\n\n### Describe the solution you'd like\n\nA clear and concise description of what you want to happen.\n\n### Describe alternatives you've considered\n\nA clear and concise description of any alternative solutions or features you've\nconsidered.\n\n### Additional context\n\nAdd any other context or screenshots about the feature request here.\n"
  },
  {
    "path": ".github/pull_request_template.md",
    "content": "Please reference any Issue related to this Pull Request. Example: `Fixes #1`.\n\nSee\n[here](https://blog.github.com/2015-01-21-how-to-write-the-perfect-pull-request/)\nfor tips on good Pull Request description.\n"
  },
  {
    "path": ".github/workflows/tests.yml",
    "content": "# Copyright 2021 The Wire Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nname: Wire Tests\non: [push, pull_request]\njobs:\n  build:\n    strategy:\n      matrix:\n        os: [ubuntu-latest, macos-latest, windows-latest]\n        go-version: [1.25.x]\n    runs-on: ${{ matrix.os }}\n    steps:\n      - name: Install Go\n        uses: actions/setup-go@v2\n        with:\n          go-version: ${{ matrix.go-version }}\n      - name: Checkout code\n        uses: actions/checkout@v2\n        with:\n          fetch-depth: 2  # required for codecov\n      - name: Run Tests\n        shell: bash\n        run: 'internal/runtests.sh'\n"
  },
  {
    "path": "AUTHORS",
    "content": "# This is the official list of Wire authors for copyright purposes.\n# This file is distinct from the CONTRIBUTORS files.\n# See the latter for an explanation.\n\n# Names should be added to this file as one of\n#     Organization's name\n#     Individual's name <submission email address>\n#     Individual's name <submission email address> <email2> <emailN>\n# See CONTRIBUTORS for the meaning of multiple email addresses.\n\n# Please keep the list sorted.\n\nGoogle LLC\nktr <ktr@syfm.me>\nKumbirai Tanekha <kumbirai.tanekha@gmail.com>\nOleg Kovalov <iamolegkovalov@gmail.com>\nYoichiro Shimizu <budougumi0617@gmail.com>\nZachary Romero <zacromero3@gmail.com>\n"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "content": "# Code of Conduct\n\nThis project is covered under the [Go Code of Conduct][]. In summary:\n\n-   Treat everyone with respect and kindness.\n-   Be thoughtful in how you communicate.\n-   Don’t be destructive or inflammatory.\n-   If you encounter an issue, please mail conduct@golang.org.\n\n[Go Code of Conduct]: https://golang.org/conduct\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# How to Contribute\n\nWe would love to accept your patches and contributions to this project. Here is\nhow you can help.\n\n## Filing issues\n\nFiling issues is an important way you can contribute to the Wire Project. We\nwant your feedback on things like bugs, desired API changes, or just anything\nthat isn't working for you.\n\n### Bugs\n\nIf your issue is a bug, open one\n[here](https://github.com/google/wire/issues/new). The easiest way to file an\nissue with all the right information is to run `go bug`. `go bug` will print out\na handy template of questions and system information that will help us get to\nthe root of the issue quicker.\n\n### Changes\n\nUnlike the core Go project, we do not have a formal proposal process for\nchanges. If you have a change you would like to see in Wire, please file an\nissue with the necessary details.\n\n### Triaging\n\nThe Go Cloud team triages issues at least every two weeks, but usually within\ntwo business days. Bugs or feature requests are either placed into a **Sprint**\nmilestone which means the issue is intended to be worked on. Issues that we\nwould like to address but do not have time for are placed into the [Unplanned][]\nmilestone.\n\n[Unplanned]: https://github.com/google/wire/milestone/1\n\n## Contributing Code\n\nWe love accepting contributions! If your change is minor, please feel free\nsubmit a [pull request](https://help.github.com/articles/about-pull-requests/).\nIf your change is larger, or adds a feature, please file an issue beforehand so\nthat we can discuss the change. You're welcome to file an implementation pull\nrequest immediately as well, although we generally lean towards discussing the\nchange and then reviewing the implementation separately.\n\n### Finding something to work on\n\nIf you want to write some code, but don't know where to start or what you might\nwant to do, take a look at our [Unplanned][] milestone. This is where you can\nfind issues we would like to address but can't currently find time for. See if\nany of the latest ones look interesting! If you need help before you can start\nwork, you can comment on the issue and we will try to help as best we can.\n\n### Contributor License Agreement\n\nContributions to this project can only be made by those who have signed Google's\nContributor License Agreement. You (or your employer) retain the copyright to\nyour contribution, this simply gives us permission to use and redistribute your\ncontributions as part of the project. Head over to\n<https://cla.developers.google.com/> to see your current agreements on file or\nto sign a new one.\n\nAs a personal contributor, you only need to sign the Google CLA once across all\nGoogle projects. If you've already signed the CLA, there is no need to do it\nagain. If you are submitting code on behalf of your employer, there's\n[a separate corporate CLA that your employer manages for you](https://opensource.google.com/docs/cla/#external-contributors).\n\n## Making a pull request\n\n*   Follow the normal\n    [pull request flow](https://help.github.com/articles/creating-a-pull-request/)\n*   Build your changes using Go 1.11 with Go modules enabled. Wire's continuous\n    integration uses Go modules in order to ensure\n    [reproducible builds](https://research.swtch.com/vgo-repro).\n*   Test your changes using `go test ./...`. Please add tests that show the\n    change does what it says it does, even if there wasn't a test in the first\n    place.\n*   Feel free to make as many commits as you want; we will squash them all into\n    a single commit before merging your change.\n*   Check the diffs, write a useful description (including something like\n    `Fixes #123` if it's fixing a bug) and send the PR out.\n*   Github will run tests against the PR. This should\n    happen within 10 minutes or so. If a test fails, go back to the coding stage\n    and try to fix the test and push the same branch again. You won't need to\n    make a new pull request, the changes will be rolled directly into the PR you\n    already opened. Wait for the tests again. There is no need to assign a reviewer\n    to the PR, the project team will assign someone for review during the\n    standard [triage](#triaging) process.\n\n## Code review\n\nAll submissions, including submissions by project members, require review. It is\nalmost never the case that a pull request is accepted without some changes\nrequested, so please do not be offended!\n\nWhen you have finished making requested changes to your pull request, please\nmake a comment containing \"PTAL\" (Please Take Another Look) on your pull\nrequest. GitHub notifications can be noisy, and it is unfortunately easy for\nthings to be lost in the shuffle.\n\nOnce your PR is approved (hooray!) the reviewer will squash your commits into a\nsingle commit, and then merge the commit onto the Wire master branch. Thank you!\n\n## Github code review workflow conventions\n\n(For project members and frequent contributors.)\n\nAs a contributor:\n\n-   Try hard to make each Pull Request as small and focused as possible. In\n    particular, this means that if a reviewer asks you to do something that is\n    beyond the scope of the Pull Request, the best practice is to file another\n    issue and reference it from the Pull Request rather than just adding more\n    commits to the existing PR.\n-   Adding someone as a Reviewer means \"please feel free to look and comment\";\n    the review is optional. Choose as many Reviewers as you'd like.\n-   Adding someone as an Assignee means that the Pull Request should not be\n    submitted until they approve. If you choose multiple Assignees, wait until\n    all of them approve. It is fine to ask someone if they are OK with being\n    removed as an Assignee.\n    -   Note that if you don't select any assignees, ContributeBot will turn all\n        of your Reviewers into Assignees.\n-   Make as many commits as you want locally, but try not to push them to Github\n    until you've addressed comments; this allows the email notification about\n    the push to be a signal to reviewers that the PR is ready to be looked at\n    again.\n-   When there may be confusion about what should happen next for a PR, be\n    explicit; add a \"PTAL\" comment if it is ready for review again, or a \"Please\n    hold off on reviewing for now\" if you are still working on addressing\n    comments.\n-   \"Resolve\" comments that you are sure you've addressed; let your reviewers\n    resolve ones that you're not sure about.\n-   Do not use `git push --force`; this can cause comments from your reviewers\n    that are associated with a specific commit to be lost. This implies that\n    once you've sent a Pull Request, you should use `git merge` instead of `git\n    rebase` to incorporate commits from the master branch.\n\nAs a reviewer:\n\n-   Be timely in your review process, especially if you are an Assignee.\n-   Try to use `Start a Review` instead of single comments, to reduce email\n    spam.\n-   \"Resolve\" your own comments if they have been addressed.\n-   If you want your review to be blocking, and are not currently an Assignee,\n    add yourself as an Assignee.\n\nWhen squashing-and-merging:\n\n-   Ensure that **all** of the Assignees have approved.\n-   Do a final review of the one-line PR summary, ensuring that it accurately\n    describes the change.\n-   Delete the automatically added commit lines; these are generally not\n    interesting and make commit history harder to read.\n"
  },
  {
    "path": "CONTRIBUTORS",
    "content": "# This is the official list of people who can contribute\n# (and typically have contributed) code to the Wire repository.\n# The AUTHORS file lists the copyright holders; this file\n# lists people.  For example, Google employees are listed here\n# but not in AUTHORS, because Google holds the copyright.\n#\n# Names should be added to this file only after verifying that\n# the individual or the individual's organization has agreed to\n# the appropriate Contributor License Agreement, found here:\n#\n#     http://code.google.com/legal/individual-cla-v1.0.html\n#     http://code.google.com/legal/corporate-cla-v1.0.html\n#\n# The agreement for individuals can be filled out on the web.\n#\n# When adding J Random Contributor's name to this file,\n# either J's name or J's organization's name should be\n# added to the AUTHORS file, depending on whether the\n# individual or corporate CLA was used.\n\n# Names should be added to this file like so:\n#     Individual's name <submission email address>\n#     Individual's name <submission email address> <email2> <emailN>\n#\n# An entry with multiple email addresses specifies that the\n# first address should be used in the submit logs and\n# that the other addresses should be recognized as the\n# same person when interacting with Git.\n\n# Please keep the list sorted.\n\nChris Lewis <cflewis@google.com> <cflewis@golang.org> <c@chris.to>\nChristina Austin <4240737+clausti@users.noreply.github.com>\nEno Compton <enocom@google.com>\nIssac Trotts <issactrotts@google.com> <issac.trotts@gmail.com>\nktr <ktr@syfm.me>\nKumbirai Tanekha <kumbirai.tanekha@gmail.com>\nOleg Kovalov <iamolegkovalov@gmail.com>\nRobert van Gent <rvangent@google.com> <vangent@gmail.com>\nRoss Light <light@google.com> <ross@zombiezen.com>\nTuo Shan <shantuo@google.com> <sturbo89@gmail.com>\nYoichiro Shimizu <budougumi0617@gmail.com>\nZachary Romero <zacromero3@gmail.com>\n"
  },
  {
    "path": "LICENSE",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# Wire: Automated Initialization in Go\n\n[![Build Status](https://github.com/google/wire/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/google/wire/actions)\n[![godoc](https://godoc.org/github.com/google/wire?status.svg)][godoc]\n\n> [!WARNING]\n> This project is no longer maintained.\n>\n> If you wish to update or extend wire, please do so in a fork.\n\nWire is a code generation tool that automates connecting components using\n[dependency injection][]. Dependencies between components are represented in\nWire as function parameters, encouraging explicit initialization instead of\nglobal variables. Because Wire operates without runtime state or reflection,\ncode written to be used with Wire is useful even for hand-written\ninitialization.\n\nFor an overview, see the [introductory blog post][].\n\n[dependency injection]: https://en.wikipedia.org/wiki/Dependency_injection\n[introductory blog post]: https://blog.golang.org/wire\n[godoc]: https://godoc.org/github.com/google/wire\n[travis]: https://travis-ci.com/google/wire\n\n## Installing\n\nInstall Wire by running:\n\n```shell\ngo install github.com/google/wire/cmd/wire@latest\n```\n\nand ensuring that `$GOPATH/bin` is added to your `$PATH`.\n\n## Documentation\n\n- [Tutorial][]\n- [User Guide][]\n- [Best Practices][]\n- [FAQ][]\n\n[Tutorial]: ./_tutorial/README.md\n[Best Practices]: ./docs/best-practices.md\n[FAQ]: ./docs/faq.md\n[User Guide]: ./docs/guide.md\n\n## Project status\n\nAs of version v0.3.0, Wire is *beta* and is considered feature complete. It\nworks well for the tasks it was designed to perform, and we prefer to keep it\nas simple as possible.\n\nWe'll not be accepting new features at this time, but will gladly accept bug\nreports and fixes.\n\n## Community\n\nFor questions, please use [GitHub Discussions](https://github.com/google/wire/discussions).\n\nThis project is covered by the Go [Code of Conduct][].\n\n[Code of Conduct]: ./CODE_OF_CONDUCT.md\n[go-cloud mailing list]: https://groups.google.com/forum/#!forum/go-cloud\n"
  },
  {
    "path": "_tutorial/README.md",
    "content": "# Wire Tutorial\n\nLet's learn to use Wire by example. The [Wire guide][guide] provides thorough\ndocumentation of the tool's usage. For readers eager to see Wire applied to a\nlarger server, the [guestbook sample in Go Cloud][guestbook] uses Wire to\ninitialize its components. Here we are going to build a small greeter program to\nunderstand how to use Wire. The finished product may be found in the same\ndirectory as this README.\n\n[guestbook]: https://github.com/google/go-cloud/tree/master/samples/guestbook\n[guide]:     https://github.com/google/wire/blob/master/docs/guide.md\n\n## A First Pass of Building the Greeter Program\n\nLet's create a small program that simulates an event with a greeter greeting\nguests with a particular message.\n\nTo start, we will create three types: 1) a message for a greeter, 2) a greeter\nwho conveys that message, and 3) an event that starts with the greeter greeting\nguests. In this design, we have three `struct` types:\n\n``` go\ntype Message string\n\ntype Greeter struct {\n    // ... TBD\n}\n\ntype Event struct {\n    // ... TBD\n}\n```\n\nThe `Message` type just wraps a string. For now, we will create a simple\ninitializer that always returns a hard-coded message:\n\n``` go\nfunc NewMessage() Message {\n    return Message(\"Hi there!\")\n}\n```\n\nOur `Greeter` will need reference to the `Message`. So let's create an\ninitializer for our `Greeter` as well.\n\n``` go\nfunc NewGreeter(m Message) Greeter {\n    return Greeter{Message: m}\n}\n\ntype Greeter struct {\n    Message Message // <- adding a Message field\n}\n```\n\nIn the initializer we assign a `Message` field to `Greeter`. Now, we can use the\n`Message` when we create a `Greet` method on `Greeter`:\n\n``` go\nfunc (g Greeter) Greet() Message {\n    return g.Message\n}\n```\n\nNext, we need our `Event` to have a `Greeter`, so we will create an initializer\nfor it as well.\n\n``` go\nfunc NewEvent(g Greeter) Event {\n    return Event{Greeter: g}\n}\n\ntype Event struct {\n    Greeter Greeter // <- adding a Greeter field\n}\n```\n\nThen we add a method to start the `Event`:\n\n``` go\nfunc (e Event) Start() {\n    msg := e.Greeter.Greet()\n    fmt.Println(msg)\n}\n```\n\nThe `Start` method holds the core of our small application: it tells the\ngreeter to issue a greeting and then prints that message to the screen.\n\nNow that we have all the components of our application ready, let's see what it\ntakes to initialize all the components without using Wire. Our main function\nwould look like this:\n\n``` go\nfunc main() {\n    message := NewMessage()\n    greeter := NewGreeter(message)\n    event := NewEvent(greeter)\n\n    event.Start()\n}\n```\n\nFirst we create a message, then we create a greeter with that message, and\nfinally we create an event with that greeter. With all the initialization done,\nwe're ready to start our event.\n\nWe are using the [dependency injection][di] design principle. In practice, that\nmeans we pass in whatever each component needs. This style of design lends\nitself to writing easily tested code and makes it easy to swap out one\ndependency with another.\n\n[di]: https://stackoverflow.com/questions/130794/what-is-dependency-injection\n\n## Using Wire to Generate Code\n\nOne downside to dependency injection is the need for so many initialization\nsteps. Let's see how we can use Wire to make the process of initializing our\ncomponents smoother.\n\nLet's start by changing our `main` function to look like this:\n\n``` go\nfunc main() {\n    e := InitializeEvent()\n\n    e.Start()\n}\n```\n\nNext, in a separate file called `wire.go` we will define `InitializeEvent`.\nThis is where things get interesting:\n\n``` go\n// wire.go\n\nfunc InitializeEvent() Event {\n    wire.Build(NewEvent, NewGreeter, NewMessage)\n    return Event{}\n}\n```\n\nRather than go through the trouble of initializing each component in turn and\npassing it into the next one, we instead have a single call to `wire.Build`\npassing in the initializers we want to use. In Wire, initializers are known as\n\"providers,\" functions which provide a particular type. We add a zero value for\n`Event` as a return value to satisfy the compiler. Note that even if we add\nvalues to `Event`, Wire will ignore them. In fact, the injector's purpose is to\nprovide information about which providers to use to construct an `Event` and so\nwe will exclude it from our final binary with a build constraint at the top of\nthe file:\n\n``` go\n//+build wireinject\n\n```\n\nNote, a [build constraint][constraint] requires a blank, trailing line.\n\nIn Wire parlance, `InitializeEvent` is an \"injector.\" Now that we have our\ninjector complete, we are ready to use the `wire` command line tool.\n\nInstall the tool with:\n\n``` shell\ngo install github.com/google/wire/cmd/wire@latest\n```\n\nThen in the same directory with the above code, simply run `wire`. Wire will\nfind the `InitializeEvent` injector and generate a function whose body is\nfilled out with all the necessary initialization steps. The result will be\nwritten to a file named `wire_gen.go`.\n\nLet's take a look at what Wire did for us:\n\n``` go\n// wire_gen.go\n\nfunc InitializeEvent() Event {\n    message := NewMessage()\n    greeter := NewGreeter(message)\n    event := NewEvent(greeter)\n    return event\n}\n```\n\nIt looks just like what we wrote above! Now this is a simple example with just\nthree components, so writing the initializer by hand isn't too painful. Imagine\nhow useful Wire is for components that are much more complex. When working with\nWire, we will commit both `wire.go` and `wire_gen.go` to source control.\n\n[constraint]: https://godoc.org/go/build#hdr-Build_Constraints\n\n## Making Changes with Wire\n\nTo show a small part of how Wire handles more complex setups, let's refactor\nour initializer for `Event` to return an error and see what happens.\n\n``` go\nfunc NewEvent(g Greeter) (Event, error) {\n    if g.Grumpy {\n        return Event{}, errors.New(\"could not create event: event greeter is grumpy\")\n    }\n    return Event{Greeter: g}, nil\n}\n```\n\nWe'll say that sometimes a `Greeter` might be grumpy and so we cannot create\nan `Event`. The `NewGreeter` initializer now looks like this:\n\n``` go\nfunc NewGreeter(m Message) Greeter {\n    var grumpy bool\n    if time.Now().Unix()%2 == 0 {\n        grumpy = true\n    }\n    return Greeter{Message: m, Grumpy: grumpy}\n}\n```\n\nWe have added a `Grumpy` field to `Greeter` struct and if the invocation time\nof the initializer is an even number of seconds since the Unix epoch, we will\ncreate a grumpy greeter instead of a friendly one.\n\nThe `Greet` method then becomes:\n\n``` go\nfunc (g Greeter) Greet() Message {\n    if g.Grumpy {\n        return Message(\"Go away!\")\n    }\n    return g.Message\n}\n```\n\nNow you see how a grumpy `Greeter` is no good for an `Event`. So `NewEvent` may\nfail. Our `main` must now take into account that `InitializeEvent` may in fact\nfail:\n\n``` go\nfunc main() {\n    e, err := InitializeEvent()\n    if err != nil {\n        fmt.Printf(\"failed to create event: %s\\n\", err)\n        os.Exit(2)\n    }\n    e.Start()\n}\n```\n\nWe also need to update `InitializeEvent` to add an `error` type to the return value:\n\n``` go\n// wire.go\n\nfunc InitializeEvent() (Event, error) {\n    wire.Build(NewEvent, NewGreeter, NewMessage)\n    return Event{}, nil\n}\n```\n\nWith the setup complete, we are ready to invoke the `wire` command again. Note,\nthat after running `wire` once to produce a `wire_gen.go` file, we may also use\n`go generate`. Having run the command, our `wire_gen.go` file looks like\nthis:\n\n``` go\n// wire_gen.go\n\nfunc InitializeEvent() (Event, error) {\n    message := NewMessage()\n    greeter := NewGreeter(message)\n    event, err := NewEvent(greeter)\n    if err != nil {\n        return Event{}, err\n    }\n    return event, nil\n}\n```\n\nWire has detected that the `NewEvent` provider may fail and has done the right\nthing inside the generated code: it checks the error and returns early if one\nis present.\n\n## Changing the Injector Signature\n\nAs another improvement, let's look at how Wire generates code based on the\nsignature of the injector. Presently, we have hard-coded the message inside\n`NewMessage`. In practice, it's much nicer to allow callers to change that\nmessage however they see fit. So let's change `InitializeEvent` to look like\nthis:\n\n``` go\nfunc InitializeEvent(phrase string) (Event, error) {\n    wire.Build(NewEvent, NewGreeter, NewMessage)\n    return Event{}, nil\n}\n```\n\nNow `InitializeEvent` allows callers to pass in the `phrase` for a `Greeter` to\nuse. We also add a `phrase` argument to `NewMessage`:\n\n``` go\nfunc NewMessage(phrase string) Message {\n    return Message(phrase)\n}\n```\n\nAfter we run `wire` again, we will see that the tool has generated an\ninitializer which passes the `phrase` value as a `Message` into `Greeter`.\nNeat!\n\n``` go\n// wire_gen.go\n\nfunc InitializeEvent(phrase string) (Event, error) {\n    message := NewMessage(phrase)\n    greeter := NewGreeter(message)\n    event, err := NewEvent(greeter)\n    if err != nil {\n        return Event{}, err\n    }\n    return event, nil\n}\n```\n\nWire inspects the arguments to the injector, sees that we added a string to the\nlist of arguments (e.g., `phrase`), and likewise sees that among all the\nproviders, `NewMessage` takes a string, and so it passes `phrase` into\n`NewMessage`.\n\n## Catching Mistakes with Helpful Errors\n\nLet's also look at what happens when Wire detects mistakes in our code and see\nhow Wire's error messages help us correct any problems.\n\nFor example, when writing our injector `InitializeEvent`, let's say we forget\nto add a provider for `Greeter`. Let's see what happens:\n\n``` go\nfunc InitializeEvent(phrase string) (Event, error) {\n    wire.Build(NewEvent, NewMessage) // woops! We forgot to add a provider for Greeter\n    return Event{}, nil\n}\n```\n\nRunning `wire`, we see the following:\n\n``` shell\n# wrapping the error across lines for readability\n$GOPATH/src/github.com/google/wire/_tutorial/wire.go:24:1:\ninject InitializeEvent: no provider found for github.com/google/wire/_tutorial.Greeter\n(required by provider of github.com/google/wire/_tutorial.Event)\nwire: generate failed\n```\n\nWire is telling us some useful information: it cannot find a provider for\n`Greeter`. Note that the error message prints out the full path to the\n`Greeter` type. It's also telling us the line number and injector name where\nthe problem occurred: line 24 inside `InitializeEvent`. In addition, the error\nmessage tells us which provider needs a `Greeter`. It's the `Event` type. Once\nwe pass in a provider of `Greeter`, the problem will be solved.\n\nAlternatively, what happens if we provide one too many providers to `wire.Build`?\n\n``` go\nfunc NewEventNumber() int  {\n    return 1\n}\n\nfunc InitializeEvent(phrase string) (Event, error) {\n     // woops! NewEventNumber is unused.\n    wire.Build(NewEvent, NewGreeter, NewMessage, NewEventNumber)\n    return Event{}, nil\n}\n```\n\nWire helpfully tells us that we have an unused provider:\n\n``` shell\n$GOPATH/src/github.com/google/wire/_tutorial/wire.go:24:1:\ninject InitializeEvent: unused provider \"NewEventNumber\"\nwire: generate failed\n```\n\nDeleting the unused provider from the call to `wire.Build` resolves the error.\n\n## Conclusion\n\nLet's summarize what we have done here. First, we wrote a number of components\nwith corresponding initializers, or providers. Next, we created an injector\nfunction, specifying which arguments it receives and which types it returns.\nThen, we filled in the injector function with a call to `wire.Build` supplying\nall necessary providers. Finally, we ran the `wire` command to generate code\nthat wires up all the different initializers. When we added an argument to the\ninjector and an error return value, running `wire` again made all the necessary\nupdates to our generated code.\n\nThe example here is small, but it demonstrates some of the power of Wire, and\nhow it takes much of the pain out of initializing code using dependency\ninjection. Furthermore, using Wire produced code that looks much like what we\nwould otherwise write. There are no bespoke types that commit a user to Wire.\nInstead it's just generated code. We may do with it what we will. Finally,\nanother point worth considering is how easy it is to add new dependencies to\nour component initialization. As long as we tell Wire how to provide (i.e.,\ninitialize) a component, we may add that component anywhere in the dependency\ngraph and Wire will handle the rest.\n\nIn closing, it is worth mentioning that Wire supports a number of additional\nfeatures not discussed here. Providers may be grouped in [provider sets][sets].\nThere is support for [binding interfaces][interfaces], [binding\nvalues][values], as well as support for [cleanup functions][cleanup]. See the\n[Advanced Features][advanced] section for more.\n\n[advanced]:   https://github.com/google/wire/blob/master/docs/guide.md#advanced-features\n[cleanup]:    https://github.com/google/wire/blob/master/docs/guide.md#cleanup-functions\n[interfaces]: https://github.com/google/wire/blob/master/docs/guide.md#binding-interfaces\n[sets]:       https://github.com/google/wire/blob/master/docs/guide.md#defining-providers\n[values]:     https://github.com/google/wire/blob/master/docs/guide.md#binding-values\n"
  },
  {
    "path": "_tutorial/main.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// The greeter binary simulates an event with greeters greeting guests.\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\t\"time\"\n)\n\n// Message is what greeters will use to greet guests.\ntype Message string\n\n// NewMessage creates a default Message.\nfunc NewMessage(phrase string) Message {\n\treturn Message(phrase)\n}\n\n// NewGreeter initializes a Greeter. If the current epoch time is an even\n// number, NewGreeter will create a grumpy Greeter.\nfunc NewGreeter(m Message) Greeter {\n\tvar grumpy bool\n\tif time.Now().Unix()%2 == 0 {\n\t\tgrumpy = true\n\t}\n\treturn Greeter{Message: m, Grumpy: grumpy}\n}\n\n// Greeter is the type charged with greeting guests.\ntype Greeter struct {\n\tGrumpy  bool\n\tMessage Message\n}\n\n// Greet produces a greeting for guests.\nfunc (g Greeter) Greet() Message {\n\tif g.Grumpy {\n\t\treturn Message(\"Go away!\")\n\t}\n\treturn g.Message\n}\n\n// NewEvent creates an event with the specified greeter.\nfunc NewEvent(g Greeter) (Event, error) {\n\tif g.Grumpy {\n\t\treturn Event{}, errors.New(\"could not create event: event greeter is grumpy\")\n\t}\n\treturn Event{Greeter: g}, nil\n}\n\n// Event is a gathering with greeters.\ntype Event struct {\n\tGreeter Greeter\n}\n\n// Start ensures the event starts with greeting all guests.\nfunc (e Event) Start() {\n\tmsg := e.Greeter.Greet()\n\tfmt.Println(msg)\n}\n\nfunc main() {\n\te, err := InitializeEvent(\"hi there!\")\n\tif err != nil {\n\t\tfmt.Printf(\"failed to create event: %s\\n\", err)\n\t\tos.Exit(2)\n\t}\n\te.Start()\n}\n"
  },
  {
    "path": "_tutorial/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//go:build wireinject\n// +build wireinject\n\n// The build tag makes sure the stub is not built in the final build.\npackage main\n\nimport \"github.com/google/wire\"\n\n// InitializeEvent creates an Event. It will error if the Event is staffed with\n// a grumpy greeter.\nfunc InitializeEvent(phrase string) (Event, error) {\n\twire.Build(NewEvent, NewGreeter, NewMessage)\n\treturn Event{}, nil\n}\n"
  },
  {
    "path": "_tutorial/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc InitializeEvent(phrase string) (Event, error) {\n\tmessage := NewMessage(phrase)\n\tgreeter := NewGreeter(message)\n\tevent, err := NewEvent(greeter)\n\tif err != nil {\n\t\treturn Event{}, err\n\t}\n\treturn event, nil\n}\n"
  },
  {
    "path": "cmd/wire/main.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Wire is a compile-time dependency injection tool.\n//\n// For an overview, see https://github.com/google/wire/blob/master/README.md\npackage main\n\nimport (\n\t\"context\"\n\t\"flag\"\n\t\"fmt\"\n\t\"go/token\"\n\t\"go/types\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"os\"\n\t\"reflect\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"github.com/google/subcommands\"\n\t\"github.com/google/wire/internal/wire\"\n\t\"github.com/pmezard/go-difflib/difflib\"\n\t\"golang.org/x/tools/go/types/typeutil\"\n)\n\nfunc main() {\n\tsubcommands.Register(subcommands.CommandsCommand(), \"\")\n\tsubcommands.Register(subcommands.FlagsCommand(), \"\")\n\tsubcommands.Register(subcommands.HelpCommand(), \"\")\n\tsubcommands.Register(&checkCmd{}, \"\")\n\tsubcommands.Register(&diffCmd{}, \"\")\n\tsubcommands.Register(&genCmd{}, \"\")\n\tsubcommands.Register(&showCmd{}, \"\")\n\tflag.Parse()\n\n\t// Initialize the default logger to log to stderr.\n\tlog.SetFlags(0)\n\tlog.SetPrefix(\"wire: \")\n\tlog.SetOutput(os.Stderr)\n\n\t// TODO(rvangent): Use subcommands's VisitCommands instead of hardcoded map,\n\t// once there is a release that contains it:\n\t// allCmds := map[string]bool{}\n\t// subcommands.DefaultCommander.VisitCommands(func(_ *subcommands.CommandGroup, cmd subcommands.Command) { allCmds[cmd.Name()] = true })\n\tallCmds := map[string]bool{\n\t\t\"commands\": true, // builtin\n\t\t\"help\":     true, // builtin\n\t\t\"flags\":    true, // builtin\n\t\t\"check\":    true,\n\t\t\"diff\":     true,\n\t\t\"gen\":      true,\n\t\t\"show\":     true,\n\t}\n\t// Default to running the \"gen\" command.\n\tif args := flag.Args(); len(args) == 0 || !allCmds[args[0]] {\n\t\tgenCmd := &genCmd{}\n\t\tos.Exit(int(genCmd.Execute(context.Background(), flag.CommandLine)))\n\t}\n\tos.Exit(int(subcommands.Execute(context.Background())))\n}\n\n// packages returns the slice of packages to run wire over based on f.\n// It defaults to \".\".\nfunc packages(f *flag.FlagSet) []string {\n\tpkgs := f.Args()\n\tif len(pkgs) == 0 {\n\t\tpkgs = []string{\".\"}\n\t}\n\treturn pkgs\n}\n\n// newGenerateOptions returns an initialized wire.GenerateOptions, possibly\n// with the Header option set.\nfunc newGenerateOptions(headerFile string) (*wire.GenerateOptions, error) {\n\topts := new(wire.GenerateOptions)\n\tif headerFile != \"\" {\n\t\tvar err error\n\t\topts.Header, err = ioutil.ReadFile(headerFile)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to read header file %q: %v\", headerFile, err)\n\t\t}\n\t}\n\treturn opts, nil\n}\n\ntype genCmd struct {\n\theaderFile     string\n\tprefixFileName string\n\ttags           string\n}\n\nfunc (*genCmd) Name() string { return \"gen\" }\nfunc (*genCmd) Synopsis() string {\n\treturn \"generate the wire_gen.go file for each package\"\n}\nfunc (*genCmd) Usage() string {\n\treturn `gen [packages]\n\n  Given one or more packages, gen creates the wire_gen.go file for each.\n\n  If no packages are listed, it defaults to \".\".\n`\n}\nfunc (cmd *genCmd) SetFlags(f *flag.FlagSet) {\n\tf.StringVar(&cmd.headerFile, \"header_file\", \"\", \"path to file to insert as a header in wire_gen.go\")\n\tf.StringVar(&cmd.prefixFileName, \"output_file_prefix\", \"\", \"string to prepend to output file names.\")\n\tf.StringVar(&cmd.tags, \"tags\", \"\", \"append build tags to the default wirebuild\")\n}\n\nfunc (cmd *genCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {\n\twd, err := os.Getwd()\n\tif err != nil {\n\t\tlog.Println(\"failed to get working directory: \", err)\n\t\treturn subcommands.ExitFailure\n\t}\n\topts, err := newGenerateOptions(cmd.headerFile)\n\tif err != nil {\n\t\tlog.Println(err)\n\t\treturn subcommands.ExitFailure\n\t}\n\n\topts.PrefixOutputFile = cmd.prefixFileName\n\topts.Tags = cmd.tags\n\n\touts, errs := wire.Generate(ctx, wd, os.Environ(), packages(f), opts)\n\tif len(errs) > 0 {\n\t\tlogErrors(errs)\n\t\tlog.Println(\"generate failed\")\n\t\treturn subcommands.ExitFailure\n\t}\n\tif len(outs) == 0 {\n\t\treturn subcommands.ExitSuccess\n\t}\n\tsuccess := true\n\tfor _, out := range outs {\n\t\tif len(out.Errs) > 0 {\n\t\t\tlogErrors(out.Errs)\n\t\t\tlog.Printf(\"%s: generate failed\\n\", out.PkgPath)\n\t\t\tsuccess = false\n\t\t}\n\t\tif len(out.Content) == 0 {\n\t\t\t// No Wire output. Maybe errors, maybe no Wire directives.\n\t\t\tcontinue\n\t\t}\n\t\tif err := out.Commit(); err == nil {\n\t\t\tlog.Printf(\"%s: wrote %s\\n\", out.PkgPath, out.OutputPath)\n\t\t} else {\n\t\t\tlog.Printf(\"%s: failed to write %s: %v\\n\", out.PkgPath, out.OutputPath, err)\n\t\t\tsuccess = false\n\t\t}\n\t}\n\tif !success {\n\t\tlog.Println(\"at least one generate failure\")\n\t\treturn subcommands.ExitFailure\n\t}\n\treturn subcommands.ExitSuccess\n}\n\ntype diffCmd struct {\n\theaderFile string\n\ttags       string\n}\n\nfunc (*diffCmd) Name() string { return \"diff\" }\nfunc (*diffCmd) Synopsis() string {\n\treturn \"output a diff between existing wire_gen.go files and what gen would generate\"\n}\nfunc (*diffCmd) Usage() string {\n\treturn `diff [packages]\n\n  Given one or more packages, diff generates the content for their wire_gen.go\n  files and outputs the diff against the existing files.\n\n  If no packages are listed, it defaults to \".\".\n\n  Similar to the diff command, it returns 0 if no diff, 1 if different, 2\n  plus an error if trouble.\n`\n}\nfunc (cmd *diffCmd) SetFlags(f *flag.FlagSet) {\n\tf.StringVar(&cmd.headerFile, \"header_file\", \"\", \"path to file to insert as a header in wire_gen.go\")\n\tf.StringVar(&cmd.tags, \"tags\", \"\", \"append build tags to the default wirebuild\")\n}\nfunc (cmd *diffCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {\n\tconst (\n\t\terrReturn  = subcommands.ExitStatus(2)\n\t\tdiffReturn = subcommands.ExitStatus(1)\n\t)\n\twd, err := os.Getwd()\n\tif err != nil {\n\t\tlog.Println(\"failed to get working directory: \", err)\n\t\treturn errReturn\n\t}\n\topts, err := newGenerateOptions(cmd.headerFile)\n\tif err != nil {\n\t\tlog.Println(err)\n\t\treturn subcommands.ExitFailure\n\t}\n\n\topts.Tags = cmd.tags\n\n\touts, errs := wire.Generate(ctx, wd, os.Environ(), packages(f), opts)\n\tif len(errs) > 0 {\n\t\tlogErrors(errs)\n\t\tlog.Println(\"generate failed\")\n\t\treturn errReturn\n\t}\n\tif len(outs) == 0 {\n\t\treturn subcommands.ExitSuccess\n\t}\n\tsuccess := true\n\thadDiff := false\n\tfor _, out := range outs {\n\t\tif len(out.Errs) > 0 {\n\t\t\tlogErrors(out.Errs)\n\t\t\tlog.Printf(\"%s: generate failed\\n\", out.PkgPath)\n\t\t\tsuccess = false\n\t\t}\n\t\tif len(out.Content) == 0 {\n\t\t\t// No Wire output. Maybe errors, maybe no Wire directives.\n\t\t\tcontinue\n\t\t}\n\t\t// Assumes the current file is empty if we can't read it.\n\t\tcur, _ := ioutil.ReadFile(out.OutputPath)\n\t\tif diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{\n\t\t\tA: difflib.SplitLines(string(cur)),\n\t\t\tB: difflib.SplitLines(string(out.Content)),\n\t\t}); err == nil {\n\t\t\tif diff != \"\" {\n\t\t\t\t// Print the actual diff to stdout, not stderr.\n\t\t\t\tfmt.Printf(\"%s: diff from %s:\\n%s\\n\", out.PkgPath, out.OutputPath, diff)\n\t\t\t\thadDiff = true\n\t\t\t}\n\t\t} else {\n\t\t\tlog.Printf(\"%s: failed to diff %s: %v\\n\", out.PkgPath, out.OutputPath, err)\n\t\t\tsuccess = false\n\t\t}\n\t}\n\tif !success {\n\t\tlog.Println(\"at least one generate failure\")\n\t\treturn errReturn\n\t}\n\tif hadDiff {\n\t\treturn diffReturn\n\t}\n\treturn subcommands.ExitSuccess\n}\n\ntype showCmd struct {\n\ttags string\n}\n\nfunc (*showCmd) Name() string { return \"show\" }\nfunc (*showCmd) Synopsis() string {\n\treturn \"describe all top-level provider sets\"\n}\nfunc (*showCmd) Usage() string {\n\treturn `show [packages]\n\n  Given one or more packages, show finds all the provider sets declared as\n  top-level variables and prints what other provider sets they import and what\n  outputs they can produce, given possible inputs. It also lists any injector\n  functions defined in the package.\n\n  If no packages are listed, it defaults to \".\".\n`\n}\nfunc (cmd *showCmd) SetFlags(f *flag.FlagSet) {\n\tf.StringVar(&cmd.tags, \"tags\", \"\", \"append build tags to the default wirebuild\")\n}\nfunc (cmd *showCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {\n\twd, err := os.Getwd()\n\tif err != nil {\n\t\tlog.Println(\"failed to get working directory: \", err)\n\t\treturn subcommands.ExitFailure\n\t}\n\tinfo, errs := wire.Load(ctx, wd, os.Environ(), cmd.tags, packages(f))\n\tif info != nil {\n\t\tkeys := make([]wire.ProviderSetID, 0, len(info.Sets))\n\t\tfor k := range info.Sets {\n\t\t\tkeys = append(keys, k)\n\t\t}\n\t\tsort.Slice(keys, func(i, j int) bool {\n\t\t\tif keys[i].ImportPath == keys[j].ImportPath {\n\t\t\t\treturn keys[i].VarName < keys[j].VarName\n\t\t\t}\n\t\t\treturn keys[i].ImportPath < keys[j].ImportPath\n\t\t})\n\t\tfor i, k := range keys {\n\t\t\tif i > 0 {\n\t\t\t\tfmt.Println()\n\t\t\t}\n\t\t\toutGroups, imports := gather(info, k)\n\t\t\tfmt.Println(k)\n\t\t\tfor _, imp := range sortSet(imports) {\n\t\t\t\tfmt.Printf(\"\\t%s\\n\", imp)\n\t\t\t}\n\t\t\tfor i := range outGroups {\n\t\t\t\tfmt.Printf(\"\\tOutputs given %s:\\n\", outGroups[i].name)\n\t\t\t\tout := make(map[string]token.Pos, outGroups[i].outputs.Len())\n\t\t\t\toutGroups[i].outputs.Iterate(func(t types.Type, v interface{}) {\n\t\t\t\t\tswitch v := v.(type) {\n\t\t\t\t\tcase *wire.Provider:\n\t\t\t\t\t\tout[types.TypeString(t, nil)] = v.Pos\n\t\t\t\t\tcase *wire.Value:\n\t\t\t\t\t\tout[types.TypeString(t, nil)] = v.Pos\n\t\t\t\t\tcase *wire.Field:\n\t\t\t\t\t\tout[types.TypeString(t, nil)] = v.Pos\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tpanic(\"unreachable\")\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\tfor _, t := range sortSet(out) {\n\t\t\t\t\tfmt.Printf(\"\\t\\t%s\\n\", t)\n\t\t\t\t\tfmt.Printf(\"\\t\\t\\tat %v\\n\", info.Fset.Position(out[t]))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif len(info.Injectors) > 0 {\n\t\t\tinjectors := append([]*wire.Injector(nil), info.Injectors...)\n\t\t\tsort.Slice(injectors, func(i, j int) bool {\n\t\t\t\tif injectors[i].ImportPath == injectors[j].ImportPath {\n\t\t\t\t\treturn injectors[i].FuncName < injectors[j].FuncName\n\t\t\t\t}\n\t\t\t\treturn injectors[i].ImportPath < injectors[j].ImportPath\n\t\t\t})\n\t\t\tfmt.Println(\"\\nInjectors:\")\n\t\t\tfor _, in := range injectors {\n\t\t\t\tfmt.Printf(\"\\t%v\\n\", in)\n\t\t\t}\n\t\t}\n\t}\n\tif len(errs) > 0 {\n\t\tlogErrors(errs)\n\t\tlog.Println(\"error loading packages\")\n\t\treturn subcommands.ExitFailure\n\t}\n\treturn subcommands.ExitSuccess\n}\n\ntype checkCmd struct {\n\ttags string\n}\n\nfunc (*checkCmd) Name() string { return \"check\" }\nfunc (*checkCmd) Synopsis() string {\n\treturn \"print any Wire errors found\"\n}\nfunc (*checkCmd) Usage() string {\n\treturn `check [-tags tag,list] [packages]\n\n  Given one or more packages, check prints any type-checking or Wire errors\n  found with top-level variable provider sets or injector functions.\n\n  If no packages are listed, it defaults to \".\".\n`\n}\nfunc (cmd *checkCmd) SetFlags(f *flag.FlagSet) {\n\tf.StringVar(&cmd.tags, \"tags\", \"\", \"append build tags to the default wirebuild\")\n}\nfunc (cmd *checkCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {\n\twd, err := os.Getwd()\n\tif err != nil {\n\t\tlog.Println(\"failed to get working directory: \", err)\n\t\treturn subcommands.ExitFailure\n\t}\n\t_, errs := wire.Load(ctx, wd, os.Environ(), cmd.tags, packages(f))\n\tif len(errs) > 0 {\n\t\tlogErrors(errs)\n\t\tlog.Println(\"error loading packages\")\n\t\treturn subcommands.ExitFailure\n\t}\n\treturn subcommands.ExitSuccess\n}\n\ntype outGroup struct {\n\tname    string\n\tinputs  *typeutil.Map // values are not important\n\toutputs *typeutil.Map // values are *wire.Provider, *wire.Value, or *wire.Field\n}\n\n// gather flattens a provider set into outputs grouped by the inputs\n// required to create them. As it flattens the provider set, it records\n// the visited named provider sets as imports.\nfunc gather(info *wire.Info, key wire.ProviderSetID) (_ []outGroup, imports map[string]struct{}) {\n\tset := info.Sets[key]\n\thash := typeutil.MakeHasher()\n\n\t// Find imports.\n\tnext := []*wire.ProviderSet{info.Sets[key]}\n\tvisited := make(map[*wire.ProviderSet]struct{})\n\timports = make(map[string]struct{})\n\tfor len(next) > 0 {\n\t\tcurr := next[len(next)-1]\n\t\tnext = next[:len(next)-1]\n\t\tif _, found := visited[curr]; found {\n\t\t\tcontinue\n\t\t}\n\t\tvisited[curr] = struct{}{}\n\t\tif curr.VarName != \"\" && !(curr.PkgPath == key.ImportPath && curr.VarName == key.VarName) {\n\t\t\timports[formatProviderSetName(curr.PkgPath, curr.VarName)] = struct{}{}\n\t\t}\n\t\tnext = append(next, curr.Imports...)\n\t}\n\n\t// Depth-first search to build groups.\n\tvar groups []outGroup\n\tinputVisited := new(typeutil.Map) // values are int, indices into groups or -1 for input.\n\tinputVisited.SetHasher(hash)\n\tvar stk []types.Type\n\tfor _, k := range set.Outputs() {\n\t\t// Start a DFS by picking a random unvisited node.\n\t\tif inputVisited.At(k) == nil {\n\t\t\tstk = append(stk, k)\n\t\t}\n\n\t\t// Run DFS\n\tdfs:\n\t\tfor len(stk) > 0 {\n\t\t\tcurr := stk[len(stk)-1]\n\t\t\tstk = stk[:len(stk)-1]\n\t\t\tif inputVisited.At(curr) != nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tswitch pv := set.For(curr); {\n\t\t\tcase pv.IsNil():\n\t\t\t\t// This is an input.\n\t\t\t\tinputVisited.Set(curr, -1)\n\t\t\tcase pv.IsArg():\n\t\t\t\t// This is an injector argument.\n\t\t\t\tinputVisited.Set(curr, -1)\n\t\t\tcase pv.IsProvider():\n\t\t\t\t// Try to see if any args haven't been visited.\n\t\t\t\tp := pv.Provider()\n\t\t\t\tallPresent := true\n\t\t\t\tfor _, arg := range p.Args {\n\t\t\t\t\tif inputVisited.At(arg.Type) == nil {\n\t\t\t\t\t\tallPresent = false\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif !allPresent {\n\t\t\t\t\tstk = append(stk, curr)\n\t\t\t\t\tfor _, arg := range p.Args {\n\t\t\t\t\t\tif inputVisited.At(arg.Type) == nil {\n\t\t\t\t\t\t\tstk = append(stk, arg.Type)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcontinue dfs\n\t\t\t\t}\n\n\t\t\t\t// Build up set of input types, match to a group.\n\t\t\t\tin := new(typeutil.Map)\n\t\t\t\tin.SetHasher(hash)\n\t\t\t\tfor _, arg := range p.Args {\n\t\t\t\t\ti := inputVisited.At(arg.Type).(int)\n\t\t\t\t\tif i == -1 {\n\t\t\t\t\t\tin.Set(arg.Type, true)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tmergeTypeSets(in, groups[i].inputs)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor i := range groups {\n\t\t\t\t\tif sameTypeKeys(groups[i].inputs, in) {\n\t\t\t\t\t\tgroups[i].outputs.Set(curr, p)\n\t\t\t\t\t\tinputVisited.Set(curr, i)\n\t\t\t\t\t\tcontinue dfs\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tout := new(typeutil.Map)\n\t\t\t\tout.SetHasher(hash)\n\t\t\t\tout.Set(curr, p)\n\t\t\t\tinputVisited.Set(curr, len(groups))\n\t\t\t\tgroups = append(groups, outGroup{\n\t\t\t\t\tinputs:  in,\n\t\t\t\t\toutputs: out,\n\t\t\t\t})\n\t\t\tcase pv.IsValue():\n\t\t\t\tv := pv.Value()\n\t\t\t\tfor i := range groups {\n\t\t\t\t\tif groups[i].inputs.Len() == 0 {\n\t\t\t\t\t\tgroups[i].outputs.Set(curr, v)\n\t\t\t\t\t\tinputVisited.Set(curr, i)\n\t\t\t\t\t\tcontinue dfs\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tin := new(typeutil.Map)\n\t\t\t\tin.SetHasher(hash)\n\t\t\t\tout := new(typeutil.Map)\n\t\t\t\tout.SetHasher(hash)\n\t\t\t\tout.Set(curr, v)\n\t\t\t\tinputVisited.Set(curr, len(groups))\n\t\t\t\tgroups = append(groups, outGroup{\n\t\t\t\t\tinputs:  in,\n\t\t\t\t\toutputs: out,\n\t\t\t\t})\n\t\t\tcase pv.IsField():\n\t\t\t\t// Try to see if the parent struct hasn't been visited.\n\t\t\t\tf := pv.Field()\n\t\t\t\tif inputVisited.At(f.Parent) == nil {\n\t\t\t\t\tstk = append(stk, curr, f.Parent)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t// Build the input map for the parent struct.\n\t\t\t\tin := new(typeutil.Map)\n\t\t\t\tin.SetHasher(hash)\n\t\t\t\ti := inputVisited.At(f.Parent).(int)\n\t\t\t\tif i == -1 {\n\t\t\t\t\tin.Set(f.Parent, true)\n\t\t\t\t} else {\n\t\t\t\t\tmergeTypeSets(in, groups[i].inputs)\n\t\t\t\t}\n\t\t\t\t// Group all fields together under the same parent struct.\n\t\t\t\tfor i := range groups {\n\t\t\t\t\tif sameTypeKeys(groups[i].inputs, in) {\n\t\t\t\t\t\tgroups[i].outputs.Set(curr, f)\n\t\t\t\t\t\tinputVisited.Set(curr, i)\n\t\t\t\t\t\tcontinue dfs\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tout := new(typeutil.Map)\n\t\t\t\tout.SetHasher(hash)\n\t\t\t\tout.Set(curr, f)\n\t\t\t\tinputVisited.Set(curr, len(groups))\n\t\t\t\tgroups = append(groups, outGroup{\n\t\t\t\t\tinputs:  in,\n\t\t\t\t\toutputs: out,\n\t\t\t\t})\n\t\t\tdefault:\n\t\t\t\tpanic(\"unreachable\")\n\t\t\t}\n\t\t}\n\t}\n\n\t// Name and sort groups.\n\tfor i := range groups {\n\t\tif groups[i].inputs.Len() == 0 {\n\t\t\tgroups[i].name = \"no inputs\"\n\t\t\tcontinue\n\t\t}\n\t\tinstr := make([]string, 0, groups[i].inputs.Len())\n\t\tgroups[i].inputs.Iterate(func(k types.Type, _ interface{}) {\n\t\t\tinstr = append(instr, types.TypeString(k, nil))\n\t\t})\n\t\tsort.Strings(instr)\n\t\tgroups[i].name = strings.Join(instr, \", \")\n\t}\n\tsort.Slice(groups, func(i, j int) bool {\n\t\tif groups[i].inputs.Len() == groups[j].inputs.Len() {\n\t\t\treturn groups[i].name < groups[j].name\n\t\t}\n\t\treturn groups[i].inputs.Len() < groups[j].inputs.Len()\n\t})\n\treturn groups, imports\n}\n\nfunc mergeTypeSets(dst, src *typeutil.Map) {\n\tsrc.Iterate(func(k types.Type, _ interface{}) {\n\t\tdst.Set(k, true)\n\t})\n}\n\nfunc sameTypeKeys(a, b *typeutil.Map) bool {\n\tif a.Len() != b.Len() {\n\t\treturn false\n\t}\n\tsame := true\n\ta.Iterate(func(k types.Type, _ interface{}) {\n\t\tif b.At(k) == nil {\n\t\t\tsame = false\n\t\t}\n\t})\n\treturn same\n}\n\nfunc sortSet(set interface{}) []string {\n\trv := reflect.ValueOf(set)\n\ta := make([]string, 0, rv.Len())\n\tkeys := rv.MapKeys()\n\tfor _, k := range keys {\n\t\ta = append(a, k.String())\n\t}\n\tsort.Strings(a)\n\treturn a\n}\n\nfunc formatProviderSetName(importPath, varName string) string {\n\t// Since varName is an identifier, it doesn't make sense to quote.\n\treturn strconv.Quote(importPath) + \".\" + varName\n}\n\nfunc logErrors(errs []error) {\n\tfor _, err := range errs {\n\t\tlog.Println(strings.Replace(err.Error(), \"\\n\", \"\\n\\t\", -1))\n\t}\n}\n"
  },
  {
    "path": "docs/best-practices.md",
    "content": "# Best Practices\n\nThe following are practices we recommend for using Wire. This list will grow\nover time.\n\n## Distinguishing Types\n\nIf you need to inject a common type like `string`, create a new string type to\navoid conflicts with other providers. For example:\n\n```go\ntype MySQLConnectionString string\n```\n\n## Options Structs\n\nA provider function that includes many dependencies can pair the function with\nan options struct.\n\n```go\ntype Options struct {\n    // Messages is the set of recommended greetings.\n    Messages []Message\n    // Writer is the location to send greetings. nil goes to stdout.\n    Writer io.Writer\n}\n\nfunc NewGreeter(ctx context.Context, opts *Options) (*Greeter, error) {\n    // ...\n}\n\nvar GreeterSet = wire.NewSet(wire.Struct(new(Options), \"*\"), NewGreeter)\n```\n\n## Provider Sets in Libraries\n\nWhen creating a provider set for use in a library, the only changes you can make\nwithout breaking compatibility are:\n\n-   Change which provider a provider set uses to provide a specific output, as\n    long as it does not introduce a new input to the provider set. It may remove\n    inputs. However, note that existing injectors will use the old provider\n    until they are regenerated.\n-   Introduce a new output type into the provider set, but only if the type\n    itself is newly added. If the type is not new, it is possible that some\n    injector already has the output type included, which would cause a conflict.\n\nAll other changes are not safe. This includes:\n\n-   Requiring a new input in the provider set.\n-   Removing an output type from a provider set.\n-   Adding an existing output type into the provider set.\n\nInstead of making one of these breaking changes, consider adding a new provider\nset.\n\nAs an example, if you have a provider set like this:\n\n```go\nvar GreeterSet = wire.NewSet(NewStdoutGreeter)\n\nfunc DefaultGreeter(ctx context.Context) *Greeter {\n    // ...\n}\n\nfunc NewStdoutGreeter(ctx context.Context, msgs []Message) *Greeter {\n    // ...\n}\n\nfunc NewGreeter(ctx context.Context, w io.Writer, msgs []Message) (*Greeter, error) {\n    // ...\n}\n```\n\nYou may:\n\n-   Use `DefaultGreeter` instead of `NewStdoutGreeter` in `GreeterSet`.\n-   Create a new type `T` and add a provider for `T` to `GreeterSet`, as long as\n    `T` is introduced in the same commit/release as the provider is added.\n\nYou may not:\n\n-   Use `NewGreeter` instead of `NewStdoutGreeter` in `GreeterSet`. This both\n    adds an input type (`io.Writer`) and requires injectors to return an `error`\n    where the provider of `*Greeter` did not require this before.\n-   Remove `NewStdoutGreeter` from `GreeterSet`. Injectors depending on\n    `*Greeter` will be broken.\n-   Add a provider for `io.Writer` to `GreeterSet`. Injectors might already have\n    a provider for `io.Writer` which might conflict with this one.\n\nAs such, you should pick the output types in a library provider set carefully.\nIn general, prefer small provider sets in a library. For example, it is common\nfor a library provider set to contain a single provider function along with a\n`wire.Bind` to the interface the return type implements. Avoiding larger\nprovider sets reduces the likelihood that applications will encounter conflicts.\nTo illustrate, imagine your library provides a client for a web service. While\nit may be tempting to bundle a provider for `*http.Client` in a provider set for\nyour library's client, doing so would cause conflicts if every library did the\nsame. Instead, the library's provider set should only include the provider for\nthe API client, and let `*http.Client` be an input of the provider set.\n\n## Mocking\n\nThere are two approaches for creating an injected app with mocked dependencies.\nExamples of both approaches are shown\n[here](https://github.com/google/wire/tree/master/internal/wire/testdata/ExampleWithMocks/foo).\n\n### Approach A: Pass mocks to the injector\n\nCreate a test-only injector that takes all of the mocks as arguments; the\nargument types must be the interface types the mocks are mocking. `wire.Build`\ncan't include providers for the mocked dependencies without creating conflicts,\nso if you're using provider set(s) you will need to define one that doesn't\ninclude the mocked types.\n\n### Approach B: Return the mocks from the injector\n\nCreate a new struct that includes the app plus all of the dependencies you want\nto mock. Create a test-only injector that returns this struct, give it providers\nfor the concrete mock types, and use `wire.Bind` to tell Wire that the concrete\nmock types should be used to fulfill the appropriate interface.\n"
  },
  {
    "path": "docs/faq.md",
    "content": "# Frequently Asked Questions\n\n## How does Wire relate to other Go dependency injection tools?\n\nOther dependency injection tools for Go like [dig][] or [facebookgo/inject][]\nare based on reflection. Wire runs as a code generator, which means that the\ninjector works without making calls to a runtime library. This enables easier\nintrospection of initialization and correct cross-references for tooling like\n[guru][].\n\n[dig]: https://github.com/uber-go/dig\n[facebookgo/inject]: https://github.com/facebookgo/inject\n[guru]: https://golang.org/s/using-guru\n\n## How does Wire relate to other non-Go dependency injection tools (like Dagger 2)?\n\nWire's approach was inspired by [Dagger 2][]. However, it is not the aim of Wire\nto emulate dependency injection tools from other languages: the design space and\nrequirements are quite different. For example, the Go compiler does not support\nanything like Java's annotation processing mechanisms. The difference in\nlanguages and their idioms necessarily requires different approaches in\nprimitives and API.\n\n[Dagger 2]: https://google.github.io/dagger/\n\n## Why use pseudo-functions to create provider sets or injectors?\n\nIn the early prototypes, Wire directives were specially formatted comments. This\nseemed appealing at first glance as this meant no compile-time or runtime\nimpact. However, this unstructured approach becomes opaque to other tooling not\nwritten for Wire. Tools like [`gorename`][] or [guru][] would not be able to\nrecognize references to the identifiers existing in comments without being\nspecially modified to understand Wire's comment format. By moving the references\ninto no-op function calls, Wire interoperates seamlessly with other Go tooling.\n\n[`gorename`]: https://godoc.org/golang.org/x/tools/cmd/gorename\n\n## What if my dependency graph has two dependencies of the same type?\n\nThis most frequently appears with common types like `string`. An example of this\nproblem would be:\n\n```go\ntype Foo struct { /* ... */ }\ntype Bar struct { /* ... */ }\n\nfunc newFoo1() *Foo { /* ... */ }\nfunc newFoo2() *Foo { /* ... */ }\nfunc newBar(foo1 *Foo, foo2 *Foo) *Bar { /* ... */ }\n\nfunc inject() *Bar {\n\t// ERROR! Multiple providers for *Foo.\n\twire.Build(newFoo1, newFoo2, newBar)\n\treturn nil\n}\n```\n\nWire does not allow multiple providers for one type to exist in the transitive\nclosure of the providers presented to `wire.Build`, as this is usually a\nmistake. For legitimate cases where you need multiple dependencies of the same\ntype, you need to invent a new type to call this other dependency. For example,\nyou can name OAuth credentials after the service they connect to. Once you have\na suitable different type, you can wrap and unwrap the type when plumbing it\nthrough Wire. Continuing our above example:\n\n```go\ntype OtherFoo Foo\n\nfunc newOtherFoo() *OtherFoo {\n\t// Call the original provider...\n\tfoo := newFoo2()\n\t// ...then convert it to the new type.\n\treturn (*OtherFoo)(foo)\n}\n\nfunc provideBar(foo1 *Foo, otherFoo *OtherFoo) *Bar {\n\t// Convert the new type into the unwrapped type...\n\tfoo2 := (*Foo)(otherFoo)\n\t// ...then use it to call the original provider.\n\treturn newBar(foo1, foo2)\n}\n\nfunc inject() *Bar {\n\twire.Build(newFoo1, newOtherFoo, provideBar)\n\treturn nil\n}\n```\n\n## Why does Wire forbid including the same provider multiple times?\n\nWire forbids this to remain consistent with the principle that specifying\nmultiple providers for the same type is an error. On the surface, Wire could\npermit duplication, but this would introduce a few unintended consequences:\n\n-  Wire would have to specify what kinds of duplicates are permissible: are two\n   `wire.Value` calls ever considered to be the \"same\"?\n-  If a provider set changes the function it uses to provide a type, then this\n   could break an application, since it may introduce a new conflict between\n   another provider set that was specifying the \"same\" provider.\n\nAs such, we decided that the simpler behavior would be for this case to be an\nerror, knowing we can always relax this restriction later. The user can always\ncreate a new provider set that does not have the conflicting type. A [proposed\nsubtract command][] would automate the toil in this process.\n\n[proposed subtract command]: https://github.com/google/wire/issues/8\n\n## Why does Wire require explicitly declare that a type provides an interface type?\n\nThe reason the binding is explicit is to avoid scenarios where adding a new type\nto the provider graph that implements the same interface causes the graph to\nbreak, because that can be surprising. While this does result in more typing,\nthe end-effect is that the developer's intent is more explicit in the code,\nwhich we felt was most consistent with the Go philosophy.\n\nThere is an [open issue](https://github.com/google/wire/issues/242) to consider\nimproving this.\n\n## Should I use Wire for small applications?\n\nProbably not. Wire is designed to automate more intricate setup code found in\nlarger applications. For small applications, hand-wiring dependencies is\nsimpler.\n\n## Who is using Wire?\n\nWire is still fairly new and doesn't have a large user base yet. However, we\nhave heard a lot of interest from Go users wanting to simplify their\napplications. If your project or company uses Wire, please let us know by either\nemailing us or sending a pull request amending this section.\n"
  },
  {
    "path": "docs/guide.md",
    "content": "# Wire User Guide\n\n## Basics\n\nWire has two core concepts: providers and injectors.\n\n### Defining Providers\n\nThe primary mechanism in Wire is the **provider**: a function that can produce a\nvalue. These functions are ordinary Go code.\n\n```go\npackage foobarbaz\n\ntype Foo struct {\n    X int\n}\n\n// ProvideFoo returns a Foo.\nfunc ProvideFoo() Foo {\n    return Foo{X: 42}\n}\n```\n\nProvider functions must be exported in order to be used from other packages,\njust like ordinary functions.\n\nProviders can specify dependencies with parameters:\n\n```go\npackage foobarbaz\n\n// ...\n\ntype Bar struct {\n    X int\n}\n\n// ProvideBar returns a Bar: a negative Foo.\nfunc ProvideBar(foo Foo) Bar {\n    return Bar{X: -foo.X}\n}\n```\n\nProviders can also return errors:\n\n```go\npackage foobarbaz\n\nimport (\n    \"context\"\n    \"errors\"\n)\n\n// ...\n\ntype Baz struct {\n    X int\n}\n\n// ProvideBaz returns a value if Bar is not zero.\nfunc ProvideBaz(ctx context.Context, bar Bar) (Baz, error) {\n    if bar.X == 0 {\n        return Baz{}, errors.New(\"cannot provide baz when bar is zero\")\n    }\n    return Baz{X: bar.X}, nil\n}\n```\n\nProviders can be grouped into **provider sets**. This is useful if several\nproviders will frequently be used together. To add these providers to a new set\ncalled `SuperSet`, use the `wire.NewSet` function:\n\n```go\npackage foobarbaz\n\nimport (\n    // ...\n    \"github.com/google/wire\"\n)\n\n// ...\n\nvar SuperSet = wire.NewSet(ProvideFoo, ProvideBar, ProvideBaz)\n```\n\nYou can also add other provider sets into a provider set.\n\n```go\npackage foobarbaz\n\nimport (\n    // ...\n    \"example.com/some/other/pkg\"\n)\n\n// ...\n\nvar MegaSet = wire.NewSet(SuperSet, pkg.OtherSet)\n```\n\n### Injectors\n\nAn application wires up these providers with an **injector**: a function that\ncalls providers in dependency order. With Wire, you write the injector's\nsignature, then Wire generates the function's body.\n\nAn injector is declared by writing a function declaration whose body is a call\nto `wire.Build`. The return values don't matter as long as they are of the\ncorrect type. The values themselves will be ignored in the generated code. Let's\nsay that the above providers were defined in a package called\n`example.com/foobarbaz`. The following would declare an injector to obtain a\n`Baz`:\n\n```go\n// +build wireinject\n// The build tag makes sure the stub is not built in the final build.\n\npackage main\n\nimport (\n    \"context\"\n\n    \"github.com/google/wire\"\n    \"example.com/foobarbaz\"\n)\n\nfunc initializeBaz(ctx context.Context) (foobarbaz.Baz, error) {\n    wire.Build(foobarbaz.MegaSet)\n    return foobarbaz.Baz{}, nil\n}\n```\n\nLike providers, injectors can be parameterized on inputs (which then get sent to\nproviders) and can return errors. Arguments to `wire.Build` are the same as\n`wire.NewSet`: they form a provider set. This is the provider set that gets used\nduring code generation for that injector.\n\nAny non-injector declarations found in a file with injectors will be copied into\nthe generated file.\n\nYou can generate the injector by invoking Wire in the package directory:\n\n```shell\nwire\n```\n\nWire will produce an implementation of the injector in a file called\n`wire_gen.go` that looks something like this:\n\n```go\n// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//+build !wireinject\n\npackage main\n\nimport (\n    \"example.com/foobarbaz\"\n)\n\nfunc initializeBaz(ctx context.Context) (foobarbaz.Baz, error) {\n    foo := foobarbaz.ProvideFoo()\n    bar := foobarbaz.ProvideBar(foo)\n    baz, err := foobarbaz.ProvideBaz(ctx, bar)\n    if err != nil {\n        return foobarbaz.Baz{}, err\n    }\n    return baz, nil\n}\n```\n\nAs you can see, the output is very close to what a developer would write\nthemselves. Further, there is little dependency on Wire at runtime: all of the\nwritten code is just normal Go code, and can be used without Wire.\n\nOnce `wire_gen.go` is created, you can regenerate it by running [`go generate`].\n\n[`go generate`]: https://blog.golang.org/generate\n\n## Advanced Features\n\nThe following features all build on top of the concepts of providers and\ninjectors.\n\n### Binding Interfaces\n\nFrequently, dependency injection is used to bind a concrete implementation for\nan interface. Wire matches inputs to outputs via [type identity][], so the\ninclination might be to create a provider that returns an interface type.\nHowever, this would not be idiomatic, since the Go best practice is to\n[return concrete types][]. Instead, you can declare an interface binding in a\nprovider set:\n\n```go\ntype Fooer interface {\n    Foo() string\n}\n\ntype MyFooer string\n\nfunc (b *MyFooer) Foo() string {\n    return string(*b)\n}\n\nfunc provideMyFooer() *MyFooer {\n    b := new(MyFooer)\n    *b = \"Hello, World!\"\n    return b\n}\n\ntype Bar string\n\nfunc provideBar(f Fooer) string {\n    // f will be a *MyFooer.\n    return f.Foo()\n}\n\nvar Set = wire.NewSet(\n    provideMyFooer,\n    wire.Bind(new(Fooer), new(*MyFooer)),\n    provideBar)\n```\n\nThe first argument to `wire.Bind` is a pointer to a value of the desired\ninterface type and the second argument is a pointer to a value of the type that\nimplements the interface. Any set that includes an interface binding must also\nhave a provider in the same set that provides the concrete type.\n\n[type identity]: https://golang.org/ref/spec#Type_identity\n[return concrete types]: https://github.com/golang/go/wiki/CodeReviewComments#interfaces\n\n### Struct Providers\n\nStructs can be constructed using provided types. Use the `wire.Struct` function\nto construct a struct type and tell the injector which field(s) should be injected.\nThe injector will fill in each field using the provider for the field's type.\nFor the resulting struct type `S`, `wire.Struct` provides both `S` and `*S`. For\nexample, given the following providers:\n\n```go\ntype Foo int\ntype Bar int\n\nfunc ProvideFoo() Foo {/* ... */}\n\nfunc ProvideBar() Bar {/* ... */}\n\ntype FooBar struct {\n    MyFoo Foo\n    MyBar Bar\n}\n\nvar Set = wire.NewSet(\n    ProvideFoo,\n    ProvideBar,\n    wire.Struct(new(FooBar), \"MyFoo\", \"MyBar\"))\n```\n\nA generated injector for `FooBar` would look like this:\n\n```go\nfunc injectFooBar() FooBar {\n    foo := ProvideFoo()\n    bar := ProvideBar()\n    fooBar := FooBar{\n        MyFoo: foo,\n        MyBar: bar,\n    }\n    return fooBar\n}\n```\n\nThe first argument to `wire.Struct` is a pointer to the desired struct type and\nthe subsequent arguments are the names of fields to be injected. A special\nstring `\"*\"` can be used as a shortcut to tell the injector to inject all\nfields. So `wire.Struct(new(FooBar), \"*\")` produces the same result as above.\n\nFor the above example, you can specify only injecting `\"MyFoo\"` by changing the\n`Set` to:\n\n```go\nvar Set = wire.NewSet(\n    ProvideFoo,\n    wire.Struct(new(FooBar), \"MyFoo\"))\n```\n\nThen the generated injector for `FooBar` would look like this:\n\n```go\nfunc injectFooBar() FooBar {\n    foo := ProvideFoo()\n    fooBar := FooBar{\n        MyFoo: foo,\n    }\n    return fooBar\n}\n```\n\nIf the injector returned a `*FooBar` instead of a `FooBar`, the generated injector\nwould look like this:\n\n```go\nfunc injectFooBar() *FooBar {\n    foo := ProvideFoo()\n    fooBar := &FooBar{\n        MyFoo: foo,\n    }\n    return fooBar\n}\n```\n\nIt is sometimes useful to prevent certain fields from being filled in by the\ninjector, especially when passing `*` to `wire.Struct`. You can tag a field with\n`` `wire:\"-\"` `` to have Wire ignore such fields. For example:\n\n```go\ntype Foo struct {\n    mu sync.Mutex `wire:\"-\"`\n    Bar Bar\n}\n```\n\nWhen you provide the `Foo` type using `wire.Struct(new(Foo), \"*\")`, Wire will\nautomatically omit the `mu` field. Additionally, it is an error to explicitly\nspecify a prevented field as in `wire.Struct(new(Foo), \"mu\")`.\n\n### Binding Values\n\nOccasionally, it is useful to bind a basic value (usually `nil`) to a type.\nInstead of having injectors depend on a throwaway provider function, you can add\na value expression to a provider set.\n\n```go\ntype Foo struct {\n    X int\n}\n\nfunc injectFoo() Foo {\n    wire.Build(wire.Value(Foo{X: 42}))\n    return Foo{}\n}\n```\n\nThe generated injector would look like this:\n\n```go\nfunc injectFoo() Foo {\n    foo := _wireFooValue\n    return foo\n}\n\nvar (\n    _wireFooValue = Foo{X: 42}\n)\n```\n\nIt's important to note that the expression will be copied to the injector's\npackage; references to variables will be evaluated during the injector package's\ninitialization. Wire will emit an error if the expression calls any functions or\nreceives from any channels.\n\nFor interface values, use `InterfaceValue`:\n\n```go\nfunc injectReader() io.Reader {\n    wire.Build(wire.InterfaceValue(new(io.Reader), os.Stdin))\n    return nil\n}\n```\n\n### Use Fields of a Struct as Providers\n\nSometimes the providers the user wants are some fields of a struct. If you find\nyourself writing a provider like `getS` in the example below to promote struct\nfields into provided types:\n\n```go\ntype Foo struct {\n    S string\n    N int\n    F float64\n}\n\nfunc getS(foo Foo) string {\n    // Bad! Use wire.FieldsOf instead.\n    return foo.S\n}\n\nfunc provideFoo() Foo {\n    return Foo{ S: \"Hello, World!\", N: 1, F: 3.14 }\n}\n\nfunc injectedMessage() string {\n    wire.Build(\n        provideFoo,\n        getS)\n    return \"\"\n}\n```\n\nYou can instead use `wire.FieldsOf` to use those fields directly without writing\n`getS`:\n\n```go\nfunc injectedMessage() string {\n    wire.Build(\n        provideFoo,\n        wire.FieldsOf(new(Foo), \"S\"))\n    return \"\"\n}\n```\n\nThe generated injector would look like this:\n\n```go\nfunc injectedMessage() string {\n    foo := provideFoo()\n    string2 := foo.S\n    return string2\n}\n```\n\nYou can add as many field names to a `wire.FieldsOf` function as you like.\nFor a given field type `T`, `FieldsOf` provides at least `T`; if the struct\nargument is a pointer to a struct, then `FieldsOf` also provides `*T`.\n\n### Cleanup functions\n\nIf a provider creates a value that needs to be cleaned up (e.g. closing a file),\nthen it can return a closure to clean up the resource. The injector will use\nthis to either return an aggregated cleanup function to the caller or to clean\nup the resource if a provider called later in the injector's implementation\nreturns an error.\n\n```go\nfunc provideFile(log Logger, path Path) (*os.File, func(), error) {\n    f, err := os.Open(string(path))\n    if err != nil {\n        return nil, nil, err\n    }\n    cleanup := func() {\n        if err := f.Close(); err != nil {\n            log.Log(err)\n        }\n    }\n    return f, cleanup, nil\n}\n```\n\nA cleanup function is guaranteed to be called before the cleanup function of any\nof the provider's inputs and must have the signature `func()`.\n\n### Alternate Injector Syntax\n\nIf you grow weary of writing `return foobarbaz.Foo{}, nil` at the end of your\ninjector function declaration, you can instead write it more concisely with a\n`panic`:\n\n```go\nfunc injectFoo() Foo {\n    panic(wire.Build(/* ... */))\n}\n```\n"
  },
  {
    "path": "go.mod",
    "content": "module github.com/google/wire\n\ngo 1.19\n\nrequire (\n\tgithub.com/google/go-cmp v0.6.0\n\tgithub.com/google/subcommands v1.2.0\n\tgithub.com/pmezard/go-difflib v1.0.0\n\tgolang.org/x/tools v0.24.1\n)\n\nrequire (\n\tgolang.org/x/mod v0.20.0 // indirect\n\tgolang.org/x/sync v0.8.0 // indirect\n)\n"
  },
  {
    "path": "go.sum",
    "content": "github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=\ngithub.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=\ngithub.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=\ngithub.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=\ngithub.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=\ngithub.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=\ngolang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=\ngolang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=\ngolang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=\ngolang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=\ngolang.org/x/tools v0.24.1 h1:vxuHLTNS3Np5zrYoPRpcheASHX/7KiGo+8Y4ZM1J2O8=\ngolang.org/x/tools v0.24.1/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=\n"
  },
  {
    "path": "internal/alldeps",
    "content": "github.com/google/subcommands\ngithub.com/google/wire\ngithub.com/pmezard/go-difflib\ngolang.org/x/mod\ngolang.org/x/sync\ngolang.org/x/tools\n"
  },
  {
    "path": "internal/check_api_change.sh",
    "content": "#!/usr/bin/env bash\n# Copyright 2019 The Wire Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# This script checks to see if there are any incompatible API changes on the\n# current branch relative to the upstream branch.\n# It fails if it finds any, unless there is a commit with BREAKING_CHANGE_OK\n# in the first line of the commit message.\n\n# This script expects:\n# a) to be run at the root of the repository\n# b) HEAD is pointing to a commit that merges between the pull request and the\n#    upstream branch (GITHUB_BASE_REF).\n\nset -euo pipefail\n\nUPSTREAM_BRANCH=\"${GITHUB_BASE_REF:-master}\"\necho \"Checking for incompatible API changes relative to ${UPSTREAM_BRANCH}...\"\n\nMASTER_CLONE_DIR=\"$(mktemp -d)\"\nPKGINFO_BRANCH=$(mktemp)\nPKGINFO_MASTER=$(mktemp)\n\nfunction cleanup() {\n  rm -rf \"$MASTER_CLONE_DIR\"\n  rm -f \"$PKGINFO_BRANCH\"\n  rm -f \"$PKGINFO_MASTER\"\n}\ntrap cleanup EXIT\n\n# Install apidiff.\ngo install golang.org/x/exp/cmd/apidiff@latest\n\ngit clone -b \"$UPSTREAM_BRANCH\" . \"$MASTER_CLONE_DIR\" &> /dev/null\n\nincompatible_change_pkgs=()\nPKGS=$(cd \"$MASTER_CLONE_DIR\"; go list ./... | grep -v test | grep -v internal)\nfor pkg in $PKGS; do\n  echo \"  Testing ${pkg}...\"\n\n  # Compute export data for the current branch.\n  package_deleted=0\n  apidiff -w \"$PKGINFO_BRANCH\" \"$pkg\" || package_deleted=1\n  if [[ $package_deleted -eq 1 ]]; then\n    echo \"  Package ${pkg} was deleted! Recording as an incompatible change.\";\n    incompatible_change_pkgs+=(${pkg});\n    continue;\n  fi\n\n  # Compute export data for master@HEAD.\n  (cd \"$MASTER_CLONE_DIR\"; apidiff -w \"$PKGINFO_MASTER\" \"$pkg\")\n\n  # Print all changes for posterity.\n  apidiff \"$PKGINFO_MASTER\" \"$PKGINFO_BRANCH\"\n\n  # Note if there's an incompatible change.\n  ic=$(apidiff -incompatible \"$PKGINFO_MASTER\" \"$PKGINFO_BRANCH\")\n  if [ ! -z \"$ic\" ]; then\n    incompatible_change_pkgs+=(\"$pkg\");\n  fi\ndone\n\nif [ ${#incompatible_change_pkgs[@]} -eq 0 ]; then\n  # No incompatible changes, we are good.\n  echo \"OK: No incompatible changes found.\"\n  exit 0;\nfi\necho \"Found breaking API change(s) in: ${incompatible_change_pkgs[*]}.\"\n\n# Found incompatible changes; see if they were declared as OK via a commit.\nif git cherry -v master | grep -q \"BREAKING_CHANGE_OK\"; then\n  echo \"Allowing them due to a commit message with BREAKING_CHANGE_OK.\";\n  exit 0;\nfi\n\necho \"FAIL. If this is expected and OK, you can pass this check by adding a commit with BREAKING_CHANGE_OK in the first line of the message.\"\nexit 1\n\n"
  },
  {
    "path": "internal/listdeps.sh",
    "content": "#!/usr/bin/env bash\n# Copyright 2019 The Wire Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nset -euo pipefail\n\n# To run this script manually to update alldeps:\n#\n# $ internal/listdeps.sh > internal/alldeps\n#\n# Important note: there are changes in module tooling behavior between go 1.11\n# and go 1.12; please make sure to use the same version of Go as used by Github\n# Actions (see .github/workflows/tests.yml) when updating the alldeps file.\ngo list -deps -f '{{with .Module}}{{.Path}}{{end}}' ./... | sort | uniq\n"
  },
  {
    "path": "internal/runtests.sh",
    "content": "#!/usr/bin/env bash\n# Copyright 2019 The Wire Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n# https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail\nset -euo pipefail\n\nif [[ $# -gt 0 ]]; then\n  echo \"usage: runtests.sh\" 1>&2\n  exit 64\nfi\n\n# Run Go tests.\nresult=0\necho \"Running Go tests...\"\ngo test -mod=readonly -race ./... || result=1\n\n# No need to run other checks on OSs other than linux.\n# We default RUNNER_OS to \"Linux\" so that we don't abort here when run locally.\nif [[ \"${RUNNER_OS:-Linux}\" != \"Linux\" ]]; then\n  exit $result\nfi\n\necho\necho \"Ensuring .go files are formatted with gofmt -s...\"\nmapfile -t go_files < <(find . -name '*.go' -type f | grep -v testdata)\nDIFF=\"$(gofmt -s -d \"${go_files[@]}\")\"\nif [ -n \"$DIFF\" ]; then\n  echo \"FAIL: please run gofmt -s and commit the result\"\n  echo \"$DIFF\";\n  result=1;\nelse\n  echo \"OK\"\nfi;\n\n\n# Ensure that the code has no extra dependencies (including transitive\n# dependencies) that we're not already aware of by comparing with\n# ./internal/alldeps\n#\n# Whenever project dependencies change, rerun ./internal/listdeps.sh\necho\necho \"Ensuring that there are no dependencies not listed in ./internal/alldeps...\"\n(./internal/listdeps.sh | diff ./internal/alldeps - && echo \"OK\") || {\n  echo \"FAIL: dependencies changed; run: internal/listdeps.sh > internal/alldeps\"\n  # Module behavior may differ across versions.\n  echo \"using the latest go version.\"\n  result=1\n}\n\n\n# For pull requests, check if there are undeclared incompatible API changes.\n# Skip this if we're already going to fail since it is expensive.\n# CURRENTLY BROKEN\n# if [[ ${result} -eq 0 ]] && [[ ! -z \"${GITHUB_HEAD_REF:-x}\" ]]; then\n  # echo\n  # ./internal/check_api_change.sh || result=1;\n# fi\n\nexit $result\n"
  },
  {
    "path": "internal/wire/analyze.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage wire\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"go/ast\"\n\t\"go/token\"\n\t\"go/types\"\n\t\"sort\"\n\t\"strings\"\n\n\t\"golang.org/x/tools/go/types/typeutil\"\n)\n\ntype callKind int\n\nconst (\n\tfuncProviderCall callKind = iota\n\tstructProvider\n\tvalueExpr\n\tselectorExpr\n)\n\n// A call represents a step of an injector function.  It may be either a\n// function call or a composite struct literal, depending on the value\n// of kind.\ntype call struct {\n\t// kind indicates the code pattern to use.\n\tkind callKind\n\n\t// out is the type this step produces.\n\tout types.Type\n\n\t// pkg and name identify one of the following:\n\t// 1) the provider to call for kind == funcProviderCall;\n\t// 2) the type to construct for kind == structProvider;\n\t// 3) the name to select for kind == selectorExpr.\n\tpkg  *types.Package\n\tname string\n\n\t// args is a list of arguments to call the provider with. Each element is:\n\t// a) one of the givens (args[i] < len(given)),\n\t// b) the result of a previous provider call (args[i] >= len(given))\n\t//\n\t// This will be nil for kind == valueExpr.\n\t//\n\t// If kind == selectorExpr, then the length of this slice will be 1 and the\n\t// \"argument\" will be the value to access fields from.\n\targs []int\n\n\t// varargs is true if the provider function is variadic.\n\tvarargs bool\n\n\t// fieldNames maps the arguments to struct field names.\n\t// This will only be set if kind == structProvider.\n\tfieldNames []string\n\n\t// ins is the list of types this call receives as arguments.\n\t// This will be nil for kind == valueExpr.\n\tins []types.Type\n\n\t// The following are only set for kind == funcProviderCall:\n\n\t// hasCleanup is true if the provider call returns a cleanup function.\n\thasCleanup bool\n\t// hasErr is true if the provider call returns an error.\n\thasErr bool\n\n\t// The following are only set for kind == valueExpr:\n\n\tvalueExpr     ast.Expr\n\tvalueTypeInfo *types.Info\n\n\t// The following are only set for kind == selectorExpr:\n\n\tptrToField bool\n}\n\n// solve finds the sequence of calls required to produce an output type\n// with an optional set of provided inputs.\nfunc solve(fset *token.FileSet, out types.Type, given *types.Tuple, set *ProviderSet) ([]call, []error) {\n\tec := new(errorCollector)\n\n\t// Start building the mapping of type to local variable of the given type.\n\t// The first len(given) local variables are the given types.\n\tindex := new(typeutil.Map)\n\tfor i := 0; i < given.Len(); i++ {\n\t\tindex.Set(given.At(i).Type(), i)\n\t}\n\n\t// Topological sort of the directed graph defined by the providers\n\t// using a depth-first search using a stack. Provider set graphs are\n\t// guaranteed to be acyclic. An index value of errAbort indicates that\n\t// the type was visited, but failed due to an error added to ec.\n\terrAbort := errors.New(\"failed to visit\")\n\tvar used []*providerSetSrc\n\tvar calls []call\n\ttype frame struct {\n\t\tt    types.Type\n\t\tfrom types.Type\n\t\tup   *frame\n\t}\n\tstk := []frame{{t: out}}\ndfs:\n\tfor len(stk) > 0 {\n\t\tcurr := stk[len(stk)-1]\n\t\tstk = stk[:len(stk)-1]\n\t\tif index.At(curr.t) != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\tpv := set.For(curr.t)\n\t\tif pv.IsNil() {\n\t\t\tif curr.from == nil {\n\t\t\t\tec.add(fmt.Errorf(\"no provider found for %s, output of injector\", types.TypeString(curr.t, nil)))\n\t\t\t\tindex.Set(curr.t, errAbort)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tsb := new(strings.Builder)\n\t\t\tfmt.Fprintf(sb, \"no provider found for %s\", types.TypeString(curr.t, nil))\n\t\t\tfor f := curr.up; f != nil; f = f.up {\n\t\t\t\tfmt.Fprintf(sb, \"\\nneeded by %s in %s\", types.TypeString(f.t, nil), set.srcMap.At(f.t).(*providerSetSrc).description(fset, f.t))\n\t\t\t}\n\t\t\tec.add(errors.New(sb.String()))\n\t\t\tindex.Set(curr.t, errAbort)\n\t\t\tcontinue\n\t\t}\n\t\tsrc := set.srcMap.At(curr.t).(*providerSetSrc)\n\t\tused = append(used, src)\n\t\tif concrete := pv.Type(); !types.Identical(concrete, curr.t) {\n\t\t\t// Interface binding does not create a call.\n\t\t\ti := index.At(concrete)\n\t\t\tif i == nil {\n\t\t\t\tstk = append(stk, curr, frame{t: concrete, from: curr.t, up: &curr})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tindex.Set(curr.t, i)\n\t\t\tcontinue\n\t\t}\n\n\t\tswitch pv := set.For(curr.t); {\n\t\tcase pv.IsArg():\n\t\t\t// Continue, already added to stk.\n\t\tcase pv.IsProvider():\n\t\t\tp := pv.Provider()\n\t\t\t// Ensure that all argument types have been visited. If not, push them\n\t\t\t// on the stack in reverse order so that calls are added in argument\n\t\t\t// order.\n\t\t\tvisitedArgs := true\n\t\t\tfor i := len(p.Args) - 1; i >= 0; i-- {\n\t\t\t\ta := p.Args[i]\n\t\t\t\tif index.At(a.Type) == nil {\n\t\t\t\t\tif visitedArgs {\n\t\t\t\t\t\t// Make sure to re-visit this type after visiting all arguments.\n\t\t\t\t\t\tstk = append(stk, curr)\n\t\t\t\t\t\tvisitedArgs = false\n\t\t\t\t\t}\n\t\t\t\t\tstk = append(stk, frame{t: a.Type, from: curr.t, up: &curr})\n\t\t\t\t}\n\t\t\t}\n\t\t\tif !visitedArgs {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\targs := make([]int, len(p.Args))\n\t\t\tins := make([]types.Type, len(p.Args))\n\t\t\tfor i := range p.Args {\n\t\t\t\tins[i] = p.Args[i].Type\n\t\t\t\tv := index.At(p.Args[i].Type)\n\t\t\t\tif v == errAbort {\n\t\t\t\t\tindex.Set(curr.t, errAbort)\n\t\t\t\t\tcontinue dfs\n\t\t\t\t}\n\t\t\t\targs[i] = v.(int)\n\t\t\t}\n\t\t\tindex.Set(curr.t, given.Len()+len(calls))\n\t\t\tkind := funcProviderCall\n\t\t\tfieldNames := []string(nil)\n\t\t\tif p.IsStruct {\n\t\t\t\tkind = structProvider\n\t\t\t\tfor _, arg := range p.Args {\n\t\t\t\t\tfieldNames = append(fieldNames, arg.FieldName)\n\t\t\t\t}\n\t\t\t}\n\t\t\tcalls = append(calls, call{\n\t\t\t\tkind:       kind,\n\t\t\t\tpkg:        p.Pkg,\n\t\t\t\tname:       p.Name,\n\t\t\t\targs:       args,\n\t\t\t\tvarargs:    p.Varargs,\n\t\t\t\tfieldNames: fieldNames,\n\t\t\t\tins:        ins,\n\t\t\t\tout:        curr.t,\n\t\t\t\thasCleanup: p.HasCleanup,\n\t\t\t\thasErr:     p.HasErr,\n\t\t\t})\n\t\tcase pv.IsValue():\n\t\t\tv := pv.Value()\n\t\t\tindex.Set(curr.t, given.Len()+len(calls))\n\t\t\tcalls = append(calls, call{\n\t\t\t\tkind:          valueExpr,\n\t\t\t\tout:           curr.t,\n\t\t\t\tvalueExpr:     v.expr,\n\t\t\t\tvalueTypeInfo: v.info,\n\t\t\t})\n\t\tcase pv.IsField():\n\t\t\tf := pv.Field()\n\t\t\tif index.At(f.Parent) == nil {\n\t\t\t\t// Fields have one dependency which is the parent struct. Make\n\t\t\t\t// sure to visit it first if it is not already visited.\n\t\t\t\tstk = append(stk, curr, frame{t: f.Parent, from: curr.t, up: &curr})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tindex.Set(curr.t, given.Len()+len(calls))\n\t\t\tv := index.At(f.Parent)\n\t\t\tif v == errAbort {\n\t\t\t\tindex.Set(curr.t, errAbort)\n\t\t\t\tcontinue dfs\n\t\t\t}\n\t\t\t// Use args[0] to store the position of the parent struct.\n\t\t\targs := []int{v.(int)}\n\t\t\t// If f.Out has 2 elements and curr.t is the 2nd one, then the call must\n\t\t\t// provide a pointer to the field.\n\t\t\tptrToField := len(f.Out) == 2 && types.Identical(curr.t, f.Out[1])\n\t\t\tcalls = append(calls, call{\n\t\t\t\tkind:       selectorExpr,\n\t\t\t\tpkg:        f.Pkg,\n\t\t\t\tname:       f.Name,\n\t\t\t\tout:        curr.t,\n\t\t\t\targs:       args,\n\t\t\t\tptrToField: ptrToField,\n\t\t\t})\n\t\tdefault:\n\t\t\tpanic(\"unknown return value from ProviderSet.For\")\n\t\t}\n\t}\n\tif len(ec.errors) > 0 {\n\t\treturn nil, ec.errors\n\t}\n\tif errs := verifyArgsUsed(set, used); len(errs) > 0 {\n\t\treturn nil, errs\n\t}\n\treturn calls, nil\n}\n\n// verifyArgsUsed ensures that all of the arguments in set were used during solve.\nfunc verifyArgsUsed(set *ProviderSet, used []*providerSetSrc) []error {\n\tvar errs []error\n\tfor _, imp := range set.Imports {\n\t\tfound := false\n\t\tfor _, u := range used {\n\t\t\tif u.Import == imp {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !found {\n\t\t\tif imp.VarName == \"\" {\n\t\t\t\terrs = append(errs, errors.New(\"unused provider set\"))\n\t\t\t} else {\n\t\t\t\terrs = append(errs, fmt.Errorf(\"unused provider set %q\", imp.VarName))\n\t\t\t}\n\t\t}\n\t}\n\tfor _, p := range set.Providers {\n\t\tfound := false\n\t\tfor _, u := range used {\n\t\t\tif u.Provider == p {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !found {\n\t\t\terrs = append(errs, fmt.Errorf(\"unused provider %q\", p.Pkg.Name()+\".\"+p.Name))\n\t\t}\n\t}\n\tfor _, v := range set.Values {\n\t\tfound := false\n\t\tfor _, u := range used {\n\t\t\tif u.Value == v {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !found {\n\t\t\terrs = append(errs, fmt.Errorf(\"unused value of type %s\", types.TypeString(v.Out, nil)))\n\t\t}\n\t}\n\tfor _, b := range set.Bindings {\n\t\tfound := false\n\t\tfor _, u := range used {\n\t\t\tif u.Binding == b {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !found {\n\t\t\terrs = append(errs, fmt.Errorf(\"unused interface binding to type %s\", types.TypeString(b.Iface, nil)))\n\t\t}\n\t}\n\tfor _, f := range set.Fields {\n\t\tfound := false\n\t\tfor _, u := range used {\n\t\t\tif u.Field == f {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif !found {\n\t\t\terrs = append(errs, fmt.Errorf(\"unused field %q.%s\", f.Parent, f.Name))\n\t\t}\n\t}\n\treturn errs\n}\n\n// buildProviderMap creates the providerMap and srcMap fields for a given\n// provider set. The given provider set's providerMap and srcMap fields are\n// ignored.\nfunc buildProviderMap(fset *token.FileSet, hasher typeutil.Hasher, set *ProviderSet) (*typeutil.Map, *typeutil.Map, []error) {\n\tproviderMap := new(typeutil.Map)\n\tproviderMap.SetHasher(hasher)\n\tsrcMap := new(typeutil.Map) // to *providerSetSrc\n\tsrcMap.SetHasher(hasher)\n\n\tec := new(errorCollector)\n\t// Process injector arguments.\n\tif set.InjectorArgs != nil {\n\t\tgivens := set.InjectorArgs.Tuple\n\t\tfor i := 0; i < givens.Len(); i++ {\n\t\t\ttyp := givens.At(i).Type()\n\t\t\targ := &InjectorArg{Args: set.InjectorArgs, Index: i}\n\t\t\tsrc := &providerSetSrc{InjectorArg: arg}\n\t\t\tif prevSrc := srcMap.At(typ); prevSrc != nil {\n\t\t\t\tec.add(bindingConflictError(fset, typ, set, src, prevSrc.(*providerSetSrc)))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tproviderMap.Set(typ, &ProvidedType{t: typ, a: arg})\n\t\t\tsrcMap.Set(typ, src)\n\t\t}\n\t}\n\t// Process imports, verifying that there are no conflicts between sets.\n\tfor _, imp := range set.Imports {\n\t\tsrc := &providerSetSrc{Import: imp}\n\t\timp.providerMap.Iterate(func(k types.Type, v interface{}) {\n\t\t\tif prevSrc := srcMap.At(k); prevSrc != nil {\n\t\t\t\tec.add(bindingConflictError(fset, k, set, src, prevSrc.(*providerSetSrc)))\n\t\t\t\treturn\n\t\t\t}\n\t\t\tproviderMap.Set(k, v)\n\t\t\tsrcMap.Set(k, src)\n\t\t})\n\t}\n\tif len(ec.errors) > 0 {\n\t\treturn nil, nil, ec.errors\n\t}\n\n\t// Process non-binding providers in new set.\n\tfor _, p := range set.Providers {\n\t\tsrc := &providerSetSrc{Provider: p}\n\t\tfor _, typ := range p.Out {\n\t\t\tif prevSrc := srcMap.At(typ); prevSrc != nil {\n\t\t\t\tec.add(bindingConflictError(fset, typ, set, src, prevSrc.(*providerSetSrc)))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tproviderMap.Set(typ, &ProvidedType{t: typ, p: p})\n\t\t\tsrcMap.Set(typ, src)\n\t\t}\n\t}\n\tfor _, v := range set.Values {\n\t\tsrc := &providerSetSrc{Value: v}\n\t\tif prevSrc := srcMap.At(v.Out); prevSrc != nil {\n\t\t\tec.add(bindingConflictError(fset, v.Out, set, src, prevSrc.(*providerSetSrc)))\n\t\t\tcontinue\n\t\t}\n\t\tproviderMap.Set(v.Out, &ProvidedType{t: v.Out, v: v})\n\t\tsrcMap.Set(v.Out, src)\n\t}\n\tfor _, f := range set.Fields {\n\t\tsrc := &providerSetSrc{Field: f}\n\t\tfor _, typ := range f.Out {\n\t\t\tif prevSrc := srcMap.At(typ); prevSrc != nil {\n\t\t\t\tec.add(bindingConflictError(fset, typ, set, src, prevSrc.(*providerSetSrc)))\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tproviderMap.Set(typ, &ProvidedType{t: typ, f: f})\n\t\t\tsrcMap.Set(typ, src)\n\t\t}\n\t}\n\tif len(ec.errors) > 0 {\n\t\treturn nil, nil, ec.errors\n\t}\n\n\t// Process bindings in set. Must happen after the other providers to\n\t// ensure the concrete type is being provided.\n\tfor _, b := range set.Bindings {\n\t\tsrc := &providerSetSrc{Binding: b}\n\t\tif prevSrc := srcMap.At(b.Iface); prevSrc != nil {\n\t\t\tec.add(bindingConflictError(fset, b.Iface, set, src, prevSrc.(*providerSetSrc)))\n\t\t\tcontinue\n\t\t}\n\t\tconcrete := providerMap.At(b.Provided)\n\t\tif concrete == nil {\n\t\t\tsetName := set.VarName\n\t\t\tif setName == \"\" {\n\t\t\t\tsetName = \"provider set\"\n\t\t\t}\n\t\t\tec.add(notePosition(fset.Position(b.Pos), fmt.Errorf(\"wire.Bind of concrete type %q to interface %q, but %s does not include a provider for %q\", b.Provided, b.Iface, setName, b.Provided)))\n\t\t\tcontinue\n\t\t}\n\t\tproviderMap.Set(b.Iface, concrete)\n\t\tsrcMap.Set(b.Iface, src)\n\t}\n\tif len(ec.errors) > 0 {\n\t\treturn nil, nil, ec.errors\n\t}\n\treturn providerMap, srcMap, nil\n}\n\nfunc verifyAcyclic(providerMap *typeutil.Map, hasher typeutil.Hasher) []error {\n\t// We must visit every provider type inside provider map, but we don't\n\t// have a well-defined starting point and there may be several\n\t// distinct graphs. Thus, we start a depth-first search at every\n\t// provider, but keep a shared record of visited providers to avoid\n\t// duplicating work.\n\tvisited := new(typeutil.Map) // to bool\n\tvisited.SetHasher(hasher)\n\tec := new(errorCollector)\n\t// Sort output types so that errors about cycles are consistent.\n\toutputs := providerMap.Keys()\n\tsort.Slice(outputs, func(i, j int) bool { return types.TypeString(outputs[i], nil) < types.TypeString(outputs[j], nil) })\n\tfor _, root := range outputs {\n\t\t// Depth-first search using a stack of trails through the provider map.\n\t\tstk := [][]types.Type{{root}}\n\t\tfor len(stk) > 0 {\n\t\t\tcurr := stk[len(stk)-1]\n\t\t\tstk = stk[:len(stk)-1]\n\t\t\thead := curr[len(curr)-1]\n\t\t\tif v, _ := visited.At(head).(bool); v {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tvisited.Set(head, true)\n\t\t\tx := providerMap.At(head)\n\t\t\tif x == nil {\n\t\t\t\t// Leaf: input.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tpt := x.(*ProvidedType)\n\t\t\tswitch {\n\t\t\tcase pt.IsValue():\n\t\t\t\t// Leaf: values do not have dependencies.\n\t\t\tcase pt.IsArg():\n\t\t\t\t// Injector arguments do not have dependencies.\n\t\t\tcase pt.IsProvider() || pt.IsField():\n\t\t\t\tvar args []types.Type\n\t\t\t\tif pt.IsProvider() {\n\t\t\t\t\tfor _, arg := range pt.Provider().Args {\n\t\t\t\t\t\targs = append(args, arg.Type)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\targs = append(args, pt.Field().Parent)\n\t\t\t\t}\n\t\t\t\tfor _, a := range args {\n\t\t\t\t\thasCycle := false\n\t\t\t\t\tfor i, b := range curr {\n\t\t\t\t\t\tif types.Identical(a, b) {\n\t\t\t\t\t\t\tsb := new(strings.Builder)\n\t\t\t\t\t\t\tfmt.Fprintf(sb, \"cycle for %s:\\n\", types.TypeString(a, nil))\n\t\t\t\t\t\t\tfor j := i; j < len(curr); j++ {\n\t\t\t\t\t\t\t\tt := providerMap.At(curr[j]).(*ProvidedType)\n\t\t\t\t\t\t\t\tif t.IsProvider() {\n\t\t\t\t\t\t\t\t\tp := t.Provider()\n\t\t\t\t\t\t\t\t\tfmt.Fprintf(sb, \"%s (%s.%s) ->\\n\", types.TypeString(curr[j], nil), p.Pkg.Path(), p.Name)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tp := t.Field()\n\t\t\t\t\t\t\t\t\tfmt.Fprintf(sb, \"%s (%s.%s) ->\\n\", types.TypeString(curr[j], nil), p.Parent, p.Name)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfmt.Fprintf(sb, \"%s\", types.TypeString(a, nil))\n\t\t\t\t\t\t\tec.add(errors.New(sb.String()))\n\t\t\t\t\t\t\thasCycle = true\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif !hasCycle {\n\t\t\t\t\t\tnext := append(append([]types.Type(nil), curr...), a)\n\t\t\t\t\t\tstk = append(stk, next)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\tpanic(\"invalid provider map value\")\n\t\t\t}\n\t\t}\n\t}\n\treturn ec.errors\n}\n\n// bindingConflictError creates a new error describing multiple bindings\n// for the same output type.\nfunc bindingConflictError(fset *token.FileSet, typ types.Type, set *ProviderSet, cur, prev *providerSetSrc) error {\n\tsb := new(strings.Builder)\n\tif set.VarName != \"\" {\n\t\tfmt.Fprintf(sb, \"%s has \", set.VarName)\n\t}\n\tfmt.Fprintf(sb, \"multiple bindings for %s\\n\", types.TypeString(typ, nil))\n\tfmt.Fprintf(sb, \"current:\\n<- %s\\n\", strings.Join(cur.trace(fset, typ), \"\\n<- \"))\n\tfmt.Fprintf(sb, \"previous:\\n<- %s\", strings.Join(prev.trace(fset, typ), \"\\n<- \"))\n\treturn notePosition(fset.Position(set.Pos), errors.New(sb.String()))\n}\n"
  },
  {
    "path": "internal/wire/copyast.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage wire\n\nimport (\n\t\"fmt\"\n\t\"go/ast\"\n\n\t\"golang.org/x/tools/go/ast/astutil\"\n)\n\n// copyAST performs a deep copy of an AST. *ast.Ident identity will be\n// preserved.\n//\n// This allows using astutil.Apply to rewrite an AST without modifying\n// the original AST.\nfunc copyAST(original ast.Node) ast.Node {\n\t// This function is necessarily long. No utility function exists to do this\n\t// clone, as most any attempt would need to have customization options, which\n\t// would need to be as expressive as Apply. A possibility to shorten the code\n\t// here would be to use reflection, but that trades clarity for shorter code.\n\n\tm := make(map[ast.Node]ast.Node)\n\tastutil.Apply(original, nil, func(c *astutil.Cursor) bool {\n\t\tswitch node := c.Node().(type) {\n\t\tcase nil:\n\t\t\t// No-op.\n\t\tcase *ast.ArrayType:\n\t\t\tm[node] = &ast.ArrayType{\n\t\t\t\tLbrack: node.Lbrack,\n\t\t\t\tLen:    exprFromMap(m, node.Len),\n\t\t\t\tElt:    exprFromMap(m, node.Elt),\n\t\t\t}\n\t\tcase *ast.AssignStmt:\n\t\t\tm[node] = &ast.AssignStmt{\n\t\t\t\tLhs:    copyExprList(m, node.Lhs),\n\t\t\t\tTokPos: node.TokPos,\n\t\t\t\tTok:    node.Tok,\n\t\t\t\tRhs:    copyExprList(m, node.Rhs),\n\t\t\t}\n\t\tcase *ast.BadDecl:\n\t\t\tm[node] = &ast.BadDecl{\n\t\t\t\tFrom: node.From,\n\t\t\t\tTo:   node.To,\n\t\t\t}\n\t\tcase *ast.BadExpr:\n\t\t\tm[node] = &ast.BadExpr{\n\t\t\t\tFrom: node.From,\n\t\t\t\tTo:   node.To,\n\t\t\t}\n\t\tcase *ast.BadStmt:\n\t\t\tm[node] = &ast.BadStmt{\n\t\t\t\tFrom: node.From,\n\t\t\t\tTo:   node.To,\n\t\t\t}\n\t\tcase *ast.BasicLit:\n\t\t\tm[node] = &ast.BasicLit{\n\t\t\t\tValuePos: node.ValuePos,\n\t\t\t\tKind:     node.Kind,\n\t\t\t\tValue:    node.Value,\n\t\t\t}\n\t\tcase *ast.BinaryExpr:\n\t\t\tm[node] = &ast.BinaryExpr{\n\t\t\t\tX:     exprFromMap(m, node.X),\n\t\t\t\tOpPos: node.OpPos,\n\t\t\t\tOp:    node.Op,\n\t\t\t\tY:     exprFromMap(m, node.Y),\n\t\t\t}\n\t\tcase *ast.BlockStmt:\n\t\t\tm[node] = &ast.BlockStmt{\n\t\t\t\tLbrace: node.Lbrace,\n\t\t\t\tList:   copyStmtList(m, node.List),\n\t\t\t\tRbrace: node.Rbrace,\n\t\t\t}\n\t\tcase *ast.BranchStmt:\n\t\t\tm[node] = &ast.BranchStmt{\n\t\t\t\tTokPos: node.TokPos,\n\t\t\t\tTok:    node.Tok,\n\t\t\t\tLabel:  identFromMap(m, node.Label),\n\t\t\t}\n\t\tcase *ast.CallExpr:\n\t\t\tm[node] = &ast.CallExpr{\n\t\t\t\tFun:      exprFromMap(m, node.Fun),\n\t\t\t\tLparen:   node.Lparen,\n\t\t\t\tArgs:     copyExprList(m, node.Args),\n\t\t\t\tEllipsis: node.Ellipsis,\n\t\t\t\tRparen:   node.Rparen,\n\t\t\t}\n\t\tcase *ast.CaseClause:\n\t\t\tm[node] = &ast.CaseClause{\n\t\t\t\tCase:  node.Case,\n\t\t\t\tList:  copyExprList(m, node.List),\n\t\t\t\tColon: node.Colon,\n\t\t\t\tBody:  copyStmtList(m, node.Body),\n\t\t\t}\n\t\tcase *ast.ChanType:\n\t\t\tm[node] = &ast.ChanType{\n\t\t\t\tBegin: node.Begin,\n\t\t\t\tArrow: node.Arrow,\n\t\t\t\tDir:   node.Dir,\n\t\t\t\tValue: exprFromMap(m, node.Value),\n\t\t\t}\n\t\tcase *ast.CommClause:\n\t\t\tm[node] = &ast.CommClause{\n\t\t\t\tCase:  node.Case,\n\t\t\t\tComm:  stmtFromMap(m, node.Comm),\n\t\t\t\tColon: node.Colon,\n\t\t\t\tBody:  copyStmtList(m, node.Body),\n\t\t\t}\n\t\tcase *ast.Comment:\n\t\t\tm[node] = &ast.Comment{\n\t\t\t\tSlash: node.Slash,\n\t\t\t\tText:  node.Text,\n\t\t\t}\n\t\tcase *ast.CommentGroup:\n\t\t\tcg := new(ast.CommentGroup)\n\t\t\tif node.List != nil {\n\t\t\t\tcg.List = make([]*ast.Comment, len(node.List))\n\t\t\t\tfor i := range node.List {\n\t\t\t\t\tcg.List[i] = m[node.List[i]].(*ast.Comment)\n\t\t\t\t}\n\t\t\t}\n\t\t\tm[node] = cg\n\t\tcase *ast.CompositeLit:\n\t\t\tm[node] = &ast.CompositeLit{\n\t\t\t\tType:   exprFromMap(m, node.Type),\n\t\t\t\tLbrace: node.Lbrace,\n\t\t\t\tElts:   copyExprList(m, node.Elts),\n\t\t\t\tRbrace: node.Rbrace,\n\t\t\t}\n\t\tcase *ast.DeclStmt:\n\t\t\tm[node] = &ast.DeclStmt{\n\t\t\t\tDecl: m[node.Decl].(ast.Decl),\n\t\t\t}\n\t\tcase *ast.DeferStmt:\n\t\t\tm[node] = &ast.DeferStmt{\n\t\t\t\tDefer: node.Defer,\n\t\t\t\tCall:  callExprFromMap(m, node.Call),\n\t\t\t}\n\t\tcase *ast.Ellipsis:\n\t\t\tm[node] = &ast.Ellipsis{\n\t\t\t\tEllipsis: node.Ellipsis,\n\t\t\t\tElt:      exprFromMap(m, node.Elt),\n\t\t\t}\n\t\tcase *ast.EmptyStmt:\n\t\t\tm[node] = &ast.EmptyStmt{\n\t\t\t\tSemicolon: node.Semicolon,\n\t\t\t\tImplicit:  node.Implicit,\n\t\t\t}\n\t\tcase *ast.ExprStmt:\n\t\t\tm[node] = &ast.ExprStmt{\n\t\t\t\tX: exprFromMap(m, node.X),\n\t\t\t}\n\t\tcase *ast.Field:\n\t\t\tm[node] = &ast.Field{\n\t\t\t\tDoc:     commentGroupFromMap(m, node.Doc),\n\t\t\t\tNames:   copyIdentList(m, node.Names),\n\t\t\t\tType:    exprFromMap(m, node.Type),\n\t\t\t\tTag:     basicLitFromMap(m, node.Tag),\n\t\t\t\tComment: commentGroupFromMap(m, node.Comment),\n\t\t\t}\n\t\tcase *ast.FieldList:\n\t\t\tfl := &ast.FieldList{\n\t\t\t\tOpening: node.Opening,\n\t\t\t\tClosing: node.Closing,\n\t\t\t}\n\t\t\tif node.List != nil {\n\t\t\t\tfl.List = make([]*ast.Field, len(node.List))\n\t\t\t\tfor i := range node.List {\n\t\t\t\t\tfl.List[i] = m[node.List[i]].(*ast.Field)\n\t\t\t\t}\n\t\t\t}\n\t\t\tm[node] = fl\n\t\tcase *ast.ForStmt:\n\t\t\tm[node] = &ast.ForStmt{\n\t\t\t\tFor:  node.For,\n\t\t\t\tInit: stmtFromMap(m, node.Init),\n\t\t\t\tCond: exprFromMap(m, node.Cond),\n\t\t\t\tPost: stmtFromMap(m, node.Post),\n\t\t\t\tBody: blockStmtFromMap(m, node.Body),\n\t\t\t}\n\t\tcase *ast.FuncDecl:\n\t\t\tm[node] = &ast.FuncDecl{\n\t\t\t\tDoc:  commentGroupFromMap(m, node.Doc),\n\t\t\t\tRecv: fieldListFromMap(m, node.Recv),\n\t\t\t\tName: identFromMap(m, node.Name),\n\t\t\t\tType: funcTypeFromMap(m, node.Type),\n\t\t\t\tBody: blockStmtFromMap(m, node.Body),\n\t\t\t}\n\t\tcase *ast.FuncLit:\n\t\t\tm[node] = &ast.FuncLit{\n\t\t\t\tType: funcTypeFromMap(m, node.Type),\n\t\t\t\tBody: blockStmtFromMap(m, node.Body),\n\t\t\t}\n\t\tcase *ast.FuncType:\n\t\t\tm[node] = &ast.FuncType{\n\t\t\t\tFunc:    node.Func,\n\t\t\t\tParams:  fieldListFromMap(m, node.Params),\n\t\t\t\tResults: fieldListFromMap(m, node.Results),\n\t\t\t}\n\t\tcase *ast.GenDecl:\n\t\t\tdecl := &ast.GenDecl{\n\t\t\t\tDoc:    commentGroupFromMap(m, node.Doc),\n\t\t\t\tTokPos: node.TokPos,\n\t\t\t\tTok:    node.Tok,\n\t\t\t\tLparen: node.Lparen,\n\t\t\t\tRparen: node.Rparen,\n\t\t\t}\n\t\t\tif node.Specs != nil {\n\t\t\t\tdecl.Specs = make([]ast.Spec, len(node.Specs))\n\t\t\t\tfor i := range node.Specs {\n\t\t\t\t\tdecl.Specs[i] = m[node.Specs[i]].(ast.Spec)\n\t\t\t\t}\n\t\t\t}\n\t\t\tm[node] = decl\n\t\tcase *ast.GoStmt:\n\t\t\tm[node] = &ast.GoStmt{\n\t\t\t\tGo:   node.Go,\n\t\t\t\tCall: callExprFromMap(m, node.Call),\n\t\t\t}\n\t\tcase *ast.Ident:\n\t\t\t// Keep identifiers the same identity so they can be conveniently\n\t\t\t// used with the original *types.Info.\n\t\t\tm[node] = node\n\t\tcase *ast.IfStmt:\n\t\t\tm[node] = &ast.IfStmt{\n\t\t\t\tIf:   node.If,\n\t\t\t\tInit: stmtFromMap(m, node.Init),\n\t\t\t\tCond: exprFromMap(m, node.Cond),\n\t\t\t\tBody: blockStmtFromMap(m, node.Body),\n\t\t\t\tElse: stmtFromMap(m, node.Else),\n\t\t\t}\n\t\tcase *ast.ImportSpec:\n\t\t\tm[node] = &ast.ImportSpec{\n\t\t\t\tDoc:     commentGroupFromMap(m, node.Doc),\n\t\t\t\tName:    identFromMap(m, node.Name),\n\t\t\t\tPath:    basicLitFromMap(m, node.Path),\n\t\t\t\tComment: commentGroupFromMap(m, node.Comment),\n\t\t\t\tEndPos:  node.EndPos,\n\t\t\t}\n\t\tcase *ast.IncDecStmt:\n\t\t\tm[node] = &ast.IncDecStmt{\n\t\t\t\tX:      exprFromMap(m, node.X),\n\t\t\t\tTokPos: node.TokPos,\n\t\t\t\tTok:    node.Tok,\n\t\t\t}\n\t\tcase *ast.IndexExpr:\n\t\t\tm[node] = &ast.IndexExpr{\n\t\t\t\tX:      exprFromMap(m, node.X),\n\t\t\t\tLbrack: node.Lbrack,\n\t\t\t\tIndex:  exprFromMap(m, node.Index),\n\t\t\t\tRbrack: node.Rbrack,\n\t\t\t}\n\t\tcase *ast.InterfaceType:\n\t\t\tm[node] = &ast.InterfaceType{\n\t\t\t\tInterface:  node.Interface,\n\t\t\t\tMethods:    fieldListFromMap(m, node.Methods),\n\t\t\t\tIncomplete: node.Incomplete,\n\t\t\t}\n\t\tcase *ast.KeyValueExpr:\n\t\t\tm[node] = &ast.KeyValueExpr{\n\t\t\t\tKey:   exprFromMap(m, node.Key),\n\t\t\t\tColon: node.Colon,\n\t\t\t\tValue: exprFromMap(m, node.Value),\n\t\t\t}\n\t\tcase *ast.LabeledStmt:\n\t\t\tm[node] = &ast.LabeledStmt{\n\t\t\t\tLabel: identFromMap(m, node.Label),\n\t\t\t\tColon: node.Colon,\n\t\t\t\tStmt:  stmtFromMap(m, node.Stmt),\n\t\t\t}\n\t\tcase *ast.MapType:\n\t\t\tm[node] = &ast.MapType{\n\t\t\t\tMap:   node.Map,\n\t\t\t\tKey:   exprFromMap(m, node.Key),\n\t\t\t\tValue: exprFromMap(m, node.Value),\n\t\t\t}\n\t\tcase *ast.ParenExpr:\n\t\t\tm[node] = &ast.ParenExpr{\n\t\t\t\tLparen: node.Lparen,\n\t\t\t\tX:      exprFromMap(m, node.X),\n\t\t\t\tRparen: node.Rparen,\n\t\t\t}\n\t\tcase *ast.RangeStmt:\n\t\t\tm[node] = &ast.RangeStmt{\n\t\t\t\tFor:    node.For,\n\t\t\t\tKey:    exprFromMap(m, node.Key),\n\t\t\t\tValue:  exprFromMap(m, node.Value),\n\t\t\t\tTokPos: node.TokPos,\n\t\t\t\tTok:    node.Tok,\n\t\t\t\tX:      exprFromMap(m, node.X),\n\t\t\t\tBody:   blockStmtFromMap(m, node.Body),\n\t\t\t}\n\t\tcase *ast.ReturnStmt:\n\t\t\tm[node] = &ast.ReturnStmt{\n\t\t\t\tReturn:  node.Return,\n\t\t\t\tResults: copyExprList(m, node.Results),\n\t\t\t}\n\t\tcase *ast.SelectStmt:\n\t\t\tm[node] = &ast.SelectStmt{\n\t\t\t\tSelect: node.Select,\n\t\t\t\tBody:   blockStmtFromMap(m, node.Body),\n\t\t\t}\n\t\tcase *ast.SelectorExpr:\n\t\t\tm[node] = &ast.SelectorExpr{\n\t\t\t\tX:   exprFromMap(m, node.X),\n\t\t\t\tSel: identFromMap(m, node.Sel),\n\t\t\t}\n\t\tcase *ast.SendStmt:\n\t\t\tm[node] = &ast.SendStmt{\n\t\t\t\tChan:  exprFromMap(m, node.Chan),\n\t\t\t\tArrow: node.Arrow,\n\t\t\t\tValue: exprFromMap(m, node.Value),\n\t\t\t}\n\t\tcase *ast.SliceExpr:\n\t\t\tm[node] = &ast.SliceExpr{\n\t\t\t\tX:      exprFromMap(m, node.X),\n\t\t\t\tLbrack: node.Lbrack,\n\t\t\t\tLow:    exprFromMap(m, node.Low),\n\t\t\t\tHigh:   exprFromMap(m, node.High),\n\t\t\t\tMax:    exprFromMap(m, node.Max),\n\t\t\t\tSlice3: node.Slice3,\n\t\t\t\tRbrack: node.Rbrack,\n\t\t\t}\n\t\tcase *ast.StarExpr:\n\t\t\tm[node] = &ast.StarExpr{\n\t\t\t\tStar: node.Star,\n\t\t\t\tX:    exprFromMap(m, node.X),\n\t\t\t}\n\t\tcase *ast.StructType:\n\t\t\tm[node] = &ast.StructType{\n\t\t\t\tStruct:     node.Struct,\n\t\t\t\tFields:     fieldListFromMap(m, node.Fields),\n\t\t\t\tIncomplete: node.Incomplete,\n\t\t\t}\n\t\tcase *ast.SwitchStmt:\n\t\t\tm[node] = &ast.SwitchStmt{\n\t\t\t\tSwitch: node.Switch,\n\t\t\t\tInit:   stmtFromMap(m, node.Init),\n\t\t\t\tTag:    exprFromMap(m, node.Tag),\n\t\t\t\tBody:   blockStmtFromMap(m, node.Body),\n\t\t\t}\n\t\tcase *ast.TypeAssertExpr:\n\t\t\tm[node] = &ast.TypeAssertExpr{\n\t\t\t\tX:      exprFromMap(m, node.X),\n\t\t\t\tLparen: node.Lparen,\n\t\t\t\tType:   exprFromMap(m, node.Type),\n\t\t\t\tRparen: node.Rparen,\n\t\t\t}\n\t\tcase *ast.TypeSpec:\n\t\t\tm[node] = &ast.TypeSpec{\n\t\t\t\tDoc:     commentGroupFromMap(m, node.Doc),\n\t\t\t\tName:    identFromMap(m, node.Name),\n\t\t\t\tAssign:  node.Assign,\n\t\t\t\tType:    exprFromMap(m, node.Type),\n\t\t\t\tComment: commentGroupFromMap(m, node.Comment),\n\t\t\t}\n\t\tcase *ast.TypeSwitchStmt:\n\t\t\tm[node] = &ast.TypeSwitchStmt{\n\t\t\t\tSwitch: node.Switch,\n\t\t\t\tInit:   stmtFromMap(m, node.Init),\n\t\t\t\tAssign: stmtFromMap(m, node.Assign),\n\t\t\t\tBody:   blockStmtFromMap(m, node.Body),\n\t\t\t}\n\t\tcase *ast.UnaryExpr:\n\t\t\tm[node] = &ast.UnaryExpr{\n\t\t\t\tOpPos: node.OpPos,\n\t\t\t\tOp:    node.Op,\n\t\t\t\tX:     exprFromMap(m, node.X),\n\t\t\t}\n\t\tcase *ast.ValueSpec:\n\t\t\tm[node] = &ast.ValueSpec{\n\t\t\t\tDoc:     commentGroupFromMap(m, node.Doc),\n\t\t\t\tNames:   copyIdentList(m, node.Names),\n\t\t\t\tType:    exprFromMap(m, node.Type),\n\t\t\t\tValues:  copyExprList(m, node.Values),\n\t\t\t\tComment: commentGroupFromMap(m, node.Comment),\n\t\t\t}\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"unhandled AST node: %T\", node))\n\t\t}\n\t\treturn true\n\t})\n\treturn m[original]\n}\n\nfunc commentGroupFromMap(m map[ast.Node]ast.Node, key *ast.CommentGroup) *ast.CommentGroup {\n\tif key == nil {\n\t\treturn nil\n\t}\n\treturn m[key].(*ast.CommentGroup)\n}\n\nfunc exprFromMap(m map[ast.Node]ast.Node, key ast.Expr) ast.Expr {\n\tif key == nil {\n\t\treturn nil\n\t}\n\treturn m[key].(ast.Expr)\n}\n\nfunc stmtFromMap(m map[ast.Node]ast.Node, key ast.Stmt) ast.Stmt {\n\tif key == nil {\n\t\treturn nil\n\t}\n\treturn m[key].(ast.Stmt)\n}\n\nfunc identFromMap(m map[ast.Node]ast.Node, key *ast.Ident) *ast.Ident {\n\tif key == nil {\n\t\treturn nil\n\t}\n\treturn m[key].(*ast.Ident)\n}\n\nfunc blockStmtFromMap(m map[ast.Node]ast.Node, key *ast.BlockStmt) *ast.BlockStmt {\n\tif key == nil {\n\t\treturn nil\n\t}\n\treturn m[key].(*ast.BlockStmt)\n}\n\nfunc fieldListFromMap(m map[ast.Node]ast.Node, key *ast.FieldList) *ast.FieldList {\n\tif key == nil {\n\t\treturn nil\n\t}\n\treturn m[key].(*ast.FieldList)\n}\n\nfunc callExprFromMap(m map[ast.Node]ast.Node, key *ast.CallExpr) *ast.CallExpr {\n\tif key == nil {\n\t\treturn nil\n\t}\n\treturn m[key].(*ast.CallExpr)\n}\n\nfunc basicLitFromMap(m map[ast.Node]ast.Node, key *ast.BasicLit) *ast.BasicLit {\n\tif key == nil {\n\t\treturn nil\n\t}\n\treturn m[key].(*ast.BasicLit)\n}\n\nfunc funcTypeFromMap(m map[ast.Node]ast.Node, key *ast.FuncType) *ast.FuncType {\n\tif key == nil {\n\t\treturn nil\n\t}\n\treturn m[key].(*ast.FuncType)\n}\n\nfunc copyExprList(m map[ast.Node]ast.Node, exprs []ast.Expr) []ast.Expr {\n\tif exprs == nil {\n\t\treturn nil\n\t}\n\tnewExprs := make([]ast.Expr, len(exprs))\n\tfor i := range exprs {\n\t\tnewExprs[i] = m[exprs[i]].(ast.Expr)\n\t}\n\treturn newExprs\n}\n\nfunc copyStmtList(m map[ast.Node]ast.Node, stmts []ast.Stmt) []ast.Stmt {\n\tif stmts == nil {\n\t\treturn nil\n\t}\n\tnewStmts := make([]ast.Stmt, len(stmts))\n\tfor i := range stmts {\n\t\tnewStmts[i] = m[stmts[i]].(ast.Stmt)\n\t}\n\treturn newStmts\n}\n\nfunc copyIdentList(m map[ast.Node]ast.Node, idents []*ast.Ident) []*ast.Ident {\n\tif idents == nil {\n\t\treturn nil\n\t}\n\tnewIdents := make([]*ast.Ident, len(idents))\n\tfor i := range idents {\n\t\tnewIdents[i] = m[idents[i]].(*ast.Ident)\n\t}\n\treturn newIdents\n}\n"
  },
  {
    "path": "internal/wire/errors.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage wire\n\nimport (\n\t\"go/token\"\n)\n\n// errorCollector manages a list of errors. The zero value is an empty list.\ntype errorCollector struct {\n\terrors []error\n}\n\n// add appends any non-nil errors to the collector.\nfunc (ec *errorCollector) add(errs ...error) {\n\tfor _, e := range errs {\n\t\tif e != nil {\n\t\t\tec.errors = append(ec.errors, e)\n\t\t}\n\t}\n}\n\n// mapErrors returns a new slice that wraps any errors using the given function.\nfunc mapErrors(errs []error, f func(error) error) []error {\n\tif len(errs) == 0 {\n\t\treturn nil\n\t}\n\tnewErrs := make([]error, len(errs))\n\tfor i := range errs {\n\t\tnewErrs[i] = f(errs[i])\n\t}\n\treturn newErrs\n}\n\n// A wireErr is an error with an optional position.\ntype wireErr struct {\n\terror    error\n\tposition token.Position\n}\n\n// notePosition wraps an error with position information if it doesn't already\n// have it.\n//\n// notePosition is usually called multiple times as an error goes up the call\n// stack, so calling notePosition on an existing *wireErr will not modify the\n// position, as the assumption is that deeper calls have more precise position\n// information about the source of the error.\nfunc notePosition(p token.Position, e error) error {\n\tswitch e.(type) {\n\tcase nil:\n\t\treturn nil\n\tcase *wireErr:\n\t\treturn e\n\tdefault:\n\t\treturn &wireErr{error: e, position: p}\n\t}\n}\n\n// notePositionAll wraps a list of errors with the given position.\nfunc notePositionAll(p token.Position, errs []error) []error {\n\treturn mapErrors(errs, func(e error) error {\n\t\treturn notePosition(p, e)\n\t})\n}\n\n// Error returns the error message prefixed by the position if valid.\nfunc (w *wireErr) Error() string {\n\tif !w.position.IsValid() {\n\t\treturn w.error.Error()\n\t}\n\treturn w.position.String() + \": \" + w.error.Error()\n}\n"
  },
  {
    "path": "internal/wire/parse.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage wire\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"go/ast\"\n\t\"go/token\"\n\t\"go/types\"\n\t\"os\"\n\t\"reflect\"\n\t\"strconv\"\n\t\"strings\"\n\n\t\"golang.org/x/tools/go/ast/astutil\"\n\t\"golang.org/x/tools/go/packages\"\n\t\"golang.org/x/tools/go/types/typeutil\"\n)\n\n// A providerSetSrc captures the source for a type provided by a ProviderSet.\n// Exactly one of the fields will be set.\ntype providerSetSrc struct {\n\tProvider    *Provider\n\tBinding     *IfaceBinding\n\tValue       *Value\n\tImport      *ProviderSet\n\tInjectorArg *InjectorArg\n\tField       *Field\n}\n\n// description returns a string describing the source of p, including line numbers.\nfunc (p *providerSetSrc) description(fset *token.FileSet, typ types.Type) string {\n\tquoted := func(s string) string {\n\t\tif s == \"\" {\n\t\t\treturn \"\"\n\t\t}\n\t\treturn fmt.Sprintf(\"%q \", s)\n\t}\n\tswitch {\n\tcase p.Provider != nil:\n\t\tkind := \"provider\"\n\t\tif p.Provider.IsStruct {\n\t\t\tkind = \"struct provider\"\n\t\t}\n\t\treturn fmt.Sprintf(\"%s %s(%s)\", kind, quoted(p.Provider.Name), fset.Position(p.Provider.Pos))\n\tcase p.Binding != nil:\n\t\treturn fmt.Sprintf(\"wire.Bind (%s)\", fset.Position(p.Binding.Pos))\n\tcase p.Value != nil:\n\t\treturn fmt.Sprintf(\"wire.Value (%s)\", fset.Position(p.Value.Pos))\n\tcase p.Import != nil:\n\t\treturn fmt.Sprintf(\"provider set %s(%s)\", quoted(p.Import.VarName), fset.Position(p.Import.Pos))\n\tcase p.InjectorArg != nil:\n\t\targs := p.InjectorArg.Args\n\t\treturn fmt.Sprintf(\"argument %s to injector function %s (%s)\", args.Tuple.At(p.InjectorArg.Index).Name(), args.Name, fset.Position(args.Pos))\n\tcase p.Field != nil:\n\t\treturn fmt.Sprintf(\"wire.FieldsOf (%s)\", fset.Position(p.Field.Pos))\n\t}\n\tpanic(\"providerSetSrc with no fields set\")\n}\n\n// trace returns a slice of strings describing the (possibly recursive) source\n// of p, including line numbers.\nfunc (p *providerSetSrc) trace(fset *token.FileSet, typ types.Type) []string {\n\tvar retval []string\n\t// Only Imports need recursion.\n\tif p.Import != nil {\n\t\tif parent := p.Import.srcMap.At(typ); parent != nil {\n\t\t\tretval = append(retval, parent.(*providerSetSrc).trace(fset, typ)...)\n\t\t}\n\t}\n\tretval = append(retval, p.description(fset, typ))\n\treturn retval\n}\n\n// A ProviderSet describes a set of providers.  The zero value is an empty\n// ProviderSet.\ntype ProviderSet struct {\n\t// Pos is the position of the call to wire.NewSet or wire.Build that\n\t// created the set.\n\tPos token.Pos\n\t// PkgPath is the import path of the package that declared this set.\n\tPkgPath string\n\t// VarName is the variable name of the set, if it came from a package\n\t// variable.\n\tVarName string\n\n\tProviders []*Provider\n\tBindings  []*IfaceBinding\n\tValues    []*Value\n\tFields    []*Field\n\tImports   []*ProviderSet\n\t// InjectorArgs is only filled in for wire.Build.\n\tInjectorArgs *InjectorArgs\n\n\t// providerMap maps from provided type to a *ProvidedType.\n\t// It includes all of the imported types.\n\tproviderMap *typeutil.Map\n\n\t// srcMap maps from provided type to a *providerSetSrc capturing the\n\t// Provider, Binding, Value, or Import that provided the type.\n\tsrcMap *typeutil.Map\n}\n\n// Outputs returns a new slice containing the set of possible types the\n// provider set can produce. The order is unspecified.\nfunc (set *ProviderSet) Outputs() []types.Type {\n\treturn set.providerMap.Keys()\n}\n\n// For returns a ProvidedType for the given type, or the zero ProvidedType.\nfunc (set *ProviderSet) For(t types.Type) ProvidedType {\n\tpt := set.providerMap.At(t)\n\tif pt == nil {\n\t\treturn ProvidedType{}\n\t}\n\treturn *pt.(*ProvidedType)\n}\n\n// An IfaceBinding declares that a type should be used to satisfy inputs\n// of the given interface type.\ntype IfaceBinding struct {\n\t// Iface is the interface type, which is what can be injected.\n\tIface types.Type\n\n\t// Provided is always a type that is assignable to Iface.\n\tProvided types.Type\n\n\t// Pos is the position where the binding was declared.\n\tPos token.Pos\n}\n\n// Provider records the signature of a provider. A provider is a\n// single Go object, either a function or a named struct type.\ntype Provider struct {\n\t// Pkg is the package that the Go object resides in.\n\tPkg *types.Package\n\n\t// Name is the name of the Go object.\n\tName string\n\n\t// Pos is the source position of the func keyword or type spec\n\t// defining this provider.\n\tPos token.Pos\n\n\t// Args is the list of data dependencies this provider has.\n\tArgs []ProviderInput\n\n\t// Varargs is true if the provider function is variadic.\n\tVarargs bool\n\n\t// IsStruct is true if this provider is a named struct type.\n\t// Otherwise it's a function.\n\tIsStruct bool\n\n\t// Out is the set of types this provider produces. It will always\n\t// contain at least one type.\n\tOut []types.Type\n\n\t// HasCleanup reports whether the provider function returns a cleanup\n\t// function.  (Always false for structs.)\n\tHasCleanup bool\n\n\t// HasErr reports whether the provider function can return an error.\n\t// (Always false for structs.)\n\tHasErr bool\n}\n\n// ProviderInput describes an incoming edge in the provider graph.\ntype ProviderInput struct {\n\tType types.Type\n\n\t// If the provider is a struct, FieldName will be the field name to set.\n\tFieldName string\n}\n\n// Value describes a value expression.\ntype Value struct {\n\t// Pos is the source position of the expression defining this value.\n\tPos token.Pos\n\n\t// Out is the type this value produces.\n\tOut types.Type\n\n\t// expr is the expression passed to wire.Value.\n\texpr ast.Expr\n\n\t// info is the type info for the expression.\n\tinfo *types.Info\n}\n\n// InjectorArg describes a specific argument passed to an injector function.\ntype InjectorArg struct {\n\t// Args is the full set of arguments.\n\tArgs *InjectorArgs\n\t// Index is the index into Args.Tuple for this argument.\n\tIndex int\n}\n\n// InjectorArgs describes the arguments passed to an injector function.\ntype InjectorArgs struct {\n\t// Name is the name of the injector function.\n\tName string\n\t// Tuple represents the arguments.\n\tTuple *types.Tuple\n\t// Pos is the source position of the injector function.\n\tPos token.Pos\n}\n\n// Field describes a specific field selected from a struct.\ntype Field struct {\n\t// Parent is the struct or pointer to the struct that the field belongs to.\n\tParent types.Type\n\t// Name is the field name.\n\tName string\n\t// Pkg is the package that the struct resides in.\n\tPkg *types.Package\n\t// Pos is the source position of the field declaration.\n\t// defining these fields.\n\tPos token.Pos\n\t// Out is the field's provided types. The first element provides the\n\t// field type. If the field is coming from a pointer to a struct,\n\t// there will be a second element providing a pointer to the field.\n\tOut []types.Type\n}\n\n// Load finds all the provider sets in the packages that match the given\n// patterns, as well as the provider sets' transitive dependencies. It\n// may return both errors and Info. The patterns are defined by the\n// underlying build system. For the go tool, this is described at\n// https://golang.org/cmd/go/#hdr-Package_lists_and_patterns\n//\n// wd is the working directory and env is the set of environment\n// variables to use when loading the packages specified by patterns. If\n// env is nil or empty, it is interpreted as an empty set of variables.\n// In case of duplicate environment variables, the last one in the list\n// takes precedence.\nfunc Load(ctx context.Context, wd string, env []string, tags string, patterns []string) (*Info, []error) {\n\tpkgs, errs := load(ctx, wd, env, tags, patterns)\n\tif len(errs) > 0 {\n\t\treturn nil, errs\n\t}\n\tif len(pkgs) == 0 {\n\t\treturn new(Info), nil\n\t}\n\tfset := pkgs[0].Fset\n\tinfo := &Info{\n\t\tFset: fset,\n\t\tSets: make(map[ProviderSetID]*ProviderSet),\n\t}\n\toc := newObjectCache(pkgs)\n\tec := new(errorCollector)\n\tfor _, pkg := range pkgs {\n\t\tif isWireImport(pkg.PkgPath) {\n\t\t\t// The marker function package confuses analysis.\n\t\t\tcontinue\n\t\t}\n\t\tscope := pkg.Types.Scope()\n\t\tfor _, name := range scope.Names() {\n\t\t\tobj := scope.Lookup(name)\n\t\t\tif !isProviderSetType(obj.Type()) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\titem, errs := oc.get(obj)\n\t\t\tif len(errs) > 0 {\n\t\t\t\tec.add(notePositionAll(fset.Position(obj.Pos()), errs)...)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tpset := item.(*ProviderSet)\n\t\t\t// pset.Name may not equal name, since it could be an alias to\n\t\t\t// another provider set.\n\t\t\tid := ProviderSetID{ImportPath: pset.PkgPath, VarName: name}\n\t\t\tinfo.Sets[id] = pset\n\t\t}\n\t\tfor _, f := range pkg.Syntax {\n\t\t\tfor _, decl := range f.Decls {\n\t\t\t\tfn, ok := decl.(*ast.FuncDecl)\n\t\t\t\tif !ok {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbuildCall, err := findInjectorBuild(pkg.TypesInfo, fn)\n\t\t\t\tif err != nil {\n\t\t\t\t\tec.add(notePosition(fset.Position(fn.Pos()), fmt.Errorf(\"inject %s: %v\", fn.Name.Name, err)))\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif buildCall == nil {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tsig := pkg.TypesInfo.ObjectOf(fn.Name).Type().(*types.Signature)\n\t\t\t\tins, out, err := injectorFuncSignature(sig)\n\t\t\t\tif err != nil {\n\t\t\t\t\tif w, ok := err.(*wireErr); ok {\n\t\t\t\t\t\tec.add(notePosition(w.position, fmt.Errorf(\"inject %s: %v\", fn.Name.Name, w.error)))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tec.add(notePosition(fset.Position(fn.Pos()), fmt.Errorf(\"inject %s: %v\", fn.Name.Name, err)))\n\t\t\t\t\t}\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tinjectorArgs := &InjectorArgs{\n\t\t\t\t\tName:  fn.Name.Name,\n\t\t\t\t\tTuple: ins,\n\t\t\t\t\tPos:   fn.Pos(),\n\t\t\t\t}\n\t\t\t\tset, errs := oc.processNewSet(pkg.TypesInfo, pkg.PkgPath, buildCall, injectorArgs, \"\")\n\t\t\t\tif len(errs) > 0 {\n\t\t\t\t\tec.add(notePositionAll(fset.Position(fn.Pos()), errs)...)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t_, errs = solve(fset, out.out, ins, set)\n\t\t\t\tif len(errs) > 0 {\n\t\t\t\t\tec.add(mapErrors(errs, func(e error) error {\n\t\t\t\t\t\tif w, ok := e.(*wireErr); ok {\n\t\t\t\t\t\t\treturn notePosition(w.position, fmt.Errorf(\"inject %s: %v\", fn.Name.Name, w.error))\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn notePosition(fset.Position(fn.Pos()), fmt.Errorf(\"inject %s: %v\", fn.Name.Name, e))\n\t\t\t\t\t})...)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tinfo.Injectors = append(info.Injectors, &Injector{\n\t\t\t\t\tImportPath: pkg.PkgPath,\n\t\t\t\t\tFuncName:   fn.Name.Name,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\treturn info, ec.errors\n}\n\n// load typechecks the packages that match the given patterns and\n// includes source for all transitive dependencies. The patterns are\n// defined by the underlying build system. For the go tool, this is\n// described at https://golang.org/cmd/go/#hdr-Package_lists_and_patterns\n//\n// wd is the working directory and env is the set of environment\n// variables to use when loading the packages specified by patterns. If\n// env is nil or empty, it is interpreted as an empty set of variables.\n// In case of duplicate environment variables, the last one in the list\n// takes precedence.\nfunc load(ctx context.Context, wd string, env []string, tags string, patterns []string) ([]*packages.Package, []error) {\n\tcfg := &packages.Config{\n\t\tContext:    ctx,\n\t\tMode:       packages.LoadAllSyntax,\n\t\tDir:        wd,\n\t\tEnv:        env,\n\t\tBuildFlags: []string{\"-tags=wireinject\"},\n\t\t// TODO(light): Use ParseFile to skip function bodies and comments in indirect packages.\n\t}\n\tif len(tags) > 0 {\n\t\tcfg.BuildFlags[0] += \" \" + tags\n\t}\n\tescaped := make([]string, len(patterns))\n\tfor i := range patterns {\n\t\tescaped[i] = \"pattern=\" + patterns[i]\n\t}\n\tpkgs, err := packages.Load(cfg, escaped...)\n\tif err != nil {\n\t\treturn nil, []error{err}\n\t}\n\tvar errs []error\n\tfor _, p := range pkgs {\n\t\tfor _, e := range p.Errors {\n\t\t\terrs = append(errs, e)\n\t\t}\n\t}\n\tif len(errs) > 0 {\n\t\treturn nil, errs\n\t}\n\treturn pkgs, nil\n}\n\n// Info holds the result of Load.\ntype Info struct {\n\tFset *token.FileSet\n\n\t// Sets contains all the provider sets in the initial packages.\n\tSets map[ProviderSetID]*ProviderSet\n\n\t// Injectors contains all the injector functions in the initial packages.\n\t// The order is undefined.\n\tInjectors []*Injector\n}\n\n// A ProviderSetID identifies a named provider set.\ntype ProviderSetID struct {\n\tImportPath string\n\tVarName    string\n}\n\n// String returns the ID as \"\"path/to/pkg\".Foo\".\nfunc (id ProviderSetID) String() string {\n\treturn strconv.Quote(id.ImportPath) + \".\" + id.VarName\n}\n\n// An Injector describes an injector function.\ntype Injector struct {\n\tImportPath string\n\tFuncName   string\n}\n\n// String returns the injector name as \"\"path/to/pkg\".Foo\".\nfunc (in *Injector) String() string {\n\treturn strconv.Quote(in.ImportPath) + \".\" + in.FuncName\n}\n\n// objectCache is a lazily evaluated mapping of objects to Wire structures.\ntype objectCache struct {\n\tfset     *token.FileSet\n\tpackages map[string]*packages.Package\n\tobjects  map[objRef]objCacheEntry\n\thasher   typeutil.Hasher\n}\n\ntype objRef struct {\n\timportPath string\n\tname       string\n}\n\ntype objCacheEntry struct {\n\tval  interface{} // *Provider, *ProviderSet, *IfaceBinding, or *Value\n\terrs []error\n}\n\nfunc newObjectCache(pkgs []*packages.Package) *objectCache {\n\tif len(pkgs) == 0 {\n\t\tpanic(\"object cache must have packages to draw from\")\n\t}\n\toc := &objectCache{\n\t\tfset:     pkgs[0].Fset,\n\t\tpackages: make(map[string]*packages.Package),\n\t\tobjects:  make(map[objRef]objCacheEntry),\n\t\thasher:   typeutil.MakeHasher(),\n\t}\n\t// Depth-first search of all dependencies to gather import path to\n\t// packages.Package mapping. go/packages guarantees that for a single\n\t// call to packages.Load and an import path X, there will exist only\n\t// one *packages.Package value with PkgPath X.\n\tstk := append([]*packages.Package(nil), pkgs...)\n\tfor len(stk) > 0 {\n\t\tp := stk[len(stk)-1]\n\t\tstk = stk[:len(stk)-1]\n\t\tif oc.packages[p.PkgPath] != nil {\n\t\t\tcontinue\n\t\t}\n\t\toc.packages[p.PkgPath] = p\n\t\tfor _, imp := range p.Imports {\n\t\t\tstk = append(stk, imp)\n\t\t}\n\t}\n\treturn oc\n}\n\n// get converts a Go object into a Wire structure. It may return a *Provider, an\n// *IfaceBinding, a *ProviderSet, a *Value, or a []*Field.\nfunc (oc *objectCache) get(obj types.Object) (val interface{}, errs []error) {\n\tref := objRef{\n\t\timportPath: obj.Pkg().Path(),\n\t\tname:       obj.Name(),\n\t}\n\tif ent, cached := oc.objects[ref]; cached {\n\t\treturn ent.val, append([]error(nil), ent.errs...)\n\t}\n\tdefer func() {\n\t\toc.objects[ref] = objCacheEntry{\n\t\t\tval:  val,\n\t\t\terrs: append([]error(nil), errs...),\n\t\t}\n\t}()\n\tswitch obj := obj.(type) {\n\tcase *types.Var:\n\t\tspec := oc.varDecl(obj)\n\t\tif spec == nil || len(spec.Values) == 0 {\n\t\t\treturn nil, []error{fmt.Errorf(\"%v is not a provider or a provider set\", obj)}\n\t\t}\n\t\tvar i int\n\t\tfor i = range spec.Names {\n\t\t\tif spec.Names[i].Name == obj.Name() {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tpkgPath := obj.Pkg().Path()\n\t\treturn oc.processExpr(oc.packages[pkgPath].TypesInfo, pkgPath, spec.Values[i], obj.Name())\n\tcase *types.Func:\n\t\treturn processFuncProvider(oc.fset, obj)\n\tdefault:\n\t\treturn nil, []error{fmt.Errorf(\"%v is not a provider or a provider set\", obj)}\n\t}\n}\n\n// varDecl finds the declaration that defines the given variable.\nfunc (oc *objectCache) varDecl(obj *types.Var) *ast.ValueSpec {\n\t// TODO(light): Walk files to build object -> declaration mapping, if more performant.\n\t// Recommended by https://golang.org/s/types-tutorial\n\tpkg := oc.packages[obj.Pkg().Path()]\n\tpos := obj.Pos()\n\tfor _, f := range pkg.Syntax {\n\t\ttokenFile := oc.fset.File(f.Pos())\n\t\tif base := tokenFile.Base(); base <= int(pos) && int(pos) < base+tokenFile.Size() {\n\t\t\tpath, _ := astutil.PathEnclosingInterval(f, pos, pos)\n\t\t\tfor _, node := range path {\n\t\t\t\tif spec, ok := node.(*ast.ValueSpec); ok {\n\t\t\t\t\treturn spec\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\n// processExpr converts an expression into a Wire structure. It may return a\n// *Provider, an *IfaceBinding, a *ProviderSet, a *Value or a []*Field.\nfunc (oc *objectCache) processExpr(info *types.Info, pkgPath string, expr ast.Expr, varName string) (interface{}, []error) {\n\texprPos := oc.fset.Position(expr.Pos())\n\texpr = astutil.Unparen(expr)\n\tif obj := qualifiedIdentObject(info, expr); obj != nil {\n\t\titem, errs := oc.get(obj)\n\t\treturn item, mapErrors(errs, func(err error) error {\n\t\t\treturn notePosition(exprPos, err)\n\t\t})\n\t}\n\tif call, ok := expr.(*ast.CallExpr); ok {\n\t\tfnObj := qualifiedIdentObject(info, call.Fun)\n\t\tif fnObj == nil {\n\t\t\treturn nil, []error{notePosition(exprPos, errors.New(\"unknown pattern fnObj nil\"))}\n\t\t}\n\t\tpkg := fnObj.Pkg()\n\t\tif pkg == nil {\n\t\t\treturn nil, []error{notePosition(exprPos, fmt.Errorf(\"unknown pattern - pkg in fnObj is nil - %s\", fnObj))}\n\t\t}\n\t\tif !isWireImport(pkg.Path()) {\n\t\t\treturn nil, []error{notePosition(exprPos, errors.New(\"unknown pattern\"))}\n\t\t}\n\t\tswitch fnObj.Name() {\n\t\tcase \"NewSet\":\n\t\t\tpset, errs := oc.processNewSet(info, pkgPath, call, nil, varName)\n\t\t\treturn pset, notePositionAll(exprPos, errs)\n\t\tcase \"Bind\":\n\t\t\tb, err := processBind(oc.fset, info, call)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, []error{notePosition(exprPos, err)}\n\t\t\t}\n\t\t\treturn b, nil\n\t\tcase \"Value\":\n\t\t\tv, err := processValue(oc.fset, info, call)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, []error{notePosition(exprPos, err)}\n\t\t\t}\n\t\t\treturn v, nil\n\t\tcase \"InterfaceValue\":\n\t\t\tv, err := processInterfaceValue(oc.fset, info, call)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, []error{notePosition(exprPos, err)}\n\t\t\t}\n\t\t\treturn v, nil\n\t\tcase \"Struct\":\n\t\t\ts, err := processStructProvider(oc.fset, info, call)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, []error{notePosition(exprPos, err)}\n\t\t\t}\n\t\t\treturn s, nil\n\t\tcase \"FieldsOf\":\n\t\t\tv, err := processFieldsOf(oc.fset, info, call)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, []error{notePosition(exprPos, err)}\n\t\t\t}\n\t\t\treturn v, nil\n\t\tdefault:\n\t\t\treturn nil, []error{notePosition(exprPos, errors.New(\"unknown pattern\"))}\n\t\t}\n\t}\n\tif tn := structArgType(info, expr); tn != nil {\n\t\tp, errs := processStructLiteralProvider(oc.fset, tn)\n\t\tif len(errs) > 0 {\n\t\t\treturn nil, notePositionAll(exprPos, errs)\n\t\t}\n\t\treturn p, nil\n\t}\n\treturn nil, []error{notePosition(exprPos, errors.New(\"unknown pattern\"))}\n}\n\nfunc (oc *objectCache) processNewSet(info *types.Info, pkgPath string, call *ast.CallExpr, args *InjectorArgs, varName string) (*ProviderSet, []error) {\n\t// Assumes that call.Fun is wire.NewSet or wire.Build.\n\n\tpset := &ProviderSet{\n\t\tPos:          call.Pos(),\n\t\tInjectorArgs: args,\n\t\tPkgPath:      pkgPath,\n\t\tVarName:      varName,\n\t}\n\tec := new(errorCollector)\n\tfor _, arg := range call.Args {\n\t\titem, errs := oc.processExpr(info, pkgPath, arg, \"\")\n\t\tif len(errs) > 0 {\n\t\t\tec.add(errs...)\n\t\t\tcontinue\n\t\t}\n\t\tswitch item := item.(type) {\n\t\tcase *Provider:\n\t\t\tpset.Providers = append(pset.Providers, item)\n\t\tcase *ProviderSet:\n\t\t\tpset.Imports = append(pset.Imports, item)\n\t\tcase *IfaceBinding:\n\t\t\tpset.Bindings = append(pset.Bindings, item)\n\t\tcase *Value:\n\t\t\tpset.Values = append(pset.Values, item)\n\t\tcase []*Field:\n\t\t\tpset.Fields = append(pset.Fields, item...)\n\t\tdefault:\n\t\t\tpanic(\"unknown item type\")\n\t\t}\n\t}\n\tif len(ec.errors) > 0 {\n\t\treturn nil, ec.errors\n\t}\n\tvar errs []error\n\tpset.providerMap, pset.srcMap, errs = buildProviderMap(oc.fset, oc.hasher, pset)\n\tif len(errs) > 0 {\n\t\treturn nil, errs\n\t}\n\tif errs := verifyAcyclic(pset.providerMap, oc.hasher); len(errs) > 0 {\n\t\treturn nil, errs\n\t}\n\treturn pset, nil\n}\n\n// structArgType attempts to interpret an expression as a simple struct type.\n// It assumes any parentheses have been stripped.\nfunc structArgType(info *types.Info, expr ast.Expr) *types.TypeName {\n\tlit, ok := expr.(*ast.CompositeLit)\n\tif !ok {\n\t\treturn nil\n\t}\n\ttn, ok := qualifiedIdentObject(info, lit.Type).(*types.TypeName)\n\tif !ok {\n\t\treturn nil\n\t}\n\tif _, isStruct := tn.Type().Underlying().(*types.Struct); !isStruct {\n\t\treturn nil\n\t}\n\treturn tn\n}\n\n// qualifiedIdentObject finds the object for an identifier or a\n// qualified identifier, or nil if the object could not be found.\nfunc qualifiedIdentObject(info *types.Info, expr ast.Expr) types.Object {\n\tswitch expr := expr.(type) {\n\tcase *ast.Ident:\n\t\treturn info.ObjectOf(expr)\n\tcase *ast.SelectorExpr:\n\t\tpkgName, ok := expr.X.(*ast.Ident)\n\t\tif !ok {\n\t\t\treturn nil\n\t\t}\n\t\tif _, ok := info.ObjectOf(pkgName).(*types.PkgName); !ok {\n\t\t\treturn nil\n\t\t}\n\t\treturn info.ObjectOf(expr.Sel)\n\tdefault:\n\t\treturn nil\n\t}\n}\n\n// processFuncProvider creates a provider for a function declaration.\nfunc processFuncProvider(fset *token.FileSet, fn *types.Func) (*Provider, []error) {\n\tsig := fn.Type().(*types.Signature)\n\tfpos := fn.Pos()\n\tproviderSig, err := funcOutput(sig)\n\tif err != nil {\n\t\treturn nil, []error{notePosition(fset.Position(fpos), fmt.Errorf(\"wrong signature for provider %s: %v\", fn.Name(), err))}\n\t}\n\tparams := sig.Params()\n\tprovider := &Provider{\n\t\tPkg:        fn.Pkg(),\n\t\tName:       fn.Name(),\n\t\tPos:        fn.Pos(),\n\t\tArgs:       make([]ProviderInput, params.Len()),\n\t\tVarargs:    sig.Variadic(),\n\t\tOut:        []types.Type{providerSig.out},\n\t\tHasCleanup: providerSig.cleanup,\n\t\tHasErr:     providerSig.err,\n\t}\n\tfor i := 0; i < params.Len(); i++ {\n\t\tprovider.Args[i] = ProviderInput{\n\t\t\tType: params.At(i).Type(),\n\t\t}\n\t\tfor j := 0; j < i; j++ {\n\t\t\tif types.Identical(provider.Args[i].Type, provider.Args[j].Type) {\n\t\t\t\treturn nil, []error{notePosition(fset.Position(fpos), fmt.Errorf(\"provider has multiple parameters of type %s\", types.TypeString(provider.Args[j].Type, nil)))}\n\t\t\t}\n\t\t}\n\t}\n\treturn provider, nil\n}\n\nfunc injectorFuncSignature(sig *types.Signature) (*types.Tuple, outputSignature, error) {\n\tout, err := funcOutput(sig)\n\tif err != nil {\n\t\treturn nil, outputSignature{}, err\n\t}\n\treturn sig.Params(), out, nil\n}\n\ntype outputSignature struct {\n\tout     types.Type\n\tcleanup bool\n\terr     bool\n}\n\n// funcOutput validates an injector or provider function's return signature.\nfunc funcOutput(sig *types.Signature) (outputSignature, error) {\n\tresults := sig.Results()\n\tswitch results.Len() {\n\tcase 0:\n\t\treturn outputSignature{}, errors.New(\"no return values\")\n\tcase 1:\n\t\treturn outputSignature{out: results.At(0).Type()}, nil\n\tcase 2:\n\t\tout := results.At(0).Type()\n\t\tswitch t := results.At(1).Type(); {\n\t\tcase types.Identical(t, errorType):\n\t\t\treturn outputSignature{out: out, err: true}, nil\n\t\tcase types.Identical(t, cleanupType):\n\t\t\treturn outputSignature{out: out, cleanup: true}, nil\n\t\tdefault:\n\t\t\treturn outputSignature{}, fmt.Errorf(\"second return type is %s; must be error or func()\", types.TypeString(t, nil))\n\t\t}\n\tcase 3:\n\t\tif t := results.At(1).Type(); !types.Identical(t, cleanupType) {\n\t\t\treturn outputSignature{}, fmt.Errorf(\"second return type is %s; must be func()\", types.TypeString(t, nil))\n\t\t}\n\t\tif t := results.At(2).Type(); !types.Identical(t, errorType) {\n\t\t\treturn outputSignature{}, fmt.Errorf(\"third return type is %s; must be error\", types.TypeString(t, nil))\n\t\t}\n\t\treturn outputSignature{\n\t\t\tout:     results.At(0).Type(),\n\t\t\tcleanup: true,\n\t\t\terr:     true,\n\t\t}, nil\n\tdefault:\n\t\treturn outputSignature{}, errors.New(\"too many return values\")\n\t}\n}\n\n// processStructLiteralProvider creates a provider for a named struct type.\n// It produces pointer and non-pointer variants via two values in Out.\n//\n// This is a copy of the old processStructProvider, which is deprecated now.\n// It will not support any new feature introduced after v0.2. Please use the new\n// wire.Struct syntax for those.\nfunc processStructLiteralProvider(fset *token.FileSet, typeName *types.TypeName) (*Provider, []error) {\n\tout := typeName.Type()\n\tst, ok := out.Underlying().(*types.Struct)\n\tif !ok {\n\t\treturn nil, []error{fmt.Errorf(\"%v does not name a struct\", typeName)}\n\t}\n\n\tpos := typeName.Pos()\n\tfmt.Fprintf(os.Stderr,\n\t\t\"Warning: %v, see https://godoc.org/github.com/google/wire#Struct for more information.\\n\",\n\t\tnotePosition(fset.Position(pos),\n\t\t\tfmt.Errorf(\"using struct literal to inject %s is deprecated and will be removed in the next release; use wire.Struct instead\",\n\t\t\t\ttypeName.Type())))\n\tprovider := &Provider{\n\t\tPkg:      typeName.Pkg(),\n\t\tName:     typeName.Name(),\n\t\tPos:      pos,\n\t\tArgs:     make([]ProviderInput, st.NumFields()),\n\t\tIsStruct: true,\n\t\tOut:      []types.Type{out, types.NewPointer(out)},\n\t}\n\tfor i := 0; i < st.NumFields(); i++ {\n\t\tf := st.Field(i)\n\t\tprovider.Args[i] = ProviderInput{\n\t\t\tType:      f.Type(),\n\t\t\tFieldName: f.Name(),\n\t\t}\n\t\tfor j := 0; j < i; j++ {\n\t\t\tif types.Identical(provider.Args[i].Type, provider.Args[j].Type) {\n\t\t\t\treturn nil, []error{notePosition(fset.Position(pos), fmt.Errorf(\"provider struct has multiple fields of type %s\", types.TypeString(provider.Args[j].Type, nil)))}\n\t\t\t}\n\t\t}\n\t}\n\treturn provider, nil\n}\n\n// processStructProvider creates a provider for a named struct type.\n// It produces pointer and non-pointer variants via two values in Out.\nfunc processStructProvider(fset *token.FileSet, info *types.Info, call *ast.CallExpr) (*Provider, error) {\n\t// Assumes that call.Fun is wire.Struct.\n\n\tif len(call.Args) < 1 {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\terrors.New(\"call to Struct must specify the struct to be injected\"))\n\t}\n\tconst firstArgReqFormat = \"first argument to Struct must be a pointer to a named struct; found %s\"\n\tstructType := info.TypeOf(call.Args[0])\n\tstructPtr, ok := structType.(*types.Pointer)\n\tif !ok {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\tfmt.Errorf(firstArgReqFormat, types.TypeString(structType, nil)))\n\t}\n\n\tst, ok := structPtr.Elem().Underlying().(*types.Struct)\n\tif !ok {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\tfmt.Errorf(firstArgReqFormat, types.TypeString(structPtr, nil)))\n\t}\n\n\tstExpr := call.Args[0].(*ast.CallExpr)\n\ttypeName := qualifiedIdentObject(info, stExpr.Args[0]) // should be either an identifier or selector\n\tprovider := &Provider{\n\t\tPkg:      typeName.Pkg(),\n\t\tName:     typeName.Name(),\n\t\tPos:      typeName.Pos(),\n\t\tIsStruct: true,\n\t\tOut:      []types.Type{structPtr.Elem(), structPtr},\n\t}\n\tif allFields(call) {\n\t\tfor i := 0; i < st.NumFields(); i++ {\n\t\t\tif isPrevented(st.Tag(i)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tf := st.Field(i)\n\t\t\tprovider.Args = append(provider.Args, ProviderInput{\n\t\t\t\tType:      f.Type(),\n\t\t\t\tFieldName: f.Name(),\n\t\t\t})\n\t\t}\n\t} else {\n\t\tprovider.Args = make([]ProviderInput, len(call.Args)-1)\n\t\tfor i := 1; i < len(call.Args); i++ {\n\t\t\tv, err := checkField(call.Args[i], st)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, notePosition(fset.Position(call.Pos()), err)\n\t\t\t}\n\t\t\tprovider.Args[i-1] = ProviderInput{\n\t\t\t\tType:      v.Type(),\n\t\t\t\tFieldName: v.Name(),\n\t\t\t}\n\t\t}\n\t}\n\tfor i := 0; i < len(provider.Args); i++ {\n\t\tfor j := 0; j < i; j++ {\n\t\t\tif types.Identical(provider.Args[i].Type, provider.Args[j].Type) {\n\t\t\t\tf := st.Field(j)\n\t\t\t\treturn nil, notePosition(fset.Position(f.Pos()), fmt.Errorf(\"provider struct has multiple fields of type %s\", types.TypeString(provider.Args[j].Type, nil)))\n\t\t\t}\n\t\t}\n\t}\n\treturn provider, nil\n}\n\nfunc allFields(call *ast.CallExpr) bool {\n\tif len(call.Args) != 2 {\n\t\treturn false\n\t}\n\tb, ok := call.Args[1].(*ast.BasicLit)\n\tif !ok {\n\t\treturn false\n\t}\n\treturn strings.EqualFold(strconv.Quote(\"*\"), b.Value)\n}\n\n// isPrevented checks whether field i is prevented by tag \"-\".\n// Since this is the only tag used by wire, we can do string comparison\n// without using reflect.\nfunc isPrevented(tag string) bool {\n\treturn reflect.StructTag(tag).Get(\"wire\") == \"-\"\n}\n\n// processBind creates an interface binding from a wire.Bind call.\nfunc processBind(fset *token.FileSet, info *types.Info, call *ast.CallExpr) (*IfaceBinding, error) {\n\t// Assumes that call.Fun is wire.Bind.\n\n\tif len(call.Args) != 2 {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\terrors.New(\"call to Bind takes exactly two arguments\"))\n\t}\n\t// TODO(light): Verify that arguments are simple expressions.\n\tifaceArgType := info.TypeOf(call.Args[0])\n\tifacePtr, ok := ifaceArgType.(*types.Pointer)\n\tif !ok {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\tfmt.Errorf(\"first argument to Bind must be a pointer to an interface type; found %s\", types.TypeString(ifaceArgType, nil)))\n\t}\n\tiface := ifacePtr.Elem()\n\tmethodSet, ok := iface.Underlying().(*types.Interface)\n\tif !ok {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\tfmt.Errorf(\"first argument to Bind must be a pointer to an interface type; found %s\", types.TypeString(ifaceArgType, nil)))\n\t}\n\n\tprovided := info.TypeOf(call.Args[1])\n\tif bindShouldUsePointer(info, call) {\n\t\tprovidedPtr, ok := provided.(*types.Pointer)\n\t\tif !ok {\n\t\t\treturn nil, notePosition(fset.Position(call.Args[0].Pos()),\n\t\t\t\tfmt.Errorf(\"second argument to Bind must be a pointer or a pointer to a pointer; found %s\", types.TypeString(provided, nil)))\n\t\t}\n\t\tprovided = providedPtr.Elem()\n\t}\n\tif types.Identical(iface, provided) {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\terrors.New(\"cannot bind interface to itself\"))\n\t}\n\tif !types.Implements(provided, methodSet) {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\tfmt.Errorf(\"%s does not implement %s\", types.TypeString(provided, nil), types.TypeString(iface, nil)))\n\t}\n\treturn &IfaceBinding{\n\t\tPos:      call.Pos(),\n\t\tIface:    iface,\n\t\tProvided: provided,\n\t}, nil\n}\n\n// processValue creates a value from a wire.Value call.\nfunc processValue(fset *token.FileSet, info *types.Info, call *ast.CallExpr) (*Value, error) {\n\t// Assumes that call.Fun is wire.Value.\n\n\tif len(call.Args) != 1 {\n\t\treturn nil, notePosition(fset.Position(call.Pos()), errors.New(\"call to Value takes exactly one argument\"))\n\t}\n\tok := true\n\tast.Inspect(call.Args[0], func(node ast.Node) bool {\n\t\tswitch expr := node.(type) {\n\t\tcase nil, *ast.ArrayType, *ast.BasicLit, *ast.BinaryExpr, *ast.ChanType, *ast.CompositeLit, *ast.FuncType, *ast.Ident, *ast.IndexExpr, *ast.InterfaceType, *ast.KeyValueExpr, *ast.MapType, *ast.ParenExpr, *ast.SelectorExpr, *ast.SliceExpr, *ast.StarExpr, *ast.StructType, *ast.TypeAssertExpr:\n\t\t\t// Good!\n\t\tcase *ast.UnaryExpr:\n\t\t\tif expr.Op == token.ARROW {\n\t\t\t\tok = false\n\t\t\t\treturn false\n\t\t\t}\n\t\tcase *ast.CallExpr:\n\t\t\t// Only acceptable if it's a type conversion.\n\t\t\tif _, isFunc := info.TypeOf(expr.Fun).(*types.Signature); isFunc {\n\t\t\t\tok = false\n\t\t\t\treturn false\n\t\t\t}\n\t\tdefault:\n\t\t\tok = false\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t})\n\tif !ok {\n\t\treturn nil, notePosition(fset.Position(call.Pos()), errors.New(\"argument to Value is too complex\"))\n\t}\n\t// Result type can't be an interface type; use wire.InterfaceValue for that.\n\targType := info.TypeOf(call.Args[0])\n\tif _, isInterfaceType := argType.Underlying().(*types.Interface); isInterfaceType {\n\t\treturn nil, notePosition(fset.Position(call.Pos()), fmt.Errorf(\"argument to Value may not be an interface value (found %s); use InterfaceValue instead\", types.TypeString(argType, nil)))\n\t}\n\treturn &Value{\n\t\tPos:  call.Args[0].Pos(),\n\t\tOut:  info.TypeOf(call.Args[0]),\n\t\texpr: call.Args[0],\n\t\tinfo: info,\n\t}, nil\n}\n\n// processInterfaceValue creates a value from a wire.InterfaceValue call.\nfunc processInterfaceValue(fset *token.FileSet, info *types.Info, call *ast.CallExpr) (*Value, error) {\n\t// Assumes that call.Fun is wire.InterfaceValue.\n\n\tif len(call.Args) != 2 {\n\t\treturn nil, notePosition(fset.Position(call.Pos()), errors.New(\"call to InterfaceValue takes exactly two arguments\"))\n\t}\n\tifaceArgType := info.TypeOf(call.Args[0])\n\tifacePtr, ok := ifaceArgType.(*types.Pointer)\n\tif !ok {\n\t\treturn nil, notePosition(fset.Position(call.Pos()), fmt.Errorf(\"first argument to InterfaceValue must be a pointer to an interface type; found %s\", types.TypeString(ifaceArgType, nil)))\n\t}\n\tiface := ifacePtr.Elem()\n\tmethodSet, ok := iface.Underlying().(*types.Interface)\n\tif !ok {\n\t\treturn nil, notePosition(fset.Position(call.Pos()), fmt.Errorf(\"first argument to InterfaceValue must be a pointer to an interface type; found %s\", types.TypeString(ifaceArgType, nil)))\n\t}\n\tprovided := info.TypeOf(call.Args[1])\n\tif !types.Implements(provided, methodSet) {\n\t\treturn nil, notePosition(fset.Position(call.Pos()), fmt.Errorf(\"%s does not implement %s\", types.TypeString(provided, nil), types.TypeString(iface, nil)))\n\t}\n\treturn &Value{\n\t\tPos:  call.Args[1].Pos(),\n\t\tOut:  iface,\n\t\texpr: call.Args[1],\n\t\tinfo: info,\n\t}, nil\n}\n\n// processFieldsOf creates a slice of fields from a wire.FieldsOf call.\nfunc processFieldsOf(fset *token.FileSet, info *types.Info, call *ast.CallExpr) ([]*Field, error) {\n\t// Assumes that call.Fun is wire.FieldsOf.\n\n\tif len(call.Args) < 2 {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\terrors.New(\"call to FieldsOf must specify fields to be extracted\"))\n\t}\n\tconst firstArgReqFormat = \"first argument to FieldsOf must be a pointer to a struct or a pointer to a pointer to a struct; found %s\"\n\tstructType := info.TypeOf(call.Args[0])\n\tstructPtr, ok := structType.(*types.Pointer)\n\tif !ok {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\tfmt.Errorf(firstArgReqFormat, types.TypeString(structType, nil)))\n\t}\n\n\tvar struc *types.Struct\n\tisPtrToStruct := false\n\tswitch t := structPtr.Elem().Underlying().(type) {\n\tcase *types.Pointer:\n\t\tstruc, ok = t.Elem().Underlying().(*types.Struct)\n\t\tif !ok {\n\t\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\t\tfmt.Errorf(firstArgReqFormat, types.TypeString(struc, nil)))\n\t\t}\n\t\tisPtrToStruct = true\n\tcase *types.Struct:\n\t\tstruc = t\n\tdefault:\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\tfmt.Errorf(firstArgReqFormat, types.TypeString(t, nil)))\n\t}\n\tif struc.NumFields() < len(call.Args)-1 {\n\t\treturn nil, notePosition(fset.Position(call.Pos()),\n\t\t\tfmt.Errorf(\"fields number exceeds the number available in the struct which has %d fields\", struc.NumFields()))\n\t}\n\n\tfields := make([]*Field, 0, len(call.Args)-1)\n\tfor i := 1; i < len(call.Args); i++ {\n\t\tv, err := checkField(call.Args[i], struc)\n\t\tif err != nil {\n\t\t\treturn nil, notePosition(fset.Position(call.Pos()), err)\n\t\t}\n\t\tout := []types.Type{v.Type()}\n\t\tif isPtrToStruct {\n\t\t\t// If the field is from a pointer to a struct, then\n\t\t\t// wire.Fields also provides a pointer to the field.\n\t\t\tout = append(out, types.NewPointer(v.Type()))\n\t\t}\n\t\tfields = append(fields, &Field{\n\t\t\tParent: structPtr.Elem(),\n\t\t\tName:   v.Name(),\n\t\t\tPkg:    v.Pkg(),\n\t\t\tPos:    v.Pos(),\n\t\t\tOut:    out,\n\t\t})\n\t}\n\treturn fields, nil\n}\n\n// checkField reports whether f is a field of st. f should be a string with the\n// field name.\nfunc checkField(f ast.Expr, st *types.Struct) (*types.Var, error) {\n\tb, ok := f.(*ast.BasicLit)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"%v must be a string with the field name\", f)\n\t}\n\tfor i := 0; i < st.NumFields(); i++ {\n\t\tif strings.EqualFold(strconv.Quote(st.Field(i).Name()), b.Value) {\n\t\t\tif isPrevented(st.Tag(i)) {\n\t\t\t\treturn nil, fmt.Errorf(\"%s is prevented from injecting by wire\", b.Value)\n\t\t\t}\n\t\t\treturn st.Field(i), nil\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"%s is not a field of %s\", b.Value, st.String())\n}\n\n// findInjectorBuild returns the wire.Build call if fn is an injector template.\n// It returns nil if the function is not an injector template.\nfunc findInjectorBuild(info *types.Info, fn *ast.FuncDecl) (*ast.CallExpr, error) {\n\tif fn.Body == nil {\n\t\treturn nil, nil\n\t}\n\tnumStatements := 0\n\tinvalid := false\n\tvar wireBuildCall *ast.CallExpr\n\tfor _, stmt := range fn.Body.List {\n\t\tswitch stmt := stmt.(type) {\n\t\tcase *ast.ExprStmt:\n\t\t\tnumStatements++\n\t\t\tif numStatements > 1 {\n\t\t\t\tinvalid = true\n\t\t\t}\n\t\t\tcall, ok := stmt.X.(*ast.CallExpr)\n\t\t\tif !ok {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif qualifiedIdentObject(info, call.Fun) == types.Universe.Lookup(\"panic\") {\n\t\t\t\tif len(call.Args) != 1 {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tcall, ok = call.Args[0].(*ast.CallExpr)\n\t\t\t\tif !ok {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\tbuildObj := qualifiedIdentObject(info, call.Fun)\n\t\t\tif buildObj == nil || buildObj.Pkg() == nil || !isWireImport(buildObj.Pkg().Path()) || buildObj.Name() != \"Build\" {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twireBuildCall = call\n\t\tcase *ast.EmptyStmt:\n\t\t\t// Do nothing.\n\t\tcase *ast.ReturnStmt:\n\t\t\t// Allow the function to end in a return.\n\t\t\tif numStatements == 0 {\n\t\t\t\treturn nil, nil\n\t\t\t}\n\t\tdefault:\n\t\t\tinvalid = true\n\t\t}\n\n\t}\n\tif wireBuildCall == nil {\n\t\treturn nil, nil\n\t}\n\tif invalid {\n\t\treturn nil, errors.New(\"a call to wire.Build indicates that this function is an injector, but injectors must consist of only the wire.Build call and an optional return\")\n\t}\n\treturn wireBuildCall, nil\n}\n\nfunc isWireImport(path string) bool {\n\t// TODO(light): This is depending on details of the current loader.\n\tconst vendorPart = \"vendor/\"\n\tif i := strings.LastIndex(path, vendorPart); i != -1 && (i == 0 || path[i-1] == '/') {\n\t\tpath = path[i+len(vendorPart):]\n\t}\n\treturn path == \"github.com/google/wire\"\n}\n\nfunc isProviderSetType(t types.Type) bool {\n\tn, ok := t.(*types.Named)\n\tif !ok {\n\t\treturn false\n\t}\n\tobj := n.Obj()\n\treturn obj.Pkg() != nil && isWireImport(obj.Pkg().Path()) && obj.Name() == \"ProviderSet\"\n}\n\n// ProvidedType represents a type provided from a source. The source\n// can be a *Provider (a provider function), a *Value (wire.Value), or an\n// *InjectorArgs (arguments to the injector function). The zero value has\n// none of the above, and returns true for IsNil.\ntype ProvidedType struct {\n\t// t is the provided concrete type.\n\tt types.Type\n\tp *Provider\n\tv *Value\n\ta *InjectorArg\n\tf *Field\n}\n\n// IsNil reports whether pt is the zero value.\nfunc (pt ProvidedType) IsNil() bool {\n\treturn pt.p == nil && pt.v == nil && pt.a == nil && pt.f == nil\n}\n\n// Type returns the output type.\n//\n//   - For a function provider, this is the first return value type.\n//   - For a struct provider, this is either the struct type or the pointer type\n//     whose element type is the struct type.\n//   - For a value, this is the type of the expression.\n//   - For an argument, this is the type of the argument.\nfunc (pt ProvidedType) Type() types.Type {\n\treturn pt.t\n}\n\n// IsProvider reports whether pt points to a Provider.\nfunc (pt ProvidedType) IsProvider() bool {\n\treturn pt.p != nil\n}\n\n// IsValue reports whether pt points to a Value.\nfunc (pt ProvidedType) IsValue() bool {\n\treturn pt.v != nil\n}\n\n// IsArg reports whether pt points to an injector argument.\nfunc (pt ProvidedType) IsArg() bool {\n\treturn pt.a != nil\n}\n\n// IsField reports whether pt points to a Fields.\nfunc (pt ProvidedType) IsField() bool {\n\treturn pt.f != nil\n}\n\n// Provider returns pt as a Provider pointer. It panics if pt does not point\n// to a Provider.\nfunc (pt ProvidedType) Provider() *Provider {\n\tif pt.p == nil {\n\t\tpanic(\"ProvidedType does not hold a Provider\")\n\t}\n\treturn pt.p\n}\n\n// Value returns pt as a Value pointer. It panics if pt does not point\n// to a Value.\nfunc (pt ProvidedType) Value() *Value {\n\tif pt.v == nil {\n\t\tpanic(\"ProvidedType does not hold a Value\")\n\t}\n\treturn pt.v\n}\n\n// Arg returns pt as an *InjectorArg representing an injector argument. It\n// panics if pt does not point to an arg.\nfunc (pt ProvidedType) Arg() *InjectorArg {\n\tif pt.a == nil {\n\t\tpanic(\"ProvidedType does not hold an Arg\")\n\t}\n\treturn pt.a\n}\n\n// Field returns pt as a Field pointer. It panics if pt does not point to a\n// struct Field.\nfunc (pt ProvidedType) Field() *Field {\n\tif pt.f == nil {\n\t\tpanic(\"ProvidedType does not hold a Field\")\n\t}\n\treturn pt.f\n}\n\n// bindShouldUsePointer loads the wire package the user is importing from their\n// injector. The call is a wire marker function call.\nfunc bindShouldUsePointer(info *types.Info, call *ast.CallExpr) bool {\n\t// These type assertions should not fail, otherwise panic.\n\tfun := call.Fun.(*ast.SelectorExpr)                 // wire.Bind\n\tpkgName := fun.X.(*ast.Ident)                       // wire\n\twireName := info.ObjectOf(pkgName).(*types.PkgName) // wire package\n\treturn wireName.Imported().Scope().Lookup(\"bindToUsePointer\") != nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArg/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(inject(Foo{\"hello\"}).Name)\n}\n\ntype Fooer interface {\n\tFoo() string\n}\n\ntype Foo struct {\n\tf string\n}\n\nfunc (f Foo) Foo() string {\n\treturn f.f\n}\n\ntype Bar struct {\n\tName string\n}\n\nfunc NewBar(fooer Fooer) *Bar {\n\treturn &Bar{Name: fooer.Foo()}\n}\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArg/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc inject(foo Foo) *Bar {\n\twire.Build(\n\t\tNewBar,\n\t\twire.Bind(new(Fooer), new(Foo)),\n\t)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArg/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArg/want/program_out.txt",
    "content": "hello\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArg/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc inject(foo Foo) *Bar {\n\tbar := NewBar(foo)\n\treturn bar\n}\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArgPointer/foo/foo.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(inject(&Foo{\"hello\"}).Name)\n}\n\ntype Fooer interface {\n\tFoo() string\n}\n\ntype Foo struct {\n\tf string\n}\n\nfunc (f *Foo) Foo() string {\n\treturn f.f\n}\n\ntype Bar struct {\n\tName string\n}\n\nfunc NewBar(fooer Fooer) *Bar {\n\treturn &Bar{Name: fooer.Foo()}\n}\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArgPointer/foo/wire.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc inject(foo *Foo) *Bar {\n\twire.Build(\n\t\tNewBar,\n\t\twire.Bind(new(Fooer), new(*Foo)),\n\t)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArgPointer/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArgPointer/want/program_out.txt",
    "content": "hello\n"
  },
  {
    "path": "internal/wire/testdata/BindInjectorArgPointer/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc inject(foo *Foo) *Bar {\n\tbar := NewBar(foo)\n\treturn bar\n}\n"
  },
  {
    "path": "internal/wire/testdata/BindInterfaceWithValue/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nfunc main() {\n\tw := inject()\n\tw.Write([]byte(\"Hello, World!\"))\n}\n"
  },
  {
    "path": "internal/wire/testdata/BindInterfaceWithValue/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\n//+build wireinject\n\npackage main\n\nimport (\n\t\"io\"\n\t\"os\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc inject() io.Writer {\n\twire.Build(\n\t\twire.Value(os.Stdout),\n\t\twire.Bind(new(io.Writer), new(*os.File)),\n\t)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/BindInterfaceWithValue/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/BindInterfaceWithValue/want/program_out.txt",
    "content": "Hello, World!"
  },
  {
    "path": "internal/wire/testdata/BindInterfaceWithValue/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"io\"\n\t\"os\"\n)\n\n// Injectors from wire.go:\n\nfunc inject() io.Writer {\n\tfile := _wireFileValue\n\treturn file\n}\n\nvar (\n\t_wireFileValue = os.Stdout\n)\n"
  },
  {
    "path": "internal/wire/testdata/BuildTagsAllPackages/bar/bar.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build !wireinject\n\n// Package bar includes both wireinject and non-wireinject variants.\npackage bar\n\nimport \"github.com/google/wire\"\n\n// Set provides an unfriendly user greeting.\nvar Set = wire.NewSet(wire.Value(\"Bah humbug! This is the wrong variant!\"))\n"
  },
  {
    "path": "internal/wire/testdata/BuildTagsAllPackages/bar/bar_inject.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage bar\n\nimport \"github.com/google/wire\"\n\n// Set provides a friendly user greeting.\nvar Set = wire.NewSet(wire.Value(\"Hello, World!\"))\n"
  },
  {
    "path": "internal/wire/testdata/BuildTagsAllPackages/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n"
  },
  {
    "path": "internal/wire/testdata/BuildTagsAllPackages/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"example.com/bar\"\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\twire.Build(bar.Set)\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/BuildTagsAllPackages/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/BuildTagsAllPackages/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/BuildTagsAllPackages/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage() string {\n\tstring2 := _wireStringValue\n\treturn string2\n}\n\nvar (\n\t_wireStringValue = \"Hello, World!\"\n)\n"
  },
  {
    "path": "internal/wire/testdata/Chain/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooBar())\n}\n\ntype Foo int\ntype FooBar int\n\nvar Set = wire.NewSet(\n\tprovideFoo,\n\tprovideFooBar)\n\nfunc provideFoo() Foo {\n\treturn 41\n}\n\nfunc provideFooBar(foo Foo) FooBar {\n\treturn FooBar(foo) + 1\n}\n"
  },
  {
    "path": "internal/wire/testdata/Chain/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooBar() FooBar {\n\twire.Build(Set)\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/Chain/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/Chain/want/program_out.txt",
    "content": "42\n"
  },
  {
    "path": "internal/wire/testdata/Chain/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFooBar() FooBar {\n\tfoo := provideFoo()\n\tfooBar := provideFooBar(foo)\n\treturn fooBar\n}\n"
  },
  {
    "path": "internal/wire/testdata/Cleanup/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tbar, cleanup := injectBar()\n\tfmt.Println(*bar)\n\tcleanup()\n\tfmt.Println(*bar)\n}\n\ntype Foo int\ntype Bar int\n\nfunc provideFoo() (*Foo, func()) {\n\tfoo := new(Foo)\n\t*foo = 42\n\treturn foo, func() { *foo = 0 }\n}\n\nfunc provideBar(foo *Foo) (*Bar, func()) {\n\tbar := new(Bar)\n\t*bar = 77\n\treturn bar, func() {\n\t\tif *foo == 0 {\n\t\t\tpanic(\"foo cleaned up before bar\")\n\t\t}\n\t\t*bar = 0\n\t}\n}\n"
  },
  {
    "path": "internal/wire/testdata/Cleanup/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectBar() (*Bar, func()) {\n\twire.Build(provideFoo, provideBar)\n\treturn nil, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/Cleanup/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/Cleanup/want/program_out.txt",
    "content": "77\n0\n"
  },
  {
    "path": "internal/wire/testdata/Cleanup/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectBar() (*Bar, func()) {\n\tfoo, cleanup := provideFoo()\n\tbar, cleanup2 := provideBar(foo)\n\treturn bar, func() {\n\t\tcleanup2()\n\t\tcleanup()\n\t}\n}\n"
  },
  {
    "path": "internal/wire/testdata/CopyOtherDecls/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\n// All of the declarations are in one file.\n// Wire should copy non-injectors over, preserving imports.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n\n// provideMessage provides a friendly user greeting.\nfunc provideMessage() string {\n\treturn \"Hello, World!\"\n}\n\nfunc injectedMessage() string {\n\twire.Build(provideMessage)\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/CopyOtherDecls/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/CopyOtherDecls/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/CopyOtherDecls/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// Injectors from foo.go:\n\nfunc injectedMessage() string {\n\tstring2 := provideMessage()\n\treturn string2\n}\n\n// foo.go:\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n\n// provideMessage provides a friendly user greeting.\nfunc provideMessage() string {\n\treturn \"Hello, World!\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/Cycle/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedBaz())\n}\n\ntype Foo int\ntype Bar int\ntype Baz int\n\nfunc provideFoo(_ Baz) Foo {\n\treturn 0\n}\n\nfunc provideBar(_ Foo) Bar {\n\treturn 0\n}\n\nfunc provideBaz(_ Bar) Baz {\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/Cycle/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedBaz() Baz {\n\twire.Build(provideFoo, provideBar, provideBaz)\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/Cycle/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/Cycle/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: cycle for example.com/foo.Bar:\nexample.com/foo.Bar (example.com/foo.provideBar) ->\nexample.com/foo.Foo (example.com/foo.provideFoo) ->\nexample.com/foo.Baz (example.com/foo.provideBaz) ->\nexample.com/foo.Bar"
  },
  {
    "path": "internal/wire/testdata/DocComment/foo/foo.go",
    "content": "// Copyright 2020 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\ntype (\n\tBar struct{}\n\tFoo struct{}\n)\n\nfunc main() {\n\tfmt.Println(\"Hello, World\")\n}\n"
  },
  {
    "path": "internal/wire/testdata/DocComment/foo/wire.go",
    "content": "// Copyright 2020 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n//\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\n/* blockComment returns Foo and has a /*- style doc comment */\nfunc blockComment() *Foo {\n\tpanic(wire.Build(wire.Struct(new(Foo))))\n}\n\n// lineComment returns Bar and has a //- style doc comment\nfunc lineComment() *Bar {\n\tpanic(wire.Build(wire.Struct(new(Bar))))\n}\n"
  },
  {
    "path": "internal/wire/testdata/DocComment/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/DocComment/want/program_out.txt",
    "content": "Hello, World\n"
  },
  {
    "path": "internal/wire/testdata/DocComment/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\n/* blockComment returns Foo and has a /*- style doc comment */\nfunc blockComment() *Foo {\n\tfoo := &Foo{}\n\treturn foo\n}\n\n// lineComment returns Bar and has a //- style doc comment\nfunc lineComment() *Bar {\n\tbar := &Bar{}\n\treturn bar\n}\n"
  },
  {
    "path": "internal/wire/testdata/EmptyVar/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n\nvar myFakeSet struct{}\n"
  },
  {
    "path": "internal/wire/testdata/EmptyVar/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\twire.Build(myFakeSet)\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/EmptyVar/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/EmptyVar/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: var example.com/foo.myFakeSet struct{} is not a provider or a provider set"
  },
  {
    "path": "internal/wire/testdata/ExampleWithMocks/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// This test demonstrates how to use mocks with wire.\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\t// Create a \"real\" greeter.\n\t// Greet() will include the real current time, so elide it for repeatable\n\t// tests.\n\tfmt.Printf(\"Real time greeting: %s [current time elided]\\n\", initApp().Greet()[0:15])\n\n\t// There are two approaches for creating an app with mocks.\n\n\t// Approach A: create the mocks manually, and pass them to an injector.\n\t// This approach is useful if you need to prime the mocks beforehand.\n\tfmt.Println(\"Approach A\")\n\tmt := newMockTimer()\n\tmockedApp := initMockedAppFromArgs(mt)\n\tfmt.Println(mockedApp.Greet()) // prints greeting with time = zero time\n\tmt.T = mt.T.AddDate(1999, 0, 0)\n\tfmt.Println(mockedApp.Greet()) // prints greeting with time = year 2000\n\n\t// Approach B: allow the injector to create the mocks, and return a struct\n\t// that includes the resulting app plus the mocks.\n\tfmt.Println(\"Approach B\")\n\tappWithMocks := initMockedApp()\n\tfmt.Println(appWithMocks.app.Greet()) // prints greeting with time = zero time\n\tappWithMocks.mt.T = appWithMocks.mt.T.AddDate(999, 0, 0)\n\tfmt.Println(appWithMocks.app.Greet()) // prints greeting with time = year 1000\n}\n\n// appSet is a provider set for creating a real app.\nvar appSet = wire.NewSet(\n\twire.Struct(new(app), \"*\"),\n\twire.Struct(new(greeter), \"*\"),\n\twire.InterfaceValue(new(timer), realTime{}),\n)\n\n// appSetWithoutMocks is a provider set for creating an app with mocked\n// dependencies. The mocked dependencies are omitted and must be provided as\n// arguments to the injector.\n// It is used for Approach A.\nvar appSetWithoutMocks = wire.NewSet(\n\twire.Struct(new(app), \"*\"),\n\twire.Struct(new(greeter), \"*\"),\n)\n\n// mockAppSet is a provider set for creating a mocked app, including the mocked\n// dependencies.\n// It is used for Approach B.\nvar mockAppSet = wire.NewSet(\n\twire.Struct(new(app), \"*\"),\n\twire.Struct(new(greeter), \"*\"),\n\twire.Struct(new(appWithMocks), \"*\"),\n\t// For each mocked dependency, add a provider and use wire.Bind to bind\n\t// the concrete type to the relevant interface.\n\tnewMockTimer,\n\twire.Bind(new(timer), new(*mockTimer)),\n)\n\ntype timer interface {\n\tNow() time.Time\n}\n\n// realTime implements timer with the real time.\ntype realTime struct{}\n\nfunc (realTime) Now() time.Time { return time.Now() }\n\n// mockTimer implements timer using a mocked time.\ntype mockTimer struct {\n\tT time.Time\n}\n\nfunc newMockTimer() *mockTimer      { return &mockTimer{} }\nfunc (m *mockTimer) Now() time.Time { return m.T }\n\n// greeter issues greetings with the time provided by T.\ntype greeter struct {\n\tT timer\n}\n\nfunc (g greeter) Greet() string {\n\treturn fmt.Sprintf(\"Good day! It is %v\", g.T.Now())\n}\n\ntype app struct {\n\tg greeter\n}\n\nfunc (a app) Greet() string {\n\treturn a.g.Greet()\n}\n\n// appWithMocks is used for Approach B, to return the app plus its mocked\n// dependencies.\ntype appWithMocks struct {\n\tapp app\n\tmt  *mockTimer\n}\n"
  },
  {
    "path": "internal/wire/testdata/ExampleWithMocks/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\n// initApp returns a real app.\nfunc initApp() *app {\n\twire.Build(appSet)\n\treturn nil\n}\n\n// initMockedAppFromArgs returns an app with mocked dependencies provided via\n// arguments (Approach A). Note that the argument's type is the interface\n// type (timer), but the concrete mock type should be passed.\nfunc initMockedAppFromArgs(mt timer) *app {\n\twire.Build(appSetWithoutMocks)\n\treturn nil\n}\n\n// initMockedApp returns an app with its mocked dependencies, created\n// via providers (Approach B).\nfunc initMockedApp() *appWithMocks {\n\twire.Build(mockAppSet)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/ExampleWithMocks/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ExampleWithMocks/want/program_out.txt",
    "content": "Real time greeting: Good day! It is [current time elided]\nApproach A\nGood day! It is 0001-01-01 00:00:00 +0000 UTC\nGood day! It is 2000-01-01 00:00:00 +0000 UTC\nApproach B\nGood day! It is 0001-01-01 00:00:00 +0000 UTC\nGood day! It is 1000-01-01 00:00:00 +0000 UTC\n"
  },
  {
    "path": "internal/wire/testdata/ExampleWithMocks/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\n// initApp returns a real app.\nfunc initApp() *app {\n\tmainTimer := _wireRealTimeValue\n\tmainGreeter := greeter{\n\t\tT: mainTimer,\n\t}\n\tmainApp := &app{\n\t\tg: mainGreeter,\n\t}\n\treturn mainApp\n}\n\nvar (\n\t_wireRealTimeValue = realTime{}\n)\n\n// initMockedAppFromArgs returns an app with mocked dependencies provided via\n// arguments (Approach A). Note that the argument's type is the interface\n// type (timer), but the concrete mock type should be passed.\nfunc initMockedAppFromArgs(mt timer) *app {\n\tmainGreeter := greeter{\n\t\tT: mt,\n\t}\n\tmainApp := &app{\n\t\tg: mainGreeter,\n\t}\n\treturn mainApp\n}\n\n// initMockedApp returns an app with its mocked dependencies, created\n// via providers (Approach B).\nfunc initMockedApp() *appWithMocks {\n\tmainMockTimer := newMockTimer()\n\tmainGreeter := greeter{\n\t\tT: mainMockTimer,\n\t}\n\tmainApp := app{\n\t\tg: mainGreeter,\n\t}\n\tmainAppWithMocks := &appWithMocks{\n\t\tapp: mainApp,\n\t\tmt:  mainMockTimer,\n\t}\n\treturn mainAppWithMocks\n}\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValue/bar/bar.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bar\n\nimport \"github.com/google/wire\"\n\nvar Value = wire.Value(PublicMsg)\n\nvar PublicMsg = \"Hello, World!\"\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValue/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValue/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"example.com/bar\"\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\twire.Build(bar.Value)\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValue/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValue/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValue/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"example.com/bar\"\n)\n\n// Injectors from wire.go:\n\nfunc injectedMessage() string {\n\tstring2 := _wireStringValue\n\treturn string2\n}\n\nvar (\n\t_wireStringValue = bar.PublicMsg\n)\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValueDifferentPackage/bar/bar.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bar\n\nimport (\n\t\"os\"\n\n\t\"github.com/google/wire\"\n)\n\nvar Value = wire.Value(os.Stdout)\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValueDifferentPackage/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Fprintln(injectedFile(), \"Hello, World!\")\n}\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValueDifferentPackage/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"os\"\n\n\t\"example.com/bar\"\n\t\"github.com/google/wire\"\n)\n\nfunc injectedFile() *os.File {\n\twire.Build(bar.Value)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValueDifferentPackage/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValueDifferentPackage/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/ExportedValueDifferentPackage/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"os\"\n)\n\n// Injectors from wire.go:\n\nfunc injectedFile() *os.File {\n\tfile := _wireFileValue\n\treturn file\n}\n\nvar (\n\t_wireFileValue = os.Stdout\n)\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfCycle/foo/foo.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(injectedBaz())\n}\n\ntype Foo int\ntype Baz int\n\ntype Bar struct {\n\tBz Baz\n}\n\nfunc provideFoo(_ Baz) Foo {\n\treturn 0\n}\n\nfunc provideBar(_ Foo) Bar {\n\treturn Bar{}\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfCycle/foo/wire.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedBaz() Baz {\n\twire.Build(provideFoo, provideBar, wire.FieldsOf(new(Bar), \"Bz\"))\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfCycle/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfCycle/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: cycle for example.com/foo.Bar:\nexample.com/foo.Bar (example.com/foo.provideBar) ->\nexample.com/foo.Foo (example.com/foo.provideFoo) ->\nexample.com/foo.Baz (example.com/foo.Bar.Bz) ->\nexample.com/foo.Bar"
  },
  {
    "path": "internal/wire/testdata/FieldsOfImportedStruct/bar/bar.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bar\n\nimport (\n\t\"example.com/foo\"\n)\n\ntype Config struct {\n\tV int\n}\n\ntype Service struct {\n\tCfg *Config\n\tF   *foo.Service\n}\n\nfunc New(cfg *Config, f *foo.Service) *Service {\n\treturn &Service{Cfg: cfg, F: f}\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfImportedStruct/baz/baz.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage baz\n\nimport (\n\t\"fmt\"\n\n\t\"example.com/bar\"\n\t\"example.com/foo\"\n)\n\ntype Config struct {\n\tFoo *foo.Config\n\tBar *bar.Config\n}\n\ntype Service struct {\n\tFoo *foo.Service\n\tBar *bar.Service\n}\n\nfunc (m *Service) String() string {\n\treturn fmt.Sprintf(\"%d %d\", m.Foo.Cfg.V, m.Bar.Cfg.V)\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfImportedStruct/foo/foo.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage foo\n\ntype Config struct {\n\tV int\n}\n\ntype Service struct {\n\tCfg *Config\n}\n\nfunc New(cfg *Config) *Service {\n\treturn &Service{Cfg: cfg}\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfImportedStruct/main/wire.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"example.com/bar\"\n\t\"example.com/baz\"\n\t\"example.com/foo\"\n\t\"github.com/google/wire\"\n)\n\nfunc newBazService(*baz.Config) *baz.Service {\n\twire.Build(\n\t\twire.Struct(new(baz.Service), \"*\"),\n\t\twire.FieldsOf(\n\t\t\tnew(*baz.Config),\n\t\t\t\"Foo\",\n\t\t\t\"Bar\",\n\t\t),\n\t\tfoo.New,\n\t\tbar.New,\n\t)\n\treturn nil\n}\n\nfunc main() {\n\tcfg := &baz.Config{\n\t\tFoo: &foo.Config{1},\n\t\tBar: &bar.Config{2},\n\t}\n\tsvc := newBazService(cfg)\n\tfmt.Println(svc.String())\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfImportedStruct/pkg",
    "content": "example.com/main\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfImportedStruct/want/program_out.txt",
    "content": "1 2\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfImportedStruct/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"example.com/bar\"\n\t\"example.com/baz\"\n\t\"example.com/foo\"\n\t\"fmt\"\n)\n\n// Injectors from wire.go:\n\nfunc newBazService(config *baz.Config) *baz.Service {\n\tfooConfig := config.Foo\n\tservice := foo.New(fooConfig)\n\tbarConfig := config.Bar\n\tbarService := bar.New(barConfig, service)\n\tbazService := &baz.Service{\n\t\tFoo: service,\n\t\tBar: barService,\n\t}\n\treturn bazService\n}\n\n// wire.go:\n\nfunc main() {\n\tcfg := &baz.Config{\n\t\tFoo: &foo.Config{1},\n\t\tBar: &bar.Config{2},\n\t}\n\tsvc := newBazService(cfg)\n\tfmt.Println(svc.String())\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStruct/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\ntype S struct {\n\tFoo string\n}\n\nfunc provideS() S {\n\treturn S{Foo: \"Hello, World!\"}\n}\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStruct/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\twire.Build(\n\t\tprovideS,\n\t\twire.FieldsOf(new(S), \"Foo\"))\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStruct/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStruct/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStruct/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage() string {\n\ts := provideS()\n\tstring2 := s.Foo\n\treturn string2\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStructDoNotProvidePtrToField/foo/foo.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\ntype S struct {\n\tFoo string\n}\n\nfunc provideS() S {\n\treturn S{Foo: \"Hello, World!\"}\n}\n\nfunc main() {\n\tfmt.Println(\"pointer to \" + *injectedMessagePtr())\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStructDoNotProvidePtrToField/foo/wire.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessagePtr() *string {\n\t// This shouldn't work; FieldsOf provides a pointer to the\n\t// field only when the struct type is a pointer to a struct.\n\t// See FieldsOfStructPointer for a working example using\n\t// a pointer to a struct.\n\twire.Build(\n\t\tprovideS,\n\t\twire.FieldsOf(new(S), \"Foo\"))\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStructDoNotProvidePtrToField/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStructDoNotProvidePtrToField/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: inject injectedMessagePtr: no provider found for *string, output of injector"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStructPointer/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\ntype S struct {\n\tFoo string\n}\n\nfunc provideS() *S {\n\treturn &S{Foo: \"Hello, World!\"}\n}\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n\tfmt.Println(\"pointer to \" + *injectedMessagePtr())\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStructPointer/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\twire.Build(\n\t\tprovideS,\n\t\twire.FieldsOf(new(*S), \"Foo\"))\n\treturn \"\"\n}\n\nfunc injectedMessagePtr() *string {\n\twire.Build(\n\t\tprovideS,\n\t\twire.FieldsOf(new(*S), \"Foo\"))\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStructPointer/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStructPointer/want/program_out.txt",
    "content": "Hello, World!\npointer to Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfStructPointer/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage() string {\n\ts := provideS()\n\tstring2 := s.Foo\n\treturn string2\n}\n\nfunc injectedMessagePtr() *string {\n\ts := provideS()\n\tstring2 := &s.Foo\n\treturn string2\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfValueStruct/bar/bar.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bar\n\nimport (\n\t\"example.com/foo\"\n)\n\ntype Config struct {\n\tV int\n}\n\ntype Service struct {\n\tCfg *Config\n\tF   *foo.Service\n}\n\nfunc New(cfg *Config, f *foo.Service) *Service {\n\treturn &Service{Cfg: cfg, F: f}\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfValueStruct/baz/baz.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage baz\n\nimport (\n\t\"fmt\"\n\n\t\"example.com/bar\"\n\t\"example.com/foo\"\n)\n\ntype Config struct {\n\tFoo *foo.Config\n\tBar *bar.Config\n}\n\ntype Service struct {\n\tFoo *foo.Service\n\tBar *bar.Service\n}\n\nfunc (m *Service) String() string {\n\treturn fmt.Sprintf(\"%d %d\", m.Foo.Cfg.V, m.Bar.Cfg.V)\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfValueStruct/foo/foo.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage foo\n\ntype Config struct {\n\tV int\n}\n\ntype Service struct {\n\tCfg *Config\n}\n\nfunc New(cfg *Config) *Service {\n\treturn &Service{Cfg: cfg}\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfValueStruct/main/wire.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"example.com/bar\"\n\t\"example.com/baz\"\n\t\"example.com/foo\"\n\t\"github.com/google/wire\"\n)\n\nfunc newBazService() *baz.Service {\n\twire.Build(\n\t\twire.Struct(new(baz.Service), \"*\"),\n\t\twire.Value(&baz.Config{\n\t\t\tFoo: &foo.Config{1},\n\t\t\tBar: &bar.Config{2},\n\t\t}),\n\t\twire.FieldsOf(\n\t\t\tnew(*baz.Config),\n\t\t\t\"Foo\",\n\t\t\t\"Bar\",\n\t\t),\n\t\tfoo.New,\n\t\tbar.New,\n\t)\n\treturn nil\n}\n\nfunc main() {\n\tsvc := newBazService()\n\tfmt.Println(svc.String())\n}\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfValueStruct/pkg",
    "content": "example.com/main\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfValueStruct/want/program_out.txt",
    "content": "1 2\n"
  },
  {
    "path": "internal/wire/testdata/FieldsOfValueStruct/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"example.com/bar\"\n\t\"example.com/baz\"\n\t\"example.com/foo\"\n\t\"fmt\"\n)\n\n// Injectors from wire.go:\n\nfunc newBazService() *baz.Service {\n\tconfig := _wireConfigValue\n\tfooConfig := config.Foo\n\tservice := foo.New(fooConfig)\n\tbarConfig := config.Bar\n\tbarService := bar.New(barConfig, service)\n\tbazService := &baz.Service{\n\t\tFoo: service,\n\t\tBar: barService,\n\t}\n\treturn bazService\n}\n\nvar (\n\t_wireConfigValue = &baz.Config{\n\t\tFoo: &foo.Config{1},\n\t\tBar: &bar.Config{2},\n\t}\n)\n\n// wire.go:\n\nfunc main() {\n\tsvc := newBazService()\n\tfmt.Println(svc.String())\n}\n"
  },
  {
    "path": "internal/wire/testdata/FuncArgProvider/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tbar := injectBar(func() *Foo { return &Foo{42} })\n\tfmt.Println(bar.Name)\n}\n\ntype Foo struct {\n\tVal int\n}\n\ntype Bar struct {\n\tName string\n}\n\nfunc NewBar(f *Foo) *Bar {\n\treturn &Bar{Name: fmt.Sprintf(\"foo value %d\", f.Val)}\n}\n"
  },
  {
    "path": "internal/wire/testdata/FuncArgProvider/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectBar(fn func() *Foo) *Bar {\n\t// fails because it doesn't identify fn as a Provider; see #723.\n\tpanic(wire.Build(fn, NewBar))\n}\n"
  },
  {
    "path": "internal/wire/testdata/FuncArgProvider/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/FuncArgProvider/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: var fn func() *example.com/foo.Foo is not a provider or a provider set"
  },
  {
    "path": "internal/wire/testdata/Header/foo/foo.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(injectFoo())\n}\n\ntype Foo int\n\nfunc provideFoo() Foo {\n\treturn 41\n}\n"
  },
  {
    "path": "internal/wire/testdata/Header/foo/wire.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFoo() Foo {\n\twire.Build(provideFoo)\n\treturn Foo(0)\n}\n"
  },
  {
    "path": "internal/wire/testdata/Header/header",
    "content": "// This is a sample header file.\n//\n"
  },
  {
    "path": "internal/wire/testdata/Header/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/Header/want/program_out.txt",
    "content": "41\n"
  },
  {
    "path": "internal/wire/testdata/Header/want/wire_gen.go",
    "content": "// This is a sample header file.\n//\n// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFoo() Foo {\n\tfoo := provideFoo()\n\treturn foo\n}\n"
  },
  {
    "path": "internal/wire/testdata/ImportedInterfaceBinding/bar/bar.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"example.com/foo\"\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooer().Foo())\n}\n\ntype Bar string\n\nfunc (b *Bar) Foo() string {\n\treturn string(*b)\n}\n\nfunc provideBar() *Bar {\n\tb := new(Bar)\n\t*b = \"Hello, World!\"\n\treturn b\n}\n\nvar Set = wire.NewSet(\n\tprovideBar,\n\twire.Bind(new(foo.Fooer), new(*Bar)))\n"
  },
  {
    "path": "internal/wire/testdata/ImportedInterfaceBinding/bar/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"example.com/foo\"\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooer() foo.Fooer {\n\twire.Build(Set)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/ImportedInterfaceBinding/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage foo\n\ntype Fooer interface {\n\tFoo() string\n}\n"
  },
  {
    "path": "internal/wire/testdata/ImportedInterfaceBinding/pkg",
    "content": "example.com/bar\n"
  },
  {
    "path": "internal/wire/testdata/ImportedInterfaceBinding/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/ImportedInterfaceBinding/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"example.com/foo\"\n)\n\n// Injectors from wire.go:\n\nfunc injectFooer() foo.Fooer {\n\tbar := provideBar()\n\treturn bar\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectInput/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooBar(40))\n}\n\ntype Foo int\ntype Bar int\ntype FooBar int\n\nvar Set = wire.NewSet(\n\tprovideBar,\n\tprovideFooBar)\n\nfunc provideBar() Bar {\n\treturn 2\n}\n\nfunc provideFooBar(foo Foo, bar Bar) FooBar {\n\treturn FooBar(foo) + FooBar(bar)\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectInput/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooBar(foo Foo) FooBar {\n\twire.Build(Set)\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectInput/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InjectInput/want/program_out.txt",
    "content": "42\n"
  },
  {
    "path": "internal/wire/testdata/InjectInput/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFooBar(foo Foo) FooBar {\n\tbar := provideBar()\n\tfooBar := provideFooBar(foo, bar)\n\treturn fooBar\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectInputConflict/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\t// I'm on the fence as to whether this should be an error (versus an\n\t// override). For now, I will make it an error that can be relaxed\n\t// later.\n\tfmt.Println(injectBar(40))\n}\n\ntype Foo int\ntype Bar int\n\nvar Set = wire.NewSet(\n\tprovideFoo,\n\tprovideBar)\n\nfunc provideFoo() Foo {\n\treturn -888\n}\n\nfunc provideBar(foo Foo) Bar {\n\treturn 2\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectInputConflict/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectBar(foo Foo) Bar {\n\twire.Build(Set)\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectInputConflict/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InjectInputConflict/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo\ncurrent:\n<- provider \"provideFoo\" (example.com/foo/foo.go:x:y)\n<- provider set \"Set\" (example.com/foo/foo.go:x:y)\nprevious:\n<- argument foo to injector function injectBar (example.com/foo/wire.go:x:y)"
  },
  {
    "path": "internal/wire/testdata/InjectWithPanic/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n\n// provideMessage provides a friendly user greeting.\nfunc provideMessage() string {\n\treturn \"Hello, World!\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectWithPanic/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\tpanic(wire.Build(provideMessage))\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectWithPanic/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InjectWithPanic/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/InjectWithPanic/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage() string {\n\tstring2 := provideMessage()\n\treturn string2\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectorMissingCleanup/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfoo := injectFoo()\n\tfmt.Println(foo)\n}\n\ntype Foo int\n\nfunc provideFoo() (Foo, func()) {\n\treturn Foo(42), func() {}\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectorMissingCleanup/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFoo() Foo {\n\t// provideFoo returns a cleanup, but injectFoo does not.\n\twire.Build(provideFoo)\n\treturn Foo(0)\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectorMissingCleanup/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InjectorMissingCleanup/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: inject injectFoo: provider for example.com/foo.Foo returns cleanup but injection does not return cleanup function"
  },
  {
    "path": "internal/wire/testdata/InjectorMissingError/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfoo := injectFoo()\n\tfmt.Println(foo)\n}\n\ntype Foo int\n\nfunc provideFoo() (Foo, error) {\n\treturn Foo(42), nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectorMissingError/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFoo() Foo {\n\t// provideFoo returns an error, but injectFoo does not.\n\twire.Build(provideFoo)\n\treturn Foo(0)\n}\n"
  },
  {
    "path": "internal/wire/testdata/InjectorMissingError/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InjectorMissingError/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: inject injectFoo: provider for example.com/foo.Foo returns error but injection not allowed to fail"
  },
  {
    "path": "internal/wire/testdata/InterfaceBinding/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooer().Foo())\n}\n\ntype Fooer interface {\n\tFoo() string\n}\n\ntype Bar string\n\nfunc (b *Bar) Foo() string {\n\treturn string(*b)\n}\n\nfunc provideBar() *Bar {\n\tb := new(Bar)\n\t*b = \"Hello, World!\"\n\treturn b\n}\n\nvar Set = wire.NewSet(\n\tprovideBar,\n\twire.Bind(new(Fooer), new(*Bar)))\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBinding/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooer() Fooer {\n\twire.Build(Set)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBinding/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBinding/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBinding/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFooer() Fooer {\n\tbar := provideBar()\n\treturn bar\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingDoesntImplement/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooer().Foo())\n}\n\ntype Fooer interface {\n\tFoo() string\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingDoesntImplement/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooer() Fooer {\n\t// wrong: string doesn't implement Fooer.\n\twire.Build(wire.Bind(new(Fooer), new(string)))\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingDoesntImplement/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingDoesntImplement/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: string does not implement example.com/foo.Fooer"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingInvalidArg0/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooer().Foo())\n}\n\ntype Fooer interface {\n\tFoo() string\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingInvalidArg0/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooer() Fooer {\n\t// wrong: arg0 must be a pointer to an interface.\n\twire.Build(wire.Bind(\"foo\", \"bar\"))\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingInvalidArg0/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingInvalidArg0/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: first argument to Bind must be a pointer to an interface type; found string"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingNotEnoughArgs/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooer().Foo())\n}\n\ntype Fooer interface {\n\tFoo() string\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingNotEnoughArgs/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooer() Fooer {\n\t// wrong: wire.Bind requires 2 args.\n\twire.Build(wire.Bind(new(Fooer)))\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingNotEnoughArgs/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingNotEnoughArgs/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: not enough arguments in call to wire.Bind\n\thave (*Fooer)\n\twant (interface{}, interface{})"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingReuse/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// This test verifies that the concrete type is provided only once, even if an\n// interface additionally depends on it.\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sync\"\n)\n\nfunc main() {\n\tinjectFooBar()\n\tfmt.Println(provideBarCalls)\n}\n\ntype Fooer interface {\n\tFoo() string\n}\n\ntype Bar string\n\ntype FooBar struct {\n\tFooer Fooer\n\tBar   *Bar\n}\n\nfunc (b *Bar) Foo() string {\n\treturn string(*b)\n}\n\nfunc provideBar() *Bar {\n\tmu.Lock()\n\tprovideBarCalls++\n\tmu.Unlock()\n\tb := new(Bar)\n\t*b = \"Hello, World!\"\n\treturn b\n}\n\nvar (\n\tmu              sync.Mutex\n\tprovideBarCalls int\n)\n\nfunc provideFooBar(fooer Fooer, bar *Bar) FooBar {\n\treturn FooBar{fooer, bar}\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingReuse/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooBar() FooBar {\n\twire.Build(\n\t\tprovideBar,\n\t\tprovideFooBar,\n\t\twire.Bind(new(Fooer), new(*Bar)),\n\t)\n\treturn FooBar{}\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingReuse/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingReuse/want/program_out.txt",
    "content": "1\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceBindingReuse/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFooBar() FooBar {\n\tbar := provideBar()\n\tfooBar := provideFooBar(bar, bar)\n\treturn fooBar\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValue/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n)\n\nfunc main() {\n\tr := injectedReader()\n\tbuf, _ := ioutil.ReadAll(r)\n\tfmt.Println(string(buf))\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValue/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"io\"\n\t\"strings\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc injectedReader() io.Reader {\n\twire.Build(wire.InterfaceValue(new(io.Reader), strings.NewReader(\"hello world\")))\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValue/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValue/want/program_out.txt",
    "content": "hello world\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValue/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"io\"\n\t\"strings\"\n)\n\n// Injectors from wire.go:\n\nfunc injectedReader() io.Reader {\n\treader := _wireReaderValue\n\treturn reader\n}\n\nvar (\n\t_wireReaderValue = strings.NewReader(\"hello world\")\n)\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueDoesntImplement/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueDoesntImplement/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n\t\"io\"\n)\n\nfunc injectedMessage() string {\n\t// wrong: string doesn't implement io.Reader.\n\twire.Build(wire.InterfaceValue(new(io.Reader), \"bar\"))\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueDoesntImplement/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueDoesntImplement/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: string does not implement io.Reader"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueInvalidArg0/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueInvalidArg0/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\t// wrong: arg0 must be a pointer to an interface.\n\twire.Build(wire.InterfaceValue(\"foo\", \"bar\"))\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueInvalidArg0/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueInvalidArg0/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: first argument to InterfaceValue must be a pointer to an interface type; found string"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueNotEnoughArgs/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueNotEnoughArgs/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\t// wrong: InterfaceValue requires 2 args.\n\twire.Build(wire.InterfaceValue(\"foo\"))\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueNotEnoughArgs/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InterfaceValueNotEnoughArgs/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: not enough arguments in call to wire.InterfaceValue\n\thave (string)\n\twant (interface{}, interface{})"
  },
  {
    "path": "internal/wire/testdata/InvalidInjector/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfoo := injectFoo()\n\tbar := injectBar()\n\tfmt.Println(foo)\n\tfmt.Println(bar)\n}\n\ntype Foo int\ntype Bar int\n\nfunc provideFoo() Foo {\n\treturn Foo(42)\n}\nfunc provideBar() Bar {\n\treturn Bar(99)\n}\n"
  },
  {
    "path": "internal/wire/testdata/InvalidInjector/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFoo() Foo {\n\t// This non-call statement makes this an invalid injector.\n\t_ = 42\n\tpanic(wire.Build(provideFoo))\n}\n\nfunc injectBar() Bar {\n\t// Two call statements are also invalid.\n\tpanic(wire.Build(provideBar))\n\tpanic(wire.Build(provideBar))\n}\n"
  },
  {
    "path": "internal/wire/testdata/InvalidInjector/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/InvalidInjector/want/wire_errs.txt",
    "content": "a call to wire.Build indicates that this function is an injector, but injectors must consist of only the wire.Build call and an optional return\n\na call to wire.Build indicates that this function is an injector, but injectors must consist of only the wire.Build call and an optional return"
  },
  {
    "path": "internal/wire/testdata/MultipleArgsSameType/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(inject(\"foo\", \"bar\").A)\n}\n\ntype Foo struct {\n\tA string\n}\n\nfunc provideFoo(a string) *Foo {\n\treturn &Foo{A: a}\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleArgsSameType/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc inject(a, b string) *Foo {\n\t// fail: can't have two args of the same type.\n\tpanic(wire.Build(provideFoo))\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleArgsSameType/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/MultipleArgsSameType/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: multiple bindings for string\ncurrent:\n<- argument b to injector function inject (example.com/foo/wire.go:x:y)\nprevious:\n<- argument a to injector function inject (example.com/foo/wire.go:x:y)"
  },
  {
    "path": "internal/wire/testdata/MultipleBindings/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"io\"\n\t\"strings\"\n\n\t\"github.com/google/wire\"\n)\n\ntype context struct{}\n\nfunc main() {}\n\ntype Foo string\ntype Bar io.Reader\n\nvar Set = wire.NewSet(provideFoo)\nvar SuperSet = wire.NewSet(Set)\nvar SetWithDuplicateBindings = wire.NewSet(Set, SuperSet)\n\nfunc provideFoo() Foo {\n\treturn Foo(\"foo\")\n}\n\nfunc provideFooAgain() Foo {\n\treturn Foo(\"foo foo\")\n}\n\nfunc provideBar() Bar {\n\treturn io.Reader(strings.NewReader(\"hello\"))\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleBindings/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"strings\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc inject() Foo {\n\t// fail: provideFoo and provideFooAgain both provide Foo.\n\tpanic(wire.Build(provideFoo, provideFooAgain))\n}\n\nfunc injectFromSet() Foo {\n\t// fail: provideFoo is also provided by Set.\n\tpanic(wire.Build(provideFoo, Set))\n}\n\nfunc injectFromNestedSet() Foo {\n\t// fail: provideFoo is also provided by SuperSet, via Set.\n\tpanic(wire.Build(provideFoo, SuperSet))\n}\n\nfunc injectFromSetWithDuplicateBindings() Foo {\n\t// fail: DuplicateBindingsSet has two providers for Foo.\n\tpanic(wire.Build(SetWithDuplicateBindings))\n}\n\nfunc injectDuplicateValues() Foo {\n\t// fail: provideFoo and wire.Value both provide Foo.\n\tpanic(wire.Build(provideFoo, wire.Value(Foo(\"foo\"))))\n}\n\nfunc injectDuplicateInterface() Bar {\n\t// fail: provideBar and wire.Bind both provide Bar.\n\tpanic(wire.Build(provideBar, wire.Bind(new(Bar), new(*strings.Reader))))\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleBindings/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/MultipleBindings/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo\ncurrent:\n<- provider \"provideFooAgain\" (example.com/foo/foo.go:x:y)\nprevious:\n<- provider \"provideFoo\" (example.com/foo/foo.go:x:y)\n\nexample.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo\ncurrent:\n<- provider \"provideFoo\" (example.com/foo/foo.go:x:y)\nprevious:\n<- provider \"provideFoo\" (example.com/foo/foo.go:x:y)\n<- provider set \"Set\" (example.com/foo/foo.go:x:y)\n\nexample.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo\ncurrent:\n<- provider \"provideFoo\" (example.com/foo/foo.go:x:y)\nprevious:\n<- provider \"provideFoo\" (example.com/foo/foo.go:x:y)\n<- provider set \"Set\" (example.com/foo/foo.go:x:y)\n<- provider set \"SuperSet\" (example.com/foo/foo.go:x:y)\n\nexample.com/foo/foo.go:x:y: SetWithDuplicateBindings has multiple bindings for example.com/foo.Foo\ncurrent:\n<- provider \"provideFoo\" (example.com/foo/foo.go:x:y)\n<- provider set \"Set\" (example.com/foo/foo.go:x:y)\n<- provider set \"SuperSet\" (example.com/foo/foo.go:x:y)\nprevious:\n<- provider \"provideFoo\" (example.com/foo/foo.go:x:y)\n<- provider set \"Set\" (example.com/foo/foo.go:x:y)\n\nexample.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo\ncurrent:\n<- wire.Value (example.com/foo/wire.go:x:y)\nprevious:\n<- provider \"provideFoo\" (example.com/foo/foo.go:x:y)\n\nexample.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Bar\ncurrent:\n<- wire.Bind (example.com/foo/wire.go:x:y)\nprevious:\n<- provider \"provideBar\" (example.com/foo/foo.go:x:y)"
  },
  {
    "path": "internal/wire/testdata/MultipleMissingInputs/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectMissingOutputType())\n\tfmt.Println(injectMultipleMissingTypes())\n\tfmt.Println(injectMissingRecursiveType())\n}\n\ntype Foo int\ntype Bar int\ntype Baz int\n\nfunc provideBaz(foo Foo, bar Bar) Baz {\n\treturn 0\n}\n\ntype Zip int\ntype Zap int\ntype Zop int\n\nfunc provideZip(foo Foo) Zip {\n\treturn 0\n}\n\nfunc provideZap(zip Zip) Zap {\n\treturn 0\n}\n\nfunc provideZop(zap Zap) Zop {\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleMissingInputs/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectMissingOutputType() Foo {\n\t// Error: no provider for Foo.\n\twire.Build()\n\treturn Foo(0)\n}\n\nfunc injectMultipleMissingTypes() Baz {\n\t// Error: provideBaz needs Foo and Bar, both missing.\n\twire.Build(provideBaz)\n\treturn Baz(0)\n}\n\nfunc injectMissingRecursiveType() Zop {\n\t// Error:\n\t// Zop  -> Zap -> Zip -> Foo\n\t// provideZop needs Zap, provideZap needs Zip, provideZip needs Foo,\n\t// which is missing.\n\twire.Build(provideZop, provideZap, provideZip)\n\treturn Zop(0)\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleMissingInputs/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/MultipleMissingInputs/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: inject injectMissingOutputType: no provider found for example.com/foo.Foo, output of injector\n\nexample.com/foo/wire.go:x:y: inject injectMultipleMissingTypes: no provider found for example.com/foo.Foo\nneeded by example.com/foo.Baz in provider \"provideBaz\" (example.com/foo/foo.go:x:y)\n\nexample.com/foo/wire.go:x:y: inject injectMultipleMissingTypes: no provider found for example.com/foo.Bar\nneeded by example.com/foo.Baz in provider \"provideBaz\" (example.com/foo/foo.go:x:y)\n\nexample.com/foo/wire.go:x:y: inject injectMissingRecursiveType: no provider found for example.com/foo.Foo\nneeded by example.com/foo.Zip in provider \"provideZip\" (example.com/foo/foo.go:x:y)\nneeded by example.com/foo.Zap in provider \"provideZap\" (example.com/foo/foo.go:x:y)\nneeded by example.com/foo.Zop in provider \"provideZop\" (example.com/foo/foo.go:x:y)"
  },
  {
    "path": "internal/wire/testdata/MultipleSimilarPackages/bar/bar.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bar\n\nimport (\n\t\"example.com/foo\"\n)\n\ntype Config struct {\n\tV int\n}\n\ntype Service struct {\n\tCfg *Config\n\tF   *foo.Service\n}\n\nfunc New(cfg *Config, f *foo.Service) *Service {\n\treturn &Service{Cfg: cfg, F: f}\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleSimilarPackages/baz/baz.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage baz\n\nimport (\n\t\"example.com/bar\"\n)\n\ntype Config struct {\n\tV int\n}\n\ntype Service struct {\n\tCfg *Config\n\tB   *bar.Service\n}\n\nfunc New(cfg *Config, b *bar.Service) *Service {\n\treturn &Service{Cfg: cfg, B: b}\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleSimilarPackages/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage foo\n\ntype Config struct {\n\tV int\n}\n\ntype Service struct {\n\tCfg *Config\n}\n\nfunc New(cfg *Config) *Service {\n\treturn &Service{Cfg: cfg}\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleSimilarPackages/main/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"example.com/bar\"\n\t\"example.com/baz\"\n\t\"example.com/foo\"\n\t\"github.com/google/wire\"\n)\n\ntype MainConfig struct {\n\tFoo *foo.Config\n\tBar *bar.Config\n\tbaz *baz.Config\n}\n\ntype MainService struct {\n\tFoo *foo.Service\n\tBar *bar.Service\n\tbaz *baz.Service\n}\n\nfunc (m *MainService) String() string {\n\treturn fmt.Sprintf(\"%d %d %d\", m.Foo.Cfg.V, m.Bar.Cfg.V, m.baz.Cfg.V)\n}\n\nfunc newMainService(MainConfig) *MainService {\n\twire.Build(\n\t\twire.Struct(new(MainService), \"Foo\", \"Bar\", \"baz\"),\n\t\twire.FieldsOf(\n\t\t\tnew(MainConfig),\n\t\t\t\"Foo\",\n\t\t\t\"Bar\",\n\t\t\t\"baz\",\n\t\t),\n\t\tfoo.New,\n\t\tbar.New,\n\t\tbaz.New,\n\t)\n\treturn nil\n}\n\nfunc main() {\n\tcfg := MainConfig{\n\t\tFoo: &foo.Config{1},\n\t\tBar: &bar.Config{2},\n\t\tbaz: &baz.Config{3},\n\t}\n\tsvc := newMainService(cfg)\n\tfmt.Println(svc.String())\n}\n"
  },
  {
    "path": "internal/wire/testdata/MultipleSimilarPackages/pkg",
    "content": "example.com/main\n"
  },
  {
    "path": "internal/wire/testdata/MultipleSimilarPackages/want/program_out.txt",
    "content": "1 2 3\n"
  },
  {
    "path": "internal/wire/testdata/MultipleSimilarPackages/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"example.com/bar\"\n\t\"example.com/baz\"\n\t\"example.com/foo\"\n\t\"fmt\"\n)\n\n// Injectors from wire.go:\n\nfunc newMainService(mainConfig MainConfig) *MainService {\n\tconfig := mainConfig.Foo\n\tservice := foo.New(config)\n\tbarConfig := mainConfig.Bar\n\tbarService := bar.New(barConfig, service)\n\tbazConfig := mainConfig.baz\n\tbazService := baz.New(bazConfig, barService)\n\tmainService := &MainService{\n\t\tFoo: service,\n\t\tBar: barService,\n\t\tbaz: bazService,\n\t}\n\treturn mainService\n}\n\n// wire.go:\n\ntype MainConfig struct {\n\tFoo *foo.Config\n\tBar *bar.Config\n\tbaz *baz.Config\n}\n\ntype MainService struct {\n\tFoo *foo.Service\n\tBar *bar.Service\n\tbaz *baz.Service\n}\n\nfunc (m *MainService) String() string {\n\treturn fmt.Sprintf(\"%d %d %d\", m.Foo.Cfg.V, m.Bar.Cfg.V, m.baz.Cfg.V)\n}\n\nfunc main() {\n\tcfg := MainConfig{\n\t\tFoo: &foo.Config{1},\n\t\tBar: &bar.Config{2},\n\t\tbaz: &baz.Config{3},\n\t}\n\tsvc := newMainService(cfg)\n\tfmt.Println(svc.String())\n}\n"
  },
  {
    "path": "internal/wire/testdata/NamingWorstCase/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\tstdcontext \"context\"\n\t\"fmt\"\n\t\"os\"\n)\n\ntype context struct{}\n\nfunc main() {\n\tc, err := inject(stdcontext.Background(), struct{}{})\n\tif err != nil {\n\t\tfmt.Println(\"ERROR:\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Println(c)\n}\n\nfunc provide(ctx stdcontext.Context) (context, error) {\n\treturn context{}, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/NamingWorstCase/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\tstdcontext \"context\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc inject(context stdcontext.Context, err struct{}) (context, error) {\n\tpanic(wire.Build(provide))\n}\n"
  },
  {
    "path": "internal/wire/testdata/NamingWorstCase/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/NamingWorstCase/want/program_out.txt",
    "content": "{}\n"
  },
  {
    "path": "internal/wire/testdata/NamingWorstCase/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\tcontext2 \"context\"\n)\n\n// Injectors from wire.go:\n\nfunc inject(context3 context2.Context, err2 struct{}) (context, error) {\n\tmainContext, err := provide(context3)\n\tif err != nil {\n\t\treturn context{}, err\n\t}\n\treturn mainContext, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/NamingWorstCaseAllInOne/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\n// This file is specifically designed to cause issues with copying the\n// AST, particularly with the identifier \"context\".\n\npackage main\n\nimport (\n\tstdcontext \"context\"\n\t\"fmt\"\n\t\"os\"\n\t\"reflect\"\n\n\t\"github.com/google/wire\"\n)\n\ntype context struct{}\n\nfunc main() {\n\tif _, ok := reflect.TypeOf(context{}).MethodByName(\"Provide\"); !ok {\n\t\tfmt.Println(\"ERROR: context.Provide renamed\")\n\t\tos.Exit(1)\n\t}\n\tc, err := inject(stdcontext.Background(), struct{}{})\n\tif err != nil {\n\t\tfmt.Println(\"ERROR:\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Println(c)\n}\n\nfunc Provide(context2 stdcontext.Context) (context, error) {\n\tvar context3 = stdcontext.Background()\n\t_ = context2\n\t_ = context3\n\treturn context{}, nil\n}\n\nfunc inject(context stdcontext.Context, err struct{}) (context, error) {\n\tpanic(wire.Build(Provide))\n}\n\nfunc (context) Provide() {\n}\n"
  },
  {
    "path": "internal/wire/testdata/NamingWorstCaseAllInOne/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/NamingWorstCaseAllInOne/want/program_out.txt",
    "content": "{}\n"
  },
  {
    "path": "internal/wire/testdata/NamingWorstCaseAllInOne/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\tcontext2 \"context\"\n\t\"fmt\"\n\t\"os\"\n\t\"reflect\"\n)\n\n// Injectors from foo.go:\n\nfunc inject(context3 context2.Context, err2 struct{}) (context, error) {\n\tmainContext, err := Provide(context3)\n\tif err != nil {\n\t\treturn context{}, err\n\t}\n\treturn mainContext, nil\n}\n\n// foo.go:\n\ntype context struct{}\n\nfunc main() {\n\tif _, ok := reflect.TypeOf(context{}).MethodByName(\"Provide\"); !ok {\n\t\tfmt.Println(\"ERROR: context.Provide renamed\")\n\t\tos.Exit(1)\n\t}\n\tc, err := inject(context2.Background(), struct{}{})\n\tif err != nil {\n\t\tfmt.Println(\"ERROR:\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Println(c)\n}\n\nfunc Provide(context2_2 context2.Context) (context, error) {\n\tvar context3 = context2.Background()\n\t_ = context2_2\n\t_ = context3\n\treturn context{}, nil\n}\n\nfunc (context) Provide() {\n}\n"
  },
  {
    "path": "internal/wire/testdata/NiladicIdentity/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n\n// provideMessage provides a friendly user greeting.\nfunc provideMessage() string {\n\treturn \"Hello, World!\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/NiladicIdentity/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\twire.Build(provideMessage)\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/NiladicIdentity/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/NiladicIdentity/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/NiladicIdentity/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage() string {\n\tstring2 := provideMessage()\n\treturn string2\n}\n"
  },
  {
    "path": "internal/wire/testdata/NiladicValue/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n"
  },
  {
    "path": "internal/wire/testdata/NiladicValue/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\twire.Build(wire.Value(\"Hello, World!\"))\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/NiladicValue/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/NiladicValue/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/NiladicValue/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage() string {\n\tstring2 := _wireStringValue\n\treturn string2\n}\n\nvar (\n\t_wireStringValue = \"Hello, World!\"\n)\n"
  },
  {
    "path": "internal/wire/testdata/NoImplicitInterface/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectFooer().Foo())\n}\n\ntype Fooer interface {\n\tFoo() string\n}\n\ntype Bar string\n\nfunc (b Bar) Foo() string {\n\treturn string(b)\n}\n\nfunc provideBar() Bar {\n\treturn \"Hello, World!\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/NoImplicitInterface/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooer() Fooer {\n\twire.Build(provideBar)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/NoImplicitInterface/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/NoImplicitInterface/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: inject injectFooer: no provider found for example.com/foo.Fooer, output of injector"
  },
  {
    "path": "internal/wire/testdata/NoInjectParamNames/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\tstdcontext \"context\"\n\t\"fmt\"\n\t\"os\"\n)\n\ntype context struct{}\n\nfunc main() {\n\tc, err := inject(stdcontext.Background(), struct{}{})\n\tif err != nil {\n\t\tfmt.Println(\"ERROR:\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Println(c)\n}\n\nfunc provide(ctx stdcontext.Context) (context, error) {\n\treturn context{}, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/NoInjectParamNames/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\tstdcontext \"context\"\n\n\t\"github.com/google/wire\"\n)\n\n// The notable characteristic of this test is that there are no\n// parameter names on the inject stub.\n\nfunc inject(stdcontext.Context, struct{}) (context, error) {\n\twire.Build(provide)\n\treturn context{}, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/NoInjectParamNames/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/NoInjectParamNames/want/program_out.txt",
    "content": "{}\n"
  },
  {
    "path": "internal/wire/testdata/NoInjectParamNames/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\tcontext2 \"context\"\n)\n\n// Injectors from wire.go:\n\nfunc inject(contextContext context2.Context, arg struct{}) (context, error) {\n\tmainContext, err := provide(contextContext)\n\tif err != nil {\n\t\treturn context{}, err\n\t}\n\treturn mainContext, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/NoopBuild/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello, World!\")\n}\n"
  },
  {
    "path": "internal/wire/testdata/NoopBuild/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/NoopBuild/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/NoopBuild/want/wire_gen.go",
    "content": ""
  },
  {
    "path": "internal/wire/testdata/PartialCleanup/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strings\"\n)\n\nvar (\n\tcleanedFoo = false\n\tcleanedBar = false\n)\n\nfunc main() {\n\t_, cleanup, err := injectBaz()\n\tif err == nil {\n\t\tfmt.Println(\"<nil>\")\n\t} else {\n\t\tfmt.Println(strings.Contains(err.Error(), \"bork!\"))\n\t}\n\tfmt.Println(cleanedFoo, cleanedBar, cleanup == nil)\n}\n\ntype Foo int\ntype Bar int\ntype Baz int\n\nfunc provideFoo() (*Foo, func()) {\n\tfoo := new(Foo)\n\t*foo = 42\n\treturn foo, func() { *foo = 0; cleanedFoo = true }\n}\n\nfunc provideBar(foo *Foo) (*Bar, func(), error) {\n\tbar := new(Bar)\n\t*bar = 77\n\treturn bar, func() {\n\t\tif *foo == 0 {\n\t\t\tpanic(\"foo cleaned up before bar\")\n\t\t}\n\t\t*bar = 0\n\t\tcleanedBar = true\n\t}, nil\n}\n\nfunc provideBaz(bar *Bar) (Baz, error) {\n\treturn 0, errors.New(\"bork!\")\n}\n"
  },
  {
    "path": "internal/wire/testdata/PartialCleanup/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectBaz() (Baz, func(), error) {\n\twire.Build(provideFoo, provideBar, provideBaz)\n\treturn 0, nil, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/PartialCleanup/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/PartialCleanup/want/program_out.txt",
    "content": "true\ntrue true true\n"
  },
  {
    "path": "internal/wire/testdata/PartialCleanup/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectBaz() (Baz, func(), error) {\n\tfoo, cleanup := provideFoo()\n\tbar, cleanup2, err := provideBar(foo)\n\tif err != nil {\n\t\tcleanup()\n\t\treturn 0, nil, err\n\t}\n\tbaz, err := provideBaz(bar)\n\tif err != nil {\n\t\tcleanup2()\n\t\tcleanup()\n\t\treturn 0, nil, err\n\t}\n\treturn baz, func() {\n\t\tcleanup2()\n\t\tcleanup()\n\t}, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/PkgImport/anon1/anon1.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage anon1\n"
  },
  {
    "path": "internal/wire/testdata/PkgImport/anon2/anon2.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage anon2\n"
  },
  {
    "path": "internal/wire/testdata/PkgImport/bar/bar.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bar\n\ntype Bar int\n\nfunc ProvideBar() Bar {\n\treturn 1\n}\n"
  },
  {
    "path": "internal/wire/testdata/PkgImport/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"example.com/bar\"\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooBar())\n}\n\ntype Foo int\ntype FooBar int\n\nvar Set = wire.NewSet(\n\tprovideFoo,\n\tbar.ProvideBar,\n\tprovideFooBar)\n\nfunc provideFoo() Foo {\n\treturn 41\n}\n\nfunc provideFooBar(foo Foo, barVal bar.Bar) FooBar {\n\treturn FooBar(foo) + FooBar(barVal)\n}\n"
  },
  {
    "path": "internal/wire/testdata/PkgImport/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t_ \"example.com/anon1\" // intentionally duplicated\n\t_ \"example.com/anon1\" // intentionally duplicated\n\t_ \"example.com/anon2\"\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooBar() FooBar {\n\twire.Build(Set)\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/PkgImport/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/PkgImport/want/program_out.txt",
    "content": "42\n"
  },
  {
    "path": "internal/wire/testdata/PkgImport/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"example.com/bar\"\n)\n\nimport (\n\t_ \"example.com/anon1\"\n\t_ \"example.com/anon2\"\n)\n\n// Injectors from wire.go:\n\nfunc injectFooBar() FooBar {\n\tfoo := provideFoo()\n\tbarBar := bar.ProvideBar()\n\tfooBar := provideFooBar(foo, barBar)\n\treturn fooBar\n}\n"
  },
  {
    "path": "internal/wire/testdata/ProviderSetBindingMissingConcreteType/foo/foo.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectFoo())\n}\n\ntype fooer interface {\n\tDo() string\n}\n\ntype foo struct{}\n\nfunc (f *foo) Do() string {\n\treturn \"did foo\"\n}\n\nfunc newFoo() *foo {\n\treturn &foo{}\n}\n\nvar (\n\tsetA = wire.NewSet(newFoo)\n\t// This set is invalid because it has a wire.Bind but no matching provider.\n\t// From the user guide:\n\t// Any set that includes an interface binding must also have a provider in\n\t// the same set that provides the concrete type.\n\tsetB = wire.NewSet(wire.Bind(new(fooer), new(*foo)))\n\tsetC = wire.NewSet(setA, setB)\n)\n"
  },
  {
    "path": "internal/wire/testdata/ProviderSetBindingMissingConcreteType/foo/wire.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFoo() *foo {\n\twire.Build(setC)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/ProviderSetBindingMissingConcreteType/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ProviderSetBindingMissingConcreteType/want/wire_errs.txt",
    "content": "example.com/foo/foo.go:x:y: wire.Bind of concrete type \"*example.com/foo.foo\" to interface \"example.com/foo.fooer\", but setB does not include a provider for \"*example.com/foo.foo\""
  },
  {
    "path": "internal/wire/testdata/RelativePkg/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n\n// provideMessage provides a friendly user greeting.\nfunc provideMessage() string {\n\treturn \"Hello, World!\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/RelativePkg/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\twire.Build(provideMessage)\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/RelativePkg/pkg",
    "content": "./foo\n"
  },
  {
    "path": "internal/wire/testdata/RelativePkg/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/RelativePkg/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage() string {\n\tstring2 := provideMessage()\n\treturn string2\n}\n"
  },
  {
    "path": "internal/wire/testdata/ReservedKeywords/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\ti := injectInterface()\n\tfmt.Println(i)\n}\n\ntype Interface int\ntype Select int\n\nfunc provideInterface(s Select) Interface {\n\treturn Interface(int(s) + 1)\n}\n\nfunc provideSelect() Select {\n\treturn Select(41)\n}\n"
  },
  {
    "path": "internal/wire/testdata/ReservedKeywords/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\n// Wire tries to disambiguate the variable \"select\" by prepending\n// the package name; this package-scoped variable conflicts with that\n// and forces a different name.\nvar mainSelect = 0\n\nfunc injectInterface() Interface {\n\t// interface and select are Go reserved words, so\n\t// Wire should avoid using them as variable names.\n\tpanic(wire.Build(provideInterface, provideSelect))\n}\n"
  },
  {
    "path": "internal/wire/testdata/ReservedKeywords/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ReservedKeywords/want/program_out.txt",
    "content": "42\n"
  },
  {
    "path": "internal/wire/testdata/ReservedKeywords/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectInterface() Interface {\n\tselect2 := provideSelect()\n\tmainInterface := provideInterface(select2)\n\treturn mainInterface\n}\n\n// wire.go:\n\n// Wire tries to disambiguate the variable \"select\" by prepending\n// the package name; this package-scoped variable conflicts with that\n// and forces a different name.\nvar mainSelect = 0\n"
  },
  {
    "path": "internal/wire/testdata/ReturnArgumentAsInterface/foo/foo.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectStringer(\"Hello, World!\"))\n}\n\ntype MyString string\n\nfunc (s MyString) String() string { return string(s) }\n"
  },
  {
    "path": "internal/wire/testdata/ReturnArgumentAsInterface/foo/wire.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc injectStringer(s MyString) fmt.Stringer {\n\twire.Build(wire.Bind(new(fmt.Stringer), new(MyString)))\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/ReturnArgumentAsInterface/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ReturnArgumentAsInterface/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/ReturnArgumentAsInterface/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\n// Injectors from wire.go:\n\nfunc injectStringer(s MyString) fmt.Stringer {\n\treturn s\n}\n"
  },
  {
    "path": "internal/wire/testdata/ReturnError/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfoo, err := injectFoo()\n\tfmt.Println(foo) // should be zero, the injector should ignore provideFoo's return value.\n\tif err == nil {\n\t\tfmt.Println(\"<nil>\")\n\t} else {\n\t\tfmt.Println(strings.Contains(err.Error(), \"there is no Foo\"))\n\t}\n}\n\ntype Foo int\n\nfunc provideFoo() (Foo, error) {\n\treturn 42, errors.New(\"there is no Foo\")\n}\n\nvar Set = wire.NewSet(provideFoo)\n"
  },
  {
    "path": "internal/wire/testdata/ReturnError/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFoo() (Foo, error) {\n\twire.Build(Set)\n\treturn 0, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/ReturnError/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ReturnError/want/program_out.txt",
    "content": "0\ntrue\n"
  },
  {
    "path": "internal/wire/testdata/ReturnError/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFoo() (Foo, error) {\n\tfoo, err := provideFoo()\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\treturn foo, nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/Struct/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sync\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfb := injectFooBar()\n\tpfb := injectPartFooBar()\n\tfmt.Println(fb.Foo, fb.Bar)\n\tfmt.Println(pfb.Foo, pfb.Bar)\n}\n\ntype Foo int\ntype Bar int\n\ntype FooBar struct {\n\tmu  sync.Mutex `wire:\"-\"`\n\tFoo Foo\n\tBar Bar\n}\n\nfunc provideFoo() Foo {\n\treturn 41\n}\n\nfunc provideBar() Bar {\n\treturn 1\n}\n\nvar Set = wire.NewSet(\n\twire.Struct(new(FooBar), \"*\"),\n\tprovideFoo,\n\tprovideBar)\n\nvar PartSet = wire.NewSet(\n\twire.Struct(new(FooBar), \"Foo\"),\n\tprovideFoo,\n)\n"
  },
  {
    "path": "internal/wire/testdata/Struct/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooBar() FooBar {\n\twire.Build(Set)\n\treturn FooBar{}\n}\n\nfunc injectPartFooBar() FooBar {\n\twire.Build(PartSet)\n\treturn FooBar{}\n}\n"
  },
  {
    "path": "internal/wire/testdata/Struct/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/Struct/want/program_out.txt",
    "content": "41 1\n41 0\n"
  },
  {
    "path": "internal/wire/testdata/Struct/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFooBar() FooBar {\n\tfoo := provideFoo()\n\tbar := provideBar()\n\tfooBar := FooBar{\n\t\tFoo: foo,\n\t\tBar: bar,\n\t}\n\treturn fooBar\n}\n\nfunc injectPartFooBar() FooBar {\n\tfoo := provideFoo()\n\tfooBar := FooBar{\n\t\tFoo: foo,\n\t}\n\treturn fooBar\n}\n"
  },
  {
    "path": "internal/wire/testdata/StructNotAStruct/foo/foo.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tfmt.Println(inject(A{\"Hello\"}))\n}\n\ntype A struct {\n\tB string\n}\n"
  },
  {
    "path": "internal/wire/testdata/StructNotAStruct/foo/wire.go",
    "content": "// Copyright 2019 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc inject(a A) string {\n\twire.Build(wire.Struct(new(*A), \"*\"))\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/StructNotAStruct/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/StructNotAStruct/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: first argument to Struct must be a pointer to a named struct; found **example.com/foo.A"
  },
  {
    "path": "internal/wire/testdata/StructPointer/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfb := injectFooBar()\n\te := injectEmptyStruct()\n\tfmt.Printf(\"%d %d %v\\n\", fb.Foo, fb.Bar, e)\n}\n\ntype Foo int\ntype Bar int\n\ntype FooBar struct {\n\tFoo Foo\n\tBar Bar\n}\n\ntype Empty struct{}\n\nfunc provideFoo() Foo {\n\treturn 41\n}\n\nfunc provideBar() Bar {\n\treturn 1\n}\n\nvar Set = wire.NewSet(\n\twire.Struct(new(FooBar), \"*\"),\n\tprovideFoo,\n\tprovideBar)\n"
  },
  {
    "path": "internal/wire/testdata/StructPointer/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooBar() *FooBar {\n\twire.Build(Set)\n\treturn nil\n}\n\nfunc injectEmptyStruct() *Empty {\n\twire.Build(wire.Struct(new(Empty)))\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/StructPointer/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/StructPointer/want/program_out.txt",
    "content": "41 1 &{}\n"
  },
  {
    "path": "internal/wire/testdata/StructPointer/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFooBar() *FooBar {\n\tfoo := provideFoo()\n\tbar := provideBar()\n\tfooBar := &FooBar{\n\t\tFoo: foo,\n\t\tBar: bar,\n\t}\n\treturn fooBar\n}\n\nfunc injectEmptyStruct() *Empty {\n\tempty := &Empty{}\n\treturn empty\n}\n"
  },
  {
    "path": "internal/wire/testdata/StructWithPreventTag/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"sync\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tpfb := injectPartFooBar()\n\tfmt.Println(pfb.Foo)\n}\n\ntype Foo int\n\ntype FooBar struct {\n\tmu  sync.Mutex `wire:\"-\"`\n\tFoo Foo\n}\n\nfunc provideFoo() Foo {\n\treturn 42\n}\n\nfunc provideMutex() sync.Mutex {\n\treturn sync.Mutex{}\n}\n\nvar ProhibitSet = wire.NewSet(\n\twire.Struct(new(FooBar), \"mu\", \"Foo\"),\n\tprovideMutex,\n\tprovideFoo,\n)\n"
  },
  {
    "path": "internal/wire/testdata/StructWithPreventTag/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectPartFooBar() FooBar {\n\twire.Build(ProhibitSet)\n\treturn FooBar{}\n}\n"
  },
  {
    "path": "internal/wire/testdata/StructWithPreventTag/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/StructWithPreventTag/want/wire_errs.txt",
    "content": "example.com/foo/foo.go:x:y: \"mu\" is prevented from injecting by wire"
  },
  {
    "path": "internal/wire/testdata/TwoDeps/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooBar())\n}\n\ntype Foo int\ntype Bar int\ntype FooBar int\n\nfunc provideFoo() Foo {\n\treturn 40\n}\n\nfunc provideBar() Bar {\n\treturn 2\n}\n\nfunc provideFooBar(foo Foo, bar Bar) FooBar {\n\treturn FooBar(foo) + FooBar(bar)\n}\n\nvar Set = wire.NewSet(\n\tprovideFoo,\n\tprovideBar,\n\tprovideFooBar)\n"
  },
  {
    "path": "internal/wire/testdata/TwoDeps/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooBar() FooBar {\n\twire.Build(Set)\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/TwoDeps/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/TwoDeps/want/program_out.txt",
    "content": "42\n"
  },
  {
    "path": "internal/wire/testdata/TwoDeps/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFooBar() FooBar {\n\tfoo := provideFoo()\n\tbar := provideBar()\n\tfooBar := provideFooBar(foo, bar)\n\treturn fooBar\n}\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedStruct/bar/bar.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bar\n\nvar foo struct {\n\tX int\n}\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedStruct/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Printf(\"%v\\n\", injectedBar())\n}\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedStruct/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"example.com/bar\"\n\t\"github.com/google/wire\"\n)\n\nfunc injectedBar() string {\n\t// Fails because bar.foo is unexported.\n\twire.Build(bar.foo.X)\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedStruct/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedStruct/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: name foo not exported by package bar\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedValue/bar/bar.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage bar\n\nimport \"github.com/google/wire\"\n\nvar Value = wire.Value(privateMsg)\n\nvar privateMsg = \"Hello, World!\"\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedValue/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedValue/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"example.com/bar\"\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\t// Fails because bar.Value references unexported bar.privateMsg.\n\twire.Build(bar.Value)\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedValue/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/UnexportedValue/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: inject injectedMessage: value string can't be used: uses unexported identifier privateMsg"
  },
  {
    "path": "internal/wire/testdata/UnusedProviders/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooBar())\n}\n\ntype Foo int\ntype Bar int\ntype Unused int\ntype UnusedInSet int\ntype OneOfTwo int\ntype TwoOfTwo int\n\ntype FooBar struct {\n\tMyFoo    *Foo\n\tMyBar    Bar\n\tMyUnused Unused\n}\n\nvar (\n\tunusedSet        = wire.NewSet(provideUnusedInSet)\n\tpartiallyUsedSet = wire.NewSet(provideOneOfTwo, provideTwoOfTwo)\n)\n\ntype Fooer interface {\n\tFoo() string\n}\n\nfunc (f *Foo) Foo() string {\n\treturn fmt.Sprintf(\"Hello World %d\", f)\n}\n\nfunc provideFoo() *Foo {\n\tf := new(Foo)\n\t*f = 1\n\treturn f\n}\n\nfunc provideBar(foo *Foo, one OneOfTwo) Bar {\n\treturn Bar(int(*foo) + int(one))\n}\n\nfunc provideUnused() Unused {\n\treturn 1\n}\n\nfunc provideUnusedInSet() UnusedInSet {\n\treturn 1\n}\n\nfunc provideOneOfTwo() OneOfTwo {\n\treturn 1\n}\n\nfunc provideTwoOfTwo() TwoOfTwo {\n\treturn 1\n}\n\ntype S struct {\n\tCfg Config\n}\n\ntype Config int\n"
  },
  {
    "path": "internal/wire/testdata/UnusedProviders/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooBar() FooBar {\n\twire.Build(\n\t\tprovideFoo,                       // needed as input for provideBar\n\t\tprovideBar,                       // needed for FooBar\n\t\tpartiallyUsedSet,                 // 1/2 providers in the set are needed\n\t\tprovideUnused,                    // not needed -> error\n\t\twire.Value(\"unused\"),             // not needed -> error\n\t\tunusedSet,                        // nothing in set is needed -> error\n\t\twire.Bind(new(Fooer), new(*Foo)), // binding to Fooer is not needed -> error\n\t\twire.FieldsOf(new(S), \"Cfg\"),     // S.Cfg not needed -> error\n\t\twire.Struct(new(FooBar), \"MyFoo\", \"MyBar\"), // needed for FooBar\n\t)\n\treturn FooBar{}\n}\n"
  },
  {
    "path": "internal/wire/testdata/UnusedProviders/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/UnusedProviders/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: inject injectFooBar: unused provider set \"unusedSet\"\n\nexample.com/foo/wire.go:x:y: inject injectFooBar: unused provider \"main.provideUnused\"\n\nexample.com/foo/wire.go:x:y: inject injectFooBar: unused value of type string\n\nexample.com/foo/wire.go:x:y: inject injectFooBar: unused interface binding to type example.com/foo.Fooer\n\nexample.com/foo/wire.go:x:y: inject injectFooBar: unused field \"example.com/foo.S\".Cfg"
  },
  {
    "path": "internal/wire/testdata/ValueChain/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc main() {\n\tfmt.Println(injectFooBar())\n}\n\ntype Foo int\ntype FooBar int\n\nvar Set = wire.NewSet(\n\twire.Value(Foo(41)),\n\tprovideFooBar)\n\nfunc provideFooBar(foo Foo) FooBar {\n\treturn FooBar(foo) + 1\n}\n"
  },
  {
    "path": "internal/wire/testdata/ValueChain/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFooBar() FooBar {\n\twire.Build(Set)\n\treturn 0\n}\n"
  },
  {
    "path": "internal/wire/testdata/ValueChain/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ValueChain/want/program_out.txt",
    "content": "42\n"
  },
  {
    "path": "internal/wire/testdata/ValueChain/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFooBar() FooBar {\n\tfoo := _wireFooValue\n\tfooBar := provideFooBar(foo)\n\treturn fooBar\n}\n\nvar (\n\t_wireFooValue = Foo(41)\n)\n"
  },
  {
    "path": "internal/wire/testdata/ValueConversion/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(injectedMessage())\n}\n\ntype Foo string\n"
  },
  {
    "path": "internal/wire/testdata/ValueConversion/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() Foo {\n\twire.Build(wire.Value(Foo(\"Hello, World!\")))\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/ValueConversion/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ValueConversion/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/ValueConversion/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage() Foo {\n\tfoo := _wireFooValue\n\treturn foo\n}\n\nvar (\n\t_wireFooValue = Foo(\"Hello, World!\")\n)\n"
  },
  {
    "path": "internal/wire/testdata/ValueFromFunctionScope/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\ntype foo struct {\n\tV int\n}\n\ntype bar struct {\n\tV int\n}\n\nfunc newBar(v int) *bar {\n\treturn &bar{V: v}\n}\n\nfunc main() {\n\tf := &foo{V: 42}\n\tb := injectBar(f)\n\tfmt.Printf(\"%d\\n\", b.V)\n}\n"
  },
  {
    "path": "internal/wire/testdata/ValueFromFunctionScope/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectBar(f *foo) *bar {\n\twire.Build(\n\t\tnewBar,\n\t\twire.Value(f.V), // fails because f.V is not from package scope\n\t)\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/ValueFromFunctionScope/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ValueFromFunctionScope/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: inject injectBar: value int can't be used: f is not declared in package scope"
  },
  {
    "path": "internal/wire/testdata/ValueIsInterfaceValue/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"io/ioutil\"\n\t\"strings\"\n)\n\nfunc main() {\n\tr := injectedReader(strings.NewReader(\"hello world\"))\n\tbuf, _ := ioutil.ReadAll(r)\n\tfmt.Println(string(buf))\n}\n"
  },
  {
    "path": "internal/wire/testdata/ValueIsInterfaceValue/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"io\"\n\t\"strings\"\n\n\t\"github.com/google/wire\"\n)\n\nfunc injectedReader(r *strings.Reader) io.Reader {\n\twire.Build(wire.Value(io.Reader(r)))\n\treturn nil\n}\n"
  },
  {
    "path": "internal/wire/testdata/ValueIsInterfaceValue/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ValueIsInterfaceValue/want/wire_errs.txt",
    "content": "example.com/foo/wire.go:x:y: argument to Value may not be an interface value (found io.Reader); use InterfaceValue instead"
  },
  {
    "path": "internal/wire/testdata/ValueIsStruct/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n)\n\nfunc main() {\n\tf := injectFoo()\n\tfmt.Printf(\"%d\\n\", f.X)\n}\n\ntype Foo struct {\n\tX int\n}\n"
  },
  {
    "path": "internal/wire/testdata/ValueIsStruct/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectFoo() Foo {\n\twire.Build(wire.Value(Foo{X: 42}))\n\treturn Foo{}\n}\n"
  },
  {
    "path": "internal/wire/testdata/ValueIsStruct/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/ValueIsStruct/want/program_out.txt",
    "content": "42\n"
  },
  {
    "path": "internal/wire/testdata/ValueIsStruct/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectFoo() Foo {\n\tfoo := _wireFooValue\n\treturn foo\n}\n\nvar (\n\t_wireFooValue = Foo{X: 42}\n)\n"
  },
  {
    "path": "internal/wire/testdata/VarValue/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\t// Mutating value; value should have been stored at package initialization.\n\tmsg = \"Hello, World!\"\n\n\tfmt.Println(injectedMessage())\n}\n\nvar msg string = \"Package init\"\n"
  },
  {
    "path": "internal/wire/testdata/VarValue/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage() string {\n\twire.Build(wire.Value(msg))\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/VarValue/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/VarValue/want/program_out.txt",
    "content": "Package init\n"
  },
  {
    "path": "internal/wire/testdata/VarValue/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage() string {\n\tstring2 := _wireStringValue\n\treturn string2\n}\n\nvar (\n\t_wireStringValue = msg\n)\n"
  },
  {
    "path": "internal/wire/testdata/Varargs/foo/foo.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n)\n\nfunc main() {\n\tfmt.Println(injectedMessage(\"\", \"Hello,\", \"World!\"))\n}\n\ntype title string\n\n// provideMessage provides a friendly user greeting.\nfunc provideMessage(words ...string) string {\n\treturn strings.Join(words, \" \")\n}\n"
  },
  {
    "path": "internal/wire/testdata/Varargs/foo/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n//+build wireinject\n\npackage main\n\nimport (\n\t\"github.com/google/wire\"\n)\n\nfunc injectedMessage(t title, lines ...string) string {\n\twire.Build(provideMessage)\n\treturn \"\"\n}\n"
  },
  {
    "path": "internal/wire/testdata/Varargs/pkg",
    "content": "example.com/foo\n"
  },
  {
    "path": "internal/wire/testdata/Varargs/want/program_out.txt",
    "content": "Hello, World!\n"
  },
  {
    "path": "internal/wire/testdata/Varargs/want/wire_gen.go",
    "content": "// Code generated by Wire. DO NOT EDIT.\n\n//go:generate go run -mod=mod github.com/google/wire/cmd/wire\n//go:build !wireinject\n// +build !wireinject\n\npackage main\n\n// Injectors from wire.go:\n\nfunc injectedMessage(t title, lines ...string) string {\n\tstring2 := provideMessage(lines...)\n\treturn string2\n}\n"
  },
  {
    "path": "internal/wire/wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Package wire provides compile-time dependency injection logic as a\n// Go library.\npackage wire\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"go/ast\"\n\t\"go/format\"\n\t\"go/printer\"\n\t\"go/token\"\n\t\"go/types\"\n\t\"io/ioutil\"\n\t\"path/filepath\"\n\t\"sort\"\n\t\"strconv\"\n\t\"strings\"\n\t\"unicode\"\n\t\"unicode/utf8\"\n\n\t\"golang.org/x/tools/go/ast/astutil\"\n\t\"golang.org/x/tools/go/packages\"\n)\n\n// GenerateResult stores the result for a package from a call to Generate.\ntype GenerateResult struct {\n\t// PkgPath is the package's PkgPath.\n\tPkgPath string\n\t// OutputPath is the path where the generated output should be written.\n\t// May be empty if there were errors.\n\tOutputPath string\n\t// Content is the gofmt'd source code that was generated. May be nil if\n\t// there were errors during generation.\n\tContent []byte\n\t// Errs is a slice of errors identified during generation.\n\tErrs []error\n}\n\n// Commit writes the generated file to disk.\nfunc (gen GenerateResult) Commit() error {\n\tif len(gen.Content) == 0 {\n\t\treturn nil\n\t}\n\treturn ioutil.WriteFile(gen.OutputPath, gen.Content, 0666)\n}\n\n// GenerateOptions holds options for Generate.\ntype GenerateOptions struct {\n\t// Header will be inserted at the start of each generated file.\n\tHeader           []byte\n\tPrefixOutputFile string\n\tTags             string\n}\n\n// Generate performs dependency injection for the packages that match the given\n// patterns, return a GenerateResult for each package. The package pattern is\n// defined by the underlying build system. For the go tool, this is described at\n// https://golang.org/cmd/go/#hdr-Package_lists_and_patterns\n//\n// wd is the working directory and env is the set of environment\n// variables to use when loading the package specified by pkgPattern. If\n// env is nil or empty, it is interpreted as an empty set of variables.\n// In case of duplicate environment variables, the last one in the list\n// takes precedence.\n//\n// Generate may return one or more errors if it failed to load the packages.\nfunc Generate(ctx context.Context, wd string, env []string, patterns []string, opts *GenerateOptions) ([]GenerateResult, []error) {\n\tif opts == nil {\n\t\topts = &GenerateOptions{}\n\t}\n\tpkgs, errs := load(ctx, wd, env, opts.Tags, patterns)\n\tif len(errs) > 0 {\n\t\treturn nil, errs\n\t}\n\tgenerated := make([]GenerateResult, len(pkgs))\n\tfor i, pkg := range pkgs {\n\t\tgenerated[i].PkgPath = pkg.PkgPath\n\t\toutDir, err := detectOutputDir(pkg.GoFiles)\n\t\tif err != nil {\n\t\t\tgenerated[i].Errs = append(generated[i].Errs, err)\n\t\t\tcontinue\n\t\t}\n\t\tgenerated[i].OutputPath = filepath.Join(outDir, opts.PrefixOutputFile+\"wire_gen.go\")\n\t\tg := newGen(pkg)\n\t\tinjectorFiles, errs := generateInjectors(g, pkg)\n\t\tif len(errs) > 0 {\n\t\t\tgenerated[i].Errs = errs\n\t\t\tcontinue\n\t\t}\n\t\tcopyNonInjectorDecls(g, injectorFiles, pkg.TypesInfo)\n\t\tgoSrc := g.frame(opts.Tags)\n\t\tif len(opts.Header) > 0 {\n\t\t\tgoSrc = append(opts.Header, goSrc...)\n\t\t}\n\t\tfmtSrc, err := format.Source(goSrc)\n\t\tif err != nil {\n\t\t\t// This is likely a bug from a poorly generated source file.\n\t\t\t// Add an error but also the unformatted source.\n\t\t\tgenerated[i].Errs = append(generated[i].Errs, err)\n\t\t} else {\n\t\t\tgoSrc = fmtSrc\n\t\t}\n\t\tgenerated[i].Content = goSrc\n\t}\n\treturn generated, nil\n}\n\nfunc detectOutputDir(paths []string) (string, error) {\n\tif len(paths) == 0 {\n\t\treturn \"\", errors.New(\"no files to derive output directory from\")\n\t}\n\tdir := filepath.Dir(paths[0])\n\tfor _, p := range paths[1:] {\n\t\tif dir2 := filepath.Dir(p); dir2 != dir {\n\t\t\treturn \"\", fmt.Errorf(\"found conflicting directories %q and %q\", dir, dir2)\n\t\t}\n\t}\n\treturn dir, nil\n}\n\n// generateInjectors generates the injectors for a given package.\nfunc generateInjectors(g *gen, pkg *packages.Package) (injectorFiles []*ast.File, _ []error) {\n\toc := newObjectCache([]*packages.Package{pkg})\n\tinjectorFiles = make([]*ast.File, 0, len(pkg.Syntax))\n\tec := new(errorCollector)\n\tfor _, f := range pkg.Syntax {\n\t\tfor _, decl := range f.Decls {\n\t\t\tfn, ok := decl.(*ast.FuncDecl)\n\t\t\tif !ok {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tbuildCall, err := findInjectorBuild(pkg.TypesInfo, fn)\n\t\t\tif err != nil {\n\t\t\t\tec.add(err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif buildCall == nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif len(injectorFiles) == 0 || injectorFiles[len(injectorFiles)-1] != f {\n\t\t\t\t// This is the first injector generated for this file.\n\t\t\t\t// Write a file header.\n\t\t\t\tname := filepath.Base(g.pkg.Fset.File(f.Pos()).Name())\n\t\t\t\tg.p(\"// Injectors from %s:\\n\\n\", name)\n\t\t\t\tinjectorFiles = append(injectorFiles, f)\n\t\t\t}\n\t\t\tsig := pkg.TypesInfo.ObjectOf(fn.Name).Type().(*types.Signature)\n\t\t\tins, _, err := injectorFuncSignature(sig)\n\t\t\tif err != nil {\n\t\t\t\tif w, ok := err.(*wireErr); ok {\n\t\t\t\t\tec.add(notePosition(w.position, fmt.Errorf(\"inject %s: %v\", fn.Name.Name, w.error)))\n\t\t\t\t} else {\n\t\t\t\t\tec.add(notePosition(g.pkg.Fset.Position(fn.Pos()), fmt.Errorf(\"inject %s: %v\", fn.Name.Name, err)))\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tinjectorArgs := &InjectorArgs{\n\t\t\t\tName:  fn.Name.Name,\n\t\t\t\tTuple: ins,\n\t\t\t\tPos:   fn.Pos(),\n\t\t\t}\n\t\t\tset, errs := oc.processNewSet(pkg.TypesInfo, pkg.PkgPath, buildCall, injectorArgs, \"\")\n\t\t\tif len(errs) > 0 {\n\t\t\t\tec.add(notePositionAll(g.pkg.Fset.Position(fn.Pos()), errs)...)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif errs := g.inject(fn.Pos(), fn.Name.Name, sig, set, fn.Doc); len(errs) > 0 {\n\t\t\t\tec.add(errs...)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\tfor _, impt := range f.Imports {\n\t\t\tif impt.Name != nil && impt.Name.Name == \"_\" {\n\t\t\t\tg.anonImports[impt.Path.Value] = true\n\t\t\t}\n\t\t}\n\t}\n\tif len(ec.errors) > 0 {\n\t\treturn nil, ec.errors\n\t}\n\treturn injectorFiles, nil\n}\n\n// copyNonInjectorDecls copies any non-injector declarations from the\n// given files into the generated output.\nfunc copyNonInjectorDecls(g *gen, files []*ast.File, info *types.Info) {\n\tfor _, f := range files {\n\t\tname := filepath.Base(g.pkg.Fset.File(f.Pos()).Name())\n\t\tfirst := true\n\t\tfor _, decl := range f.Decls {\n\t\t\tswitch decl := decl.(type) {\n\t\t\tcase *ast.FuncDecl:\n\t\t\t\t// OK to ignore error, as any error cases should already have\n\t\t\t\t// been filtered out.\n\t\t\t\tif buildCall, _ := findInjectorBuild(info, decl); buildCall != nil {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\tcase *ast.GenDecl:\n\t\t\t\tif decl.Tok == token.IMPORT {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\tdefault:\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif first {\n\t\t\t\tg.p(\"// %s:\\n\\n\", name)\n\t\t\t\tfirst = false\n\t\t\t}\n\t\t\t// TODO(light): Add line number at top of each declaration.\n\t\t\tg.writeAST(info, decl)\n\t\t\tg.p(\"\\n\\n\")\n\t\t}\n\t}\n}\n\n// importInfo holds info about an import.\ntype importInfo struct {\n\t// name is the identifier that is used in the generated source.\n\tname string\n\t// differs is true if the import is given an identifier that does not\n\t// match the package's identifier.\n\tdiffers bool\n}\n\n// gen is the file-wide generator state.\ntype gen struct {\n\tpkg         *packages.Package\n\tbuf         bytes.Buffer\n\timports     map[string]importInfo\n\tanonImports map[string]bool\n\tvalues      map[ast.Expr]string\n}\n\nfunc newGen(pkg *packages.Package) *gen {\n\treturn &gen{\n\t\tpkg:         pkg,\n\t\tanonImports: make(map[string]bool),\n\t\timports:     make(map[string]importInfo),\n\t\tvalues:      make(map[ast.Expr]string),\n\t}\n}\n\n// frame bakes the built up source body into an unformatted Go source file.\nfunc (g *gen) frame(tags string) []byte {\n\tif g.buf.Len() == 0 {\n\t\treturn nil\n\t}\n\tvar buf bytes.Buffer\n\tif len(tags) > 0 {\n\t\ttags = fmt.Sprintf(\" gen -tags \\\"%s\\\"\", tags)\n\t}\n\tbuf.WriteString(\"// Code generated by Wire. DO NOT EDIT.\\n\\n\")\n\tbuf.WriteString(\"//go:generate go run -mod=mod github.com/google/wire/cmd/wire\" + tags + \"\\n\")\n\tbuf.WriteString(\"//+build !wireinject\\n\\n\")\n\tbuf.WriteString(\"package \")\n\tbuf.WriteString(g.pkg.Name)\n\tbuf.WriteString(\"\\n\\n\")\n\tif len(g.imports) > 0 {\n\t\tbuf.WriteString(\"import (\\n\")\n\t\timps := make([]string, 0, len(g.imports))\n\t\tfor path := range g.imports {\n\t\t\timps = append(imps, path)\n\t\t}\n\t\tsort.Strings(imps)\n\t\tfor _, path := range imps {\n\t\t\t// Omit the local package identifier if it matches the package name.\n\t\t\tinfo := g.imports[path]\n\t\t\tif info.differs {\n\t\t\t\tfmt.Fprintf(&buf, \"\\t%s %q\\n\", info.name, path)\n\t\t\t} else {\n\t\t\t\tfmt.Fprintf(&buf, \"\\t%q\\n\", path)\n\t\t\t}\n\t\t}\n\t\tbuf.WriteString(\")\\n\\n\")\n\t}\n\tif len(g.anonImports) > 0 {\n\t\tbuf.WriteString(\"import (\\n\")\n\t\tanonImps := make([]string, 0, len(g.anonImports))\n\t\tfor path := range g.anonImports {\n\t\t\tanonImps = append(anonImps, path)\n\t\t}\n\t\tsort.Strings(anonImps)\n\n\t\tfor _, path := range anonImps {\n\t\t\tfmt.Fprintf(&buf, \"\\t_ %s\\n\", path)\n\t\t}\n\t\tbuf.WriteString(\")\\n\\n\")\n\t}\n\tbuf.Write(g.buf.Bytes())\n\treturn buf.Bytes()\n}\n\n// inject emits the code for an injector.\nfunc (g *gen) inject(pos token.Pos, name string, sig *types.Signature, set *ProviderSet, doc *ast.CommentGroup) []error {\n\tinjectSig, err := funcOutput(sig)\n\tif err != nil {\n\t\treturn []error{notePosition(g.pkg.Fset.Position(pos),\n\t\t\tfmt.Errorf(\"inject %s: %v\", name, err))}\n\t}\n\tparams := sig.Params()\n\tcalls, errs := solve(g.pkg.Fset, injectSig.out, params, set)\n\tif len(errs) > 0 {\n\t\treturn mapErrors(errs, func(e error) error {\n\t\t\tif w, ok := e.(*wireErr); ok {\n\t\t\t\treturn notePosition(w.position, fmt.Errorf(\"inject %s: %v\", name, w.error))\n\t\t\t}\n\t\t\treturn notePosition(g.pkg.Fset.Position(pos), fmt.Errorf(\"inject %s: %v\", name, e))\n\t\t})\n\t}\n\ttype pendingVar struct {\n\t\tname     string\n\t\texpr     ast.Expr\n\t\ttypeInfo *types.Info\n\t}\n\tvar pendingVars []pendingVar\n\tec := new(errorCollector)\n\tfor i := range calls {\n\t\tc := &calls[i]\n\t\tif c.hasCleanup && !injectSig.cleanup {\n\t\t\tts := types.TypeString(c.out, nil)\n\t\t\tec.add(notePosition(\n\t\t\t\tg.pkg.Fset.Position(pos),\n\t\t\t\tfmt.Errorf(\"inject %s: provider for %s returns cleanup but injection does not return cleanup function\", name, ts)))\n\t\t}\n\t\tif c.hasErr && !injectSig.err {\n\t\t\tts := types.TypeString(c.out, nil)\n\t\t\tec.add(notePosition(\n\t\t\t\tg.pkg.Fset.Position(pos),\n\t\t\t\tfmt.Errorf(\"inject %s: provider for %s returns error but injection not allowed to fail\", name, ts)))\n\t\t}\n\t\tif c.kind == valueExpr {\n\t\t\tif err := accessibleFrom(c.valueTypeInfo, c.valueExpr, g.pkg.PkgPath); err != nil {\n\t\t\t\t// TODO(light): Display line number of value expression.\n\t\t\t\tts := types.TypeString(c.out, nil)\n\t\t\t\tec.add(notePosition(\n\t\t\t\t\tg.pkg.Fset.Position(pos),\n\t\t\t\t\tfmt.Errorf(\"inject %s: value %s can't be used: %v\", name, ts, err)))\n\t\t\t}\n\t\t\tif g.values[c.valueExpr] == \"\" {\n\t\t\t\tt := c.valueTypeInfo.TypeOf(c.valueExpr)\n\n\t\t\t\tname := typeVariableName(t, \"\", func(name string) string { return \"_wire\" + export(name) + \"Value\" }, g.nameInFileScope)\n\t\t\t\tg.values[c.valueExpr] = name\n\t\t\t\tpendingVars = append(pendingVars, pendingVar{\n\t\t\t\t\tname:     name,\n\t\t\t\t\texpr:     c.valueExpr,\n\t\t\t\t\ttypeInfo: c.valueTypeInfo,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t}\n\tif len(ec.errors) > 0 {\n\t\treturn ec.errors\n\t}\n\n\t// Perform one pass to collect all imports, followed by the real pass.\n\tinjectPass(name, sig, calls, set, doc, &injectorGen{\n\t\tg:       g,\n\t\terrVar:  disambiguate(\"err\", g.nameInFileScope),\n\t\tdiscard: true,\n\t})\n\tinjectPass(name, sig, calls, set, doc, &injectorGen{\n\t\tg:       g,\n\t\terrVar:  disambiguate(\"err\", g.nameInFileScope),\n\t\tdiscard: false,\n\t})\n\tif len(pendingVars) > 0 {\n\t\tg.p(\"var (\\n\")\n\t\tfor _, pv := range pendingVars {\n\t\t\tg.p(\"\\t%s = \", pv.name)\n\t\t\tg.writeAST(pv.typeInfo, pv.expr)\n\t\t\tg.p(\"\\n\")\n\t\t}\n\t\tg.p(\")\\n\\n\")\n\t}\n\treturn nil\n}\n\n// rewritePkgRefs rewrites any package references in an AST into references for the\n// generated package.\nfunc (g *gen) rewritePkgRefs(info *types.Info, node ast.Node) ast.Node {\n\tstart, end := node.Pos(), node.End()\n\tnode = copyAST(node)\n\t// First, rewrite all package names. This lets us know all the\n\t// potentially colliding identifiers.\n\tnode = astutil.Apply(node, func(c *astutil.Cursor) bool {\n\t\tswitch node := c.Node().(type) {\n\t\tcase *ast.Ident:\n\t\t\t// This is an unqualified identifier (qualified identifiers are peeled off below).\n\t\t\tobj := info.ObjectOf(node)\n\t\t\tif obj == nil {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif pkg := obj.Pkg(); pkg != nil && obj.Parent() == pkg.Scope() && pkg.Path() != g.pkg.PkgPath {\n\t\t\t\t// An identifier from either a dot import or read from a different package.\n\t\t\t\tnewPkgID := g.qualifyImport(pkg.Name(), pkg.Path())\n\t\t\t\tc.Replace(&ast.SelectorExpr{\n\t\t\t\t\tX:   ast.NewIdent(newPkgID),\n\t\t\t\t\tSel: ast.NewIdent(node.Name),\n\t\t\t\t})\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\tcase *ast.SelectorExpr:\n\t\t\tpkgIdent, ok := node.X.(*ast.Ident)\n\t\t\tif !ok {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tpkgName, ok := info.ObjectOf(pkgIdent).(*types.PkgName)\n\t\t\tif !ok {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\t// This is a qualified identifier. Rewrite and avoid visiting subexpressions.\n\t\t\timported := pkgName.Imported()\n\t\t\tnewPkgID := g.qualifyImport(imported.Name(), imported.Path())\n\t\t\tc.Replace(&ast.SelectorExpr{\n\t\t\t\tX:   ast.NewIdent(newPkgID),\n\t\t\t\tSel: ast.NewIdent(node.Sel.Name),\n\t\t\t})\n\t\t\treturn false\n\t\tdefault:\n\t\t\treturn true\n\t\t}\n\t}, nil)\n\t// Now that we have all the identifiers, rename any variables declared\n\t// in this scope to not collide.\n\tnewNames := make(map[types.Object]string)\n\tinNewNames := func(n string) bool {\n\t\tfor _, other := range newNames {\n\t\t\tif other == n {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\tvar scopeStack []*types.Scope\n\tpkgScope := g.pkg.Types.Scope()\n\tnode = astutil.Apply(node, func(c *astutil.Cursor) bool {\n\t\tif scope := info.Scopes[c.Node()]; scope != nil {\n\t\t\tscopeStack = append(scopeStack, scope)\n\t\t}\n\t\tid, ok := c.Node().(*ast.Ident)\n\t\tif !ok {\n\t\t\treturn true\n\t\t}\n\t\tobj := info.ObjectOf(id)\n\t\tif obj == nil {\n\t\t\t// We rewrote this identifier earlier, so it does not need\n\t\t\t// further rewriting.\n\t\t\treturn true\n\t\t}\n\t\tif n, ok := newNames[obj]; ok {\n\t\t\t// We picked a new name for this symbol. Rewrite it.\n\t\t\tc.Replace(ast.NewIdent(n))\n\t\t\treturn false\n\t\t}\n\t\tif par := obj.Parent(); par == nil || par == pkgScope {\n\t\t\t// Don't rename methods, field names, or top-level identifiers.\n\t\t\treturn true\n\t\t}\n\n\t\t// Rename any symbols defined within rewritePkgRefs's node that conflict\n\t\t// with any symbols in the generated file.\n\t\tobjName := obj.Name()\n\t\tif pos := obj.Pos(); pos < start || end <= pos || !(g.nameInFileScope(objName) || inNewNames(objName)) {\n\t\t\treturn true\n\t\t}\n\t\tnewName := disambiguate(objName, func(n string) bool {\n\t\t\tif g.nameInFileScope(n) || inNewNames(n) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif len(scopeStack) > 0 {\n\t\t\t\t// Avoid picking a name that conflicts with other names in the\n\t\t\t\t// current scope.\n\t\t\t\t_, obj := scopeStack[len(scopeStack)-1].LookupParent(n, token.NoPos)\n\t\t\t\tif obj != nil {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t})\n\t\tnewNames[obj] = newName\n\t\tc.Replace(ast.NewIdent(newName))\n\t\treturn false\n\t}, func(c *astutil.Cursor) bool {\n\t\tif info.Scopes[c.Node()] != nil {\n\t\t\t// Should be top of stack; pop it.\n\t\t\tscopeStack = scopeStack[:len(scopeStack)-1]\n\t\t}\n\t\treturn true\n\t})\n\treturn node\n}\n\n// writeAST prints an AST node into the generated output, rewriting any\n// package references it encounters.\nfunc (g *gen) writeAST(info *types.Info, node ast.Node) {\n\tnode = g.rewritePkgRefs(info, node)\n\tif err := printer.Fprint(&g.buf, g.pkg.Fset, node); err != nil {\n\t\tpanic(err)\n\t}\n}\n\nfunc (g *gen) qualifiedID(pkgName, pkgPath, sym string) string {\n\tname := g.qualifyImport(pkgName, pkgPath)\n\tif name == \"\" {\n\t\treturn sym\n\t}\n\treturn name + \".\" + sym\n}\n\nfunc (g *gen) qualifyImport(name, path string) string {\n\tif path == g.pkg.PkgPath {\n\t\treturn \"\"\n\t}\n\t// TODO(light): This is depending on details of the current loader.\n\tconst vendorPart = \"vendor/\"\n\tunvendored := path\n\tif i := strings.LastIndex(path, vendorPart); i != -1 && (i == 0 || path[i-1] == '/') {\n\t\tunvendored = path[i+len(vendorPart):]\n\t}\n\tif info, ok := g.imports[unvendored]; ok {\n\t\treturn info.name\n\t}\n\t// TODO(light): Use parts of import path to disambiguate.\n\tnewName := disambiguate(name, func(n string) bool {\n\t\t// Don't let an import take the \"err\" name. That's annoying.\n\t\treturn n == \"err\" || g.nameInFileScope(n)\n\t})\n\tg.imports[unvendored] = importInfo{\n\t\tname:    newName,\n\t\tdiffers: newName != name,\n\t}\n\treturn newName\n}\n\nfunc (g *gen) nameInFileScope(name string) bool {\n\tfor _, other := range g.imports {\n\t\tif other.name == name {\n\t\t\treturn true\n\t\t}\n\t}\n\tfor _, other := range g.values {\n\t\tif other == name {\n\t\t\treturn true\n\t\t}\n\t}\n\t_, obj := g.pkg.Types.Scope().LookupParent(name, token.NoPos)\n\treturn obj != nil\n}\n\nfunc (g *gen) qualifyPkg(pkg *types.Package) string {\n\treturn g.qualifyImport(pkg.Name(), pkg.Path())\n}\n\nfunc (g *gen) p(format string, args ...interface{}) {\n\tfmt.Fprintf(&g.buf, format, args...)\n}\n\n// injectorGen is the per-injector pass generator state.\ntype injectorGen struct {\n\tg *gen\n\n\tparamNames   []string\n\tlocalNames   []string\n\tcleanupNames []string\n\terrVar       string\n\n\t// discard causes ig.p and ig.writeAST to no-op. Useful to run\n\t// generation for side-effects like filling in g.imports.\n\tdiscard bool\n}\n\n// injectPass generates an injector given the output from analysis.\n// The sig passed in should be verified.\nfunc injectPass(name string, sig *types.Signature, calls []call, set *ProviderSet, doc *ast.CommentGroup, ig *injectorGen) {\n\tparams := sig.Params()\n\tinjectSig, err := funcOutput(sig)\n\tif err != nil {\n\t\t// This should be checked by the caller already.\n\t\tpanic(err)\n\t}\n\tif doc != nil {\n\t\tfor _, c := range doc.List {\n\t\t\tig.p(\"%s\\n\", c.Text)\n\t\t}\n\t}\n\tig.p(\"func %s(\", name)\n\tfor i := 0; i < params.Len(); i++ {\n\t\tif i > 0 {\n\t\t\tig.p(\", \")\n\t\t}\n\t\tpi := params.At(i)\n\t\ta := pi.Name()\n\t\tif a == \"\" || a == \"_\" {\n\t\t\ta = typeVariableName(pi.Type(), \"arg\", unexport, ig.nameInInjector)\n\t\t} else {\n\t\t\ta = disambiguate(a, ig.nameInInjector)\n\t\t}\n\t\tig.paramNames = append(ig.paramNames, a)\n\t\tif sig.Variadic() && i == params.Len()-1 {\n\t\t\t// Keep the varargs signature instead of a slice for the last argument if the\n\t\t\t// injector is variadic.\n\t\t\tig.p(\"%s ...%s\", ig.paramNames[i], types.TypeString(pi.Type().(*types.Slice).Elem(), ig.g.qualifyPkg))\n\t\t} else {\n\t\t\tig.p(\"%s %s\", ig.paramNames[i], types.TypeString(pi.Type(), ig.g.qualifyPkg))\n\t\t}\n\t}\n\toutTypeString := types.TypeString(injectSig.out, ig.g.qualifyPkg)\n\tswitch {\n\tcase injectSig.cleanup && injectSig.err:\n\t\tig.p(\") (%s, func(), error) {\\n\", outTypeString)\n\tcase injectSig.cleanup:\n\t\tig.p(\") (%s, func()) {\\n\", outTypeString)\n\tcase injectSig.err:\n\t\tig.p(\") (%s, error) {\\n\", outTypeString)\n\tdefault:\n\t\tig.p(\") %s {\\n\", outTypeString)\n\t}\n\tfor i := range calls {\n\t\tc := &calls[i]\n\t\tlname := typeVariableName(c.out, \"v\", unexport, ig.nameInInjector)\n\t\tig.localNames = append(ig.localNames, lname)\n\t\tswitch c.kind {\n\t\tcase structProvider:\n\t\t\tig.structProviderCall(lname, c)\n\t\tcase funcProviderCall:\n\t\t\tig.funcProviderCall(lname, c, injectSig)\n\t\tcase valueExpr:\n\t\t\tig.valueExpr(lname, c)\n\t\tcase selectorExpr:\n\t\t\tig.fieldExpr(lname, c)\n\t\tdefault:\n\t\t\tpanic(\"unknown kind\")\n\t\t}\n\t}\n\tif len(calls) == 0 {\n\t\tig.p(\"\\treturn %s\", ig.paramNames[set.For(injectSig.out).Arg().Index])\n\t} else {\n\t\tig.p(\"\\treturn %s\", ig.localNames[len(calls)-1])\n\t}\n\tif injectSig.cleanup {\n\t\tig.p(\", func() {\\n\")\n\t\tfor i := len(ig.cleanupNames) - 1; i >= 0; i-- {\n\t\t\tig.p(\"\\t\\t%s()\\n\", ig.cleanupNames[i])\n\t\t}\n\t\tig.p(\"\\t}\")\n\t}\n\tif injectSig.err {\n\t\tig.p(\", nil\")\n\t}\n\tig.p(\"\\n}\\n\\n\")\n}\n\nfunc (ig *injectorGen) funcProviderCall(lname string, c *call, injectSig outputSignature) {\n\tig.p(\"\\t%s\", lname)\n\tprevCleanup := len(ig.cleanupNames)\n\tif c.hasCleanup {\n\t\tcname := disambiguate(\"cleanup\", ig.nameInInjector)\n\t\tig.cleanupNames = append(ig.cleanupNames, cname)\n\t\tig.p(\", %s\", cname)\n\t}\n\tif c.hasErr {\n\t\tig.p(\", %s\", ig.errVar)\n\t}\n\tig.p(\" := \")\n\tig.p(\"%s(\", ig.g.qualifiedID(c.pkg.Name(), c.pkg.Path(), c.name))\n\tfor i, a := range c.args {\n\t\tif i > 0 {\n\t\t\tig.p(\", \")\n\t\t}\n\t\tif a < len(ig.paramNames) {\n\t\t\tig.p(\"%s\", ig.paramNames[a])\n\t\t} else {\n\t\t\tig.p(\"%s\", ig.localNames[a-len(ig.paramNames)])\n\t\t}\n\t}\n\tif c.varargs {\n\t\tig.p(\"...\")\n\t}\n\tig.p(\")\\n\")\n\tif c.hasErr {\n\t\tig.p(\"\\tif %s != nil {\\n\", ig.errVar)\n\t\tfor i := prevCleanup - 1; i >= 0; i-- {\n\t\t\tig.p(\"\\t\\t%s()\\n\", ig.cleanupNames[i])\n\t\t}\n\t\tig.p(\"\\t\\treturn %s\", zeroValue(injectSig.out, ig.g.qualifyPkg))\n\t\tif injectSig.cleanup {\n\t\t\tig.p(\", nil\")\n\t\t}\n\t\t// TODO(light): Give information about failing provider.\n\t\tig.p(\", err\\n\")\n\t\tig.p(\"\\t}\\n\")\n\t}\n}\n\nfunc (ig *injectorGen) structProviderCall(lname string, c *call) {\n\tig.p(\"\\t%s\", lname)\n\tig.p(\" := \")\n\tif _, ok := c.out.(*types.Pointer); ok {\n\t\tig.p(\"&\")\n\t}\n\tig.p(\"%s{\\n\", ig.g.qualifiedID(c.pkg.Name(), c.pkg.Path(), c.name))\n\tfor i, a := range c.args {\n\t\tig.p(\"\\t\\t%s: \", c.fieldNames[i])\n\t\tif a < len(ig.paramNames) {\n\t\t\tig.p(\"%s\", ig.paramNames[a])\n\t\t} else {\n\t\t\tig.p(\"%s\", ig.localNames[a-len(ig.paramNames)])\n\t\t}\n\t\tig.p(\",\\n\")\n\t}\n\tig.p(\"\\t}\\n\")\n}\n\nfunc (ig *injectorGen) valueExpr(lname string, c *call) {\n\tig.p(\"\\t%s := %s\\n\", lname, ig.g.values[c.valueExpr])\n}\n\nfunc (ig *injectorGen) fieldExpr(lname string, c *call) {\n\ta := c.args[0]\n\tig.p(\"\\t%s := \", lname)\n\tif c.ptrToField {\n\t\tig.p(\"&\")\n\t}\n\tif a < len(ig.paramNames) {\n\t\tig.p(\"%s.%s\\n\", ig.paramNames[a], c.name)\n\t} else {\n\t\tig.p(\"%s.%s\\n\", ig.localNames[a-len(ig.paramNames)], c.name)\n\t}\n}\n\n// nameInInjector reports whether name collides with any other identifier\n// in the current injector.\nfunc (ig *injectorGen) nameInInjector(name string) bool {\n\tif name == ig.errVar {\n\t\treturn true\n\t}\n\tfor _, a := range ig.paramNames {\n\t\tif a == name {\n\t\t\treturn true\n\t\t}\n\t}\n\tfor _, l := range ig.localNames {\n\t\tif l == name {\n\t\t\treturn true\n\t\t}\n\t}\n\tfor _, l := range ig.cleanupNames {\n\t\tif l == name {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn ig.g.nameInFileScope(name)\n}\n\nfunc (ig *injectorGen) p(format string, args ...interface{}) {\n\tif ig.discard {\n\t\treturn\n\t}\n\tig.g.p(format, args...)\n}\n\n// zeroValue returns the shortest expression that evaluates to the zero\n// value for the given type.\nfunc zeroValue(t types.Type, qf types.Qualifier) string {\n\tswitch u := t.Underlying().(type) {\n\tcase *types.Array, *types.Struct:\n\t\treturn types.TypeString(t, qf) + \"{}\"\n\tcase *types.Basic:\n\t\tinfo := u.Info()\n\t\tswitch {\n\t\tcase info&types.IsBoolean != 0:\n\t\t\treturn \"false\"\n\t\tcase info&(types.IsInteger|types.IsFloat|types.IsComplex) != 0:\n\t\t\treturn \"0\"\n\t\tcase info&types.IsString != 0:\n\t\t\treturn `\"\"`\n\t\tdefault:\n\t\t\tpanic(\"unreachable\")\n\t\t}\n\tcase *types.Chan, *types.Interface, *types.Map, *types.Pointer, *types.Signature, *types.Slice:\n\t\treturn \"nil\"\n\tdefault:\n\t\tpanic(\"unreachable\")\n\t}\n}\n\n// typeVariableName invents a disambiguated variable name derived from the type name.\n// If no name can be derived from the type, defaultName is used.\n// transform is used to transform the derived name(s) (including defaultName);\n// commonly used functions include export and unexport.\n// collides is used to see if a name is ambiguous. If any one of the derived\n// names is unambiguous, it used; otherwise, the first derived name is\n// disambiguated using disambiguate().\nfunc typeVariableName(t types.Type, defaultName string, transform func(string) string, collides func(string) bool) string {\n\tif p, ok := t.(*types.Pointer); ok {\n\t\tt = p.Elem()\n\t}\n\tvar names []string\n\tswitch t := t.(type) {\n\tcase *types.Basic:\n\t\tif t.Name() != \"\" {\n\t\t\tnames = append(names, t.Name())\n\t\t}\n\tcase *types.Named:\n\t\tobj := t.Obj()\n\t\tif name := obj.Name(); name != \"\" {\n\t\t\tnames = append(names, name)\n\t\t}\n\t\t// Provide an alternate name prefixed with the package name if possible.\n\t\t// E.g., in case of collisions, we'll use \"fooCfg\" instead of \"cfg2\".\n\t\tif pkg := obj.Pkg(); pkg != nil && pkg.Name() != \"\" {\n\t\t\tnames = append(names, fmt.Sprintf(\"%s%s\", pkg.Name(), strings.Title(obj.Name())))\n\t\t}\n\t}\n\n\t// If we were unable to derive a name, use defaultName.\n\tif len(names) == 0 {\n\t\tnames = append(names, defaultName)\n\t}\n\n\t// Transform the name(s).\n\tfor i, name := range names {\n\t\tnames[i] = transform(name)\n\t}\n\n\t// See if there's an unambiguous name; if so, use it.\n\tfor _, name := range names {\n\t\tif !token.Lookup(name).IsKeyword() && !collides(name) {\n\t\t\treturn name\n\t\t}\n\t}\n\t// Otherwise, disambiguate the first name.\n\treturn disambiguate(names[0], collides)\n}\n\n// unexport converts a name that is potentially exported to an unexported name.\nfunc unexport(name string) string {\n\tif name == \"\" {\n\t\treturn \"\"\n\t}\n\tr, sz := utf8.DecodeRuneInString(name)\n\tif !unicode.IsUpper(r) {\n\t\t// foo -> foo\n\t\treturn name\n\t}\n\tr2, sz2 := utf8.DecodeRuneInString(name[sz:])\n\tif !unicode.IsUpper(r2) {\n\t\t// Foo -> foo\n\t\treturn string(unicode.ToLower(r)) + name[sz:]\n\t}\n\t// UPPERWord -> upperWord\n\tsbuf := new(strings.Builder)\n\tsbuf.WriteRune(unicode.ToLower(r))\n\ti := sz\n\tr, sz = r2, sz2\n\tfor unicode.IsUpper(r) && sz > 0 {\n\t\tr2, sz2 := utf8.DecodeRuneInString(name[i+sz:])\n\t\tif sz2 > 0 && unicode.IsLower(r2) {\n\t\t\tbreak\n\t\t}\n\t\ti += sz\n\t\tsbuf.WriteRune(unicode.ToLower(r))\n\t\tr, sz = r2, sz2\n\t}\n\tsbuf.WriteString(name[i:])\n\treturn sbuf.String()\n}\n\n// export converts a name that is potentially unexported to an exported name.\nfunc export(name string) string {\n\tif name == \"\" {\n\t\treturn \"\"\n\t}\n\tr, sz := utf8.DecodeRuneInString(name)\n\tif unicode.IsUpper(r) {\n\t\t// Foo -> Foo\n\t\treturn name\n\t}\n\t// fooBar -> FooBar\n\tsbuf := new(strings.Builder)\n\tsbuf.WriteRune(unicode.ToUpper(r))\n\tsbuf.WriteString(name[sz:])\n\treturn sbuf.String()\n}\n\n// disambiguate picks a unique name, preferring name if it is already unique.\n// It also disambiguates against Go's reserved keywords.\nfunc disambiguate(name string, collides func(string) bool) string {\n\tif !token.Lookup(name).IsKeyword() && !collides(name) {\n\t\treturn name\n\t}\n\tbuf := []byte(name)\n\tif len(buf) > 0 && buf[len(buf)-1] >= '0' && buf[len(buf)-1] <= '9' {\n\t\tbuf = append(buf, '_')\n\t}\n\tbase := len(buf)\n\tfor n := 2; ; n++ {\n\t\tbuf = strconv.AppendInt(buf[:base], int64(n), 10)\n\t\tsbuf := string(buf)\n\t\tif !token.Lookup(sbuf).IsKeyword() && !collides(sbuf) {\n\t\t\treturn sbuf\n\t\t}\n\t}\n}\n\n// accessibleFrom reports whether node can be copied to wantPkg without\n// violating Go visibility rules.\nfunc accessibleFrom(info *types.Info, node ast.Node, wantPkg string) error {\n\tvar unexportError error\n\tast.Inspect(node, func(node ast.Node) bool {\n\t\tif unexportError != nil {\n\t\t\treturn false\n\t\t}\n\t\tident, ok := node.(*ast.Ident)\n\t\tif !ok {\n\t\t\treturn true\n\t\t}\n\t\tobj := info.ObjectOf(ident)\n\t\tif _, ok := obj.(*types.PkgName); ok {\n\t\t\t// Local package names are fine, since we can just reimport them.\n\t\t\treturn true\n\t\t}\n\t\tif pkg := obj.Pkg(); pkg != nil {\n\t\t\tif !ast.IsExported(ident.Name) && pkg.Path() != wantPkg {\n\t\t\t\tunexportError = fmt.Errorf(\"uses unexported identifier %s\", obj.Name())\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif obj.Parent() != nil && obj.Parent() != pkg.Scope() {\n\t\t\t\tunexportError = fmt.Errorf(\"%s is not declared in package scope\", obj.Name())\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t})\n\treturn unexportError\n}\n\nvar (\n\terrorType   = types.Universe.Lookup(\"error\").Type()\n\tcleanupType = types.NewSignature(nil, nil, nil, false)\n)\n"
  },
  {
    "path": "internal/wire/wire_test.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage wire\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"flag\"\n\t\"fmt\"\n\t\"go/build\"\n\t\"go/types\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"os/exec\"\n\t\"path/filepath\"\n\t\"strings\"\n\t\"testing\"\n\t\"unicode\"\n\t\"unicode/utf8\"\n\n\t\"github.com/google/go-cmp/cmp\"\n)\n\nvar record = flag.Bool(\"record\", false, \"whether to run tests against cloud resources and record the interactions\")\n\nfunc TestWire(t *testing.T) {\n\tconst testRoot = \"testdata\"\n\ttestdataEnts, err := ioutil.ReadDir(testRoot) // ReadDir sorts by name.\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\t// The marker function package source is needed to have the test cases\n\t// type check. loadTestCase places this file at the well-known import path.\n\twireGo, err := ioutil.ReadFile(filepath.Join(\"..\", \"..\", \"wire.go\"))\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\ttests := make([]*testCase, 0, len(testdataEnts))\n\tfor _, ent := range testdataEnts {\n\t\tname := ent.Name()\n\t\tif !ent.IsDir() || strings.HasPrefix(name, \".\") || strings.HasPrefix(name, \"_\") {\n\t\t\tcontinue\n\t\t}\n\t\ttest, err := loadTestCase(filepath.Join(testRoot, name), wireGo)\n\t\tif err != nil {\n\t\t\tt.Error(err)\n\t\t\tcontinue\n\t\t}\n\t\ttests = append(tests, test)\n\t}\n\n\tvar goToolPath string\n\tif *record {\n\t\tgoToolPath = filepath.Join(build.Default.GOROOT, \"bin\", \"go\")\n\t\tif _, err := os.Stat(goToolPath); err != nil {\n\t\t\tt.Fatal(\"go toolchain not available:\", err)\n\t\t}\n\t}\n\tctx := context.Background()\n\tfor _, test := range tests {\n\t\ttest := test\n\t\tt.Run(test.name, func(t *testing.T) {\n\t\t\tt.Parallel()\n\n\t\t\t// Materialize a temporary GOPATH directory.\n\t\t\tgopath, err := ioutil.TempDir(\"\", \"wire_test\")\n\t\t\tif err != nil {\n\t\t\t\tt.Fatal(err)\n\t\t\t}\n\t\t\tdefer os.RemoveAll(gopath)\n\t\t\tgopath, err = filepath.EvalSymlinks(gopath)\n\t\t\tif err != nil {\n\t\t\t\tt.Fatal(err)\n\t\t\t}\n\t\t\tif err := test.materialize(gopath); err != nil {\n\t\t\t\tt.Fatal(err)\n\t\t\t}\n\t\t\twd := filepath.Join(gopath, \"src\", \"example.com\")\n\t\t\tgens, errs := Generate(ctx, wd, append(os.Environ(), \"GOPATH=\"+gopath), []string{test.pkg}, &GenerateOptions{Header: test.header})\n\t\t\tvar gen GenerateResult\n\t\t\tif len(gens) > 1 {\n\t\t\t\tt.Fatalf(\"got %d generated files, want 0 or 1\", len(gens))\n\t\t\t}\n\t\t\tif len(gens) == 1 {\n\t\t\t\tgen = gens[0]\n\t\t\t\tif len(gen.Errs) > 0 {\n\t\t\t\t\terrs = append(errs, gen.Errs...)\n\t\t\t\t}\n\t\t\t\tif len(gen.Content) > 0 {\n\t\t\t\t\tdefer t.Logf(\"wire_gen.go:\\n%s\", gen.Content)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif len(errs) > 0 {\n\t\t\t\tgotErrStrings := make([]string, len(errs))\n\t\t\t\tfor i, e := range errs {\n\t\t\t\t\tt.Log(e.Error())\n\t\t\t\t\tgotErrStrings[i] = scrubError(gopath, e.Error())\n\t\t\t\t}\n\t\t\t\tif !test.wantWireError {\n\t\t\t\t\tt.Fatal(\"Did not expect errors. To -record an error, create want/wire_errs.txt.\")\n\t\t\t\t}\n\t\t\t\tif *record {\n\t\t\t\t\twireErrsFile := filepath.Join(testRoot, test.name, \"want\", \"wire_errs.txt\")\n\t\t\t\t\tif err := ioutil.WriteFile(wireErrsFile, []byte(strings.Join(gotErrStrings, \"\\n\\n\")), 0666); err != nil {\n\t\t\t\t\t\tt.Fatalf(\"failed to write wire_errs.txt file: %v\", err)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif diff := cmp.Diff(gotErrStrings, test.wantWireErrorStrings); diff != \"\" {\n\t\t\t\t\t\tt.Errorf(\"Errors didn't match expected errors from wire_errors.txt:\\n%s\", diff)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif test.wantWireError {\n\t\t\t\tt.Fatal(\"wire succeeded; want error\")\n\t\t\t}\n\t\t\toutPathSane := true\n\t\t\tif prefix := gopath + string(os.PathSeparator) + \"src\" + string(os.PathSeparator); !strings.HasPrefix(gen.OutputPath, prefix) {\n\t\t\t\toutPathSane = false\n\t\t\t\tt.Errorf(\"suggested output path = %q; want to start with %q\", gen.OutputPath, prefix)\n\t\t\t}\n\n\t\t\tif *record {\n\t\t\t\t// Record ==> Build the generated Wire code,\n\t\t\t\t// check that the program's output matches the\n\t\t\t\t// expected output, save wire output on\n\t\t\t\t// success.\n\t\t\t\tif !outPathSane {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif err := gen.Commit(); err != nil {\n\t\t\t\t\tt.Fatalf(\"failed to write wire_gen.go to test GOPATH: %v\", err)\n\t\t\t\t}\n\t\t\t\tif err := goBuildCheck(goToolPath, gopath, test); err != nil {\n\t\t\t\t\tt.Fatalf(\"go build check failed: %v\", err)\n\t\t\t\t}\n\t\t\t\ttestdataWireGenPath := filepath.Join(testRoot, test.name, \"want\", \"wire_gen.go\")\n\t\t\t\tif err := ioutil.WriteFile(testdataWireGenPath, gen.Content, 0666); err != nil {\n\t\t\t\t\tt.Fatalf(\"failed to record wire_gen.go to testdata: %v\", err)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Replay ==> Load golden file and compare to\n\t\t\t\t// generated result. This check is meant to\n\t\t\t\t// detect non-deterministic behavior in the\n\t\t\t\t// Generate function.\n\t\t\t\tif !bytes.Equal(gen.Content, test.wantWireOutput) {\n\t\t\t\t\tgotS, wantS := string(gen.Content), string(test.wantWireOutput)\n\t\t\t\t\tdiff := cmp.Diff(strings.Split(gotS, \"\\n\"), strings.Split(wantS, \"\\n\"))\n\t\t\t\t\tt.Fatalf(\"wire output differs from golden file. If this change is expected, run with -record to update the wire_gen.go file.\\n*** got:\\n%s\\n\\n*** want:\\n%s\\n\\n*** diff:\\n%s\", gotS, wantS, diff)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc goBuildCheck(goToolPath, gopath string, test *testCase) error {\n\t// Run `go build`.\n\ttestExePath := filepath.Join(gopath, \"bin\", \"testprog\")\n\tbuildCmd := []string{\"build\", \"-o\", testExePath}\n\tbuildCmd = append(buildCmd, test.pkg)\n\tcmd := exec.Command(goToolPath, buildCmd...)\n\tcmd.Dir = filepath.Join(gopath, \"src\", \"example.com\")\n\tcmd.Env = append(os.Environ(), \"GOPATH=\"+gopath)\n\tif buildOut, err := cmd.CombinedOutput(); err != nil {\n\t\tif len(buildOut) > 0 {\n\t\t\treturn fmt.Errorf(\"build: %v; output:\\n%s\", err, buildOut)\n\t\t}\n\t\treturn fmt.Errorf(\"build: %v\", err)\n\t}\n\n\t// Run the resulting program and compare its output to the expected\n\t// output.\n\tout, err := exec.Command(testExePath).Output()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"run compiled program: %v\", err)\n\t}\n\tif !bytes.Equal(out, test.wantProgramOutput) {\n\t\tgotS, wantS := string(out), string(test.wantProgramOutput)\n\t\tdiff := cmp.Diff(strings.Split(gotS, \"\\n\"), strings.Split(wantS, \"\\n\"))\n\t\treturn fmt.Errorf(\"compiled program output doesn't match:\\n*** got:\\n%s\\n\\n*** want:\\n%s\\n\\n*** diff:\\n%s\", gotS, wantS, diff)\n\t}\n\treturn nil\n}\n\nfunc TestUnexport(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\twant string\n\t}{\n\t\t{\"\", \"\"},\n\t\t{\"a\", \"a\"},\n\t\t{\"ab\", \"ab\"},\n\t\t{\"A\", \"a\"},\n\t\t{\"AB\", \"ab\"},\n\t\t{\"A_\", \"a_\"},\n\t\t{\"ABc\", \"aBc\"},\n\t\t{\"ABC\", \"abc\"},\n\t\t{\"AB_\", \"ab_\"},\n\t\t{\"foo\", \"foo\"},\n\t\t{\"Foo\", \"foo\"},\n\t\t{\"HTTPClient\", \"httpClient\"},\n\t\t{\"IFace\", \"iFace\"},\n\t\t{\"SNAKE_CASE\", \"snake_CASE\"},\n\t\t{\"HTTP\", \"http\"},\n\t}\n\tfor _, test := range tests {\n\t\tif got := unexport(test.name); got != test.want {\n\t\t\tt.Errorf(\"unexport(%q) = %q; want %q\", test.name, got, test.want)\n\t\t}\n\t}\n}\n\nfunc TestExport(t *testing.T) {\n\ttests := []struct {\n\t\tname string\n\t\twant string\n\t}{\n\t\t{\"\", \"\"},\n\t\t{\"a\", \"A\"},\n\t\t{\"ab\", \"Ab\"},\n\t\t{\"A\", \"A\"},\n\t\t{\"AB\", \"AB\"},\n\t\t{\"A_\", \"A_\"},\n\t\t{\"ABc\", \"ABc\"},\n\t\t{\"ABC\", \"ABC\"},\n\t\t{\"AB_\", \"AB_\"},\n\t\t{\"foo\", \"Foo\"},\n\t\t{\"Foo\", \"Foo\"},\n\t\t{\"HTTPClient\", \"HTTPClient\"},\n\t\t{\"httpClient\", \"HttpClient\"},\n\t\t{\"IFace\", \"IFace\"},\n\t\t{\"iFace\", \"IFace\"},\n\t\t{\"SNAKE_CASE\", \"SNAKE_CASE\"},\n\t\t{\"HTTP\", \"HTTP\"},\n\t}\n\tfor _, test := range tests {\n\t\tif got := export(test.name); got != test.want {\n\t\t\tt.Errorf(\"export(%q) = %q; want %q\", test.name, got, test.want)\n\t\t}\n\t}\n}\n\nfunc TestTypeVariableName(t *testing.T) {\n\tvar (\n\t\tboolT           = types.Typ[types.Bool]\n\t\tstringT         = types.Typ[types.String]\n\t\tfooVarT         = types.NewNamed(types.NewTypeName(0, nil, \"foo\", stringT), stringT, nil)\n\t\tnonameVarT      = types.NewNamed(types.NewTypeName(0, nil, \"\", stringT), stringT, nil)\n\t\tbarVarInFooPkgT = types.NewNamed(types.NewTypeName(0, types.NewPackage(\"my.example/foo\", \"foo\"), \"bar\", stringT), stringT, nil)\n\t)\n\ttests := []struct {\n\t\tdescription     string\n\t\ttyp             types.Type\n\t\tdefaultName     string\n\t\ttransformAppend string\n\t\tcollides        map[string]bool\n\t\twant            string\n\t}{\n\t\t{\"basic type\", boolT, \"\", \"\", map[string]bool{}, \"bool\"},\n\t\t{\"basic type with transform\", boolT, \"\", \"suffix\", map[string]bool{}, \"boolsuffix\"},\n\t\t{\"basic type with collision\", boolT, \"\", \"\", map[string]bool{\"bool\": true}, \"bool2\"},\n\t\t{\"basic type with transform and collision\", boolT, \"\", \"suffix\", map[string]bool{\"boolsuffix\": true}, \"boolsuffix2\"},\n\t\t{\"a different basic type\", stringT, \"\", \"\", map[string]bool{}, \"string\"},\n\t\t{\"named type\", fooVarT, \"\", \"\", map[string]bool{}, \"foo\"},\n\t\t{\"named type with transform\", fooVarT, \"\", \"suffix\", map[string]bool{}, \"foosuffix\"},\n\t\t{\"named type with collision\", fooVarT, \"\", \"\", map[string]bool{\"foo\": true}, \"foo2\"},\n\t\t{\"named type with transform and collision\", fooVarT, \"\", \"suffix\", map[string]bool{\"foosuffix\": true}, \"foosuffix2\"},\n\t\t{\"noname type\", nonameVarT, \"bar\", \"\", map[string]bool{}, \"bar\"},\n\t\t{\"noname type with transform\", nonameVarT, \"bar\", \"s\", map[string]bool{}, \"bars\"},\n\t\t{\"noname type with transform and collision\", nonameVarT, \"bar\", \"s\", map[string]bool{\"bars\": true}, \"bars2\"},\n\t\t{\"var in pkg type\", barVarInFooPkgT, \"\", \"\", map[string]bool{}, \"bar\"},\n\t\t{\"var in pkg type with collision\", barVarInFooPkgT, \"\", \"\", map[string]bool{\"bar\": true}, \"fooBar\"},\n\t\t{\"var in pkg type with double collision\", barVarInFooPkgT, \"\", \"\", map[string]bool{\"bar\": true, \"fooBar\": true}, \"bar2\"},\n\t}\n\tfor _, test := range tests {\n\t\tt.Run(fmt.Sprintf(\"%s: typeVariableName(%v, %q, %q, %v)\", test.description, test.typ, test.defaultName, test.transformAppend, test.collides), func(t *testing.T) {\n\t\t\tgot := typeVariableName(test.typ, test.defaultName, func(name string) string { return name + test.transformAppend }, func(name string) bool { return test.collides[name] })\n\t\t\tif !isIdent(got) {\n\t\t\t\tt.Errorf(\"%q is not an identifier\", got)\n\t\t\t}\n\t\t\tif got != test.want {\n\t\t\t\tt.Errorf(\"got %q want %q\", got, test.want)\n\t\t\t}\n\t\t\tif test.collides[got] {\n\t\t\t\tt.Errorf(\"%q collides\", got)\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc TestDisambiguate(t *testing.T) {\n\ttests := []struct {\n\t\tname     string\n\t\twant     string\n\t\tcollides map[string]bool\n\t}{\n\t\t{\"foo\", \"foo\", nil},\n\t\t{\"foo\", \"foo2\", map[string]bool{\"foo\": true}},\n\t\t{\"foo\", \"foo3\", map[string]bool{\"foo\": true, \"foo1\": true, \"foo2\": true}},\n\t\t{\"foo1\", \"foo1_2\", map[string]bool{\"foo\": true, \"foo1\": true, \"foo2\": true}},\n\t\t{\"foo\\u0661\", \"foo\\u0661\", map[string]bool{\"foo\": true, \"foo1\": true, \"foo2\": true}},\n\t\t{\"foo\\u0661\", \"foo\\u06612\", map[string]bool{\"foo\": true, \"foo1\": true, \"foo2\": true, \"foo\\u0661\": true}},\n\t\t{\"select\", \"select2\", nil},\n\t\t{\"var\", \"var2\", nil},\n\t}\n\tfor _, test := range tests {\n\t\tt.Run(fmt.Sprintf(\"disambiguate(%q, %v)\", test.name, test.collides), func(t *testing.T) {\n\t\t\tgot := disambiguate(test.name, func(name string) bool { return test.collides[name] })\n\t\t\tif !isIdent(got) {\n\t\t\t\tt.Errorf(\"%q is not an identifier\", got)\n\t\t\t}\n\t\t\tif got != test.want {\n\t\t\t\tt.Errorf(\"got %q want %q\", got, test.want)\n\t\t\t}\n\t\t\tif test.collides[got] {\n\t\t\t\tt.Errorf(\"%q collides\", got)\n\t\t\t}\n\t\t})\n\t}\n}\n\nfunc isIdent(s string) bool {\n\tif len(s) == 0 {\n\t\treturn false\n\t}\n\tr, i := utf8.DecodeRuneInString(s)\n\tif !unicode.IsLetter(r) && r != '_' {\n\t\treturn false\n\t}\n\tfor i < len(s) {\n\t\tr, sz := utf8.DecodeRuneInString(s[i:])\n\t\tif !unicode.IsLetter(r) && !unicode.IsDigit(r) && r != '_' {\n\t\t\treturn false\n\t\t}\n\t\ti += sz\n\t}\n\treturn true\n}\n\n// scrubError rewrites the given string to remove occurrences of GOPATH/src,\n// rewrites OS-specific path separators to slashes, and any line/column\n// information to a fixed \":x:y\". For example, if the gopath parameter is\n// \"C:\\GOPATH\" and running on Windows, the string\n// \"C:\\GOPATH\\src\\foo\\bar.go:15:4\" would be rewritten to \"foo/bar.go:x:y\".\nfunc scrubError(gopath string, s string) string {\n\tsb := new(strings.Builder)\n\tquery := gopath + string(os.PathSeparator) + \"src\" + string(os.PathSeparator)\n\tfor {\n\t\t// Find next occurrence of source root. This indicates the next path to\n\t\t// scrub.\n\t\tstart := strings.Index(s, query)\n\t\tif start == -1 {\n\t\t\tsb.WriteString(s)\n\t\t\tbreak\n\t\t}\n\n\t\t// Find end of file name (extension \".go\").\n\t\tfileStart := start + len(query)\n\t\tfileEnd := strings.Index(s[fileStart:], \".go\")\n\t\tif fileEnd == -1 {\n\t\t\t// If no \".go\" occurs to end of string, further searches will fail too.\n\t\t\t// Break the loop.\n\t\t\tsb.WriteString(s)\n\t\t\tbreak\n\t\t}\n\t\tfileEnd += fileStart + 3 // Advance to end of extension.\n\n\t\t// Write out file name and advance scrub position.\n\t\tfile := s[fileStart:fileEnd]\n\t\tif os.PathSeparator != '/' {\n\t\t\tfile = strings.Replace(file, string(os.PathSeparator), \"/\", -1)\n\t\t}\n\t\tsb.WriteString(s[:start])\n\t\tsb.WriteString(file)\n\t\ts = s[fileEnd:]\n\n\t\t// Peek past to see if there is line/column info.\n\t\tlinecol, linecolLen := scrubLineColumn(s)\n\t\tsb.WriteString(linecol)\n\t\ts = s[linecolLen:]\n\t}\n\treturn sb.String()\n}\n\nfunc scrubLineColumn(s string) (replacement string, n int) {\n\tif !strings.HasPrefix(s, \":\") {\n\t\treturn \"\", 0\n\t}\n\t// Skip first colon and run of digits.\n\tfor n++; len(s) > n && '0' <= s[n] && s[n] <= '9'; {\n\t\tn++\n\t}\n\tif n == 1 {\n\t\t// No digits followed colon.\n\t\treturn \"\", 0\n\t}\n\n\t// Start on column part.\n\tif !strings.HasPrefix(s[n:], \":\") {\n\t\treturn \":x\", n\n\t}\n\tlineEnd := n\n\t// Skip second colon and run of digits.\n\tfor n++; len(s) > n && '0' <= s[n] && s[n] <= '9'; {\n\t\tn++\n\t}\n\tif n == lineEnd+1 {\n\t\t// No digits followed second colon.\n\t\treturn \":x\", lineEnd\n\t}\n\treturn \":x:y\", n\n}\n\ntype testCase struct {\n\tname                 string\n\tpkg                  string\n\theader               []byte\n\tgoFiles              map[string][]byte\n\twantProgramOutput    []byte\n\twantWireOutput       []byte\n\twantWireError        bool\n\twantWireErrorStrings []string\n}\n\n// loadTestCase reads a test case from a directory.\n//\n// The directory structure is:\n//\n//\troot/\n//\n//\t\tpkg\n//\t\t\tfile containing the package name containing the inject function\n//\t\t\t(must also be package main)\n//\n//\t\t...\n//\t\t\tany Go files found recursively placed under GOPATH/src/...\n//\n//\t\twant/\n//\n//\t\t\twire_errs.txt\n//\t\t\t\t\tExpected errors from the Wire Generate function,\n//\t\t\t\t\tmissing if no errors expected.\n//\t\t\t\t\tDistinct errors are separated by a blank line,\n//\t\t\t\t\tand line numbers and line positions are scrubbed\n//\t\t\t\t\t(e.g. \"$GOPATH/src/foo.go:52:8\" --> \"foo.go:x:y\").\n//\n//\t\t\twire_gen.go\n//\t\t\t\t\tverified output of wire from a test run with\n//\t\t\t\t\t-record, missing if wire_errs.txt is present\n//\n//\t\t\tprogram_out.txt\n//\t\t\t\t\texpected output from the final compiled program,\n//\t\t\t\t\tmissing if wire_errs.txt is present\nfunc loadTestCase(root string, wireGoSrc []byte) (*testCase, error) {\n\tname := filepath.Base(root)\n\tpkg, err := ioutil.ReadFile(filepath.Join(root, \"pkg\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"load test case %s: %v\", name, err)\n\t}\n\theader, _ := ioutil.ReadFile(filepath.Join(root, \"header\"))\n\tvar wantProgramOutput []byte\n\tvar wantWireOutput []byte\n\twireErrb, err := ioutil.ReadFile(filepath.Join(root, \"want\", \"wire_errs.txt\"))\n\twantWireError := err == nil\n\tvar wantWireErrorStrings []string\n\tif wantWireError {\n\t\tfor _, errs := range strings.Split(string(wireErrb), \"\\n\\n\") {\n\t\t\t// Allow for trailing newlines, which can be hard to remove in some editors.\n\t\t\twantWireErrorStrings = append(wantWireErrorStrings, strings.TrimRight(errs, \"\\n\\r\"))\n\t\t}\n\t} else {\n\t\tif !*record {\n\t\t\twantWireOutput, err = ioutil.ReadFile(filepath.Join(root, \"want\", \"wire_gen.go\"))\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"load test case %s: %v, if this is a new testcase, run with -record to generate the wire_gen.go file\", name, err)\n\t\t\t}\n\t\t}\n\t\twantProgramOutput, err = ioutil.ReadFile(filepath.Join(root, \"want\", \"program_out.txt\"))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"load test case %s: %v\", name, err)\n\t\t}\n\t}\n\tgoFiles := map[string][]byte{\n\t\t\"github.com/google/wire/wire.go\": wireGoSrc,\n\t}\n\terr = filepath.Walk(root, func(src string, info os.FileInfo, err error) error {\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\trel, err := filepath.Rel(root, src)\n\t\tif err != nil {\n\t\t\treturn err // unlikely\n\t\t}\n\t\tif info.Mode().IsDir() && rel == \"want\" {\n\t\t\t// The \"want\" directory should not be included in goFiles.\n\t\t\treturn filepath.SkipDir\n\t\t}\n\t\tif !info.Mode().IsRegular() || filepath.Ext(src) != \".go\" {\n\t\t\treturn nil\n\t\t}\n\t\tdata, err := ioutil.ReadFile(src)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tgoFiles[\"example.com/\"+filepath.ToSlash(rel)] = data\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"load test case %s: %v\", name, err)\n\t}\n\treturn &testCase{\n\t\tname:                 name,\n\t\tpkg:                  string(bytes.TrimSpace(pkg)),\n\t\theader:               header,\n\t\tgoFiles:              goFiles,\n\t\twantWireOutput:       wantWireOutput,\n\t\twantProgramOutput:    wantProgramOutput,\n\t\twantWireError:        wantWireError,\n\t\twantWireErrorStrings: wantWireErrorStrings,\n\t}, nil\n}\n\n// materialize creates a new GOPATH at the given directory, which may or\n// may not exist.\nfunc (test *testCase) materialize(gopath string) error {\n\tfor name, content := range test.goFiles {\n\t\tdst := filepath.Join(gopath, \"src\", filepath.FromSlash(name))\n\t\tif err := os.MkdirAll(filepath.Dir(dst), 0777); err != nil {\n\t\t\treturn fmt.Errorf(\"materialize GOPATH: %v\", err)\n\t\t}\n\t\tif err := ioutil.WriteFile(dst, content, 0666); err != nil {\n\t\t\treturn fmt.Errorf(\"materialize GOPATH: %v\", err)\n\t\t}\n\t}\n\n\t// Add go.mod files to example.com and github.com/google/wire.\n\tconst importPath = \"example.com\"\n\tconst depPath = \"github.com/google/wire\"\n\tdepLoc := filepath.Join(gopath, \"src\", filepath.FromSlash(depPath))\n\texample := fmt.Sprintf(\"module %s\\n\\nrequire %s v0.1.0\\nreplace %s => %s\\n\", importPath, depPath, depPath, depLoc)\n\tgomod := filepath.Join(gopath, \"src\", filepath.FromSlash(importPath), \"go.mod\")\n\tif err := ioutil.WriteFile(gomod, []byte(example), 0666); err != nil {\n\t\treturn fmt.Errorf(\"generate go.mod for %s: %v\", gomod, err)\n\t}\n\tif err := ioutil.WriteFile(filepath.Join(depLoc, \"go.mod\"), []byte(\"module \"+depPath+\"\\n\"), 0666); err != nil {\n\t\treturn fmt.Errorf(\"generate go.mod for %s: %v\", depPath, err)\n\t}\n\treturn nil\n}\n"
  },
  {
    "path": "wire.go",
    "content": "// Copyright 2018 The Wire Authors\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//     https://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Package wire contains directives for Wire code generation.\n// For an overview of working with Wire, see the user guide at\n// https://github.com/google/wire/blob/master/docs/guide.md\n//\n// The directives in this package are used as input to the Wire code generation\n// tool. The entry point of Wire's analysis are injector functions: function\n// templates denoted by only containing a call to Build. The arguments to Build\n// describes a set of providers and the Wire code generation tool builds a\n// directed acylic graph of the providers' output types. The generated code will\n// fill in the function template by using the providers from the provider set to\n// instantiate any needed types.\npackage wire\n\n// ProviderSet is a marker type that collects a group of providers.\ntype ProviderSet struct{}\n\n// NewSet creates a new provider set that includes the providers in its\n// arguments. Each argument is a function value, a provider set, a call to\n// Struct, a call to Bind, a call to Value, a call to InterfaceValue or a call\n// to FieldsOf.\n//\n// Passing a function value to NewSet declares that the function's first\n// return value type will be provided by calling the function. The arguments\n// to the function will come from the providers for their types. As such, all\n// the function's parameters must be of non-identical types. The function may\n// optionally return an error as its last return value and a cleanup function\n// as the second return value. A cleanup function must be of type func() and is\n// guaranteed to be called before the cleanup function of any of the\n// provider's inputs. If any provider returns an error, the injector function\n// will call all the appropriate cleanup functions and return the error from\n// the injector function.\n//\n// Passing a ProviderSet to NewSet is the same as if the set's contents\n// were passed as arguments to NewSet directly.\n//\n// The behavior of passing the result of a call to other functions in this\n// package are described in their respective doc comments.\n//\n// For compatibility with older versions of Wire, passing a struct value of type\n// S to NewSet declares that both S and *S will be provided by creating a new\n// value of the appropriate type by filling in each field of S using the\n// provider of the field's type. This form is deprecated and will be removed in\n// a future version of Wire: new providers sets should use wire.Struct.\nfunc NewSet(...interface{}) ProviderSet {\n\treturn ProviderSet{}\n}\n\n// Build is placed in the body of an injector function template to declare the\n// providers to use. The Wire code generation tool will fill in an\n// implementation of the function. The arguments to Build are interpreted the\n// same as NewSet: they determine the provider set presented to Wire's\n// dependency graph. Build returns an error message that can be sent to a call\n// to panic().\n//\n// The parameters of the injector function are used as inputs in the dependency\n// graph.\n//\n// Similar to provider functions passed into NewSet, the first return value is\n// the output of the injector function, the optional second return value is a\n// cleanup function, and the optional last return value is an error. If any of\n// the provider functions in the injector function's provider set return errors\n// or cleanup functions, the corresponding return value must be present in the\n// injector function template.\n//\n// Examples:\n//\n//\tfunc injector(ctx context.Context) (*sql.DB, error) {\n//\t\twire.Build(otherpkg.FooSet, myProviderFunc)\n//\t\treturn nil, nil\n//\t}\n//\n//\tfunc injector(ctx context.Context) (*sql.DB, error) {\n//\t\tpanic(wire.Build(otherpkg.FooSet, myProviderFunc))\n//\t}\nfunc Build(...interface{}) string {\n\treturn \"implementation not generated, run wire\"\n}\n\n// A Binding maps an interface to a concrete type.\ntype Binding struct{}\n\n// Bind declares that a concrete type should be used to satisfy a dependency on\n// the type of iface. iface must be a pointer to an interface type, to must be a\n// pointer to a concrete type.\n//\n// Example:\n//\n//\ttype Fooer interface {\n//\t\tFoo()\n//\t}\n//\n//\ttype MyFoo struct{}\n//\n//\tfunc (MyFoo) Foo() {}\n//\n//\tvar MySet = wire.NewSet(\n//\t\twire.Struct(new(MyFoo))\n//\t\twire.Bind(new(Fooer), new(MyFoo)))\nfunc Bind(iface, to interface{}) Binding {\n\treturn Binding{}\n}\n\n// bindToUsePointer is detected by the wire tool to indicate that Bind's second argument should take a pointer.\n// See https://github.com/google/wire/issues/120 for details.\nconst bindToUsePointer = true\n\n// A ProvidedValue is an expression that is copied to the generated injector.\ntype ProvidedValue struct{}\n\n// Value binds an expression to provide the type of the expression.\n// The expression may not be an interface value; use InterfaceValue for that.\n//\n// Example:\n//\n//\tvar MySet = wire.NewSet(wire.Value([]string(nil)))\nfunc Value(interface{}) ProvidedValue {\n\treturn ProvidedValue{}\n}\n\n// InterfaceValue binds an expression to provide a specific interface type.\n// The first argument is a pointer to the interface which user wants to provide.\n// The second argument is the actual variable value whose type implements the\n// interface.\n//\n// Example:\n//\n//\tvar MySet = wire.NewSet(wire.InterfaceValue(new(io.Reader), os.Stdin))\nfunc InterfaceValue(typ interface{}, x interface{}) ProvidedValue {\n\treturn ProvidedValue{}\n}\n\n// A StructProvider represents a named struct.\ntype StructProvider struct{}\n\n// Struct specifies that the given struct type will be provided by filling in\n// the fields in the struct that have the names given.\n//\n// The first argument must be a pointer to the struct type. For a struct type\n// Foo, Wire will use field-filling to provide both Foo and *Foo. The remaining\n// arguments are field names to fill in. As a special case, if a single name \"*\"\n// is given, then all of the fields in the struct will be filled in.\n//\n// For example:\n//\n//\ttype S struct {\n//\t  MyFoo *Foo\n//\t  MyBar *Bar\n//\t}\n//\tvar Set = wire.NewSet(wire.Struct(new(S), \"MyFoo\")) -> inject only S.MyFoo\n//\tvar Set = wire.NewSet(wire.Struct(new(S), \"*\")) -> inject all fields\nfunc Struct(structType interface{}, fieldNames ...string) StructProvider {\n\treturn StructProvider{}\n}\n\n// StructFields is a collection of the fields from a struct.\ntype StructFields struct{}\n\n// FieldsOf declares that the fields named of the given struct type will be used\n// to provide the types of those fields. The structType argument must be a\n// pointer to the struct or a pointer to a pointer to the struct it wishes to reference.\n//\n// The following example would provide Foo and Bar using S.MyFoo and S.MyBar respectively:\n//\n//\ttype S struct {\n//\t\tMyFoo Foo\n//\t\tMyBar Bar\n//\t}\n//\n//\tfunc NewStruct() S { /* ... */ }\n//\tvar Set = wire.NewSet(wire.FieldsOf(new(S), \"MyFoo\", \"MyBar\"))\n//\n//\tor\n//\n//\tfunc NewStruct() *S { /* ... */ }\n//\tvar Set = wire.NewSet(wire.FieldsOf(new(*S), \"MyFoo\", \"MyBar\"))\n//\n//\tIf the structType argument is a pointer to a pointer to a struct, then FieldsOf\n//\tadditionally provides a pointer to each field type (e.g., *Foo and *Bar in the\n//\texample above).\nfunc FieldsOf(structType interface{}, fieldNames ...string) StructFields {\n\treturn StructFields{}\n}\n"
  }
]