From d031d20d565bd7962bd26c5ba4719c8eca741154 Mon Sep 17 00:00:00 2001 From: Joseph Cloutier Date: Sun, 16 Jun 2024 12:05:44 -0400 Subject: [PATCH] Use `final` where possible. --- src/echoes/ComponentStorage.hx | 4 +- src/echoes/Echoes.hx | 14 ++--- src/echoes/Entity.hx | 4 +- src/echoes/System.hx | 6 +- src/echoes/SystemList.hx | 12 ++-- src/echoes/macro/ComponentStorageBuilder.hx | 14 ++--- src/echoes/macro/EntityTemplateBuilder.hx | 40 ++++++------- src/echoes/macro/EntityTools.hx | 22 ++++---- src/echoes/macro/MacroTools.hx | 14 ++--- src/echoes/macro/Report.hx | 4 +- src/echoes/macro/SystemBuilder.hx | 46 +++++++-------- src/echoes/macro/TypeSubstitutions.hx | 20 +++---- src/echoes/macro/ViewBuilder.hx | 36 ++++++------ src/echoes/utils/Clock.hx | 2 +- test/AdvancedFunctionalityTest.hx | 62 ++++++++++----------- test/BasicFunctionalityTest.hx | 34 +++++------ test/EdgeCaseTest.hx | 28 +++++----- test/MethodCounter.hx | 18 +++--- 18 files changed, 190 insertions(+), 190 deletions(-) diff --git a/src/echoes/ComponentStorage.hx b/src/echoes/ComponentStorage.hx index d413f85..53168b2 100644 --- a/src/echoes/ComponentStorage.hx +++ b/src/echoes/ComponentStorage.hx @@ -135,7 +135,7 @@ class ComponentStorage { } public function remove(entity:Entity):Void { - var removedComponent:Null = get(entity); + final removedComponent:Null = get(entity); #if (echoes_storage == "Map") storage.remove(entity.id); @@ -253,7 +253,7 @@ abstract EntityComponents(ComponentTypes) from ComponentTypes { * might be `["StdTypes.Bool" => true, "String" => "Hello World"]`. */ @:to private inline function toMap():Map { - var entity:Entity = switch(components.indexOf(cast this)) { + final entity:Entity = switch(components.indexOf(cast this)) { case -1: throw "This EntityComponents instance was disposed."; case x: diff --git a/src/echoes/Echoes.hx b/src/echoes/Echoes.hx index da67d43..3af5ae8 100644 --- a/src/echoes/Echoes.hx +++ b/src/echoes/Echoes.hx @@ -66,8 +66,8 @@ class Echoes { * * To search the full tree, use `activeSystems.find()`. */ - public static var activeSystems(default, null):SystemList = { - var activeSystems:SystemList = new SystemList(); + public static final activeSystems:SystemList = { + final activeSystems:SystemList = new SystemList(); activeSystems.__activate__(); activeSystems.clock.maxTime = 1; activeSystems; @@ -127,8 +127,8 @@ class Echoes { * Updates all active systems. */ public static function update():Void { - var startTime:Float = haxe.Timer.stamp(); - var dt:Float = startTime - lastUpdate; + final startTime:Float = haxe.Timer.stamp(); + final dt:Float = startTime - lastUpdate; lastUpdate = startTime; activeSystems.__update__(dt); @@ -192,8 +192,8 @@ class Echoes { * @see `getView()` to automatically activate the view. */ public static #if !macro macro #end function getInactiveView(componentTypes:Array>>):Expr { - var componentComplexTypes:Array = [for(type in componentTypes) type.parseClassExpr()]; - var viewName:String = componentComplexTypes.getViewName(); + final componentComplexTypes:Array = [for(type in componentTypes) type.parseClassExpr()]; + final viewName:String = componentComplexTypes.getViewName(); componentComplexTypes.createViewType(); return macro $i{ viewName }.instance; @@ -212,7 +212,7 @@ class Echoes { * ``` */ public static #if !macro macro #end function getView(componentTypes:Array>>):Expr { - var view:Expr = getInactiveView(componentTypes); + final view:Expr = getInactiveView(componentTypes); return macro { $view.activate(); diff --git a/src/echoes/Entity.hx b/src/echoes/Entity.hx index 5fe7f84..95bb82e 100644 --- a/src/echoes/Entity.hx +++ b/src/echoes/Entity.hx @@ -61,7 +61,7 @@ abstract Entity(Int) { * A destroyed entity's ID will go in this pool, and will then be reassigned * to the next entity to be created. */ - private static var idPool:Array = []; + private static final idPool:Array = []; /** * Whether this entity is active. If false, it may also be destroyed. @@ -93,7 +93,7 @@ abstract Entity(Int) { * you'll have to call `activate()`. */ public inline function new(?active:Bool = true) { - var id:Null = idPool.pop(); + final id:Null = idPool.pop(); this = id != null ? id : nextId++; diff --git a/src/echoes/System.hx b/src/echoes/System.hx index 87c36da..693a41d 100644 --- a/src/echoes/System.hx +++ b/src/echoes/System.hx @@ -198,9 +198,9 @@ class System { * Returns a view that will activate and deactivate when the system does. */ public macro function getLinkedView(self:Expr, componentTypes:Array>>):Expr { - var view:Expr = Echoes.getInactiveView(componentTypes); + final view:Expr = Echoes.getInactiveView(componentTypes); return macro { - var self = $self; + final self = $self; self.onActivate.push($view.activate); self.onDeactivate.push($view.deactivate); $view; @@ -227,7 +227,7 @@ private class ChildSystem extends System { private override function __update__(dt:Float):Void { #if echoes_profiling - var __timestamp__ = Date.now().getTime(); + final __timestamp__ = Date.now().getTime(); #end runUpdateListeners(dt); diff --git a/src/echoes/SystemList.hx b/src/echoes/SystemList.hx index 8f48014..7400f87 100644 --- a/src/echoes/SystemList.hx +++ b/src/echoes/SystemList.hx @@ -36,7 +36,7 @@ class SystemList extends System { return clock.paused = value; } - private var systems:Array = []; + private final systems:Array = []; public function new(?name:String = "SystemList", ?clock:Clock, ?priority:Int = 0) { super(priority); @@ -67,7 +67,7 @@ class SystemList extends System { private function __recalculateOrder__(system:System):Void { if(systems.remove(system)) { - var index:Int = Lambda.findIndex(systems, existingSystem -> + final index:Int = Lambda.findIndex(systems, existingSystem -> existingSystem.priority < system.priority); if(index >= 0) { @@ -80,7 +80,7 @@ class SystemList extends System { private override function __update__(dt:Float):Void { #if echoes_profiling - var startTime:Float = haxe.Timer.stamp(); + final startTime:Float = haxe.Timer.stamp(); #end __dt__ = dt; @@ -108,7 +108,7 @@ class SystemList extends System { system.parent.remove(system); } - var index:Int = Lambda.findIndex(systems, existingSystem -> + final index:Int = Lambda.findIndex(systems, existingSystem -> existingSystem.priority < system.priority); if(index >= 0) { @@ -148,7 +148,7 @@ class SystemList extends System { */ public override function find(systemType:Class):Null { for(child in systems) { - var result:Null = child.find(systemType); + final result:Null = child.find(systemType); if(result != null) { return result; @@ -159,7 +159,7 @@ class SystemList extends System { } public override function getStatistics():SystemDetails { - var result:SystemDetails = super.getStatistics(); + final result:SystemDetails = super.getStatistics(); result.children = [for(system in systems) system.getStatistics()]; return result; } diff --git a/src/echoes/macro/ComponentStorageBuilder.hx b/src/echoes/macro/ComponentStorageBuilder.hx index 0a57b27..7c8d3e5 100644 --- a/src/echoes/macro/ComponentStorageBuilder.hx +++ b/src/echoes/macro/ComponentStorageBuilder.hx @@ -14,7 +14,7 @@ using haxe.macro.ComplexTypeTools; class ComponentStorageBuilder { public static inline final PREFIX:String = "ComponentStorage_"; - private static var storageCache:Map = new Map(); + private static final storageCache:Map = new Map(); private static var registered:Bool = false; @@ -25,20 +25,20 @@ class ComponentStorageBuilder { public static function getComponentStorageName(componentComplexType:ComplexType):String { componentComplexType = componentComplexType.followComplexType(); - var error:String = componentComplexType.getReservedComponentMessage(); + final error:String = componentComplexType.getReservedComponentMessage(); if(error != null) { Context.error(error, Context.currentPos()); } - var storageTypeName:String = PREFIX + componentComplexType.toIdentifier(); + final storageTypeName:String = PREFIX + componentComplexType.toIdentifier(); if(storageCache.exists(storageTypeName)) { return storageTypeName; } - var componentTypeName:String = new Printer().printComplexType(componentComplexType); - var storageTypePath:TypePath = { pack: [], name: storageTypeName }; - var storageType:ComplexType = TPath(storageTypePath); - var def:TypeDefinition = macro class $storageTypeName extends echoes.ComponentStorage<$componentComplexType> { + final componentTypeName:String = new Printer().printComplexType(componentComplexType); + final storageTypePath:TypePath = { pack: [], name: storageTypeName }; + final storageType:ComplexType = TPath(storageTypePath); + final def:TypeDefinition = macro class $storageTypeName extends echoes.ComponentStorage<$componentComplexType> { public static final instance:$storageType = new $storageTypePath(); private function new() { diff --git a/src/echoes/macro/EntityTemplateBuilder.hx b/src/echoes/macro/EntityTemplateBuilder.hx index 40d7545..f866419 100644 --- a/src/echoes/macro/EntityTemplateBuilder.hx +++ b/src/echoes/macro/EntityTemplateBuilder.hx @@ -30,7 +30,7 @@ class EntityTemplateBuilder { //===================== //Get information about the `abstract` being built. - var type:AbstractType = switch(Context.getLocalType()) { + final type:AbstractType = switch(Context.getLocalType()) { case TInst(_.get().kind => KAbstractImpl(_.get() => type), _): type; default: @@ -42,7 +42,7 @@ class EntityTemplateBuilder { } //Get information about parent types. - var parents:Array<{ complexType:ComplexType, abstractType:AbstractType }> = []; + final parents:Array<{ complexType:ComplexType, abstractType:AbstractType }> = []; var nextParent:Type = type.type; for(_ in 0...100) { switch(nextParent.follow()) { @@ -87,22 +87,22 @@ class EntityTemplateBuilder { * Contains a temporary `storage` value, which is the identifier for the * `ComponentStorage` for this type. */ - var parameters:Array = []; + final parameters:Array = []; /** * Arguments to pass to `applyTemplateToSelf()`. */ - var arguments:Array = []; + final arguments:Array = []; /** * Arguments to pass to the super type's `applyTemplateToSelf()`. */ - var superArguments:Array = []; + final superArguments:Array = []; /** * The types marked as optional that don't yet have a default value. */ - var optionalValuesRemaining:Map = []; + final optionalValuesRemaining:Map = []; /** * Adds the given value to `parameters` and `arguments` unless it's @@ -117,7 +117,7 @@ class EntityTemplateBuilder { name = n; type = t.followComplexType(); default: - var fieldChain:Null = param.printFieldChain(); + final fieldChain:Null = param.printFieldChain(); if(fieldChain != null) { try { type = fieldChain.getType().followMono().toComplexType(); @@ -132,7 +132,7 @@ class EntityTemplateBuilder { } } - var storage:String = type.getComponentStorageName(); + final storage:String = type.getComponentStorageName(); var existingName:String = null; for(existing in parameters) { if(existing.storage == storage) { @@ -188,8 +188,8 @@ class EntityTemplateBuilder { //Allow converting to all parent types. for(parent in parents) { - var name:String = "to" + parent.abstractType.name; - var parentType:ComplexType = parent.complexType; + final name:String = "to" + parent.abstractType.name; + final parentType:ComplexType = parent.complexType; fields.pushFields(macro class ToParent { /** * Caution: in C++, this converts `null` to `0`. Specifically, @@ -204,7 +204,7 @@ class EntityTemplateBuilder { } //Process the component variables. - var knownComponents:Array = []; + final knownComponents:Array = []; for(field in fields) { if(field.access != null && field.access.contains(AStatic)) { continue; @@ -258,8 +258,8 @@ class EntityTemplateBuilder { //update the metadata to make it match, but since macro order is //unspecified, a child type may have already been built using //the wrong metadata.) - var storage:String = componentType.getComponentStorageName(); - var parameter:FunctionArg = parameters.find(p -> p.storage == storage); + final storage:String = componentType.getComponentStorageName(); + final parameter:FunctionArg = parameters.find(p -> p.storage == storage); if(parameter != null) { if(parameter.opt) { optionalValuesRemaining.remove(storage); @@ -282,8 +282,8 @@ class EntityTemplateBuilder { //Convert the field to a property, and remove the expression. field.kind = FProp("get", "set", macro:Null<$componentType>, null); - var getter:String = "get_" + field.name; - var setter:String = "set_" + field.name; + final getter:String = "get_" + field.name; + final setter:String = "set_" + field.name; fields.pushFields(macro class Accessors { private inline function $getter():Null<$componentType> { @@ -298,9 +298,9 @@ class EntityTemplateBuilder { } if(!optionalValuesRemaining.empty()) { - var missing:Array = [for(type in optionalValuesRemaining) + final missing:Array = [for(type in optionalValuesRemaining) new Printer().printComplexType(type)]; - var s:String = missing.length == 1 ? "" : "s"; + final s:String = missing.length == 1 ? "" : "s"; Context.fatalError('Missing default value$s for the following component type$s: ' + missing.join(", "), Context.currentPos()); @@ -313,7 +313,7 @@ class EntityTemplateBuilder { * An ordered list of parameters taken by the constructor and the * "apply" functions. This version no longer exposes `storage`. */ - var parameters:Array = [for(p in parameters) p]; + final parameters:Array = [for(p in parameters) p]; /** * Adds `parameters` to each function in the given type definition, then @@ -335,7 +335,7 @@ class EntityTemplateBuilder { } //Add the constructor and `applyTemplateTo()`. - var templateType:ComplexType = TPath({ pack: [], name: type.name }); + final templateType:ComplexType = TPath({ pack: [], name: type.name }); addFunctions(macro class Constructor { public static inline function applyTemplateTo(entity:echoes.Entity):$templateType { (cast entity:$templateType).applyTemplateToSelf($a{ arguments }); @@ -353,7 +353,7 @@ class EntityTemplateBuilder { //Prepare the `applyTemplateToSelf()` function. Set the components in //order of priority: values passed by the user, then known values, then //inherited values. - var applyToSelfExprs:Array = []; + final applyToSelfExprs:Array = []; for(parameter in parameters) { applyToSelfExprs.push(macro this.addIfMissing($i{ parameter.name })); } diff --git a/src/echoes/macro/EntityTools.hx b/src/echoes/macro/EntityTools.hx index c9308a1..b532cf0 100644 --- a/src/echoes/macro/EntityTools.hx +++ b/src/echoes/macro/EntityTools.hx @@ -27,12 +27,12 @@ class EntityTools { */ public static function add(self:Expr, components:Array):ExprOf { return macro @:pos(Context.currentPos()) { - var __entity__:echoes.Entity = $self; + final __entity__:echoes.Entity = $self; $b{ [for(component in components) { - var type:Type = component.parseComponentType(); + final type:Type = component.parseComponentType(); - var operation:String = switch(type) { + final operation:String = switch(type) { case TEnum(_.get().meta => m, _), TInst(_.get().meta => m, _), TType(_.get().meta => m, _), @@ -43,7 +43,7 @@ class EntityTools { "add"; }; - var storage:Expr = type.toComplexType().getComponentStorage(); + final storage:Expr = type.toComplexType().getComponentStorage(); macro $storage.$operation(__entity__, $component); }] } @@ -64,12 +64,12 @@ class EntityTools { */ public static function addIfMissing(self:Expr, components:Array):ExprOf { return macro @:pos(Context.currentPos()) { - var __entity__:echoes.Entity = $self; + final __entity__:echoes.Entity = $self; $b{ [for(component in components) { - var type:Type = component.parseComponentType(); + final type:Type = component.parseComponentType(); - var storage:Expr = type.toComplexType().getComponentStorage(); + final storage:Expr = type.toComplexType().getComponentStorage(); macro if(!$storage.exists(__entity__)) $storage.add(__entity__, $component); }] } @@ -85,10 +85,10 @@ class EntityTools { */ public static function remove(self:Expr, types:Array):ExprOf { return macro @:pos(Context.currentPos()) { - var __entity__:echoes.Entity = $self; + final __entity__:echoes.Entity = $self; $b{ [for(type in types) { - var storage:Expr = type.getComponentStorage(); + final storage:Expr = type.getComponentStorage(); macro $storage.remove(__entity__); }] } @@ -103,7 +103,7 @@ class EntityTools { * @return The component, or `null` if the entity doesn't have it. */ public static function get(self:Expr, complexType:ComplexType):ExprOf { - var storage:Expr = complexType.getComponentStorage(); + final storage:Expr = complexType.getComponentStorage(); return macro @:pos(Context.currentPos()) $storage.get($self); } @@ -112,7 +112,7 @@ class EntityTools { * @param type The type to check for. */ public static function exists(self:Expr, complexType:ComplexType):ExprOf { - var storage:Expr = complexType.getComponentStorage(); + final storage:Expr = complexType.getComponentStorage(); return macro @:pos(Context.currentPos()) $storage.exists($self); } } diff --git a/src/echoes/macro/MacroTools.hx b/src/echoes/macro/MacroTools.hx index 6322f32..11d7e2a 100644 --- a/src/echoes/macro/MacroTools.hx +++ b/src/echoes/macro/MacroTools.hx @@ -62,13 +62,13 @@ class MacroTools { case FFun(func): switch(func.expr) { case null: - var block:Array = []; + final block:Array = []; func.expr = macro @:pos(field.pos) $b{ block }; return block; case _.expr => EBlock(exprs): return exprs; case expr: - var block:Array = [expr]; + final block:Array = [expr]; func.expr.expr = EBlock(block); return block; } @@ -102,13 +102,13 @@ class MacroTools { } public static function joinNames(types:Array, sep:String, ?qualify:Bool = true):String { - var typeNames:Array = [for(type in types) toIdentifier(type, qualify)]; + final typeNames:Array = [for(type in types) toIdentifier(type, qualify)]; typeNames.sort(compareStrings); return typeNames.join(sep); } public static function makeTypePath(parts:Array):TypePath { - var typePath:TypePath = { + final typePath:TypePath = { pack: parts, name: parts.pop() }; @@ -133,7 +133,7 @@ class MacroTools { default: } - var fieldChain:Null = printFieldChain(e); + final fieldChain:Null = printFieldChain(e); if(fieldChain != null) { try { return followMono(fieldChain.getType()).toComplexType(); @@ -146,7 +146,7 @@ class MacroTools { } catch(err:Exception) { } } - var expr:String = new Printer().printExpr(e); + final expr:String = new Printer().printExpr(e); if(~/^[\w\d\.]+$/.match(expr)) { Context.error('Type not found: `$expr`.', e.pos); } else { @@ -191,7 +191,7 @@ class MacroTools { public static function printFieldChain(fieldExpr:Expr):Null { switch(fieldExpr.expr) { case EField(e, field): - var sub:Null = printFieldChain(e); + final sub:Null = printFieldChain(e); return sub != null ? '$sub.$field' : null; case EConst(CIdent(s)): return s; diff --git a/src/echoes/macro/Report.hx b/src/echoes/macro/Report.hx index 68a15f7..4bab59d 100644 --- a/src/echoes/macro/Report.hx +++ b/src/echoes/macro/Report.hx @@ -14,10 +14,10 @@ import haxe.macro.Type; */ class Report { @:allow(echoes.macro.ComponentStorageBuilder) - private static var componentNames:Array = []; + private static final componentNames:Array = []; @:allow(echoes.macro.ViewBuilder) - private static var viewNames:Array = []; + private static final viewNames:Array = []; private static var registered = false; diff --git a/src/echoes/macro/SystemBuilder.hx b/src/echoes/macro/SystemBuilder.hx index 2c74994..3d8e0d2 100644 --- a/src/echoes/macro/SystemBuilder.hx +++ b/src/echoes/macro/SystemBuilder.hx @@ -71,7 +71,7 @@ class SystemBuilder { } private static function getPriority(meta:Metadata):Null { - var entry:MetadataEntry = getMeta(meta, PRIORITY_META); + final entry:MetadataEntry = getMeta(meta, PRIORITY_META); switch(entry) { case null: case _.params => [_.expr => EConst(CInt(v))]: @@ -93,7 +93,7 @@ class SystemBuilder { var substitutions:TypeSubstitutions = null; var nameWithParams:String; - var classType:ClassType = switch(Context.getLocalType()) { + final classType:ClassType = switch(Context.getLocalType()) { case TInst(_.get() => inst, types): nameWithParams = inst.name; @@ -114,7 +114,7 @@ class SystemBuilder { /** * `classType`, plus all superclasses in order, including `System`. */ - var parentTypes:Array = [classType]; + final parentTypes:Array = [classType]; { var parentType:ClassType = classType; while(parentType.superClass != null) { @@ -157,19 +157,19 @@ class SystemBuilder { /** * Names of views that should activate and deactivate with the system. */ - var linkedViews:Array = []; + final linkedViews:Array = []; //Variable initializers can't actually call `getLinkedView()`, so locate //and replace such calls. for(field in fields) { - var expr:Expr = switch(field.kind) { + final expr:Expr = switch(field.kind) { case FVar(_, expr), FProp(_, _, _, expr) if(expr != null): expr; default: continue; }; - var params:Array = switch(expr.expr) { + final params:Array = switch(expr.expr) { case ECall(_.expr => EConst(CIdent("getLinkedView")) | EField(_, "getLinkedView"), params): params; default: @@ -179,7 +179,7 @@ class SystemBuilder { //Get the inactive view for now. expr.expr = Echoes.getInactiveView(params).expr; - var viewName:String = switch(expr.expr) { + final viewName:String = switch(expr.expr) { case EField(_.expr => EConst(CIdent(name)), "instance"): name; default: @@ -195,9 +195,9 @@ class SystemBuilder { //Listener function priorities //============================ - var updateListeners:Array = fields.map(ListenerFunction.fromField.bind(_, UPDATE_META)).filter(notNull); - var addListeners:Array = fields.map(ListenerFunction.fromField.bind(_, ADD_META)).filter(notNull); - var removeListeners:Array = fields.map(ListenerFunction.fromField.bind(_, REMOVE_META)).filter(notNull); + final updateListeners:Array = fields.map(ListenerFunction.fromField.bind(_, UPDATE_META)).filter(notNull); + final addListeners:Array = fields.map(ListenerFunction.fromField.bind(_, ADD_META)).filter(notNull); + final removeListeners:Array = fields.map(ListenerFunction.fromField.bind(_, REMOVE_META)).filter(notNull); for(listener in addListeners.concat(removeListeners)) { if(listener.wrapperFunction == null) { Context.error("An @:add or @:remove listener must take at least one component. (Optional arguments don't count.)", listener.pos); @@ -208,7 +208,7 @@ class SystemBuilder { * Update listeners that have `@:priority` tags. Each group of these * will be used to create a `ChildSystem`. */ - var fixedPriorityUpdateListeners:Map> = new Map(); + final fixedPriorityUpdateListeners:Map> = new Map(); for(listener in updateListeners) { if(listener.priority != null) { if(!fixedPriorityUpdateListeners.exists(listener.priority)) { @@ -219,7 +219,7 @@ class SystemBuilder { } } - var defaultPriority:Null = getPriority(classType.meta.get()); + final defaultPriority:Null = getPriority(classType.meta.get()); if(defaultPriority != null) { fields.pushFields(macro class DefaultPriority { private override function __getDefaultPriority__():Int { @@ -231,8 +231,8 @@ class SystemBuilder { //Constructor //=========== - var initializeChildren:Array = [for(priority => listeners in fixedPriorityUpdateListeners) { - var body:Array = [for(listener in listeners) listener.callDuringUpdate()]; + final initializeChildren:Array = [for(priority => listeners in fixedPriorityUpdateListeners) { + final body:Array = [for(listener in listeners) listener.callDuringUpdate()]; body.unshift(macro __dt__ = dt); macro __addListenersWithPriority__($v{ priority }, function(dt:Float) $b{ body }); @@ -291,7 +291,7 @@ class SystemBuilder { }); //Add lifecycle functions no matter what. - var requiredFields:TypeDefinition = macro class RequiredFields { + final requiredFields:TypeDefinition = macro class RequiredFields { private override function __activate__():Void { if(!active) { $b{ [for(view in linkedViews) macro $i{ view }.instance.activate()] } @@ -319,7 +319,7 @@ class SystemBuilder { private override function __update__(dt:Float):Void { #if echoes_profiling - var __timestamp__ = Date.now().getTime(); + final __timestamp__ = Date.now().getTime(); #end ${ if(parentTypes.length <= 2) { @@ -374,7 +374,7 @@ class SystemBuilder { return Context.fatalError("SystemBuilder only acts on classes.", Context.currentPos()); } - var qualifiedName:String = classType.pack.concat([name]).join("."); + final qualifiedName:String = classType.pack.concat([name]).join("."); if(genericSystemCache.exists(qualifiedName)) { return genericSystemCache[qualifiedName]; } @@ -383,9 +383,9 @@ class SystemBuilder { return Context.fatalError(classType.name + " must extend System.", Context.currentPos()); } - var superClass:ClassType = classType.superClass.t.get(); - var superClassModule:String = superClass.module.split(".").pop(); - var importsAndUsings:{ imports: Array, usings: Array } + final superClass:ClassType = classType.superClass.t.get(); + final superClassModule:String = superClass.module.split(".").pop(); + final importsAndUsings:{ imports: Array, usings: Array } = TypeSubstitutions.getCachedImports(classType); Context.defineModule(qualifiedName, [{ @@ -405,7 +405,7 @@ class SystemBuilder { }] }], importsAndUsings.imports, importsAndUsings.usings); - var type:ComplexType = TPath({ + final type:ComplexType = TPath({ pack: classType.pack, name: name }); @@ -524,7 +524,7 @@ abstract ListenerFunction(ListenerFunctionData) from ListenerFunctionData { } //The arguments used in the wrapper function signature. - var args:Array = + final args:Array = //The view always passes an `Entity` as the first argument. [{ name: "entity", type: macro:echoes.Entity }] //The remaining arguments must also be in the view's order. @@ -560,7 +560,7 @@ abstract ListenerFunction(ListenerFunctionData) from ListenerFunctionData { * these values are available in the current context. */ private function call():Expr { - var args:Array = [for(arg in this.args) { + final args:Array = [for(arg in this.args) { switch(arg.type.followComplexType()) { case macro:StdTypes.Float: //Defined as a private variable of `System`. diff --git a/src/echoes/macro/TypeSubstitutions.hx b/src/echoes/macro/TypeSubstitutions.hx index d6882bb..5af162e 100644 --- a/src/echoes/macro/TypeSubstitutions.hx +++ b/src/echoes/macro/TypeSubstitutions.hx @@ -69,7 +69,7 @@ class TypeSubstitutions { } public static inline function getCachedImports(classType:ClassType):CachedImports { - var qualifiedClassName:String = classType.pack.join(".") + "." + classType.name; + final qualifiedClassName:String = classType.pack.join(".") + "." + classType.name; return cache[qualifiedClassName]; } @@ -99,7 +99,7 @@ class TypeSubstitutions { final params:Array = classType.params; - var codeCompletionMode:Bool = types == null; + final codeCompletionMode:Bool = types == null; if(codeCompletionMode) { //Replace each param with its constraint type. If multiple //constraints are specified, pick one. @@ -116,11 +116,11 @@ class TypeSubstitutions { applyDefaultTypeParams(classType, types); for(i => param in params) { - var type:ComplexType = types[i].followMono().toComplexType(); + final type:ComplexType = types[i].followMono().toComplexType(); addSubstitution(param.name, type); //Check for `Entity` and `Float`. - var error:String = type.getReservedComponentMessage(); + final error:String = type.getReservedComponentMessage(); if(error != null && !codeCompletionMode) { Context.error('$className.${ param.name }: ' + error, Context.currentPos()); } @@ -128,13 +128,13 @@ class TypeSubstitutions { //Local imports and usings become inaccessible during a generic build, //so save them for future reference. - var qualifiedClassName:String = classType.pack.join(".") + "." + className; + final qualifiedClassName:String = classType.pack.join(".") + "." + className; if(!cache.exists(qualifiedClassName) && Context.getLocalModule() == classType.module) { cache[qualifiedClassName] = { imports: Context.getLocalImports(), usings: [for(u in Context.getLocalUsing()) if(u != null) { - var usingType:ClassType = u.get(); - var parts:Array = usingType.module.split("."); + final usingType:ClassType = u.get(); + final parts:Array = usingType.module.split("."); if(parts[parts.length - 1] != usingType.name) { parts.push(usingType.name); } @@ -171,7 +171,7 @@ class TypeSubstitutions { if(!substitutions.exists(identifier)) { substitutions[identifier] = type; - var printedType:String = new Printer().printComplexType(type); + final printedType:String = new Printer().printComplexType(type); if(printedType.indexOf("<") < 0) { substitutionExprs[identifier] = printedType.parse(Context.currentPos()).expr; } @@ -291,7 +291,7 @@ class TypeSubstitutions { return switch(type) { case TPath(p): - var p:TypePath = substituteTypePath(p); + final p:TypePath = substituteTypePath(p); if(p.isResolvable()) { TPath(p).toType().toComplexType(); } else { @@ -330,7 +330,7 @@ class TypeSubstitutions { } public function substituteTypePath(typePath:TypePath):TypePath { - var substitute:Bool = switch(typePath) { + final substitute:Bool = switch(typePath) { case { pack: [], name: name, sub: null }: true; case { pack: [module], name: name, sub: null }, diff --git a/src/echoes/macro/ViewBuilder.hx b/src/echoes/macro/ViewBuilder.hx index ec0915d..6977aa2 100644 --- a/src/echoes/macro/ViewBuilder.hx +++ b/src/echoes/macro/ViewBuilder.hx @@ -14,7 +14,7 @@ using haxe.macro.Context; using Lambda; class ViewBuilder { - private static var viewCache:Map, type:Type }> = new Map(); + private static final viewCache:Map, type:Type }> = new Map(); public static inline function isView(name:String):Bool { return viewCache.exists(name); @@ -25,7 +25,7 @@ class ViewBuilder { * hasn't been defined, the given order will become canonical.) */ public static function getComponentOrder(components:Array):Array { - var name:String = getViewName(components); + final name:String = getViewName(components); if(!viewCache.exists(name)) { createViewType(components); } @@ -44,11 +44,11 @@ class ViewBuilder { */ public static function getViewName(components:Array):String { //Use the fully-qualified component names to generate a unique hash. - var md5:String = "_" + Md5.encode(components.joinNames("_")).substr(0, 5); + final md5:String = "_" + Md5.encode(components.joinNames("_")).substr(0, 5); //Use the unqualified component names for the final result, as they're //easier to read. Include part of the hash to avoid collisions. - var name:String = "ViewOf_" + components.joinNames("_", false) + md5; + final name:String = "ViewOf_" + components.joinNames("_", false) + md5; if(Context.defined("cpp")) { var maxLength:Null = null; @@ -77,14 +77,14 @@ class ViewBuilder { } public static function createViewType(components:Array):Type { - var viewClassName:String = getViewName(components); + final viewClassName:String = getViewName(components); if(viewCache.exists(viewClassName)) { return viewCache[viewClassName].type; } - var viewTypePath:TypePath = { pack: [], name: viewClassName }; - var viewComplexType:ComplexType = TPath(viewTypePath); + final viewTypePath:TypePath = { pack: [], name: viewClassName }; + final viewComplexType:ComplexType = TPath(viewTypePath); /** * The function signature for any event listeners attached to this view. @@ -92,7 +92,7 @@ class ViewBuilder { * `View`, listeners would need to have the signature * `(Entity, Hue, Saturation) -> Void`. */ - var callbackType:ComplexType = TFunction([macro:echoes.Entity].concat(components), macro:Void); + final callbackType:ComplexType = TFunction([macro:echoes.Entity].concat(components), macro:Void); /** * The arguments required to dispatch an add or update event. In a @@ -103,7 +103,7 @@ class ViewBuilder { * SaturationContainer.instance.get(entity)); * ``` */ - var callbackArgs:Array = [for(component in components) + final callbackArgs:Array = [for(component in components) macro ${ component.getComponentStorage() }.get(entity)]; /** @@ -126,8 +126,8 @@ class ViewBuilder { * may sound inefficient, in practice many (if not most) views will only * run the loop for 0-1 iterations. */ - var removedCallbackArgs:Array = [for(component in components) { - var inst:Expr = macro ${ component.getComponentStorage() }; + final removedCallbackArgs:Array = [for(component in components) { + final inst:Expr = macro ${ component.getComponentStorage() }; macro $inst == removedComponentStorage ? removedComponent : $inst.get(entity); }]; @@ -135,11 +135,11 @@ class ViewBuilder { callbackArgs.unshift(macro entity); removedCallbackArgs.unshift(macro entity); - var def:TypeDefinition = macro class $viewClassName extends echoes.View.ViewBase { + final def:TypeDefinition = macro class $viewClassName extends echoes.View.ViewBase { public static final instance:$viewComplexType = new $viewTypePath(); - public var onAdded(default, null) = new echoes.utils.Signal<$callbackType>(); - public var onRemoved(default, null) = new echoes.utils.Signal<$callbackType>(); + public final onAdded = new echoes.utils.Signal<$callbackType>(); + public final onRemoved = new echoes.utils.Signal<$callbackType>(); private function new() { } @@ -150,7 +150,7 @@ class ViewBuilder { if(activations == 1) $b{ //Each expression adds this `View` to a related list. [for(component in components) { - var storage:Expr = component.getComponentStorage(); + final storage:Expr = component.getComponentStorage(); macro $storage._relatedViews.push(this); }] } @@ -198,7 +198,7 @@ class ViewBuilder { $b{ //Each expression removes this `View` from a related list. [for(component in components) { - var storage:Expr = component.getComponentStorage(); + final storage:Expr = component.getComponentStorage(); macro ${ storage }._relatedViews.remove(this); }] } @@ -218,7 +218,7 @@ class ViewBuilder { //instance, in a `View`, the two checks //would be `HueContainer.instance.exists(entity)` and //`SaturationContainer.instance.exists(entity)`. - var checks:Array = [for(component in components) + final checks:Array = [for(component in components) macro ${ component.getComponentStorage() }.exists(entity)]; //The checks are joined by `&&` operators. checks.fold((a, b) -> macro $a && $b, checks.shift()); @@ -237,7 +237,7 @@ class ViewBuilder { Context.defineType(def); - var viewType:Type = viewComplexType.toType(); + final viewType:Type = viewComplexType.toType(); viewCache.set(viewClassName, { cls: viewComplexType, components: components, type: viewType }); Report.viewNames.push(viewClassName); diff --git a/src/echoes/utils/Clock.hx b/src/echoes/utils/Clock.hx index f7b8197..32e9ef3 100644 --- a/src/echoes/utils/Clock.hx +++ b/src/echoes/utils/Clock.hx @@ -105,7 +105,7 @@ class Clock { } public function next():Float { - var tick:Float = time > maxTickLength ? maxTickLength : time; + final tick:Float = time > maxTickLength ? maxTickLength : time; time -= tick; tickCount++; return tick; diff --git a/test/AdvancedFunctionalityTest.hx b/test/AdvancedFunctionalityTest.hx index c4633a3..994606c 100644 --- a/test/AdvancedFunctionalityTest.hx +++ b/test/AdvancedFunctionalityTest.hx @@ -31,7 +31,7 @@ class AdvancedFunctionalityTest extends Test { //Tests may be run in any order, but not in parallel. private function testComponentTypes():Void { - var types:ComponentTypes = new ComponentTypes(); + final types:ComponentTypes = new ComponentTypes(); types.add(Bool); types.add(Bool); Assert.equals(1, types.length); @@ -54,10 +54,10 @@ class AdvancedFunctionalityTest extends Test { new NameSystem().activate(); new AppearanceSystem().activate(); - var entity:Entity = new Entity(); + final entity:Entity = new Entity(); entity.add(("John":Name)); - var namedEntity:NamedEntity = NamedEntity.applyTemplateTo(entity); + final namedEntity:NamedEntity = NamedEntity.applyTemplateTo(entity); Assert.equals(entity, namedEntity); Assert.equals("John", namedEntity.name); assertTimesCalled(1, "NameSystem.nameAdded"); @@ -68,7 +68,7 @@ class AdvancedFunctionalityTest extends Test { assertTimesCalled(1, "NameSystem.nameAdded"); assertTimesCalled(1, "NameSystem.nameRemoved"); - var visualEntity:VisualEntity = VisualEntity.applyTemplateTo(namedEntity); + final visualEntity:VisualEntity = VisualEntity.applyTemplateTo(namedEntity); Assert.equals(VisualEntity.DEFAULT_COLOR, visualEntity.color); assertTimesCalled(1, "AppearanceSystem.colorAdded"); assertTimesCalled(0, "AppearanceSystem.colorRemoved"); @@ -84,7 +84,7 @@ class AdvancedFunctionalityTest extends Test { assertTimesCalled(4, "NameSystem.nameAdded"); assertTimesCalled(1, "NameSystem.nameRemoved"); - var nullEntity:Null = null; + final nullEntity:Null = null; Assert.isNull(nullEntity); #if cpp Assert.notNull((nullEntity:Null), "C++ code generation has improved, and a warning can be removed from EntityTemplateBuilder."); @@ -94,10 +94,10 @@ class AdvancedFunctionalityTest extends Test { } private function testFindSystem():Void { - var parent:SystemList = new SystemList(); - var child:SystemList = new SystemList(); - var name:NameSystem = new NameSystem(); - var appearance:AppearanceSystem = new AppearanceSystem(); + final parent:SystemList = new SystemList(); + final child:SystemList = new SystemList(); + final name:NameSystem = new NameSystem(); + final appearance:AppearanceSystem = new AppearanceSystem(); parent.add(child); parent.add(name); @@ -111,10 +111,10 @@ class AdvancedFunctionalityTest extends Test { } private function testGenerics():Void { - var system:GenericSystem = new GenericSystem(); + final system:GenericSystem = new GenericSystem(); system.activate(); - var entity:Entity = new Entity(); + final entity:Entity = new Entity(); entity.add("STRING"); entity.add(0); switch(system.record) { @@ -132,7 +132,7 @@ class AdvancedFunctionalityTest extends Test { Assert.fail("Incorrect record: " + system.record); } - var system = new GenericSystem, String>(); + final system = new GenericSystem, String>(); system.activate(); entity.add(("NAME":Alias)); @@ -152,7 +152,7 @@ class AdvancedFunctionalityTest extends Test { Assert.equals("Array", Echoes.getComponentStorage((_:Array)).componentType); Assert.equals("ComponentStorage", Std.string(Echoes.getComponentStorage(Bool))); - var entity:Entity = new Entity(); + final entity:Entity = new Entity(); entity.add(["xyz"]); switch(Echoes.getComponentStorage((_:Array)).get(entity)) { case ["xyz"]: @@ -164,7 +164,7 @@ class AdvancedFunctionalityTest extends Test { @:access(echoes.System) private function testPriority():Void { - var list:SystemList = new SystemList(); + final list:SystemList = new SystemList(); inline function assertListContents(contents:Array, ?pos:PosInfos):Void { if(Assert.equals(contents.length, list.length, @@ -179,9 +179,9 @@ class AdvancedFunctionalityTest extends Test { } //Add systems from low to high priority. - var high:HighPrioritySystem = new HighPrioritySystem(); - var middle:NameSystem = new NameSystem(); - var low:NameSystem = new NameSystem(-1); + final high:HighPrioritySystem = new HighPrioritySystem(); + final middle:NameSystem = new NameSystem(); + final low:NameSystem = new NameSystem(-1); list.add(low); list.add(middle); @@ -189,7 +189,7 @@ class AdvancedFunctionalityTest extends Test { assertListContents([high, middle, low]); //Next, add a system with children. - var parent:UpdateOrderSystem = new UpdateOrderSystem(); + final parent:UpdateOrderSystem = new UpdateOrderSystem(); Assert.equals(0, parent.priority); Assert.equals(1, parent.__children__[0].priority); Assert.equals(-1, parent.__children__[1].priority); @@ -201,7 +201,7 @@ class AdvancedFunctionalityTest extends Test { low, parent.__children__[1] //-1 ]); - var updateOrder:Array = []; + final updateOrder:Array = []; new Entity(true).add(updateOrder); list.__activate__(); list.__update__(1); @@ -245,7 +245,7 @@ class AdvancedFunctionalityTest extends Test { Assert.isTrue(Reflect.compareMethods(listener2, listener2)); //Make a signal. - var signal:Signal<()->Void> = new Signal(); + final signal:Signal<()->Void> = new Signal(); signal.push(listener1); Assert.isTrue(signal.contains(listener1)); @@ -268,7 +268,7 @@ class AdvancedFunctionalityTest extends Test { } private function testTypeParameters():Void { - var entity:Entity = new Entity(); + final entity:Entity = new Entity(); entity.add([1, 2, 3]); Assert.isFalse(entity.exists(IntArray)); //Regular typedef @@ -278,18 +278,18 @@ class AdvancedFunctionalityTest extends Test { private function testViews():Void { //Make several entities with varying components. - var name:Entity = new Entity().add(("name1":Name)); - var shape:Entity = new Entity().add(CIRCLE); - var colorName:Entity = new Entity().add((0x00FF00:Color), ("name2":Name)); - var colorShape:Entity = new Entity().add((0xFFFFFF:Color), STAR); + final name:Entity = new Entity().add(("name1":Name)); + final shape:Entity = new Entity().add(CIRCLE); + final colorName:Entity = new Entity().add((0x00FF00:Color), ("name2":Name)); + final colorShape:Entity = new Entity().add((0xFFFFFF:Color), STAR); //Make some views; each should see a different selection of entities. - var viewOfName:View = Echoes.getView(Name); + final viewOfName:View = Echoes.getView(Name); Assert.equals(2, viewOfName.entities.length); Assert.isTrue(viewOfName.entities.contains(name)); Assert.isTrue(viewOfName.entities.contains(colorName)); - var viewOfShape:View = Echoes.getView(Shape); + final viewOfShape:View = Echoes.getView(Shape); Assert.equals(2, viewOfShape.entities.length); Assert.isTrue(viewOfShape.entities.contains(shape)); Assert.isTrue(viewOfShape.entities.contains(colorShape)); @@ -305,8 +305,8 @@ class AdvancedFunctionalityTest extends Test { Assert.isFalse(viewOfName.entities.contains(colorName)); //Make a view that's linked to a system. - var nameSystem:NameSystem = new NameSystem(); - var viewOfColor:View = nameSystem.getLinkedView(Color); + final nameSystem:NameSystem = new NameSystem(); + final viewOfColor:View = nameSystem.getLinkedView(Color); Assert.isFalse(viewOfColor.active); Assert.equals(0, viewOfColor.entities.length); @@ -323,9 +323,9 @@ class AdvancedFunctionalityTest extends Test { } private function testViewSignals():Void { - var entity:Entity = new Entity(); + final entity:Entity = new Entity(); - var viewOfShape:View = Echoes.getView(Shape); + final viewOfShape:View = Echoes.getView(Shape); var signalDispatched:Bool = false; function listener(e:Entity, s:Shape):Void { diff --git a/test/BasicFunctionalityTest.hx b/test/BasicFunctionalityTest.hx index b3624e7..59b04d0 100644 --- a/test/BasicFunctionalityTest.hx +++ b/test/BasicFunctionalityTest.hx @@ -24,7 +24,7 @@ class BasicFunctionalityTest extends Test { //If this fails on any target, update `ComponentStorage.clear()`, then skip //this test on that target. private function testArrayBehavior():Void { - var array:Array> = [for(i in 0...5) i]; + final array:Array> = [for(i in 0...5) i]; Assert.equals(2, array[2]); Assert.isNull(array[6]); @@ -41,7 +41,7 @@ class BasicFunctionalityTest extends Test { private function testEntities():Void { //Make an inactive entity. - var entity:Entity = new Entity(false); + final entity:Entity = new Entity(false); Assert.isFalse(entity.active); Assert.equals(0, Echoes.activeEntities.length); Assert.equals(0, entity.id); @@ -74,7 +74,7 @@ class BasicFunctionalityTest extends Test { Assert.equals(1, @:privateAccess Entity.idPool.length); //Make a new entity (should use the same ID as the old). - var newEntity:Entity = new Entity(); + final newEntity:Entity = new Entity(); Assert.equals(entity, newEntity); Assert.equals(0, @:privateAccess Entity.idPool.length); Assert.equals(0, newEntity.id); @@ -82,15 +82,15 @@ class BasicFunctionalityTest extends Test { private function testComponents():Void { //Create the entity. - var blackSquare:Entity = new Entity(); + final blackSquare:Entity = new Entity(); Assert.isTrue(blackSquare.active); Assert.equals(0, Lambda.count(blackSquare.getComponents())); //Create some interchangeable components. - var black:Color = 0x000000; - var nearBlack:Color = 0x111111; - var name:Name = "blackSquare"; - var shortName:Name = "blSq"; + final black:Color = 0x000000; + final nearBlack:Color = 0x111111; + final name:Name = "blackSquare"; + final shortName:Name = "blSq"; //Add components. blackSquare.add(black); @@ -133,7 +133,7 @@ class BasicFunctionalityTest extends Test { } private function testInactiveEntities():Void { - var inactive:Entity = new Entity(false); + final inactive:Entity = new Entity(false); Assert.isFalse(inactive.active); Assert.equals(0, Echoes.activeEntities.length); @@ -156,7 +156,7 @@ class BasicFunctionalityTest extends Test { private function testAddAndRemoveEvents():Void { //Add a system. - var appearanceSystem:AppearanceSystem = new AppearanceSystem(); + final appearanceSystem:AppearanceSystem = new AppearanceSystem(); Assert.equals(0, Echoes.activeSystems.length); appearanceSystem.activate(); @@ -166,7 +166,7 @@ class BasicFunctionalityTest extends Test { //Add a red line. Assert.equals(0, Echoes.activeEntities.length); - var redLine:Entity = new Entity(); + final redLine:Entity = new Entity(); Assert.equals(1, Echoes.activeEntities.length); redLine.add((0xFF0000:Color), Shape.LINE); @@ -175,7 +175,7 @@ class BasicFunctionalityTest extends Test { assertTimesCalled(0, "AppearanceSystem.colorAndShapeRemoved"); //Add a circle. - var circle:Entity = new Entity(); + final circle:Entity = new Entity(); Assert.equals(2, Echoes.activeEntities.length); circle.add(CIRCLE); @@ -188,7 +188,7 @@ class BasicFunctionalityTest extends Test { circle.add(("circle":Name)); assertTimesCalled(0, "NameSystem.nameAdded", "NameSystem doesn't exist but its method was still called."); - var nameSystem:NameSystem = new NameSystem(); + final nameSystem:NameSystem = new NameSystem(); redLine.add(("redLine":Name)); assertTimesCalled(0, "NameSystem.nameAdded", "NameSystem isn't active but its method was still called."); @@ -237,19 +237,19 @@ class BasicFunctionalityTest extends Test { @:access(echoes.Echoes.lastUpdate) private function testUpdateEvents():Void { //Create a `TimeCountSystem` and use a custom `Clock`. - var systems:SystemList = new SystemList(new OneSecondClock()); + final systems:SystemList = new SystemList(new OneSecondClock()); systems.activate(); - var timeCountSystem:TimeCountSystem = new TimeCountSystem(); + final timeCountSystem:TimeCountSystem = new TimeCountSystem(); Assert.equals(0.0, timeCountSystem.totalTime); systems.add(timeCountSystem); //Create some entities, but none with both color and shape. - var green:Entity = new Entity().add((0x00FF00:Color)); + final green:Entity = new Entity().add((0x00FF00:Color)); Assert.equals(0.0, timeCountSystem.colorTime); - var star:Entity = new Entity().add(STAR, ("Proxima Centauri":Name)); + final star:Entity = new Entity().add(STAR, ("Proxima Centauri":Name)); Assert.equals(0.0, timeCountSystem.shapeTime); Assert.isNull(star.get(Color), star.get(Color) + " should be null. See ComponentStorage constructor for details."); diff --git a/test/EdgeCaseTest.hx b/test/EdgeCaseTest.hx index 6a3b9c4..b9fe5ed 100644 --- a/test/EdgeCaseTest.hx +++ b/test/EdgeCaseTest.hx @@ -25,7 +25,7 @@ class EdgeCaseTest extends Test { private function testChildSystems():Void { new NameSubsystem().activate(); - var entity:Entity = new Entity(); + final entity:Entity = new Entity(); entity.add(("Name":Name)); assertTimesCalled(0, "NameSystem.nameAdded"); assertTimesCalled(1, "NameSubsystem.nameAdded"); @@ -47,7 +47,7 @@ class EdgeCaseTest extends Test { private function testComponentsExist():Void { new ComponentsExistSystem().activate(); - var entity:Entity = new Entity(); + final entity:Entity = new Entity(); entity.add(("name":Name)); entity.add((0xFFFFFF:Color)); entity.remove(Color); @@ -75,10 +75,10 @@ class EdgeCaseTest extends Test { } } - var a:Entity = new Entity(); - var b:Entity = new Entity(); - var c:Entity = new Entity(); - var d:Entity = new Entity(); + final a:Entity = new Entity(); + final b:Entity = new Entity(); + final c:Entity = new Entity(); + final d:Entity = new Entity(); #if echoes_stable_order @@ -124,7 +124,7 @@ class EdgeCaseTest extends Test { } private function testNullComponents():Void { - var entity:Entity = new Entity(); + final entity:Entity = new Entity(); entity.add("Hello world."); Assert.isTrue(entity.exists(String)); @@ -138,7 +138,7 @@ class EdgeCaseTest extends Test { private function testRedundantOperations():Void { new AppearanceSystem().activate(); - var entity:Entity = new Entity(false); + final entity:Entity = new Entity(false); //Deactivate an inactive entity. Assert.isFalse(entity.active); @@ -186,7 +186,7 @@ class EdgeCaseTest extends Test { } private function testRecursiveEvents():Void { - var entity:Entity = new Entity(); + final entity:Entity = new Entity(); //Activate the system first so that it can process events first. new RecursiveEventSystem().activate(); @@ -253,9 +253,9 @@ class EdgeCaseTest extends Test { } private function testSystemLists():Void { - var list0:SystemList = new SystemList(); - var list1:SystemList = new SystemList(); - var system:NameSystem = new NameSystem(); + final list0:SystemList = new SystemList(); + final list1:SystemList = new SystemList(); + final system:NameSystem = new NameSystem(); list0.add(system); Assert.equals(list0, system.parent); @@ -267,8 +267,8 @@ class EdgeCaseTest extends Test { } private function testTypeParsing():Void { - var entity:Entity = new Entity(); - var infos:PosInfos = ((?infos:PosInfos) -> infos)(); + final entity:Entity = new Entity(); + final infos:PosInfos = ((?infos:PosInfos) -> infos)(); entity.add(infos); Assert.equals(infos, entity.get(PosInfos)); diff --git a/test/MethodCounter.hx b/test/MethodCounter.hx index b026f82..4b52447 100644 --- a/test/MethodCounter.hx +++ b/test/MethodCounter.hx @@ -13,7 +13,7 @@ using echoes.macro.MacroTools; * `assertTimesCalled()`. */ class MethodCounter { - private static var counts:Map = new Map(); + private static final counts:Map = new Map(); /** * Resets all counters. @@ -31,20 +31,20 @@ class MethodCounter { * a `String` error. */ public static function assertTimesCalled(count:Int, method:String, ?message:String, ?debugErrors:Bool = false, ?pos:PosInfos):Void { - var actualCount:Int = counts.exists(method) ? counts[method] : 0; + final actualCount:Int = counts.exists(method) ? counts[method] : 0; if(message == null) { message = '$method expected $count ' + (count == 1 ? "time" : "times") + ', but was called $actualCount ' + (actualCount == 1 ? "time." : "times."); } - var result:Bool = Assert.equals(count, actualCount, message, pos); + final result:Bool = Assert.equals(count, actualCount, message, pos); if(!result && debugErrors) { - var methodClass:String = method.substr(0, method.indexOf(".") + 1); + final methodClass:String = method.substr(0, method.indexOf(".") + 1); if(methodClass.length == 0) { throw 'The given method string ($method) has the wrong format.'; } - var knownMethods:Array = []; + final knownMethods:Array = []; for(key in counts.keys()) { if(StringTools.startsWith(key, methodClass)) { knownMethods.push(key.substr(methodClass.length)); @@ -68,14 +68,14 @@ class MethodCounter { } @:noCompletion public static macro function build():Array { - var fields:Array = Context.getBuildFields(); + final fields:Array = Context.getBuildFields(); - var className:String = Context.getLocalClass().get().name; + final className:String = Context.getLocalClass().get().name; for(field in fields) { - var body:Null> = field.getFunctionBody(); + final body:Null> = field.getFunctionBody(); if(body != null) { - var key:String = '$className.${ field.name }'; + final key:String = '$className.${ field.name }'; body.unshift(macro MethodCounter.count($v{ key })); } }