KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > corba > generator > dependencies > lib > IDL2DeclarationDependencies


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.corba.generator.dependencies.lib;
28
29 // Package dependencies.
30
import org.objectweb.openccm.ast.api.TypeKind;
31 import org.objectweb.openccm.ast.api.DeclarationKind;
32 import org.objectweb.openccm.ast.api.ConstantDecl;
33 import org.objectweb.openccm.ast.api.EnumDecl;
34 import org.objectweb.openccm.ast.api.StructDecl;
35 import org.objectweb.openccm.ast.api.UnionDecl;
36 import org.objectweb.openccm.ast.api.AbstractInterfaceDecl;
37 import org.objectweb.openccm.ast.api.LocalInterfaceDecl;
38 import org.objectweb.openccm.ast.api.InterfaceDecl;
39 import org.objectweb.openccm.ast.api.ValueDecl;
40 import org.objectweb.openccm.ast.api.ValueBoxDecl;
41 import org.objectweb.openccm.ast.api.ValueMemberDecl;
42 import org.objectweb.openccm.ast.api.ExceptionDecl;
43 import org.objectweb.openccm.ast.api.AliasDecl;
44 import org.objectweb.openccm.ast.api.AnyValue;
45 import org.objectweb.openccm.ast.api.AttributeDecl;
46 import org.objectweb.openccm.ast.api.TypeRef;
47 import org.objectweb.openccm.ast.api.UnionMember;
48 import org.objectweb.openccm.ast.api.Parameter;
49 import org.objectweb.openccm.ast.api.OperationDecl;
50 import org.objectweb.openccm.ast.api.Scope;
51 import org.objectweb.openccm.ast.api.Declaration;
52 import org.objectweb.openccm.ast.api.Initializer;
53 import org.objectweb.openccm.ast.api.StructMember;
54 import java.util.Set JavaDoc;
55
56 /**
57  * This class allows you to get classes dependencies for an IDL2 declaration.
58  *
59  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
60  *
61  * @version 0.1
62  */

