1 /* <lambda>null2 * 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.EnumDeclarationParser 21 import writer.formatTextasHTML 22 import writer.htmlEscape 23 24 class EnumElement(parser: EntryParser) : AbstractElement(parser) { 25 //name [String], type [String], members [EnumMember: name, value?] 26 override val declarationParser = parser.declarationParser as EnumDeclarationParser 27 28 override fun declaration(): String { 29 return "enum ${declarationParser.name}: ${declarationParser.type}" 30 } 31 32 override fun detailsRows(): String { 33 //build member rows 34 val sb = StringBuilder() 35 if (declarationParser.members.isNotEmpty()) { 36 sb.append(""" 37 <tr> 38 <td>Members</td> 39 <td> 40 <table class="function param responsive"> 41 <tbody>""") 42 //EnumMember => name, value? 43 declarationParser.members.forEach { arg -> 44 val fieldVal = arg.value?.let { " = ${htmlEscape(it)}" } ?: "" 45 val fieldDesc = arg.docParser?.description?.let { formatTextasHTML(it, useParagraphs = false) } ?: "" 46 sb.append(""" 47 <tr> 48 <td> 49 <code>${htmlEscape(arg.name)}${fieldVal}</code> 50 </td> 51 <td> 52 <div>$fieldDesc</div> 53 </td> 54 </tr>""") 55 } 56 sb.append(""" 57 </tbody> 58 </table> 59 </td> 60 </tr>""") 61 } 62 return sb.toString().trim() 63 } 64 }