Skip to content

Commit

Permalink
fixed field rename with null-safe access
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHaxe committed Dec 22, 2024
1 parent 26d5f47 commit e739240
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/refactor/rename/RenameField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class RenameField {
static function replaceInTypeWithFieldAccess(changelist:Changelist, type:Type, prefix:String, from:String, to:String) {
var allUses:Array<Identifier> = type.getIdentifiers(prefix + from);
var allAccess:Array<Identifier> = type.getStartsWith('$prefix$from.');
allAccess = allAccess.concat(type.getStartsWith('$prefix$from?.'));
var shadowed:Bool = false;
for (access in allAccess) {
for (use in allUses) {
Expand Down
13 changes: 13 additions & 0 deletions test/refactor/rename/RenameClassTest.hx
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,17 @@ class RenameClassTest extends RenameTestBase {

checkRename({fileName: "testcases/classes/DocModule.hx", toName: "doMore", pos: 128}, edits, async);
}

public function testRenameLogger(async:Async) {
var edits:Array<TestEdit> = [
makeReplaceTestEdit("testcases/classes/Logger.hx", "log", 104, 110),
makeReplaceTestEdit("testcases/classes/Logger.hx", "log", 209, 215),
makeReplaceTestEdit("testcases/classes/Logger.hx", "log", 330, 336),
makeReplaceTestEdit("testcases/classes/Logger.hx", "log", 450, 456),
makeReplaceTestEdit("testcases/classes/Logger.hx", "log", 569, 575),
makeReplaceTestEdit("testcases/classes/Logger.hx", "log", 689, 695),
];

checkRename({fileName: "testcases/classes/Logger.hx", toName: "log", pos: 107}, edits, async);
}
}
44 changes: 44 additions & 0 deletions testcases/classes/Logger.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package classes;

import haxe.Exception;
import haxe.PosInfos;

class Log {
@inject private static var logger:ILogger;

public static inline function fatal(text:String, ?e:Exception, ?pos:PosInfos):Void {
logger?.fatal(text, e, pos);
}

public static inline function error(text:String, ?e:Exception, ?pos:PosInfos):Void {
logger?.error(text, e, pos);
}

public static inline function warn(text:String, ?e:Exception, ?pos:PosInfos):Void {
logger?.warn(text, e, pos);
}

public static inline function info(text:String, ?e:Exception, ?pos:PosInfos):Void {
logger?.info(text, e, pos);
}

public static inline function debug(text:String, ?e:Exception, ?pos:PosInfos):Void {
logger?.debug(text, e, pos);
}

public static inline function logVersion():Void {
debug("Version: 1.0");
}
}

interface ILogger {
function fatal(text:String, ?e:Exception, ?pos:PosInfos):Void;

function error(text:String, ?e:Exception, ?pos:PosInfos):Void;

function warn(text:String, ?e:Exception, ?pos:PosInfos):Void;

function info(text:String, ?e:Exception, ?pos:PosInfos):Void;

function debug(text:String, ?e:Exception, ?pos:PosInfos):Void;
}

0 comments on commit e739240

Please sign in to comment.