예제 #1
0
  // TODO: check it's external module
  // TODO?: assert method exists in facade?
  public String changeOwnerForExternalPackage(String type, int opcode) {
    if (isSameModule || (opcode & Opcodes.INVOKESTATIC) == 0) {
      return type;
    }

    JvmClassName name = JvmClassName.byInternalName(type);
    String packageClassInternalName =
        PackageClassUtils.getPackageClassInternalName(name.getPackageFqName());
    if (type.startsWith(packageClassInternalName + '$')) {
      VirtualFile virtualFile =
          InlineCodegenUtil.findVirtualFile(inliningContext.state.getProject(), type);
      if (virtualFile != null) {
        KotlinJvmBinaryClass klass = KotlinBinaryClassCache.getKotlinBinaryClass(virtualFile);
        if (klass != null
            && klass.getClassHeader().getSyntheticClassKind()
                == KotlinSyntheticClass.Kind.PACKAGE_PART) {
          return packageClassInternalName;
        }
      }
    }

    return type;
  }
예제 #2
0
 // TODO: navigate to inner classes
 @Nullable
 public static ClassId getContainerClassId(@NotNull DeclarationDescriptor referencedDescriptor) {
   ClassOrPackageFragmentDescriptor containerDescriptor =
       DescriptorUtils.getParentOfType(
           referencedDescriptor, ClassOrPackageFragmentDescriptor.class, false);
   if (containerDescriptor instanceof PackageFragmentDescriptor) {
     return PackageClassUtils.getPackageClassId(getFqName(containerDescriptor).toSafe());
   }
   if (containerDescriptor instanceof ClassDescriptor) {
     ClassId classId = DescriptorUtilPackage.getClassId((ClassDescriptor) containerDescriptor);
     if (isInterface(containerDescriptor)) {
       FqName relativeClassName = classId.getRelativeClassName();
       // TODO test nested trait fun inlining
       classId =
           new ClassId(
               classId.getPackageFqName(),
               Name.identifier(
                   relativeClassName.shortName().asString() + JvmAbi.DEFAULT_IMPLS_SUFFIX));
     }
     return classId;
   }
   return null;
 }