Closed phroa closed 8 years ago
OCD is good for those kind of things, haha.
Maybe we should cleanup the checked ones?
@kenzierocks I considered deleting, but let's keep them there for history. Any new issues will go in a new comment.
EDIT: Github does not track todo items outside of the original issue topic and they're already in the commit history so I'll delete.
Creeper.java line 36: "Gets whether or not the creeper has been struck by lightning." shouldn't it be "Gets whether or not the creeper is powered.", considering plugins can power them.
@ST-DDT why would we use a nullable when we could use an optional with an overloaded helper?
i.e. two methods
void setCarriedBlock(BlockState carriedBlock);
and
void setCarriedBlock(Optional<BlockState> carriedBlock);
or even just the second one.
Because null can still fit into both, Optionals are designed for return types.
http://java.dzone.com/articles/java-8-optional-how-use-it
What is Optional not trying to solve Optional is not meant to be a mechanism to avoid all types of null pointers. The mandatory input parameters of methods and constructors still have to be tested for example.
Like when using null, Optional does not help with conveying the meaning of an absent value. In a similar way that null can mean many different things (value not found, etc.), so can an absent Optional value.
@ryantheleach I haven't seen any official Oracle statements that have said or implied that Optionals are only for return types, and the Optional used here is not the Java optional anyway. In my opinion moving the possibly of a missing value into the type system is beneficial in many situations, not just for method return statements.
I'm offering this up as an opinion and I hope there is some truth to it.
TL;DR
In Java we're left with either consuming a result that is either wrapped in some class (eg., the Optional
NTL;R
The way I'd suggest looking at this is to treat the SpongeAPI as a black box.
When we use Optional<T>
as a return type, the Sponge through the API is providing the plugin developer more than a simple assurance that whatever the result of the method is, the result is safe. The result is required to be tested by the caller in a safe manner.
The example is:
public Optional<T> getSomethingFromSponge();
// ...
// and in the caller:
Optional<T> result = getSomethingFromSponge();
if ( result.isAbsent() ) {
// proceed down sad path
} else {
// proceed down happy path
}
vs.
public T getSomethingFromSponge()
// ...
// and in the caller:
T result = getSomethingFromSponge();
if ( result == null ) {
// proceed down sad path .. Gee, I think.does null mean it truly failed?
} else {
// proceed down happy path .. Hmm, a non null value may mean success, perhaps?
}
I'd rather see the use of Optional
On the other hand, when we look at arguments to methods:
doAnotherThing( T arg)
I'd rather there be no Optional
Methods in the Sponge are (or will be) well crafted and do the right amount of due diligence on the arguments passed to them. Using Optional
Another case for methods with Optional
Optional<T> getSomethingFromSponge( int arg ) {
// ...
if (arg <= 0) {
// resort to some default behavior
this.internalParameter = -1;
} else {
// the argument has quality we can use
this.internalParameter = arg;
}
// return something ...
}
The problem with this kind of code IMHO is that the caller must know in advance that when arg is less or equal to 0, that the internal behavior of the class has a default case. A case where perhaps the behavior in that area is turned off or disabled.
So thus, the argument for Optional
public Optional<T> getSomething( Optional<Integer> arg ) {
// ...
if ( arg.isAbsent() ) {
// setup behavior to cope with sad-path
} else {
// setup behavior to cope with happy path
}
// ...
// return something ...
}
I'd counter that this excuse for Optional
public Optional<T> getSomething()
Why pass in an Optional
I cannot make the blanket statement for Sponge that methods shall not have Optional
I could make a blanket statement for Sponge API design that recommends Optional
All of this is syntax sugar to overcome the fact that Java is merely pass-by-value. There is simply no way to do what we do with pointers in C/C++:
RESULT doSomething( int x, T* pArg ) {
// whatever the case may be choose:
// A) modify the whatever pArg points to and then return S_OK or
// B) leave pArg alone and return E_FAIL;
}
// and in the caller:
if ( SUCCEEDED ( doSomething ( n, pFoo ) ) ) {
// proceed down happy path
} else {
// proceed down sad path
}
There is, since objects can be passed in and their reference is passed by value, you can just modify the object passed in and return a result. (of course this changes if you are passing in a primitive)
Result method(int x, Object pArg){
//A) Modify the fields of pArg or call methods as appropriate, then return Result.OK or
//B) leave pArg alone and return Result.FAIL
}
if(Results.success(doSomething(n, pFoo)){
//proceed down happy path
} else {
// proceed down sad path
}
But the reason why I am against using Optionals in parameters is
I think (?) we're in agreement that Optional
Where we may (?) agree is using the Optional
Thanks
This list can now be cleared, to make way for any new minor issues discovered :)
@simon816 Have you fixed all of them in your pull request?
@Minecrell Yes, that was the main purpose of the PR. Of course you could check by hand if you wanted...
@simon816 That's why I asked, I've updated the issue now.
I personally can't hit format on GameRegistry
because all of the javadoc comments are incorrectly formatted according to Eclipse + Google style formatter. Possibly something to look into?
Add @SuppressWarnings("rawtypes")
to SimpleServiceManager line 86.
Missing 'is' at javadoc in MinecraftVersion:49
@Bammerbom Fixed, thanks
BiomeType
needs a getter for its nameLiving
needs a class javadocPotionEffect#apply
is questionable and should possibly be moved to LivingSuggested changes from #462
EntityUnleashEvent
to match our EntityLeashEvent
ExplosionPrimeEvent
are misspelledEntityInteractEvent
and children should implement CancellableEntityTameEvent
offers no way either to get the tamerEntityTeleportEvent
has no velocity methods (for maintaining or changing the velocity of the player after the teleport)EntityIgniteEvent
getter and setter for fire ticksEntityEnterPortalEvent
and EntityLeavePortalEvent
Missing Javadocs for
Missing additional methods in:
Entity#setRotation(Vector3f)
and Entity#setLocationAndRotation(Location, Vector3f, EnumSet<RelativePositions>)
to specify that the vector is formed as {yaw, pitch, roll}
setLocationAndRotation
that doesn't include the relative position flagsLooks like I made a slight error in my last PR. This doc has the number 35 twice.
Here is a list of all classes/interfaces that have missing class javadocs. Most of the Event
s have already been detected by gabizou, but i added them for completeness.
EDIT: Fixed by gabizou
Shall i help adding them?
Tamer.getName
returns null
, not Optional<String>
. Tamer.java
@ST-DDT By default, someone from staff will take care of the outstanding issues on the OCD list. It'll be taken care of soon.
@gabizou Thanks for fixing all those javadoc issues:
I scanned the API for more missing javadocs, and this classes are missing their class javadocs.
org.spongepowered.api.attribute.AttributeCalculator
org.spongepowered.api.entity.Tamer
org.spongepowered.api.event.inventory.ItemExtractEvent
org.spongepowered.api.item.CookedFishes
org.spongepowered.api.item.DyeColor
org.spongepowered.api.item.DyeColors
org.spongepowered.api.item.Enchantment
org.spongepowered.api.item.Enchantments
org.spongepowered.api.item.Fishes
org.spongepowered.api.item.GoldenApples
In addition to that ItemExtractEvent
does not extend Event
at all.
Was that file commited accidentally?
EDIT: Everything fixed
PlayerDeathEvent
into new PlayerDropsEvent
PlayerDeathEvent
not cancellable@gabizou
GenericArguments.none()
should return a static CommandElement
instead of rebuilding it every time.
GameMode
javadoc uses fully qualified link to Player
. :disappointed: InventoryOperationResult.Type.Cancelled
has incomplete javadocBan.User#getUser
wrong return type:
https://github.com/SpongePowered/SpongeAPI/blob/master/src/main/java/org/spongepowered/api/util/ban/Ban.java#L91
maybe rename to UserBan?Or use the full package declaration.
* <li>{@link #NORTH} targeting towards -Z</li>
* <li>{@link #EAST} targeting towards +X</li>
* <li>{@link #SOUTH} targeting towards +Z</li>
* <li>{@link #WEST} targeting towards -X</li>
* <li>{@link #UP} targeting towards +Y</li>
* <li>{@link #DOWN} targeting towards -Y</li>
Throws a few checkstyle warning because it uses @param
tags in the description. Should be replaced with @code
tags.
Some method declarations in DataHolder
are generic although they don't have to. This leads to worse usability / more raw casts.
DataHolder holder = null;
DataManipulator<?> data = null;
holder.offer(data); // Does not compile
holder.offer((DataManipulator) data);
That offer is usually used in for each loops like SpongeItemStackBuilder
.
<T extends DataManipulator<T>> boolean remove(Class<T> manipulatorClass)
<T extends DataManipulator<T>> boolean isCompatible(Class<T> manipulatorClass)
<T extends DataManipulator<T>> DataTransactionResult offer(T manipulatorData)
<T extends DataManipulator<T>> DataTransactionResult offer(T manipulatorData, DataPriority priority)
They should be declared this way:
boolean remove(Class<? extends DataManipulator<?>> manipulatorClass)
boolean isCompatible(Class<? extends DataManipulator<?>> manipulatorClass)
DataTransactionResult offer(DataManipulator<?> manipulatorData)
DataTransactionResult offer(DataManipulator<?> manipulatorData, DataPriority priority)
or that way:
<T extends DataManipulator<?>> boolean remove(Class<T> manipulatorClass)
<T extends DataManipulator<?>> boolean isCompatible(Class<T> manipulatorClass)
<T extends DataManipulator<?>> DataTransactionResult offer(T manipulatorData)
<T extends DataManipulator<?>> DataTransactionResult offer(T manipulatorData, DataPriority priority)
Clean up some javadocs for MessageSinks#combined and MessageSinkFactory#combined: #727
Should these be keys or types? The constructor and method calls them types but the public fields call them keys.
Quote from @AlphaModder Now that doclint is turned off, there is no need for unnecessary imports like the ones here
IMO they are still needed. I think they are used when generating the javadoc HTML in order to provide links to the docs for that class.
Quote from @saladoc
InventoryOperationResult.Type.Cancelled
has incomplete javadoc
What's incomplete? There have been no changes since you wrote that comment and to me it reads fine.
Optional
return values. Although spawning of the provided Projectile
class may not be possible at all times. Such as in UnknownProjectileSource, which itself could/should be a singleton for easier comparison.this(...)
call is flipped (bug?)Operator
parameter being (not) @Nullable
(bug?)equals(Object)
is different of course (but keeping the simple overwrite is enough, although i'm not sure whether this is even necessary)Coerce.toLong Number.shortValue()
should be Number.longValue()
.
@SuppressWarnings("fallthrough")
@ST-DDT
CommandFlags:162 - [fallthrough] possible fall-through into case
I think what's wrong is that there is a space between //
and $
.
Now: // $FALL-THROUGH$
Should be: //$FALL-THROUGH$
Javadoc states it takes a color to strip as opposed to a format marker. Implementation instead looks for a formatter marker and removes both the marker and the color.
Either the JavaDocs should be fixed, or the implementation should be changed to match the javadocs.
Track at https://github.com/SpongePowered/SpongeAPI/pull/860
Minor Issues List
Direction:30
GameMode
javadoc uses fully qualified link toPlayer
Some method declarations inappears to have been refactored so I won't touchDataHolder
are generic although they don't have to. This leads to worse usability / more raw casts. See comment: https://github.com/SpongePowered/SpongeAPI/issues/221#issuecomment-107156044AbstractInventoryProperty
could extendAbstractProperty
. See comment: https://github.com/SpongePowered/SpongeAPI/issues/221#issuecomment-119275472 for moreCheckstyle warnings