Skip to content

Compiler manager should use providers #359

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

import java.util.Map;

Expand All @@ -36,19 +37,27 @@
@Named
public class DefaultCompilerManager implements CompilerManager {
@Inject
private Map<String, Compiler> compilers;
private Map<String, Provider<Compiler>> compilers;

// ----------------------------------------------------------------------
// CompilerManager Implementation
// ----------------------------------------------------------------------

public Compiler getCompiler(String compilerId) throws NoSuchCompilerException {
Compiler compiler = compilers.get(compilerId);
// Provider<Class> is lazy
// presence of provider means component is present (but not yet constructed)
Provider<Compiler> compiler = compilers.get(compilerId);

// it exists: as provider is found
Copy link
Contributor

Choose a reason for hiding this comment

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

Should that not mean that it is NOT there if it is null?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, yes, bad worded comments but i hope the intent is clear 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe remove or move down into the if case (code speaks for itself?)

if (compiler == null) {
throw new NoSuchCompilerException(compilerId);
}

return compiler;
// provider is lazy: if we are here, it exists but not yet created
try {
return compiler.get();
} catch (Exception e) {
// if we are here: DI could not construct it: so report proper error
throw new RuntimeException(e);
}
}
}