1   // Copyright 2012- Bill Campbell, Swami Iyer and Bahar Akbal-Delibas
2   
3   package jminusminus;
4   
5   import java.util.ArrayList;
6   
7   /**
8    * A representation of an interface declaration.
9    */
10  class JInterfaceDeclaration extends JAST implements JTypeDecl {
11      // Interface modifiers.
12      private ArrayList<String> mods;
13  
14      // Interface name.
15      private String name;
16  
17      // This interface type.
18      private Type thisType;
19  
20      // Super class type.
21      private Type superType;
22  
23      // Extended interfaces.
24      private ArrayList<TypeName> superInterfaces;
25  
26      // Interface block.
27      private ArrayList<JMember> interfaceBlock;
28  
29      // Context for this interface.
30      private ClassContext context;
31  
32      /**
33       * Constructs an AST node for an interface declaration.
34       *
35       * @param line            line in which the interface declaration occurs in the source file.
36       * @param mods            class modifiers.
37       * @param name            class name.
38       * @param superInterfaces super class types.
39       * @param interfaceBlock  interface block.
40       */
41      public JInterfaceDeclaration(int line, ArrayList<String> mods, String name,
42                                   ArrayList<TypeName> superInterfaces,
43                                   ArrayList<JMember> interfaceBlock) {
44          super(line);
45          this.mods = mods;
46          this.name = name;
47          this.superType = Type.OBJECT;
48          this.superInterfaces = superInterfaces;
49          this.interfaceBlock = interfaceBlock;
50      }
51  
52      /**
53       * {@inheritDoc}
54       */
55      public void declareThisType(Context context) {
56          // TODO
57      }
58  
59      /**
60       * {@inheritDoc}
61       */
62      public void preAnalyze(Context context) {
63          // TODO
64      }
65  
66      /**
67       * {@inheritDoc}
68       */
69      public String name() {
70          return name;
71      }
72  
73      /**
74       * {@inheritDoc}
75       */
76      public Type superType() {
77          return superType;
78      }
79  
80      /**
81       * {@inheritDoc}
82       */
83      public ArrayList<TypeName> superInterfaces() {
84          return superInterfaces;
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      public Type thisType() {
91          // TODO
92          return null;
93      }
94  
95      /**
96       * {@inheritDoc}
97       */
98      public JAST analyze(Context context) {
99          // TODO
100         return this;
101     }
102 
103     /**
104      * {@inheritDoc}
105      */
106     public void codegen(CLEmitter output) {
107         // TODO
108     }
109 
110     /**
111      * {@inheritDoc}
112      */
113     public void toJSON(JSONElement json) {
114         JSONElement e = new JSONElement();
115         json.addChild("JInterfaceDeclaration:" + line, e);
116         if (mods != null) {
117             ArrayList<String> value = new ArrayList<String>();
118             for (String mod : mods) {
119                 value.add(String.format("\"%s\"", mod));
120             }
121             e.addAttribute("modifiers", value);
122         }
123         e.addAttribute("name", name);
124         e.addAttribute("super", superType == null ? "" : superType.toString());
125         if (superInterfaces != null) {
126             ArrayList<String> value = new ArrayList<String>();
127             for (TypeName impl : superInterfaces) {
128                 value.add(String.format("\"%s\"", impl.toString()));
129             }
130             e.addAttribute("extends", value);
131         }
132         if (context != null) {
133             context.toJSON(e);
134         }
135         if (interfaceBlock != null) {
136             for (JMember member : interfaceBlock) {
137                 ((JAST) member).toJSON(e);
138             }
139         }
140     }
141 }
142