Skip to content
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

Refactoring lots of things #12

Merged
merged 59 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
106f383
- added invalidateFile / removeFile to allow rescan in case of file c…
AlexHaxe Nov 4, 2024
811d145
added ExtractType and ExtractInterface refactor modules
AlexHaxe Nov 7, 2024
5f09eba
added support for doc comments in extracted interfaces
AlexHaxe Nov 8, 2024
4163f68
added format flag for edits
AlexHaxe Nov 10, 2024
7832912
fixed missing file
AlexHaxe Nov 10, 2024
2385c12
fixed arrow function with single parameter detection
AlexHaxe Nov 13, 2024
121c3c2
refactored typehint data structure
AlexHaxe Nov 19, 2024
c5ed08b
fixed missing file
AlexHaxe Nov 19, 2024
bcb4112
added ExtractMethod
AlexHaxe Nov 19, 2024
03bac6c
added testcases from vshaxe/vshaxe#632
AlexHaxe Nov 19, 2024
04a3f7f
refactored code generation for ExtractMethod
AlexHaxe Nov 23, 2024
19b2667
refactored typing
AlexHaxe Nov 24, 2024
5bc1166
fixed wrong position for hover requests
AlexHaxe Nov 24, 2024
7e16139
added testcases
AlexHaxe Nov 24, 2024
ed57f56
fixed type hint for return expression extracts
AlexHaxe Nov 25, 2024
d2b9aa9
fixed modifier removal for ExtractInterface
AlexHaxe Nov 25, 2024
e943f0c
fixed failing tests
AlexHaxe Nov 25, 2024
109c048
fixed missing testcase file
AlexHaxe Nov 25, 2024
d327396
fixed Demo testcases
AlexHaxe Nov 25, 2024
94e8203
fixed extracting from functions with type parameters
AlexHaxe Nov 25, 2024
3087cd2
added testcase
AlexHaxe Nov 25, 2024
df26bfa
added more testcases
AlexHaxe Nov 26, 2024
44ab547
fixed code gen for empty return or throw as last expressions of selec…
AlexHaxe Nov 26, 2024
3e225fb
fixed parameter collection from string interpolation
AlexHaxe Nov 26, 2024
c00ba7b
added testcase
AlexHaxe Nov 26, 2024
5497f7f
added support for local function extraction
AlexHaxe Nov 27, 2024
a24e2a2
fixed missing code gen
AlexHaxe Nov 27, 2024
6fb1429
updated json2object for latest nightly
AlexHaxe Nov 27, 2024
f1acf21
added testcases
AlexHaxe Nov 28, 2024
4f8d835
added missing file
AlexHaxe Nov 28, 2024
ac4b82c
fixed importInsertPos for files with comment headers
AlexHaxe Nov 29, 2024
e627131
added indentation options for snippet fomratting
AlexHaxe Nov 30, 2024
140dbbe
fixed switch cases with conditional compilation
AlexHaxe Dec 1, 2024
43e030a
cleanup
AlexHaxe Dec 1, 2024
22a77d9
fixed enum rename eating Dot field separator
AlexHaxe Dec 1, 2024
c132b04
fixed extraction of named local functions
AlexHaxe Dec 2, 2024
419b426
added type resolution for return type hints to extract interface
AlexHaxe Dec 2, 2024
9d7b478
fixed testcases
AlexHaxe Dec 2, 2024
df49ba7
fixed extrating from constructor
AlexHaxe Dec 2, 2024
3001ac0
added Extract Constructor Params refactor module
AlexHaxe Dec 2, 2024
f39e492
fixed constructors with no parameters
AlexHaxe Dec 2, 2024
3f1786d
added testcases
AlexHaxe Dec 3, 2024
22da8d2
removed trailing newline for callsite code generation
AlexHaxe Dec 3, 2024
9a93995
added Rewrite Vars to Finals and vice versa
AlexHaxe Dec 3, 2024
fe2a487
fixed vars to finals with modifiers
AlexHaxe Dec 3, 2024
750f445
fixed vars to finals changing property vars
AlexHaxe Dec 5, 2024
222e156
removed edited flag from Identifier
AlexHaxe Dec 8, 2024
6d9f509
cleanup
AlexHaxe Dec 8, 2024
031091b
fixed type rename resolving type identifier
AlexHaxe Dec 8, 2024
0cdbd5c
fixed matching type hints with one of them Null<T>
AlexHaxe Dec 8, 2024
6158060
fixed name match for Null<T>
AlexHaxe Dec 8, 2024
b7717b4
fixed identifier discovery for field access of arrays or after calls
AlexHaxe Dec 9, 2024
2c0e1c2
fixed extract method from local function
AlexHaxe Dec 9, 2024
8de3607
fixed discovery of typed parameters
AlexHaxe Dec 9, 2024
d069790
changed order of type resolution to built-in then external typer
AlexHaxe Dec 19, 2024
32b556b
added info about recently renamed filenames to help vshaxe ignore the…
AlexHaxe Dec 22, 2024
26d5f47
added findIdentifierChilds to visit all childnodes of identifiers
AlexHaxe Dec 22, 2024
e739240
fixed field rename with null-safe access
AlexHaxe Dec 22, 2024
a26c0ea
prepare release
AlexHaxe Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"parameterNames": true,
"parameterTypes": false,
"functionReturnTypes": true,
"conditionals": false
"conditionals": true
},
"haxe.importsSortOrder": "stdlib -> libs -> project"
}
30 changes: 29 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
# Version history

