Merge remote-tracking branch 'origin/master'

This commit is contained in:
pTalanov
2012-02-24 19:06:24 +04:00
73 changed files with 243 additions and 225 deletions
@@ -119,7 +119,7 @@ public abstract class ClassBodyCodegen {
if(state.getStandardLibrary().isVolatile(propertyDescriptor)) { if(state.getStandardLibrary().isVolatile(propertyDescriptor)) {
modifiers |= Opcodes.ACC_VOLATILE; modifiers |= Opcodes.ACC_VOLATILE;
} }
v.newField(p, modifiers, p.getName(), state.getTypeMapper().mapType(propertyDescriptor.getOutType()).getDescriptor(), null, null); v.newField(p, modifiers, p.getName(), state.getTypeMapper().mapType(propertyDescriptor.getType()).getDescriptor(), null, null);
} }
} }
} }
@@ -113,7 +113,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
final String funClass = getInternalClassName(funDescriptor); final String funClass = getInternalClassName(funDescriptor);
signatureWriter.visitClassType(funClass); signatureWriter.visitClassType(funClass);
for (ValueParameterDescriptor parameter : parameters) { for (ValueParameterDescriptor parameter : parameters) {
appendType(signatureWriter, parameter.getOutType(), '='); appendType(signatureWriter, parameter.getType(), '=');
} }
appendType(signatureWriter, funDescriptor.getReturnType(), '='); appendType(signatureWriter, funDescriptor.getReturnType(), '=');
@@ -233,7 +233,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
final List<ValueParameterDescriptor> params = funDescriptor.getValueParameters(); final List<ValueParameterDescriptor> params = funDescriptor.getValueParameters();
for (ValueParameterDescriptor param : params) { for (ValueParameterDescriptor param : params) {
StackValue.local(count, JetTypeMapper.TYPE_OBJECT).put(JetTypeMapper.TYPE_OBJECT, iv); StackValue.local(count, JetTypeMapper.TYPE_OBJECT).put(JetTypeMapper.TYPE_OBJECT, iv);
StackValue.onStack(JetTypeMapper.TYPE_OBJECT).upcast(state.getTypeMapper().mapType(param.getOutType()), iv); StackValue.onStack(JetTypeMapper.TYPE_OBJECT).upcast(state.getTypeMapper().mapType(param.getType()), iv);
count++; count++;
} }
@@ -280,7 +280,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
for (DeclarationDescriptor descriptor : closure.keySet()) { for (DeclarationDescriptor descriptor : closure.keySet()) {
if(descriptor instanceof VariableDescriptor && !(descriptor instanceof PropertyDescriptor)) { if(descriptor instanceof VariableDescriptor && !(descriptor instanceof PropertyDescriptor)) {
final Type sharedVarType = exprContext.getTypeMapper().getSharedVarType(descriptor); final Type sharedVarType = exprContext.getTypeMapper().getSharedVarType(descriptor);
final Type type = sharedVarType != null ? sharedVarType : state.getTypeMapper().mapType(((VariableDescriptor) descriptor).getOutType()); final Type type = sharedVarType != null ? sharedVarType : state.getTypeMapper().mapType(((VariableDescriptor) descriptor).getType());
argTypes[i++] = type; argTypes[i++] = type;
} }
else if(CodegenUtil.isNamedFun(descriptor, state.getBindingContext()) && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) { else if(CodegenUtil.isNamedFun(descriptor, state.getBindingContext()) && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) {
@@ -230,12 +230,12 @@ public abstract class CodegenContext {
if(accessor != null) if(accessor != null)
return accessor; return accessor;
if(descriptor instanceof NamedFunctionDescriptor) { if(descriptor instanceof SimpleFunctionDescriptor) {
NamedFunctionDescriptorImpl myAccessor = new NamedFunctionDescriptorImpl(contextType, SimpleFunctionDescriptorImpl myAccessor = new SimpleFunctionDescriptorImpl(contextType,
Collections.<AnnotationDescriptor>emptyList(), Collections.<AnnotationDescriptor>emptyList(),
descriptor.getName() + "$bridge$" + accessors.size(), descriptor.getName() + "$bridge$" + accessors.size(),
CallableMemberDescriptor.Kind.DECLARATION); CallableMemberDescriptor.Kind.DECLARATION);
FunctionDescriptor fd = (NamedFunctionDescriptor) descriptor; FunctionDescriptor fd = (SimpleFunctionDescriptor) descriptor;
myAccessor.initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null, myAccessor.initialize(fd.getReceiverParameter().exists() ? fd.getReceiverParameter().getType() : null,
fd.getExpectedThisObject(), fd.getExpectedThisObject(),
fd.getTypeParameters(), fd.getTypeParameters(),
@@ -257,13 +257,13 @@ public abstract class CodegenContext {
CallableMemberDescriptor.Kind.DECLARATION CallableMemberDescriptor.Kind.DECLARATION
); );
JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null; JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null;
myAccessor.setType(pd.getOutType(), Collections.<TypeParameterDescriptor>emptyList(), pd.getExpectedThisObject(), receiverType); myAccessor.setType(pd.getType(), Collections.<TypeParameterDescriptor>emptyList(), pd.getExpectedThisObject(), receiverType);
PropertyGetterDescriptor pgd = new PropertyGetterDescriptor( PropertyGetterDescriptor pgd = new PropertyGetterDescriptor(
myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(), myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(),
myAccessor.getVisibility(), myAccessor.getVisibility(),
false, false, CallableMemberDescriptor.Kind.DECLARATION); false, false, CallableMemberDescriptor.Kind.DECLARATION);
pgd.initialize(myAccessor.getOutType()); pgd.initialize(myAccessor.getType());
PropertySetterDescriptor psd = new PropertySetterDescriptor( PropertySetterDescriptor psd = new PropertySetterDescriptor(
myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(), myAccessor, Collections.<AnnotationDescriptor>emptyList(), myAccessor.getModality(),
@@ -74,9 +74,9 @@ public class CodegenUtil {
return (ClassDescriptor) outerDescriptor; return (ClassDescriptor) outerDescriptor;
} }
public static NamedFunctionDescriptor createInvoke(FunctionDescriptor fd) { public static SimpleFunctionDescriptor createInvoke(FunctionDescriptor fd) {
int arity = fd.getValueParameters().size(); int arity = fd.getValueParameters().size();
NamedFunctionDescriptorImpl invokeDescriptor = new NamedFunctionDescriptorImpl( SimpleFunctionDescriptorImpl invokeDescriptor = new SimpleFunctionDescriptorImpl(
fd.getExpectedThisObject().exists() ? JetStandardClasses.getReceiverFunction(arity) : JetStandardClasses.getFunction(arity), fd.getExpectedThisObject().exists() ? JetStandardClasses.getReceiverFunction(arity) : JetStandardClasses.getFunction(arity),
Collections.<AnnotationDescriptor>emptyList(), Collections.<AnnotationDescriptor>emptyList(),
"invoke", "invoke",
@@ -17,7 +17,6 @@
package org.jetbrains.jet.codegen; package org.jetbrains.jet.codegen;
import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Document;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiMethod;
import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.IElementType;
@@ -31,8 +30,6 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.calls.*; import org.jetbrains.jet.lang.resolve.calls.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
@@ -356,7 +353,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
JetType iteratorType = iteratorDescriptor.getReturnType(); JetType iteratorType = iteratorDescriptor.getReturnType();
Type asmIterType = boxType(asmType(iteratorType)); Type asmIterType = boxType(asmType(iteratorType));
JetType paramType = parameterDescriptor.getOutType(); JetType paramType = parameterDescriptor.getType();
Type asmParamType = asmType(paramType); Type asmParamType = asmType(paramType);
int iteratorVar = myFrameMap.enterTemp(); int iteratorVar = myFrameMap.enterTemp();
@@ -431,7 +428,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
} }
public void invoke() { public void invoke() {
JetType paramType = parameterDescriptor.getOutType(); JetType paramType = parameterDescriptor.getType();
Type asmParamType = asmType(paramType); Type asmParamType = asmType(paramType);
myFrameMap.enter(parameterDescriptor, asmParamType.getSize()); myFrameMap.enter(parameterDescriptor, asmParamType.getSize());
@@ -804,7 +801,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if(entry.getKey() instanceof VariableDescriptor && !(entry.getKey() instanceof PropertyDescriptor)) { if(entry.getKey() instanceof VariableDescriptor && !(entry.getKey() instanceof PropertyDescriptor)) {
Type sharedVarType = typeMapper.getSharedVarType(entry.getKey()); Type sharedVarType = typeMapper.getSharedVarType(entry.getKey());
if(sharedVarType == null) if(sharedVarType == null)
sharedVarType = state.getTypeMapper().mapType(((VariableDescriptor) entry.getKey()).getOutType()); sharedVarType = state.getTypeMapper().mapType(((VariableDescriptor) entry.getKey()).getType());
consArgTypes.add(sharedVarType); consArgTypes.add(sharedVarType);
entry.getValue().getOuterValue().put(sharedVarType, v); entry.getValue().getOuterValue().put(sharedVarType, v);
} }
@@ -836,7 +833,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
assert variableDescriptor != null; assert variableDescriptor != null;
final Type sharedVarType = typeMapper.getSharedVarType(variableDescriptor); final Type sharedVarType = typeMapper.getSharedVarType(variableDescriptor);
final Type type = sharedVarType != null ? sharedVarType : asmType(variableDescriptor.getOutType()); final Type type = sharedVarType != null ? sharedVarType : asmType(variableDescriptor.getType());
myFrameMap.enter(variableDescriptor, type.getSize()); myFrameMap.enter(variableDescriptor, type.getSize());
} }
@@ -877,7 +874,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
int index = myFrameMap.leave(variableDescriptor); int index = myFrameMap.leave(variableDescriptor);
final Type sharedVarType = typeMapper.getSharedVarType(variableDescriptor); final Type sharedVarType = typeMapper.getSharedVarType(variableDescriptor);
final Type type = sharedVarType != null ? sharedVarType : asmType(variableDescriptor.getOutType()); final Type type = sharedVarType != null ? sharedVarType : asmType(variableDescriptor.getType());
if(sharedVarType != null) { if(sharedVarType != null) {
v.aconst(null); v.aconst(null);
v.store(index, TYPE_OBJECT); v.store(index, TYPE_OBJECT);
@@ -986,7 +983,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if (index >= 0) { if (index >= 0) {
if(descriptor instanceof VariableDescriptor) { if(descriptor instanceof VariableDescriptor) {
Type sharedVarType = typeMapper.getSharedVarType(descriptor); Type sharedVarType = typeMapper.getSharedVarType(descriptor);
final JetType outType = ((VariableDescriptor) descriptor).getOutType(); final JetType outType = ((VariableDescriptor) descriptor).getType();
if(sharedVarType != null) { if(sharedVarType != null) {
return StackValue.shared(index, asmType(outType)); return StackValue.shared(index, asmType(outType));
} }
@@ -1234,7 +1231,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
ownerParam = callableMethod.getDefaultImplParam(); ownerParam = callableMethod.getDefaultImplParam();
} }
return StackValue.property(propertyDescriptor.getName(), owner, ownerParam, asmType(propertyDescriptor.getOutType()), isStatic, isInterface, isSuper, getter, setter, invokeOpcode); return StackValue.property(propertyDescriptor.getName(), owner, ownerParam, asmType(propertyDescriptor.getType()), isStatic, isInterface, isSuper, getter, setter, invokeOpcode);
} }
@Override @Override
@@ -1246,11 +1243,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if(resolvedCall == null) { if(resolvedCall == null) {
throw new CompilationException("Cannot resolve: " + callee.getText(), null, expression); throw new CompilationException("Cannot resolve: " + callee.getText(), null, expression);
} }
receiver = StackValue.receiver(resolvedCall, receiver, this, null);
DeclarationDescriptor funDescriptor = resolvedCall.getResultingDescriptor(); DeclarationDescriptor funDescriptor = resolvedCall.getResultingDescriptor();
if (funDescriptor instanceof ConstructorDescriptor) { if (funDescriptor instanceof ConstructorDescriptor) {
receiver = StackValue.receiver(resolvedCall, receiver, this, null);
return generateConstructorCall(expression, (JetSimpleNameExpression) callee, receiver); return generateConstructorCall(expression, (JetSimpleNameExpression) callee, receiver);
} }
else if (funDescriptor instanceof FunctionDescriptor) { else if (funDescriptor instanceof FunctionDescriptor) {
@@ -1295,6 +1292,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
return returnValueAsStackValue((FunctionDescriptor) fd, callReturnType); return returnValueAsStackValue((FunctionDescriptor) fd, callReturnType);
} }
else { else {
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
assert resolvedCall != null;
receiver = StackValue.receiver(resolvedCall, receiver, this, null);
IntrinsicMethod intrinsic = (IntrinsicMethod) callable; IntrinsicMethod intrinsic = (IntrinsicMethod) callable;
List<JetExpression> args = new ArrayList<JetExpression>(); List<JetExpression> args = new ArrayList<JetExpression>();
for (ValueArgument argument : expression.getValueArguments()) { for (ValueArgument argument : expression.getValueArguments()) {
@@ -1324,8 +1325,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
assert !superCall; assert !superCall;
callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd); callableMethod = ClosureCodegen.asCallableMethod((FunctionDescriptor) fd);
} }
else if (fd instanceof ExpressionAsFunctionDescriptor || (fd instanceof NamedFunctionDescriptor && fd.getContainingDeclaration() instanceof FunctionDescriptor)) { else if (fd instanceof ExpressionAsFunctionDescriptor || (fd instanceof SimpleFunctionDescriptor && fd.getContainingDeclaration() instanceof FunctionDescriptor)) {
NamedFunctionDescriptor invoke = CodegenUtil.createInvoke((FunctionDescriptor) fd); SimpleFunctionDescriptor invoke = CodegenUtil.createInvoke((FunctionDescriptor) fd);
callableMethod = ClosureCodegen.asCallableMethod(invoke); callableMethod = ClosureCodegen.asCallableMethod(invoke);
} }
else if (fd instanceof FunctionDescriptor) { else if (fd instanceof FunctionDescriptor) {
@@ -1510,7 +1511,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
} }
else if(resolvedValueArgument instanceof VarargValueArgument) { else if(resolvedValueArgument instanceof VarargValueArgument) {
VarargValueArgument valueArgument = (VarargValueArgument) resolvedValueArgument; VarargValueArgument valueArgument = (VarargValueArgument) resolvedValueArgument;
JetType outType = valueParameterDescriptor.getOutType(); JetType outType = valueParameterDescriptor.getType();
Type type = asmType(outType); Type type = asmType(outType);
assert type.getSort() == Type.ARRAY; assert type.getSort() == Type.ARRAY;
@@ -1681,7 +1682,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
StackValue leftValue = gen(expr); StackValue leftValue = gen(expr);
FunctionDescriptor op = (FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference()); FunctionDescriptor op = (FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
assert op != null; assert op != null;
leftValue.put(asmType(op.getValueParameters().get(0).getOutType()), v); leftValue.put(asmType(op.getValueParameters().get(0).getType()), v);
genToJVMStack(expression.getRight()); genToJVMStack(expression.getRight());
v.swap(); v.swap();
invokeFunctionNoParams(op, Type.BOOLEAN_TYPE, v); invokeFunctionNoParams(op, Type.BOOLEAN_TYPE, v);
@@ -2208,7 +2209,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
final Type sharedVarType = typeMapper.getSharedVarType(variableDescriptor); final Type sharedVarType = typeMapper.getSharedVarType(variableDescriptor);
assert variableDescriptor != null; assert variableDescriptor != null;
Type varType = asmType(variableDescriptor.getOutType()); Type varType = asmType(variableDescriptor.getType());
if(sharedVarType != null) { if(sharedVarType != null) {
v.anew(sharedVarType); v.anew(sharedVarType);
v.dup(); v.dup();
@@ -2370,7 +2371,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
final List<JetExpression> indices = expression.getIndexExpressions(); final List<JetExpression> indices = expression.getIndexExpressions();
FunctionDescriptor operationDescriptor = (FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, expression); FunctionDescriptor operationDescriptor = (FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
assert operationDescriptor != null; assert operationDescriptor != null;
if (arrayType.getSort() == Type.ARRAY && indices.size() == 1 && operationDescriptor.getValueParameters().get(0).getOutType().equals(state.getStandardLibrary().getIntType())) { if (arrayType.getSort() == Type.ARRAY && indices.size() == 1 && operationDescriptor.getValueParameters().get(0).getType().equals(state.getStandardLibrary().getIntType())) {
gen(array, arrayType); gen(array, arrayType);
for (JetExpression index : indices) { for (JetExpression index : indices) {
gen(index, Type.INT_TYPE); gen(index, Type.INT_TYPE);
@@ -2498,7 +2499,7 @@ If finally block is present, its last expression is the value of try expression.
VariableDescriptor descriptor = bindingContext.get(BindingContext.VALUE_PARAMETER, clause.getCatchParameter()); VariableDescriptor descriptor = bindingContext.get(BindingContext.VALUE_PARAMETER, clause.getCatchParameter());
assert descriptor != null; assert descriptor != null;
Type descriptorType = asmType(descriptor.getOutType()); Type descriptorType = asmType(descriptor.getType());
myFrameMap.enter(descriptor, 1); myFrameMap.enter(descriptor, 1);
int index = lookupLocal(descriptor); int index = lookupLocal(descriptor);
v.store(index, descriptorType); v.store(index, descriptorType);
@@ -2613,7 +2614,7 @@ If finally block is present, its last expression is the value of try expression.
final JetProperty var = ((JetBindingPattern) pattern).getVariableDeclaration(); final JetProperty var = ((JetBindingPattern) pattern).getVariableDeclaration();
final VariableDescriptor variableDescriptor = bindingContext.get(BindingContext.VARIABLE, var); final VariableDescriptor variableDescriptor = bindingContext.get(BindingContext.VARIABLE, var);
assert variableDescriptor != null; assert variableDescriptor != null;
final Type varType = asmType(variableDescriptor.getOutType()); final Type varType = asmType(variableDescriptor.getType());
myFrameMap.enter(variableDescriptor, varType.getSize()); myFrameMap.enter(variableDescriptor, varType.getSize());
expressionToMatch.dupReceiver(v); expressionToMatch.dupReceiver(v);
expressionToMatch.put(varType, v); expressionToMatch.put(varType, v);
@@ -56,7 +56,7 @@ public class FunctionCodegen {
} }
public void gen(JetNamedFunction f) { public void gen(JetNamedFunction f) {
final NamedFunctionDescriptor functionDescriptor = state.getBindingContext().get(BindingContext.FUNCTION, f); final SimpleFunctionDescriptor functionDescriptor = state.getBindingContext().get(BindingContext.FUNCTION, f);
assert functionDescriptor != null; assert functionDescriptor != null;
JvmMethodSignature method = typeMapper.mapToCallableMethod(functionDescriptor, false, owner.getContextKind()).getSignature(); JvmMethodSignature method = typeMapper.mapToCallableMethod(functionDescriptor, false, owner.getContextKind()).getSignature();
generateMethod(f, method, true, null, functionDescriptor); generateMethod(f, method, true, null, functionDescriptor);
@@ -120,7 +120,7 @@ public class FunctionCodegen {
if (needJetAnnotations) { if (needJetAnnotations) {
if (functionDescriptor instanceof PropertyAccessorDescriptor) { if (functionDescriptor instanceof PropertyAccessorDescriptor) {
PropertyCodegen.generateJetPropertyAnnotation(mv, propertyTypeSignature, jvmSignature.getKotlinTypeParameter()); PropertyCodegen.generateJetPropertyAnnotation(mv, propertyTypeSignature, jvmSignature.getKotlinTypeParameter());
} else if (functionDescriptor instanceof NamedFunctionDescriptor) { } else if (functionDescriptor instanceof SimpleFunctionDescriptor) {
if (propertyTypeSignature != null) { if (propertyTypeSignature != null) {
throw new IllegalStateException(); throw new IllegalStateException();
} }
@@ -153,7 +153,7 @@ public class FunctionCodegen {
if(parameterDescriptor.hasDefaultValue()) { if(parameterDescriptor.hasDefaultValue()) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true); av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true);
} }
if(parameterDescriptor.getOutType().isNullable()) { if(parameterDescriptor.getType().isNullable()) {
av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true); av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NULLABLE_FIELD, true);
} }
if (jvmSignature.getKotlinParameterTypes() != null && jvmSignature.getKotlinParameterTypes().get(i) != null) { if (jvmSignature.getKotlinParameterTypes() != null && jvmSignature.getKotlinParameterTypes().get(i) != null) {
@@ -205,7 +205,7 @@ public class FunctionCodegen {
for (ValueParameterDescriptor parameter : paramDescrs) { for (ValueParameterDescriptor parameter : paramDescrs) {
Type sharedVarType = typeMapper.getSharedVarType(parameter); Type sharedVarType = typeMapper.getSharedVarType(parameter);
if (sharedVarType != null) { if (sharedVarType != null) {
Type localVarType = typeMapper.mapType(parameter.getOutType()); Type localVarType = typeMapper.mapType(parameter.getType());
int index = frameMap.getIndex(parameter); int index = frameMap.getIndex(parameter);
mv.visitTypeInsn(NEW, sharedVarType.getInternalName()); mv.visitTypeInsn(NEW, sharedVarType.getInternalName());
mv.visitInsn(DUP); mv.visitInsn(DUP);
@@ -239,7 +239,7 @@ public class FunctionCodegen {
} }
for (ValueParameterDescriptor parameter : paramDescrs) { for (ValueParameterDescriptor parameter : paramDescrs) {
Type type = typeMapper.mapType(parameter.getOutType()); Type type = typeMapper.mapType(parameter.getType());
// TODO: specify signature // TODO: specify signature
mv.visitLocalVariable(parameter.getName(), type.getDescriptor(), null, methodBegin, methodEnd, k); mv.visitLocalVariable(parameter.getName(), type.getDescriptor(), null, methodBegin, methodEnd, k);
k += type.getSize(); k += type.getSize();
@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.JvmAbi; import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeProjection;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
@@ -452,7 +451,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
for (DeclarationDescriptor descriptor : closure.closure.keySet()) { for (DeclarationDescriptor descriptor : closure.closure.keySet()) {
if(descriptor instanceof VariableDescriptor && !(descriptor instanceof PropertyDescriptor)) { if(descriptor instanceof VariableDescriptor && !(descriptor instanceof PropertyDescriptor)) {
final Type sharedVarType = typeMapper.getSharedVarType(descriptor); final Type sharedVarType = typeMapper.getSharedVarType(descriptor);
final Type type = sharedVarType != null ? sharedVarType : state.getTypeMapper().mapType(((VariableDescriptor) descriptor).getOutType()); final Type type = sharedVarType != null ? sharedVarType : state.getTypeMapper().mapType(((VariableDescriptor) descriptor).getType());
consArgTypes.add(insert++, new JvmMethodParameterSignature(type, "", JvmMethodParameterKind.SHARED_VAR)); consArgTypes.add(insert++, new JvmMethodParameterSignature(type, "", JvmMethodParameterKind.SHARED_VAR));
} }
else if(descriptor instanceof FunctionDescriptor) { else if(descriptor instanceof FunctionDescriptor) {
@@ -533,7 +532,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
HashSet<FunctionDescriptor> overridden = new HashSet<FunctionDescriptor>(); HashSet<FunctionDescriptor> overridden = new HashSet<FunctionDescriptor>();
for (JetDeclaration declaration : myClass.getDeclarations()) { for (JetDeclaration declaration : myClass.getDeclarations()) {
if (declaration instanceof JetNamedFunction) { if (declaration instanceof JetNamedFunction) {
NamedFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, declaration); SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
assert functionDescriptor != null; assert functionDescriptor != null;
overridden.addAll(functionDescriptor.getOverriddenDescriptors()); overridden.addAll(functionDescriptor.getOverriddenDescriptors());
} }
@@ -613,7 +612,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if(varDescr instanceof VariableDescriptor && !(varDescr instanceof PropertyDescriptor)) { if(varDescr instanceof VariableDescriptor && !(varDescr instanceof PropertyDescriptor)) {
Type sharedVarType = typeMapper.getSharedVarType(varDescr); Type sharedVarType = typeMapper.getSharedVarType(varDescr);
if(sharedVarType == null) { if(sharedVarType == null) {
sharedVarType = typeMapper.mapType(((VariableDescriptor) varDescr).getOutType()); sharedVarType = typeMapper.mapType(((VariableDescriptor) varDescr).getType());
} }
iv.load(0, JetTypeMapper.TYPE_OBJECT); iv.load(0, JetTypeMapper.TYPE_OBJECT);
iv.load(k, StackValue.refType(sharedVarType)); iv.load(k, StackValue.refType(sharedVarType));
@@ -629,7 +628,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
for (JetParameter parameter : constructorParameters) { for (JetParameter parameter : constructorParameters) {
if (parameter.getValOrVarNode() != null) { if (parameter.getValOrVarNode() != null) {
VariableDescriptor descriptor = paramDescrs.get(curParam); VariableDescriptor descriptor = paramDescrs.get(curParam);
Type type = typeMapper.mapType(descriptor.getOutType()); Type type = typeMapper.mapType(descriptor.getType());
iv.load(0, classType); iv.load(0, classType);
iv.load(frameMap.getIndex(descriptor), type); iv.load(frameMap.getIndex(descriptor), type);
iv.putfield(classname, descriptor.getName(), type.getDescriptor()); iv.putfield(classname, descriptor.getName(), type.getDescriptor());
@@ -653,7 +652,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
for (Pair<CallableMemberDescriptor, CallableMemberDescriptor> needDelegates : getTraitImplementations(descriptor)) { for (Pair<CallableMemberDescriptor, CallableMemberDescriptor> needDelegates : getTraitImplementations(descriptor)) {
CallableMemberDescriptor callableDescriptor = needDelegates.first; CallableMemberDescriptor callableDescriptor = needDelegates.first;
if (needDelegates.second instanceof NamedFunctionDescriptor) { if (needDelegates.second instanceof SimpleFunctionDescriptor) {
generateDelegationToTraitImpl(codegen, (FunctionDescriptor) needDelegates.second); generateDelegationToTraitImpl(codegen, (FunctionDescriptor) needDelegates.second);
} else if (needDelegates.second instanceof PropertyDescriptor) { } else if (needDelegates.second instanceof PropertyDescriptor) {
PropertyDescriptor property = (PropertyDescriptor) needDelegates.second; PropertyDescriptor property = (PropertyDescriptor) needDelegates.second;
@@ -865,9 +864,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if(compileTimeValue != null) { if(compileTimeValue != null) {
assert compileTimeValue != null; assert compileTimeValue != null;
Object value = compileTimeValue.getValue(); Object value = compileTimeValue.getValue();
Type type = typeMapper.mapType(propertyDescriptor.getOutType()); Type type = typeMapper.mapType(propertyDescriptor.getType());
if(JetTypeMapper.isPrimitive(type)) { if(JetTypeMapper.isPrimitive(type)) {
if( !propertyDescriptor.getOutType().isNullable() && value instanceof Number) { if( !propertyDescriptor.getType().isNullable() && value instanceof Number) {
if(type == Type.INT_TYPE && ((Number)value).intValue() == 0) if(type == Type.INT_TYPE && ((Number)value).intValue() == 0)
continue; continue;
if(type == Type.BYTE_TYPE && ((Number)value).byteValue() == 0) if(type == Type.BYTE_TYPE && ((Number)value).byteValue() == 0)
@@ -893,12 +892,12 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
} }
iv.load(0, JetTypeMapper.TYPE_OBJECT); iv.load(0, JetTypeMapper.TYPE_OBJECT);
Type type = codegen.expressionType(initializer); Type type = codegen.expressionType(initializer);
if(propertyDescriptor.getOutType().isNullable()) if(propertyDescriptor.getType().isNullable())
type = JetTypeMapper.boxType(type); type = JetTypeMapper.boxType(type);
codegen.gen(initializer, type); codegen.gen(initializer, type);
// @todo write directly to the field. Fix test excloset.jet::test6 // @todo write directly to the field. Fix test excloset.jet::test6
String owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION); String owner = typeMapper.getOwner(propertyDescriptor, OwnerKind.IMPLEMENTATION);
StackValue.property(propertyDescriptor.getName(), owner, owner, typeMapper.mapType(propertyDescriptor.getOutType()), false, false, false, null, null, 0).store(iv); StackValue.property(propertyDescriptor.getName(), owner, owner, typeMapper.mapType(propertyDescriptor.getType()), false, false, false, null, null, 0).store(iv);
} }
} }
@@ -924,8 +923,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (declaration instanceof PropertyDescriptor) { if (declaration instanceof PropertyDescriptor) {
propertyCodegen.genDelegate((PropertyDescriptor) declaration, (PropertyDescriptor) overriddenDescriptor, field); propertyCodegen.genDelegate((PropertyDescriptor) declaration, (PropertyDescriptor) overriddenDescriptor, field);
} }
else if (declaration instanceof NamedFunctionDescriptor) { else if (declaration instanceof SimpleFunctionDescriptor) {
functionCodegen.genDelegate((NamedFunctionDescriptor) declaration, overriddenDescriptor, field); functionCodegen.genDelegate((SimpleFunctionDescriptor) declaration, overriddenDescriptor, field);
} }
} }
} }
@@ -488,7 +488,7 @@ public class JetTypeMapper {
for (ValueParameterDescriptor parameter : parameters) { for (ValueParameterDescriptor parameter : parameters) {
signatureVisitor.writeParameterType(JvmMethodParameterKind.VALUE); signatureVisitor.writeParameterType(JvmMethodParameterKind.VALUE);
mapType(parameter.getOutType(), signatureVisitor); mapType(parameter.getType(), signatureVisitor);
signatureVisitor.writeParameterTypeEnd(); signatureVisitor.writeParameterTypeEnd();
} }
@@ -576,7 +576,7 @@ public class JetTypeMapper {
} }
for (ValueParameterDescriptor parameter : parameters) { for (ValueParameterDescriptor parameter : parameters) {
signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE); signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE);
mapType(parameter.getOutType(), signatureWriter); mapType(parameter.getType(), signatureWriter);
signatureWriter.writeParameterTypeEnd(); signatureWriter.writeParameterTypeEnd();
} }
@@ -617,7 +617,7 @@ public class JetTypeMapper {
signatureWriter.writeParametersEnd(); signatureWriter.writeParametersEnd();
signatureWriter.writeReturnType(); signatureWriter.writeReturnType();
mapType(descriptor.getOutType(), signatureWriter); mapType(descriptor.getType(), signatureWriter);
signatureWriter.writeReturnTypeEnd(); signatureWriter.writeReturnTypeEnd();
JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name); JvmMethodSignature jvmMethodSignature = signatureWriter.makeJvmMethodSignature(name);
@@ -636,7 +636,7 @@ public class JetTypeMapper {
writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter); writeFormalTypeParameters(descriptor.getTypeParameters(), signatureWriter);
JetType outType = descriptor.getOutType(); JetType outType = descriptor.getType();
signatureWriter.writeParametersStart(); signatureWriter.writeParametersStart();
@@ -687,7 +687,7 @@ public class JetTypeMapper {
for (ValueParameterDescriptor parameter : parameters) { for (ValueParameterDescriptor parameter : parameters) {
signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE); signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE);
mapType(parameter.getOutType(), signatureWriter); mapType(parameter.getType(), signatureWriter);
signatureWriter.writeParameterTypeEnd(); signatureWriter.writeParameterTypeEnd();
} }
@@ -854,7 +854,7 @@ public class JetTypeMapper {
if(descriptor instanceof PropertyDescriptor) { if(descriptor instanceof PropertyDescriptor) {
return StackValue.sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType())); return StackValue.sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType()));
} }
else if (descriptor instanceof NamedFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) { else if (descriptor instanceof SimpleFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) {
PsiElement psiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor); PsiElement psiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, descriptor);
return Type.getObjectType(classNameForAnonymousClass((JetElement) psiElement)); return Type.getObjectType(classNameForAnonymousClass((JetElement) psiElement));
} }
@@ -864,7 +864,7 @@ public class JetTypeMapper {
else if (descriptor instanceof VariableDescriptor) { else if (descriptor instanceof VariableDescriptor) {
Boolean aBoolean = bindingContext.get(BindingContext.MUST_BE_WRAPPED_IN_A_REF, (VariableDescriptor) descriptor); Boolean aBoolean = bindingContext.get(BindingContext.MUST_BE_WRAPPED_IN_A_REF, (VariableDescriptor) descriptor);
if (aBoolean != null && aBoolean) { if (aBoolean != null && aBoolean) {
JetType outType = ((VariableDescriptor) descriptor).getOutType(); JetType outType = ((VariableDescriptor) descriptor).getType();
return StackValue.sharedTypeForType(mapType(outType)); return StackValue.sharedTypeForType(mapType(outType));
} }
else { else {
@@ -61,7 +61,7 @@ public class ObjectOrClosureCodegen {
if (idx < 0) return null; if (idx < 0) return null;
final Type sharedVarType = state.getTypeMapper().getSharedVarType(vd); final Type sharedVarType = state.getTypeMapper().getSharedVarType(vd);
Type localType = state.getTypeMapper().mapType(vd.getOutType()); Type localType = state.getTypeMapper().mapType(vd.getType());
final Type type = sharedVarType != null ? sharedVarType : localType; final Type type = sharedVarType != null ? sharedVarType : localType;
StackValue outerValue = StackValue.local(idx, type); StackValue outerValue = StackValue.local(idx, type);
@@ -30,10 +30,6 @@ import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
import org.objectweb.asm.commons.InstructionAdapter; import org.objectweb.asm.commons.InstructionAdapter;
import org.objectweb.asm.commons.Method;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
/** /**
* @author max * @author max
@@ -99,7 +95,7 @@ public class PropertyCodegen {
if(state.getStandardLibrary().isVolatile(propertyDescriptor)) { if(state.getStandardLibrary().isVolatile(propertyDescriptor)) {
modifiers |= Opcodes.ACC_VOLATILE; modifiers |= Opcodes.ACC_VOLATILE;
} }
FieldVisitor fieldVisitor = v.newField(p, modifiers, p.getName(), state.getTypeMapper().mapType(propertyDescriptor.getOutType()).getDescriptor(), null, value); FieldVisitor fieldVisitor = v.newField(p, modifiers, p.getName(), state.getTypeMapper().mapType(propertyDescriptor.getType()).getDescriptor(), null, value);
AnnotationCodegen.forField(fieldVisitor).genAnnotations(propertyDescriptor, state.getTypeMapper()); AnnotationCodegen.forField(fieldVisitor).genAnnotations(propertyDescriptor, state.getTypeMapper());
} }
} }
@@ -179,7 +175,7 @@ public class PropertyCodegen {
if (kind != OwnerKind.NAMESPACE) { if (kind != OwnerKind.NAMESPACE) {
iv.load(0, JetTypeMapper.TYPE_OBJECT); iv.load(0, JetTypeMapper.TYPE_OBJECT);
} }
final Type type = state.getTypeMapper().mapType(propertyDescriptor.getOutType()); final Type type = state.getTypeMapper().mapType(propertyDescriptor.getType());
if (kind instanceof OwnerKind.DelegateKind) { if (kind instanceof OwnerKind.DelegateKind) {
OwnerKind.DelegateKind dk = (OwnerKind.DelegateKind) kind; OwnerKind.DelegateKind dk = (OwnerKind.DelegateKind) kind;
dk.getDelegate().put(JetTypeMapper.TYPE_OBJECT, iv); dk.getDelegate().put(JetTypeMapper.TYPE_OBJECT, iv);
@@ -240,7 +236,7 @@ public class PropertyCodegen {
if (v.generateCode() && (!isTrait || kind instanceof OwnerKind.DelegateKind)) { if (v.generateCode() && (!isTrait || kind instanceof OwnerKind.DelegateKind)) {
mv.visitCode(); mv.visitCode();
InstructionAdapter iv = new InstructionAdapter(mv); InstructionAdapter iv = new InstructionAdapter(mv);
final Type type = state.getTypeMapper().mapType(propertyDescriptor.getOutType()); final Type type = state.getTypeMapper().mapType(propertyDescriptor.getType());
int paramCode = 0; int paramCode = 0;
if (kind != OwnerKind.NAMESPACE) { if (kind != OwnerKind.NAMESPACE) {
iv.load(0, JetTypeMapper.TYPE_OBJECT); iv.load(0, JetTypeMapper.TYPE_OBJECT);
@@ -593,7 +593,7 @@ public abstract class StackValue {
List<ValueParameterDescriptor> valueParameters = resolvedGetCall.getResultingDescriptor().getValueParameters(); List<ValueParameterDescriptor> valueParameters = resolvedGetCall.getResultingDescriptor().getValueParameters();
int firstParamIndex = -1; int firstParamIndex = -1;
for(int i = valueParameters.size()-1; i >= 0; --i) { for(int i = valueParameters.size()-1; i >= 0; --i) {
Type type = codegen.typeMapper.mapType(valueParameters.get(i).getOutType()); Type type = codegen.typeMapper.mapType(valueParameters.get(i).getType());
int sz = type.getSize(); int sz = type.getSize();
frame.enterTemp(sz); frame.enterTemp(sz);
lastIndex += sz; lastIndex += sz;
@@ -673,7 +673,7 @@ public abstract class StackValue {
int index = firstParamIndex; int index = firstParamIndex;
for(int i = 0; i != valueParameters.size(); ++i) { for(int i = 0; i != valueParameters.size(); ++i) {
Type type = codegen.typeMapper.mapType(valueParameters.get(i).getOutType()); Type type = codegen.typeMapper.mapType(valueParameters.get(i).getType());
int sz = type.getSize(); int sz = type.getSize();
v.load(index-sz, type); v.load(index-sz, type);
index -= sz; index -= sz;
@@ -701,7 +701,7 @@ public abstract class StackValue {
index = firstParamIndex; index = firstParamIndex;
for(int i = 0; i != valueParameters.size(); ++i) { for(int i = 0; i != valueParameters.size(); ++i) {
Type type = codegen.typeMapper.mapType(valueParameters.get(i).getOutType()); Type type = codegen.typeMapper.mapType(valueParameters.get(i).getType());
int sz = type.getSize(); int sz = type.getSize();
v.load(index-sz, type); v.load(index-sz, type);
index -= sz; index -= sz;
@@ -725,7 +725,7 @@ public abstract class StackValue {
return false; return false;
for (ValueParameterDescriptor valueParameter : valueParameters) { for (ValueParameterDescriptor valueParameter : valueParameters) {
if (codegen.typeMapper.mapType(valueParameter.getOutType()).getSize() != 1) if (codegen.typeMapper.mapType(valueParameter.getType()).getSize() != 1)
return false; return false;
} }
@@ -182,8 +182,8 @@ public class IntrinsicMethods {
} }
); );
for (DeclarationDescriptor stringMember : stringMembers) { for (DeclarationDescriptor stringMember : stringMembers) {
if (stringMember instanceof NamedFunctionDescriptor) { if (stringMember instanceof SimpleFunctionDescriptor) {
final NamedFunctionDescriptor stringMethod = (NamedFunctionDescriptor) stringMember; final SimpleFunctionDescriptor stringMethod = (SimpleFunctionDescriptor) stringMember;
final PsiMethod[] methods = stringPsiClass != null? final PsiMethod[] methods = stringPsiClass != null?
stringPsiClass.findMethodsByName(stringMember.getName(), false) : new PsiMethod[]{}; stringPsiClass.findMethodsByName(stringMember.getName(), false) : new PsiMethod[]{};
for (PsiMethod method : methods) { for (PsiMethod method : methods) {
@@ -21,7 +21,7 @@ import org.jetbrains.jet.codegen.CallableMethod;
import org.jetbrains.jet.codegen.ExpressionCodegen; import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.OwnerKind; import org.jetbrains.jet.codegen.OwnerKind;
import org.jetbrains.jet.codegen.StackValue; import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetCallExpression; import org.jetbrains.jet.lang.psi.JetCallExpression;
import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetExpression;
import org.objectweb.asm.Type; import org.objectweb.asm.Type;
@@ -34,9 +34,9 @@ import java.util.List;
* @author alex.tkachman * @author alex.tkachman
*/ */
public class PsiMethodCall implements IntrinsicMethod { public class PsiMethodCall implements IntrinsicMethod {
private final NamedFunctionDescriptor myMethod; private final SimpleFunctionDescriptor myMethod;
public PsiMethodCall(NamedFunctionDescriptor method) { public PsiMethodCall(SimpleFunctionDescriptor method) {
myMethod = method; myMethod = method;
} }
@@ -1240,7 +1240,7 @@ public class JavaDescriptorResolver {
getterDescriptor.initialize(propertyType); getterDescriptor.initialize(propertyType);
} }
if (setterDescriptor != null) { if (setterDescriptor != null) {
setterDescriptor.initialize(new ValueParameterDescriptorImpl(setterDescriptor, 0, Collections.<AnnotationDescriptor>emptyList(), "p0"/*TODO*/, false, propertyDescriptor.getOutType(), false, null)); setterDescriptor.initialize(new ValueParameterDescriptorImpl(setterDescriptor, 0, Collections.<AnnotationDescriptor>emptyList(), "p0"/*TODO*/, false, propertyDescriptor.getType(), false, null));
} }
semanticServices.getTrace().record(BindingContext.VARIABLE, anyMember.getMember().psiMember, propertyDescriptor); semanticServices.getTrace().record(BindingContext.VARIABLE, anyMember.getMember().psiMember, propertyDescriptor);
@@ -1258,19 +1258,19 @@ public class JavaDescriptorResolver {
final Set<FunctionDescriptor> functions = new HashSet<FunctionDescriptor>(); final Set<FunctionDescriptor> functions = new HashSet<FunctionDescriptor>();
Set<NamedFunctionDescriptor> functionsFromCurrent = Sets.newHashSet(); Set<SimpleFunctionDescriptor> functionsFromCurrent = Sets.newHashSet();
for (PsiMethodWrapper method : namedMembers.methods) { for (PsiMethodWrapper method : namedMembers.methods) {
FunctionDescriptorImpl function = resolveMethodToFunctionDescriptor(owner, psiClass, FunctionDescriptorImpl function = resolveMethodToFunctionDescriptor(owner, psiClass,
method); method);
if (function != null) { if (function != null) {
functionsFromCurrent.add((NamedFunctionDescriptor) function); functionsFromCurrent.add((SimpleFunctionDescriptor) function);
} }
} }
if (owner instanceof ClassDescriptor) { if (owner instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) owner; ClassDescriptor classDescriptor = (ClassDescriptor) owner;
Set<NamedFunctionDescriptor> functionsFromSupertypes = getFunctionsFromSupertypes(scopeData, methodName); Set<SimpleFunctionDescriptor> functionsFromSupertypes = getFunctionsFromSupertypes(scopeData, methodName);
OverrideResolver.generateOverridesInFunctionGroup(methodName, functionsFromSupertypes, functionsFromCurrent, classDescriptor, new OverrideResolver.DescriptorSink() { OverrideResolver.generateOverridesInFunctionGroup(methodName, functionsFromSupertypes, functionsFromCurrent, classDescriptor, new OverrideResolver.DescriptorSink() {
@Override @Override
@@ -1291,11 +1291,11 @@ public class JavaDescriptorResolver {
namedMembers.functionDescriptors = functions; namedMembers.functionDescriptors = functions;
} }
private Set<NamedFunctionDescriptor> getFunctionsFromSupertypes(ResolverScopeData scopeData, String methodName) { private Set<SimpleFunctionDescriptor> getFunctionsFromSupertypes(ResolverScopeData scopeData, String methodName) {
Set<NamedFunctionDescriptor> r = new HashSet<NamedFunctionDescriptor>(); Set<SimpleFunctionDescriptor> r = new HashSet<SimpleFunctionDescriptor>();
for (JetType supertype : getSupertypes(scopeData)) { for (JetType supertype : getSupertypes(scopeData)) {
for (FunctionDescriptor function : supertype.getMemberScope().getFunctions(methodName)) { for (FunctionDescriptor function : supertype.getMemberScope().getFunctions(methodName)) {
r.add((NamedFunctionDescriptor) function); r.add((SimpleFunctionDescriptor) function);
} }
} }
return r; return r;
@@ -1429,7 +1429,7 @@ public class JavaDescriptorResolver {
return null; return null;
} }
NamedFunctionDescriptorImpl functionDescriptorImpl = new NamedFunctionDescriptorImpl( SimpleFunctionDescriptorImpl functionDescriptorImpl = new SimpleFunctionDescriptorImpl(
owner, owner,
resolveAnnotations(method.getPsiMethod()), resolveAnnotations(method.getPsiMethod()),
method.getName(), method.getName(),
@@ -68,7 +68,7 @@ public class FunctionDescriptorUtil {
for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) { for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i); ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i);
// TODO : Lazy? // TODO : Lazy?
JetType substitutedType = substitutor.substitute(unsubstitutedValueParameter.getOutType(), Variance.IN_VARIANCE); JetType substitutedType = substitutor.substitute(unsubstitutedValueParameter.getType(), Variance.IN_VARIANCE);
JetType varargElementType = unsubstitutedValueParameter.getVarargElementType(); JetType varargElementType = unsubstitutedValueParameter.getVarargElementType();
JetType substituteVarargElementType = varargElementType == null ? null : substitutor.substitute(varargElementType, Variance.IN_VARIANCE); JetType substituteVarargElementType = varargElementType == null ? null : substitutor.substitute(varargElementType, Variance.IN_VARIANCE);
if (substitutedType == null) return null; if (substitutedType == null) return null;
@@ -22,7 +22,6 @@ import org.jetbrains.jet.lang.psi.JetParameter;
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter; import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler; import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
@@ -39,7 +38,7 @@ import java.util.Set;
public class MutableClassDescriptor extends MutableClassDescriptorLite { public class MutableClassDescriptor extends MutableClassDescriptorLite {
private final Set<CallableMemberDescriptor> callableMembers = Sets.newHashSet(); private final Set<CallableMemberDescriptor> callableMembers = Sets.newHashSet();
private final Set<PropertyDescriptor> properties = Sets.newHashSet(); private final Set<PropertyDescriptor> properties = Sets.newHashSet();
private final Set<NamedFunctionDescriptor> functions = Sets.newHashSet(); private final Set<SimpleFunctionDescriptor> functions = Sets.newHashSet();
private final WritableScope scopeForMemberResolution; private final WritableScope scopeForMemberResolution;
// This scope contains type parameters but does not contain inner classes // This scope contains type parameters but does not contain inner classes
@@ -119,7 +118,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
} }
@Override @Override
public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) { public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
super.addFunctionDescriptor(functionDescriptor); super.addFunctionDescriptor(functionDescriptor);
functions.add(functionDescriptor); functions.add(functionDescriptor);
callableMembers.add(functionDescriptor); callableMembers.add(functionDescriptor);
@@ -127,7 +126,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
} }
@NotNull @NotNull
public Set<NamedFunctionDescriptor> getFunctions() { public Set<SimpleFunctionDescriptor> getFunctions() {
return functions; return functions;
} }
@@ -252,7 +252,7 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor imp
} }
@Override @Override
public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) { public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(functionDescriptor); getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(functionDescriptor);
} }
@@ -65,7 +65,7 @@ public class NamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl imp
} }
@Override @Override
public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) { public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
memberScope.addFunctionDescriptor(functionDescriptor); memberScope.addFunctionDescriptor(functionDescriptor);
} }
@@ -83,7 +83,7 @@ public interface NamespaceLike extends DeclarationDescriptor {
void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor); void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor);
void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor); void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor);
void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor); void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor);
@@ -27,7 +27,6 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.*;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -151,7 +150,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
@Override @Override
public JetType getReturnType() { public JetType getReturnType() {
return getOutType(); return getType();
} }
public boolean isVar() { public boolean isVar() {
@@ -213,7 +212,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList(); List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters); TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
JetType originalOutType = getOutType(); JetType originalOutType = getType();
JetType outType = substitutor.substitute(originalOutType, Variance.OUT_VARIANCE); JetType outType = substitutor.substitute(originalOutType, Variance.OUT_VARIANCE);
if (outType == null) { if (outType == null) {
return null; // TODO : tell the user that the property was projected out return null; // TODO : tell the user that the property was projected out
@@ -37,7 +37,7 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
} }
public void initialize(JetType returnType) { public void initialize(JetType returnType) {
this.returnType = returnType == null ? getCorrespondingProperty().getOutType() : returnType; this.returnType = returnType == null ? getCorrespondingProperty().getType() : returnType;
} }
@NotNull @NotNull
@@ -19,17 +19,17 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
* ... and also a closure * Simple functions are the ones with 'fun' keyword and function literals
* *
* @author Stepan Koltsov * @author Stepan Koltsov
*/ */
public interface NamedFunctionDescriptor extends FunctionDescriptor { public interface SimpleFunctionDescriptor extends FunctionDescriptor {
@NotNull @NotNull
@Override @Override
NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides); SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides);
@NotNull @NotNull
@Override @Override
NamedFunctionDescriptor getOriginal(); SimpleFunctionDescriptor getOriginal();
} }
@@ -29,9 +29,9 @@ import java.util.List;
/** /**
* @author Stepan Koltsov * @author Stepan Koltsov
*/ */
public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implements NamedFunctionDescriptor { public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl implements SimpleFunctionDescriptor {
public NamedFunctionDescriptorImpl( public SimpleFunctionDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration, @NotNull DeclarationDescriptor containingDeclaration,
@NotNull List<AnnotationDescriptor> annotations, @NotNull List<AnnotationDescriptor> annotations,
@NotNull String name, @NotNull String name,
@@ -39,9 +39,9 @@ public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implemen
super(containingDeclaration, annotations, name, kind); super(containingDeclaration, annotations, name, kind);
} }
private NamedFunctionDescriptorImpl( private SimpleFunctionDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration, @NotNull DeclarationDescriptor containingDeclaration,
@NotNull NamedFunctionDescriptor original, @NotNull SimpleFunctionDescriptor original,
@NotNull List<AnnotationDescriptor> annotations, @NotNull List<AnnotationDescriptor> annotations,
@NotNull String name, @NotNull String name,
Kind kind) { Kind kind) {
@@ -55,14 +55,14 @@ public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implemen
@NotNull @NotNull
@Override @Override
public NamedFunctionDescriptor getOriginal() { public SimpleFunctionDescriptor getOriginal() {
return (NamedFunctionDescriptor) super.getOriginal(); return (SimpleFunctionDescriptor) super.getOriginal();
} }
@Override @Override
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) { protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
if (preserveOriginal) { if (preserveOriginal) {
return new NamedFunctionDescriptorImpl( return new SimpleFunctionDescriptorImpl(
newOwner, newOwner,
getOriginal(), getOriginal(),
// TODO : safeSubstitute // TODO : safeSubstitute
@@ -70,7 +70,7 @@ public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implemen
getName(), getName(),
kind); kind);
} else { } else {
return new NamedFunctionDescriptorImpl( return new SimpleFunctionDescriptorImpl(
newOwner, newOwner,
// TODO : safeSubstitute // TODO : safeSubstitute
getAnnotations(), getAnnotations(),
@@ -81,7 +81,7 @@ public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implemen
@NotNull @NotNull
@Override @Override
public NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) { public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
return (NamedFunctionDescriptor) doSubstitute(TypeSubstitutor.EMPTY, newOwner, DescriptorUtils.convertModality(modality, makeNonAbstract), false, copyOverrides, kind); return (SimpleFunctionDescriptor) doSubstitute(TypeSubstitutor.EMPTY, newOwner, DescriptorUtils.convertModality(modality, makeNonAbstract), false, copyOverrides, kind);
} }
} }
@@ -37,7 +37,7 @@ public interface ValueParameterDescriptor extends VariableDescriptor, Annotated
@Override @Override
@NotNull @NotNull
JetType getOutType(); JetType getType();
@Override @Override
ValueParameterDescriptor getOriginal(); ValueParameterDescriptor getOriginal();
@@ -123,6 +123,6 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
@NotNull @NotNull
@Override @Override
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) { public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), getName(), isVar, getOutType(), hasDefaultValue, varargElementType); return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), getName(), isVar, getType(), hasDefaultValue, varargElementType);
} }
} }
@@ -27,7 +27,7 @@ import java.util.Collections;
*/ */
public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl { public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
public static VariableAsFunctionDescriptor create(@NotNull VariableDescriptor variableDescriptor) { public static VariableAsFunctionDescriptor create(@NotNull VariableDescriptor variableDescriptor) {
JetType outType = variableDescriptor.getOutType(); JetType outType = variableDescriptor.getType();
assert outType != null; assert outType != null;
VariableAsFunctionDescriptor result = new VariableAsFunctionDescriptor(variableDescriptor); VariableAsFunctionDescriptor result = new VariableAsFunctionDescriptor(variableDescriptor);
FunctionDescriptorUtil.initializeFromFunctionType(result, outType, variableDescriptor.getExpectedThisObject()); FunctionDescriptorUtil.initializeFromFunctionType(result, outType, variableDescriptor.getExpectedThisObject());
@@ -25,7 +25,7 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
*/ */
public interface VariableDescriptor extends CallableDescriptor { public interface VariableDescriptor extends CallableDescriptor {
@NotNull @NotNull
JetType getOutType(); JetType getType();
@Override @Override
@SuppressWarnings({"NullableProblems"}) @SuppressWarnings({"NullableProblems"})
@@ -52,7 +52,7 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorImpl i
} }
@Override @Override
public JetType getOutType() { public JetType getType() {
return outType; return outType;
} }
@@ -99,6 +99,6 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorImpl i
@Override @Override
public JetType getReturnType() { public JetType getReturnType() {
return getOutType(); return getType();
} }
} }
@@ -146,11 +146,11 @@ public interface Errors {
return super.on(elementToBlame, nodeToMark, s, classDescriptor, modifierListOwner).add(DiagnosticParameters.CLASS, modifierListOwner); return super.on(elementToBlame, nodeToMark, s, classDescriptor, modifierListOwner).add(DiagnosticParameters.CLASS, modifierListOwner);
} }
}; };
PsiElementOnlyDiagnosticFactory1<JetFunction, NamedFunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract"); PsiElementOnlyDiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> ABSTRACT_FUNCTION_WITH_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "A function {0} with body cannot be abstract");
PsiElementOnlyDiagnosticFactory1<JetFunction, NamedFunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract"); PsiElementOnlyDiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_ABSTRACT_FUNCTION_WITH_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Method {0} without a body must be abstract");
PsiElementOnlyDiagnosticFactory1<JetModifierListOwner, NamedFunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract"); PsiElementOnlyDiagnosticFactory1<JetModifierListOwner, SimpleFunctionDescriptor> NON_MEMBER_ABSTRACT_FUNCTION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} is not a class or trait member and cannot be abstract");
PsiElementOnlyDiagnosticFactory1<JetFunction, NamedFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} must have a body"); PsiElementOnlyDiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Function {0} must have a body");
DiagnosticWithParameterFactory<JetNamedDeclaration, JetClass> NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticWithParameterFactory.create(ERROR, "Non final member in a final class", DiagnosticParameters.CLASS); DiagnosticWithParameterFactory<JetNamedDeclaration, JetClass> NON_FINAL_MEMBER_IN_FINAL_CLASS = DiagnosticWithParameterFactory.create(ERROR, "Non final member in a final class", DiagnosticParameters.CLASS);
@@ -141,7 +141,7 @@ public class AnalyzingUtils {
} }
@Override @Override
public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) { public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
scope.addFunctionDescriptor(functionDescriptor); scope.addFunctionDescriptor(functionDescriptor);
} }
@@ -106,7 +106,7 @@ public class AnnotationResolver {
List<JetExpression> argumentExpressions = descriptorToArgument.getValue().getArgumentExpressions(); List<JetExpression> argumentExpressions = descriptorToArgument.getValue().getArgumentExpressions();
ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey(); ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey();
for (JetExpression argument : argumentExpressions) { for (JetExpression argument : argumentExpressions) {
arguments.add(resolveAnnotationArgument(argument, parameterDescriptor.getOutType())); arguments.add(resolveAnnotationArgument(argument, parameterDescriptor.getType()));
} }
} }
descriptor.setValueArguments(arguments); descriptor.setValueArguments(arguments);
@@ -149,7 +149,7 @@ public interface BindingContext {
WritableSlice<PsiElement, NamespaceDescriptor> NAMESPACE = Slices.<PsiElement, NamespaceDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice<PsiElement, NamespaceDescriptor> NAMESPACE = Slices.<PsiElement, NamespaceDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
WritableSlice<PsiElement, ClassDescriptor> CLASS = Slices.<PsiElement, ClassDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice<PsiElement, ClassDescriptor> CLASS = Slices.<PsiElement, ClassDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
WritableSlice<JetTypeParameter, TypeParameterDescriptor> TYPE_PARAMETER = Slices.<JetTypeParameter, TypeParameterDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice<JetTypeParameter, TypeParameterDescriptor> TYPE_PARAMETER = Slices.<JetTypeParameter, TypeParameterDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
WritableSlice<PsiElement, NamedFunctionDescriptor> FUNCTION = Slices.<PsiElement, NamedFunctionDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice<PsiElement, SimpleFunctionDescriptor> FUNCTION = Slices.<PsiElement, SimpleFunctionDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
WritableSlice<PsiElement, ConstructorDescriptor> CONSTRUCTOR = Slices.<PsiElement, ConstructorDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice<PsiElement, ConstructorDescriptor> CONSTRUCTOR = Slices.<PsiElement, ConstructorDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
WritableSlice<PsiElement, VariableDescriptor> VARIABLE = Slices.<PsiElement, VariableDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice<PsiElement, VariableDescriptor> VARIABLE = Slices.<PsiElement, VariableDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
WritableSlice<JetParameter, VariableDescriptor> VALUE_PARAMETER = Slices.<JetParameter, VariableDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build(); WritableSlice<JetParameter, VariableDescriptor> VALUE_PARAMETER = Slices.<JetParameter, VariableDescriptor>sliceBuilder().setOpposite((WritableSlice) DESCRIPTOR_TO_DECLARATION).build();
@@ -468,12 +468,12 @@ public class BodyResolver {
private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) { private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) {
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15 //JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace); ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getOutType() : NO_EXPECTED_TYPE; JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
JetType type = typeInferrer.getType(context.getDescriptorResolver().getPropertyDeclarationInnerScope(scope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter()), initializer, expectedTypeForInitializer); JetType type = typeInferrer.getType(context.getDescriptorResolver().getPropertyDeclarationInnerScope(scope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter()), initializer, expectedTypeForInitializer);
// //
// JetType expectedType = propertyDescriptor.getInType(); // JetType expectedType = propertyDescriptor.getInType();
// if (expectedType == null) { // if (expectedType == null) {
// expectedType = propertyDescriptor.getOutType(); // expectedType = propertyDescriptor.getType();
// } // }
// if (type != null && expectedType != null // if (type != null && expectedType != null
// && !context.getSemanticServices().getTypeChecker().isSubtypeOf(type, expectedType)) { // && !context.getSemanticServices().getTypeChecker().isSubtypeOf(type, expectedType)) {
@@ -482,9 +482,9 @@ public class BodyResolver {
} }
private void resolveFunctionBodies() { private void resolveFunctionBodies() {
for (Map.Entry<JetNamedFunction, NamedFunctionDescriptor> entry : this.context.getFunctions().entrySet()) { for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry : this.context.getFunctions().entrySet()) {
JetNamedFunction declaration = entry.getKey(); JetNamedFunction declaration = entry.getKey();
NamedFunctionDescriptor descriptor = entry.getValue(); SimpleFunctionDescriptor descriptor = entry.getValue();
computeDeferredType(descriptor.getReturnType()); computeDeferredType(descriptor.getReturnType());
@@ -528,7 +528,7 @@ public class BodyResolver {
JetParameter jetParameter = valueParameters.get(i); JetParameter jetParameter = valueParameters.get(i);
JetExpression defaultValue = jetParameter.getDefaultValue(); JetExpression defaultValue = jetParameter.getDefaultValue();
if (defaultValue != null) { if (defaultValue != null) {
typeInferrer.getType(declaringScope, defaultValue, valueParameterDescriptor.getOutType()); typeInferrer.getType(declaringScope, defaultValue, valueParameterDescriptor.getType());
} }
} }
} }
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider; import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyAccessorDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyAccessorDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
@@ -51,9 +51,9 @@ public class ControlFlowAnalyzer {
if (!context.completeAnalysisNeeded(objectDeclaration)) continue; if (!context.completeAnalysisNeeded(objectDeclaration)) continue;
checkClassOrObject(objectDeclaration); checkClassOrObject(objectDeclaration);
} }
for (Map.Entry<JetNamedFunction, NamedFunctionDescriptor> entry : context.getFunctions().entrySet()) { for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry : context.getFunctions().entrySet()) {
JetNamedFunction function = entry.getKey(); JetNamedFunction function = entry.getKey();
NamedFunctionDescriptor functionDescriptor = entry.getValue(); SimpleFunctionDescriptor functionDescriptor = entry.getValue();
if (!context.completeAnalysisNeeded(function)) continue; if (!context.completeAnalysisNeeded(function)) continue;
final JetType expectedReturnType = !function.hasBlockBody() && !function.hasDeclaredReturnType() final JetType expectedReturnType = !function.hasBlockBody() && !function.hasDeclaredReturnType()
? NO_EXPECTED_TYPE ? NO_EXPECTED_TYPE
@@ -120,7 +120,7 @@ public class DeclarationResolver {
declaration.accept(new JetVisitorVoid() { declaration.accept(new JetVisitorVoid() {
@Override @Override
public void visitNamedFunction(JetNamedFunction function) { public void visitNamedFunction(JetNamedFunction function) {
NamedFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function); SimpleFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function);
namespaceLike.addFunctionDescriptor(functionDescriptor); namespaceLike.addFunctionDescriptor(functionDescriptor);
context.getFunctions().put(function, functionDescriptor); context.getFunctions().put(function, functionDescriptor);
context.getDeclaringScopes().put(function, scopeForFunctions); context.getDeclaringScopes().put(function, scopeForFunctions);
@@ -71,10 +71,10 @@ public class DeclarationsChecker {
checkObject(objectDeclaration, objectDescriptor); checkObject(objectDeclaration, objectDescriptor);
} }
Map<JetNamedFunction, NamedFunctionDescriptor> functions = context.getFunctions(); Map<JetNamedFunction, SimpleFunctionDescriptor> functions = context.getFunctions();
for (Map.Entry<JetNamedFunction, NamedFunctionDescriptor> entry : functions.entrySet()) { for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry : functions.entrySet()) {
JetNamedFunction function = entry.getKey(); JetNamedFunction function = entry.getKey();
NamedFunctionDescriptor functionDescriptor = entry.getValue(); SimpleFunctionDescriptor functionDescriptor = entry.getValue();
if (!context.completeAnalysisNeeded(function)) continue; if (!context.completeAnalysisNeeded(function)) continue;
checkFunction(function, functionDescriptor); checkFunction(function, functionDescriptor);
@@ -246,7 +246,7 @@ public class DeclarationsChecker {
} }
} }
protected void checkFunction(JetNamedFunction function, NamedFunctionDescriptor functionDescriptor) { protected void checkFunction(JetNamedFunction function, SimpleFunctionDescriptor functionDescriptor) {
DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration(); DeclarationDescriptor containingDescriptor = functionDescriptor.getContainingDeclaration();
PsiElement nameIdentifier = function.getNameIdentifier(); PsiElement nameIdentifier = function.getNameIdentifier();
JetModifierList modifierList = function.getModifierList(); JetModifierList modifierList = function.getModifierList();
@@ -62,10 +62,10 @@ public class DelegationResolver {
context.getTrace().record(DELEGATED, copy); context.getTrace().record(DELEGATED, copy);
} }
} }
else if (declarationDescriptor instanceof NamedFunctionDescriptor) { else if (declarationDescriptor instanceof SimpleFunctionDescriptor) {
NamedFunctionDescriptor functionDescriptor = (NamedFunctionDescriptor) declarationDescriptor; SimpleFunctionDescriptor functionDescriptor = (SimpleFunctionDescriptor) declarationDescriptor;
if (functionDescriptor.getModality().isOverridable()) { if (functionDescriptor.getModality().isOverridable()) {
NamedFunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true, CallableMemberDescriptor.Kind.DELEGATION, true); SimpleFunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true, CallableMemberDescriptor.Kind.DELEGATION, true);
classDescriptor.addFunctionDescriptor(copy); classDescriptor.addFunctionDescriptor(copy);
context.getTrace().record(DELEGATED, copy); context.getTrace().record(DELEGATED, copy);
} }
@@ -154,8 +154,8 @@ public class DescriptorResolver {
} }
@NotNull @NotNull
public NamedFunctionDescriptor resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, final JetScope scope, final JetNamedFunction function) { public SimpleFunctionDescriptor resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, final JetScope scope, final JetNamedFunction function) {
final NamedFunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl( final SimpleFunctionDescriptorImpl functionDescriptor = new SimpleFunctionDescriptorImpl(
containingDescriptor, containingDescriptor,
annotationResolver.resolveAnnotations(scope, function.getModifierList()), annotationResolver.resolveAnnotations(scope, function.getModifierList()),
JetPsiUtil.safeName(function.getName()), JetPsiUtil.safeName(function.getName()),
@@ -708,11 +708,11 @@ public class DescriptorResolver {
JetType type; JetType type;
JetTypeReference typeReference = parameter.getTypeReference(); JetTypeReference typeReference = parameter.getTypeReference();
if (typeReference == null) { if (typeReference == null) {
type = propertyDescriptor.getOutType(); // TODO : this maybe unknown at this point type = propertyDescriptor.getType(); // TODO : this maybe unknown at this point
} }
else { else {
type = typeResolver.resolveType(scope, typeReference); type = typeResolver.resolveType(scope, typeReference);
JetType inType = propertyDescriptor.getOutType(); JetType inType = propertyDescriptor.getType();
if (inType != null) { if (inType != null) {
if (!TypeUtils.equalTypes(type, inType)) { if (!TypeUtils.equalTypes(type, inType)) {
trace.report(WRONG_SETTER_PARAMETER_TYPE.on(setter, typeReference, inType)); trace.report(WRONG_SETTER_PARAMETER_TYPE.on(setter, typeReference, inType));
@@ -762,7 +762,7 @@ public class DescriptorResolver {
if (getter != null) { if (getter != null) {
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList()); List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList());
JetType outType = propertyDescriptor.getOutType(); JetType outType = propertyDescriptor.getType();
JetType returnType = outType; JetType returnType = outType;
JetTypeReference returnTypeReference = getter.getReturnTypeReference(); JetTypeReference returnTypeReference = getter.getReturnTypeReference();
if (returnTypeReference != null) { if (returnTypeReference != null) {
@@ -782,7 +782,7 @@ public class DescriptorResolver {
} }
else { else {
getterDescriptor = createDefaultGetter(propertyDescriptor); getterDescriptor = createDefaultGetter(propertyDescriptor);
getterDescriptor.initialize(propertyDescriptor.getOutType()); getterDescriptor.initialize(propertyDescriptor.getType());
} }
return getterDescriptor; return getterDescriptor;
} }
@@ -872,7 +872,7 @@ public class DescriptorResolver {
PropertySetterDescriptor setter = createDefaultSetter(propertyDescriptor); PropertySetterDescriptor setter = createDefaultSetter(propertyDescriptor);
propertyDescriptor.initialize(getter, setter); propertyDescriptor.initialize(getter, setter);
getter.initialize(propertyDescriptor.getOutType()); getter.initialize(propertyDescriptor.getType());
trace.record(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter, propertyDescriptor); trace.record(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter, propertyDescriptor);
return propertyDescriptor; return propertyDescriptor;
@@ -187,7 +187,7 @@ public class DescriptorUtils {
return descriptor.getName(); return descriptor.getName();
} }
public static boolean isTopLevelFunction(@NotNull NamedFunctionDescriptor functionDescriptor) { public static boolean isTopLevelFunction(@NotNull SimpleFunctionDescriptor functionDescriptor) {
return functionDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor; return functionDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor;
} }
@@ -83,7 +83,7 @@ public interface Importer {
return; return;
} }
if (descriptor instanceof VariableDescriptor) { if (descriptor instanceof VariableDescriptor) {
JetType type = ((VariableDescriptor) descriptor).getOutType(); JetType type = ((VariableDescriptor) descriptor).getType();
namespaceScope.importScope(type.getMemberScope()); namespaceScope.importScope(type.getMemberScope());
} }
else if (descriptor instanceof ClassDescriptor) { else if (descriptor instanceof ClassDescriptor) {
@@ -105,7 +105,7 @@ public class OverloadResolver {
MultiMap<Key, CallableMemberDescriptor> functionsByName = MultiMap.create(); MultiMap<Key, CallableMemberDescriptor> functionsByName = MultiMap.create();
for (NamedFunctionDescriptor function : context.getFunctions().values()) { for (SimpleFunctionDescriptor function : context.getFunctions().values()) {
DeclarationDescriptor containingDeclaration = function.getContainingDeclaration(); DeclarationDescriptor containingDeclaration = function.getContainingDeclaration();
if (containingDeclaration instanceof NamespaceDescriptor) { if (containingDeclaration instanceof NamespaceDescriptor) {
NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) containingDeclaration; NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) containingDeclaration;
@@ -18,7 +18,7 @@ package org.jetbrains.jet.lang.resolve;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor; import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor; import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
/** /**
@@ -52,7 +52,7 @@ public class OverloadUtil {
private static int braceCount(CallableDescriptor a) { private static int braceCount(CallableDescriptor a) {
if (a instanceof PropertyDescriptor) { if (a instanceof PropertyDescriptor) {
return 0; return 0;
} else if (a instanceof NamedFunctionDescriptor) { } else if (a instanceof SimpleFunctionDescriptor) {
return 1; return 1;
} else if (a instanceof ConstructorDescriptor) { } else if (a instanceof ConstructorDescriptor) {
return 1; return 1;
@@ -106,8 +106,8 @@ public class OverrideResolver {
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) { public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
if (fakeOverride instanceof PropertyDescriptor) { if (fakeOverride instanceof PropertyDescriptor) {
classDescriptor.getScopeForMemberLookupAsWritableScope().addPropertyDescriptor((PropertyDescriptor) fakeOverride); classDescriptor.getScopeForMemberLookupAsWritableScope().addPropertyDescriptor((PropertyDescriptor) fakeOverride);
} else if (fakeOverride instanceof NamedFunctionDescriptor) { } else if (fakeOverride instanceof SimpleFunctionDescriptor) {
classDescriptor.getScopeForMemberLookupAsWritableScope().addFunctionDescriptor((NamedFunctionDescriptor) fakeOverride); classDescriptor.getScopeForMemberLookupAsWritableScope().addFunctionDescriptor((SimpleFunctionDescriptor) fakeOverride);
} else { } else {
throw new IllegalStateException(fakeOverride.getClass().getName()); throw new IllegalStateException(fakeOverride.getClass().getName());
} }
@@ -191,7 +191,7 @@ public class OverrideResolver {
JetScope scope) { JetScope scope) {
List<CallableMemberDescriptor> r = Lists.newArrayList(); List<CallableMemberDescriptor> r = Lists.newArrayList();
for (DeclarationDescriptor decl : scope.getAllDescriptors()) { for (DeclarationDescriptor decl : scope.getAllDescriptors()) {
if (decl instanceof PropertyDescriptor || decl instanceof NamedFunctionDescriptor) { if (decl instanceof PropertyDescriptor || decl instanceof SimpleFunctionDescriptor) {
r.add((CallableMemberDescriptor) decl); r.add((CallableMemberDescriptor) decl);
} }
} }
@@ -115,7 +115,7 @@ public class OverridingUtil {
parameters.add(receiverParameter.getType()); parameters.add(receiverParameter.getType());
} }
for (ValueParameterDescriptor valueParameterDescriptor : callableDescriptor.getValueParameters()) { for (ValueParameterDescriptor valueParameterDescriptor : callableDescriptor.getValueParameters()) {
parameters.add(valueParameterDescriptor.getOutType()); parameters.add(valueParameterDescriptor.getType());
} }
return parameters; return parameters;
} }
@@ -50,7 +50,7 @@ import java.util.Set;
protected final Map<JetFile, NamespaceDescriptorImpl> namespaceDescriptors = Maps.newHashMap(); protected final Map<JetFile, NamespaceDescriptorImpl> namespaceDescriptors = Maps.newHashMap();
private final Map<JetDeclaration, JetScope> declaringScopes = Maps.newHashMap(); private final Map<JetDeclaration, JetScope> declaringScopes = Maps.newHashMap();
private final Map<JetNamedFunction, NamedFunctionDescriptor> functions = Maps.newLinkedHashMap(); private final Map<JetNamedFunction, SimpleFunctionDescriptor> functions = Maps.newLinkedHashMap();
private final Map<JetSecondaryConstructor, ConstructorDescriptor> constructors = Maps.newLinkedHashMap(); private final Map<JetSecondaryConstructor, ConstructorDescriptor> constructors = Maps.newLinkedHashMap();
private final Map<JetProperty, PropertyDescriptor> properties = Maps.newLinkedHashMap(); private final Map<JetProperty, PropertyDescriptor> properties = Maps.newLinkedHashMap();
private final Set<PropertyDescriptor> primaryConstructorParameterProperties = Sets.newHashSet(); private final Set<PropertyDescriptor> primaryConstructorParameterProperties = Sets.newHashSet();
@@ -154,7 +154,7 @@ import java.util.Set;
return declaringScopes; return declaringScopes;
} }
public Map<JetNamedFunction, NamedFunctionDescriptor> getFunctions() { public Map<JetNamedFunction, SimpleFunctionDescriptor> getFunctions() {
return functions; return functions;
} }
@@ -156,7 +156,7 @@ public class TopDownAnalyzer {
} }
@Override @Override
public void addFunctionDescriptor(@NotNull NamedFunctionDescriptor functionDescriptor) { public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@@ -540,7 +540,7 @@ public class CallResolver {
// We'll type check the arguments later, with the inferred types expected // We'll type check the arguments later, with the inferred types expected
TemporaryBindingTrace traceForUnknown = TemporaryBindingTrace.create(temporaryTrace); TemporaryBindingTrace traceForUnknown = TemporaryBindingTrace.create(temporaryTrace);
ExpressionTypingServices temporaryServices = new ExpressionTypingServices(semanticServices, traceForUnknown); ExpressionTypingServices temporaryServices = new ExpressionTypingServices(semanticServices, traceForUnknown);
JetType type = temporaryServices.getType(scope, expression, substituteDontCare.substitute(valueParameterDescriptor.getOutType(), Variance.INVARIANT)); JetType type = temporaryServices.getType(scope, expression, substituteDontCare.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT));
if (type != null && !ErrorUtils.isErrorType(type)) { if (type != null && !ErrorUtils.isErrorType(type)) {
constraintSystem.addSubtypingConstraint(VALUE_ARGUMENT.assertSubtyping(type, effectiveExpectedType)); constraintSystem.addSubtypingConstraint(VALUE_ARGUMENT.assertSubtyping(type, effectiveExpectedType));
} }
@@ -663,7 +663,7 @@ public class CallResolver {
private JetType getEffectiveExpectedType(ValueParameterDescriptor valueParameterDescriptor) { private JetType getEffectiveExpectedType(ValueParameterDescriptor valueParameterDescriptor) {
JetType effectiveExpectedType = valueParameterDescriptor.getVarargElementType(); JetType effectiveExpectedType = valueParameterDescriptor.getVarargElementType();
if (effectiveExpectedType == null) { if (effectiveExpectedType == null) {
effectiveExpectedType = valueParameterDescriptor.getOutType(); effectiveExpectedType = valueParameterDescriptor.getType();
} }
return effectiveExpectedType; return effectiveExpectedType;
} }
@@ -1002,7 +1002,7 @@ public class CallResolver {
for (int i = 0; i < valueParameters.size(); i++) { for (int i = 0; i < valueParameters.size(); i++) {
ValueParameterDescriptor valueParameter = valueParameters.get(i); ValueParameterDescriptor valueParameter = valueParameters.get(i);
JetType expectedType = parameterTypes.get(i); JetType expectedType = parameterTypes.get(i);
if (!TypeUtils.equalTypes(expectedType, valueParameter.getOutType())) return false; if (!TypeUtils.equalTypes(expectedType, valueParameter.getType())) return false;
} }
return true; return true;
} }
@@ -22,8 +22,6 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor; import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassKind;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.OverridingUtil; import org.jetbrains.jet.lang.resolve.OverridingUtil;
@@ -104,8 +102,8 @@ public class OverloadingConflictResolver {
int fSize = fParams.size(); int fSize = fParams.size();
if (fSize != gParams.size()) return false; if (fSize != gParams.size()) return false;
for (int i = 0; i < fSize; i++) { for (int i = 0; i < fSize; i++) {
JetType fParamType = fParams.get(i).getOutType(); JetType fParamType = fParams.get(i).getType();
JetType gParamType = gParams.get(i).getOutType(); JetType gParamType = gParams.get(i).getType();
if (!typeMoreSpecific(fParamType, gParamType)) { if (!typeMoreSpecific(fParamType, gParamType)) {
return false; return false;
@@ -93,7 +93,7 @@ public class TaskPrioritizers {
variable = DescriptorUtils.filterNonExtensionProperty(scope.getProperties(name)); variable = DescriptorUtils.filterNonExtensionProperty(scope.getProperties(name));
} }
if (variable != null) { if (variable != null) {
JetType outType = variable.getOutType(); JetType outType = variable.getType();
if (outType != null && JetStandardClasses.isFunctionType(outType)) { if (outType != null && JetStandardClasses.isFunctionType(outType)) {
VariableAsFunctionDescriptor functionDescriptor = VariableAsFunctionDescriptor.create(variable); VariableAsFunctionDescriptor functionDescriptor = VariableAsFunctionDescriptor.create(variable);
if ((functionDescriptor.getReceiverParameter().exists()) == receiverNeeded) { if ((functionDescriptor.getReceiverParameter().exists()) == receiverNeeded) {
@@ -234,8 +234,8 @@ public class DataFlowInfo {
// } // }
// //
// @Nullable // @Nullable
// public JetType getOutType(@NotNull VariableDescriptor variableDescriptor) { // public JetType getType(@NotNull VariableDescriptor variableDescriptor) {
// JetType outType = variableDescriptor.getOutType(); // JetType outType = variableDescriptor.getType();
// if (outType == null) return null; // if (outType == null) return null;
// if (!outType.isNullable()) return outType; // if (!outType.isNullable()) return outType;
// NullabilityFlags nullabilityFlags = nullabilityInfo.get(variableDescriptor); // NullabilityFlags nullabilityFlags = nullabilityInfo.get(variableDescriptor);
@@ -269,7 +269,7 @@ public class DataFlowInfo {
// //
// @NotNull // @NotNull
// public List<JetType> getPossibleTypesForVariable(@NotNull VariableDescriptor variableDescriptor) { // public List<JetType> getPossibleTypesForVariable(@NotNull VariableDescriptor variableDescriptor) {
// return getPossibleTypes(variableDescriptor, variableDescriptor.getOutType()); // return getPossibleTypes(variableDescriptor, variableDescriptor.getType());
// } // }
// //
// public List<JetType> getPossibleTypesForReceiver(@NotNull ReceiverDescriptor receiver) { // public List<JetType> getPossibleTypesForReceiver(@NotNull ReceiverDescriptor receiver) {
@@ -57,7 +57,7 @@ public class DataFlowValueFactory {
@NotNull @NotNull
public DataFlowValue createDataFlowValue(@NotNull VariableDescriptor variableDescriptor) { public DataFlowValue createDataFlowValue(@NotNull VariableDescriptor variableDescriptor) {
JetType type = variableDescriptor.getOutType(); JetType type = variableDescriptor.getType();
return new DataFlowValue(variableDescriptor, type, isStableVariable(variableDescriptor), getImmanentNullability(type)); return new DataFlowValue(variableDescriptor, type, isStableVariable(variableDescriptor), getImmanentNullability(type));
} }
@@ -22,7 +22,7 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.error.ErrorNamedFunctionDescriptorImpl; import org.jetbrains.jet.lang.types.error.ErrorSimpleFunctionDescriptorImpl;
import java.util.*; import java.util.*;
@@ -162,8 +162,8 @@ public class ErrorUtils {
CallableMemberDescriptor.Kind.DECLARATION); CallableMemberDescriptor.Kind.DECLARATION);
private static final Set<VariableDescriptor> ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY); private static final Set<VariableDescriptor> ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY);
private static NamedFunctionDescriptor createErrorFunction(ErrorScope ownerScope) { private static SimpleFunctionDescriptor createErrorFunction(ErrorScope ownerScope) {
ErrorNamedFunctionDescriptorImpl function = new ErrorNamedFunctionDescriptorImpl(ownerScope); ErrorSimpleFunctionDescriptorImpl function = new ErrorSimpleFunctionDescriptorImpl(ownerScope);
function.initialize( function.initialize(
null, null,
ReceiverDescriptor.NO_RECEIVER, ReceiverDescriptor.NO_RECEIVER,
@@ -367,7 +367,7 @@ public class JetStandardClasses {
private static List<JetType> toTypes(List<ValueParameterDescriptor> labeledEntries) { private static List<JetType> toTypes(List<ValueParameterDescriptor> labeledEntries) {
List<JetType> result = new ArrayList<JetType>(); List<JetType> result = new ArrayList<JetType>();
for (ValueParameterDescriptor entry : labeledEntries) { for (ValueParameterDescriptor entry : labeledEntries) {
result.add(entry.getOutType()); result.add(entry.getType());
} }
return result; return result;
} }
@@ -17,11 +17,8 @@
package org.jetbrains.jet.lang.types.error; package org.jetbrains.jet.lang.types.error;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorImpl;
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptorImpl;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.ErrorUtils;
@@ -30,12 +27,12 @@ import java.util.Collections;
/** /**
* @author Stepan Koltsov * @author Stepan Koltsov
*/ */
public class ErrorNamedFunctionDescriptorImpl extends NamedFunctionDescriptorImpl { public class ErrorSimpleFunctionDescriptorImpl extends SimpleFunctionDescriptorImpl {
// used for diagnostic only // used for diagnostic only
@NotNull @NotNull
private final ErrorUtils.ErrorScope ownerScope; private final ErrorUtils.ErrorScope ownerScope;
public ErrorNamedFunctionDescriptorImpl(ErrorUtils.ErrorScope ownerScope) { public ErrorSimpleFunctionDescriptorImpl(ErrorUtils.ErrorScope ownerScope) {
super(ErrorUtils.getErrorClass(), Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>", Kind.DECLARATION); super(ErrorUtils.getErrorClass(), Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>", Kind.DECLARATION);
this.ownerScope = ownerScope; this.ownerScope = ownerScope;
} }
@@ -47,7 +44,7 @@ public class ErrorNamedFunctionDescriptorImpl extends NamedFunctionDescriptorImp
@NotNull @NotNull
@Override @Override
public NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) { public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
return this; return this;
} }
@@ -607,7 +607,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
temporaryTrace.commit(); temporaryTrace.commit();
VariableDescriptor resultingDescriptor = resolutionResult.getResultingDescriptor(); VariableDescriptor resultingDescriptor = resolutionResult.getResultingDescriptor();
checkSuper(receiver, resultingDescriptor, context.trace, selectorExpression); checkSuper(receiver, resultingDescriptor, context.trace, selectorExpression);
return resultingDescriptor.getOutType(); return resultingDescriptor.getType();
} }
if (resolutionResult.isAmbiguity() || resolutionResult.singleResult()) { if (resolutionResult.isAmbiguity() || resolutionResult.singleResult()) {
temporaryTrace.commit(); temporaryTrace.commit();
@@ -84,12 +84,12 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
JetType expectedType = context.expectedType; JetType expectedType = context.expectedType;
boolean functionTypeExpected = expectedType != TypeUtils.NO_EXPECTED_TYPE && JetStandardClasses.isFunctionType(expectedType); boolean functionTypeExpected = expectedType != TypeUtils.NO_EXPECTED_TYPE && JetStandardClasses.isFunctionType(expectedType);
NamedFunctionDescriptorImpl functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected); SimpleFunctionDescriptorImpl functionDescriptor = createFunctionDescriptor(expression, context, functionTypeExpected);
List<JetType> parameterTypes = Lists.newArrayList(); List<JetType> parameterTypes = Lists.newArrayList();
List<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters(); List<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters();
for (ValueParameterDescriptor valueParameter : valueParameters) { for (ValueParameterDescriptor valueParameter : valueParameters) {
parameterTypes.add(valueParameter.getOutType()); parameterTypes.add(valueParameter.getType());
} }
ReceiverDescriptor receiverParameter = functionDescriptor.getReceiverParameter(); ReceiverDescriptor receiverParameter = functionDescriptor.getReceiverParameter();
JetType receiver = receiverParameter != NO_RECEIVER ? receiverParameter.getType() : null; JetType receiver = receiverParameter != NO_RECEIVER ? receiverParameter.getType() : null;
@@ -124,10 +124,10 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
return DataFlowUtils.checkType(JetStandardClasses.getFunctionType(Collections.<AnnotationDescriptor>emptyList(), receiver, parameterTypes, safeReturnType), expression, context); return DataFlowUtils.checkType(JetStandardClasses.getFunctionType(Collections.<AnnotationDescriptor>emptyList(), receiver, parameterTypes, safeReturnType), expression, context);
} }
private NamedFunctionDescriptorImpl createFunctionDescriptor(JetFunctionLiteralExpression expression, ExpressionTypingContext context, boolean functionTypeExpected) { private SimpleFunctionDescriptorImpl createFunctionDescriptor(JetFunctionLiteralExpression expression, ExpressionTypingContext context, boolean functionTypeExpected) {
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral(); JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef(); JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef();
NamedFunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl( SimpleFunctionDescriptorImpl functionDescriptor = new SimpleFunctionDescriptorImpl(
context.scope.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), "<anonymous>", CallableMemberDescriptor.Kind.DECLARATION); context.scope.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), "<anonymous>", CallableMemberDescriptor.Kind.DECLARATION);
List<ValueParameterDescriptor> valueParameterDescriptors = createValueParameterDescriptors(context, functionLiteral, functionDescriptor, functionTypeExpected); List<ValueParameterDescriptor> valueParameterDescriptors = createValueParameterDescriptors(context, functionLiteral, functionDescriptor, functionTypeExpected);
@@ -161,7 +161,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
if (functionTypeExpected && !hasDeclaredValueParameters && expectedValueParameters.size() == 1) { if (functionTypeExpected && !hasDeclaredValueParameters && expectedValueParameters.size() == 1) {
ValueParameterDescriptor valueParameterDescriptor = expectedValueParameters.get(0); ValueParameterDescriptor valueParameterDescriptor = expectedValueParameters.get(0);
ValueParameterDescriptor it = new ValueParameterDescriptorImpl( ValueParameterDescriptor it = new ValueParameterDescriptorImpl(
functionDescriptor, 0, Collections.<AnnotationDescriptor>emptyList(), "it", false, valueParameterDescriptor.getOutType(), valueParameterDescriptor.hasDefaultValue(), valueParameterDescriptor.getVarargElementType() functionDescriptor, 0, Collections.<AnnotationDescriptor>emptyList(), "it", false, valueParameterDescriptor.getType(), valueParameterDescriptor.hasDefaultValue(), valueParameterDescriptor.getVarargElementType()
); );
valueParameterDescriptors.add(it); valueParameterDescriptors.add(it);
context.trace.record(AUTO_CREATED_IT, it); context.trace.record(AUTO_CREATED_IT, it);
@@ -177,7 +177,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
} }
else { else {
if (expectedValueParameters != null && i < expectedValueParameters.size()) { if (expectedValueParameters != null && i < expectedValueParameters.size()) {
type = expectedValueParameters.get(i).getOutType(); type = expectedValueParameters.get(i).getType();
} }
else { else {
context.trace.report(CANNOT_INFER_PARAMETER_TYPE.on(declaredParameter)); context.trace.report(CANNOT_INFER_PARAMETER_TYPE.on(declaredParameter));
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
@@ -248,7 +248,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
VariableDescriptor variableDescriptor; VariableDescriptor variableDescriptor;
if (typeReference != null) { if (typeReference != null) {
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, loopParameter); variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, loopParameter);
JetType actualParameterType = variableDescriptor.getOutType(); JetType actualParameterType = variableDescriptor.getType();
if (expectedParameterType != null && if (expectedParameterType != null &&
actualParameterType != null && actualParameterType != null &&
!context.semanticServices.getTypeChecker().isSubtypeOf(expectedParameterType, actualParameterType)) { !context.semanticServices.getTypeChecker().isSubtypeOf(expectedParameterType, actualParameterType)) {
@@ -377,7 +377,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
if (hasNextProperty == null) { if (hasNextProperty == null) {
return null; return null;
} else { } else {
JetType hasNextReturnType = hasNextProperty.getOutType(); JetType hasNextReturnType = hasNextProperty.getType();
if (hasNextReturnType == null) { if (hasNextReturnType == null) {
// TODO : accessibility // TODO : accessibility
context.trace.report(HAS_NEXT_MUST_BE_READABLE.on(loopRange)); context.trace.report(HAS_NEXT_MUST_BE_READABLE.on(loopRange));
@@ -401,7 +401,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
if (catchParameter != null) { if (catchParameter != null) {
VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter); VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter);
JetType throwableType = context.semanticServices.getStandardLibrary().getThrowable().getDefaultType(); JetType throwableType = context.semanticServices.getStandardLibrary().getThrowable().getDefaultType();
DataFlowUtils.checkType(variableDescriptor.getOutType(), catchParameter, context.replaceExpectedType(throwableType)); DataFlowUtils.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType));
if (catchBody != null) { if (catchBody != null) {
WritableScope catchScope = newWritableScopeImpl(context).setDebugName("Catch scope"); WritableScope catchScope = newWritableScopeImpl(context).setDebugName("Catch scope");
catchScope.addVariableDescriptor(variableDescriptor); catchScope.addVariableDescriptor(variableDescriptor);
@@ -479,7 +479,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
} }
} }
else if (element != null) { else if (element != null) {
NamedFunctionDescriptor functionDescriptor = context.trace.get(FUNCTION, element); SimpleFunctionDescriptor functionDescriptor = context.trace.get(FUNCTION, element);
if (functionDescriptor != null) { if (functionDescriptor != null) {
expectedType = DescriptorUtils.getFunctionExpectedReturnType(functionDescriptor, element); expectedType = DescriptorUtils.getFunctionExpectedReturnType(functionDescriptor, element);
if (functionDescriptor != containingFunctionDescriptor) { if (functionDescriptor != containingFunctionDescriptor) {
@@ -150,7 +150,7 @@ public class ExpressionTypingUtils {
public static boolean isVariableIterable(@NotNull Project project, @NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope) { public static boolean isVariableIterable(@NotNull Project project, @NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope) {
JetExpression expression = JetPsiFactory.createExpression(project, "fake"); JetExpression expression = JetPsiFactory.createExpression(project, "fake");
ExpressionReceiver expressionReceiver = new ExpressionReceiver(expression, variableDescriptor.getOutType()); ExpressionReceiver expressionReceiver = new ExpressionReceiver(expression, variableDescriptor.getType());
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
project, project,
JetSemanticServices.createSemanticServices(project), JetSemanticServices.createSemanticServices(project),
@@ -109,7 +109,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
VariableDescriptor propertyDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property, context.dataFlowInfo); VariableDescriptor propertyDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property, context.dataFlowInfo);
JetExpression initializer = property.getInitializer(); JetExpression initializer = property.getInitializer();
if (property.getPropertyTypeRef() != null && initializer != null) { if (property.getPropertyTypeRef() != null && initializer != null) {
JetType outType = propertyDescriptor.getOutType(); JetType outType = propertyDescriptor.getType();
JetType initializerType = facade.getType(initializer, context.replaceExpectedType(outType).replaceScope(scope)); JetType initializerType = facade.getType(initializer, context.replaceExpectedType(outType).replaceScope(scope));
} }
@@ -126,7 +126,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
@Override @Override
public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) { public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) {
NamedFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function); SimpleFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function);
scope.addFunctionDescriptor(functionDescriptor); scope.addFunctionDescriptor(functionDescriptor);
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace); JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
context.getServices().checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo); context.getServices().checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo);
@@ -152,7 +152,7 @@ public class DescriptorRenderer implements Renderer {
@Override @Override
public Void visitVariableDescriptor(VariableDescriptor descriptor, StringBuilder builder) { public Void visitVariableDescriptor(VariableDescriptor descriptor, StringBuilder builder) {
String typeString = renderPropertyPrefixAndComputeTypeString(builder, Collections.<TypeParameterDescriptor>emptyList(), ReceiverDescriptor.NO_RECEIVER, descriptor.getOutType()); String typeString = renderPropertyPrefixAndComputeTypeString(builder, Collections.<TypeParameterDescriptor>emptyList(), ReceiverDescriptor.NO_RECEIVER, descriptor.getType());
renderName(descriptor, builder); renderName(descriptor, builder);
builder.append(" : ").append(escape(typeString)); builder.append(" : ").append(escape(typeString));
return super.visitVariableDescriptor(descriptor, builder); return super.visitVariableDescriptor(descriptor, builder);
@@ -188,7 +188,7 @@ public class DescriptorRenderer implements Renderer {
String typeString = renderPropertyPrefixAndComputeTypeString( String typeString = renderPropertyPrefixAndComputeTypeString(
builder, descriptor.getTypeParameters(), builder, descriptor.getTypeParameters(),
descriptor.getReceiverParameter(), descriptor.getReceiverParameter(),
descriptor.getOutType()); descriptor.getType());
renderName(descriptor, builder); renderName(descriptor, builder);
builder.append(" : ").append(escape(typeString)); builder.append(" : ").append(escape(typeString));
return null; return null;
@@ -0,0 +1,26 @@
package pack
import java.util.Collection
import java.util.ArrayList
import java.util.regex.Pattern
class C{
public fun foo(){
val items : Collection<Item> = java.util.Collections.singleton(Item()).sure()
val result = ArrayList<Item>()
val pattern: Pattern? = Pattern.compile("...")
items.filterTo(result) {
pattern.sure().matcher(it.name()).sure().matches()
}
}
private fun Item.name() : String = ""
}
class Item{
}
fun box() : String {
C().foo()
return "OK"
}
@@ -199,6 +199,7 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testKt1170() throws Exception { public void testKt1170() throws Exception {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt1170.kt"); blackBoxFile("regressions/kt1170.kt");
} }
@@ -116,4 +116,8 @@ public class StdlibTest extends CodegenTestCase {
throw t instanceof Exception ? (Exception)t : new RuntimeException(t); throw t instanceof Exception ? (Exception)t : new RuntimeException(t);
} }
} }
public void testKt1406() throws Exception {
blackBoxFile("regressions/kt1406.kt");
}
} }
@@ -16,7 +16,6 @@
package org.jetbrains.jet.compiler; package org.jetbrains.jet.compiler;
import com.google.common.io.ByteStreams;
import com.google.common.io.Files; import com.google.common.io.Files;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.PropertyCodegen; import org.jetbrains.jet.codegen.PropertyCodegen;
@@ -34,7 +33,6 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver; import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor; import org.jetbrains.jet.lang.resolve.java.JavaNamespaceDescriptor;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
@@ -282,7 +280,7 @@ class NamespaceComparator {
} }
sb.append(prop.getName()); sb.append(prop.getName());
sb.append(": "); sb.append(": ");
new Serializer(sb).serialize(prop.getOutType()); new Serializer(sb).serialize(prop.getType());
} }
public void serialize(ValueParameterDescriptor valueParameter) { public void serialize(ValueParameterDescriptor valueParameter) {
@@ -297,7 +295,7 @@ class NamespaceComparator {
if (valueParameter.getVarargElementType() != null) { if (valueParameter.getVarargElementType() != null) {
serialize(valueParameter.getVarargElementType()); serialize(valueParameter.getVarargElementType());
} else { } else {
serialize(valueParameter.getOutType()); serialize(valueParameter.getType());
} }
if (valueParameter.hasDefaultValue()) { if (valueParameter.hasDefaultValue()) {
sb.append(" = ?"); sb.append(" = ?");
@@ -142,7 +142,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
List<ValueParameterDescriptor> unsubstitutedValueParameters = resolvedCall.getResultingDescriptor().getValueParameters(); List<ValueParameterDescriptor> unsubstitutedValueParameters = resolvedCall.getResultingDescriptor().getValueParameters();
for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) { for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i); ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i);
if (unsubstitutedValueParameter.getOutType().equals(parameterType[i])) { if (unsubstitutedValueParameter.getType().equals(parameterType[i])) {
return resolvedCall.getResultingDescriptor(); return resolvedCall.getResultingDescriptor();
} }
} }
@@ -90,7 +90,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List<JetDeclaration> declarations = aClass.getDeclarations(); List<JetDeclaration> declarations = aClass.getDeclarations();
JetNamedFunction function = (JetNamedFunction) declarations.get(0); JetNamedFunction function = (JetNamedFunction) declarations.get(0);
NamedFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function); SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function);
assertEquals(expectedFunctionModality, functionDescriptor.getModality()); assertEquals(expectedFunctionModality, functionDescriptor.getModality());
} }
@@ -80,7 +80,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
if (element instanceof JetNamedFunction) { if (element instanceof JetNamedFunction) {
JetNamedFunction jetFunction = (JetNamedFunction) element; JetNamedFunction jetFunction = (JetNamedFunction) element;
final NamedFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, jetFunction); final SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, jetFunction);
if (functionDescriptor == null) return null; if (functionDescriptor == null) return null;
final Set<? extends FunctionDescriptor> overriddenFunctions = functionDescriptor.getOverriddenDescriptors(); final Set<? extends FunctionDescriptor> overriddenFunctions = functionDescriptor.getOverriddenDescriptors();
Icon icon = isMember(functionDescriptor) ? (overriddenFunctions.isEmpty() ? PlatformIcons.METHOD_ICON : OVERRIDING_FUNCTION) : PlatformIcons.FUNCTION_ICON; Icon icon = isMember(functionDescriptor) ? (overriddenFunctions.isEmpty() ? PlatformIcons.METHOD_ICON : OVERRIDING_FUNCTION) : PlatformIcons.FUNCTION_ICON;
@@ -198,7 +198,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
); );
} }
private boolean isMember(@NotNull NamedFunctionDescriptor functionDescriptor) { private boolean isMember(@NotNull SimpleFunctionDescriptor functionDescriptor) {
return functionDescriptor.getContainingDeclaration().getOriginal() instanceof ClassifierDescriptor; return functionDescriptor.getContainingDeclaration().getOriginal() instanceof ClassifierDescriptor;
} }
@@ -29,7 +29,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.asJava.JavaElementFinder; import org.jetbrains.jet.asJava.JavaElementFinder;
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.psi.JetNamedFunction; import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -135,7 +135,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
} }
@NotNull @NotNull
public Collection<NamedFunctionDescriptor> getTopLevelFunctionDescriptorsByName(final @NotNull String name, public Collection<SimpleFunctionDescriptor> getTopLevelFunctionDescriptorsByName(final @NotNull String name,
final @NotNull GlobalSearchScope scope) { final @NotNull GlobalSearchScope scope) {
// TODO: Add jet function in jar-dependencies (those functions are missing in BindingContext and stubs) // TODO: Add jet function in jar-dependencies (those functions are missing in BindingContext and stubs)
@@ -144,10 +144,10 @@ public class JetShortNamesCache extends PsiShortNamesCache {
final BindingContext context = getResolutionContext(scope); final BindingContext context = getResolutionContext(scope);
final HashSet<NamedFunctionDescriptor> result = new HashSet<NamedFunctionDescriptor>(); final HashSet<SimpleFunctionDescriptor> result = new HashSet<SimpleFunctionDescriptor>();
for (JetNamedFunction jetNamedFunction : jetNamedFunctions) { for (JetNamedFunction jetNamedFunction : jetNamedFunctions) {
final NamedFunctionDescriptor functionDescriptor = context.get(BindingContext.FUNCTION, jetNamedFunction); final SimpleFunctionDescriptor functionDescriptor = context.get(BindingContext.FUNCTION, jetNamedFunction);
if (functionDescriptor != null) { if (functionDescriptor != null) {
result.add(functionDescriptor); result.add(functionDescriptor);
} }
@@ -181,17 +181,17 @@ public class JetShortNamesCache extends PsiShortNamesCache {
return extensionFunctionNames; return extensionFunctionNames;
} }
public Collection<NamedFunctionDescriptor> getAllJetExtensionFunctionsByName(@NotNull String name, @NotNull GlobalSearchScope scope) { public Collection<SimpleFunctionDescriptor> getAllJetExtensionFunctionsByName(@NotNull String name, @NotNull GlobalSearchScope scope) {
// TODO: Add jet extension functions in jar-dependencies (those functions are missing in BindingContext and stubs) // TODO: Add jet extension functions in jar-dependencies (those functions are missing in BindingContext and stubs)
final Collection<JetNamedFunction> jetNamedFunctions = JetShortFunctionNameIndex.getInstance().get(name, project, scope); final Collection<JetNamedFunction> jetNamedFunctions = JetShortFunctionNameIndex.getInstance().get(name, project, scope);
final BindingContext context = getResolutionContext(scope); final BindingContext context = getResolutionContext(scope);
final HashSet<NamedFunctionDescriptor> result = new HashSet<NamedFunctionDescriptor>(); final HashSet<SimpleFunctionDescriptor> result = new HashSet<SimpleFunctionDescriptor>();
for (JetNamedFunction jetNamedFunction : jetNamedFunctions) { for (JetNamedFunction jetNamedFunction : jetNamedFunctions) {
final NamedFunctionDescriptor functionDescriptor = context.get(BindingContext.FUNCTION, jetNamedFunction); final SimpleFunctionDescriptor functionDescriptor = context.get(BindingContext.FUNCTION, jetNamedFunction);
if (functionDescriptor != null) { if (functionDescriptor != null) {
if (functionDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) { if (functionDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor) {
if (functionDescriptor.getExpectedThisObject() != ReceiverDescriptor.NO_RECEIVER) { if (functionDescriptor.getExpectedThisObject() != ReceiverDescriptor.NO_RECEIVER) {
@@ -73,8 +73,8 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
for (DescriptorClassMember selectedElement : selectedElements) { for (DescriptorClassMember selectedElement : selectedElements) {
final DeclarationDescriptor descriptor = selectedElement.getDescriptor(); final DeclarationDescriptor descriptor = selectedElement.getDescriptor();
JetFile containingFile = (JetFile) classOrObject.getContainingFile(); JetFile containingFile = (JetFile) classOrObject.getContainingFile();
if (descriptor instanceof NamedFunctionDescriptor) { if (descriptor instanceof SimpleFunctionDescriptor) {
JetElement target = overrideFunction(project, containingFile, (NamedFunctionDescriptor) descriptor); JetElement target = overrideFunction(project, containingFile, (SimpleFunctionDescriptor) descriptor);
body.addBefore(target, body.getRBrace()); body.addBefore(target, body.getRBrace());
} }
else if (descriptor instanceof PropertyDescriptor) { else if (descriptor instanceof PropertyDescriptor) {
@@ -92,9 +92,9 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
else { else {
bodyBuilder.append("val "); bodyBuilder.append("val ");
} }
bodyBuilder.append(descriptor.getName()).append(": ").append(descriptor.getOutType()); bodyBuilder.append(descriptor.getName()).append(": ").append(descriptor.getType());
ImportClassHelper.addImportDirectiveIfNeeded(descriptor.getOutType(), file); ImportClassHelper.addImportDirectiveIfNeeded(descriptor.getType(), file);
String initializer = defaultInitializer(descriptor.getOutType(), JetStandardLibrary.getInstance()); String initializer = defaultInitializer(descriptor.getType(), JetStandardLibrary.getInstance());
if (initializer != null) { if (initializer != null) {
bodyBuilder.append("=").append(initializer); bodyBuilder.append("=").append(initializer);
} }
@@ -104,7 +104,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
return JetPsiFactory.createProperty(project, bodyBuilder.toString()); return JetPsiFactory.createProperty(project, bodyBuilder.toString());
} }
private static JetElement overrideFunction(Project project, JetFile file, NamedFunctionDescriptor descriptor) { private static JetElement overrideFunction(Project project, JetFile file, SimpleFunctionDescriptor descriptor) {
StringBuilder bodyBuilder = new StringBuilder("override fun "); StringBuilder bodyBuilder = new StringBuilder("override fun ");
bodyBuilder.append(descriptor.getName()); bodyBuilder.append(descriptor.getName());
bodyBuilder.append("("); bodyBuilder.append("(");
@@ -116,9 +116,9 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
first = false; first = false;
bodyBuilder.append(parameterDescriptor.getName()); bodyBuilder.append(parameterDescriptor.getName());
bodyBuilder.append(": "); bodyBuilder.append(": ");
bodyBuilder.append(parameterDescriptor.getOutType().toString()); bodyBuilder.append(parameterDescriptor.getType().toString());
ImportClassHelper.addImportDirectiveIfNeeded(parameterDescriptor.getOutType(), file); ImportClassHelper.addImportDirectiveIfNeeded(parameterDescriptor.getType(), file);
} }
bodyBuilder.append(")"); bodyBuilder.append(")");
final JetType returnType = descriptor.getReturnType(); final JetType returnType = descriptor.getReturnType();
@@ -64,7 +64,7 @@ public final class DescriptorLookupConverter {
@Override @Override
public String fun(ValueParameterDescriptor valueParameterDescriptor) { public String fun(ValueParameterDescriptor valueParameterDescriptor) {
return valueParameterDescriptor.getName() + ":" + return valueParameterDescriptor.getName() + ":" +
DescriptorRenderer.TEXT.renderType(valueParameterDescriptor.getOutType()); DescriptorRenderer.TEXT.renderType(valueParameterDescriptor.getType());
} }
}, ",") + ")"; }, ",") + ")";
@@ -78,7 +78,7 @@ public final class DescriptorLookupConverter {
} }
} }
else if (descriptor instanceof VariableDescriptor) { else if (descriptor instanceof VariableDescriptor) {
JetType outType = ((VariableDescriptor) descriptor).getOutType(); JetType outType = ((VariableDescriptor) descriptor).getType();
typeText = DescriptorRenderer.TEXT.renderType(outType); typeText = DescriptorRenderer.TEXT.renderType(outType);
} }
else if (descriptor instanceof ClassDescriptor) { else if (descriptor instanceof ClassDescriptor) {
@@ -28,7 +28,7 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetImportDirective; import org.jetbrains.jet.lang.psi.JetImportDirective;
import org.jetbrains.jet.lang.psi.JetQualifiedExpression; import org.jetbrains.jet.lang.psi.JetQualifiedExpression;
@@ -122,10 +122,10 @@ public class JetFunctionInsertHandler implements InsertHandler<LookupElement> {
if (context.getFile() instanceof JetFile && item.getObject() instanceof JetLookupObject) { if (context.getFile() instanceof JetFile && item.getObject() instanceof JetLookupObject) {
final DeclarationDescriptor descriptor = ((JetLookupObject) item.getObject()).getDescriptor(); final DeclarationDescriptor descriptor = ((JetLookupObject) item.getObject()).getDescriptor();
if (descriptor instanceof NamedFunctionDescriptor) { if (descriptor instanceof SimpleFunctionDescriptor) {
final JetFile file = (JetFile) context.getFile(); final JetFile file = (JetFile) context.getFile();
NamedFunctionDescriptor functionDescriptor = (NamedFunctionDescriptor) descriptor; SimpleFunctionDescriptor functionDescriptor = (SimpleFunctionDescriptor) descriptor;
final String fqn = DescriptorUtils.getFQName(functionDescriptor); final String fqn = DescriptorUtils.getFQName(functionDescriptor);
if (DescriptorUtils.isTopLevelFunction(functionDescriptor)) { if (DescriptorUtils.isTopLevelFunction(functionDescriptor)) {
@@ -173,7 +173,7 @@ public class JetFunctionParameterInfoHandler implements
} }
private static JetType getActualParameterType(ValueParameterDescriptor descriptor) { private static JetType getActualParameterType(ValueParameterDescriptor descriptor) {
JetType paramType = descriptor.getOutType(); JetType paramType = descriptor.getType();
if (descriptor.getVarargElementType() != null) paramType = descriptor.getVarargElementType(); if (descriptor.getVarargElementType() != null) paramType = descriptor.getVarargElementType();
return paramType; return paramType;
} }
@@ -190,7 +190,7 @@ public class JetStructureViewElement implements StructureViewTreeElement {
@Override @Override
public String fun(ValueParameterDescriptor valueParameterDescriptor) { public String fun(ValueParameterDescriptor valueParameterDescriptor) {
return valueParameterDescriptor.getName() + ":" + return valueParameterDescriptor.getName() + ":" +
DescriptorRenderer.TEXT.renderType(valueParameterDescriptor.getOutType()); DescriptorRenderer.TEXT.renderType(valueParameterDescriptor.getType());
} }
}, },
","); ",");
@@ -201,7 +201,7 @@ public class JetStructureViewElement implements StructureViewTreeElement {
textBuilder.append(":").append(DescriptorRenderer.TEXT.renderType(returnType)); textBuilder.append(":").append(DescriptorRenderer.TEXT.renderType(returnType));
} }
else if (descriptor instanceof VariableDescriptor) { else if (descriptor instanceof VariableDescriptor) {
JetType outType = ((VariableDescriptor) descriptor).getOutType(); JetType outType = ((VariableDescriptor) descriptor).getType();
textBuilder = new StringBuilder(descriptor.getName()); textBuilder = new StringBuilder(descriptor.getName());
textBuilder.append(":").append(DescriptorRenderer.TEXT.renderType(outType)); textBuilder.append(":").append(DescriptorRenderer.TEXT.renderType(outType));