Skip to content

Commit 0fc4233

Browse files
committed
V413-006 Fixing tabulations handling in code-fix
Change-Id: I91d1c3720154bac50428f4a690cdfcd00979b475 Depends-On: I87bbdb69504ec92127c517e611346d057ecfa735 Depends-On: I6ffe8f79e75993c4a3e68a9ceb6de0df0715952d
1 parent 389bae4 commit 0fc4233

9 files changed

+304
-118
lines changed

codefix/core/src/codefix-ada_tools.adb

+12-4
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ package body Codefix.Ada_Tools is
281281
Line => Get_Construct (Iterator).Sloc_Start.Line,
282282
Column => To_Column_Index
283283
(String_Index_Type
284-
(Get_Construct (Iterator).Sloc_Start.Column), Line));
284+
(Get_Construct (Iterator).Sloc_Start.Column),
285+
Line,
286+
Current_Text.Tab_Width (File_Name)));
285287
end;
286288

287289
Append (Result, New_Clause);
@@ -374,7 +376,9 @@ package body Codefix.Ada_Tools is
374376
(Current_Cursor,
375377
To_Column_Index
376378
(String_Index_Type
377-
(Get_Construct (Last_Info).Sloc_End.Column) + 1, Line));
379+
(Get_Construct (Last_Info).Sloc_End.Column) + 1,
380+
Line,
381+
Current_Text.Tab_Width (File_Name)));
378382
end;
379383
else
380384
Set_Location (Current_Cursor, 0, 1);
@@ -454,7 +458,9 @@ package body Codefix.Ada_Tools is
454458
(Current_Cursor,
455459
To_Column_Index
456460
(String_Index_Type
457-
(Get_Construct (Last_Info).Sloc_End.Column) + 1, Line));
461+
(Get_Construct (Last_Info).Sloc_End.Column) + 1,
462+
Line,
463+
Current_Text.Tab_Width (File_Name)));
458464
end;
459465
else
460466
Set_Location (Current_Cursor, 0, 1);
@@ -499,7 +505,9 @@ package body Codefix.Ada_Tools is
499505
(Result, Get_Construct (Iterator).Sloc_Start.Line,
500506
To_Column_Index
501507
(String_Index_Type
502-
(Get_Construct (Iterator).Sloc_Start.Column), Line));
508+
(Get_Construct (Iterator).Sloc_Start.Column),
509+
Line,
510+
Current_Text.Tab_Width (File_Name)));
503511
end;
504512

505513
Lock.Unlock;

codefix/core/src/codefix-formal_errors.adb

+11-7
Original file line numberDiff line numberDiff line change
@@ -725,14 +725,18 @@ package body Codefix.Formal_Errors is
725725
if Apply_Also_On_Decl then
726726
declare
727727
File : constant Structured_File_Access :=
728-
Current_Text.Get_Structured_File
729-
(Message.Get_File);
730-
Decl_Entity : constant Entity_Access := Find_Declaration
731-
(Lang => Get_Tree_Language (File),
732-
File => File,
733-
Line => Word.Get_Line,
734-
Column => String_Index_Type (Word.Get_Column));
728+
Current_Text.Get_Structured_File
729+
(Message.Get_File);
730+
Decl_Entity : Entity_Access;
735731
begin
732+
if File /= null then
733+
Decl_Entity := Find_Declaration
734+
(Lang => Get_Tree_Language (File),
735+
File => File,
736+
Line => Word.Get_Line,
737+
Column => String_Index_Type (Word.Get_Column));
738+
end if;
739+
736740
if Decl_Entity /= Null_Entity_Access then
737741
declare
738742
Decl_Construct : constant access

codefix/core/src/codefix-gnat_parser.adb

+3-4
Original file line numberDiff line numberDiff line change
@@ -2390,9 +2390,9 @@ package body Codefix.GNAT_Parser is
23902390
begin
23912391
Solutions :=
23922392
Unexpected
2393-
(Current_Text,
2394-
Message,
2395-
To_Unbounded_String
2393+
(Current_Text => Current_Text,
2394+
Message => Message,
2395+
String_Unexpected => To_Unbounded_String
23962396
(Get_Message (Message) (Matches (1).First .. Matches (1).Last)));
23972397
end Fix;
23982398

@@ -4140,7 +4140,6 @@ package body Codefix.GNAT_Parser is
41404140
if Length (Solutions) = 0 then
41414141
raise Uncorrectable_Message;
41424142
end if;
4143-
41444143
end Fix;
41454144

41464145
----------------

codefix/core/src/codefix-text_manager-ada_commands.adb

+61-25
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ package body Codefix.Text_Manager.Ada_Commands is
9797
Close_Cursor.Set_Line (Sloc_Start.Line);
9898
Close_Cursor.Set_Column
9999
(To_Column_Index
100-
(String_Index_Type (Sloc_Start.Column), Line));
100+
(String_Index_Type (Sloc_Start.Column),
101+
Line,
102+
Current_Text.Tab_Width (Open_Cursor.File)));
101103