## dev branch / next version (2.x.x)
## dev branch / next version (3.x.x)

## 3.0.0 (2024-12-23)

- added ExtractType refactor module
- added ExtractInterface refactor module
- added ExtractMethod refactor module
- added Extract Constructor Params refactor module as vars or finals
- added Rewrite Vars to Finals and Rewrite Finals to Vars refactor module
- added Wrap with Try…Catch refactor module
- added invalidateFile / removeFile to allow rescan in case of file changes or deletion
- added support for create and delete file operations as edits
- added support for local function extraction
- added indentation options for snippet formatting
- changed Refactor class to Rename
- changed getFullModulName call to fullModuleName property
- changed order of type resolution to built-in then external typer
- fixed type name renaming not changing in use locations
- fixed discovery of arrow functions as type hints
- fixed extracting from functions with type parameters
- fixed discovery of identifiers in if conditions
- fixed code gen for empty return or throw as last expressions of selection
- fixed parameter collection from string interpolation
- fixed importInsertPos for files with comment headers
- fixed enum field rename eating dot separator
- fixed abstract enum type resolution
- fixed rename field with null-safe access operator
- refactored typehint data structure
- refactored identifier discovery

## 2.3.1 (2024-11-01)

Expand Down
1 change: 1 addition & 0 deletions build.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
-lib tokentree
-lib hxnodejs
-lib hxargs
-lib formatter

-D js-es=6
-js bin/rename.js
Expand Down
2 changes: 2 additions & 0 deletions display.hxml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
-cp src
-cp test
-cp testcases

-lib haxeparser
-lib tokentree
-lib hxnodejs
-lib hxargs
-lib formatter
-lib utest
-lib test-adapter

