Skip to content

Commit

Permalink
no more checkstyle warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Oct 29, 2024
1 parent 25a2d7a commit b476f9a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions source/funkin/util/macro/PolymodMacro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ import haxe.macro.Type;
using haxe.macro.ExprTools;
using StringTools;

/**
* This macro creates aliases for abstracts.
* That way we can use abstracts in hscript
*/
@SuppressWarnings(['checkstyle:CodeSimilarity', 'checkstyle:Dynamic'])
class PolymodMacro
{
/**
* The abstracts and their corresponding aliases
* `key` => original class path
* `value` => alias class path
*/
public static var aliases(get, never):Map<String, String>;

static function get_aliases():Map<String, String>
Expand All @@ -17,6 +27,11 @@ class PolymodMacro
return Reflect.callMethod(null, Reflect.field(Type.resolveClass('funkin.util.macro.AbstractAliases'), 'get'), []);
}

/**
* Function that builds all the alias classes
* @param abstractClasses An array of packages and classes
* (`!` infront of the name will exclude classes from being built)
*/
public static macro function buildPolymodAbstracts(abstractClasses:Array<String>):Void
{
Context.onAfterTyping((types) -> {
Expand All @@ -38,14 +53,14 @@ class PolymodMacro
}
}

var aliases:Map<String, String> = new Map<String, String>();
var abstractAliases:Map<String, String> = new Map<String, String>();

for (type in types)
{
switch (type)
{
case ModuleType.TAbstract(a):
var cls = a.get();
var cls:AbstractType = a.get();
if (cls.isPrivate)
{
continue;
Expand All @@ -71,7 +86,7 @@ class PolymodMacro
}
}

aliases.set('${packTypePath(cls)}', 'polymod.abstracts.${packTypePath(cls)}');
abstractAliases.set('${packTypePath(cls)}', 'polymod.abstracts.${packTypePath(cls)}');
buildAbstract(cls);
break;
}
Expand All @@ -95,7 +110,7 @@ class PolymodMacro
ret: (macro :Map<String, String>),
expr: macro
{
return $v{aliases};
return $v{abstractAliases};
}
}),
pos: Context.currentPos()
Expand Down Expand Up @@ -177,7 +192,7 @@ class PolymodMacro

static function buildCreateField(cls:AbstractType, field:ClassField):Field
{
var funcArgs = [];
var funcArgs:Array<FunctionArg> = [];
var funcArgNames:Array<String> = [];
switch (field.type)
{
Expand Down Expand Up @@ -258,7 +273,7 @@ class PolymodMacro
switch (type)
{
case Type.TFun(args, ret):
var fieldArgs = [];
var fieldArgs:Array<FunctionArg> = [];
var exprArgs:Array<String> = [];
for (arg in args)
{
Expand Down

0 comments on commit b476f9a

Please sign in to comment.