63
64 public class IDL2DeclarationDependencies
65   implements org.objectweb.corba.generator.dependencies.api.IDL2DeclarationDependencies
66 {
67     // ==================================================================
68
//
69
// Internal state.
70
//
71
// ==================================================================
72

73     /** Utility class to convert types in Java. */
74     org.objectweb.openccm.generator.translator.idl2java.api.CommonTranslator _translator;
75
76     // ==================================================================
77
//
78
// Constructor.
79
//
80
// ==================================================================
81

82     /**
83      * The default constructor.
84      */

85     public
86     IDL2DeclarationDependencies()
87     {
88         // Init internal state
89
_translator = new org.objectweb.openccm.generator.translator.idl2java.lib.CommonTranslator();
90     }
91
92     // ==================================================================
93
//
94
// Internal methods.
95
//
96
// ==================================================================
97

98     /**
99      * Add IDL Object class for a declaration to <files>, i.e. :
100      * - <declaration_name>
101      *
102      * @param files - A set of Files.
103      * @param name - The name of the declaration.
104      */

105     protected void
106     addObjectClass(Set JavaDoc files, String JavaDoc name)
107     {
108         files.add( new String JavaDoc(name + ".class") );
109     }
110
111     /**
112      * Add Helper class for a declaration to <files>, i.e. :
113      * - <declaration_name>Helper
114      *
115      * @param files - A set of Files.
116      * @param name - The name of the declaration.
117      */

118     protected void
119     addHelperClass(Set JavaDoc files, String JavaDoc name)
120     {
121         files.add( new String JavaDoc(name + "Helper.class") );
122     }
123
124     /**
125      * Add Holder class for a declaration to <files>, i.e. :
126      * - <declaration_name>Holder
127      *
128      * @param files - A set of Files.
129      * @param name - The name of the declaration.
130      */

131     protected void
132     addHolderClass(Set JavaDoc files, String JavaDoc name)
133     {
134         files.add( new String JavaDoc(name + "Holder.class") );
135     }
136
137     /**
138      * Add Standard IDL File dependencies for a declaration to <files>, i.e. :
139      * - <declaration_name>
140      * - <declaration_name>Helper
141      * - <declaration_name>Holder
142      *
143      * @param files - A set of Files.
144      * @param name - The name of the declaration.
145      */

146     protected void
147     addStantardIdlFiles(Set JavaDoc files, String JavaDoc name)
148     {
149         addObjectClass(files, name);
150         addHelperClass(files, name);
151         addHolderClass(files, name);
152     }
153
154     /**
155      * Add Operations IDL class for a declaration to <files>, i.e. :
156      * - <declaration_name>Operations
157      *
158      * @param files - A set of Files.
159      * @param name - The name of the declaration.
160      */

161     protected void
162     addOperationsClass(Set JavaDoc files, String JavaDoc name)
163     {
164         files.add( new String JavaDoc(name + "Operations.class") );
165     }
166
167     /**
168      * Add POA IDL File dependencies for a declaration to <files>, i.e. :
169      * - <declaration_name>POA
170      * - <declaration_name>POATie
171      *
172      * @param files - A set of Files.
173      * @param name - The name of the declaration.
174      */

175     protected void
176     addPoaIdlFiles(Set JavaDoc files, String JavaDoc name)
177     {
178         files.add( new String JavaDoc(name + "POA*.class") );
179         files.add( new String JavaDoc(name + "POATie.class") );
180     }
181
182     /**
183      * Add IDL Stub Class for a declaration to <files>, i.e. :
184      * - _<declaration_name>Stub
185      *
186      * @param files - A set of Files.
187      * @param name - The name of the declaration.
188      *
189      * @return The list of dependencies as a set of Files.
190      */

191     protected void
192     addStubClass(Set JavaDoc files, String JavaDoc name)
193     {
194         int index = name.lastIndexOf("/");
195
196         // Find the last package delimiter
197
if (index == -1)
198         {
199             files.add( new String JavaDoc("_" + name + "Stub.class") );
200         }
201         else
202         {
203             files.add( new String JavaDoc( name.substring(0, index+1) + "_" +
204                                    name.substring(index+1) + "Stub.class") );
205         }
206     }
207
208     // ==================================================================
209
//
210
// Public methods for org.objectweb.openccm.generator.cidl.api.IDL2DeclarationDependencies
211
//
212
// ==================================================================
213

214     /**
215      * Get Constant dependencies class files.
216      *
217      * @param aconst - Get dependencies from this constant.
218      * @param visited - List of previously visited declarations. Must not be null.
219      *
220      * @return The list of dependencies as a set of Files.
221      */

222     public Set JavaDoc
223     getConstantDependencies(ConstantDecl aconst,
224                             Set JavaDoc visited)
225     {
226         Set JavaDoc files = new java.util.HashSet JavaDoc();
227
228         // Test if this declaration was visited
229
if ( visited.contains(aconst) )
230         {
231             return files;
232         }
233         else
234         {
235             // Add this to visited declarations
236
visited.add(aconst);
237         }
238
239         if ( (aconst.getParent().getDeclKind() == DeclarationKind.dk_interface)
240              || (aconst.getParent().getDeclKind() == DeclarationKind.dk_abstract_interface)
241              || (aconst.getParent().getDeclKind() == DeclarationKind.dk_local_interface) )
242         {
243             String JavaDoc path = null;
244
245             path = _translator.getAsDirectory(aconst);
246             // Add the generated java interface
247
addObjectClass( files, path + aconst.getName() );
248         }
249
250         // Add type dependencies
251
files.addAll( getTypeRefDependencies(aconst.getType(), visited) );
252
253         // Add this to visited declarations
254
visited.add(aconst);
255
256         return files;
257     }
258
259     /**
260      * Get Enum dependencies class files.
261      *
262      * @param enumDecl - Get dependencies from this enumeration.
263      * @param visited - List of previously visited declarations. Must not be null.
264      *
265      * @return The list of dependencies as a set of Files.
266      */

267     public Set JavaDoc
268     getEnumDependencies(EnumDecl enumDecl,
269                         Set JavaDoc visited)
270     {
271         String JavaDoc path = null;
272         Set JavaDoc files = new java.util.HashSet JavaDoc();
273
274         // Test if this declaration was visited
275
if ( visited.contains(enumDecl) )
276         {
277             return files;
278         }
279         else
280         {
281             // Add this to visited declarations
282
visited.add(enumDecl);
283         }
284
285         path = _translator.getAsDirectory(enumDecl);
286         addStantardIdlFiles( files, path + enumDecl.getName() );
287
288         return files;
289     }
290
291     /**
292      * Get Struct dependencies class files.
293      *
294      * @param struct - Get dependencies from this structure.
295      * @param visited - List of previously visited declarations. Must not be null.
296      *
297      * @return The list of dependencies as a set of Files.
298      */

299     public Set JavaDoc
300     getStructDependencies(StructDecl struct,
301                           Set JavaDoc visited)
302     {
303         String JavaDoc path = null;
304         StructMember[] members = null;
305         Set JavaDoc files = new java.util.HashSet JavaDoc();
306
307         // Test if this declaration was visited
308
if ( visited.contains(struct) )
309         {
310             return files;
311         }
312         else
313         {
314             // Add this to visited declarations
315
visited.add(struct);
316         }
317
318         path = _translator.getAsDirectory(struct);
319         addStantardIdlFiles( files, path + struct.getName() );
320
321         // Add members dependencies
322
members = struct.getMemberList().getStructMembers();
323         for (int i=0; i<members.length; i++)
324         {
325             files.addAll( getTypeRefDependencies(members[i].getType(), visited) );
326         }
327
328         return files;
329     }
330
331     /**
332      * Get Union dependencies class files.
333      *
334      * @param union - Get dependencies from this union.
335      * @param visited - List of previously visited declarations. Must not be null.
336      *
337      * @return The list of dependencies as a set of Files.
338      */

339     public Set JavaDoc
340     getUnionDependencies(UnionDecl union,
341                          Set JavaDoc visited)
342     {
343         String JavaDoc path = null;
344         UnionMember[] members = null;
345         Set JavaDoc files = new java.util.HashSet JavaDoc();
346
347         // Test if this declaration was visited
348
if ( visited.contains(union) )
349         {
350             return files;
351         }
352         else
353         {
354             // Add this to visited declarations
355
visited.add(union);
356         }
357
358         path = _translator.getAsDirectory(union);
359         addStantardIdlFiles( files, path + union.getName() );
360
361         // discriminator dependencies
362
files.addAll( getTypeRefDependencies(union.getDiscriminator(), visited) );
363
364         // members dependencies
365
members = union.getMemberList().getUnionMembers();
366         for (int i=0; i<members.length; i++)
367         {
368             files.addAll( getTypeRefDependencies(members[i].getType(), visited) );
369         }
370
371         return files;
372     }
373
374     /**
375      * Get Abstract Interface dependencies class files.
376      *
377      * @param itf - Get dependencies from this abstrat interface.
378      * @param visited - List of previously visited declarations. Must not be null.
379      *
380      * @return The list of dependencies as a set of Files.
381      */

382     public Set JavaDoc
383     getAbstractInterfaceDependencies(AbstractInterfaceDecl itf,
384                                      Set JavaDoc visited)
385     {
386         String JavaDoc path = null;
387         InterfaceDecl[] bases = null;
388         Set JavaDoc files = new java.util.HashSet JavaDoc();
389
390         // Test if this declaration was visited
391
if ( visited.contains(itf) )
392         {
393             return files;
394         }
395         else
396         {
397             // Add this to visited declarations
398
visited.add(itf);
399         }
400
401         path = _translator.getAsDirectory(itf);
402         // object + helper + holder + stub
403
addStantardIdlFiles( files, path + itf.getName() );
404         addStubClass( files, path + itf.getName() );
405
406         // Add base interfaces dependencies
407
bases = itf.getInheritedInterfaceList().getInterfaces();
408         for (int i=0; i<bases.length; i++)
409         {
410             files.addAll( getAbstractInterfaceDependencies((AbstractInterfaceDecl) bases[i], visited) );
411         }
412
413         // Add contents dependencies
414
files.addAll( getContentsDependencies(itf, visited) );
415
416         return files;
417     }
418
419     /**
420      * Get Local Interface dependencies class files.
421      *
422      * @param itf - Get dependencies from this local interface.
423      * @param visited - List of previously visited declarations. Must not be null.
424      *
425      * @return The list of dependencies as a set of Files.
426      */

427     public Set JavaDoc
428     getLocalInterfaceDependencies(LocalInterfaceDecl itf,
429                                   Set JavaDoc visited)
430     {
431         String JavaDoc path = null;
432         InterfaceDecl[] bases = null;
433         Set JavaDoc files = new java.util.HashSet JavaDoc();
434
435         // Test if this declaration was visited
436
if ( visited.contains(itf) )
437         {
438             return files;
439         }
440         else
441         {
442             // Add this to visited declarations
443
visited.add(itf);
444         }
445
446         path = _translator.getAsDirectory(itf);
447         // object + helper + holder + operations
448
addStantardIdlFiles( files, path + itf.getName() );
449         addOperationsClass( files, path + itf.getName() );
450
451         // Add base interfaces dependencies
452
bases = itf.getInheritedInterfaceList().getInterfaces();
453         for (int i=0; i<bases.length; i++)
454         {
455             files.addAll( getLocalInterfaceDependencies((LocalInterfaceDecl) bases[i], visited) );
456         }
457
458         // Add contents dependencies
459
files.addAll( getContentsDependencies(itf, visited) );
460
461         return files;
462     }
463
464     /**
465      * Get Interface dependencies class files.
466      *
467      * @param itf - Get dependencies from this interface.
468      * @param server - If true, include server class files.
469      * @param visited - List of previously visited declarations. Must not be null.
470      *
471      * @return The list of dependencies as a set of Files.
472      */

473     public Set JavaDoc
474     getInterfaceDependencies(InterfaceDecl itf,
475                              boolean server,
476                              Set JavaDoc visited)
477     {
478         String JavaDoc path = null;
479         InterfaceDecl[] bases = null;
480         Set JavaDoc files = new java.util.HashSet JavaDoc();
481
482         // Test if this declaration was visited
483
if ( visited.contains(itf) )
484         {
485             return files;
486         }
487         else
488         {
489             // Add this to visited declarations
490
visited.add(itf);
491         }
492
493         path = _translator.getAsDirectory(itf);
494         // object + helper + holder + operations + poa + poatie + stub
495
addStantardIdlFiles( files, path + itf.getName() );
496         addStubClass( files, path + itf.getName() );
497         addOperationsClass( files, path + itf.getName() );
498         if (server)
499         {
500             addPoaIdlFiles( files, path + itf.getName() );
501         }
502
503         // Add base interfaces dependencies
504
bases = itf.getInheritedInterfaceList().getInterfaces();
505         for (int i=0; i<bases.length; i++)
506         {
507             files.addAll( getInterfaceDependencies(bases[i], server, visited) );
508         }
509
510         // Add contents dependencies
511
files.addAll( getContentsDependencies(itf, visited) );
512
513         return files;
514     }
515
516     /**
517      * Get Value Type dependencies class files.
518      *
519      * @param value - Get dependencies from this value type.
520      * @param visited - List of previously visited declarations. Must not be null.
521      *
522      * @return The list of dependencies as a set of Files.
523      */

524     public Set JavaDoc
525     getValueTypeDependencies(ValueDecl value,
526                              Set JavaDoc visited)
527     {
528         String JavaDoc path = null;
529         Set JavaDoc files = new java.util.HashSet JavaDoc();
530
531         // Test if this declaration was visited
532
if ( visited.contains(value) )
533         {
534             return files;
535         }
536         else
537         {
538             // Add this to visited declarations
539
visited.add(value);
540         }
541
542         path = _translator.getAsDirectory(value);
543         // object + helper + holder + ValueFactory
544
addStantardIdlFiles( files, path + value.getName() );
545         // ValueFactory class is omitted
546

547         // Add base value dependencies
548
if (value.getBaseValue() != null)
549         {
550             files.addAll( getValueTypeDependencies(value.getBaseValue(), visited) );
551         }
552
553         // Add abstract base values dependencies
554
ValueDecl[] abs = value.getAbstractValueList().getValues();
555         for (int i=0; i<abs.length; i++)
556         {
557             files.addAll( getValueTypeDependencies(abs[i], visited) );
558         }
559
560         // Add supported interfaces dependencies
561
InterfaceDecl[] supp = value.getSupportedInterfaceList().getInterfaces();
562         for (int i=0; i<supp.length; i++)
563         {
564             if (supp[i].getDeclKind() == DeclarationKind.dk_abstract_interface)
565             {
566                 files.addAll( getAbstractInterfaceDependencies((AbstractInterfaceDecl) supp[i], visited) );
567             }
568             else if (supp[i].getDeclKind() == DeclarationKind.dk_local_interface)
569             {
570                 files.addAll( getLocalInterfaceDependencies((LocalInterfaceDecl) supp[i], visited) );
571             }
572             // Interfaces dk_interface not supported
573
}
574
575         // Add initializers dependencies
576
Initializer[] inits = value.getInitializerList().getInitializers();
577         for (int i=0; i<inits.length; i++)
578         {
579             Parameter[] parameters = inits[i].getParameterList().
580                                      getParameters();
581             for (int j=0; j<parameters.length; j++)
582             {
583                 files.addAll( getTypeRefDependencies(parameters[j].getType(), visited) );
584             }
585         }
586
587         // Add contents dependencies
588
files.addAll( getContentsDependencies(value, visited) );
589
590         return files;
591     }
592
593     /**
594      * Get Value Box dependencies class files.
595      *
596      * @param box - Get dependencies from this value box.
597      * @param visited - List of previously visited declarations. Must not be null.
598      *
599      * @return The list of dependencies as a set of Files.
600      */

601     public Set JavaDoc
602     getValueBoxDependencies(ValueBoxDecl box,
603                             Set JavaDoc visited)
604     {
605         String JavaDoc path = null;
606         Set JavaDoc files = new java.util.HashSet JavaDoc();
607
608         // Test if this declaration was visited
609
if ( visited.contains(box) )
610         {
611             return files;
612         }
613         else
614         {
615             // Add this to visited declarations
616
visited.add(box);
617         }
618
619         path = _translator.getAsDirectory(box);
620         // if value box maps to a java primitive (ex: float) : object + helper + holder
621
// else helper + holder
622
// The object class is added in all cases (if not generated, not included in the jar)
623
addStantardIdlFiles( files, path + box.getName() );
624
625         // Add value box type dependencies
626
files.addAll( getTypeRefDependencies(box.getType(), visited) );
627
628         return files;
629     }
630
631     /**
632      * Get Exception dependencies class files.
633      *
634      * @param ex - Get dependencies from this exception.
635      * @param visited - List of previously visited declarations. Must not be null.
636      *
637      * @return The list of dependencies as a set of Files.
638      */

639     public Set JavaDoc
640     getExceptionDependencies(ExceptionDecl ex,
641                              Set JavaDoc visited)
642     {
643         String JavaDoc path = null;
644         StructMember[] members = null;
645         Set JavaDoc files = new java.util.HashSet JavaDoc();
646
647         // Test if this declaration was visited
648
if ( visited.contains(ex) )
649         {
650             return files;
651         }
652         else
653         {
654             // Add this to visited declarations
655
visited.add(ex);
656         }
657
658         path = _translator.getAsDirectory(ex);
659         addStantardIdlFiles( files, path + ex.getName() );
660
661         // Add members dependencies
662
members = ex.getMemberList().getStructMembers();
663         for (int i=0; i<members.length; i++)
664         {
665             files.addAll( getTypeRefDependencies(members[i].getType(), visited) );
666         }
667
668         return files;
669     }
670
671     /**
672      * Get Any Value dependencies class files.
673      *
674      * @param any - Get dependencies from this Any Value.
675      * @param visited - List of previously visited declarations. Must not be null.
676      *
677      * @return The list of dependencies as a set of Files.
678      */

679     public Set JavaDoc
680     getAnyValueDependencies(AnyValue any,
681                             Set JavaDoc visited)
682     {
683         // No dependencies
684
return new java.util.HashSet JavaDoc();
685     }
686
687     /**
688      * Get Alias dependencies class files.
689      *
690      * @param alias - Get dependencies from this Alias.
691      * @param visited - List of previously visited declarations. Must not be null.
692      *
693      * @return The list of dependencies as a set of Files.
694      */

695     public Set JavaDoc
696     getAliasDependencies(AliasDecl alias,
697                          Set JavaDoc visited)
698     {
699         String JavaDoc path = null;
700         Set JavaDoc files = new java.util.HashSet JavaDoc();
701         TypeKind tk = null;
702
703         // Test if this declaration was visited
704
if ( visited.contains(alias) )
705         {
706             return files;
707         }
708         else
709         {
710             // Add this to visited declarations
711
visited.add(alias);
712         }
713
714         path = _translator.getAsDirectory(alias);
715         addHelperClass( files, path + alias.getName() );
716
717         // Add alias type dependencies
718
files.addAll( getTypeRefDependencies(alias.getType(), visited) );
719
720         // If type is a sequence or an array, add the holder class
721
tk = alias.getType().getTypeKind();
722         if ( ( tk == TypeKind.tk_sequence)
723              || ( tk == TypeKind.tk_array) )
724         {
725             addHolderClass( files, path + alias.getName() );
726         }
727
728         return files;
729     }
730
731     /**
732      * Get Attribute dependencies class files.
733      *
734      * @param att - Get dependencies from this attribute.
735      * @param visited - List of previously visited declarations. Must not be null.
736      *
737      * @return The list of dependencies as a set of Files.
738      */

739     public Set JavaDoc
740     getAttributeDependencies(AttributeDecl att,
741                              Set JavaDoc visited)
742     {
743         Set JavaDoc files = new java.util.HashSet JavaDoc();
744
745         // Test if this declaration was visited
746
if ( visited.contains(att) )
747         {
748             return files;
749         }
750         else
751         {
752             // Add this to visited declarations
753
visited.add(att);
754         }
755
756         // Add attribute type dependencies
757
files.addAll( getTypeRefDependencies(att.getType(), visited) );
758
759         // Add attribute exceptions dependencies
760
ExceptionDecl[] excs = null;
761
762         if ( att.isReadonly() )
763         {
764             excs = att.getExceptions();
765             for (int i=0; i<excs.length; i++)
766                 files.addAll( getExceptionDependencies(excs[i], visited) );
767         }
768         else
769         {
770             excs = att.getGetExceptions();
771             for (int i=0; i<excs.length; i++)
772                 files.addAll( getExceptionDependencies(excs[i], visited) );
773
774             excs = att.getSetExceptions();
775             for (int i=0; i<excs.length; i++)
776                 files.addAll( getExceptionDependencies(excs[i], visited) );
777         }
778
779         return files;
780     }
781
782     /**
783      * Get Operation dependencies class files.
784      *
785      * @param op - Get dependencies from this operation.
786      * @param visited - List of previously visited declarations. Must not be null.
787      *
788      * @return The list of dependencies as a set of Files.
789      */

790     public Set JavaDoc
791     getOperationDependencies(OperationDecl op,
792                              Set JavaDoc visited)
793     {
794         Set JavaDoc files = new java.util.HashSet JavaDoc();
795
796         // Test if this declaration was visited
797
if ( visited.contains(op) )
798         {
799             return files;
800         }
801         else
802         {
803             // Add this to visited declarations
804
visited.add(op);
805         }
806
807         // Add operation return type dependencies
808
files.addAll( getTypeRefDependencies(op.getType(), visited) );
809
810         // Add operation exceptions dependencies
811
ExceptionDecl[] excs = op.getExceptionList().getExceptions();
812         for (int i=0; i<excs.length; i++)
813         {
814             files.addAll( getExceptionDependencies(excs[i], visited) );
815         }
816
817         // Add operation parameters type dependencies
818
Parameter[] parameters = op.getParameterList().getParameters();
819         for (int i=0;i<parameters.length;i++)
820         {
821             files.addAll( getTypeRefDependencies(parameters[i].getType(), visited) );
822         }
823
824         return files;
825     }
826
827     /**
828      * Get dependencies for IDL2 scope contents.
829      *
830      * @param scope - Get dependencies for scope contents.
831      * @param visited - List of previously visited declarations. Must not be null.
832      *
833      * @return The list of dependencies as a set of Files.
834      */

835     public Set JavaDoc
836     getContentsDependencies(Scope scope,
837                             Set JavaDoc visited)
838     {
839         Set JavaDoc files = null;
840         Declaration[] decls = null;
841
842         files = new java.util.HashSet JavaDoc();
843         decls = scope.getContents(true, DeclarationKind.dk_all);
844
845         for (int i=0; i<decls.length; i++)
846         {
847             files.addAll( getDeclarationDependencies(decls[i], visited) );
848         }
849
850         return files;
851     }
852
853     /**
854      * Get dependencies for an IDL2 declaration.
855      *
856      * @param decl - Get dependencies for this declaration.
857      * @param visited - List of previously visited declarations. Must not be null.
858      *
859      * @return The list of dependencies as a set of Files.
860      */

861     public Set JavaDoc
862     getDeclarationDependencies(Declaration decl,
863                                Set JavaDoc visited)
864     {
865         Set JavaDoc files = null;
866
867         files = new java.util.HashSet JavaDoc();
868
869         // Test if this declaration was visited (to avoid following tests)
870
if ( visited.contains(decl) )
871         {
872             return files;
873         }
874
875         if (decl.getDeclKind() == DeclarationKind.dk_module)
876         {
877             files.addAll( getContentsDependencies((Scope) decl, visited) );
878         }
879         else if (decl.getDeclKind() == DeclarationKind.dk_abstract_interface)
880         {
881             files.addAll( getAbstractInterfaceDependencies((AbstractInterfaceDecl) decl, visited) );
882         }
883         else if (decl.getDeclKind() == DeclarationKind.dk_local_interface)
884         {
885             files.addAll( getLocalInterfaceDependencies((LocalInterfaceDecl) decl, visited) );
886         }
887         else if (decl.getDeclKind() == DeclarationKind.dk_interface)
888         {
889             // Add a server parameter to getContentsDependencies
890
files.addAll( getInterfaceDependencies((InterfaceDecl) decl, false, visited) );
891         }
892         else if (decl.getDeclKind() == DeclarationKind.dk_attribute)
893         {
894             files.addAll( getAttributeDependencies((AttributeDecl) decl, visited) );
895         }
896         else if (decl.getDeclKind() == DeclarationKind.dk_alias)
897         {
898             files.addAll( getAliasDependencies((AliasDecl) decl, visited) );
899         }
900         else if (decl.getDeclKind() == DeclarationKind.dk_constant)
901         {
902             files.addAll( getConstantDependencies((ConstantDecl) decl, visited) );
903         }
904         else if (decl.getDeclKind() == DeclarationKind.dk_enum)
905         {
906             files.addAll( getEnumDependencies((EnumDecl) decl, visited) );
907         }
908         else if (decl.getDeclKind() == DeclarationKind.dk_exception)
909         {
910             files.addAll( getExceptionDependencies((ExceptionDecl) decl, visited) );
911         }
912         else if (decl.getDeclKind() == DeclarationKind.dk_operation)
913         {
914             files.addAll( getOperationDependencies((OperationDecl) decl, visited) );
915         }
916         else if (decl.getDeclKind() == DeclarationKind.dk_struct)
917         {
918             files.addAll( getStructDependencies((StructDecl) decl, visited) );
919         }
920         else if (decl.getDeclKind() == DeclarationKind.dk_union)
921         {
922             files.addAll( getUnionDependencies((UnionDecl) decl, visited) );
923         }
924         else if (decl.getDeclKind() == DeclarationKind.dk_value_box)
925         {
926             files.addAll( getValueBoxDependencies((ValueBoxDecl) decl, visited) );
927         }
928         else if (decl.getDeclKind() == DeclarationKind.dk_value)
929         {
930             files.addAll( getValueTypeDependencies((ValueDecl) decl, visited) );
931         }
932         else if (decl.getDeclKind() == DeclarationKind.dk_value_member)
933         {
934             ValueMemberDecl member = null;
935
936             // Add this to visited declarations
937
visited.add(member);
938
939             member = (ValueMemberDecl) decl;
940             files.addAll( getTypeRefDependencies(member.getType(), visited) );
941         }
942         else
943         {
944             // Nothing to do
945
// Not managed : dk_null and dk_native
946
}
947
948         return files;
949     }
950
951     /**
952      * Get Type Reference dependencies class files.
953      *
954      * @param aconst - Get dependencies from this type reference.
955      * @param visited - List of previously visited declarations. Must not be null.
956      *
957      * @return The list of dependencies as a set of Files.
958      */

959     public Set JavaDoc
960     getTypeRefDependencies(TypeRef type,
961                            Set JavaDoc visited)
962     {
963         TypeKind tk = null;
964         Set JavaDoc files = new java.util.HashSet JavaDoc();
965
966         tk = type.getTypeKind();
967
968         // If type is a declaration, add declaration dependencies
969
if (type.isDeclaration())
970         {
971             Declaration decl = (Declaration) type;
972
973             if (tk == TypeKind.tk_struct)
974             {
975                 files.addAll( getStructDependencies((StructDecl) decl, visited) );
976             }
977             else if (tk == TypeKind.tk_union)
978             {
979                 files.addAll( getUnionDependencies((UnionDecl) decl, visited) );
980             }
981             else if (tk == TypeKind.tk_enum)
982             {
983                 files.addAll( getEnumDependencies((EnumDecl) decl, visited) );
984             }
985             else if (tk == TypeKind.tk_exception)
986             {
987                 files.addAll( getExceptionDependencies((ExceptionDecl) decl, visited) );
988             }
989             else if (tk == TypeKind.tk_value_box)
990             {
991                 files.addAll( getValueBoxDependencies((ValueBoxDecl) decl, visited) );
992             }
993             else if (tk == TypeKind.tk_value)
994             {
995                 files.addAll( getValueTypeDependencies((ValueDecl) decl, visited) );
996             }
997             else if (tk == TypeKind.tk_abstract_interface)
998             {
999                 files.addAll( getAbstractInterfaceDependencies((AbstractInterfaceDecl) decl, visited) );
1000            }
1001            else if (tk == TypeKind.tk_local_interface)
1002            {
1003                files.addAll( getLocalInterfaceDependencies((LocalInterfaceDecl) decl, visited) );
1004            }
1005            else if (tk == TypeKind.tk_interface)
1006            {
1007                files.addAll( getInterfaceDependencies((InterfaceDecl) decl, false, visited) );
1008            }
1009            else if (tk == TypeKind.tk_alias)
1010            {
1011                files.addAll( getAliasDependencies((AliasDecl) decl, visited) );
1012            }
1013        }
1014
1015        return files;
1016    }
1017
1018    // ==================================================================
1019
//
1020
// Public methods.
1021
//
1022
// ==================================================================
1023

1024}
1025
Popular Tags