Implicit non-nullability for fields

This commit is contained in:
Anuken 2020-10-01 13:33:43 -04:00
parent b15cdfef46
commit 199be4d13d
37 changed files with 71 additions and 87 deletions

View File

@ -19,7 +19,7 @@ public class GameState{
/** Whether the game is in game over state. */
public boolean gameOver = false, serverPaused = false, wasTimeout;
/** Map that is currently being played on. */
public @NonNull Map map = emptyMap;
public Map map = emptyMap;
/** The current game rules. */
public Rules rules = new Rules();
/** Statistics for this save/game. Displayed after game over. */

View File

@ -31,7 +31,7 @@ import static mindustry.Vars.*;
public class World{
public final Context context = new Context();
public @NonNull Tiles tiles = new Tiles(0, 0);
public Tiles tiles = new Tiles(0, 0);
private boolean generating, invalidMap;
private ObjectMap<Map, Runnable> customMapLoaders = new ObjectMap<>();
@ -86,13 +86,11 @@ public class World{
return height()*tilesize;
}
@NonNull
public Floor floor(int x, int y){
Tile tile = tile(x, y);
return tile == null ? Blocks.air.asFloor() : tile.floor();
}
@NonNull
public Floor floorWorld(float x, float y){
Tile tile = tileWorld(x, y);
return tile == null ? Blocks.air.asFloor() : tile.floor();
@ -132,7 +130,6 @@ public class World{
return tile.build;
}
@NonNull
public Tile rawTile(int x, int y){
return tiles.getn(x, y);
}

View File

@ -10,8 +10,7 @@ import mindustry.mod.Mods.*;
public abstract class Content implements Comparable<Content>, Disposable{
public final short id;
/** Info on which mod this content was loaded from. */
public @NonNull ModContentInfo minfo = new ModContentInfo();
public ModContentInfo minfo = new ModContentInfo();
public Content(){
this.id = (short)Vars.content.getBy(getContentType()).size;

View File

@ -19,7 +19,7 @@ public class EditorTile extends Tile{
}
@Override
public void setFloor(@NonNull Floor type){
public void setFloor(Floor type){
if(skip()){
super.setFloor(type);
return;

View File

@ -8,7 +8,7 @@ import mindustry.gen.*;
import mindustry.type.*;
public class StatusFieldAbility extends Ability{
public @NonNull StatusEffect effect;
public StatusEffect effect;
public float duration = 60, reload = 100, range = 20;
public Effect applyEffect = Fx.heal;
public Effect activeEffect = Fx.overdriveWave;
@ -17,7 +17,7 @@ public class StatusFieldAbility extends Ability{
StatusFieldAbility(){}
public StatusFieldAbility(@NonNull StatusEffect effect, float duration, float reload, float range){
public StatusFieldAbility(StatusEffect effect, float duration, float reload, float range){
this.duration = duration;
this.reload = reload;
this.range = range;

View File

@ -2,7 +2,6 @@ package mindustry.entities.abilities;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.*;
import mindustry.content.*;
@ -13,13 +12,13 @@ import mindustry.type.*;
import mindustry.ui.*;
public class UnitSpawnAbility extends Ability{
public @NonNull UnitType type;
public UnitType type;
public float spawnTime = 60f, spawnX, spawnY;
public Effect spawnEffect = Fx.spawn;
protected float timer;
public UnitSpawnAbility(@NonNull UnitType type, float spawnTime, float spawnX, float spawnY){
public UnitSpawnAbility(UnitType type, float spawnTime, float spawnX, float spawnY){
this.type = type;
this.spawnTime = spawnTime;
this.spawnX = spawnX;

View File

@ -13,7 +13,7 @@ import mindustry.world.*;
import static mindustry.Vars.*;
public class LiquidBulletType extends BulletType{
public @NonNull Liquid liquid;
public Liquid liquid;
public float puddleSize = 6f;
public LiquidBulletType(@Nullable Liquid liquid){

View File

@ -421,7 +421,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
* @param todump payload to dump.
* @return whether the payload was moved successfully
*/
public boolean movePayload(@NonNull Payload todump){
public boolean movePayload(Payload todump){
int trns = block.size/2 + 1;
Tile next = tile.getNearby(Geometry.d4(rotation).x * trns, Geometry.d4(rotation).y * trns);
@ -438,7 +438,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
* @param todump payload to dump.
* @return whether the payload was moved successfully
*/
public boolean dumpPayload(@NonNull Payload todump){
public boolean dumpPayload(Payload todump){
if(proximity.size == 0) return false;
int dump = this.dump;

View File

@ -33,7 +33,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
@Import float x, y;
@NonNull @ReadOnly Unit unit = Nulls.unit;
@ReadOnly Unit unit = Nulls.unit;
transient private Unit lastReadUnit = Nulls.unit;
transient @Nullable NetConnection con;

View File

@ -2,7 +2,6 @@ package mindustry.game;
import arc.*;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import mindustry.ctype.*;
import mindustry.type.*;
@ -10,7 +9,7 @@ import mindustry.type.*;
public class Objectives{
public static class Research implements Objective{
public @NonNull UnlockableContent content;
public UnlockableContent content;
public Research(UnlockableContent content){
this.content = content;
@ -50,7 +49,7 @@ public class Objectives{
//TODO merge
public abstract static class SectorObjective implements Objective{
public @NonNull SectorPreset preset;
public SectorPreset preset;
}
/** Defines a specific objective for a game. */

View File

@ -21,7 +21,7 @@ public class Schematic implements Publishable, Comparable<Schematic>{
/** Associated mod. If null, no mod is associated with this schematic. */
public @Nullable LoadedMod mod;
public Schematic(Seq<Stile> tiles, @NonNull StringMap tags, int width, int height){
public Schematic(Seq<Stile> tiles, StringMap tags, int width, int height){
this.tiles = tiles;
this.tags = tags;
this.width = width;
@ -52,7 +52,7 @@ public class Schematic implements Publishable, Comparable<Schematic>{
return tiles.contains(s -> s.block instanceof CoreBlock);
}
public @NonNull CoreBlock findCore(){
public CoreBlock findCore(){
Stile tile = tiles.find(s -> s.block instanceof CoreBlock);
if(tile == null) throw new IllegalArgumentException("Schematic is missing a core!");
return (CoreBlock)tile.block;
@ -118,7 +118,7 @@ public class Schematic implements Publishable, Comparable<Schematic>{
}
public static class Stile{
public @NonNull Block block;
public Block block;
public short x, y;
public Object config;
public byte rotation;

View File

@ -74,7 +74,7 @@ public class Team implements Comparable<Team>{
/** @return the core items for this team, or an empty item module.
* Never add to the resulting item module, as it is mutable. */
public @NonNull ItemModule items(){
public ItemModule items(){
return core() == null ? ItemModule.empty : core().items;
}

View File

@ -348,7 +348,7 @@ public class LCanvas extends Table{
public static class JumpButton extends ImageButton{
Color hoverColor = Pal.place;
Color defaultColor = Color.white;
@NonNull Prov<StatementElem> to;
Prov<StatementElem> to;
boolean selecting;
float mx, my;
ClickListener listener;
@ -356,7 +356,7 @@ public class LCanvas extends Table{
JumpCurve curve;
public JumpButton(@NonNull Prov<StatementElem> getter, Cons<StatementElem> setter){
public JumpButton(Prov<StatementElem> getter, Cons<StatementElem> setter){
super(Tex.logicNode, Styles.colori);
to = getter;

View File

@ -440,6 +440,8 @@ public class ContentParser{
}
public void markError(Content content, LoadedMod mod, Fi file, Throwable error){
Log.err("Error for @ / @:\n@\n", content, file, Strings.getStackTrace(error));
content.minfo.mod = mod;
content.minfo.sourceFile = file;
content.minfo.error = makeError(error, file);
@ -545,7 +547,7 @@ public class ContentParser{
try{
if(field.field.getType().isPrimitive()) return;
if(field.field.isAnnotationPresent(NonNull.class) && field.field.get(object) == null){
if(!field.field.isAnnotationPresent(Nullable.class) && field.field.get(object) == null){
throw new RuntimeException("'" + field.field.getName() + "' in " + object.getClass().getSimpleName() + " is missing!");
}
}catch(Exception e){

View File

@ -5,7 +5,7 @@ import arc.mock.*;
import arc.util.ArcAnnotate.*;
public class ModLoadingMusic implements Music{
public @NonNull Music music = new MockMusic();
public Music music = new MockMusic();
@Override
public void play(){

View File

@ -6,7 +6,7 @@ import arc.mock.*;
import arc.util.ArcAnnotate.*;
public class ModLoadingSound implements Sound{
public @NonNull Sound sound = new MockSound();
public Sound sound = new MockSound();
@Override
public float calcPan(float x, float y){

View File

@ -399,7 +399,7 @@ public class Mods implements Loadable{
d.button("@details", Icon.downOpen, Styles.transt, () -> {
new Dialog(""){{
setFillParent(true);
cont.pane(e -> e.add(c.minfo.error).wrap().grow()).grow();
cont.pane(e -> e.add(c.minfo.error).wrap().grow().labelAlign(Align.center, Align.left)).grow();
cont.row();
cont.button("@ok", Icon.left, this::hide).size(240f, 60f);
}}.show();

View File

@ -695,9 +695,9 @@ public class Administration{
/** Defines a (potentially dangerous) action that a player has done in the world.
* These objects are pooled; do not cache them! */
public static class PlayerAction implements Poolable{
public @NonNull Player player;
public @NonNull ActionType type;
public @NonNull Tile tile;
public Player player;
public ActionType type;
public Tile tile;
/** valid for block placement events only */
public @Nullable Block block;

View File

@ -66,7 +66,7 @@ public class AmmoTypes implements ContentList{
}
public static class ItemAmmoType extends AmmoType{
public @NonNull Item item;
public Item item;
public ItemAmmoType(Item item){
this.item = item;

View File

@ -9,7 +9,7 @@ import mindustry.ui.*;
public class Liquid extends UnlockableContent{
/** Color used in pipes and on the ground. */
public final @NonNull Color color;
public final Color color;
/** Color used in bars. */
public @Nullable Color barColor;
/** Color used to draw lights. Note that the alpha channel is used to dictate brightness. */

View File

@ -24,7 +24,7 @@ public class Planet extends UnlockableContent{
/** intersect() temp var. */
private static final Vec3 intersectResult = new Vec3();
/** Mesh used for rendering. Created on load() - will be null on the server! */
public PlanetMesh mesh;
public @Nullable PlanetMesh mesh;
/** Position in global coordinates. Will be 0,0,0 until the Universe updates it. */
public Vec3 position = new Vec3();
/** Grid used for the sectors on the planet. Null if this planet can't be landed on. */
@ -32,7 +32,7 @@ public class Planet extends UnlockableContent{
/** Generator that will make the planet. Can be null for planets that don't need to be landed on. */
public @Nullable PlanetGenerator generator;
/** Array of sectors; directly maps to tiles in the grid. */
public @NonNull Seq<Sector> sectors;
public Seq<Sector> sectors;
/** Radius of this planet's sphere. Does not take into account sattelites. */
public float radius;
/** Orbital radius around the sun. Do not change unless you know exactly what you are doing.*/
@ -60,7 +60,7 @@ public class Planet extends UnlockableContent{
/** Parent body that this planet orbits around. If null, this planet is considered to be in the middle of the solar system.*/
public @Nullable Planet parent;
/** The root parent of the whole solar system this planet is in. */
public @NonNull Planet solarSystem;
public Planet solarSystem;
/** All planets orbiting this one, in ascending order of radius. */
public Seq<Planet> children = new Seq<>();
/** Sattelites orbiting this planet. */

View File

@ -1,12 +1,10 @@
package mindustry.type;
import arc.util.ArcAnnotate.*;
/** Any object that is orbiting a planet. */
public class Satellite{
public @NonNull Planet planet;
public Planet planet;
public Satellite(@NonNull Planet orbiting){
public Satellite(Planet orbiting){
this.planet = orbiting;
}
}

View File

@ -3,7 +3,6 @@ package mindustry.type;
import arc.func.*;
import arc.graphics.g2d.*;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import mindustry.ctype.*;
import mindustry.game.*;
import mindustry.gen.*;
@ -11,9 +10,9 @@ import mindustry.maps.generators.*;
import mindustry.ui.*;
public class SectorPreset extends UnlockableContent{
public @NonNull FileMapGenerator generator;
public @NonNull Planet planet;
public @NonNull Sector sector;
public FileMapGenerator generator;
public Planet planet;
public Sector sector;
public int captureWave = 0;
public Cons<Rules> rules = rules -> rules.winWave = captureWave;

View File

@ -11,7 +11,6 @@ import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import arc.util.ArcAnnotate.*;
import mindustry.ai.types.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
@ -39,8 +38,8 @@ public class UnitType extends UnlockableContent{
/** If true, the unit is always at elevation 1. */
public boolean flying;
public @NonNull Prov<? extends Unit> constructor;
public @NonNull Prov<? extends UnitController> defaultController = () -> !flying ? new GroundAI() : new FlyingAI();
public Prov<? extends Unit> constructor;
public Prov<? extends UnitController> defaultController = () -> !flying ? new GroundAI() : new FlyingAI();
public float speed = 1.1f, boostMultiplier = 1f, rotateSpeed = 5f, baseRotateSpeed = 5f;
public float drag = 0.3f, accel = 0.5f, landShake = 0f, rippleScale = 1f, fallSpeed = 0.018f;
public float health = 200f, range = -1, armor = 0f;

View File

@ -4,7 +4,6 @@ import arc.*;
import arc.audio.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.util.ArcAnnotate.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.entities.bullet.*;
@ -16,7 +15,7 @@ public class Weapon{
/** displayed weapon region */
public String name;
/** bullet shot */
public @NonNull BulletType bullet;
public BulletType bullet;
/** shell ejection effect */
public Effect ejectEffect = Fx.none;
/** whether to create a flipped copy of this weapon upon initialization. default: true */

View File

@ -15,7 +15,7 @@ import static mindustry.Vars.*;
public class MapPlayDialog extends BaseDialog{
CustomRulesDialog dialog = new CustomRulesDialog();
Rules rules;
@NonNull Gamemode selectedGamemode = Gamemode.survival;
Gamemode selectedGamemode = Gamemode.survival;
Map lastMap;
public MapPlayDialog(){

View File

@ -26,9 +26,9 @@ public class Tile implements Position, QuadTreeObject, Displayable{
/** Tile entity, usually null. */
public @Nullable Building build;
public short x, y;
protected @NonNull Block block;
protected @NonNull Floor floor;
protected @NonNull Floor overlay;
protected Block block;
protected Floor floor;
protected Floor overlay;
protected boolean changing = false;
public Tile(int x, int y){
@ -130,15 +130,15 @@ public class Tile implements Position, QuadTreeObject, Displayable{
return block.solid && !block.synthetic() && block.fillsTile;
}
public @NonNull Floor floor(){
public Floor floor(){
return floor;
}
public @NonNull Block block(){
public Block block(){
return block;
}
public @NonNull Floor overlay(){
public Floor overlay(){
return overlay;
}
@ -173,11 +173,11 @@ public class Tile implements Position, QuadTreeObject, Displayable{
return team().id;
}
public void setBlock(@NonNull Block type, Team team, int rotation){
public void setBlock(Block type, Team team, int rotation){
setBlock(type, team, rotation, type::newBuilding);
}
public void setBlock(@NonNull Block type, Team team, int rotation, Prov<Building> entityprov){
public void setBlock(Block type, Team team, int rotation, Prov<Building> entityprov){
changing = true;
if(type.isStatic() || this.block.isStatic()){
@ -232,16 +232,16 @@ public class Tile implements Position, QuadTreeObject, Displayable{
changing = false;
}
public void setBlock(@NonNull Block type, Team team){
public void setBlock(Block type, Team team){
setBlock(type, team, 0);
}
public void setBlock(@NonNull Block type){
public void setBlock(Block type){
setBlock(type, Team.derelict, 0);
}
/** This resets the overlay! */
public void setFloor(@NonNull Floor type){
public void setFloor(Floor type){
this.floor = type;
this.overlay = (Floor)Blocks.air;
@ -252,7 +252,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{
}
/** Sets the floor, preserving overlay.*/
public void setFloorUnder(@NonNull Floor floor){
public void setFloorUnder(Floor floor){
Block overlay = this.overlay;
setFloor(floor);
setOverlay(overlay);
@ -326,7 +326,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{
setOverlay(content.block(ore));
}
public void setOverlay(@NonNull Block block){
public void setOverlay(Block block){
this.overlay = (Floor)block;
recache();

View File

@ -50,20 +50,20 @@ public class Tiles implements Iterable<Tile>{
}
/** @return a tile at coordinates; throws an exception if out of bounds */
public @NonNull Tile getn(int x, int y){
public Tile getn(int x, int y){
if(x < 0 || x >= width || y < 0 || y >= height) throw new IllegalArgumentException(x + ", " + y + " out of bounds: width=" + width + ", height=" + height);
return array[y*width + x];
}
/** @return a tile at coordinates, clamped. */
public @NonNull Tile getc(int x, int y){
public Tile getc(int x, int y){
x = Mathf.clamp(x, 0, width - 1);
y = Mathf.clamp(y, 0, height - 1);
return array[y*width + x];
}
/** @return a tile at an iteration index [0, width * height] */
public @NonNull Tile geti(int idx){
public Tile geti(int idx){
return array[idx];
}

View File

@ -1,11 +1,10 @@
package mindustry.world.blocks.defense.turrets;
import arc.util.ArcAnnotate.*;
import mindustry.entities.bullet.*;
import mindustry.world.meta.*;
public class PowerTurret extends Turret{
public @NonNull BulletType shootType;
public BulletType shootType;
public float powerUse = 1f;
public PowerTurret(String name){

View File

@ -152,7 +152,7 @@ public abstract class Turret extends Block{
public boolean logicShooting = false;
public @Nullable Posc target;
public Vec2 targetPos = new Vec2();
public @NonNull BlockUnitc unit = Nulls.blockUnit;
public BlockUnitc unit = Nulls.blockUnit;
@Override
public float range(){

View File

@ -37,7 +37,7 @@ public class Floor extends Block{
/** Effect displayed when drowning on this floor. */
public Effect drownUpdateEffect = Fx.bubble;
/** Status effect applied when walking on. */
public @NonNull StatusEffect status = StatusEffects.none;
public StatusEffect status = StatusEffects.none;
/** Intensity of applied status effect. */
public float statusDuration = 60f;
/** liquids that drop from this block, used for pumps */

View File

@ -3,12 +3,11 @@ package mindustry.world.blocks.production;
import arc.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.util.ArcAnnotate.*;
import arc.util.io.*;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.consumers.*;
import mindustry.world.meta.*;
@ -18,7 +17,7 @@ import mindustry.world.meta.values.*;
* Extracts a random list of items from an input item and an input liquid.
*/
public class Separator extends Block{
public @NonNull ItemStack[] results;
public ItemStack[] results;
public float craftTime;
public @Load("@-liquid") TextureRegion liquidRegion;

View File

@ -154,7 +154,7 @@ public class CoreBlock extends StorageBlock{
public class CoreBuild extends Building implements ControlBlock{
public int storageCapacity;
//note that this unit is never actually used for control; the possession handler makes the player respawn when this unit is controlled
public @NonNull BlockUnitc unit = Nulls.blockUnit;
public BlockUnitc unit = Nulls.blockUnit;
@Override
public void created(){

View File

@ -3,14 +3,13 @@ package mindustry.world.consumers;
import arc.func.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.meta.*;
public class ConsumeItemDynamic extends Consume{
public final @NonNull Func<Building, ItemStack[]> items;
public final Func<Building, ItemStack[]> items;
public <T extends Building> ConsumeItemDynamic(Func<T, ItemStack[]> items){
this.items = (Func<Building, ItemStack[]>)items;

View File

@ -1,9 +1,8 @@
package mindustry.world.consumers;
import arc.struct.*;
import arc.func.*;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import arc.struct.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.ui.*;
@ -13,8 +12,7 @@ import mindustry.world.meta.values.*;
import static mindustry.Vars.*;
public class ConsumeItemFilter extends Consume{
public final @NonNull
Boolf<Item> filter;
public final Boolf<Item> filter;
public ConsumeItemFilter(Boolf<Item> item){
this.filter = item;

View File

@ -2,7 +2,6 @@ package mindustry.world.consumers;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.ui.*;
@ -10,7 +9,7 @@ import mindustry.world.meta.*;
import mindustry.world.meta.values.*;
public class ConsumeItems extends Consume{
public final @NonNull ItemStack[] items;
public final ItemStack[] items;
public ConsumeItems(ItemStack[] items){
this.items = items;

View File

@ -1,15 +1,14 @@
package mindustry.world.consumers;
import arc.struct.*;
import arc.scene.ui.layout.*;
import arc.util.ArcAnnotate.*;
import arc.struct.*;
import mindustry.gen.*;
import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.meta.*;
public class ConsumeLiquid extends ConsumeLiquidBase{
public final @NonNull Liquid liquid;
public final Liquid liquid;
public ConsumeLiquid(Liquid liquid, float amount){
super(amount);