Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing properties, functions and typealiases by their fully qualified name #112

Closed
IVIanuu opened this issue Oct 6, 2020 · 7 comments
Labels
api API changes may be involved enhancement New feature or request P1 major features or blocking bugs
Milestone

Comments

@IVIanuu
Copy link

IVIanuu commented Oct 6, 2020

It should be possible get properties, functions and typealiases by their fully qualified name.

Api could look similar like Resolver.getClassDeclarationByName

@ting-yuan
Copy link
Collaborator

Yes it is possible. Can you give an example why this is necessary or convenient?

@IVIanuu
Copy link
Author

IVIanuu commented Oct 13, 2020

For example I tried to rewrite my DI plugin to use KSP. I generate top-level functions and typealiases but I can never reference them again (in other compilation units) because I can only get classes by their name.

Btw there should be also a way to get all declarations in a package. E.g. getDeclarationsInPackage(fqName: String).

@evant
Copy link
Contributor

evant commented Oct 29, 2020

You can do resolver.getAllFiles() and search them yourself, but I agree it would be convenient to get a top-level function etc directly if you already know the name.

@IVIanuu
Copy link
Author

IVIanuu commented Oct 30, 2020

I don't need to get the declarations in the current compilation unit but from others. So I cannot search for them in the files of the current compilation

@IVIanuu
Copy link
Author

IVIanuu commented Oct 30, 2020

See for example Dagger Hilt or Anvil from Square. Both of them wouldn't be possible to be implemented with KSP because they aggregate information across compilations. They store the information as classes and properties in a single package. Eventually they read the information of all modules and do the code generation.

@ting-yuan
Copy link
Collaborator

Thanks, this is an interesting use case that we didn't thought of. Will add the API.

BTW, it should be possible by accessing FileKt where top level functions and properties are stored. That is platform and implementation specific, though.

@ting-yuan ting-yuan added enhancement New feature or request P1 major features or blocking bugs labels Dec 9, 2020
@ting-yuan ting-yuan added this to the 2021Q1 milestone Mar 10, 2021
@ting-yuan ting-yuan added the api API changes may be involved label Mar 10, 2021
@neetopia
Copy link
Contributor

#387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api API changes may be involved enhancement New feature or request P1 major features or blocking bugs
Projects
None yet
Development

No branches or pull requests

4 participants