Expand Down
3 changes: 3 additions & 0 deletions haxe_libraries/formatter.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @install: lix --silent download "gh://github.com/HaxeCheckstyle/haxe-formatter#cad782a6571cea82c324fc97a83fb138b740b1bd" into formatter/1.17.1/github/cad782a6571cea82c324fc97a83fb138b740b1bd
-cp ${HAXE_LIBCACHE}/formatter/1.17.1/github/cad782a6571cea82c324fc97a83fb138b740b1bd/src
-D formatter=1.17.1
4 changes: 2 additions & 2 deletions haxe_libraries/json2object.hxml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @install: lix --silent download "haxelib:/json2object#3.11.0" into json2object/3.11.0/haxelib
# @install: lix --silent download "gh://github.com/elnabo/json2object#a75859de1e966c09e73591b6c9186086c143fe60" into json2object/3.11.0/github/a75859de1e966c09e73591b6c9186086c143fe60
-lib hxjsonast
-cp ${HAXE_LIBCACHE}/json2object/3.11.0/haxelib/src
-cp ${HAXE_LIBCACHE}/json2object/3.11.0/github/a75859de1e966c09e73591b6c9186086c143fe60/src
-D json2object=3.11.0
4 changes: 2 additions & 2 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"refactor"
],
"description": "A code renaming tool for Haxe",
"version": "2.3.1",
"releasenote": "fixed discovery of vars in pattern extraction - see CHANGELOG",
"version": "3.0.0",
"releasenote": "added ExtractType, ExtractInterface and ExtracMethod refactoring and more + bugfixes - see CHANGELOG",
"contributors": [
"AlexHaxe"
],
Expand Down
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@haxecheckstyle/haxe-rename",
"version": "2.3.1",
"version": "3.0.0",
"description": "Renaming tool for Haxe",
"repository": {
"type": "git",
Expand All @@ -16,7 +16,7 @@
"email": "[email protected]"
},
"devDependencies": {
"lix": "^15.12.0"
"lix": "^15.12.4"
},
"bin": {
"haxe-rename": "bin/rename.js"
Expand Down
20 changes: 20 additions & 0 deletions src/refactor/CacheAndTyperContext.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package refactor;

import refactor.VerboseLogger;
import refactor.discover.FileList;
import refactor.discover.FileReaderFunc;
import refactor.discover.NameMap;
import refactor.discover.TypeList;
import refactor.typing.ITyper;

typedef CacheAndTyperContext = {
var nameMap:NameMap;
var fileList:FileList;
var typeList:TypeList;
var verboseLog:VerboseLogger;
var typer:Null<ITyper>;
var fileReader:FileReaderFunc;
var converter:ByteToCharConverterFunc;
}

typedef ByteToCharConverterFunc = (string:String, byteOffset:Int) -> Int;
16 changes: 0 additions & 16 deletions src/refactor/CanRefactorContext.hx

This file was deleted.

12 changes: 7 additions & 5 deletions src/refactor/Cli.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package refactor;

import haxe.PosInfos;
import haxe.Timer;
import refactor.RefactorContext.VerboseLogger;
import refactor.discover.FileList;
import refactor.discover.NameMap;
import refactor.discover.TraverseSources;
import refactor.discover.TypeList;
import refactor.discover.UsageCollector;
import refactor.discover.UsageContext;
import refactor.edits.EditableDocument;
import refactor.rename.RenameWhat;

class Cli {
var verbose:Bool = false;
Expand Down Expand Up @@ -88,7 +88,7 @@ class Cli {
printHelp();
Sys.exit(0);
}
var what:Null<RefactorWhat> = makeWhat(loc, toName);
var what:Null<RenameWhat> = makeWhat(loc, toName);
if (what == null) {
printHelp();
Sys.exit(1);
Expand All @@ -110,15 +110,17 @@ class Cli {
TraverseSources.traverseSources(paths, usageContext);
usageContext.usageCollector.updateImportHx(usageContext);

var result:Promise<RefactorResult> = Refactor.rename({
var result:Promise<RefactorResult> = Rename.rename({
nameMap: usageContext.nameMap,
fileList: usageContext.fileList,
typeList: usageContext.typeList,
what: what,
forRealExecute: execute && forReal,
docFactory: EditableDocument.new,
verboseLog: verboseLog,
typer: null
typer: null,
fileReader: null,
converter: null,
});
result.then(function(result:RefactorResult) {
switch (result) {
Expand All @@ -145,7 +147,7 @@ class Cli {
Sys.println(text);
}

function makeWhat(location:String, toName:String):Null<RefactorWhat> {
function makeWhat(location:String, toName:String):Null<RenameWhat> {
var parts:Array<String> = location.split("@");
if (parts.length != 2) {
return null;
Expand Down
7 changes: 0 additions & 7 deletions src/refactor/ITypeList.hx

This file was deleted.

95 changes: 88 additions & 7 deletions src/refactor/PrintHelper.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package refactor;

import refactor.discover.IdentifierType;
import refactor.rename.RenameHelper.TypeHintType;
import refactor.typing.TypeHintType;
import refactor.typing.TypingHelper.TypeParameterList;

class PrintHelper {
public static function typeToString(identType:IdentifierType):String {
Expand All @@ -11,7 +12,15 @@ class PrintHelper {
case Method(isStatic):
'Method(${isStatic})';
case TypedefField(fields):
'TypedefField(${fields})';
final fieldnames = [
for (field in fields) {
return switch (field) {
case Required(identifier) | Optional(identifier):
identifier.name;
}
}
];
'TypedefField(${fieldnames.join(", ")})';
case StructureField(fieldNames):
'StructureField(${fieldNames})';
case EnumField(params):
Expand All @@ -36,16 +45,73 @@ class PrintHelper {
}
}

public static function typeHintToString(hintType:Null<TypeHintType>):String {
if (hintType == null) {
return "null";
}
return switch (hintType) {
case ClasspathType(type, paramList):
if (paramList.length > 0) {
final params = paramList.map(p -> typeHintToString(p));
return 'ClasspathType(${type.name.name}<${params.join(", ")}>)';
}
'ClasspathType(${type?.name.name}, <>)';
case LibType(name, fullName, paramList):
if (paramList.length > 0) {
final params = paramList.map(p -> typeHintToString(p));
return 'LibType($name, $fullName, <${params.join(", ")}>';
}
'LibType($name, $fullName, <>)';
case FunctionType(argTypes, retVal):
final args = argTypes.map(f -> typeHintToString(f));
if (argTypes == null) {
return 'FunctionType((${args.join(", ")}) -> Void)';
}
return 'FunctionType((${args.join(", ")}) -> ${typeHintToString(retVal)})';
case StructType(fieldTypes):
final fields = fieldTypes.map(f -> typeHintToString(f));
'StructType({${fields.join(";")}})';
case NamedType(name, namedHint):
'NamedType($name, ${typeHintToString(namedHint)})';
case UnknownType(name):
'UnknownType($name)';
}
}

public static function printTypeHint(hintType:TypeHintType):String {
return switch (hintType) {
case KnownType(type, params):
'KnownType(${type.name.name}, ${params.map((i) -> i.name)})';
case UnknownType(name, params):
'UnknownType($name, ${params.map((i) -> i.name)})';
case ClasspathType(type, paramList):
if (paramList.length > 0) {
final params = paramList.map(p -> printTypeHint(p));
return '${type.name.name}<${params.join(", ")}>';
}
'${type.name.name}';
case LibType(name, fullName, paramList):
if (paramList.length > 0) {
final params = paramList.map(p -> printTypeHint(p));
return '${name}<${params.join(", ")}>';
}
'$name';
case FunctionType(argTypes, retVal):
final args = argTypes.map(f -> printTypeHint(f));
if (argTypes == null) {
return '(${args.join(", ")}) -> Void';
}
if (argTypes.length == 1) {
return '${args.join(", ")} -> ${printTypeHint(retVal)}';
}
return '(${args.join(", ")}) -> ${printTypeHint(retVal)}';
case StructType(fieldTypes):
final fields = fieldTypes.map(f -> printTypeHint(f));
'{${fields.join(", ")}}';
case NamedType(name, namedHint):
'$name:${printTypeHint(namedHint)}';
case UnknownType(name):
'$name';
}
}

public static function printRefactorResult(result:RefactorResult):String {
public static function printRenameResult(result:RefactorResult):String {
return switch (result) {
case NoChange:
"nothing to do";
Expand All @@ -59,4 +125,19 @@ class PrintHelper {
"rename successful";
}
}

public static function printRefactorResult(result:RefactorResult):String {
return switch (result) {
case NoChange:
"nothing to do";
case NotFound:
"could not find identifier to refactor";
case Unsupported(name):
"refactor not supported for " + name;
case DryRun:
"dry run - no changes were made";
case Done:
"refactor successful";
}
}
}
12 changes: 0 additions & 12 deletions src/refactor/RefactorContext.hx

This file was deleted.

Loading
Loading