remove warnings in kdoc code
This commit is contained in:
+4
-6
@@ -50,12 +50,10 @@ class JavadocStyleHtmlDoclet() : Doclet {
|
|||||||
classes.addAll(map.keySet())
|
classes.addAll(map.keySet())
|
||||||
classes.addAll(pmap.keySet())
|
classes.addAll(pmap.keySet())
|
||||||
for (c in classes) {
|
for (c in classes) {
|
||||||
if (c != null) {
|
val functions = map.get(c).orEmpty()
|
||||||
val functions = map.get(c).orEmpty()
|
val properties = pmap.get(c).orEmpty()
|
||||||
val properties = pmap.get(c).orEmpty()
|
run("${p.nameAsPath}/${c.nameAsPath}-extensions.html",
|
||||||
run("${p.nameAsPath}/${c.nameAsPath}-extensions.html",
|
ClassExtensionsTemplate(model, p, c, functions, properties))
|
||||||
ClassExtensionsTemplate(model, p, c, functions, properties))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ class KDocCompiler() : K2JVMCompiler() {
|
|||||||
|
|
||||||
protected override fun configureEnvironment(configuration : K2JVMCompileEnvironmentConfiguration, arguments : K2JVMCompilerArguments) {
|
protected override fun configureEnvironment(configuration : K2JVMCompileEnvironmentConfiguration, arguments : K2JVMCompilerArguments) {
|
||||||
super.configureEnvironment(configuration, arguments)
|
super.configureEnvironment(configuration, arguments)
|
||||||
val coreEnvironment = configuration?.getEnvironment()
|
val coreEnvironment = configuration.getEnvironment()
|
||||||
if (coreEnvironment != null) {
|
if (coreEnvironment != null) {
|
||||||
val kdoc = KDoc()
|
val kdoc = KDoc()
|
||||||
|
|
||||||
if (arguments is KDocArguments) {
|
if (arguments is KDocArguments) {
|
||||||
kdoc.config = arguments.apply()
|
kdoc.config = arguments.apply()
|
||||||
}
|
}
|
||||||
val plugins = configuration?.getCompilerPlugins().orEmpty()
|
val plugins = configuration.getCompilerPlugins().orEmpty()
|
||||||
/*
|
/*
|
||||||
val sourcePlugin = HtmlCompilerPlugin()
|
val sourcePlugin = HtmlCompilerPlugin()
|
||||||
plugins.add(sourcePlugin)
|
plugins.add(sourcePlugin)
|
||||||
@@ -45,7 +45,7 @@ class KDocCompiler() : K2JVMCompiler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override fun usage(target : PrintStream) {
|
protected override fun usage(target : PrintStream) {
|
||||||
target?.println("Usage: KDocCompiler -docOutput <docOutputDir> [-output <outputDir>|-jar <jarFileName>] [-stdlib <path to runtime.jar>] [-src <filename or dirname>|-module <module file>] [-includeRuntime]");
|
target.println("Usage: KDocCompiler -docOutput <docOutputDir> [-output <outputDir>|-jar <jarFileName>] [-stdlib <path to runtime.jar>] [-src <filename or dirname>|-module <module file>] [-includeRuntime]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,10 +95,8 @@ class KDocConfig() {
|
|||||||
for (e in packagePrefixToUrls) {
|
for (e in packagePrefixToUrls) {
|
||||||
val p = e.key
|
val p = e.key
|
||||||
val url = e.value
|
val url = e.value
|
||||||
if (p != null && url != null) {
|
if (packageName.startsWith(p)) {
|
||||||
if (packageName.startsWith(p)) {
|
return url
|
||||||
return url
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (warn && missingPackageUrls.add(packageName)) {
|
if (warn && missingPackageUrls.add(packageName)) {
|
||||||
@@ -123,4 +121,4 @@ private class LongestFirstStringComparator() : Comparator<String> {
|
|||||||
public override fun equals(obj : Any?) : Boolean {
|
public override fun equals(obj : Any?) : Boolean {
|
||||||
return obj is LongestFirstStringComparator
|
return obj is LongestFirstStringComparator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-10
@@ -8,17 +8,12 @@ import org.jetbrains.jet.cli.common.CompilerPluginContext
|
|||||||
class HtmlCompilerPlugin: CompilerPlugin {
|
class HtmlCompilerPlugin: CompilerPlugin {
|
||||||
|
|
||||||
public override fun processFiles(context: CompilerPluginContext) {
|
public override fun processFiles(context: CompilerPluginContext) {
|
||||||
val bindingContext = context.getContext()
|
|
||||||
val files = context.getFiles()
|
val files = context.getFiles()
|
||||||
if (bindingContext != null && files != null) {
|
for (file in files) {
|
||||||
if (files != null && bindingContext != null) {
|
if (file != null) {
|
||||||
for (file in files) {
|
val visitor = HtmlKotlinVisitor()
|
||||||
if (file != null) {
|
file.accept(visitor)
|
||||||
val visitor = HtmlKotlinVisitor()
|
|
||||||
file.accept(visitor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -53,7 +53,7 @@ class SyntaxHighligher() {
|
|||||||
if (token is JetKeywordToken) {
|
if (token is JetKeywordToken) {
|
||||||
style = "keyword"
|
style = "keyword"
|
||||||
} else if (token == JetTokens.IDENTIFIER) {
|
} else if (token == JetTokens.IDENTIFIER) {
|
||||||
val types = JetTokens.SOFT_KEYWORDS?.getTypes()
|
val types = JetTokens.SOFT_KEYWORDS.getTypes()
|
||||||
if (types != null) {
|
if (types != null) {
|
||||||
for (softKeyword in types) {
|
for (softKeyword in types) {
|
||||||
if (softKeyword is JetKeywordToken) {
|
if (softKeyword is JetKeywordToken) {
|
||||||
@@ -135,4 +135,4 @@ class SyntaxHighligher() {
|
|||||||
putAll(JetTokens.OPERATIONS, "operation")
|
putAll(JetTokens.OPERATIONS, "operation")
|
||||||
return styleMap
|
return styleMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+59
-68
@@ -328,13 +328,14 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
|||||||
val rootDir = projectRootDir()
|
val rootDir = projectRootDir()
|
||||||
val canonicalFile = File(filePath).getCanonicalPath() ?: ""
|
val canonicalFile = File(filePath).getCanonicalPath() ?: ""
|
||||||
//println("=========== root dir for filePath: $canonicalFile is $rootDir")
|
//println("=========== root dir for filePath: $canonicalFile is $rootDir")
|
||||||
val relativeFile = if (rootDir != null && canonicalFile.startsWith(rootDir))
|
val relativeFile =
|
||||||
canonicalFile.substring(rootDir.length()) else canonicalFile
|
if (canonicalFile.startsWith(rootDir))
|
||||||
if (relativeFile != null) {
|
canonicalFile.substring(rootDir.length())
|
||||||
val cleanRoot = root.trimTrailing("/")
|
else
|
||||||
val cleanPath = relativeFile.trimLeading("/")
|
canonicalFile
|
||||||
return "$cleanRoot/$cleanPath$lineLinkText$sourceLine"
|
val cleanRoot = root.trimTrailing("/")
|
||||||
}
|
val cleanPath = relativeFile.trimLeading("/")
|
||||||
|
return "$cleanRoot/$cleanPath$lineLinkText$sourceLine"
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -357,7 +358,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
|||||||
val descriptors = scope.getAllDescriptors()
|
val descriptors = scope.getAllDescriptors()
|
||||||
for (descriptor in descriptors) {
|
for (descriptor in descriptors) {
|
||||||
if (descriptor is PropertyDescriptor) {
|
if (descriptor is PropertyDescriptor) {
|
||||||
val name = descriptor.getName()?.getName()
|
val name = descriptor.getName().getName()
|
||||||
val returnType = getType(descriptor.getReturnType())
|
val returnType = getType(descriptor.getReturnType())
|
||||||
if (returnType != null) {
|
if (returnType != null) {
|
||||||
val receiver = descriptor.getReceiverParameter()
|
val receiver = descriptor.getReceiverParameter()
|
||||||
@@ -385,7 +386,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
|||||||
protected fun createFunction(owner: KClassOrPackage, descriptor: CallableDescriptor): KFunction? {
|
protected fun createFunction(owner: KClassOrPackage, descriptor: CallableDescriptor): KFunction? {
|
||||||
val returnType = getType(descriptor.getReturnType())
|
val returnType = getType(descriptor.getReturnType())
|
||||||
if (returnType != null) {
|
if (returnType != null) {
|
||||||
val name = descriptor.getName()?.getName() ?: "null"
|
val name = descriptor.getName().getName()
|
||||||
val parameters = ArrayList<KParameter>()
|
val parameters = ArrayList<KParameter>()
|
||||||
val params = descriptor.getValueParameters()
|
val params = descriptor.getValueParameters()
|
||||||
for (param in params) {
|
for (param in params) {
|
||||||
@@ -422,7 +423,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun createTypeParameter(descriptor: TypeParameterDescriptor): KTypeParameter? {
|
protected fun createTypeParameter(descriptor: TypeParameterDescriptor): KTypeParameter? {
|
||||||
val name = descriptor.getName()?.getName()
|
val name = descriptor.getName().getName()
|
||||||
val answer = KTypeParameter(name, descriptor, this)
|
val answer = KTypeParameter(name, descriptor, this)
|
||||||
configureComments(answer, descriptor)
|
configureComments(answer, descriptor)
|
||||||
return answer
|
return answer
|
||||||
@@ -431,7 +432,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
|||||||
protected fun createParameter(descriptor: ValueParameterDescriptor): KParameter? {
|
protected fun createParameter(descriptor: ValueParameterDescriptor): KParameter? {
|
||||||
val returnType = getType(descriptor.getReturnType())
|
val returnType = getType(descriptor.getReturnType())
|
||||||
if (returnType != null) {
|
if (returnType != null) {
|
||||||
val name = descriptor.getName()?.getName()
|
val name = descriptor.getName().getName()
|
||||||
val answer = KParameter(descriptor, name, returnType)
|
val answer = KParameter(descriptor, name, returnType)
|
||||||
configureComments(answer, descriptor)
|
configureComments(answer, descriptor)
|
||||||
return answer
|
return answer
|
||||||
@@ -486,31 +487,27 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
|||||||
var text = node?.getText() ?: ""
|
var text = node?.getText() ?: ""
|
||||||
// lets remove the comment tokens
|
// lets remove the comment tokens
|
||||||
val lines = text.trim().split("\\n")
|
val lines = text.trim().split("\\n")
|
||||||
if (lines != null) {
|
// lets remove the /** ... * ... */ tokens
|
||||||
// lets remove the /** ... * ... */ tokens
|
val buffer = StringBuilder()
|
||||||
val buffer = StringBuilder()
|
val last = lines.size - 1
|
||||||
val last = lines.size - 1
|
for (i in 0.upto(last)) {
|
||||||
for (i in 0.upto(last)) {
|
var text = lines[i] ?: ""
|
||||||
var text = lines[i] ?: ""
|
text = text.trim()
|
||||||
text = text.trim()
|
if (i == 0) {
|
||||||
if (i == 0) {
|
text = text.trimLeading("/**").trimLeading("/*")
|
||||||
text = text.trimLeading("/**").trimLeading("/*")
|
} else {
|
||||||
} else {
|
buffer.append("\n")
|
||||||
buffer.append("\n")
|
|
||||||
}
|
|
||||||
if (i >= last) {
|
|
||||||
text = text.trimTrailing("*/")
|
|
||||||
} else if (i > 0) {
|
|
||||||
text = text.trimLeading("* ")
|
|
||||||
if (text == "*") text = ""
|
|
||||||
}
|
|
||||||
text = processMacros(text, psiElement)
|
|
||||||
buffer.append(text)
|
|
||||||
}
|
}
|
||||||
return buffer.toString() ?: ""
|
if (i >= last) {
|
||||||
} else {
|
text = text.trimTrailing("*/")
|
||||||
return text
|
} else if (i > 0) {
|
||||||
|
text = text.trimLeading("* ")
|
||||||
|
if (text == "*") text = ""
|
||||||
|
}
|
||||||
|
text = processMacros(text, psiElement)
|
||||||
|
buffer.append(text)
|
||||||
}
|
}
|
||||||
|
return buffer.toString() ?: ""
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -527,7 +524,7 @@ class KModel(var context: BindingContext, val config: KDocConfig) {
|
|||||||
// TODO we could default the test function name to match that of the
|
// TODO we could default the test function name to match that of the
|
||||||
// source code function if folks adopted a convention of naming the test method after the
|
// source code function if folks adopted a convention of naming the test method after the
|
||||||
// method its acting as a demo/test for
|
// method its acting as a demo/test for
|
||||||
if (words != null && words.size > 1) {
|
if (words.size > 1) {
|
||||||
val includeFile = words[0].sure()
|
val includeFile = words[0].sure()
|
||||||
val fnName = words[1].sure()
|
val fnName = words[1].sure()
|
||||||
val content = findFunctionInclude(psiElement, includeFile, fnName)
|
val content = findFunctionInclude(psiElement, includeFile, fnName)
|
||||||
@@ -628,22 +625,20 @@ $highlight"""
|
|||||||
|
|
||||||
// lets try resolve the include name relative to this file
|
// lets try resolve the include name relative to this file
|
||||||
val paths = relativeName.split("/")
|
val paths = relativeName.split("/")
|
||||||
if (paths != null) {
|
val size = paths.size
|
||||||
val size = paths.size
|
for (i in 0.upto(size - 2)) {
|
||||||
for (i in 0.upto(size - 2)) {
|
val path = paths[i]
|
||||||
val path = paths[i]
|
if (path == ".") continue
|
||||||
if (path == ".") continue
|
else if (path == "..") dir = dir?.getParent()
|
||||||
else if (path == "..") dir = dir?.getParent()
|
else dir = dir?.findSubdirectory(path)
|
||||||
else if (path != null) dir = dir?.findSubdirectory(path)
|
}
|
||||||
}
|
val name = paths[size - 1]
|
||||||
val name = paths[size - 1]
|
if (dir != null) {
|
||||||
if (dir != null && name != null) {
|
val file = dir?.findFile(name)
|
||||||
val file = dir?.findFile(name)
|
if (file != null) {
|
||||||
if (file != null) {
|
return file
|
||||||
return file
|
} else {
|
||||||
} else {
|
warning("could not find file $relativeName in $dir with name $name")
|
||||||
warning("could not find file $relativeName in $dir with name $name")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
@@ -672,30 +667,28 @@ $highlight"""
|
|||||||
// TODO warning this only works for top level classes
|
// TODO warning this only works for top level classes
|
||||||
// a better algorithm is to walk down each dot path dealing with nested packages/classes
|
// a better algorithm is to walk down each dot path dealing with nested packages/classes
|
||||||
val idx = qualifiedName.lastIndexOf('.')
|
val idx = qualifiedName.lastIndexOf('.')
|
||||||
val pkgName = if (idx >= 0) qualifiedName.substring(0, idx) ?: "" else ""
|
val pkgName = if (idx >= 0) qualifiedName.substring(0, idx) else ""
|
||||||
val pkg = getPackage(pkgName)
|
val pkg = getPackage(pkgName)
|
||||||
if (pkg != null) {
|
if (pkg != null) {
|
||||||
val simpleName = if (idx >= 0) qualifiedName.substring(idx + 1) ?: "" else qualifiedName
|
val simpleName = if (idx >= 0) qualifiedName.substring(idx + 1) else qualifiedName
|
||||||
return pkg.classMap.get(simpleName)
|
return pkg.classMap.get(simpleName)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getClass(classElement: ClassDescriptor): KClass? {
|
fun getClass(classElement: ClassDescriptor): KClass? {
|
||||||
val name = classElement.getName()?.getName()
|
val name = classElement.getName().getName()
|
||||||
if (name != null) {
|
var dec: DeclarationDescriptor? = classElement.getContainingDeclaration()
|
||||||
var dec: DeclarationDescriptor? = classElement.getContainingDeclaration()
|
while (dec != null) {
|
||||||
while (dec != null) {
|
val container = dec
|
||||||
val container = dec
|
if (container is NamespaceDescriptor) {
|
||||||
if (container is NamespaceDescriptor) {
|
val pkg = getPackage(container)
|
||||||
val pkg = getPackage(container)
|
return pkg.getClass(name, classElement)
|
||||||
return pkg.getClass(name, classElement)
|
} else {
|
||||||
} else {
|
dec = dec?.getContainingDeclaration()
|
||||||
dec = dec?.getContainingDeclaration()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
warning("no package found for class $name")
|
|
||||||
}
|
}
|
||||||
|
warning("no package found for class $name")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -973,9 +966,7 @@ class KPackage(model: KModel, val descriptor: NamespaceDescriptor,
|
|||||||
get() {
|
get() {
|
||||||
val answer = ArrayList<String>()
|
val answer = ArrayList<String>()
|
||||||
for (n in name.split("\\.")) {
|
for (n in name.split("\\.")) {
|
||||||
if (n != null) {
|
answer.add(n)
|
||||||
answer.add(n)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ class HtmlVisitorTest {
|
|||||||
val args = K2JVMCompilerArguments()
|
val args = K2JVMCompilerArguments()
|
||||||
args.setSrc(srcDir.toString())
|
args.setSrc(srcDir.toString())
|
||||||
args.setOutputDir(File(dir, "target/classes-htmldocs").toString())
|
args.setOutputDir(File(dir, "target/classes-htmldocs").toString())
|
||||||
args.getCompilerPlugins()?.add(HtmlCompilerPlugin())
|
args.getCompilerPlugins().add(HtmlCompilerPlugin())
|
||||||
|
|
||||||
val compiler = K2JVMCompiler()
|
val compiler = K2JVMCompiler()
|
||||||
compiler.exec(System.out, args)
|
compiler.exec(System.out, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user