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.files 18 19 import parser.config 20 import parser.files.AbstractFileParser 21 import writer.elements.CompoundElement 22 import writer.elements.EnumElement 23 import writer.elements.TypedefElement 24 import writer.getOutPath 25 import java.nio.file.Path 26 27 abstract class AbstractParserFileWriter(private val parser: AbstractFileParser) : AbstractFileWriter() { 28 29 override val baseName = parser.name 30 override val templateResource: String by lazy { "/resources/template/${this.baseName}.html" } 31 override val path: Path by lazy { getOutPath(parser, config.outDir) } 32 33 override fun replaceVars() { 34 replaceVar("name", parser.name) 35 36 replaceVar("propertyDefs") { 37 val sb = StringBuilder() 38 39 if (parser.typedefs.isNotEmpty() 40 || parser.enums.isNotEmpty() 41 || parser.structs.isNotEmpty() 42 || parser.unions.isNotEmpty()) { 43 sb.append("<section>\n") 44 sb.append("<h2>Properties</h2>\n") 45 //typedefs 46 sb.append(parser.typedefs.map { TypedefElement(it).toHTML() }.joinToString("\n")) 47 //enums 48 sb.append(parser.enums.map { EnumElement(it).toHTML() }.joinToString("\n")) 49 //structs 50 sb.append(parser.structs.map { CompoundElement(it).toHTML() }.joinToString("\n")) 51 //unions 52 sb.append(parser.unions.map { CompoundElement(it).toHTML() }.joinToString("\n")) 53 sb.append("\n</section>\n") 54 } 55 sb.toString() 56 } 57 } 58 59 override fun printInfo() { 60 super.printInfo() 61 println(" AbstractParserFileWriter:") 62 println(" package: ${parser.packageName}") 63 println(" package ver: ${parser.packageVersion}") 64 println(" enums count: ${parser.enums.size}") 65 println(" structs count: ${parser.structs.size}") 66 println(" unions count: ${parser.unions.size}") 67 println(" typedefs count: ${parser.typedefs.size}") 68 } 69 }