102104
return True;
103105
end if;
@@ -201,10 +203,11 @@ package body Codefix.Text_Manager.Ada_Commands is
201203
loop
202204
declare
203205
Full_Line : constant String :=
204-
Get_Line (Current_Text, End_Cursor, 1);
205-
J : String_Index_Type :=
206-
To_Char_Index
207-
(Get_Column (End_Cursor), Full_Line) - 1;
206+
Get_Line (Current_Text, End_Cursor, 1);
207+
J : String_Index_Type := To_Char_Index
208+
(Get_Column (End_Cursor),
209+
Full_Line,
210+
Current_Text.Tab_Width (End_Cursor.Get_File)) - 1;
208211

209212
begin
210213
-- Skip previous blanks
@@ -222,7 +225,9 @@ package body Codefix.Text_Manager.Ada_Commands is
222225
Set_Location
223226
(End_Cursor,
224227
Get_Line (End_Cursor),
225-
To_Column_Index (J, Full_Line) + 1);
228+
To_Column_Index
229+
(J, Full_Line,
230+
Current_Text.Tab_Width (End_Cursor.Get_File)) + 1);
226231

227232
exit;
228233

@@ -244,7 +249,9 @@ package body Codefix.Text_Manager.Ada_Commands is
244249
Set_Location
245250
(End_Cursor,
246251
Get_Line (End_Cursor),
247-
To_Column_Index (J, Full_Line));
252+
To_Column_Index
253+
(J, Full_Line,
254+
Current_Text.Tab_Width (End_Cursor.Get_File)));
248255

249256
exit;
250257
end if;
@@ -876,7 +883,9 @@ package body Codefix.Text_Manager.Ada_Commands is
876883
Set_Location
877884
(Position,
878885
Get_Construct (Declaration).Sloc_End.Line,
879-
To_Column_Index (Char_Ind, Line));
886+
To_Column_Index
887+
(Char_Ind, Line,
888+
Current_Text.Tab_Width (Cursor.Get_File)));
880889
end;
881890
end Add_Pragma;
882891

@@ -909,7 +918,9 @@ package body Codefix.Text_Manager.Ada_Commands is
909918
Set_Location
910919
(Position,
911920
Get_Construct (Clause).Sloc_End.Line,
912-
To_Column_Index (Char_Ind, Line));
921+
To_Column_Index
922+
(Char_Ind, Line,
923+
Current_Text.Tab_Width (Cursor.Get_File)));
913924
end;
914925
end Add_Clause_Pragma;
915926

@@ -943,7 +954,9 @@ package body Codefix.Text_Manager.Ada_Commands is
943954
Set_Location
944955
(Position,
945956
Get_Construct (Declaration).Sloc_End.Line,
946-
To_Column_Index (Char_Ind, Line));
957+
To_Column_Index
958+
(Char_Ind, Line,
959+
Current_Text.Tab_Width (Cursor.Get_File)));
947960
end;
948961
end Add_Literal_Pragma;
949962

@@ -971,7 +984,9 @@ package body Codefix.Text_Manager.Ada_Commands is
971984
(Position, Get_Construct (Declaration).Sloc_Entity.Line,
972985
To_Column_Index
973986
(String_Index_Type
974-
(Get_Construct (Declaration).Sloc_Entity.Column), Line));
987+
(Get_Construct (Declaration).Sloc_Entity.Column),
988+
Line,
989+
Current_Text.Tab_Width (Cursor.Get_File)));
975990
end;
976991

977992
Garbage := Position;
@@ -1292,7 +1307,8 @@ package body Codefix.Text_Manager.Ada_Commands is
12921307
Begin_Cursor.Line := Sloc_Start.Line;
12931308
Begin_Cursor.Col := To_Column_Index
12941309
(String_Index_Type (Sloc_Start.Column),
1295-
Get_Line (Current_Text, Begin_Cursor, 1));
1310+
Get_Line (Current_Text, Begin_Cursor, 1),
1311+
Current_Text.Tab_Width (Begin_Cursor.Get_File));
12961312
end if;
12971313
end Begin_Of_Profile;
12981314

