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

Generic ICellInventoryHandler #3624

Merged
merged 9 commits into from Jul 22, 2018

Conversation

Projects
None yet
2 participants
@fscan
Member

fscan commented Jul 15, 2018

Merge implementations of AbstractCellInventory(Handler) and make them channel agnostic.
Split GUI into its own handler to be registered separately.
This allows addons who register a custom IStorageChannel to use the IStorageCell interface without registering a cell handler.
Any item implementing IStorageCell will just work as a cell, independent of which mod registered the storage channel.
The only custom registration required is the new ICellGuiHandler and only if a GUI for the ME Chest for a new storage channel is wanted.

This breaks API, but makes it a LOT easier for addons in the long run.

Also adds some convenience API methods.

fscan added some commits Jul 15, 2018

@@ -24,11 +24,19 @@
package appeng.api.storage;
import javax.annotation.Nullable;
/**
* Tells the cell provider that changes have been made an the cell must be persisted
*
*/
public interface ISaveProvider

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

CRITICAL Annotate the "ISaveProvider" interface with the @FunctionalInterface annotation rule

{
public AbstractCellInventoryHandler( final IMEInventory c, final IStorageChannel<T> channel )
public BasicCellInventoryHandler( final IMEInventory c, final IStorageChannel<T> channel )

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

CRITICAL The Cyclomatic Complexity of this method "BasicCellInventoryHandler" is 14 which is greater than 10 authorized. rule

@@ -88,7 +88,11 @@ public AbstractCellInventoryHandler( final IMEInventory c, final IStorageChannel
final ItemStack is = config.getStackInSlot( x );
if( !is.isEmpty() )
{
priorityList.add( createConfigStackFromItem( is ) );
final T configItem = channel.createStack( is );
if( configItem != null )

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

CRITICAL Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule

@@ -33,12 +33,12 @@
public final class BasicItemStorageCell extends AbstractStorageCell<IAEItemStack>
{
protected final int perType;

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

MAJOR Remove this "protected" modifier. rule

@@ -33,12 +33,12 @@
public final class BasicItemStorageCell extends AbstractStorageCell<IAEItemStack>
{
protected final int perType;
protected final double idleDrain;

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

MAJOR Remove this "protected" modifier. rule

@@ -165,11 +188,11 @@ public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode
{
if( input.getStackSize() > remainingItemCount )
{
final IAEItemStack toReturn = input.copy();
final T toReturn = input.copy();
toReturn.setStackSize( input.getStackSize() - remainingItemCount );
if( mode == Actionable.MODULATE )

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

CRITICAL Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule

@@ -201,9 +224,9 @@ public IAEItemStack extractItems( final IAEItemStack request, final Actionable m
final long size = Math.min( Integer.MAX_VALUE, request.getStackSize() );
IAEItemStack Results = null;
T Results = null;

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

MINOR Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'. rule

return new ItemCellInventoryHandler( new ItemCellInventory( o, container2 ) );
if( o == null )
{
throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

CRITICAL Define a constant instead of duplicating this literal "ItemStack was used as a cell, but was not a cell!" 3 times. rule

throw new AppEngException( "ItemStack was used as a cell, but was not a cell!" );
}
return new BasicCellInventory<T>( cellType, o, container );

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

MINOR Replace the type specification in this constructor call with the diamond operator ("<>"). rule

}
@Override
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final IActionSource src )
public T injectItems( T input, Actionable mode, IActionSource src )

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

CRITICAL The Cyclomatic Complexity of this method "injectItems" is 16 which is greater than 10 authorized. rule

@@ -111,23 +134,23 @@ public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode
return null;
}
if( this.cellType.isBlackListed( this.i, input ) )
if( this.cellType.isBlackListed( this.getItemStack(), input ) )
{
return input;
}
// This is slightly hacky as it expects a read-only access, but fine for now.
// TODO: Guarantee a read-only access. E.g. provide an isEmpty() method and ensure CellInventory does not write

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

INFO Complete the task associated to this TODO comment. rule

@@ -292,7 +292,7 @@ else if( channel == AEApi.instance().storage().getStorageChannel( IFluidStorageC
final MEInventoryHandler<T> ih = new MEInventoryHandler<T>( h, h.getChannel() );

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

MINOR Replace the type specification in this constructor call with the diamond operator ("<>"). rule

@@ -292,7 +292,7 @@ else if( channel == AEApi.instance().storage().getStorageChannel( IFluidStorageC
final MEInventoryHandler<T> ih = new MEInventoryHandler<T>( h, h.getChannel() );
ih.setPriority( this.priority );
final MEMonitorHandler<T> g = new ChestMonitorHandler<T>( ih );
final ChestMonitorHandler<T> g = new ChestMonitorHandler<T>( ih );

This comment has been minimized.

@orod-org

orod-org Jul 15, 2018

MINOR Replace the type specification in this constructor call with the diamond operator ("<>"). rule

fscan added some commits Jul 16, 2018

@@ -1562,6 +1555,7 @@ public static ItemStack extractItemsByRecipe( final IEnergySource energySrc, fin
return ItemStack.EMPTY;
}
// TODO wtf is this?

This comment has been minimized.

@orod-org

orod-org Jul 21, 2018

INFO Complete the task associated to this TODO comment. rule

fscan added some commits Jul 21, 2018

import appeng.api.storage.data.IAEStack;
public interface IClientHelper

This comment has been minimized.

@orod-org

orod-org Jul 21, 2018

CRITICAL Annotate the "IClientHelper" interface with the @FunctionalInterface annotation rule

* @param mode Simulate or modulate
* @return items not inserted or {@code null} if everything was inserted.
*/
<T extends IAEStack<T>> T poweredInsert( final IEnergySource energy, final IMEInventory<T> inv, final T input, final IActionSource src, final Actionable mode );

This comment has been minimized.

@orod-org

orod-org Jul 21, 2018

MINOR Redundant 'final' modifier. rule
MINOR Redundant 'final' modifier. rule
MINOR Redundant 'final' modifier. rule
MINOR Redundant 'final' modifier. rule
MINOR Redundant 'final' modifier. rule

* @param mode Simulate or modulate
* @return extracted items or {@code null} of nothing was extracted.
*/
<T extends IAEStack<T>> T poweredExtraction( final IEnergySource energy, final IMEInventory<T> inv, final T request, final IActionSource src, final Actionable mode );

This comment has been minimized.

@orod-org

orod-org Jul 21, 2018

MINOR Redundant 'final' modifier. rule
MINOR Redundant 'final' modifier. rule
MINOR Redundant 'final' modifier. rule
MINOR Redundant 'final' modifier. rule
MINOR Redundant 'final' modifier. rule

@orod-org

This comment has been minimized.

orod-org commented Jul 21, 2018

SonarQube analysis reported 89 issues

  • BLOCKER 6 blocker
  • CRITICAL 22 critical
  • MAJOR 36 major
  • MINOR 23 minor
  • INFO 2 info

Watch the comments in this conversation to review them.

Top 10 extra issues

Note: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:

  1. BLOCKER ICellGuiHandler.java#: Add or update the header of this file. rule
  2. BLOCKER IClientHelper.java#: Add or update the header of this file. rule
  3. BLOCKER ApiClientHelper.java#: Add or update the header of this file. rule
  4. BLOCKER BasicItemCellGuiHandler.java#: Add or update the header of this file. rule
  5. BLOCKER BasicCellInventory.java#: Add or update the header of this file. rule
  6. BLOCKER AppEngCellInventory.java#: Add or update the header of this file. rule
  7. CRITICAL IStorageHelper.java#L85: Remove usage of generic wildcard type. rule
  8. CRITICAL AbstractStorageCell.java#L167: The Cyclomatic Complexity of this method "disassembleDrive" is 12 which is greater than 10 authorized. rule
  9. CRITICAL AbstractStorageCell.java#L188: Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule
  10. CRITICAL AbstractStorageCell.java#L195: Refactor this code to not nest more than 3 if/for/while/switch/try statements. rule

@fscan fscan added this to the rv6.alpha - 1.12 milestone Jul 21, 2018

@fscan fscan merged commit c1c7e94 into rv6-1.12 Jul 22, 2018

3 of 4 checks passed

sonarqube SonarQube reported 89 issues, with 22 critical and 6 blocker
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
jenkins Success
Details

@fscan fscan deleted the feature-generic-cell-inventory branch Jul 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment