-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(extract-subsystems): extract Context
, @In
, InjectionHelper
and @Share
to Subsystem
#4930
Open
DarkWeird
wants to merge
5
commits into
develop
Choose a base branch
from
feat/extract-context
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
46f3d99
feat(extract-subsystems): extract `Context`, `@In`, `InjectionHelper`…
DarkWeird 25eb151
Merge branch 'develop' into feat/extract-context
DarkWeird 696945e
Merge branch 'develop' into feat/extract-context
DarkWeird 45f823e
Merge branch 'develop' into feat/extract-context
DarkWeird 6f0d879
Merge branch 'develop' into feat/extract-context
pollend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Context | ||
|
||
>It is really not subsystem. but used by them | ||
|
||
Context is simple DI implementation for TS | ||
|
||
Provide interface for working with context. | ||
|
||
## How to use (from scratch, not Terasology) | ||
|
||
1. Implement `Context` class | ||
2. Create it | ||
3. Provide it. | ||
4. Use `InjectionHelper` with context to inject at `@In` fields | ||
|
||
## How to use (with Terasology) | ||
|
||
1. Create your system/manager/another injectable class type | ||
2. Write field with `@In` - be sure that Field Type is injectable. then Field will be injected | ||
with manager/system/ another injectable class type | ||
3. Mark with `@Share` - be sure that your class is injectable type. then your class be provided to `Context`. |
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,19 @@ | ||
// Copyright 2021 The Terasology Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
plugins { | ||
java | ||
`java-library` | ||
} | ||
|
||
apply(from = "$rootDir/config/gradle/common.gradle") | ||
|
||
dependencies { | ||
implementation("org.terasology.gestalt:gestalt-util:7.2.0-SNAPSHOT") | ||
implementation("org.terasology.gestalt:gestalt-module:7.2.0-SNAPSHOT") | ||
|
||
implementation("ch.qos.logback:logback-classic:1.2.3") | ||
|
||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.2") | ||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2") | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
subsystems/Context/src/test/java/org/terasology/engine/registry/ContextImplementation.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,27 @@ | ||
// Copyright 2021 The Terasology Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.terasology.engine.registry; | ||
|
||
import com.google.common.collect.Maps; | ||
import org.terasology.engine.context.Context; | ||
|
||
import java.util.Map; | ||
|
||
public class ContextImplementation implements Context { | ||
private final Map<Class<?>, Object> map = Maps.newConcurrentMap(); | ||
|
||
@Override | ||
public <T> T get(Class<? extends T> type) { | ||
T result = type.cast(map.get(type)); | ||
if (result != null) { | ||
return result; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public <T, U extends T> void put(Class<T> type, U object) { | ||
map.put(type, object); | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this intentional? (Adding the
Assertions.
qualifier back in, instead of a static import of the assertNotEquals method.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just personal prefer to avoid static imports