@@ -1306,7 +1322,8 @@ package body Codefix.Text_Manager.Ada_Commands is
13061322
End_Cursor.Line := Last_Entity_Line;
13071323
End_Cursor.Col := To_Column_Index
13081324
(String_Index_Type (Last_Entity_Column),
1309-
Get_Line (Current_Text, End_Cursor, 1));
1325+
Get_Line (Current_Text, End_Cursor, 1),
1326+
Current_Text.Tab_Width (End_Cursor.Get_File));
13101327

13111328
if Begin_Cursor = Null_File_Cursor then
13121329
End_Cursor.Col := End_Cursor.Col + 1;
@@ -1389,7 +1406,8 @@ package body Codefix.Text_Manager.Ada_Commands is
13891406
To_Column_Index
13901407
(String_Index_Type
13911408
(Get_Construct (Position_It).Sloc_Start.Column),
1392-
Get_Line (Current_Text, Begin_Analyze_Cursor, 1)));
1409+
Get_Line (Current_Text, Begin_Analyze_Cursor, 1),
1410+
Current_Text.Tab_Width (Begin_Analyze_Cursor.Get_File)));
13931411

13941412
Last_Entity_Column := Integer (Begin_Analyze_Cursor.Col);
13951413
Last_Entity_Line := Begin_Analyze_Cursor.Line;
@@ -1720,7 +1738,10 @@ package body Codefix.Text_Manager.Ada_Commands is
17201738
(Get_File (Line_Cursor)).Indent_Line (Line_Cursor);
17211739
else
17221740
Char_Ind := To_Char_Index
1723-
(This.Force_Column, Get_Line (Current_Text, Line_Cursor, 1));
1741+
(This.Force_Column,
1742+
Get_Line (Current_Text, Line_Cursor, 1),
1743+
Current_Text.Tab_Width (Line_Cursor.Get_File));
1744+
17241745
Indent_Size := Natural (Char_Ind) - 1;
17251746

17261747
declare
@@ -1929,7 +1950,9 @@ package body Codefix.Text_Manager.Ada_Commands is
19291950
(This => Cursor,
19301951
Line => Sloc_End.Line,
19311952
Column => To_Column_Index
1932-
(String_Index_Type (Sloc_End.Column), Line));
1953+
(String_Index_Type (Sloc_End.Column),
1954+
Line,
1955+
Current_Text.Tab_Width (Cursor.Get_File)));
19331956
end if;
19341957

19351958
return Stop_Scanning;
@@ -2207,7 +2230,9 @@ package body Codefix.Text_Manager.Ada_Commands is
22072230

22082231
End_Line := Sloc_End.Line;
22092232
End_Column := To_Column_Index
2210-
(String_Index_Type (Sloc_End.Column), Line);
2233+
(String_Index_Type (Sloc_End.Column),
2234+
Line,
2235+
Current_Text.Tab_Width (Cursor.Get_File));
22112236

22122237
return False;
22132238
end Scan_Forward_Callback;
@@ -2288,8 +2313,8 @@ package body Codefix.Text_Manager.Ada_Commands is
22882313
Current_Text.Get_Current_Cursor (This.Cursor.all);
22892314
Line : constant String := Get_Line (Current_Text, Cursor, 1);
22902315
New_Id : String (1 .. Line'Length);
2291-
Index : String_Index_Type :=
2292-
To_Char_Index (Get_Column (Cursor), Line);
2316+
Index : String_Index_Type := To_Char_Index
2317+
(Get_Column (Cursor), Line, Current_Text.Tab_Width (Cursor.Get_File));
22932318
New_Id_Index : Integer := 1;
22942319
Start_Index : String_Index_Type;
22952320
begin
@@ -2325,7 +2350,8 @@ package body Codefix.Text_Manager.Ada_Commands is
23252350
end if;
23262351
end loop;
23272352

2328-
Cursor.Col := To_Column_Index (Start_Index, Line);
2353+
Cursor.Col := To_Column_Index
2354+
(Start_Index, Line, Current_Text.Tab_Width (Cursor.Get_File));
23292355

23302356
Current_Text.Replace
23312357
(Cursor,
@@ -2384,7 +2410,8 @@ package body Codefix.Text_Manager.Ada_Commands is
23842410
Pragma_Cursor.Set_Column
23852411
(To_Column_Index
23862412
(String_Index_Type (Get_Construct (It).Sloc_Start.Column),
2387-
Current_Text.Get_Line (Pragma_Cursor, 0)));
2413+
Current_Text.Get_Line (Pragma_Cursor, 0),
2414+
Current_Text.Tab_Width (Pragma_Cursor.Get_File)));
23882415

23892416
declare
23902417
List : Ada_Statement;
@@ -2581,7 +2608,8 @@ package body Codefix.Text_Manager.Ada_Commands is
25812608
End_Line : constant String :=
25822609
Current_Text.Get_Line (Src_End_Cursor, 0);
25832610
begin
2584-
Src_End_Cursor.Col := To_Column_Index (End_Line'Length, End_Line);
2611+
Src_End_Cursor.Col := To_Column_Index
2612+
(End_Line'Length, End_Line, Current_Text.Tab_Width (Cursor.File));
25852613
end;
25862614

25872615
if Prev_Entity = Null_Construct_Tree_Iterator then
@@ -2596,7 +2624,10 @@ package body Codefix.Text_Manager.Ada_Commands is
25962624
End_Line : constant String :=
25972625
Current_Text.Get_Line (Dst_Cursor, 0);
25982626
begin
2599-
Dst_Cursor.Col := To_Column_Index (End_Line'Length, End_Line) + 1;
2627+
Dst_Cursor.Col := To_Column_Index
2628+
(End_Line'Length,
2629+
End_Line,
2630+
Current_Text.Tab_Width (Dst_Cursor.Get_File)) + 1;
26002631
end;
26012632
else
26022633
-- If there is a subprogram before, place it after the end of that
@@ -2608,7 +2639,10 @@ package body Codefix.Text_Manager.Ada_Commands is
26082639
End_Line : constant String :=
26092640
Current_Text.Get_Line (Dst_Cursor, 0);
26102641
begin
2611-
Dst_Cursor.Col := To_Column_Index (End_Line'Length, End_Line) + 1;
2642+
Dst_Cursor.Col := To_Column_Index
2643+
(End_Line'Length,
2644+
End_Line,
2645+
Current_Text.Tab_Width (Dst_Cursor.Get_File)) + 1;
26122646
end;
26132647
end if;
26142648

@@ -2863,7 +2897,9 @@ package body Codefix.Text_Manager.Ada_Commands is
28632897
Name_Cursor.Set_Location
28642898
(Sloc_Start.Line,
28652899
To_Column_Index
2866-
(String_Index_Type (Sloc_Start.Column), Line));
2900+
(String_Index_Type (Sloc_Start.Column),
2901+
Line,
2902+
Current_Text.Tab_Width (Name_Cursor.Get_File)));
28672903

28682904
Name_Length := Sloc_End.Column - Sloc_Start.Column + 1;
28692905

codefix/core/src/codefix-text_manager-commands.adb

+13-9
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ package body Codefix.Text_Manager.Commands is
9797
Match : constant String := Word.Get_Matching_Word
9898
(Current_Text);
9999
Str_Parsed : constant String :=
100-
Do_Tab_Expansion
101-
(Current_Text.Get_Line (Word, Start_Col => 1),
102-
Current_Text.Tab_Width (Get_File (Word)));
100+
Do_Tab_Expansion
101+
(Current_Text.Get_Line (Word, Start_Col => 1),
102+
Current_Text.Tab_Width (Get_File (Word)));
103103
Column : Natural := Natural (Get_Column (Word));
104104

105105
begin
@@ -161,13 +161,14 @@ package body Codefix.Text_Manager.Commands is
161161
exit;
162162
end if;
163163

164-
-- Check if we must remove another occurrence found immediately
165-
-- after the removed text
164+
-- Check if we must remove another occurrence found
165+
-- immediately after the removed text
166166

167167
exit when not This.All_Occurrences;
168168

169169
declare
170-
Str_Parsed : constant String := Current_Text.Get_Line (Word);
170+
Str_Parsed : constant String :=
171+
Current_Text.Get_Line (Word);
171172

172173
begin
173174
exit when Str_Parsed'Length < Match'Length
@@ -269,12 +270,15 @@ package body Codefix.Text_Manager.Commands is
269270

270271
New_Pos.Col := To_Column_Index
271272
(String_Index_Type (Matches (1).Last) + 1,
272-
Get_Line (Current_Text, New_Pos, 1));
273+
Get_Line (Current_Text, New_Pos, 1),
274+
Current_Text.Tab_Width (New_Pos.File));
273275
end;
274276
end if;
275277

276-
Word_Char_Index :=
277-
To_Char_Index (New_Pos.Col, Get_Line (Current_Text, Line_Cursor));
278+
Word_Char_Index := To_Char_Index
279+
(New_Pos.Col,
280+
Get_Line (Current_Text, Line_Cursor),
281+
Current_Text.Tab_Width (New_Pos.File));
278282

279283
if This.Position = Specified then
280284
if This.Add_Spaces then

0 commit comments

Comments
 (0)