How to get to the value of a method param (method invokation/calling, not declaration) #264
Replies: 1 comment
-
I posted a simple issue for this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
[Edit: i spent much more time to understand this and as of now in no way i can use a method computeConstantValue() f.e. i can't do inv.argumentList.arguments.first.computeConstantValue() so my question seems valid].
First and for all i guess it could only work only when the value is known to the analyser like const.
(I will probably later correct the following content, but the point of the question i think can be understood).
Still i have very limited knowledge of much stuff like custom_lint/analyzer.
The following is based on an assumption that for a invokation of a function in analyzer i can always have a value of a const when a file/library is analyzed.
When calling a simple one param method like this with const values
method(someConst) or method(10) or method('20 as string' + 'plus something ${10}') or method(const [
5,
'Some String',
ConstClass(), /non const can't be used as expected - error: NonConstClass()/
]);
To get what's needed i use context.registry.addMethodInvocation((inv) ...)
The question is
Is there a way i can get to the the real value of the const and compare it with a value i create like exactly to each corresponding method() call
The only closest way i could get to the real param I can get to the first param like this:
inv.argumentList.arguments.first.unParenthesized.toString();
But for method('20 as string' + 'plus something ${10}') this returned exactly the same string, not a computed value like '20 as string plus something 10'
and also then i get "someConst" String that i cannot use. Probably i can find the const definition but it could even be someConst1 + someVariable, etc. Still need to evaluate.
For discovering/testing/learning purposes I was even able to compute some annotation values using
var metad = inv.argumentList.arguments.first.staticParameterElement?.declaration.metadata;
But don't know what to do if i see the call like the mentioned at the beginning especially like method('20 as string' + 'plus something ${10}') and method(someConst); - how to get or compute the values of the method params.
Beta Was this translation helpful? Give feedback.
All reactions