Minor. Rename constants: TRAIT_IMPL* -> DEFAULT_IMPLS*
This commit is contained in:
@@ -179,7 +179,7 @@ public class AsmUtil {
|
||||
}
|
||||
|
||||
public static boolean isStaticKind(OwnerKind kind) {
|
||||
return kind == OwnerKind.PACKAGE || kind == OwnerKind.TRAIT_IMPL;
|
||||
return kind == OwnerKind.PACKAGE || kind == OwnerKind.DEFAULT_IMPLS;
|
||||
}
|
||||
|
||||
public static int getMethodAsmFlags(FunctionDescriptor functionDescriptor, OwnerKind kind) {
|
||||
@@ -908,6 +908,6 @@ public class AsmUtil {
|
||||
public static int getReceiverIndex(@NotNull CodegenContext context, @NotNull CallableMemberDescriptor descriptor) {
|
||||
OwnerKind kind = context.getContextKind();
|
||||
//Trait always should have this descriptor
|
||||
return kind != OwnerKind.TRAIT_IMPL && isStaticMethod(kind, descriptor) ? 0 : 1;
|
||||
return kind != OwnerKind.DEFAULT_IMPLS && isStaticMethod(kind, descriptor) ? 0 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public abstract class ClassBodyCodegen extends MemberCodegen<JetClassOrObject> {
|
||||
|
||||
@Override
|
||||
protected void generateBody() {
|
||||
if (kind != OwnerKind.TRAIT_IMPL) {
|
||||
if (kind != OwnerKind.DEFAULT_IMPLS) {
|
||||
//generate nested classes first and only then generate class body. It necessary to access to nested CodegenContexts
|
||||
for (JetDeclaration declaration : myClass.getDeclarations()) {
|
||||
if (shouldProcessFirst(declaration)) {
|
||||
|
||||
@@ -335,7 +335,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
if (declaration instanceof JetClass && ((JetClass) declaration).isInterface()) {
|
||||
Type traitImplType = state.getTypeMapper().mapTraitImpl(descriptor);
|
||||
ClassBuilder traitImplBuilder = state.getFactory().newVisitor(TraitImpl(declaration, descriptor), traitImplType, declaration.getContainingFile());
|
||||
ClassContext traitImplContext = context.intoAnonymousClass(descriptor, this, OwnerKind.TRAIT_IMPL);
|
||||
ClassContext traitImplContext = context.intoAnonymousClass(descriptor, this, OwnerKind.DEFAULT_IMPLS);
|
||||
new TraitImplBodyCodegen(declaration, traitImplContext, traitImplBuilder, state, parentCodegen).generate();
|
||||
}
|
||||
|
||||
@@ -2012,7 +2012,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
boolean directToField =
|
||||
(expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER || isSyntheticField)
|
||||
&& contextKind() != OwnerKind.TRAIT_IMPL;
|
||||
&& contextKind() != OwnerKind.DEFAULT_IMPLS;
|
||||
JetSuperExpression superExpression =
|
||||
resolvedCall == null ? null : CallResolverUtilPackage.getSuperCallExpression(resolvedCall.getCall());
|
||||
propertyDescriptor = context.accessibleDescriptor(propertyDescriptor, superExpression);
|
||||
|
||||
@@ -106,7 +106,7 @@ public class FunctionCodegen {
|
||||
assert functionDescriptor != null : "No descriptor for function " + function.getText() + "\n" +
|
||||
"in " + function.getContainingFile().getVirtualFile();
|
||||
|
||||
if (owner.getContextKind() != OwnerKind.TRAIT_IMPL || function.hasBody()) {
|
||||
if (owner.getContextKind() != OwnerKind.DEFAULT_IMPLS || function.hasBody()) {
|
||||
generateMethod(OtherOrigin(function, functionDescriptor), functionDescriptor,
|
||||
new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function));
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class FunctionCodegen {
|
||||
OwnerKind contextKind = methodContext.getContextKind();
|
||||
if (isTrait(functionDescriptor.getContainingDeclaration()) &&
|
||||
functionDescriptor.getVisibility() == Visibilities.PRIVATE &&
|
||||
contextKind != OwnerKind.TRAIT_IMPL) {
|
||||
contextKind != OwnerKind.DEFAULT_IMPLS) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -504,7 +504,7 @@ public class FunctionCodegen {
|
||||
|
||||
public void generateBridges(@NotNull FunctionDescriptor descriptor) {
|
||||
if (descriptor instanceof ConstructorDescriptor) return;
|
||||
if (owner.getContextKind() == OwnerKind.TRAIT_IMPL) return;
|
||||
if (owner.getContextKind() == OwnerKind.DEFAULT_IMPLS) return;
|
||||
if (isTrait(descriptor.getContainingDeclaration())) return;
|
||||
|
||||
// equals(Any?), hashCode(), toString() never need bridges
|
||||
@@ -585,7 +585,7 @@ public class FunctionCodegen {
|
||||
) {
|
||||
DeclarationDescriptor contextClass = owner.getContextDescriptor().getContainingDeclaration();
|
||||
|
||||
if (kind != OwnerKind.TRAIT_IMPL && isTrait(contextClass)) {
|
||||
if (kind != OwnerKind.DEFAULT_IMPLS && isTrait(contextClass)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1423,7 +1423,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
ClassDescriptor containingTrait = (ClassDescriptor) containingDeclaration;
|
||||
Type traitImplType = typeMapper.mapTraitImpl(containingTrait);
|
||||
|
||||
Method traitMethod = typeMapper.mapSignature(traitFun.getOriginal(), OwnerKind.TRAIT_IMPL).getAsmMethod();
|
||||
Method traitMethod = typeMapper.mapSignature(traitFun.getOriginal(), OwnerKind.DEFAULT_IMPLS).getAsmMethod();
|
||||
|
||||
Type[] argTypes = signature.getAsmMethod().getArgumentTypes();
|
||||
Type[] originalArgTypes = traitMethod.getArgumentTypes();
|
||||
|
||||
@@ -49,7 +49,6 @@ import java.io.File;
|
||||
|
||||
import static org.jetbrains.kotlin.descriptors.Modality.ABSTRACT;
|
||||
import static org.jetbrains.kotlin.descriptors.Modality.FINAL;
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isTrait;
|
||||
|
||||
public class JvmCodegenUtil {
|
||||
|
||||
@@ -82,7 +81,7 @@ public class JvmCodegenUtil {
|
||||
(((context.hasThisDescriptor() && containingDeclaration == context.getThisDescriptor()) ||
|
||||
(context.getParentContext() instanceof PackageContext
|
||||
&& isSamePackageInSameModule(context.getParentContext().getContextDescriptor(), containingDeclaration)))
|
||||
&& context.getContextKind() != OwnerKind.TRAIT_IMPL);
|
||||
&& context.getContextKind() != OwnerKind.DEFAULT_IMPLS);
|
||||
}
|
||||
|
||||
private static boolean isSamePackageInSameModule(
|
||||
|
||||
@@ -210,7 +210,7 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
|
||||
if (aClass instanceof JetClass && ((JetClass) aClass).isInterface()) {
|
||||
Type traitImplType = state.getTypeMapper().mapTraitImpl(descriptor);
|
||||
ClassBuilder traitImplBuilder = state.getFactory().newVisitor(TraitImpl(aClass, descriptor), traitImplType, aClass.getContainingFile());
|
||||
ClassContext traitImplContext = parentContext.intoClass(descriptor, OwnerKind.TRAIT_IMPL, state);
|
||||
ClassContext traitImplContext = parentContext.intoClass(descriptor, OwnerKind.DEFAULT_IMPLS, state);
|
||||
new TraitImplBodyCodegen(aClass, traitImplContext, traitImplBuilder, state, parentCodegen).generate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ public enum OwnerKind {
|
||||
|
||||
IMPLEMENTATION,
|
||||
|
||||
TRAIT_IMPL
|
||||
DEFAULT_IMPLS
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class PropertyCodegen {
|
||||
@Nullable JetPropertyAccessor getter,
|
||||
@Nullable JetPropertyAccessor setter
|
||||
) {
|
||||
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.TRAIT_IMPL
|
||||
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.DEFAULT_IMPLS
|
||||
: "Generating property with a wrong kind (" + kind + "): " + descriptor;
|
||||
|
||||
String implClassName = CodegenContextUtil.getImplementationClassShortName(context);
|
||||
@@ -154,7 +154,7 @@ public class PropertyCodegen {
|
||||
boolean isDefaultAccessor = accessor == null || !accessor.hasBody();
|
||||
|
||||
// Don't generate accessors for trait properties with default accessors in TRAIT_IMPL
|
||||
if (kind == OwnerKind.TRAIT_IMPL && isDefaultAccessor) return false;
|
||||
if (kind == OwnerKind.DEFAULT_IMPLS && isDefaultAccessor) return false;
|
||||
|
||||
if (declaration == null) return true;
|
||||
|
||||
@@ -216,7 +216,7 @@ public class PropertyCodegen {
|
||||
|
||||
private boolean hasBackingField(@NotNull JetNamedDeclaration p, @NotNull PropertyDescriptor descriptor) {
|
||||
return !isInterface(descriptor.getContainingDeclaration()) &&
|
||||
kind != OwnerKind.TRAIT_IMPL &&
|
||||
kind != OwnerKind.DEFAULT_IMPLS &&
|
||||
!Boolean.FALSE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor));
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ public class PropertyCodegen {
|
||||
@NotNull PropertyDescriptor descriptor,
|
||||
@NotNull Annotations annotations
|
||||
) {
|
||||
if (isInterface(descriptor.getContainingDeclaration()) || kind == OwnerKind.TRAIT_IMPL) {
|
||||
if (isInterface(descriptor.getContainingDeclaration()) || kind == OwnerKind.DEFAULT_IMPLS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ public class PropertyCodegen {
|
||||
String name = JvmAbi.getSyntheticMethodNameForAnnotatedProperty(descriptor.getName());
|
||||
String desc = receiver == null ? "()V" : "(" + typeMapper.mapType(receiver.getType()) + ")V";
|
||||
|
||||
if (!isTrait(context.getContextDescriptor()) || kind == OwnerKind.TRAIT_IMPL) {
|
||||
if (!isTrait(context.getContextDescriptor()) || kind == OwnerKind.DEFAULT_IMPLS) {
|
||||
int flags = ACC_DEPRECATED | ACC_FINAL | ACC_PRIVATE | ACC_STATIC | ACC_SYNTHETIC;
|
||||
MethodVisitor mv = v.newMethod(OtherOrigin(descriptor), flags, name, desc, null, null);
|
||||
AnnotationCodegen.forMethod(mv, typeMapper)
|
||||
@@ -264,7 +264,7 @@ public class PropertyCodegen {
|
||||
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, shortNameByAsmType(tImplType));
|
||||
}
|
||||
|
||||
if (kind != OwnerKind.TRAIT_IMPL) {
|
||||
if (kind != OwnerKind.DEFAULT_IMPLS) {
|
||||
v.getSerializationBindings().put(SYNTHETIC_METHOD_FOR_PROPERTY, descriptor, new Method(name, desc));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -595,7 +595,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
CodegenContext parent = getContext(descriptor.getContainingDeclaration(), state);
|
||||
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
OwnerKind kind = DescriptorUtils.isTrait(descriptor) ? OwnerKind.TRAIT_IMPL : OwnerKind.IMPLEMENTATION;
|
||||
OwnerKind kind = DescriptorUtils.isTrait(descriptor) ? OwnerKind.DEFAULT_IMPLS : OwnerKind.IMPLEMENTATION;
|
||||
return parent.intoClass((ClassDescriptor) descriptor, kind, state);
|
||||
}
|
||||
else if (descriptor instanceof ScriptDescriptor) {
|
||||
|
||||
@@ -196,7 +196,7 @@ public class InlineCodegenUtil {
|
||||
if (isTrait(containerDescriptor)) {
|
||||
FqName relativeClassName = classId.getRelativeClassName();
|
||||
//TODO test nested trait fun inlining
|
||||
classId = new ClassId(classId.getPackageFqName(), Name.identifier(relativeClassName.shortName().asString() + JvmAbi.TRAIT_IMPL_SUFFIX));
|
||||
classId = new ClassId(classId.getPackageFqName(), Name.identifier(relativeClassName.shortName().asString() + JvmAbi.DEFAULT_IMPLS_SUFFIX));
|
||||
}
|
||||
return classId;
|
||||
}
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider
|
||||
|
||||
private val EXTERNAL_SOURCES_KINDS = arrayOf(
|
||||
JvmDeclarationOriginKind.DELEGATION_TO_TRAIT_IMPL,
|
||||
JvmDeclarationOriginKind.DELEGATION_TO_DEFAULT_IMPLS,
|
||||
JvmDeclarationOriginKind.DELEGATION,
|
||||
JvmDeclarationOriginKind.BRIDGE)
|
||||
|
||||
|
||||
@@ -474,7 +474,7 @@ public class JetTypeMapper {
|
||||
|
||||
@NotNull
|
||||
public Type mapTraitImpl(@NotNull ClassDescriptor descriptor) {
|
||||
return Type.getObjectType(mapType(descriptor).getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||
return Type.getObjectType(mapType(descriptor).getInternalName() + JvmAbi.DEFAULT_IMPLS_SUFFIX);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -632,7 +632,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
else {
|
||||
invokeOpcode = INVOKESTATIC;
|
||||
signature = mapSignature(descriptor.getOriginal(), OwnerKind.TRAIT_IMPL);
|
||||
signature = mapSignature(descriptor.getOriginal(), OwnerKind.DEFAULT_IMPLS);
|
||||
owner = mapTraitImpl(currentOwner);
|
||||
}
|
||||
}
|
||||
@@ -900,7 +900,7 @@ public class JetTypeMapper {
|
||||
@NotNull BothSignatureWriter sw
|
||||
) {
|
||||
ClassDescriptor thisType;
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
if (kind == OwnerKind.DEFAULT_IMPLS) {
|
||||
thisType = getTraitImplThisParameterClass((ClassDescriptor) descriptor.getContainingDeclaration());
|
||||
}
|
||||
else if (isAccessor(descriptor) && descriptor.getDispatchReceiverParameter() != null) {
|
||||
|
||||
+4
-4
@@ -36,8 +36,8 @@ public enum class JvmDeclarationOriginKind {
|
||||
OTHER,
|
||||
PACKAGE_FACADE,
|
||||
PACKAGE_PART,
|
||||
TRAIT_IMPL,
|
||||
DELEGATION_TO_TRAIT_IMPL,
|
||||
INTERFACE_DEFAULT_IMPL,
|
||||
DELEGATION_TO_DEFAULT_IMPLS,
|
||||
DELEGATION,
|
||||
BRIDGE,
|
||||
MULTIFILE_CLASS,
|
||||
@@ -78,9 +78,9 @@ public fun MultifileClass(representativeFile: JetFile?, descriptor: PackageFragm
|
||||
public fun MultifileClassPart(file: JetFile, descriptor: PackageFragmentDescriptor, multifileClassFqName: FqName): JvmDeclarationOrigin =
|
||||
JvmDeclarationOrigin(MULTIFILE_CLASS_PART, file, descriptor)
|
||||
|
||||
public fun TraitImpl(element: JetClassOrObject, descriptor: ClassDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(TRAIT_IMPL, element, descriptor)
|
||||
public fun TraitImpl(element: JetClassOrObject, descriptor: ClassDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(INTERFACE_DEFAULT_IMPL, element, descriptor)
|
||||
public fun DelegationToTraitImpl(element: PsiElement?, descriptor: FunctionDescriptor): JvmDeclarationOrigin =
|
||||
JvmDeclarationOrigin(DELEGATION_TO_TRAIT_IMPL, element, descriptor)
|
||||
JvmDeclarationOrigin(DELEGATION_TO_DEFAULT_IMPLS, element, descriptor)
|
||||
|
||||
public fun Delegation(element: PsiElement?, descriptor: FunctionDescriptor): JvmDeclarationOrigin = JvmDeclarationOrigin(DELEGATION, element, descriptor)
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ class FilteredJvmDiagnostics(val jvmDiagnostics: Diagnostics, val otherDiagnosti
|
||||
private fun ConflictingJvmDeclarationsData.higherThan(other: ConflictingJvmDeclarationsData): Boolean {
|
||||
return when (other.classOrigin.originKind) {
|
||||
PACKAGE_PART -> this.classOrigin.originKind == PACKAGE_FACADE
|
||||
TRAIT_IMPL -> this.classOrigin.originKind != TRAIT_IMPL
|
||||
INTERFACE_DEFAULT_IMPL -> this.classOrigin.originKind != INTERFACE_DEFAULT_IMPL
|
||||
MULTIFILE_CLASS_PART -> this.classOrigin.originKind == MULTIFILE_CLASS
|
||||
else -> false
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public object InlineTestUtil {
|
||||
val fromCall = MethodInfo(className, this.name, this.desc)
|
||||
|
||||
//skip delegation to trait impl from child class
|
||||
if (methodCall.owner.endsWith(JvmAbi.TRAIT_IMPL_SUFFIX) && fromCall.owner != methodCall.owner) {
|
||||
if (methodCall.owner.endsWith(JvmAbi.DEFAULT_IMPLS_SUFFIX) && fromCall.owner != methodCall.owner) {
|
||||
return
|
||||
}
|
||||
notInlined.add(NotInlinedCall(fromCall, methodCall))
|
||||
|
||||
@@ -51,7 +51,7 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
|
||||
public void testTraitImpl() {
|
||||
doTestKotlinSyntheticClass(
|
||||
"interface A { fun foo() = 42 }",
|
||||
JvmAbi.TRAIT_IMPL_SUFFIX,
|
||||
JvmAbi.DEFAULT_IMPLS_SUFFIX,
|
||||
TRAIT_IMPL
|
||||
);
|
||||
}
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class SyntheticMethodForAnnotatedPropertyGenTest extends CodegenTestCase
|
||||
loadFile();
|
||||
GeneratedClassLoader loader = generateAndCreateClassLoader();
|
||||
assertAnnotatedSyntheticMethodExistence(false, loader.loadClass("T"));
|
||||
assertAnnotatedSyntheticMethodExistence(true, loader.loadClass("T" + JvmAbi.TRAIT_IMPL_SUFFIX));
|
||||
assertAnnotatedSyntheticMethodExistence(true, loader.loadClass("T" + JvmAbi.DEFAULT_IMPLS_SUFFIX));
|
||||
}
|
||||
|
||||
private static void assertAnnotatedSyntheticMethodExistence(boolean expected, @NotNull Class<?> clazz) {
|
||||
|
||||
@@ -36,8 +36,8 @@ public final class JvmAbi {
|
||||
*/
|
||||
public static final BinaryVersion VERSION = BinaryVersion.create(0, 27, 0);
|
||||
|
||||
public static final String TRAIT_IMPL_CLASS_NAME = "$TImpl";
|
||||
public static final String TRAIT_IMPL_SUFFIX = "$" + TRAIT_IMPL_CLASS_NAME;
|
||||
public static final String DEFAULT_IMPLS_CLASS_NAME = "$TImpl";
|
||||
public static final String DEFAULT_IMPLS_SUFFIX = "$" + DEFAULT_IMPLS_CLASS_NAME;
|
||||
|
||||
public static final String DEFAULT_PARAMS_IMPL_SUFFIX = "$default";
|
||||
|
||||
|
||||
@@ -70,10 +70,10 @@ public class JvmClassName {
|
||||
public FqName getFqNameForClassNameWithoutDollars() {
|
||||
if (fqName == null) {
|
||||
String fqName = internalName
|
||||
.replace(JvmAbi.TRAIT_IMPL_CLASS_NAME, TRAIT_IMPL_REPLACE_GUARD)
|
||||
.replace(JvmAbi.DEFAULT_IMPLS_CLASS_NAME, TRAIT_IMPL_REPLACE_GUARD)
|
||||
.replace('$', '.')
|
||||
.replace('/', '.')
|
||||
.replace(TRAIT_IMPL_REPLACE_GUARD, JvmAbi.TRAIT_IMPL_CLASS_NAME);
|
||||
.replace(TRAIT_IMPL_REPLACE_GUARD, JvmAbi.DEFAULT_IMPLS_CLASS_NAME);
|
||||
this.fqName = new FqName(fqName);
|
||||
}
|
||||
return fqName;
|
||||
|
||||
+1
-2
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass.Ki
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.junit.Assert
|
||||
import kotlin.test.assertFalse
|
||||
|
||||
public abstract class AbstractInternalCompiledClassesTest : JetLightCodeInsightFixtureTestCase() {
|
||||
private fun isFileWithHeader(predicate: (KotlinClassHeader) -> Boolean) : VirtualFile.() -> Boolean = {
|
||||
@@ -58,7 +57,7 @@ public abstract class AbstractInternalCompiledClassesTest : JetLightCodeInsightF
|
||||
decompiledPsiFile is PsiJavaFile)
|
||||
val classes = (decompiledPsiFile as PsiJavaFile).getClasses()
|
||||
Assert.assertTrue("Should have some decompiled text",
|
||||
classes.size() == 1 && classes[0].getName()!!.endsWith(JvmAbi.TRAIT_IMPL_SUFFIX))
|
||||
classes.size() == 1 && classes[0].getName()!!.endsWith(JvmAbi.DEFAULT_IMPLS_SUFFIX))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user