use of org.jetbrains.kotlin.name.ClassId in project kotlin by JetBrains.
the class InlineCodegen method doCreateMethodNodeFromCompiled.
@Nullable
private static SMAPAndMethodNode doCreateMethodNodeFromCompiled(@NotNull CallableMemberDescriptor callableDescriptor, @NotNull final GenerationState state, @NotNull Method asmMethod) {
if (isBuiltInArrayIntrinsic(callableDescriptor)) {
ClassId classId = IntrinsicArrayConstructorsKt.getClassId();
byte[] bytes = InlineCacheKt.getOrPut(state.getInlineCache().getClassBytes(), classId, new Function0<byte[]>() {
@Override
public byte[] invoke() {
return IntrinsicArrayConstructorsKt.getBytecode();
}
});
return InlineCodegenUtil.getMethodNode(bytes, asmMethod.getName(), asmMethod.getDescriptor(), classId);
}
assert callableDescriptor instanceof DeserializedCallableMemberDescriptor : "Not a deserialized function or proper: " + callableDescriptor;
KotlinTypeMapper.ContainingClassesInfo containingClasses = state.getTypeMapper().getContainingClassesForDeserializedCallable((DeserializedCallableMemberDescriptor) callableDescriptor);
final ClassId containerId = containingClasses.getImplClassId();
byte[] bytes = InlineCacheKt.getOrPut(state.getInlineCache().getClassBytes(), containerId, new Function0<byte[]>() {
@Override
public byte[] invoke() {
VirtualFile file = InlineCodegenUtil.findVirtualFile(state, containerId);
if (file == null) {
throw new IllegalStateException("Couldn't find declaration file for " + containerId);
}
try {
return file.contentsToByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
return InlineCodegenUtil.getMethodNode(bytes, asmMethod.getName(), asmMethod.getDescriptor(), containerId);
}
use of org.jetbrains.kotlin.name.ClassId in project kotlin by JetBrains.
the class JavaAnnotationImpl method computeClassId.
@Nullable
private static ClassId computeClassId(@NotNull PsiClass psiClass) {
PsiClass container = psiClass.getContainingClass();
if (container != null) {
ClassId parentClassId = computeClassId(container);
String name = psiClass.getName();
return parentClassId == null || name == null ? null : parentClassId.createNestedClassId(Name.identifier(name));
}
String fqName = psiClass.getQualifiedName();
return fqName == null ? null : ClassId.topLevel(new FqName(fqName));
}
use of org.jetbrains.kotlin.name.ClassId in project kotlin by JetBrains.
the class FileBasedKotlinClass method resolveNameByInternalName.
@NotNull
private static ClassId resolveNameByInternalName(@NotNull String name, @NotNull InnerClassesInfo innerClasses) {
if (!name.contains("$")) {
return ClassId.topLevel(new FqName(name.replace('/', '.')));
}
List<String> classes = new ArrayList<String>(1);
boolean local = false;
while (true) {
OuterAndInnerName outer = innerClasses.get(name);
if (outer == null)
break;
if (outer.outerInternalName == null) {
local = true;
break;
}
classes.add(outer.innerSimpleName);
name = outer.outerInternalName;
}
FqName outermostClassFqName = new FqName(name.replace('/', '.'));
classes.add(outermostClassFqName.shortName().asString());
Collections.reverse(classes);
FqName packageFqName = outermostClassFqName.parent();
FqName relativeClassName = FqName.fromSegments(classes);
return new ClassId(packageFqName, relativeClassName, local);
}
use of org.jetbrains.kotlin.name.ClassId in project kotlin by JetBrains.
the class FileBasedKotlinClass method create.
// TODO public to be accessible in companion object of subclass, workaround for KT-3974
@Nullable
public static <T extends FileBasedKotlinClass> T create(@NotNull byte[] fileContents, @NotNull Function4<ClassId, Integer, KotlinClassHeader, InnerClassesInfo, T> factory) {
final ReadKotlinClassHeaderAnnotationVisitor readHeaderVisitor = new ReadKotlinClassHeaderAnnotationVisitor();
final Ref<String> classNameRef = Ref.create();
final Ref<Integer> classVersion = Ref.create();
final InnerClassesInfo innerClasses = new InnerClassesInfo();
new ClassReader(fileContents).accept(new ClassVisitor(ASM5) {
@Override
public void visit(int version, int access, @NotNull String name, String signature, String superName, String[] interfaces) {
classNameRef.set(name);
classVersion.set(version);
}
@Override
public void visitInnerClass(@NotNull String name, String outerName, String innerName, int access) {
innerClasses.add(name, outerName, innerName);
}
@Override
public org.jetbrains.org.objectweb.asm.AnnotationVisitor visitAnnotation(@NotNull String desc, boolean visible) {
return convertAnnotationVisitor(readHeaderVisitor, desc, innerClasses);
}
@Override
public void visitEnd() {
readHeaderVisitor.visitEnd();
}
}, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES);
String className = classNameRef.get();
if (className == null)
return null;
KotlinClassHeader header = readHeaderVisitor.createHeader();
if (header == null)
return null;
ClassId id = resolveNameByInternalName(className, innerClasses);
return factory.invoke(id, classVersion.get(), header, innerClasses);
}
use of org.jetbrains.kotlin.name.ClassId in project kotlin by JetBrains.
the class InlineCodegenUtil method findVirtualFileImprecise.
@Nullable
private static VirtualFile findVirtualFileImprecise(@NotNull GenerationState state, @NotNull String internalClassName) {
FqName packageFqName = JvmClassName.byInternalName(internalClassName).getPackageFqName();
String classNameWithDollars = StringsKt.substringAfterLast(internalClassName, "/", internalClassName);
// we construct valid.package.name/RelativeClassNameAsSingleName that should work in compiler, but fails for inner classes in IDE
return findVirtualFile(state, new ClassId(packageFqName, Name.identifier(classNameWithDollars)));
}
Aggregations