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

Fix TypeName.get() on top-level error types #646

Merged
merged 3 commits into from May 16, 2018
Merged

Fix TypeName.get() on top-level error types #646

merged 3 commits into from May 16, 2018

Conversation

ronshapiro
Copy link
Contributor

No description provided.

@ronshapiro
Copy link
Contributor Author

ronshapiro commented May 9, 2018

One thing I noticed: if there's a type that can be resolved that has type parameters, javac seems to give a TypeMirror that's simple name is "<any>".

I imagine that that was never supported (I don't see any way to get out of that), but maybe that means we should throw on ErrorTypes? That would be a behavioral change though, and it's not clear to me that that's what we should do.

default:
throw new IllegalArgumentException("unexpected type nesting");
Element enclosingElement = element.getEnclosingElement();
if (enclosingElement instanceof PackageElement) {
Copy link
Member

Choose a reason for hiding this comment

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

Any way to do this without instanceof? My read of the docs is that a single class is allowed to implement multiple types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I changed it to use a visitor. LMK if the visitUnknown part looks weird though.

ErrorType errorType =
new DeclaredTypeAsErrorType(getTypes().getDeclaredType(getElement(Set.class)));
assertThat(TypeName.get(errorType)).isEqualTo(ClassName.get(Set.class));
@Test public void errorTypes() {
Copy link
Member

Choose a reason for hiding this comment

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

Great test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🌮 🥙

@swankjesse swankjesse merged commit 5584016 into square:master May 16, 2018
@swankjesse
Copy link
Member

Will release as 1.11.1.

@ronshapiro
Copy link
Contributor Author

Awesome thanks!

@ronshapiro ronshapiro deleted the errortypes branch May 16, 2018 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants