j2ada_1.4.2_79a46634/src/importmgr.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
--------------------------------------------------------------------------------
-- NOM DU CSU (corps)               : ImportMgr.adb
-- AUTEUR DU CSU                    : P. Pignard
-- VERSION DU CSU                   : 1.0a
-- DATE DE LA DERNIERE MISE A JOUR  : 8 octobre 2008
-- ROLE DU CSU                      : Unité de gestion des unités importées.
--
--
-- FONCTIONS EXPORTEES DU CSU       :
--
--
-- FONCTIONS LOCALES DU CSU         :
--
--
-- NOTES                            :
--
-- COPYRIGHT                        : (c) Pascal Pignard 2008
-- LICENCE                          : CeCILL V2 (http://www.cecill.info)
-- CONTACT                          : http://blady.pagesperso-orange.fr
--------------------------------------------------------------------------------

with Ada.Directories;  use Ada.Directories;
with Ada.Strings;
with Ada.Strings.Maps;
--with text_io; use text_io;
package body ImportMgr is

   LastFoundClass : TText := NullTText;

   procedure SetAPILocation (O : in out TImportUnit; JavaAPILocation : TText) is
   begin
      O.APIPath := JavaAPILocation;
   end SetAPILocation;

   procedure Add (O : in out TImportUnit; Unit : TText) is
      -- java-lang-reflect-method.ads
      PackageName : constant TText :=
         Translate
           (Head (Unit, Index (Unit, "-", Ada.Strings.Backward) - 1),
            Ada.Strings.Maps.To_Mapping ("-", "."));
      ClassName   : constant TText :=
         Unbounded_Slice
           (Unit,
            Index (Unit, "-", Ada.Strings.Backward) + 1,
            Index (Unit, ".", Ada.Strings.Backward) - 1);
   begin
      --Put_line(to_string(PackageName));
      --Put_line(to_string(ClassName));
      O.Classes.Append ((PackageName, ClassName));
   end Add;

   procedure AddAll (O : in out TImportUnit; Unit : TText) is
      -- java.io.*
      ST : Search_Type;
      --Path : constant String := "../java-API-1.0";
      Pattern         : constant String      :=
         To_String (Translate (Unit, Ada.Strings.Maps.To_Mapping (".", "-"))) & ".ads";
      Filter          : constant Filter_Type :=
        (Directory     => False,
         Ordinary_File => True,
         Special_File  => False);
      Directory_Entry : Directory_Entry_Type;
   begin
      Start_Search (ST, To_String (O.APIPath), Pattern, Filter);
      while More_Entries (ST) loop
         Get_Next_Entry (ST, Directory_Entry);
         --Put_Line (Simple_Name (Directory_Entry));
         O.Add (+Simple_Name (Directory_Entry));
      end loop;
      End_Search (ST);
   end AddAll;

   function Search (O : TImportUnit; Class : TText) return Boolean is
      LowerClass : constant TText := LowStr (Class);
      Found      : Boolean        := False;
      procedure Iterator (Pos : in ClassLists.Cursor) is
         E : constant TClass := ClassLists.Element (Pos);
      begin
         if E.ClassName = LowerClass then
            Found          := True;
            LastFoundClass := E.PackageName & '.' & E.ClassName;
         end if;
      end Iterator;
   begin
      O.Classes.Iterate (Iterator'Access);
      return Found;
   end Search;

   function GetLast (O : TImportUnit) return TText is
   begin
      return LastFoundClass;
   end GetLast;

end ImportMgr;