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

test: use DI instead of CoreRegistry #5266

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 @@ -19,11 +19,13 @@
import com.google.gson.stream.JsonWriter;
import org.joml.Vector3f;
import org.joml.Vector4f;
import org.terasology.engine.registry.In;
import org.terasology.engine.world.block.DefaultColorSource;
import org.terasology.engine.world.generator.internal.WorldGeneratorManager;

Check warning on line 24 in engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java

View check run for this annotation

Terasology Jenkins.io / CheckStyle

UnusedImportsCheck

NORMAL: Unused import - org.terasology.engine.world.generator.internal.WorldGeneratorManager.
Raw output
<p>Since Checkstyle 3.0</p><p> Checks for unused import statements. Checkstyle uses a simple but very reliable algorithm to report on unused import statements. An import statement is considered unused if: </p><ul><li> It is not referenced in the file. The algorithm does not support wild-card imports like <code>import java.io.*;</code>. Most IDE's provide very sophisticated checks for imports that handle wild-card imports. </li><li> It is a duplicate of another import. This is when a class is imported more than once. </li><li> The class imported is from the <code>java.lang</code> package. For example importing <code>java.lang.String</code>. </li><li> The class imported is from the same package. </li><li><b>Optionally:</b> it is referenced in Javadoc comments. This check is on by default, but it is considered bad practice to introduce a compile time dependency for documentation purposes only. As an example, the import <code>java.util.Date</code> would be considered referenced with the Javadoc comment <code>{@link Date}</code>. The alternative to avoid introducing a compile time dependency would be to write the Javadoc comment as <code>{@link java.util.Date}</code>. </li></ul><p> The main limitation of this check is handling the case where an imported type has the same name as a declaration, such as a member variable. </p><p> For example, in the following case the import <code>java.awt.Component</code> will not be flagged as unused: </p><pre><code> import java.awt.Component; class FooBar { private Object Component; // a bad practice in my opinion ... } </code></pre>
import org.terasology.gestalt.assets.Asset;
import org.terasology.gestalt.assets.ResourceUrn;
import org.terasology.engine.entitySystem.prefab.Prefab;
import org.terasology.engine.registry.CoreRegistry;

Check warning on line 28 in engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java

View check run for this annotation

Terasology Jenkins.io / CheckStyle

UnusedImportsCheck

NORMAL: Unused import - org.terasology.engine.registry.CoreRegistry.
Raw output
<p>Since Checkstyle 3.0</p><p> Checks for unused import statements. Checkstyle uses a simple but very reliable algorithm to report on unused import statements. An import statement is considered unused if: </p><ul><li> It is not referenced in the file. The algorithm does not support wild-card imports like <code>import java.io.*;</code>. Most IDE's provide very sophisticated checks for imports that handle wild-card imports. </li><li> It is a duplicate of another import. This is when a class is imported more than once. </li><li> The class imported is from the <code>java.lang</code> package. For example importing <code>java.lang.String</code>. </li><li> The class imported is from the same package. </li><li><b>Optionally:</b> it is referenced in Javadoc comments. This check is on by default, but it is considered bad practice to introduce a compile time dependency for documentation purposes only. As an example, the import <code>java.util.Date</code> would be considered referenced with the Javadoc comment <code>{@link Date}</code>. The alternative to avoid introducing a compile time dependency would be to write the Javadoc comment as <code>{@link java.util.Date}</code>. </li></ul><p> The main limitation of this check is handling the case where an imported type has the same name as a declaration, such as a member variable. </p><p> For example, in the following case the import <code>java.awt.Component</code> will not be flagged as unused: </p><pre><code> import java.awt.Component; class FooBar { private Object Component; // a bad practice in my opinion ... } </code></pre>
import org.terasology.engine.world.block.shapes.BlockShape;
import org.terasology.engine.world.block.sounds.BlockSounds;
import org.terasology.engine.utilities.gson.CaseInsensitiveEnumTypeAdapterFactory;
Expand Down Expand Up @@ -311,16 +313,21 @@
}
}

private static class BlockFamilyHandler implements JsonDeserializer<Class<? extends BlockFamily>> {
private class BlockFamilyHandler implements JsonDeserializer<Class<? extends BlockFamily>> {
@In
private BlockFamilyLibrary library;

BlockFamilyHandler() {
}

@Override
public Class<? extends BlockFamily> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {

BlockFamilyLibrary library = CoreRegistry.get(BlockFamilyLibrary.class);
if (library == null) {
return null;
}
return library.getBlockFamily(json.getAsString());

Check warning on line 330 in engine/src/main/java/org/terasology/engine/world/block/loader/BlockFamilyDefinitionFormat.java

View check run for this annotation

Terasology Jenkins.io / SpotBugs

SIC_INNER_SHOULD_BE_STATIC

LOW: Should org.terasology.engine.world.block.loader.BlockFamilyDefinitionFormat$BlockFamilyHandler be a _static_ inner class?
Raw output
<p> This class is an inner class, but does not use its embedded reference to the object which created it.&nbsp; This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary.&nbsp; If possible, the class should be made static. </p>
}
}

Expand Down
Loading