Delete JvmClassName.byType

Replace JvmClassName by ASM Type in many places of JVM codegen: it wasn't used
to abstract anything, but there was a lot of useless conversions between the
two
This commit is contained in:
Alexander Udalov
2013-09-27 20:06:45 +04:00
parent 57ed81521d
commit f4abaaee10
27 changed files with 219 additions and 240 deletions
@@ -676,4 +676,10 @@ public class AsmUtil {
int lastSlash = internalName.lastIndexOf('/');
return lastSlash < 0 ? internalName : internalName.substring(lastSlash + 1);
}
// WARNING: this method works incorrectly for classes with dollars in their names
@NotNull
public static FqName fqNameByAsmTypeUnsafe(@NotNull Type asmType) {
return JvmClassName.byInternalName(asmType.getInternalName()).getFqName();
}
}
@@ -25,7 +25,6 @@ import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import java.util.List;
@@ -34,28 +33,28 @@ import static org.jetbrains.asm4.Opcodes.INVOKESTATIC;
public class CallableMethod implements Callable {
@NotNull
private final JvmClassName owner;
private final Type owner;
@Nullable
private final JvmClassName defaultImplOwner;
private final Type defaultImplOwner;
@Nullable
private final Type defaultImplParam;
private final JvmMethodSignature signature;
private final int invokeOpcode;
@Nullable
private final JvmClassName thisClass;
private final Type thisClass;
@Nullable
private final Type receiverParameterType;
@Nullable
private final Type generateCalleeType;
public CallableMethod(
@NotNull JvmClassName owner, @Nullable JvmClassName defaultImplOwner, @Nullable JvmClassName defaultImplParam,
@NotNull Type owner, @Nullable Type defaultImplOwner, @Nullable Type defaultImplParam,
JvmMethodSignature signature, int invokeOpcode,
@Nullable JvmClassName thisClass, @Nullable Type receiverParameterType, @Nullable Type generateCalleeType
@Nullable Type thisClass, @Nullable Type receiverParameterType, @Nullable Type generateCalleeType
) {
this.owner = owner;
this.defaultImplOwner = defaultImplOwner;
this.defaultImplParam = defaultImplParam == null ? null : defaultImplParam.getAsmType();
this.defaultImplParam = defaultImplParam;
this.signature = signature;
this.invokeOpcode = invokeOpcode;
this.thisClass = thisClass;
@@ -64,7 +63,7 @@ public class CallableMethod implements Callable {
}
@NotNull
public JvmClassName getOwner() {
public Type getOwner() {
return owner;
}
@@ -81,7 +80,7 @@ public class CallableMethod implements Callable {
}
@Nullable
public JvmClassName getThisType() {
public Type getThisType() {
return thisClass;
}
@@ -26,7 +26,6 @@ import org.jetbrains.jet.codegen.state.GenerationStateAware;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.FqName;
import javax.inject.Inject;
@@ -53,13 +52,13 @@ public final class ClassFileFactory extends GenerationStateAware {
}
@NotNull
ClassBuilder newVisitor(@NotNull JvmClassName className, @NotNull PsiFile sourceFile) {
return newVisitor(className, Collections.singletonList(sourceFile));
ClassBuilder newVisitor(@NotNull Type asmType, @NotNull PsiFile sourceFile) {
return newVisitor(asmType, Collections.singletonList(sourceFile));
}
@NotNull
private ClassBuilder newVisitor(@NotNull JvmClassName className, @NotNull Collection<? extends PsiFile> sourceFiles) {
String outputFilePath = className.getInternalName() + ".class";
private ClassBuilder newVisitor(@NotNull Type asmType, @NotNull Collection<? extends PsiFile> sourceFiles) {
String outputFilePath = asmType.getInternalName() + ".class";
state.getProgress().reportOutput(toIoFilesIgnoringNonPhysical(sourceFiles), new File(outputFilePath));
ClassBuilder answer = builderFactory.newClassBuilder();
generators.put(outputFilePath, answer);
@@ -112,7 +111,7 @@ public final class ClassFileFactory extends GenerationStateAware {
@NotNull
@Override
protected ClassBuilder createClassBuilder() {
return newVisitor(NamespaceCodegen.getJVMClassNameForKotlinNs(fqName), files);
return newVisitor(NamespaceCodegen.getJVMClassNameForKotlinNs(fqName).getAsmType(), files);
}
};
codegen = new NamespaceCodegen(onDemand, fqName, state, files);
@@ -127,18 +126,18 @@ public final class ClassFileFactory extends GenerationStateAware {
if (isPrimitive(type)) {
throw new IllegalStateException("Codegen for primitive type is not possible: " + aClass);
}
return newVisitor(JvmClassName.byType(type), sourceFile);
return newVisitor(type, sourceFile);
}
@NotNull
public ClassBuilder forNamespacePart(@NotNull JvmClassName name, @NotNull PsiFile sourceFile) {
return newVisitor(name, sourceFile);
public ClassBuilder forNamespacePart(@NotNull Type asmType, @NotNull PsiFile sourceFile) {
return newVisitor(asmType, sourceFile);
}
@NotNull
public ClassBuilder forTraitImplementation(@NotNull ClassDescriptor aClass, @NotNull GenerationState state, @NotNull PsiFile file) {
Type type = state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL);
return newVisitor(JvmClassName.byType(type), file);
return newVisitor(type, file);
}
private static Collection<File> toIoFilesIgnoringNonPhysical(Collection<? extends PsiFile> psiFiles) {
@@ -37,7 +37,6 @@ import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType;
@@ -56,7 +55,7 @@ public class ClosureCodegen extends GenerationStateAware {
private final PsiElement fun;
private final FunctionDescriptor funDescriptor;
private final ClassDescriptor samInterface;
private final JvmClassName superClass;
private final Type superClass;
private final CodegenContext context;
private final FunctionGenerationStrategy strategy;
private final CalculatedClosure closure;
@@ -69,7 +68,7 @@ public class ClosureCodegen extends GenerationStateAware {
@NotNull PsiElement fun,
@NotNull FunctionDescriptor funDescriptor,
@Nullable ClassDescriptor samInterface,
@NotNull JvmClassName closureSuperClass,
@NotNull Type closureSuperClass,
@NotNull CodegenContext context,
@NotNull LocalLookup localLookup,
@NotNull FunctionGenerationStrategy strategy
@@ -87,12 +86,12 @@ public class ClosureCodegen extends GenerationStateAware {
this.closure = bindingContext.get(CLOSURE, classDescriptor);
assert closure != null : "Closure must be calculated for class: " + classDescriptor;
this.asmType = classNameForAnonymousClass(bindingContext, funDescriptor).getAsmType();
this.asmType = asmTypeForAnonymousClass(bindingContext, funDescriptor);
}
public void gen() {
ClassBuilder cv = state.getFactory().newVisitor(JvmClassName.byType(asmType), fun.getContainingFile());
ClassBuilder cv = state.getFactory().newVisitor(asmType, fun.getContainingFile());
FunctionDescriptor interfaceFunction;
String[] superInterfaces;
@@ -231,7 +230,7 @@ public class ClosureCodegen extends GenerationStateAware {
mv.visitCode();
InstructionAdapter iv = new InstructionAdapter(mv);
iv.load(0, superClass.getAsmType());
iv.load(0, superClass);
iv.invokespecial(superClass.getInternalName(), "<init>", "()V");
int k = 1;
@@ -274,8 +273,8 @@ public class ClosureCodegen extends GenerationStateAware {
args.add(FieldInfo.createForHiddenField(ownerType, type, "$" + descriptor.getName().asString()));
}
else if (isLocalNamedFun(descriptor)) {
JvmClassName className = classNameForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
args.add(FieldInfo.createForHiddenField(ownerType, className.getAsmType(), "$" + descriptor.getName().asString()));
Type classType = asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
args.add(FieldInfo.createForHiddenField(ownerType, classType, "$" + descriptor.getName().asString()));
}
else if (descriptor instanceof FunctionDescriptor) {
assert captureReceiver != null;
@@ -70,10 +70,9 @@ import static org.jetbrains.asm4.Opcodes.*;
import static org.jetbrains.jet.codegen.AsmUtil.*;
import static org.jetbrains.jet.codegen.CodegenUtil.*;
import static org.jetbrains.jet.codegen.FunctionTypesUtil.functionTypeToImpl;
import static org.jetbrains.jet.codegen.FunctionTypesUtil.getFunctionImplClassName;
import static org.jetbrains.jet.codegen.FunctionTypesUtil.getFunctionImplType;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.getNotNull;
import static org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.RECEIVER_ARGUMENT;
import static org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.THIS_OBJECT;
@@ -112,8 +111,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
public CalculatedClosure generateObjectLiteral(GenerationState state, JetObjectLiteralExpression literal) {
JetObjectDeclaration objectDeclaration = literal.getObjectDeclaration();
JvmClassName className = classNameForAnonymousClass(bindingContext, objectDeclaration);
ClassBuilder classBuilder = state.getFactory().newVisitor(className, literal.getContainingFile());
Type asmType = asmTypeForAnonymousClass(bindingContext, objectDeclaration);
ClassBuilder classBuilder = state.getFactory().newVisitor(asmType, literal.getContainingFile());
ClassDescriptor classDescriptor = bindingContext.get(CLASS, objectDeclaration);
assert classDescriptor != null;
@@ -286,8 +285,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ClassDescriptor descriptor = bindingContext.get(BindingContext.CLASS, declaration);
assert descriptor != null;
JvmClassName className = classNameForAnonymousClass(bindingContext, declaration);
ClassBuilder classBuilder = state.getFactory().newVisitor(className, declaration.getContainingFile());
Type asmType = asmTypeForAnonymousClass(bindingContext, declaration);
ClassBuilder classBuilder = state.getFactory().newVisitor(asmType, declaration.getContainingFile());
ClassContext objectContext = context.intoAnonymousClass(descriptor, this);
@@ -1310,7 +1309,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
FunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
assert descriptor != null : "Function is not resolved to descriptor: " + declaration.getText();
JvmClassName closureSuperClass = samInterfaceClass == null ? getFunctionImplClassName(descriptor) : JvmClassName.byType(OBJECT_TYPE);
Type closureSuperClass = samInterfaceClass == null ? getFunctionImplType(descriptor) : OBJECT_TYPE;
ClosureCodegen closureCodegen = new ClosureCodegen(state, declaration, descriptor, samInterfaceClass, closureSuperClass, context,
this, new FunctionGenerationStrategy.FunctionDefault(state, descriptor, declaration));
@@ -1701,13 +1700,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (descriptor instanceof ValueParameterDescriptor && descriptor.getContainingDeclaration() instanceof ScriptDescriptor) {
ScriptDescriptor scriptDescriptor = (ScriptDescriptor) descriptor.getContainingDeclaration();
assert scriptDescriptor != null;
JvmClassName scriptClassName = classNameForScriptDescriptor(bindingContext, scriptDescriptor);
Type scriptClassType = asmTypeForScriptDescriptor(bindingContext, scriptDescriptor);
ValueParameterDescriptor valueParameterDescriptor = (ValueParameterDescriptor) descriptor;
ClassDescriptor scriptClass = bindingContext.get(CLASS_FOR_SCRIPT, scriptDescriptor);
StackValue script = StackValue.thisOrOuter(this, scriptClass, false);
script.put(script.type, v);
Type fieldType = typeMapper.mapType(valueParameterDescriptor);
return StackValue.field(fieldType, scriptClassName, valueParameterDescriptor.getName().getIdentifier(), false);
return StackValue.field(fieldType, scriptClassType, valueParameterDescriptor.getName().getIdentifier(), false);
}
throw new UnsupportedOperationException("don't know how to generate reference " + descriptor);
@@ -1719,7 +1718,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ClassDescriptor containing = (ClassDescriptor) variableDescriptor.getContainingDeclaration().getContainingDeclaration();
assert containing != null;
Type type = typeMapper.mapType(containing);
return StackValue.field(type, JvmClassName.byType(type), variableDescriptor.getName().asString(), true);
return StackValue.field(type, type, variableDescriptor.getName().asString(), true);
}
else {
return StackValue.singleton(objectClassDescriptor, typeMapper);
@@ -1846,7 +1845,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
}
JvmClassName owner;
Type owner;
CallableMethod callableMethod = callableGetter != null ? callableGetter : callableSetter;
propertyDescriptor = unwrapFakeOverride(propertyDescriptor);
@@ -1938,10 +1937,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return genClosure(((JetFunctionLiteralExpression) expression).getFunctionLiteral(), samInterface);
}
else {
JvmClassName className =
state.getSamWrapperClasses().getSamWrapperClass(samInterface, (JetFile) expression.getContainingFile());
Type asmType = state.getSamWrapperClasses().getSamWrapperClass(samInterface, (JetFile) expression.getContainingFile());
v.anew(className.getAsmType());
v.anew(asmType);
v.dup();
Type functionType = typeMapper.mapType(samInterface.getFunctionTypeForSamInterface());
@@ -1960,10 +1958,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
v.goTo(afterAll);
v.mark(ifNonNull);
v.invokespecial(className.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType));
v.invokespecial(asmType.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType));
v.mark(afterAll);
return StackValue.onStack(className.getAsmType());
return StackValue.onStack(asmType);
}
}
@@ -2216,19 +2214,15 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (cur instanceof ScriptContext) {
ScriptContext scriptContext = (ScriptContext) cur;
JvmClassName currentScriptClassName =
classNameForScriptDescriptor(bindingContext,
scriptContext.getScriptDescriptor());
Type currentScriptType = asmTypeForScriptDescriptor(bindingContext, scriptContext.getScriptDescriptor());
if (scriptContext.getScriptDescriptor() == receiver.getDeclarationDescriptor()) {
result.put(currentScriptClassName.getAsmType(), v);
result.put(currentScriptType, v);
}
else {
JvmClassName className =
classNameForScriptDescriptor(bindingContext,
receiver.getDeclarationDescriptor());
Type classType = asmTypeForScriptDescriptor(bindingContext, receiver.getDeclarationDescriptor());
String fieldName = state.getScriptCodegen().getScriptFieldName(receiver.getDeclarationDescriptor());
result.put(currentScriptClassName.getAsmType(), v);
StackValue.field(className.getAsmType(), currentScriptClassName, fieldName, false).put(className.getAsmType(), v);
result.put(currentScriptType, v);
StackValue.field(classType, currentScriptType, fieldName, false).put(classType, v);
}
return;
}
@@ -2433,7 +2427,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ClassDescriptor kFunctionImpl = functionTypeToImpl(kFunctionType);
assert kFunctionImpl != null : "Impl type is not found for the function type: " + kFunctionType;
JvmClassName closureSuperClass = JvmClassName.byType(typeMapper.mapType(kFunctionImpl));
Type closureSuperClass = typeMapper.mapType(kFunctionImpl);
ClosureCodegen closureCodegen = new ClosureCodegen(state, expression, functionDescriptor, null, closureSuperClass, context, this,
new FunctionGenerationStrategy.CodegenBased<CallableDescriptor>(state, functionDescriptor) {
@@ -3019,7 +3013,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
private StackValue invokeOperation(JetOperationExpression expression, FunctionDescriptor op, CallableMethod callable) {
int functionLocalIndex = lookupLocalIndex(op);
if (functionLocalIndex >= 0) {
stackValueForLocal(op, functionLocalIndex).put(callable.getOwner().getAsmType(), v);
stackValueForLocal(op, functionLocalIndex).put(callable.getOwner(), v);
}
ResolvedCall<? extends CallableDescriptor> resolvedCall =
bindingContext.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
@@ -3217,8 +3211,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
generateInitializer.fun(variableDescriptor);
JetScript scriptPsi = JetPsiUtil.getScript(variableDeclaration);
assert scriptPsi != null;
JvmClassName scriptClassName = classNameForScriptPsi(bindingContext, scriptPsi);
v.putfield(scriptClassName.getInternalName(), variableDeclaration.getName(), varType.getDescriptor());
Type scriptClassType = asmTypeForScriptPsi(bindingContext, scriptPsi);
v.putfield(scriptClassType.getInternalName(), variableDeclaration.getName(), varType.getDescriptor());
}
else if (sharedVarType == null) {
generateInitializer.fun(variableDescriptor);
@@ -42,7 +42,6 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.*;
@@ -50,7 +49,7 @@ import java.util.*;
import static org.jetbrains.asm4.Opcodes.*;
import static org.jetbrains.jet.codegen.AsmUtil.*;
import static org.jetbrains.jet.codegen.CodegenUtil.*;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
@@ -112,8 +111,8 @@ public class FunctionCodegen extends GenerationStateAware {
OwnerKind contextKind = owner.getContextKind();
if (contextKind instanceof OwnerKind.StaticDelegateKind) {
JvmClassName ownerName = ((OwnerKind.StaticDelegateKind) contextKind).getOwnerClass();
v.getMemberMap().recordSrcClassNameForCallable(functionDescriptor, shortNameByAsmType(ownerName.getAsmType()));
Type ownerType = ((OwnerKind.StaticDelegateKind) contextKind).getOwnerClass();
v.getMemberMap().recordSrcClassNameForCallable(functionDescriptor, shortNameByAsmType(ownerType));
}
else {
v.getMemberMap().recordMethodOfDescriptor(functionDescriptor, asmMethod);
@@ -486,9 +485,9 @@ public class FunctionCodegen extends GenerationStateAware {
InstructionAdapter v = new InstructionAdapter(mv);
mv.visitCode();
JvmClassName ownerInternalName = method.getOwner();
Type methodOwner = method.getOwner();
Method jvmSignature = method.getSignature().getAsmMethod();
v.load(0, ownerInternalName.getAsmType()); // Load this on stack
v.load(0, methodOwner); // Load this on stack
int mask = 0;
for (ValueParameterDescriptor parameterDescriptor : constructorDescriptor.getValueParameters()) {
@@ -498,9 +497,9 @@ public class FunctionCodegen extends GenerationStateAware {
}
v.iconst(mask);
String desc = jvmSignature.getDescriptor().replace(")", "I)");
v.invokespecial(ownerInternalName.getInternalName(), "<init>", desc);
v.invokespecial(methodOwner.getInternalName(), "<init>", desc);
v.areturn(Type.VOID_TYPE);
endVisit(mv, "default constructor for " + ownerInternalName.getInternalName(), null);
endVisit(mv, "default constructor for " + methodOwner.getInternalName(), null);
}
}
@@ -533,13 +532,13 @@ public class FunctionCodegen extends GenerationStateAware {
Type ownerType;
if (contextClass instanceof NamespaceDescriptor) {
ownerType = state.getTypeMapper().getOwner(functionDescriptor, kind, true).getAsmType();
ownerType = state.getTypeMapper().getOwner(functionDescriptor, kind, true);
}
else if (contextClass instanceof ClassDescriptor) {
ownerType = state.getTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), JetTypeMapperMode.IMPL);
}
else if (isLocalNamedFun(functionDescriptor)) {
ownerType = classNameForAnonymousClass(state.getBindingContext(), functionDescriptor).getAsmType();
ownerType = asmTypeForAnonymousClass(state.getBindingContext(), functionDescriptor);
}
else {
throw new IllegalStateException("Couldn't obtain owner name for " + functionDescriptor);
@@ -19,9 +19,9 @@ package org.jetbrains.jet.codegen;
import com.google.common.collect.ImmutableMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType;
@@ -157,24 +157,24 @@ public class FunctionTypesUtil {
}
@NotNull
public static JvmClassName getFunctionTraitClassName(@NotNull FunctionDescriptor descriptor) {
public static Type getFunctionTraitClassName(@NotNull FunctionDescriptor descriptor) {
int paramCount = descriptor.getValueParameters().size();
if (descriptor.getReceiverParameter() != null) {
return JvmClassName.byInternalName("jet/ExtensionFunction" + paramCount);
return Type.getObjectType("jet/ExtensionFunction" + paramCount);
}
else {
return JvmClassName.byInternalName("jet/Function" + paramCount);
return Type.getObjectType("jet/Function" + paramCount);
}
}
@NotNull
public static JvmClassName getFunctionImplClassName(@NotNull FunctionDescriptor descriptor) {
public static Type getFunctionImplType(@NotNull FunctionDescriptor descriptor) {
int paramCount = descriptor.getValueParameters().size();
if (descriptor.getReceiverParameter() != null) {
return JvmClassName.byInternalName("jet/ExtensionFunctionImpl" + paramCount);
return Type.getObjectType("jet/ExtensionFunctionImpl" + paramCount);
}
else {
return JvmClassName.byInternalName("jet/FunctionImpl" + paramCount);
return Type.getObjectType("jet/FunctionImpl" + paramCount);
}
}
}
@@ -57,7 +57,6 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
@@ -867,7 +866,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (closure != null && closure.getCaptureThis() != null) {
Type type = typeMapper.mapType(enclosingClassDescriptor(bindingContext, descriptor));
iv.load(0, classAsmType);
iv.getfield(JvmClassName.byType(classAsmType).getInternalName(), CAPTURED_THIS_FIELD, type.getDescriptor());
iv.getfield(classAsmType.getInternalName(), CAPTURED_THIS_FIELD, type.getDescriptor());
}
int parameterIndex = 1; // localVariable 0 = this
@@ -1041,7 +1040,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
int reg = 1;
if (isConstructor) {
iv.anew(callableMethod.getOwner().getAsmType());
iv.anew(callableMethod.getOwner());
iv.dup();
reg = 0;
}
@@ -1123,8 +1122,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ExpressionCodegen codegen = createOrGetClInitCodegen();
StackValue property = codegen.intermediateValueForProperty(propertyDescriptor, false, null);
property.put(property.type, codegen.v);
StackValue.Field field = StackValue.field(property.type, JvmClassName.byType(classAsmType),
propertyDescriptor.getName().asString(), true);
StackValue.Field field = StackValue.field(property.type, classAsmType, propertyDescriptor.getName().asString(), true);
field.store(field.type, codegen.v);
}
@@ -1195,8 +1193,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
InstructionAdapter iv = codegen.v;
JvmClassName className = JvmClassName.byType(classAsmType);
if (superCall == null) {
genSimpleSuperCall(iv);
}
@@ -1222,7 +1218,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
if (specifier instanceof JetDelegatorByExpressionSpecifier) {
genCallToDelegatorByExpressionSpecifier(iv, codegen, classAsmType, className, n++, specifier);
genCallToDelegatorByExpressionSpecifier(iv, codegen, n++, specifier);
}
}
@@ -1288,8 +1284,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private void genCallToDelegatorByExpressionSpecifier(
InstructionAdapter iv,
ExpressionCodegen codegen,
Type classType,
JvmClassName className,
int n,
JetDelegationSpecifier specifier
) {
@@ -1325,20 +1319,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
!propertyDescriptor.isVar() &&
Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor))) {
// final property with backing field
field = StackValue.field(typeMapper.mapType(propertyDescriptor.getType()), className,
field = StackValue.field(typeMapper.mapType(propertyDescriptor.getType()), classAsmType,
propertyDescriptor.getName().asString(), false);
}
else {
iv.load(0, classType);
iv.load(0, classAsmType);
codegen.genToJVMStack(expression);
String delegateField = "$delegate_" + n;
Type fieldType = typeMapper.mapType(superClassDescriptor);
String fieldDesc = fieldType.getDescriptor();
v.newField(specifier, ACC_PRIVATE|ACC_FINAL|ACC_SYNTHETIC, delegateField, fieldDesc, /*TODO*/null, null);
v.newField(specifier, ACC_PRIVATE | ACC_FINAL | ACC_SYNTHETIC, delegateField, fieldDesc, /*TODO*/null, null);
field = StackValue.field(fieldType, className, delegateField, false);
field = StackValue.field(fieldType, classAsmType, delegateField, false);
field.store(fieldType, iv);
}
@@ -19,6 +19,7 @@ package org.jetbrains.jet.codegen;
import com.intellij.openapi.util.Pair;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -48,7 +49,7 @@ public class KotlinCodegenFacade {
}
}
state.getScriptCodegen().registerEarlierScripts(Collections.<Pair<ScriptDescriptor, JvmClassName>>emptyList());
state.getScriptCodegen().registerEarlierScripts(Collections.<Pair<ScriptDescriptor, Type>>emptyList());
state.beforeCompile();
@@ -183,12 +183,12 @@ public class NamespaceCodegen extends MemberCodegen {
if (!generateSrcClass) return null;
JvmClassName className = getMultiFileNamespaceInternalName(PackageClassUtils.getPackageClassFqName(name), file);
ClassBuilder builder = state.getFactory().forNamespacePart(className, file);
Type namespacePartType = getNamespacePartType(PackageClassUtils.getPackageClassFqName(name), file);
ClassBuilder builder = state.getFactory().forNamespacePart(namespacePartType, file);
builder.defineClass(file, V1_6,
ACC_PUBLIC | ACC_FINAL,
className.getInternalName(),
namespacePartType.getInternalName(),
null,
//"jet/lang/Namespace",
"java/lang/Object",
@@ -200,7 +200,7 @@ public class NamespaceCodegen extends MemberCodegen {
FieldOwnerContext nameSpaceContext = CodegenContext.STATIC.intoNamespace(descriptor);
FieldOwnerContext nameSpacePart = CodegenContext.STATIC.intoNamespacePart(className, descriptor);
FieldOwnerContext nameSpacePart = CodegenContext.STATIC.intoNamespacePart(namespacePartType, descriptor);
for (JetDeclaration declaration : file.getDeclarations()) {
if (declaration instanceof JetNamedFunction || declaration instanceof JetProperty) {
@@ -319,7 +319,7 @@ public class NamespaceCodegen extends MemberCodegen {
}
@NotNull
private static JvmClassName getMultiFileNamespaceInternalName(@NotNull FqName facadeFqName, @NotNull PsiFile file) {
private static Type getNamespacePartType(@NotNull FqName facadeFqName, @NotNull PsiFile file) {
String fileName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(file.getName()));
// path hashCode to prevent same name / different path collision
@@ -328,7 +328,7 @@ public class NamespaceCodegen extends MemberCodegen {
FqName srcFqName = facadeFqName.parent().child(Name.identifier(srcName));
return JvmClassName.byFqNameWithoutInnerClasses(srcFqName);
return JvmClassName.byFqNameWithoutInnerClasses(srcFqName).getAsmType();
}
@NotNull
@@ -340,6 +340,6 @@ public class NamespaceCodegen extends MemberCodegen {
public static String getNamespacePartInternalName(@NotNull JetFile file) {
FqName fqName = JetPsiUtil.getFQName(file);
JvmClassName namespaceJvmClassName = getJVMClassNameForKotlinNs(fqName);
return getMultiFileNamespaceInternalName(namespaceJvmClassName.getFqName(), file).getInternalName();
return getNamespacePartType(namespaceJvmClassName.getFqName(), file).getInternalName();
}
}
@@ -17,7 +17,7 @@
package org.jetbrains.jet.codegen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.asm4.Type;
public class OwnerKind {
private final String name;
@@ -31,15 +31,15 @@ public class OwnerKind {
public static final OwnerKind TRAIT_IMPL = new OwnerKind("trait implementation");
public static class StaticDelegateKind extends OwnerKind {
private final JvmClassName ownerClass;
private final Type ownerClass;
public StaticDelegateKind(@NotNull JvmClassName ownerClass) {
public StaticDelegateKind(@NotNull Type ownerClass) {
super("staticDelegateKind");
this.ownerClass = ownerClass;
}
@NotNull
public JvmClassName getOwnerClass() {
public Type getOwnerClass() {
return ownerClass;
}
}
@@ -37,7 +37,6 @@ import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType;
@@ -88,8 +87,8 @@ public class PropertyCodegen extends GenerationStateAware {
: "Generating property with a wrong kind (" + kind + "): " + propertyDescriptor;
if (kind instanceof OwnerKind.StaticDelegateKind) {
JvmClassName ownerName = ((OwnerKind.StaticDelegateKind) kind).getOwnerClass();
v.getMemberMap().recordSrcClassNameForCallable(propertyDescriptor, shortNameByAsmType(ownerName.getAsmType()));
Type ownerType = ((OwnerKind.StaticDelegateKind) kind).getOwnerClass();
v.getMemberMap().recordSrcClassNameForCallable(propertyDescriptor, shortNameByAsmType(ownerType));
}
else if (kind != OwnerKind.TRAIT_IMPL) {
generateBackingField(p, propertyDescriptor);
@@ -21,11 +21,9 @@ import com.intellij.openapi.util.Factory;
import com.intellij.openapi.util.Pair;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmBytecode;
import java.util.Map;
@@ -33,18 +31,18 @@ import java.util.Map;
public class SamWrapperClasses {
private final GenerationState state;
private final Map<Pair<ClassDescriptorFromJvmBytecode, JetFile>, JvmClassName> samInterfaceToWrapperClass = Maps.newHashMap();
private final Map<Pair<ClassDescriptorFromJvmBytecode, JetFile>, Type> samInterfaceToWrapperClass = Maps.newHashMap();
public SamWrapperClasses(GenerationState state) {
this.state = state;
}
@NotNull
public JvmClassName getSamWrapperClass(@NotNull final ClassDescriptorFromJvmBytecode samInterface, @NotNull final JetFile file) {
public Type getSamWrapperClass(@NotNull final ClassDescriptorFromJvmBytecode samInterface, @NotNull final JetFile file) {
return ContainerUtil.getOrCreate(samInterfaceToWrapperClass, Pair.create(samInterface, file),
new Factory<JvmClassName>() {
new Factory<Type>() {
@Override
public JvmClassName create() {
public Type create() {
return new SamWrapperCodegen(state, samInterface).genWrapper(file);
}
});
@@ -53,9 +53,9 @@ public class SamWrapperCodegen extends GenerationStateAware {
this.samInterface = samInterface;
}
public JvmClassName genWrapper(@NotNull JetFile file) {
public Type genWrapper(@NotNull JetFile file) {
// Name for generated class, in form of whatever$1
JvmClassName name = JvmClassName.byInternalName(getWrapperName(file));
Type asmType = Type.getObjectType(getWrapperName(file));
// e.g. (T, T) -> Int
JetType functionType = samInterface.getFunctionTypeForSamInterface();
@@ -63,11 +63,11 @@ public class SamWrapperCodegen extends GenerationStateAware {
// e.g. compare(T, T)
SimpleFunctionDescriptor interfaceFunction = SingleAbstractMethodUtils.getAbstractMethodOfSamInterface(samInterface);
ClassBuilder cv = state.getFactory().newVisitor(name, file);
ClassBuilder cv = state.getFactory().newVisitor(asmType, file);
cv.defineClass(file,
V1_6,
ACC_FINAL,
name.getInternalName(),
asmType.getInternalName(),
null,
OBJECT_TYPE.getInternalName(),
new String[]{ typeMapper.mapType(samInterface).getInternalName() }
@@ -84,12 +84,12 @@ public class SamWrapperCodegen extends GenerationStateAware {
null,
null);
generateConstructor(name.getAsmType(), functionAsmType, cv);
generateMethod(name.getAsmType(), functionAsmType, cv, interfaceFunction, functionType);
generateConstructor(asmType, functionAsmType, cv);
generateMethod(asmType, functionAsmType, cv, interfaceFunction, functionType);
cv.done();
return name;
return asmType;
}
private void generateConstructor(Type ownerType, Type functionType, ClassBuilder cv) {
@@ -129,7 +129,7 @@ public class SamWrapperCodegen extends GenerationStateAware {
FunctionDescriptor invokeFunction = functionJetType.getMemberScope()
.getFunctions(Name.identifier("invoke")).iterator().next().getOriginal();
StackValue functionField = StackValue.field(functionType, JvmClassName.byType(ownerType), FUNCTION_FIELD_NAME, false);
StackValue functionField = StackValue.field(functionType, ownerType, FUNCTION_FIELD_NAME, false);
codegen.genDelegate(interfaceFunction, invokeFunction, functionField);
}
@@ -76,7 +76,7 @@ public class ScriptCodegen extends MemberCodegen {
JvmClassName className = bindingContext.get(FQN, classDescriptorForScript);
assert className != null;
ClassBuilder classBuilder = classFileFactory.newVisitor(className, scriptDeclaration.getContainingFile());
ClassBuilder classBuilder = classFileFactory.newVisitor(className.getAsmType(), scriptDeclaration.getContainingFile());
classBuilder.defineClass(scriptDeclaration,
V1_6,
ACC_PUBLIC,
@@ -151,12 +151,11 @@ public class ScriptCodegen extends MemberCodegen {
int offset = 1;
for (ScriptDescriptor earlierScript : importedScripts) {
JvmClassName earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript);
Type earlierClassType = asmTypeForScriptDescriptor(bindingContext, earlierScript);
instructionAdapter.load(0, className.getAsmType());
instructionAdapter.load(offset, earlierClassName.getAsmType());
offset += earlierClassName.getAsmType().getSize();
instructionAdapter.putfield(className.getInternalName(), getScriptFieldName(earlierScript),
earlierClassName.getAsmType().getDescriptor());
instructionAdapter.load(offset, earlierClassType);
offset += earlierClassType.getSize();
instructionAdapter.putfield(className.getInternalName(), getScriptFieldName(earlierScript), earlierClassType.getDescriptor());
}
for (ValueParameterDescriptor parameter : scriptDescriptor.getValueParameters()) {
@@ -171,8 +170,8 @@ public class ScriptCodegen extends MemberCodegen {
new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, context, state).gen(scriptDeclaration.getBlockExpression());
if (stackValue.type != Type.VOID_TYPE) {
stackValue.put(stackValue.type, instructionAdapter);
instructionAdapter
.putfield(className.getInternalName(), ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME, blockType.getDescriptor());
instructionAdapter.putfield(className.getInternalName(), ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME,
blockType.getDescriptor());
}
instructionAdapter.areturn(Type.VOID_TYPE);
@@ -182,9 +181,9 @@ public class ScriptCodegen extends MemberCodegen {
private void genFieldsForParameters(@NotNull ScriptDescriptor script, @NotNull ClassBuilder classBuilder) {
for (ScriptDescriptor earlierScript : earlierScripts) {
JvmClassName earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript);
Type earlierClassName = asmTypeForScriptDescriptor(bindingContext, earlierScript);
int access = ACC_PRIVATE | ACC_FINAL;
classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getAsmType().getDescriptor(), null, null);
classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getDescriptor(), null, null);
}
for (ValueParameterDescriptor parameter : script.getValueParameters()) {
@@ -200,16 +199,17 @@ public class ScriptCodegen extends MemberCodegen {
}
}
public void registerEarlierScripts(List<Pair<ScriptDescriptor, JvmClassName>> earlierScripts) {
for (Pair<ScriptDescriptor, JvmClassName> t : earlierScripts) {
public void registerEarlierScripts(List<Pair<ScriptDescriptor, Type>> earlierScripts) {
for (Pair<ScriptDescriptor, Type> t : earlierScripts) {
ScriptDescriptor earlierDescriptor = t.first;
JvmClassName earlierClassName = t.second;
Type earlierClassName = t.second;
registerClassNameForScript(state.getBindingTrace(), earlierDescriptor, earlierClassName);
registerClassNameForScript(state.getBindingTrace(), earlierDescriptor,
JvmClassName.byInternalName(earlierClassName.getInternalName()));
}
List<ScriptDescriptor> earlierScriptDescriptors = Lists.newArrayList();
for (Pair<ScriptDescriptor, JvmClassName> t : earlierScripts) {
for (Pair<ScriptDescriptor, Type> t : earlierScripts) {
ScriptDescriptor earlierDescriptor = t.first;
earlierScriptDescriptors.add(earlierDescriptor);
}
@@ -238,12 +238,12 @@ public class ScriptCodegen extends MemberCodegen {
public void compileScript(
@NotNull JetScript script,
@NotNull JvmClassName className,
@NotNull List<Pair<ScriptDescriptor, JvmClassName>> earlierScripts,
@NotNull Type classType,
@NotNull List<Pair<ScriptDescriptor, Type>> earlierScripts,
@NotNull CompilationErrorHandler errorHandler
) {
registerEarlierScripts(earlierScripts);
registerClassNameForScript(state.getBindingTrace(), script, className);
registerClassNameForScript(state.getBindingTrace(), script, JvmClassName.byInternalName(classType.getInternalName()));
state.beforeCompile();
KotlinCodegenFacade.generateNamespace(
@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.jet.lexer.JetTokens;
@@ -132,14 +131,14 @@ public abstract class StackValue {
}
@NotNull
public static Field field(@NotNull Type type, @NotNull JvmClassName owner, @NotNull String name, boolean isStatic) {
public static Field field(@NotNull Type type, @NotNull Type owner, @NotNull String name, boolean isStatic) {
return new Field(type, owner, name, isStatic);
}
@NotNull
public static Property property(
@NotNull PropertyDescriptor descriptor,
@NotNull JvmClassName methodOwner,
@NotNull Type methodOwner,
@NotNull Type type,
boolean isStatic,
@NotNull String name,
@@ -288,8 +287,8 @@ public abstract class StackValue {
return None.INSTANCE;
}
public static StackValue fieldForSharedVar(Type type, JvmClassName name, String fieldName) {
return new FieldForSharedVar(type, name, fieldName);
public static StackValue fieldForSharedVar(Type localType, Type classType, String fieldName) {
return new FieldForSharedVar(localType, classType, fieldName);
}
public static StackValue composed(StackValue prefix, StackValue suffix) {
@@ -334,7 +333,7 @@ public abstract class StackValue {
public static Field singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
FieldInfo info = FieldInfo.createForSingleton(classDescriptor, typeMapper);
return field(info.getFieldType(), JvmClassName.byInternalName(info.getOwnerInternalName()), info.getFieldName(), true);
return field(info.getFieldType(), Type.getObjectType(info.getOwnerInternalName()), info.getFieldName(), true);
}
private static class None extends StackValue {
@@ -830,10 +829,10 @@ public abstract class StackValue {
static class Field extends StackValueWithSimpleReceiver {
final JvmClassName owner;
final Type owner;
final String name;
public Field(Type type, JvmClassName owner, String name, boolean isStatic) {
public Field(Type type, Type owner, String name, boolean isStatic) {
super(type, isStatic);
this.owner = owner;
this.name = name;
@@ -858,7 +857,7 @@ public abstract class StackValue {
@Nullable
private final CallableMethod setter;
@NotNull
public final JvmClassName methodOwner;
public final Type methodOwner;
@NotNull
private final PropertyDescriptor descriptor;
@@ -868,7 +867,7 @@ public abstract class StackValue {
private final String name;
public Property(
@NotNull PropertyDescriptor descriptor, @NotNull JvmClassName methodOwner,
@NotNull PropertyDescriptor descriptor, @NotNull Type methodOwner,
@Nullable CallableMethod getter, @Nullable CallableMethod setter, boolean isStatic,
@NotNull String name, @NotNull Type type, @NotNull GenerationState state
) {
@@ -1014,10 +1013,10 @@ public abstract class StackValue {
}
static class FieldForSharedVar extends StackValueWithSimpleReceiver {
final JvmClassName owner;
final Type owner;
final String name;
public FieldForSharedVar(Type type, JvmClassName owner, String name) {
public FieldForSharedVar(Type type, Type owner, String name) {
super(type, false);
this.owner = owner;
this.name = name;
@@ -1162,7 +1161,7 @@ public abstract class StackValue {
}
else {
//noinspection ConstantConditions
return callableMethod.getThisType().getAsmType();
return callableMethod.getThisType();
}
}
else {
@@ -1198,7 +1197,7 @@ public abstract class StackValue {
if (thisObject.exists()) {
if (receiverArgument.exists()) {
if (callableMethod != null) {
codegen.generateFromResolvedCall(thisObject, callableMethod.getOwner().getAsmType());
codegen.generateFromResolvedCall(thisObject, callableMethod.getOwner());
}
else {
codegen.generateFromResolvedCall(thisObject, codegen.typeMapper
@@ -131,7 +131,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
ClassDescriptor classDescriptor = bindingContext.get(CLASS_FOR_SCRIPT, bindingContext.get(SCRIPT, file.getScript()));
classStack.push(classDescriptor);
//noinspection ConstantConditions
nameStack.push(classNameForScriptPsi(bindingContext, file.getScript()).getInternalName());
nameStack.push(asmTypeForScriptPsi(bindingContext, file.getScript()).getInternalName());
}
else {
nameStack.push(JvmClassName.byFqNameWithoutInnerClasses(JetPsiUtil.getFQName(file)).getInternalName());
@@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl;
@@ -79,19 +80,19 @@ public class CodegenBinding {
}
@NotNull
public static JvmClassName classNameForScriptDescriptor(BindingContext bindingContext, @NotNull ScriptDescriptor scriptDescriptor) {
public static Type asmTypeForScriptDescriptor(BindingContext bindingContext, @NotNull ScriptDescriptor scriptDescriptor) {
ClassDescriptor classDescriptor = bindingContext.get(CLASS_FOR_SCRIPT, scriptDescriptor);
//noinspection ConstantConditions
return fqn(bindingContext, classDescriptor);
}
@NotNull
public static JvmClassName classNameForScriptPsi(BindingContext bindingContext, @NotNull JetScript script) {
public static Type asmTypeForScriptPsi(BindingContext bindingContext, @NotNull JetScript script) {
ScriptDescriptor scriptDescriptor = bindingContext.get(SCRIPT, script);
if (scriptDescriptor == null) {
throw new IllegalStateException("Script descriptor not found by PSI " + script);
}
return classNameForScriptDescriptor(bindingContext, scriptDescriptor);
return asmTypeForScriptDescriptor(bindingContext, scriptDescriptor);
}
public static ClassDescriptor enclosingClassDescriptor(BindingContext bindingContext, ClassDescriptor descriptor) {
@@ -109,13 +110,13 @@ public class CodegenBinding {
}
@NotNull
private static JvmClassName fqn(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor descriptor) {
private static Type fqn(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor descriptor) {
//noinspection ConstantConditions
return bindingContext.get(FQN, descriptor);
return bindingContext.get(FQN, descriptor).getAsmType();
}
@NotNull
public static JvmClassName classNameForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull JetElement expression) {
public static Type asmTypeForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull JetElement expression) {
if (expression instanceof JetObjectLiteralExpression) {
JetObjectLiteralExpression jetObjectLiteralExpression = (JetObjectLiteralExpression) expression;
expression = jetObjectLiteralExpression.getObjectDeclaration();
@@ -125,14 +126,14 @@ public class CodegenBinding {
if (descriptor == null) {
SimpleFunctionDescriptor functionDescriptor = bindingContext.get(FUNCTION, expression);
assert functionDescriptor != null;
return classNameForAnonymousClass(bindingContext, functionDescriptor);
return asmTypeForAnonymousClass(bindingContext, functionDescriptor);
}
return fqn(bindingContext, descriptor);
}
@NotNull
public static JvmClassName classNameForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull FunctionDescriptor descriptor) {
public static Type asmTypeForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull FunctionDescriptor descriptor) {
ClassDescriptor classDescriptor = anonymousClassForFunction(bindingContext, descriptor);
return fqn(bindingContext, classDescriptor);
}
@@ -153,7 +153,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
}
@NotNull
public FieldOwnerContext intoNamespacePart(@NotNull JvmClassName delegateTo, @NotNull NamespaceDescriptor descriptor) {
public FieldOwnerContext intoNamespacePart(@NotNull Type delegateTo, @NotNull NamespaceDescriptor descriptor) {
return new NamespaceContext(descriptor, this, new OwnerKind.StaticDelegateKind(delegateTo));
}
@@ -278,7 +278,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
ClassDescriptor enclosingClass = getEnclosingClass();
outerExpression = enclosingClass != null && canHaveOuter(typeMapper.getBindingContext(), classDescriptor)
? StackValue.field(typeMapper.mapType(enclosingClass),
CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor),
CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor).getAsmType(),
CAPTURED_THIS_FIELD,
false)
: null;
@@ -295,7 +295,9 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
for (LocalLookup.LocalLookupCase aCase : LocalLookup.LocalLookupCase.values()) {
if (aCase.isCase(d, state)) {
StackValue innerValue = aCase.innerValue(d, enclosingLocalLookup, state, closure, state.getBindingContext().get(FQN, getThisDescriptor()));
JvmClassName className = state.getBindingContext().get(FQN, getThisDescriptor());
Type classType = className == null ? null : className.getAsmType();
StackValue innerValue = aCase.innerValue(d, enclosingLocalLookup, state, closure, classType);
if (innerValue == null) {
break;
}
@@ -22,11 +22,10 @@ import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.codegen.binding.MutableClosure;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.types.JetType;
import static org.jetbrains.jet.codegen.AsmUtil.CAPTURED_RECEIVER_FIELD;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
public interface LocalLookup {
@@ -44,7 +43,8 @@ public interface LocalLookup {
DeclarationDescriptor d,
LocalLookup localLookup,
GenerationState state,
MutableClosure closure, JvmClassName className
MutableClosure closure,
Type classType
) {
VariableDescriptor vd = (VariableDescriptor) d;
@@ -57,8 +57,8 @@ public interface LocalLookup {
String fieldName = "$" + vd.getName();
StackValue innerValue = sharedVarType != null
? StackValue.fieldForSharedVar(localType, className, fieldName)
: StackValue.field(type, className, fieldName, false);
? StackValue.fieldForSharedVar(localType, classType, fieldName)
: StackValue.field(type, classType, fieldName, false);
closure.recordField(fieldName, type);
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, type));
@@ -79,17 +79,17 @@ public interface LocalLookup {
LocalLookup localLookup,
GenerationState state,
MutableClosure closure,
JvmClassName className
Type classType
) {
FunctionDescriptor vd = (FunctionDescriptor) d;
boolean idx = localLookup != null && localLookup.lookupLocal(vd);
if (!idx) return null;
Type localType = classNameForAnonymousClass(state.getBindingContext(), vd).getAsmType();
Type localType = asmTypeForAnonymousClass(state.getBindingContext(), vd);
String fieldName = "$" + vd.getName();
StackValue innerValue = StackValue.field(localType, className, fieldName, false);
StackValue innerValue = StackValue.field(localType, classType, fieldName, false);
closure.recordField(fieldName, localType);
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, localType));
@@ -109,13 +109,14 @@ public interface LocalLookup {
DeclarationDescriptor d,
LocalLookup enclosingLocalLookup,
GenerationState state,
MutableClosure closure, JvmClassName className
MutableClosure closure,
Type classType
) {
if (closure.getEnclosingReceiverDescriptor() != d) return null;
JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
Type type = state.getTypeMapper().mapType(receiverType);
StackValue innerValue = StackValue.field(type, className, CAPTURED_RECEIVER_FIELD, false);
StackValue innerValue = StackValue.field(type, classType, CAPTURED_RECEIVER_FIELD, false);
closure.setCaptureReceiver();
return innerValue;
@@ -135,7 +136,7 @@ public interface LocalLookup {
LocalLookup localLookup,
GenerationState state,
MutableClosure closure,
JvmClassName className
Type classType
);
public StackValue outerValue(EnclosedValueDescriptor d, ExpressionCodegen expressionCodegen) {
@@ -54,7 +54,6 @@ import static org.jetbrains.jet.codegen.AsmUtil.getTraitImplThisParameterType;
import static org.jetbrains.jet.codegen.CodegenUtil.*;
import static org.jetbrains.jet.codegen.FunctionTypesUtil.getFunctionTraitClassName;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass;
public class JetTypeMapper extends BindingTraceAware {
@@ -68,12 +67,12 @@ public class JetTypeMapper extends BindingTraceAware {
}
@NotNull
public JvmClassName getOwner(DeclarationDescriptor descriptor, OwnerKind kind, boolean isInsideModule) {
public Type getOwner(DeclarationDescriptor descriptor, OwnerKind kind, boolean isInsideModule) {
JetTypeMapperMode mapTypeMode = ownerKindToMapTypeMode(kind);
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
if (containingDeclaration instanceof NamespaceDescriptor) {
return jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration, descriptor, isInsideModule);
return asmTypeForNamespace((NamespaceDescriptor) containingDeclaration, descriptor, isInsideModule);
}
else if (containingDeclaration instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
@@ -84,10 +83,10 @@ public class JetTypeMapper extends BindingTraceAware {
if (asmType.getSort() != Type.OBJECT) {
throw new IllegalStateException();
}
return JvmClassName.byType(asmType);
return asmType;
}
else if (containingDeclaration instanceof ScriptDescriptor) {
return classNameForScriptDescriptor(bindingContext, (ScriptDescriptor) containingDeclaration);
return asmTypeForScriptDescriptor(bindingContext, (ScriptDescriptor) containingDeclaration);
}
else {
throw new UnsupportedOperationException("don't know how to generate owner for parent " + containingDeclaration);
@@ -128,7 +127,7 @@ public class JetTypeMapper extends BindingTraceAware {
}
@NotNull
private JvmClassName jvmClassNameForNamespace(
private Type asmTypeForNamespace(
@NotNull NamespaceDescriptor namespace,
@NotNull DeclarationDescriptor descriptor,
boolean insideModule
@@ -170,7 +169,7 @@ public class JetTypeMapper extends BindingTraceAware {
throw new IllegalStateException("internal error: failed to generate classname for " + namespace);
}
return JvmClassName.byInternalName(r.toString());
return Type.getObjectType(r.toString());
}
@NotNull
@@ -482,11 +481,11 @@ public class JetTypeMapper extends BindingTraceAware {
functionDescriptor = unwrapFakeOverride(functionDescriptor);
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), true, kind);
JvmClassName owner;
JvmClassName ownerForDefaultImpl;
JvmClassName ownerForDefaultParam;
Type owner;
Type ownerForDefaultImpl;
Type ownerForDefaultParam;
int invokeOpcode;
JvmClassName thisClass;
Type thisClass;
Type calleeType = null;
if (isLocalNamedFun(functionDescriptor) || functionDescriptor instanceof ExpressionAsFunctionDescriptor) {
@@ -499,15 +498,15 @@ public class JetTypeMapper extends BindingTraceAware {
}
functionDescriptor = functionDescriptor.getOriginal();
owner = classNameForAnonymousClass(bindingContext, functionDescriptor);
owner = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
ownerForDefaultImpl = ownerForDefaultParam = thisClass = owner;
invokeOpcode = INVOKEVIRTUAL;
descriptor = mapSignature("invoke", functionDescriptor, true, kind);
calleeType = owner.getAsmType();
calleeType = owner;
}
else if (functionParent instanceof NamespaceDescriptor) {
assert !superCall;
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent, functionDescriptor, isInsideModule);
owner = asmTypeForNamespace((NamespaceDescriptor) functionParent, functionDescriptor, isInsideModule);
ownerForDefaultImpl = ownerForDefaultParam = owner;
invokeOpcode = INVOKESTATIC;
thisClass = null;
@@ -515,14 +514,14 @@ public class JetTypeMapper extends BindingTraceAware {
else if (functionDescriptor instanceof ConstructorDescriptor) {
assert !superCall;
ClassDescriptor containingClass = (ClassDescriptor) functionParent;
owner = JvmClassName.byType(mapType(containingClass.getDefaultType(), JetTypeMapperMode.IMPL));
owner = mapType(containingClass.getDefaultType(), JetTypeMapperMode.IMPL);
ownerForDefaultImpl = ownerForDefaultParam = owner;
invokeOpcode = INVOKESPECIAL;
thisClass = null;
}
else if (functionParent instanceof ScriptDescriptor) {
thisClass = owner =
ownerForDefaultParam = ownerForDefaultImpl = classNameForScriptDescriptor(bindingContext, (ScriptDescriptor) functionParent);
thisClass = owner = ownerForDefaultParam = ownerForDefaultImpl =
asmTypeForScriptDescriptor(bindingContext, (ScriptDescriptor) functionParent);
invokeOpcode = INVOKEVIRTUAL;
}
else if (functionParent instanceof ClassDescriptor) {
@@ -548,12 +547,11 @@ public class JetTypeMapper extends BindingTraceAware {
// TODO: TYPE_PARAMETER is hack here
boolean isInterface = originalIsInterface && currentIsInterface;
Type type = mapType(receiver.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER);
owner = JvmClassName.byType(type);
owner = mapType(receiver.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER);
ClassDescriptor declarationOwnerForDefault = (ClassDescriptor) findBaseDeclaration(functionDescriptor).getContainingDeclaration();
ownerForDefaultParam = JvmClassName.byType(mapType(declarationOwnerForDefault.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER));
ownerForDefaultImpl = JvmClassName.byInternalName(
ownerForDefaultParam = mapType(declarationOwnerForDefault.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER);
ownerForDefaultImpl = Type.getObjectType(
ownerForDefaultParam.getInternalName() + (isInterface(declarationOwnerForDefault) ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
if (isInterface) {
invokeOpcode = superCall ? INVOKESTATIC : INVOKEINTERFACE;
@@ -570,9 +568,9 @@ public class JetTypeMapper extends BindingTraceAware {
if (isInterface && superCall) {
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
owner = Type.getObjectType(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
}
thisClass = JvmClassName.byType(mapType(receiver.getDefaultType()));
thisClass = mapType(receiver.getDefaultType());
}
else {
throw new UnsupportedOperationException("unknown function parent");
@@ -876,7 +874,7 @@ public class JetTypeMapper extends BindingTraceAware {
type = sharedVarType;
}
else if (isLocalNamedFun(variableDescriptor)) {
type = classNameForAnonymousClass(bindingContext, (FunctionDescriptor) variableDescriptor).getAsmType();
type = asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) variableDescriptor);
}
if (type != null) {
@@ -953,11 +951,10 @@ public class JetTypeMapper extends BindingTraceAware {
public CallableMethod mapToCallableMethod(@NotNull ConstructorDescriptor descriptor, @Nullable CalculatedClosure closure) {
JvmMethodSignature method = mapConstructorSignature(descriptor, closure);
JetType defaultType = descriptor.getContainingDeclaration().getDefaultType();
Type mapped = mapType(defaultType, JetTypeMapperMode.IMPL);
if (mapped.getSort() != Type.OBJECT) {
throw new IllegalStateException("type must have been mapped to object: " + defaultType + ", actual: " + mapped);
Type owner = mapType(defaultType, JetTypeMapperMode.IMPL);
if (owner.getSort() != Type.OBJECT) {
throw new IllegalStateException("type must have been mapped to object: " + defaultType + ", actual: " + owner);
}
JvmClassName owner = JvmClassName.byType(mapped);
return new CallableMethod(owner, owner, owner, method, INVOKESPECIAL, null, null, null);
}
@@ -969,15 +966,13 @@ public class JetTypeMapper extends BindingTraceAware {
public Type getSharedVarType(DeclarationDescriptor descriptor) {
if (descriptor instanceof PropertyDescriptor) {
return StackValue
.sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType()));
return StackValue.sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType()));
}
else if (descriptor instanceof SimpleFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) {
return classNameForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor).getAsmType();
return asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
}
else if (descriptor instanceof FunctionDescriptor) {
return StackValue
.sharedTypeForType(mapType(((FunctionDescriptor) descriptor).getReceiverParameter().getType()));
return StackValue.sharedTypeForType(mapType(((FunctionDescriptor) descriptor).getReceiverParameter().getType()));
}
else if (descriptor instanceof VariableDescriptor && isVarCapturedInClosure(bindingContext, descriptor)) {
JetType outType = ((VariableDescriptor) descriptor).getType();
@@ -989,7 +984,7 @@ public class JetTypeMapper extends BindingTraceAware {
@NotNull
public CallableMethod mapToFunctionInvokeCallableMethod(@NotNull FunctionDescriptor fd) {
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
JvmClassName owner = getFunctionTraitClassName(fd);
Type owner = getFunctionTraitClassName(fd);
Type receiverParameterType;
ReceiverParameterDescriptor receiverParameter = fd.getOriginal().getReceiverParameter();
if (receiverParameter != null) {
@@ -998,7 +993,7 @@ public class JetTypeMapper extends BindingTraceAware {
else {
receiverParameterType = null;
}
return new CallableMethod(owner, null, null, descriptor, INVOKEINTERFACE, owner, receiverParameterType, owner.getAsmType());
return new CallableMethod(owner, null, null, descriptor, INVOKEINTERFACE, owner, receiverParameterType, owner);
}
@NotNull
@@ -17,8 +17,8 @@
package org.jetbrains.jet.cli.jvm.repl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
public class EarlierLine {
@NotNull
@@ -30,14 +30,14 @@ public class EarlierLine {
@NotNull
private final Object scriptInstance;
@NotNull
private final JvmClassName className;
private final Type classType;
public EarlierLine(@NotNull String code, @NotNull ScriptDescriptor scriptDescriptor, @NotNull Class<?> scriptClass, @NotNull Object scriptInstance, @NotNull JvmClassName className) {
public EarlierLine(@NotNull String code, @NotNull ScriptDescriptor scriptDescriptor, @NotNull Class<?> scriptClass, @NotNull Object scriptInstance, @NotNull Type classType) {
this.code = code;
this.scriptDescriptor = scriptDescriptor;
this.scriptClass = scriptClass;
this.scriptInstance = scriptInstance;
this.className = className;
this.classType = classType;
}
@NotNull
@@ -61,7 +61,7 @@ public class EarlierLine {
}
@NotNull
public JvmClassName getClassName() {
return className;
public Type getClassType() {
return classType;
}
}
@@ -29,6 +29,7 @@ import com.intellij.psi.impl.PsiFileFactoryImpl;
import com.intellij.testFramework.LightVirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
@@ -66,6 +67,8 @@ import java.net.URLClassLoader;
import java.util.Collections;
import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.fqNameByAsmTypeUnsafe;
public class ReplInterpreter {
private int lineNumber = 0;
@@ -181,7 +184,7 @@ public class ReplInterpreter {
public LineResult eval(@NotNull String line) {
++lineNumber;
JvmClassName scriptClassName = JvmClassName.byInternalName("Line" + lineNumber);
Type scriptClassType = Type.getObjectType("Line" + lineNumber);
StringBuilder fullText = new StringBuilder();
for (String prevLine : previousIncompleteLines) {
@@ -219,16 +222,16 @@ public class ReplInterpreter {
return LineResult.error(errorCollector.getString());
}
List<Pair<ScriptDescriptor, JvmClassName>> earierScripts = Lists.newArrayList();
List<Pair<ScriptDescriptor, Type>> earlierScripts = Lists.newArrayList();
for (EarlierLine earlierLine : earlierLines) {
earierScripts.add(Pair.create(earlierLine.getScriptDescriptor(), earlierLine.getClassName()));
earlierScripts.add(Pair.create(earlierLine.getScriptDescriptor(), earlierLine.getClassType()));
}
BindingContext bindingContext = AnalyzeExhaust.success(trace.getBindingContext(), module).getBindingContext();
GenerationState generationState = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false),
bindingContext, Collections.singletonList(psiFile));
generationState.getScriptCodegen().compileScript(psiFile.getScript(), scriptClassName, earierScripts,
generationState.getScriptCodegen().compileScript(psiFile.getScript(), scriptClassType, earlierScripts,
CompilationErrorHandler.THROW_EXCEPTION);
for (String file : generationState.getFactory().files()) {
@@ -236,7 +239,7 @@ public class ReplInterpreter {
}
try {
Class<?> scriptClass = classLoader.loadClass(scriptClassName.getFqName().asString());
Class<?> scriptClass = classLoader.loadClass(fqNameByAsmTypeUnsafe(scriptClassType).asString());
Class<?>[] constructorParams = new Class<?>[earlierLines.size()];
Object[] constructorArgs = new Object[earlierLines.size()];
@@ -257,7 +260,7 @@ public class ReplInterpreter {
rvField.setAccessible(true);
Object rv = rvField.get(scriptInstance);
earlierLines.add(new EarlierLine(line, scriptDescriptor, scriptClass, scriptInstance, scriptClassName));
earlierLines.add(new EarlierLine(line, scriptDescriptor, scriptClass, scriptInstance, scriptClassType));
return LineResult.successful(rv, scriptDescriptor.getReturnType().equals(KotlinBuiltIns.getInstance().getUnitType()));
} catch (Throwable e) {
@@ -210,7 +210,7 @@ public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
Type javaAnalog = KotlinToJavaTypesMap.getInstance().getJavaAnalog(originalType);
if (javaAnalog == null || javaAnalog.getSort() != Type.OBJECT) return null;
Collection<ClassDescriptor> descriptors =
JavaToKotlinClassMap.getInstance().mapPlatformClass(JvmClassName.byType(javaAnalog).getFqName());
JavaToKotlinClassMap.getInstance().mapPlatformClass(JvmClassName.byInternalName(javaAnalog.getInternalName()).getFqName());
for (ClassDescriptor descriptor : descriptors) {
String fqName = DescriptorUtils.getFQName(descriptor).asString();
if (isSameName(qualifiedName, fqName)) {
@@ -28,14 +28,6 @@ public class JvmClassName {
return new JvmClassName(internalName);
}
@NotNull
public static JvmClassName byType(@NotNull Type type) {
if (type.getSort() != Type.OBJECT) {
throw new IllegalArgumentException("Type is not convertible to " + JvmClassName.class.getSimpleName() + ": " + type);
}
return byInternalName(type.getInternalName());
}
/**
* WARNING: fq name cannot be uniquely mapped to JVM class name.
*/
@@ -34,6 +34,7 @@ import com.sun.jdi.request.ClassPrepareRequest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.codegen.ClassBuilderMode;
import org.jetbrains.jet.codegen.NamespaceCodegen;
@@ -55,7 +56,7 @@ import java.util.Collection;
import java.util.List;
import java.util.WeakHashMap;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
public class JetPositionManager implements PositionManager {
private final DebugProcess myDebugProcess;
@@ -139,8 +140,8 @@ public class JetPositionManager implements PositionManager {
result.set(getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) element));
}
else if (element instanceof JetFunctionLiteral) {
result.set(classNameForAnonymousClass(typeMapper.getBindingContext(),
((JetFunctionLiteral) element)).getInternalName());
Type asmType = asmTypeForAnonymousClass(typeMapper.getBindingContext(), ((JetFunctionLiteral) element));
result.set(asmType.getInternalName());
}
else if (element instanceof JetNamedFunction) {
PsiElement parent = PsiTreeUtil.getParentOfType(element, JetClassOrObject.class, JetFunctionLiteralExpression.class, JetNamedFunction.class);
@@ -148,8 +149,8 @@ public class JetPositionManager implements PositionManager {
result.set(getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) parent));
}
else if (parent instanceof JetFunctionLiteralExpression || parent instanceof JetNamedFunction) {
result.set(classNameForAnonymousClass(typeMapper.getBindingContext(),
(JetElement) element).getInternalName());
Type asmType = asmTypeForAnonymousClass(typeMapper.getBindingContext(), (JetElement) element);
result.set(asmType.getInternalName());
}
}
@@ -70,6 +70,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import static org.jetbrains.jet.codegen.AsmUtil.fqNameByAsmTypeUnsafe;
import static org.jetbrains.jet.plugin.libraries.MemberMatching.*;
public class JetSourceNavigationHelper {
@@ -360,7 +361,7 @@ public class JetSourceNavigationHelper {
if (javaAnalog.getSort() != Type.OBJECT) {
return null;
}
String fqName = JvmClassName.byType(javaAnalog).getFqName().asString();
String fqName = fqNameByAsmTypeUnsafe(javaAnalog).asString();
return JavaPsiFacade.getInstance(classOrObject.getProject()).
findClass(fqName, GlobalSearchScope.allScope(classOrObject.getProject()));
}
@@ -390,7 +391,7 @@ public class JetSourceNavigationHelper {
if (vFile == null || !idx.isInLibrarySource(vFile)) return null;
final Set<OrderEntry> orderEntries = new THashSet<OrderEntry>(idx.getOrderEntriesForFile(vFile));
PsiClass original = JavaPsiFacade.getInstance(project).findClass(fqName, new GlobalSearchScope(project) {
return JavaPsiFacade.getInstance(project).findClass(fqName, new GlobalSearchScope(project) {
@Override
public int compare(VirtualFile file1, VirtualFile file2) {
return 0;
@@ -399,9 +400,7 @@ public class JetSourceNavigationHelper {
@Override
public boolean contains(VirtualFile file) {
List<OrderEntry> entries = idx.getOrderEntriesForFile(file);
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < entries.size(); i++) {
final OrderEntry entry = entries.get(i);
for (OrderEntry entry : entries) {
if (orderEntries.contains(entry)) return true;
}
return false;
@@ -417,8 +416,6 @@ public class JetSourceNavigationHelper {
return true;
}
});
return original;
}
@NotNull