Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Workaround for Eclipse JDT/APT bug around intersection types #305

Merged
merged 2 commits into from
Jul 12, 2015

Conversation

tbroyer
Copy link
Collaborator

@tbroyer tbroyer commented Jul 10, 2015

When in presence of a TypeVariable with an intersection type as the upper
bound, Eclipse JDT/APT returns a TypeVariable equivalent to the declaring
TypeVariable when calling getUpperBound. The only way to retrieve the
actual bounds is to go look at the TypeParameterElement represented by
the TypeVariable.

See #303

When in presence of a TypeVariable with an intersection type as the upper
bound, Eclipse JDT/APT returns a TypeVariable equivalent to the declaring
TypeVariable when calling getUpperBound. The only way to retrieve the
actual bounds is to go look at the TypeParameterElement represented by
the TypeVariable.
@tbroyer
Copy link
Collaborator Author

tbroyer commented Jul 10, 2015

I'm absolutely not fond (read: I find it ugly) of the copied CompilationRule (and it cannot even use the InMemoryJavaFileManager as that's package-private in compile-testing) but that was the easiest way to do it.

}

static private boolean compile(Iterable<? extends Processor> processors) {
JavaCompiler compiler = new EclipseCompiler();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would I be right in thinking that the need for this copied @Rule would go away if the original CompilationRule had an optional constructor parameter that was a JavaCompiler or a Supplier<JavaCompiler>? That seems as if it would be a very useful thing for cases like this. What does @gk5885 think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's right, that's the only required change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Occasionally I try to take a stab at making compile testing work with ecj, but end up running into walls where it makes assumptions about the implementation of the filer and whatnot and ends up crashing. I haven't tried in particular with CompilationRule though. It might work, but I wouldn't be remotely surprised if it didn't either.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah right, I also had to change from compiling dummy sources to processing a class instead, because ECJ requires "all JavaFileObjects be Files" as you note in google/compile-testing#31.

So maybe CompilationRule could just use the JavaCompiler directly taking into account those limitations, rather than calling Compilation.compile(). AFAICT, it doesn't really need an InMemoryJavaFileManager either, or processing the diagnostics, so it would be really simple (well, just like the rule in this PR)

@tbroyer
Copy link
Collaborator Author

tbroyer commented Jul 11, 2015

I'll revisit this PR once google/compile-testing#71 is merged. I might revisit it earlier though wrt the simplification discussed in #303 to unconditionally use asElement().getBounds().

@swankjesse
Copy link
Collaborator

Wow, that's involved! Should I merge as-is and you can follow up?

There's actually no need to deal with intersection types as type mirrors,
we can just go down to the TypeParameterElement and directly get its
bounds.
@tbroyer
Copy link
Collaborator Author

tbroyer commented Jul 11, 2015

I just added a commit with the simplification; I also added a TypeVariableName.get(TypeParameterElement) method.

It's good to merge IMO, and we can follow up with a simplification to the tests when compile-testing makes it possible.

swankjesse added a commit that referenced this pull request Jul 12, 2015
Workaround for Eclipse JDT/APT bug around intersection types
@swankjesse swankjesse merged commit b716399 into square:master Jul 12, 2015
@swankjesse
Copy link
Collaborator

Works for me. Merged. Thanks @tbroyer !

@tbroyer tbroyer deleted the intersectiontypes-in-ecj branch July 12, 2015 17:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants