Home | History | Annotate | Download | only in elements
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package writer.elements
     18 
     19 import parser.elements.EntryParser
     20 import parser.elements.declarations.CompoundDeclarationParser
     21 import parser.elements.declarations.CompoundMemberDeclaration
     22 import writer.formatTextasHTML
     23 
     24 // used for structs and unions
     25 class CompoundElement(parser: EntryParser): AbstractElement(parser) {
     26     //type, name, members [IMemberDeclaration]
     27     override val declarationParser = parser.declarationParser as CompoundDeclarationParser
     28 
     29     override fun declaration(): String {
     30         val sb = StringBuilder()
     31         sb.append("${declarationParser.type.value} ${declarationParser.name} {")
     32         declarationParser.members.forEachIndexed { i, arg ->
     33             val typedef = if (arg is CompoundMemberDeclaration) "${arg.typeDef.value} " else ""
     34             sb.append("${typedef}${arg.type} ${arg.name}")
     35             if (i < declarationParser.members.size-1) sb.append("; ")
     36         }
     37         sb.append("}")
     38         return sb.toString()
     39     }
     40 
     41     override fun detailsRows(): String {
     42         //build member rows
     43         val sb = StringBuilder()
     44         if (declarationParser.members.isNotEmpty()) {
     45             sb.append("""
     46             <tr>
     47               <td>Members</td>
     48               <td>
     49                 <table class="function param responsive">
     50                   <tbody>""")
     51             //type, name, tokens, typedef
     52             declarationParser.members.forEach { arg ->
     53                 val fieldDesc = arg.docParser?.description?.let { formatTextasHTML(it, useParagraphs = false) } ?: ""
     54                 sb.append("""
     55                 <tr>
     56                   <td>
     57                     <code>${arg.name}</code>
     58                   </td>
     59                   <td>
     60                     <div>${fieldDesc}</div>
     61                   </td>
     62                 </tr>""")
     63             }
     64             sb.append("""
     65                   </tbody>
     66                 </table>
     67               </td>
     68             </tr>""")
     69         }
     70         return sb.toString()
     71     }
     72 }