Kapt3: Allow function overloads based on return type (KT-14996). Fix wrong facade class name inside the default package

This commit is contained in:
Yan Zhulanow
2016-11-29 19:51:41 +03:00
committed by Yan Zhulanow
parent 6217d21c24
commit 01c76153c7
6 changed files with 73 additions and 1 deletions
@@ -21,6 +21,7 @@ import com.sun.tools.javac.main.JavaCompiler
import com.sun.tools.javac.util.Context
import com.sun.tools.javac.util.Options
import org.jetbrains.kotlin.kapt3.javac.KaptJavaCompiler
import org.jetbrains.kotlin.kapt3.javac.KaptJavaLog
import org.jetbrains.kotlin.kapt3.javac.KaptTreeMaker
import org.jetbrains.kotlin.kapt3.util.KaptLogger
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
@@ -39,6 +40,7 @@ class KaptContext(
val options: Options
init {
KaptJavaLog.preRegister(context)
JavacFileManager.preRegister(context)
KaptTreeMaker.preRegister(context)
KaptJavaCompiler.preRegister(context)
@@ -0,0 +1,43 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.kapt3.javac
import com.sun.tools.javac.util.Context
import com.sun.tools.javac.util.JCDiagnostic
import com.sun.tools.javac.util.Log
class KaptJavaLog(context: Context?) : Log(context) {
override fun report(diagnostic: JCDiagnostic) {
if (diagnostic.type == JCDiagnostic.DiagnosticType.ERROR && diagnostic.code in IGNORED_DIAGNOSTICS) {
return
}
super.report(diagnostic)
}
companion object {
private val IGNORED_DIAGNOSTICS = setOf(
"compiler.err.name.clash.same.erasure",
"compiler.err.name.clash.same.erasure.no.override",
"compiler.err.name.clash.same.erasure.no.override.1",
"compiler.err.name.clash.same.erasure.no.hide")
internal fun preRegister(context: Context) {
context.put(Log.logKey, Context.Factory<Log>(::KaptJavaLog))
}
}
}
@@ -150,7 +150,7 @@ class ClassFileToSourceStubConverter(
val simpleName = when (descriptor) {
is PackageFragmentDescriptor -> {
val className = clazz.name.drop(packageFqName.length + 1)
val className = if (packageFqName.isEmpty()) clazz.name else clazz.name.drop(packageFqName.length + 1)
if (className.isEmpty()) throw IllegalStateException("Invalid package facade class name: ${clazz.name}")
className
}
@@ -114,6 +114,12 @@ public class ClassFileToSourceStubConverterTestGenerated extends AbstractClassFi
doTest(fileName);
}
@TestMetadata("kt14996.kt")
public void testKt14996() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/kt14996.kt");
doTest(fileName);
}
@TestMetadata("modifiers.kt")
public void testModifiers() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/kapt3/testData/converter/modifiers.kt");
+7
View File
@@ -0,0 +1,7 @@
fun crashMe(values: List<String>): String {
throw UnsupportedOperationException()
}
fun crashMe(values: List<CharSequence>): CharSequence {
throw UnsupportedOperationException()
}
+14
View File
@@ -0,0 +1,14 @@
public final class Kt14996Kt {
public Kt14996Kt() {
super();
}
public static final java.lang.String crashMe(java.util.List<java.lang.String> values) {
return null;
}
public static final java.lang.CharSequence crashMe(java.util.List<? extends java.lang.CharSequence> values) {
return null;
}
}