-
Notifications
You must be signed in to change notification settings - Fork 105
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
wildcard resolved first instead of current package #223
Comments
seems like this will be hard to solve , as far as i see roaster parses a single file this means we lose context of other files within the same package - this is also why the resolving of wildcard imports is incorrect since it tries to find the class by using ContextualClassLoader.loadClass. but this will only work for classes which are also in the runtime environment.... |
here is the solution i have implemented on my fork of jboss:
and
now JavaType implements ContextCapable.
wildcard imports check is later.
should i create a pull request? |
…looking into wildcard import , uses a new mechanism - ParsingContext
@asafbennatan If I understand it correctly, this won't solve the problem because in your We had a similar use case for resolving types out of wildcard imports, which is why we introduced |
@gastaldi my idea is that once you create the parsing context you should only parse using the parsingContext.parse - which parses the source and adds it to its internal map. |
I think the ParsingContext context =
ParsingContextBuilder.create()
.addImportResolver(new ProjectImportResolver(Path.of("/foo"))
.build();
// Introduce a new parse method:
Roaster.parse(ParsingContext context, final Class<T> type, final InputStream data); |
I think you'll need to resolve the current project directory sources and check if the type exists in the path. |
hmm , will that work ? since i will need to parse the source code to actually know it contains the class I'm looking for (i think we cant just rely on the file name -right ? ) this means every time we run the resolver it will parse it - unless we cache the result . |
how about :
and Roaster.parse will be incharge of adding the parsed source into the parsingContext |
Right, now we'll need to define what's in the |
I like the idea of having a |
@gastaldi in addition there might be other locations where you would like to use context from other parsing instances ? ( though im not sure if there are actual or not ). |
also keep in mind that even we if are solving it with import resolvers - the implementation for the import resolver will have to keep track of the previously parsed classes anyway |
@gastaldi noted another issue with type resolution - java.lang classes are being resolved out of order - if there's specific import of my.package.Object or if in the same package it should have priority over java.lang.Object |
…looking into wildcard import , uses a new mechanism - ParsingContext , resolving java.lang according to actual order
when looking for super type of a type we try to resolve the canonical name of that type.
the issue is that we are trying to resolve wildcard imports before checking in the current package first.
example of the issue:
and in the same package:
roaster resolves
HttpRequest
asjava.net.http.HttpRequest
even though it should beorg.jboss.forge.grammar.java.HttpRequest
The text was updated successfully, but these errors were encountered: