fidley / ABAPQuickFix

ABAP Quick Fix
https://abapblog.com
MIT License
42 stars 9 forks source link

Replace Operators #18

Closed g-back closed 3 years ago

g-back commented 3 years ago

Idea for new quick fix: replace operators "EQ" "NE" with their "proper" counterparts. I'd try this myself but there's a couple of traps:

My regex abilities are unfortunately not good enough to handle those traps...

fidley commented 3 years ago

Nice one, it should not be that hard with regex, but maybe instead one, there will be a need to use more of the regexes.

Will take a look on it.

larshp commented 3 years ago

something for testing,

types eq type c.
data eq type eq.
if strlen( eq ) eq eq and eq eq eq and boolc( eq eq eq ) eq eq.
endif.
MDagni commented 3 years ago

That would be impossible to solve :smile:

fidley commented 3 years ago

if compiler can handle this, then it is possible 😄 but maybe not with regex 😄

fidley commented 3 years ago

The list of keywords and functions that operators can appear in:

What else I miss? This could be starting point to check if in current statement one the keywords appear.

larshp commented 3 years ago

There is a where-used list in the bottom of https://syntax.abaplint.org/?filter=compare#/expression/CompareOperator, which might help.

Its ABAP so there is always another special case, and note syntax.abaplint.org is also not complete but runs okay for a lot of code

fidley commented 3 years ago

Thanks Lars, I will go through it. The other option would be to get the info directly from ADT editor, so far I haven't found the styled editor control, only plain text, but I will also deep dive into it.

larshp commented 3 years ago

tried to make an overview, https://syntax.abaplint.org/expression_CompareOperator_WhereUsed.svg, did not work out very well :)

MDagni commented 3 years ago

Is that where-used list for "eq" only?? That's huge!

larshp commented 3 years ago

yea, it is, basically EQ can be used inside boolc, and boolc can be used almost anywhere

fidley commented 3 years ago

I found the solution for this, but firstly I will finish the book and then I will implement this :) I followed the idea of getting if the token is keyword or not from ADT classes.

fidley commented 3 years ago

I've created a new branch with the solution for this. So far using the old interfaces, but better that this would be splitted into separate solution, as it uses other technique. Example of @larshp works perfectly.

EQ QuickFix

fidley commented 3 years ago

Branch 1.0.13_EQ

fidley commented 3 years ago

is there a chance that someone will help me to redesign architecture of the StatementAssistProcessor to fit two scenarios, old using regex and new using internal ADT classes? I don't want to refactor everything as I don't have commitment from SAP about the internal classes that they will became API someday yet.

fidley commented 3 years ago

Relasesd with 1.0.13