Skip to content

Commit

Permalink
resolve definitions for game object handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
zznty committed Mar 7, 2024
1 parent 7cdee2f commit 4cf11cf
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,35 @@ public static ASTNode getDefinition(ASTNode node, boolean strict, ASTContext con
return new VariableExpression(variableExpression.getName(), new ClassNode(binding.getClass()));
} else if (node instanceof Variable) {
return node;
} else if (node instanceof MethodCallExpression methodCallExpression &&
methodCallExpression.getObjectExpression() instanceof StaticMethodCallExpression staticMethodCallExpression) {
return getDefinition(staticMethodCallExpression, strict, context);
} else if (node instanceof StaticMethodCallExpression staticMethodCallExpression &&
staticMethodCallExpression.getOwnerType().equals(ClassHelper.makeCached(GameObjectHandlerManager.class)) &&
staticMethodCallExpression.getMethod().equals("getGameObject") &&
staticMethodCallExpression.getArguments() instanceof ArgumentListExpression argumentListExpression &&
!argumentListExpression.getExpressions().isEmpty() &&
argumentListExpression.getExpression(0) instanceof ConstantExpression objectNameConstantExpression) {
var gameObjectName = objectNameConstantExpression.getText();
var gameObjectReturnType = GameObjectHandlerManager.getReturnTypeOf(gameObjectName);

if (gameObjectReturnType == null) {
return null;
}

var methodNode = new MethodNode(gameObjectName, Opcodes.ACC_PUBLIC,
ClassHelper.makeCached(gameObjectReturnType),
new Parameter[]{
new Parameter(ClassHelper.makeCached(String.class), "mainArg"),
new Parameter(ClassHelper.makeCached(Object[].class), "args")
},
null,
null
);

methodNode.setDeclaringClass(ClassHelper.makeCached(GameObjectHandlerManager.class));

return methodNode;
}
return null;
}
Expand Down

0 comments on commit 4cf11cf

Please sign in to comment.