-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#27 No longer throw an exception directly if requested class cannot b…
…e instantiated - There may be instantiation providers that know of a subclass to use (e.g. with the newly supported Provider class)
- Loading branch information
Showing
14 changed files
with
109 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/ch/jalu/injector/handlers/instantiation/DirectInstantiationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package ch.jalu.injector.handlers.instantiation; | ||
|
||
import ch.jalu.injector.utils.InjectorUtils; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Instantiation provider for instantiations that happen on the class directly, | ||
* i.e. limited to classes which are instantiable. | ||
*/ | ||
public abstract class DirectInstantiationProvider implements InstantiationProvider { | ||
|
||
@Override | ||
public final <T> Instantiation<T> get(Class<T> clazz) { | ||
if (InjectorUtils.canInstantiate(clazz)) { | ||
return safeGet(clazz); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Gets the instantiation for the class or null if unavailable. This method | ||
* is only called with classes which can be instantiated. | ||
* | ||
* @param clazz the class to process | ||
* @param <T> the class' type | ||
* @return the instantiation, or null if not applicable | ||
*/ | ||
@Nullable | ||
protected abstract <T> Instantiation<T> safeGet(Class<T> clazz); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters