mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-14 00:21:27 +00:00
Compare commits
22 Commits
get-script
...
build-0.6.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c8852b5fa | ||
|
|
71fbb4f7d7 | ||
|
|
9312967594 | ||
|
|
8f5f2c52af | ||
|
|
f4cede4de8 | ||
|
|
fc6dd3e293 | ||
|
|
1de5c21557 | ||
|
|
6141296de6 | ||
|
|
be2d46f37f | ||
|
|
ecf9c0dd29 | ||
|
|
72187acf78 | ||
|
|
5e7ddc5c46 | ||
|
|
99eb6d59db | ||
|
|
57cd2c61d8 | ||
|
|
223e8c8511 | ||
|
|
5bbf20d94d | ||
|
|
4446761371 | ||
|
|
35d053d6a6 | ||
|
|
81396309ee | ||
|
|
e35c24ebdf | ||
|
|
34a3fe2088 | ||
|
|
44cf725322 |
3
.idea/inspectionProfiles/idea_default.xml
generated
3
.idea/inspectionProfiles/idea_default.xml
generated
@@ -273,9 +273,6 @@
|
||||
<inspection_tool class="ObsoleteCollection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoreRequiredObsoleteCollectionTypes" value="false" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PointlessArithmeticExpression" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="m_ignoreExpressionsContainingConstants" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="ProtectedMemberInFinalClass" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PublicFieldAccessedInSynchronizedContext" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="ERROR" enabled_by_default="true">
|
||||
|
||||
@@ -82,16 +82,37 @@ public class AsmUtil {
|
||||
private static final String STUB_EXCEPTION = "java/lang/RuntimeException";
|
||||
private static final String STUB_EXCEPTION_MESSAGE = "Stubs are for compiler only, do not add them to runtime classpath";
|
||||
|
||||
private static final ImmutableMap<Integer, JvmPrimitiveType> primitiveTypeByAsmSort;
|
||||
private static final ImmutableMap<Type, JvmPrimitiveType> primitiveTypeByBoxedType;
|
||||
|
||||
static {
|
||||
ImmutableMap.Builder<Integer, JvmPrimitiveType> typeBySortBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<Type, JvmPrimitiveType> typeByWrapperBuilder = ImmutableMap.builder();
|
||||
for (JvmPrimitiveType type : JvmPrimitiveType.values()) {
|
||||
typeBySortBuilder.put(type.getAsmType().getSort(), type);
|
||||
typeByWrapperBuilder.put(type.getWrapper().getAsmType(), type);
|
||||
}
|
||||
primitiveTypeByAsmSort = typeBySortBuilder.build();
|
||||
primitiveTypeByBoxedType = typeByWrapperBuilder.build();
|
||||
}
|
||||
|
||||
private AsmUtil() {
|
||||
}
|
||||
|
||||
public static Type boxType(Type asmType) {
|
||||
JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByAsmType(asmType);
|
||||
@NotNull
|
||||
public static Type boxType(@NotNull Type type) {
|
||||
JvmPrimitiveType jvmPrimitiveType = primitiveTypeByAsmSort.get(type.getSort());
|
||||
return jvmPrimitiveType != null ? jvmPrimitiveType.getWrapper().getAsmType() : type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Type unboxType(@NotNull Type type) {
|
||||
JvmPrimitiveType jvmPrimitiveType = primitiveTypeByBoxedType.get(type);
|
||||
if (jvmPrimitiveType != null) {
|
||||
return jvmPrimitiveType.getWrapper().getAsmType();
|
||||
return jvmPrimitiveType.getAsmType();
|
||||
}
|
||||
else {
|
||||
return asmType;
|
||||
throw new UnsupportedOperationException("Unboxing: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,16 +141,6 @@ public class AsmUtil {
|
||||
return Type.getType(internalName.substring(1));
|
||||
}
|
||||
|
||||
public static Type unboxType(Type type) {
|
||||
JvmPrimitiveType jvmPrimitiveType = JvmPrimitiveType.getByWrapperAsmType(type);
|
||||
if (jvmPrimitiveType != null) {
|
||||
return jvmPrimitiveType.getAsmType();
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Unboxing: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAbstractMethod(FunctionDescriptor functionDescriptor, OwnerKind kind) {
|
||||
return (functionDescriptor.getModality() == Modality.ABSTRACT
|
||||
|| isInterface(functionDescriptor.getContainingDeclaration()))
|
||||
|
||||
@@ -27,8 +27,11 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -196,9 +199,26 @@ public abstract class ClassBodyCodegen extends MemberCodegen {
|
||||
|
||||
private void generateRemoveInIterator() {
|
||||
// generates stub 'remove' function for subclasses of Iterator to be compatible with java.util.Iterator
|
||||
if (DescriptorUtils.isIteratorWithoutRemoveImpl(descriptor)) {
|
||||
if (isIteratorWithoutRemoveImpl(descriptor)) {
|
||||
MethodVisitor mv = v.getVisitor().visitMethod(ACC_PUBLIC, "remove", "()V", null, null);
|
||||
genMethodThrow(mv, "java/lang/UnsupportedOperationException", "Mutating method called on a Kotlin Iterator");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isIteratorWithoutRemoveImpl(@NotNull ClassDescriptor classDescriptor) {
|
||||
ClassDescriptor iteratorOfT = KotlinBuiltIns.getInstance().getIterator();
|
||||
JetType iteratorOfAny =
|
||||
TypeUtils.substituteParameters(iteratorOfT, Collections.singletonList(KotlinBuiltIns.getInstance().getAnyType()));
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(classDescriptor.getDefaultType(), iteratorOfAny)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (FunctionDescriptor function : classDescriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("remove"))) {
|
||||
if (function.getValueParameters().isEmpty() && function.getTypeParameters().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +251,13 @@ public class CodegenUtil {
|
||||
!specialTypeProperty &&
|
||||
(accessorDescriptor == null ||
|
||||
accessorDescriptor.isDefault() &&
|
||||
(!DescriptorUtils.isExternallyAccessible(propertyDescriptor) || accessorDescriptor.getModality() == Modality.FINAL));
|
||||
(!isExternallyAccessible(propertyDescriptor) || accessorDescriptor.getModality() == Modality.FINAL));
|
||||
}
|
||||
|
||||
private static boolean isExternallyAccessible(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return propertyDescriptor.getVisibility() != Visibilities.PRIVATE ||
|
||||
DescriptorUtils.isClassObject(propertyDescriptor.getContainingDeclaration()) ||
|
||||
DescriptorUtils.isTopLevelDeclaration(propertyDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -54,7 +54,6 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmBytecode;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -673,12 +672,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
// This method consumes range/progression from stack
|
||||
// The result is stored to local variable
|
||||
protected void generateRangeOrProgressionProperty(Type loopRangeType, String getterName, Type elementType, int varToStore) {
|
||||
JvmPrimitiveType primitiveType = JvmPrimitiveType.getByAsmType(elementType);
|
||||
assert primitiveType != null : elementType;
|
||||
Type asmWrapperType = primitiveType.getWrapper().getAsmType();
|
||||
|
||||
v.invokevirtual(loopRangeType.getInternalName(), getterName, "()" + asmWrapperType.getDescriptor());
|
||||
StackValue.coerce(asmWrapperType, elementType, v);
|
||||
Type boxedType = boxType(elementType);
|
||||
v.invokevirtual(loopRangeType.getInternalName(), getterName, "()" + boxedType.getDescriptor());
|
||||
StackValue.coerce(boxedType, elementType, v);
|
||||
v.store(varToStore, elementType);
|
||||
}
|
||||
}
|
||||
@@ -2489,16 +2485,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
computeAndSaveArguments(codegen.myFrameMap, fakeArguments, codegen);
|
||||
|
||||
ResolvedCall<CallableDescriptor> fakeResolvedCall = new DelegatingResolvedCall<CallableDescriptor>(resolvedCall) {
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getReceiverArgument() {
|
||||
return resolvedCall.getExplicitReceiverKind() == RECEIVER_ARGUMENT ? receiverValue : NO_RECEIVER;
|
||||
return resolvedCall.getExplicitReceiverKind() == RECEIVER_ARGUMENT ? receiverValue : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getThisObject() {
|
||||
return resolvedCall.getExplicitReceiverKind() == THIS_OBJECT ? receiverValue : NO_RECEIVER;
|
||||
return resolvedCall.getExplicitReceiverKind() == THIS_OBJECT ? receiverValue : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -2563,7 +2559,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
private ReceiverValue computeAndSaveReceiver(
|
||||
@NotNull JvmMethodSignature signature,
|
||||
@NotNull ExpressionCodegen codegen
|
||||
@@ -2578,7 +2574,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
ReceiverParameterDescriptor receiver = receiverParameter != null ? receiverParameter : expectedThisObject;
|
||||
|
||||
if (receiver == null) {
|
||||
return NO_RECEIVER;
|
||||
return null;
|
||||
}
|
||||
|
||||
JetExpression receiverExpression = JetPsiFactory.createExpression(state.getProject(),
|
||||
@@ -3288,7 +3284,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
//Resolved call to local class constructor doesn't have resolvedCall.getThisObject() and resolvedCall.getReceiverArgument()
|
||||
//so we need generate closure on stack
|
||||
//See StackValue.receiver for more info
|
||||
pushClosureOnStack(closure, resolvedCall.getThisObject().exists() || resolvedCall.getReceiverArgument().exists());
|
||||
pushClosureOnStack(closure, resolvedCall.getThisObject() != null || resolvedCall.getReceiverArgument() != null);
|
||||
|
||||
ConstructorDescriptor originalOfSamAdapter = (ConstructorDescriptor) SamCodegenUtil.getOriginalIfSamAdapter(constructorDescriptor);
|
||||
CallableMethod method = typeMapper.mapToCallableMethod(originalOfSamAdapter == null ? constructorDescriptor : originalOfSamAdapter);
|
||||
|
||||
@@ -467,11 +467,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private List<PropertyDescriptor> getDataProperties() {
|
||||
ArrayList<PropertyDescriptor> result = Lists.newArrayList();
|
||||
for (JetParameter parameter : getPrimaryConstructorParameters()) {
|
||||
if (parameter.getValOrVarNode() == null) continue;
|
||||
|
||||
PropertyDescriptor propertyDescriptor = DescriptorUtils.getPropertyDescriptor(parameter, bindingContext);
|
||||
|
||||
result.add(propertyDescriptor);
|
||||
if (parameter.getValOrVarNode() != null) {
|
||||
result.add(bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1107,9 +1105,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
Type type = typeMapper.mapType(descriptor);
|
||||
iv.load(0, classAsmType);
|
||||
iv.load(codegen.myFrameMap.getIndex(descriptor), type);
|
||||
iv.putfield(classAsmType.getInternalName(),
|
||||
context.getFieldName(DescriptorUtils.getPropertyDescriptor(parameter, bindingContext)),
|
||||
type.getDescriptor());
|
||||
PropertyDescriptor propertyDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter);
|
||||
assert propertyDescriptor != null : "Property descriptor is not found for primary constructor parameter: " + parameter;
|
||||
iv.putfield(classAsmType.getInternalName(), context.getFieldName(propertyDescriptor), type.getDescriptor());
|
||||
}
|
||||
curParam++;
|
||||
}
|
||||
@@ -1740,7 +1738,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
CallableMemberDescriptor candidate = null;
|
||||
|
||||
for (CallableMemberDescriptor overriddenDeclaration : filteredOverriddenDeclarations) {
|
||||
if (isKindOf(overriddenDeclaration.getContainingDeclaration(), ClassKind.TRAIT) &&
|
||||
if (isTrait(overriddenDeclaration.getContainingDeclaration()) &&
|
||||
overriddenDeclaration.getModality() != Modality.ABSTRACT) {
|
||||
candidate = overriddenDeclaration;
|
||||
count++;
|
||||
|
||||
@@ -33,8 +33,7 @@ import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.DefaultDescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
@@ -82,7 +81,10 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
}
|
||||
|
||||
public void gen(JetProperty p) {
|
||||
PropertyDescriptor propertyDescriptor = DescriptorUtils.getPropertyDescriptor(p, bindingContext);
|
||||
VariableDescriptor variableDescriptor = bindingContext.get(BindingContext.VARIABLE, p);
|
||||
assert variableDescriptor instanceof PropertyDescriptor : "Property should have a property descriptor: " + variableDescriptor;
|
||||
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) variableDescriptor;
|
||||
assert kind instanceof OwnerKind.StaticDelegateKind || kind == OwnerKind.NAMESPACE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.TRAIT_IMPL
|
||||
: "Generating property with a wrong kind (" + kind + "): " + propertyDescriptor;
|
||||
|
||||
@@ -231,7 +233,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
//if (!defaultGetter || isExternallyAccessible(propertyDescriptor)) {
|
||||
JvmMethodSignature signature = typeMapper.mapGetterSignature(propertyDescriptor, kind);
|
||||
PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
|
||||
getterDescriptor = getterDescriptor != null ? getterDescriptor : DescriptorResolver.createDefaultGetter(propertyDescriptor);
|
||||
getterDescriptor = getterDescriptor != null ? getterDescriptor : DefaultDescriptorFactory.createDefaultGetter(propertyDescriptor);
|
||||
|
||||
if (kind != OwnerKind.TRAIT_IMPL || !defaultGetter) {
|
||||
FunctionGenerationStrategy strategy;
|
||||
@@ -261,7 +263,8 @@ public class PropertyCodegen extends GenerationStateAware {
|
||||
if (/*!defaultSetter || isExternallyAccessible(propertyDescriptor) &&*/ propertyDescriptor.isVar()) {
|
||||
JvmMethodSignature signature = typeMapper.mapSetterSignature(propertyDescriptor, kind);
|
||||
PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
|
||||
setterDescriptor = setterDescriptor != null ? setterDescriptor : DescriptorResolver.createDefaultSetter(propertyDescriptor);
|
||||
setterDescriptor =
|
||||
setterDescriptor != null ? setterDescriptor : DefaultDescriptorFactory.createDefaultSetter(propertyDescriptor);
|
||||
|
||||
if (kind != OwnerKind.TRAIT_IMPL || !defaultSetter) {
|
||||
FunctionGenerationStrategy strategy;
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
@@ -40,8 +41,8 @@ public class RangeCodegenUtil {
|
||||
ImmutableMap.Builder<FqName, PrimitiveType> rangeBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<FqName, PrimitiveType> progressionBuilder = ImmutableMap.builder();
|
||||
for (PrimitiveType primitiveType : PrimitiveType.values()) {
|
||||
rangeBuilder.put(primitiveType.getRangeClassName(), primitiveType);
|
||||
progressionBuilder.put(primitiveType.getProgressionClassName(), primitiveType);
|
||||
rangeBuilder.put(getRangeClassFqName(primitiveType), primitiveType);
|
||||
progressionBuilder.put(getProgressionClassFqName(primitiveType), primitiveType);
|
||||
}
|
||||
RANGE_TO_ELEMENT_TYPE = rangeBuilder.build();
|
||||
PROGRESSION_TO_ELEMENT_TYPE = progressionBuilder.build();
|
||||
@@ -120,6 +121,16 @@ public class RangeCodegenUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FqName getRangeClassFqName(@NotNull PrimitiveType type) {
|
||||
return KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier(type.getTypeName() + "Range"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static FqName getProgressionClassFqName(@NotNull PrimitiveType type) {
|
||||
return KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier(type.getTypeName() + "Progression"));
|
||||
}
|
||||
|
||||
public static class BinaryCall {
|
||||
public final JetExpression left;
|
||||
public final JetExpression op;
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -106,7 +105,7 @@ public class ScriptCodegen extends MemberCodegen {
|
||||
|
||||
Type blockType = typeMapper.mapType(scriptDescriptor.getReturnType());
|
||||
|
||||
classBuilder.newField(null, ACC_PUBLIC | ACC_FINAL, ScriptNameUtil.LAST_EXPRESSION_VALUE_FIELD_NAME,
|
||||
classBuilder.newField(null, ACC_PUBLIC | ACC_FINAL, ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME,
|
||||
blockType.getDescriptor(), null, null);
|
||||
|
||||
JvmMethodSignature jvmSignature = typeMapper.mapScriptSignature(scriptDescriptor, importedScripts);
|
||||
@@ -173,7 +172,7 @@ public class ScriptCodegen extends MemberCodegen {
|
||||
if (stackValue.type != Type.VOID_TYPE) {
|
||||
stackValue.put(stackValue.type, instructionAdapter);
|
||||
instructionAdapter
|
||||
.putfield(className.getInternalName(), ScriptNameUtil.LAST_EXPRESSION_VALUE_FIELD_NAME, blockType.getDescriptor());
|
||||
.putfield(className.getInternalName(), ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME, blockType.getDescriptor());
|
||||
}
|
||||
|
||||
instructionAdapter.areturn(Type.VOID_TYPE);
|
||||
|
||||
@@ -317,7 +317,7 @@ public abstract class StackValue {
|
||||
ExpressionCodegen codegen,
|
||||
@Nullable CallableMethod callableMethod
|
||||
) {
|
||||
if (resolvedCall.getThisObject().exists() || resolvedCall.getReceiverArgument().exists()) {
|
||||
if (resolvedCall.getThisObject() != null || resolvedCall.getReceiverArgument() != null) {
|
||||
return new CallReceiver(resolvedCall, receiver, codegen, callableMethod, true);
|
||||
}
|
||||
return receiver;
|
||||
@@ -691,7 +691,7 @@ public abstract class StackValue {
|
||||
|
||||
ReceiverValue receiverParameter = resolvedGetCall.getReceiverArgument();
|
||||
int receiverIndex = -1;
|
||||
if (receiverParameter.exists()) {
|
||||
if (receiverParameter != null) {
|
||||
Type type = codegen.typeMapper.mapType(receiverParameter.getType());
|
||||
int sz = type.getSize();
|
||||
frame.enterTemp(type);
|
||||
@@ -700,9 +700,8 @@ public abstract class StackValue {
|
||||
v.store((receiverIndex = lastIndex) - sz, type);
|
||||
}
|
||||
|
||||
ReceiverValue thisObject = resolvedGetCall.getThisObject();
|
||||
int thisIndex = -1;
|
||||
if (thisObject.exists()) {
|
||||
if (resolvedGetCall.getThisObject() != null) {
|
||||
frame.enterTemp(OBJECT_TYPE);
|
||||
lastIndex++;
|
||||
size++;
|
||||
@@ -733,19 +732,19 @@ public abstract class StackValue {
|
||||
}
|
||||
}
|
||||
|
||||
if (resolvedSetCall.getThisObject().exists()) {
|
||||
if (resolvedSetCall.getReceiverArgument().exists()) {
|
||||
codegen.generateFromResolvedCall(resolvedSetCall.getThisObject(), OBJECT_TYPE);
|
||||
ReceiverValue thisObject = resolvedSetCall.getThisObject();
|
||||
ReceiverValue receiverArgument = resolvedSetCall.getReceiverArgument();
|
||||
if (thisObject != null) {
|
||||
if (receiverArgument != null) {
|
||||
codegen.generateFromResolvedCall(thisObject, OBJECT_TYPE);
|
||||
}
|
||||
v.load(realReceiverIndex - realReceiverType.getSize(), realReceiverType);
|
||||
}
|
||||
else if (receiverArgument != null) {
|
||||
v.load(realReceiverIndex - realReceiverType.getSize(), realReceiverType);
|
||||
}
|
||||
else {
|
||||
if (resolvedSetCall.getReceiverArgument().exists()) {
|
||||
v.load(realReceiverIndex - realReceiverType.getSize(), realReceiverType);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
int index = firstParamIndex;
|
||||
@@ -812,14 +811,13 @@ public abstract class StackValue {
|
||||
}
|
||||
}
|
||||
|
||||
if (call.getThisObject().exists()) {
|
||||
if (call.getReceiverArgument().exists()) {
|
||||
if (call.getThisObject() != null) {
|
||||
if (call.getReceiverArgument() != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (codegen.typeMapper.mapType(call.getResultingDescriptor().getReceiverParameter().getType())
|
||||
.getSize() != 1) {
|
||||
if (codegen.typeMapper.mapType(call.getResultingDescriptor().getReceiverParameter().getType()).getSize() != 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1155,9 +1153,9 @@ public abstract class StackValue {
|
||||
|
||||
CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
|
||||
|
||||
if (thisObject.exists()) {
|
||||
if (thisObject != null) {
|
||||
if (callableMethod != null) {
|
||||
if (receiverArgument.exists()) {
|
||||
if (receiverArgument != null) {
|
||||
return callableMethod.getReceiverClass();
|
||||
}
|
||||
else {
|
||||
@@ -1166,7 +1164,7 @@ public abstract class StackValue {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (receiverArgument.exists()) {
|
||||
if (receiverArgument != null) {
|
||||
return codegen.typeMapper.mapType(descriptor.getReceiverParameter().getType());
|
||||
}
|
||||
else {
|
||||
@@ -1175,7 +1173,7 @@ public abstract class StackValue {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (receiverArgument.exists()) {
|
||||
if (receiverArgument != null) {
|
||||
if (callableMethod != null) {
|
||||
return callableMethod.getReceiverClass();
|
||||
}
|
||||
@@ -1195,8 +1193,8 @@ public abstract class StackValue {
|
||||
|
||||
ReceiverValue thisObject = resolvedCall.getThisObject();
|
||||
ReceiverValue receiverArgument = resolvedCall.getReceiverArgument();
|
||||
if (thisObject.exists()) {
|
||||
if (receiverArgument.exists()) {
|
||||
if (thisObject != null) {
|
||||
if (receiverArgument != null) {
|
||||
if (callableMethod != null) {
|
||||
codegen.generateFromResolvedCall(thisObject, callableMethod.getOwner().getAsmType());
|
||||
}
|
||||
@@ -1213,7 +1211,7 @@ public abstract class StackValue {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (putReceiverArgumentOnStack && receiverArgument.exists()) {
|
||||
if (putReceiverArgumentOnStack && receiverArgument != null) {
|
||||
genReceiver(v, receiverArgument, type, descriptor.getReceiverParameter(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
@@ -30,6 +29,8 @@ import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
@@ -62,9 +63,10 @@ public class ArrayIterator implements IntrinsicMethod {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType);
|
||||
if (containingDeclaration.equals(arrayClass)) {
|
||||
String methodSignature = "([" + jvmPrimitiveType.getJvmLetter() + ")" + jvmPrimitiveType.getIterator().getDescriptor();
|
||||
JvmClassName iterator = JvmClassName.byFqNameWithoutInnerClasses("jet." + primitiveType.getTypeName() + "Iterator");
|
||||
String methodSignature = "([" + jvmPrimitiveType.getAsmType() + ")" + iterator.getDescriptor();
|
||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
||||
return StackValue.onStack(jvmPrimitiveType.getIterator().getAsmType());
|
||||
return StackValue.onStack(iterator.getAsmType());
|
||||
}
|
||||
}
|
||||
throw new UnsupportedOperationException(containingDeclaration.toString());
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.codegen.intrinsics;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.RangeCodegenUtil;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
@@ -150,16 +151,17 @@ public class IntrinsicMethods {
|
||||
registerStaticField(getFQName(KotlinBuiltIns.getInstance().getUnit()).toSafe(), Name.identifier("VALUE"));
|
||||
|
||||
for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) {
|
||||
registerStaticField(type.getRangeClassName(), Name.identifier("EMPTY"));
|
||||
}
|
||||
FqName rangeClassFqName = RangeCodegenUtil.getRangeClassFqName(type);
|
||||
FqName progressionClassFqName = RangeCodegenUtil.getProgressionClassFqName(type);
|
||||
|
||||
for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) {
|
||||
registerRangeOrProgressionProperty(type.getRangeClassName(), Name.identifier("start"));
|
||||
registerRangeOrProgressionProperty(type.getRangeClassName(), Name.identifier("end"));
|
||||
registerStaticField(rangeClassFqName, Name.identifier("EMPTY"));
|
||||
|
||||
registerRangeOrProgressionProperty(type.getProgressionClassName(), Name.identifier("start"));
|
||||
registerRangeOrProgressionProperty(type.getProgressionClassName(), Name.identifier("end"));
|
||||
registerRangeOrProgressionProperty(type.getProgressionClassName(), Name.identifier("increment"));
|
||||
registerRangeOrProgressionProperty(rangeClassFqName, Name.identifier("start"));
|
||||
registerRangeOrProgressionProperty(rangeClassFqName, Name.identifier("end"));
|
||||
|
||||
registerRangeOrProgressionProperty(progressionClassFqName, Name.identifier("start"));
|
||||
registerRangeOrProgressionProperty(progressionClassFqName, Name.identifier("end"));
|
||||
registerRangeOrProgressionProperty(progressionClassFqName, Name.identifier("increment"));
|
||||
}
|
||||
|
||||
declareArrayMethods();
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
@@ -30,11 +29,14 @@ import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||
|
||||
public class JavaClassFunction implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(
|
||||
@@ -49,9 +51,8 @@ public class JavaClassFunction implements IntrinsicMethod {
|
||||
JetType returnType = resultingDescriptor.getReturnType();
|
||||
assert returnType != null;
|
||||
Type type = state.getTypeMapper().mapType(returnType.getArguments().get(0).getType());
|
||||
JvmPrimitiveType primitiveType = JvmPrimitiveType.getByAsmType(type);
|
||||
if (primitiveType != null) {
|
||||
v.getstatic(primitiveType.getWrapper().getAsmType().getInternalName(), "TYPE", "Ljava/lang/Class;");
|
||||
if (isPrimitive(type)) {
|
||||
v.getstatic(boxType(type).getInternalName(), "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else {
|
||||
v.aconst(type);
|
||||
|
||||
@@ -21,15 +21,17 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||
|
||||
public class JavaClassProperty implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(
|
||||
@@ -41,12 +43,12 @@ public class JavaClassProperty implements IntrinsicMethod {
|
||||
StackValue receiver,
|
||||
@NotNull GenerationState state
|
||||
) {
|
||||
JvmPrimitiveType primitiveType = JvmPrimitiveType.getByAsmType(receiver.type);
|
||||
if (primitiveType != null) {
|
||||
v.getstatic(primitiveType.getWrapper().getAsmType().getInternalName(), "TYPE", "Ljava/lang/Class;");
|
||||
Type type = receiver.type;
|
||||
if (isPrimitive(type)) {
|
||||
v.getstatic(boxType(type).getInternalName(), "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
else {
|
||||
receiver.put(receiver.type, v);
|
||||
receiver.put(type, v);
|
||||
v.invokevirtual("java/lang/Object", "getClass", "()Ljava/lang/Class;");
|
||||
}
|
||||
return StackValue.onStack(AsmTypeConstants.getType(Class.class));
|
||||
|
||||
@@ -25,14 +25,14 @@ import org.jetbrains.jet.codegen.PropertyCodegen;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
||||
|
||||
public class PropertyOfProgressionOrRange implements IntrinsicMethod {
|
||||
private final FqName ownerClass;
|
||||
private final Name propertyName;
|
||||
@@ -53,12 +53,12 @@ public class PropertyOfProgressionOrRange implements IntrinsicMethod {
|
||||
@NotNull GenerationState state
|
||||
) {
|
||||
String ownerInternalName = JvmClassName.byFqNameWithoutInnerClasses(this.ownerClass).getInternalName();
|
||||
JvmClassName wrapperClass = JvmPrimitiveType.getByAsmType(expectedType).getWrapper();
|
||||
Type boxedType = boxType(expectedType);
|
||||
String getterName = PropertyCodegen.getterName(propertyName);
|
||||
|
||||
receiver.put(receiver.type, v);
|
||||
v.invokevirtual(ownerInternalName, getterName, "()" + wrapperClass.getDescriptor());
|
||||
StackValue.coerce(wrapperClass.getAsmType(), expectedType, v);
|
||||
v.invokevirtual(ownerInternalName, getterName, "()" + boxedType.getDescriptor());
|
||||
StackValue.coerce(boxedType, expectedType, v);
|
||||
return StackValue.onStack(expectedType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.codegen.state;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -132,10 +133,9 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
@NotNull DeclarationDescriptor descriptor,
|
||||
boolean insideModule
|
||||
) {
|
||||
|
||||
StringBuilder r = new StringBuilder();
|
||||
|
||||
List<DeclarationDescriptor> path = DescriptorUtils.getPathWithoutRootNsAndModule(namespace);
|
||||
List<DeclarationDescriptor> path = getPathWithoutRootNsAndModule(namespace);
|
||||
|
||||
for (DeclarationDescriptor pathElement : path) {
|
||||
NamespaceDescriptor ns = (NamespaceDescriptor) pathElement;
|
||||
@@ -173,6 +173,20 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
return JvmClassName.byInternalName(r.toString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<DeclarationDescriptor> getPathWithoutRootNsAndModule(@NotNull NamespaceDescriptor descriptor) {
|
||||
List<DeclarationDescriptor> path = new ArrayList<DeclarationDescriptor>();
|
||||
DeclarationDescriptor current = descriptor;
|
||||
while (true) {
|
||||
if (current instanceof NamespaceDescriptor && DescriptorUtils.isRootNamespace((NamespaceDescriptor) current)) {
|
||||
return Lists.reverse(path);
|
||||
}
|
||||
path.add(current);
|
||||
assert current != null : "Namespace must have a parent: " + descriptor;
|
||||
current = current.getContainingDeclaration();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type mapReturnType(@NotNull JetType jetType) {
|
||||
return mapReturnType(jetType, null);
|
||||
|
||||
@@ -21,12 +21,10 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaClassFinderImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedExternalSignatureResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedJavaResolverCache;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.FakeOverrideVisibilityResolverImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedErrorReporter;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedMethodSignatureChecker;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedExternalAnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.PsiClassFinderImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.vfilefinder.VirtualFileFinder;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationArgumentResolver;
|
||||
@@ -53,12 +51,10 @@ public class InjectorForJavaDescriptorResolver {
|
||||
private final JavaClassFinderImpl javaClassFinder;
|
||||
private final TraceBasedExternalSignatureResolver traceBasedExternalSignatureResolver;
|
||||
private final TraceBasedJavaResolverCache traceBasedJavaResolverCache;
|
||||
private final FakeOverrideVisibilityResolverImpl fakeOverrideVisibilityResolver;
|
||||
private final TraceBasedErrorReporter traceBasedErrorReporter;
|
||||
private final PsiBasedMethodSignatureChecker psiBasedMethodSignatureChecker;
|
||||
private final PsiBasedExternalAnnotationResolver psiBasedExternalAnnotationResolver;
|
||||
private final JavaDescriptorResolver javaDescriptorResolver;
|
||||
private final PsiClassFinderImpl psiClassFinder;
|
||||
private final VirtualFileFinder virtualFileFinder;
|
||||
private final JavaAnnotationResolver javaAnnotationResolver;
|
||||
private final JavaAnnotationArgumentResolver javaAnnotationArgumentResolver;
|
||||
@@ -84,12 +80,10 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.javaClassFinder = new JavaClassFinderImpl();
|
||||
this.traceBasedExternalSignatureResolver = new TraceBasedExternalSignatureResolver();
|
||||
this.traceBasedJavaResolverCache = new TraceBasedJavaResolverCache();
|
||||
this.fakeOverrideVisibilityResolver = new FakeOverrideVisibilityResolverImpl();
|
||||
this.traceBasedErrorReporter = new TraceBasedErrorReporter();
|
||||
this.psiBasedMethodSignatureChecker = new PsiBasedMethodSignatureChecker();
|
||||
this.psiBasedExternalAnnotationResolver = new PsiBasedExternalAnnotationResolver();
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver();
|
||||
this.psiClassFinder = new PsiClassFinderImpl();
|
||||
this.virtualFileFinder = com.intellij.openapi.components.ServiceManager.getService(project, VirtualFileFinder.class);
|
||||
this.javaAnnotationResolver = new JavaAnnotationResolver();
|
||||
this.javaAnnotationArgumentResolver = new JavaAnnotationArgumentResolver();
|
||||
@@ -106,15 +100,13 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.javaPropertyResolver = new JavaPropertyResolver();
|
||||
this.javaSupertypeResolver = new JavaSupertypeResolver();
|
||||
|
||||
javaClassFinder.setPsiClassFinder(psiClassFinder);
|
||||
this.javaClassFinder.setProject(project);
|
||||
|
||||
traceBasedExternalSignatureResolver.setAnnotationResolver(javaAnnotationResolver);
|
||||
traceBasedExternalSignatureResolver.setTrace(bindingTrace);
|
||||
|
||||
traceBasedJavaResolverCache.setTrace(bindingTrace);
|
||||
|
||||
fakeOverrideVisibilityResolver.setTrace(bindingTrace);
|
||||
|
||||
traceBasedErrorReporter.setTrace(bindingTrace);
|
||||
|
||||
psiBasedMethodSignatureChecker.setAnnotationResolver(javaAnnotationResolver);
|
||||
@@ -123,8 +115,6 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.javaDescriptorResolver.setClassResolver(javaClassResolver);
|
||||
this.javaDescriptorResolver.setNamespaceResolver(javaNamespaceResolver);
|
||||
|
||||
this.psiClassFinder.setProject(project);
|
||||
|
||||
javaAnnotationResolver.setArgumentResolver(javaAnnotationArgumentResolver);
|
||||
javaAnnotationResolver.setClassResolver(javaClassResolver);
|
||||
javaAnnotationResolver.setExternalAnnotationResolver(psiBasedExternalAnnotationResolver);
|
||||
@@ -176,8 +166,8 @@ public class InjectorForJavaDescriptorResolver {
|
||||
|
||||
javaFunctionResolver.setAnnotationResolver(javaAnnotationResolver);
|
||||
javaFunctionResolver.setCache(traceBasedJavaResolverCache);
|
||||
javaFunctionResolver.setErrorReporter(traceBasedErrorReporter);
|
||||
javaFunctionResolver.setExternalSignatureResolver(traceBasedExternalSignatureResolver);
|
||||
javaFunctionResolver.setFakeOverrideVisibilityResolver(fakeOverrideVisibilityResolver);
|
||||
javaFunctionResolver.setSignatureChecker(psiBasedMethodSignatureChecker);
|
||||
javaFunctionResolver.setTypeParameterResolver(javaTypeParameterResolver);
|
||||
javaFunctionResolver.setTypeTransformer(javaTypeTransformer);
|
||||
@@ -187,14 +177,14 @@ public class InjectorForJavaDescriptorResolver {
|
||||
|
||||
javaPropertyResolver.setAnnotationResolver(javaAnnotationResolver);
|
||||
javaPropertyResolver.setCache(traceBasedJavaResolverCache);
|
||||
javaPropertyResolver.setErrorReporter(traceBasedErrorReporter);
|
||||
javaPropertyResolver.setExternalSignatureResolver(traceBasedExternalSignatureResolver);
|
||||
javaPropertyResolver.setFakeOverrideVisibilityResolver(fakeOverrideVisibilityResolver);
|
||||
javaPropertyResolver.setTypeTransformer(javaTypeTransformer);
|
||||
|
||||
javaSupertypeResolver.setClassResolver(javaClassResolver);
|
||||
javaSupertypeResolver.setTypeTransformer(javaTypeTransformer);
|
||||
|
||||
psiClassFinder.initialize();
|
||||
javaClassFinder.initialize();
|
||||
|
||||
}
|
||||
|
||||
@@ -202,12 +192,12 @@ public class InjectorForJavaDescriptorResolver {
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public JavaClassFinderImpl getJavaClassFinder() {
|
||||
return this.javaClassFinder;
|
||||
}
|
||||
|
||||
public JavaDescriptorResolver getJavaDescriptorResolver() {
|
||||
return this.javaDescriptorResolver;
|
||||
}
|
||||
|
||||
public PsiClassFinderImpl getPsiClassFinder() {
|
||||
return this.psiClassFinder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,12 +29,10 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.PsiClassFinderImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaClassFinderImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedExternalSignatureResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedJavaResolverCache;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.FakeOverrideVisibilityResolverImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedErrorReporter;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedMethodSignatureChecker;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedExternalAnnotationResolver;
|
||||
@@ -89,12 +87,10 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
private final ModuleDescriptorImpl moduleDescriptor;
|
||||
private final JavaBridgeConfiguration javaBridgeConfiguration;
|
||||
private final JavaDescriptorResolver javaDescriptorResolver;
|
||||
private final PsiClassFinderImpl psiClassFinder;
|
||||
private final JavaToKotlinClassMap javaToKotlinClassMap;
|
||||
private final JavaClassFinderImpl javaClassFinder;
|
||||
private final TraceBasedExternalSignatureResolver traceBasedExternalSignatureResolver;
|
||||
private final TraceBasedJavaResolverCache traceBasedJavaResolverCache;
|
||||
private final FakeOverrideVisibilityResolverImpl fakeOverrideVisibilityResolver;
|
||||
private final TraceBasedErrorReporter traceBasedErrorReporter;
|
||||
private final PsiBasedMethodSignatureChecker psiBasedMethodSignatureChecker;
|
||||
private final PsiBasedExternalAnnotationResolver psiBasedExternalAnnotationResolver;
|
||||
@@ -150,12 +146,10 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
this.javaBridgeConfiguration = new JavaBridgeConfiguration();
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver();
|
||||
this.psiClassFinder = new PsiClassFinderImpl();
|
||||
this.javaToKotlinClassMap = org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap.getInstance();
|
||||
this.javaClassFinder = new JavaClassFinderImpl();
|
||||
this.traceBasedExternalSignatureResolver = new TraceBasedExternalSignatureResolver();
|
||||
this.traceBasedJavaResolverCache = new TraceBasedJavaResolverCache();
|
||||
this.fakeOverrideVisibilityResolver = new FakeOverrideVisibilityResolverImpl();
|
||||
this.traceBasedErrorReporter = new TraceBasedErrorReporter();
|
||||
this.psiBasedMethodSignatureChecker = new PsiBasedMethodSignatureChecker();
|
||||
this.psiBasedExternalAnnotationResolver = new PsiBasedExternalAnnotationResolver();
|
||||
@@ -230,17 +224,13 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
javaDescriptorResolver.setClassResolver(javaClassResolver);
|
||||
javaDescriptorResolver.setNamespaceResolver(javaNamespaceResolver);
|
||||
|
||||
psiClassFinder.setProject(project);
|
||||
|
||||
javaClassFinder.setPsiClassFinder(psiClassFinder);
|
||||
javaClassFinder.setProject(project);
|
||||
|
||||
traceBasedExternalSignatureResolver.setAnnotationResolver(javaAnnotationResolver);
|
||||
traceBasedExternalSignatureResolver.setTrace(bindingTrace);
|
||||
|
||||
traceBasedJavaResolverCache.setTrace(bindingTrace);
|
||||
|
||||
fakeOverrideVisibilityResolver.setTrace(bindingTrace);
|
||||
|
||||
traceBasedErrorReporter.setTrace(bindingTrace);
|
||||
|
||||
psiBasedMethodSignatureChecker.setAnnotationResolver(javaAnnotationResolver);
|
||||
@@ -367,8 +357,8 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
|
||||
javaFunctionResolver.setAnnotationResolver(javaAnnotationResolver);
|
||||
javaFunctionResolver.setCache(traceBasedJavaResolverCache);
|
||||
javaFunctionResolver.setErrorReporter(traceBasedErrorReporter);
|
||||
javaFunctionResolver.setExternalSignatureResolver(traceBasedExternalSignatureResolver);
|
||||
javaFunctionResolver.setFakeOverrideVisibilityResolver(fakeOverrideVisibilityResolver);
|
||||
javaFunctionResolver.setSignatureChecker(psiBasedMethodSignatureChecker);
|
||||
javaFunctionResolver.setTypeParameterResolver(javaTypeParameterResolver);
|
||||
javaFunctionResolver.setTypeTransformer(javaTypeTransformer);
|
||||
@@ -378,14 +368,14 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
|
||||
javaPropertyResolver.setAnnotationResolver(javaAnnotationResolver);
|
||||
javaPropertyResolver.setCache(traceBasedJavaResolverCache);
|
||||
javaPropertyResolver.setErrorReporter(traceBasedErrorReporter);
|
||||
javaPropertyResolver.setExternalSignatureResolver(traceBasedExternalSignatureResolver);
|
||||
javaPropertyResolver.setFakeOverrideVisibilityResolver(fakeOverrideVisibilityResolver);
|
||||
javaPropertyResolver.setTypeTransformer(javaTypeTransformer);
|
||||
|
||||
javaSupertypeResolver.setClassResolver(javaClassResolver);
|
||||
javaSupertypeResolver.setTypeTransformer(javaTypeTransformer);
|
||||
|
||||
psiClassFinder.initialize();
|
||||
javaClassFinder.initialize();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.FileBasedDeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.LockBasedLazyResolveStorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -81,33 +81,41 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
public ResolveSession getLazyResolveSession(@NotNull Project fileProject, @NotNull Collection<JetFile> files) {
|
||||
BindingTraceContext javaResolverTrace = new BindingTraceContext();
|
||||
InjectorForJavaDescriptorResolver injector = new InjectorForJavaDescriptorResolver(fileProject, javaResolverTrace);
|
||||
return createLazyResolveSession(fileProject, files, javaResolverTrace, injector, true);
|
||||
}
|
||||
|
||||
final PsiClassFinder psiClassFinder = injector.getPsiClassFinder();
|
||||
@NotNull
|
||||
public static ResolveSession createLazyResolveSession(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull InjectorForJavaDescriptorResolver injector,
|
||||
final boolean addBuiltIns
|
||||
) {
|
||||
final JavaClassFinderImpl classFinder = injector.getJavaClassFinder();
|
||||
|
||||
// TODO: Replace with stub declaration provider
|
||||
LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
LockBasedLazyResolveStorageManager storageManager = new LockBasedLazyResolveStorageManager();
|
||||
FileBasedDeclarationProviderFactory declarationProviderFactory = new FileBasedDeclarationProviderFactory(storageManager, files, new Predicate<FqName>() {
|
||||
@Override
|
||||
public boolean apply(FqName fqName) {
|
||||
return psiClassFinder.findPsiPackage(fqName) != null || new FqName("jet").equals(fqName);
|
||||
return classFinder.findPackage(fqName) != null || KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.equals(fqName);
|
||||
}
|
||||
});
|
||||
|
||||
final JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
||||
|
||||
ModuleConfiguration moduleConfiguration = new ModuleConfiguration() {
|
||||
|
||||
@Override
|
||||
public void extendNamespaceScope(
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull NamespaceDescriptor namespaceDescriptor,
|
||||
@NotNull WritableScope namespaceMemberScope
|
||||
) {
|
||||
FqName fqName = DescriptorUtils.getFQName(namespaceDescriptor).toSafe();
|
||||
if (new FqName("jet").equals(fqName)) {
|
||||
if (KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.equals(fqName) && addBuiltIns) {
|
||||
namespaceMemberScope.importScope(KotlinBuiltIns.getInstance().getBuiltInsScope());
|
||||
}
|
||||
if (psiClassFinder.findPsiPackage(fqName) != null) {
|
||||
if (classFinder.findPackage(fqName) != null) {
|
||||
JetScope javaPackageScope = javaDescriptorResolver.getJavaPackageScope(namespaceDescriptor);
|
||||
assert javaPackageScope != null;
|
||||
namespaceMemberScope.importScope(javaPackageScope);
|
||||
@@ -118,7 +126,7 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
ModuleDescriptorImpl lazyModule = createJavaModule("<lazy module>");
|
||||
lazyModule.setModuleConfiguration(moduleConfiguration);
|
||||
|
||||
return new ResolveSession(fileProject, storageManager, lazyModule, declarationProviderFactory, javaResolverTrace);
|
||||
return new ResolveSession(project, storageManager, lazyModule, declarationProviderFactory, trace);
|
||||
}
|
||||
|
||||
public static AnalyzeExhaust analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
||||
@@ -145,9 +153,9 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
Predicate<PsiFile> filesToAnalyzeCompletely
|
||||
) {
|
||||
for (JetFile file : files) {
|
||||
AnalyzingUtils.checkForSyntacticErrors(file);
|
||||
AnalyzingUtils.checkForSyntacticErrors(file);
|
||||
}
|
||||
|
||||
|
||||
AnalyzeExhaust analyzeExhaust = analyzeFilesWithJavaIntegration(
|
||||
project, files, scriptParameters, filesToAnalyzeCompletely, false);
|
||||
|
||||
|
||||
@@ -16,8 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
|
||||
@@ -25,28 +30,74 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaPackage;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaClassImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaPackageImpl;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class JavaClassFinderImpl implements JavaClassFinder {
|
||||
private PsiClassFinder psiClassFinder;
|
||||
@NotNull
|
||||
private Project project;
|
||||
|
||||
private GlobalSearchScope javaSearchScope;
|
||||
private JavaPsiFacadeKotlinHacks javaFacade;
|
||||
|
||||
@Inject
|
||||
public void setPsiClassFinder(@NotNull PsiClassFinder psiClassFinder) {
|
||||
this.psiClassFinder = psiClassFinder;
|
||||
public void setProject(@NotNull Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
javaSearchScope = new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
|
||||
@Override
|
||||
public boolean contains(VirtualFile file) {
|
||||
return myBaseScope.contains(file) && file.getFileType() != JetFileType.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(VirtualFile file1, VirtualFile file2) {
|
||||
// TODO: this is a hackish workaround for the following problem:
|
||||
// since we are working with the allScope(), if the same class FqName
|
||||
// to be on the class path twice, because it is included into different libraries
|
||||
// (e.g. junit-4.0.jar is used as a separate library and as a part of idea_full)
|
||||
// the two libraries are attached to different modules, the parent compare()
|
||||
// can't tell which one comes first, so they can come in random order
|
||||
// To fix this, we sort additionally by the full path, to make the ordering deterministic
|
||||
// TODO: Delete this hack when proper scopes are used
|
||||
int compare = super.compare(file1, file2);
|
||||
if (compare == 0) {
|
||||
return Comparing.compare(file1.getPath(), file2.getPath());
|
||||
}
|
||||
return compare;
|
||||
}
|
||||
};
|
||||
javaFacade = new JavaPsiFacadeKotlinHacks(project);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JavaClass findClass(@NotNull FqName fqName) {
|
||||
PsiClass psiClass = psiClassFinder.findPsiClass(fqName);
|
||||
return psiClass == null ? null : new JavaClassImpl(psiClass);
|
||||
PsiClass psiClass = javaFacade.findClass(fqName.asString(), javaSearchScope);
|
||||
if (psiClass == null) return null;
|
||||
|
||||
JavaClassImpl javaClass = new JavaClassImpl(psiClass);
|
||||
|
||||
if (!fqName.equals(javaClass.getFqName())) {
|
||||
throw new IllegalStateException("Requested " + fqName + ", got " + javaClass.getFqName());
|
||||
}
|
||||
|
||||
if (javaClass.getOriginKind() == JavaClass.OriginKind.KOTLIN_LIGHT_CLASS) {
|
||||
throw new IllegalStateException("Kotlin light classes should not be found by JavaPsiFacade, resolving: " + fqName);
|
||||
}
|
||||
|
||||
return javaClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JavaPackage findPackage(@NotNull FqName fqName) {
|
||||
PsiPackage psiPackage = psiClassFinder.findPsiPackage(fqName);
|
||||
PsiPackage psiPackage = javaFacade.findPackage(fqName.asString());
|
||||
return psiPackage == null ? null : new JavaPackageImpl(psiPackage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.jetAsJava.JetJavaMirrorMarker;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class PsiClassFinderImpl implements PsiClassFinder {
|
||||
@NotNull
|
||||
private Project project;
|
||||
|
||||
private GlobalSearchScope javaSearchScope;
|
||||
private JavaPsiFacadeKotlinHacks javaFacade;
|
||||
|
||||
@Inject
|
||||
public void setProject(@NotNull Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
javaSearchScope = new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
|
||||
@Override
|
||||
public boolean contains(VirtualFile file) {
|
||||
return myBaseScope.contains(file) && file.getFileType() != JetFileType.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(VirtualFile file1, VirtualFile file2) {
|
||||
// TODO: this is a hackish workaround for the following problem:
|
||||
// since we are working with the allScope(), if the same class FqName
|
||||
// to be on the class path twice, because it is included into different libraries
|
||||
// (e.g. junit-4.0.jar is used as a separate library and as a part of idea_full)
|
||||
// the two libraries are attached to different modules, the parent compare()
|
||||
// can't tell which one comes first, so they can come in random order
|
||||
// To fix this, we sort additionally by the full path, to make the ordering deterministic
|
||||
// TODO: Delete this hack when proper scopes are used
|
||||
int compare = super.compare(file1, file2);
|
||||
if (compare == 0) {
|
||||
return Comparing.compare(file1.getPath(), file2.getPath());
|
||||
}
|
||||
return compare;
|
||||
}
|
||||
};
|
||||
javaFacade = new JavaPsiFacadeKotlinHacks(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiClass findPsiClass(@NotNull FqName qualifiedName) {
|
||||
PsiClass original = javaFacade.findClass(qualifiedName.asString(), javaSearchScope);
|
||||
|
||||
if (original != null) {
|
||||
String classQualifiedName = original.getQualifiedName();
|
||||
FqName actualQualifiedName = classQualifiedName != null ? new FqName(classQualifiedName) : null;
|
||||
if (!qualifiedName.equals(actualQualifiedName)) {
|
||||
throw new IllegalStateException("requested " + qualifiedName + ", got " + actualQualifiedName);
|
||||
}
|
||||
}
|
||||
|
||||
if (original instanceof JetJavaMirrorMarker) {
|
||||
throw new IllegalStateException("JetJavaMirrorMaker is not possible in resolve.java, resolving: " + qualifiedName);
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiPackage findPsiPackage(@NotNull FqName qualifiedName) {
|
||||
return javaFacade.findPackage(qualifiedName.asString());
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -52,15 +53,16 @@ public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
|
||||
}
|
||||
|
||||
private void initPrimitives() {
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
FqName className = jvmPrimitiveType.getPrimitiveType().getClassName();
|
||||
|
||||
register(className, jvmPrimitiveType.getAsmType());
|
||||
registerNullable(className, jvmPrimitiveType.getWrapper().getAsmType());
|
||||
}
|
||||
FqName builtInsFqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME;
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
register(primitiveType.getArrayClassName(), jvmPrimitiveType.getAsmArrayType());
|
||||
Type asmType = jvmPrimitiveType.getAsmType();
|
||||
FqName fqName = builtInsFqName.child(primitiveType.getTypeName());
|
||||
|
||||
register(fqName, asmType);
|
||||
registerNullable(fqName, jvmPrimitiveType.getWrapper().getAsmType());
|
||||
|
||||
register(builtInsFqName.child(primitiveType.getArrayTypeName()), Type.getType("[" + asmType.getDescriptor()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.resolver;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class FakeOverrideVisibilityResolverImpl implements FakeOverrideVisibilityResolver {
|
||||
private BindingTrace trace;
|
||||
|
||||
@Inject
|
||||
public void setTrace(BindingTrace trace) {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resolveUnknownVisibilityForMember(@NotNull CallableMemberDescriptor descriptor) {
|
||||
OverrideResolver.resolveUnknownVisibilityForMember(null, descriptor, trace);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,11 @@
|
||||
package org.jetbrains.jet.lang.resolve.java.resolver;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.util.slicedmap.BasicWritableSlice;
|
||||
@@ -26,6 +30,8 @@ import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.CANNOT_INFER_VISIBILITY;
|
||||
|
||||
public class TraceBasedErrorReporter implements ErrorReporter {
|
||||
public static final WritableSlice<AbiVersionErrorLocation, Integer> ABI_VERSION_ERRORS =
|
||||
new BasicWritableSlice<AbiVersionErrorLocation, Integer>(Slices.ONLY_REWRITE_TO_EQUAL, true);
|
||||
@@ -41,6 +47,14 @@ public class TraceBasedErrorReporter implements ErrorReporter {
|
||||
trace.record(ABI_VERSION_ERRORS, new AbiVersionErrorLocation(fqName, file), actualVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportCannotInferVisibility(@NotNull CallableMemberDescriptor descriptor) {
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor);
|
||||
if (element instanceof JetDeclaration) {
|
||||
trace.report(CANNOT_INFER_VISIBILITY.on((JetDeclaration) element));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class AbiVersionErrorLocation {
|
||||
@NotNull
|
||||
private final FqName classFqName;
|
||||
|
||||
@@ -9,12 +9,10 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="protobuf-java" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="junit" level="project" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="library" name="annotations" level="project" />
|
||||
<orderEntry type="library" name="trove4j" level="project" />
|
||||
<orderEntry type="library" name="intellij-core" level="project" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.descriptors.serialization;
|
||||
|
||||
import com.google.protobuf.ExtensionRegistryLite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -34,7 +33,7 @@ public final class ClassData {
|
||||
return new ClassData(nameResolver, classProto);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +65,7 @@ public final class ClassData {
|
||||
return result.toByteArray();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.jet.descriptors.serialization.descriptors.DeserializedTypeP
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.DefaultDescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
@@ -162,7 +162,7 @@ public class DescriptorDeserializer {
|
||||
);
|
||||
}
|
||||
else {
|
||||
getter = DescriptorResolver.createDefaultGetter(property);
|
||||
getter = DefaultDescriptorFactory.createDefaultGetter(property);
|
||||
}
|
||||
getter.initialize(property.getReturnType());
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public class DescriptorDeserializer {
|
||||
property.getReturnType(), false, null));
|
||||
}
|
||||
else {
|
||||
setter = DescriptorResolver.createDefaultSetter(property);
|
||||
setter = DefaultDescriptorFactory.createDefaultSetter(property);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.jet.descriptors.serialization;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -35,7 +34,7 @@ public class NameSerializationUtil {
|
||||
return new NameResolver(simpleNames, qualifiedNames);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +56,7 @@ public class NameSerializationUtil {
|
||||
qualifiedNameTable.writeDelimitedTo(out);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.descriptors.serialization;
|
||||
|
||||
import com.google.protobuf.ExtensionRegistryLite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -34,7 +33,7 @@ public final class PackageData {
|
||||
return new PackageData(nameResolver, packageProto);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +65,7 @@ public final class PackageData {
|
||||
return result.toByteArray();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ public class TypeDeserializer {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return TypeUtils.toString(this);
|
||||
return JetTypeUtil.toString(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,8 @@ import org.jetbrains.jet.descriptors.serialization.*;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.DefaultDescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.MemoizedFunctionToNullable;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.NotNullLazyValue;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.NullableLazyValue;
|
||||
@@ -36,6 +37,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -282,14 +284,16 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
|
||||
classObject.setTypeParameterDescriptors(Collections.<TypeParameterDescriptor>emptyList());
|
||||
classObject.createTypeConstructor();
|
||||
|
||||
// TODO: do something if trace has errors?
|
||||
BindingTrace trace = new BindingTraceContext();
|
||||
ConstructorDescriptorImpl primaryConstructor = DescriptorResolver.createPrimaryConstructorForObject(classObject);
|
||||
ConstructorDescriptorImpl primaryConstructor = DefaultDescriptorFactory.createPrimaryConstructorForObject(classObject);
|
||||
primaryConstructor.setReturnType(classObject.getDefaultType());
|
||||
classObject.setPrimaryConstructor(primaryConstructor, trace);
|
||||
classObject.setPrimaryConstructor(primaryConstructor);
|
||||
|
||||
classObject.getBuilder().addFunctionDescriptor(DescriptorResolver.createEnumClassObjectValuesMethod(classObject, trace));
|
||||
classObject.getBuilder().addFunctionDescriptor(DescriptorResolver.createEnumClassObjectValueOfMethod(classObject, trace));
|
||||
JetType defaultType = getDefaultType();
|
||||
JetType defaultTypeArray = KotlinBuiltIns.getInstance().getArrayType(defaultType);
|
||||
classObject.getBuilder().addFunctionDescriptor(
|
||||
DefaultDescriptorFactory.createEnumClassObjectValuesMethod(classObject, defaultTypeArray));
|
||||
classObject.getBuilder().addFunctionDescriptor(
|
||||
DefaultDescriptorFactory.createEnumClassObjectValueOfMethod(classObject, defaultType));
|
||||
|
||||
return classObject;
|
||||
}
|
||||
@@ -301,7 +305,7 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
|
||||
property.setType(getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(),
|
||||
enumClassObject.getThisAsReceiverParameter(), NO_RECEIVER_PARAMETER);
|
||||
|
||||
PropertyGetterDescriptorImpl getter = DescriptorResolver.createDefaultGetter(property);
|
||||
PropertyGetterDescriptorImpl getter = DefaultDescriptorFactory.createDefaultGetter(property);
|
||||
getter.initialize(property.getReturnType());
|
||||
property.initialize(getter, null);
|
||||
|
||||
@@ -417,15 +421,21 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
|
||||
@NotNull final Collection<D> result
|
||||
) {
|
||||
List<CallableMemberDescriptor> fromCurrent = new ArrayList<CallableMemberDescriptor>(result);
|
||||
OverrideResolver.generateOverridesInFunctionGroup(
|
||||
OverridingUtil.generateOverridesInFunctionGroup(
|
||||
name,
|
||||
fromSupertypes,
|
||||
fromCurrent,
|
||||
classDescriptor,
|
||||
new OverrideResolver.DescriptorSink() {
|
||||
new OverridingUtil.DescriptorSink() {
|
||||
@Override
|
||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||
OverrideResolver.resolveUnknownVisibilityForMember(null, fakeOverride, TraceUtil.TRACE_STUB);
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, new OverridingUtil.NotInferredVisibilitySink() {
|
||||
@Override
|
||||
public void cannotInferVisibility(@NotNull CallableMemberDescriptor descriptor) {
|
||||
// Do nothing
|
||||
// TODO: do something
|
||||
}
|
||||
});
|
||||
//noinspection unchecked
|
||||
result.add((D) fakeOverride);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
@@ -39,7 +38,7 @@ public class DefaultModuleConfiguration implements ModuleConfiguration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
public void extendNamespaceScope(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
if (DescriptorUtils.getFQName(namespaceDescriptor).equalsTo(KotlinBuiltIns.getInstance().getBuiltInsPackageFqName())) {
|
||||
namespaceMemberScope.importScope(KotlinBuiltIns.getInstance().getBuiltInsScope());
|
||||
}
|
||||
|
||||
@@ -18,14 +18,12 @@ package org.jetbrains.jet.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
public interface ModuleConfiguration {
|
||||
ModuleConfiguration EMPTY = new ModuleConfiguration() {
|
||||
|
||||
@Override
|
||||
public void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
public void extendNamespaceScope(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,5 +36,5 @@ public interface ModuleConfiguration {
|
||||
* This method is called every time a namespace descriptor is created. Use it to add extra descriptors to the namespace, e.g. merge a
|
||||
* Java package with a Kotlin one
|
||||
*/
|
||||
void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope);
|
||||
void extendNamespaceScope(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope);
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
public interface Annotation {
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import javax.inject.Inject;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleDescriptorImpl extends DeclarationDescriptorImpl implements ClassOrNamespaceDescriptor, ModuleDescriptor {
|
||||
public class ModuleDescriptorImpl extends DeclarationDescriptorImpl implements ModuleDescriptor {
|
||||
private NamespaceDescriptor rootNamepsace;
|
||||
private ModuleConfiguration moduleConfiguration;
|
||||
private final List<ImportPath> defaultImports;
|
||||
@@ -58,8 +58,8 @@ public class ModuleDescriptorImpl extends DeclarationDescriptorImpl implements C
|
||||
this.rootNamepsace = rootNs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public interface MutableValueParameterDescriptor extends ValueParameterDescriptor {
|
||||
void setType(@NotNull JetType type);
|
||||
}
|
||||
@@ -17,14 +17,18 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorParent;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
|
||||
public interface NamespaceDescriptor extends Annotated, Named, FqNamed, ClassOrNamespaceDescriptor, NamespaceDescriptorParent {
|
||||
public interface NamespaceDescriptor extends ClassOrNamespaceDescriptor, NamespaceDescriptorParent {
|
||||
@NotNull
|
||||
JetScope getMemberScope();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
NamespaceDescriptorParent getContainingDeclaration();
|
||||
|
||||
@NotNull
|
||||
FqName getFqName();
|
||||
}
|
||||
|
||||
@@ -17,14 +17,9 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.DefaultDescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
@@ -40,6 +35,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
public static final String LAST_EXPRESSION_VALUE_FIELD_NAME = "rv";
|
||||
private static final Name NAME = Name.special("<script>");
|
||||
|
||||
private final int priority;
|
||||
@@ -59,17 +55,20 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
|
||||
private final WritableScopeImpl classScope;
|
||||
|
||||
public ScriptDescriptor(@Nullable DeclarationDescriptor containingDeclaration, int priority, JetScript script, JetScope scriptScope) {
|
||||
public ScriptDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
int priority,
|
||||
@NotNull JetScope scriptScope,
|
||||
@NotNull Name className
|
||||
) {
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), NAME);
|
||||
this.priority = priority;
|
||||
|
||||
String className = ScriptNameUtil.classNameForScript((JetFile) script.getContainingFile()).replace('/','.');
|
||||
|
||||
classDescriptor = new ClassDescriptorImpl(
|
||||
containingDeclaration,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Modality.FINAL,
|
||||
new FqName(className).shortName());
|
||||
className);
|
||||
classScope = new WritableScopeImpl(scriptScope, containingDeclaration, RedeclarationHandler.DO_NOTHING, "script members");
|
||||
classScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
classDescriptor.initialize(
|
||||
@@ -82,7 +81,11 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
false);
|
||||
}
|
||||
|
||||
public void initialize(@NotNull JetType returnType, JetScript declaration, BindingContext bindingContext) {
|
||||
public void initialize(
|
||||
@NotNull JetType returnType,
|
||||
@NotNull List<? extends PropertyDescriptorImpl> properties,
|
||||
@NotNull List<? extends FunctionDescriptor> functions
|
||||
) {
|
||||
this.returnType = returnType;
|
||||
scriptCodeDescriptor.initialize(implicitReceiver, valueParameters, returnType);
|
||||
|
||||
@@ -91,7 +94,7 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
false,
|
||||
Name.identifier(ScriptNameUtil.LAST_EXPRESSION_VALUE_FIELD_NAME),
|
||||
Name.identifier(LAST_EXPRESSION_VALUE_FIELD_NAME),
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(
|
||||
returnType,
|
||||
@@ -101,34 +104,26 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
propertyDescriptor.initialize(null, null);
|
||||
classScope.addPropertyDescriptor(propertyDescriptor);
|
||||
|
||||
for (JetDeclaration jetDeclaration : declaration.getDeclarations()) {
|
||||
if(jetDeclaration instanceof JetProperty) {
|
||||
VariableDescriptor descriptor = bindingContext.get(BindingContext.VARIABLE, jetDeclaration);
|
||||
assert descriptor != null;
|
||||
initializeWithDefaultGetterSetter((PropertyDescriptorImpl) descriptor);
|
||||
classScope.addPropertyDescriptor(descriptor);
|
||||
}
|
||||
else if(jetDeclaration instanceof JetNamedFunction) {
|
||||
SimpleFunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, jetDeclaration);
|
||||
assert descriptor != null;
|
||||
SimpleFunctionDescriptor copy =
|
||||
descriptor.copy(classDescriptor, descriptor.getModality(), descriptor.getVisibility(), CallableMemberDescriptor.Kind.DECLARATION, false);
|
||||
classScope.addFunctionDescriptor(copy);
|
||||
}
|
||||
for (PropertyDescriptorImpl property : properties) {
|
||||
initializeWithDefaultGetterSetter(property);
|
||||
classScope.addPropertyDescriptor(property);
|
||||
}
|
||||
|
||||
for (FunctionDescriptor function : functions) {
|
||||
classScope.addFunctionDescriptor(function);
|
||||
}
|
||||
}
|
||||
|
||||
public static void initializeWithDefaultGetterSetter(PropertyDescriptorImpl propertyDescriptor) {
|
||||
PropertyGetterDescriptorImpl getter = propertyDescriptor.getGetter();
|
||||
if(getter == null) {
|
||||
getter = propertyDescriptor.getVisibility() != Visibilities.PRIVATE ? DescriptorResolver.createDefaultGetter(propertyDescriptor) : null;
|
||||
if(getter != null)
|
||||
getter.initialize(propertyDescriptor.getType());
|
||||
if (getter == null && propertyDescriptor.getVisibility() != Visibilities.PRIVATE) {
|
||||
getter = DefaultDescriptorFactory.createDefaultGetter(propertyDescriptor);
|
||||
getter.initialize(propertyDescriptor.getType());
|
||||
}
|
||||
|
||||
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
|
||||
if(setter == null) {
|
||||
setter = propertyDescriptor.isVar() ? DescriptorResolver.createDefaultSetter(propertyDescriptor) : null;
|
||||
if (setter == null && propertyDescriptor.isVar()) {
|
||||
setter = DefaultDescriptorFactory.createDefaultSetter(propertyDescriptor);
|
||||
}
|
||||
propertyDescriptor.initialize(getter, setter);
|
||||
}
|
||||
@@ -196,6 +191,7 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getClassDescriptor() {
|
||||
return classDescriptor;
|
||||
}
|
||||
|
||||
@@ -18,13 +18,12 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface ValueParameterDescriptor extends VariableDescriptor, Annotated {
|
||||
public interface ValueParameterDescriptor extends VariableDescriptor {
|
||||
/**
|
||||
* Returns the 0-based index of the value parameter in the parameter list of its containing function.
|
||||
*
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.descriptors.impl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.jet.lang.descriptors.Named;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -27,7 +26,7 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements Named, DeclarationDescriptor {
|
||||
public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements DeclarationDescriptor {
|
||||
|
||||
@NotNull
|
||||
private final Name name;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
|
||||
public class ExtensionDescriptor {
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -68,7 +69,8 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
protected FunctionDescriptorImpl initialize(
|
||||
@NotNull
|
||||
public FunctionDescriptorImpl initialize(
|
||||
@Nullable JetType receiverParameterType,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@@ -209,12 +211,12 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
}
|
||||
}
|
||||
|
||||
List<ValueParameterDescriptor> substitutedValueParameters = FunctionDescriptorUtil.getSubstitutedValueParameters(substitutedDescriptor, this, substitutor);
|
||||
List<ValueParameterDescriptor> substitutedValueParameters = getSubstitutedValueParameters(substitutedDescriptor, this, substitutor);
|
||||
if (substitutedValueParameters == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JetType substitutedReturnType = FunctionDescriptorUtil.getSubstitutedReturnType(this, substitutor);
|
||||
JetType substitutedReturnType = substitutor.substitute(getReturnType(), Variance.OUT_VARIANCE);
|
||||
if (substitutedReturnType == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -242,4 +244,25 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitFunctionDescriptor(this, data);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(FunctionDescriptor substitutedDescriptor, @NotNull FunctionDescriptor functionDescriptor, @NotNull TypeSubstitutor substitutor) {
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||
List<ValueParameterDescriptor> unsubstitutedValueParameters = functionDescriptor.getValueParameters();
|
||||
for (ValueParameterDescriptor unsubstitutedValueParameter : unsubstitutedValueParameters) {
|
||||
// TODO : Lazy?
|
||||
JetType substitutedType = substitutor.substitute(unsubstitutedValueParameter.getType(), Variance.IN_VARIANCE);
|
||||
JetType varargElementType = unsubstitutedValueParameter.getVarargElementType();
|
||||
JetType substituteVarargElementType = varargElementType == null ? null : substitutor.substitute(varargElementType, Variance.IN_VARIANCE);
|
||||
if (substitutedType == null) return null;
|
||||
result.add(new ValueParameterDescriptorImpl(
|
||||
substitutedDescriptor,
|
||||
unsubstitutedValueParameter,
|
||||
unsubstitutedValueParameter.getAnnotations(),
|
||||
substitutedType,
|
||||
substituteVarargElementType
|
||||
));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,10 @@ import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -65,32 +63,26 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void addConstructor(@NotNull ConstructorDescriptor constructorDescriptor, @NotNull BindingTrace trace) {
|
||||
if (constructorDescriptor.getContainingDeclaration() != this) {
|
||||
throw new IllegalStateException("invalid containing declaration of constructor");
|
||||
}
|
||||
public void setPrimaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor) {
|
||||
assert primaryConstructor == null : "Primary constructor assigned twice " + this;
|
||||
primaryConstructor = constructorDescriptor;
|
||||
|
||||
constructors.add(constructorDescriptor);
|
||||
|
||||
if (defaultType != null) {
|
||||
((ConstructorDescriptorImpl) constructorDescriptor).setReturnType(getDefaultType());
|
||||
}
|
||||
|
||||
boolean primary = constructorDescriptor.isPrimary();
|
||||
if (primary) {
|
||||
if (constructorDescriptor.isPrimary()) {
|
||||
setUpScopeForInitializers(constructorDescriptor);
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : constructorDescriptor.getValueParameters()) {
|
||||
JetParameter parameter = (JetParameter) BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), valueParameterDescriptor);
|
||||
assert parameter != null;
|
||||
if (parameter.getValOrVarNode() == null) {
|
||||
getWritableScopeForInitializers().addVariableDescriptor(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPrimaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor, BindingTrace trace) {
|
||||
assert this.primaryConstructor == null : "Primary constructor assigned twice " + this;
|
||||
this.primaryConstructor = constructorDescriptor;
|
||||
addConstructor(constructorDescriptor, trace);
|
||||
public void addConstructorParametersToInitializersScope(@NotNull Collection<? extends VariableDescriptor> variables) {
|
||||
WritableScope scope = getWritableScopeForInitializers();
|
||||
for (VariableDescriptor variable : variables) {
|
||||
scope.addVariableDescriptor(variable);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -251,7 +251,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
|
||||
substitutedDescriptor, Lists.newArrayList(setter.getAnnotations()), DescriptorUtils.convertModality(setter.getModality(), false),
|
||||
convertVisibility(setter.getVisibility(), newVisibility), setter.hasBody(), setter.isDefault(), kind, setter.getOriginal());
|
||||
if (newSetter != null) {
|
||||
List<ValueParameterDescriptor> substitutedValueParameters = FunctionDescriptorUtil.getSubstitutedValueParameters(newSetter, setter, substitutor);
|
||||
List<ValueParameterDescriptor> substitutedValueParameters = FunctionDescriptorImpl.getSubstitutedValueParameters(newSetter, setter, substitutor);
|
||||
if (substitutedValueParameters == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ValueParameterDescriptorImpl extends VariableDescriptorImpl implements MutableValueParameterDescriptor {
|
||||
public class ValueParameterDescriptorImpl extends VariableDescriptorImpl implements ValueParameterDescriptor {
|
||||
private Boolean hasDefaultValue;
|
||||
private final boolean declaresDefaultValue;
|
||||
|
||||
@@ -72,7 +72,6 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
|
||||
this.varargElementType = varargElementType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setType(@NotNull JetType type) {
|
||||
setOutType(type);
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ public interface Call {
|
||||
@Nullable
|
||||
ASTNode getCallOperationNode();
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
ReceiverValue getExplicitReceiver();
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
ReceiverValue getThisObject();
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -24,12 +24,12 @@ import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.constants.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
@@ -341,13 +341,10 @@ public class AnnotationResolver {
|
||||
}
|
||||
|
||||
private static boolean isEnumProperty(@NotNull PropertyDescriptor descriptor) {
|
||||
if (DescriptorUtils.isKindOf(descriptor.getType(), ClassKind.ENUM_CLASS)) {
|
||||
DeclarationDescriptor enumClassObject = descriptor.getContainingDeclaration();
|
||||
if (DescriptorUtils.isKindOf(enumClassObject, ClassKind.CLASS_OBJECT)) {
|
||||
return DescriptorUtils.isKindOf(enumClassObject.getContainingDeclaration(), ClassKind.ENUM_CLASS);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
ClassifierDescriptor classifier = descriptor.getType().getConstructor().getDeclarationDescriptor();
|
||||
return classifier != null &&
|
||||
DescriptorUtils.isEnumClass(classifier) &&
|
||||
DescriptorUtils.isEnumClassObject(descriptor.getContainingDeclaration());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.util.containers.Queue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
|
||||
@@ -298,6 +298,7 @@ public class DeclarationResolver {
|
||||
List<ValueParameterDescriptor> valueParameterDescriptors = constructorDescriptor.getValueParameters();
|
||||
List<JetParameter> primaryConstructorParameters = klass.getPrimaryConstructorParameters();
|
||||
assert valueParameterDescriptors.size() == primaryConstructorParameters.size();
|
||||
List<ValueParameterDescriptor> notProperties = new ArrayList<ValueParameterDescriptor>();
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : valueParameterDescriptors) {
|
||||
JetParameter parameter = primaryConstructorParameters.get(valueParameterDescriptor.getIndex());
|
||||
if (parameter.getValOrVarNode() != null) {
|
||||
@@ -310,9 +311,14 @@ public class DeclarationResolver {
|
||||
classDescriptor.getBuilder().addPropertyDescriptor(propertyDescriptor);
|
||||
context.getPrimaryConstructorParameterProperties().put(parameter, propertyDescriptor);
|
||||
}
|
||||
else {
|
||||
notProperties.add(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
if (classDescriptor.getKind() != ClassKind.TRAIT) {
|
||||
classDescriptor.setPrimaryConstructor(constructorDescriptor, trace);
|
||||
classDescriptor.setPrimaryConstructor(constructorDescriptor);
|
||||
classDescriptor.addConstructorParametersToInitializersScope(notProperties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getDefaultConstructorVisibility;
|
||||
|
||||
public class DefaultDescriptorFactory {
|
||||
public static final Name VALUE_OF_METHOD_NAME = Name.identifier("valueOf");
|
||||
public static final Name VALUES_METHOD_NAME = Name.identifier("values");
|
||||
|
||||
private DefaultDescriptorFactory() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertySetterDescriptorImpl createDefaultSetter(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return createSetter(propertyDescriptor, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertySetterDescriptorImpl createSetter(@NotNull PropertyDescriptor propertyDescriptor, boolean isDefault) {
|
||||
PropertySetterDescriptorImpl setterDescriptor = new PropertySetterDescriptorImpl(
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
!isDefault, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
setterDescriptor.initializeDefault();
|
||||
return setterDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyGetterDescriptorImpl createDefaultGetter(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return createGetter(propertyDescriptor, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyGetterDescriptorImpl createGetter(@NotNull PropertyDescriptor propertyDescriptor, boolean isDefault) {
|
||||
return new PropertyGetterDescriptorImpl(
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
!isDefault, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConstructorDescriptorImpl createPrimaryConstructorForObject(@NotNull ClassDescriptor containingClass) {
|
||||
ConstructorDescriptorImpl constructorDescriptor =
|
||||
new ConstructorDescriptorImpl(containingClass, Collections.<AnnotationDescriptor>emptyList(), true);
|
||||
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<ValueParameterDescriptor>emptyList(),
|
||||
getDefaultConstructorVisibility(containingClass));
|
||||
return constructorDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleFunctionDescriptor createEnumClassObjectValuesMethod(
|
||||
@NotNull ClassDescriptor classObject,
|
||||
@NotNull JetType returnType
|
||||
) {
|
||||
SimpleFunctionDescriptorImpl values =
|
||||
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUES_METHOD_NAME,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
return values.initialize(null, classObject.getThisAsReceiverParameter(), Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<ValueParameterDescriptor>emptyList(),
|
||||
returnType, Modality.FINAL,
|
||||
Visibilities.PUBLIC, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleFunctionDescriptor createEnumClassObjectValueOfMethod(
|
||||
@NotNull ClassDescriptor classObject,
|
||||
@NotNull JetType returnType
|
||||
) {
|
||||
SimpleFunctionDescriptorImpl values =
|
||||
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUE_OF_METHOD_NAME,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
ValueParameterDescriptor parameterDescriptor = new ValueParameterDescriptorImpl(
|
||||
values,
|
||||
0,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Name.identifier("value"),
|
||||
KotlinBuiltIns.getInstance().getStringType(),
|
||||
false,
|
||||
null);
|
||||
return values.initialize(null, classObject.getThisAsReceiverParameter(),
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.singletonList(parameterDescriptor),
|
||||
returnType, Modality.FINAL,
|
||||
Visibilities.PUBLIC, false);
|
||||
}
|
||||
}
|
||||
@@ -59,8 +59,6 @@ import static org.jetbrains.jet.lang.resolve.ModifiersChecker.*;
|
||||
import static org.jetbrains.jet.lexer.JetTokens.OVERRIDE_KEYWORD;
|
||||
|
||||
public class DescriptorResolver {
|
||||
public static final Name VALUE_OF_METHOD_NAME = Name.identifier("valueOf");
|
||||
public static final Name VALUES_METHOD_NAME = Name.identifier("values");
|
||||
public static final Name COPY_METHOD_NAME = Name.identifier("copy");
|
||||
public static final String COMPONENT_FUNCTION_NAME_PREFIX = "component";
|
||||
|
||||
@@ -504,7 +502,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MutableValueParameterDescriptor resolveValueParameterDescriptor(
|
||||
public ValueParameterDescriptorImpl resolveValueParameterDescriptor(
|
||||
JetScope scope, DeclarationDescriptor declarationDescriptor,
|
||||
JetParameter valueParameter, int index, JetType type, BindingTrace trace
|
||||
) {
|
||||
@@ -513,7 +511,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public MutableValueParameterDescriptor resolveValueParameterDescriptorWithAnnotationArguments(
|
||||
public ValueParameterDescriptorImpl resolveValueParameterDescriptorWithAnnotationArguments(
|
||||
JetScope scope, DeclarationDescriptor declarationDescriptor,
|
||||
JetParameter valueParameter, int index, JetType type, BindingTrace trace
|
||||
) {
|
||||
@@ -522,7 +520,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private MutableValueParameterDescriptor resolveValueParameterDescriptor(
|
||||
private static ValueParameterDescriptorImpl resolveValueParameterDescriptor(
|
||||
DeclarationDescriptor declarationDescriptor,
|
||||
JetParameter valueParameter, int index, JetType type, BindingTrace trace,
|
||||
List<AnnotationDescriptor> annotations
|
||||
@@ -533,7 +531,7 @@ public class DescriptorResolver {
|
||||
varargElementType = type;
|
||||
variableType = DescriptorUtils.getVarargParameterType(type);
|
||||
}
|
||||
MutableValueParameterDescriptor valueParameterDescriptor = new ValueParameterDescriptorImpl(
|
||||
ValueParameterDescriptorImpl valueParameterDescriptor = new ValueParameterDescriptorImpl(
|
||||
declarationDescriptor,
|
||||
index,
|
||||
annotations,
|
||||
@@ -595,23 +593,13 @@ public class DescriptorResolver {
|
||||
@NotNull ClassDescriptor classDescriptor,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
ConstructorDescriptorImpl constructorDescriptor = createPrimaryConstructorForObject(classDescriptor);
|
||||
ConstructorDescriptorImpl constructorDescriptor = DefaultDescriptorFactory.createPrimaryConstructorForObject(classDescriptor);
|
||||
if (object != null) {
|
||||
trace.record(CONSTRUCTOR, object, constructorDescriptor);
|
||||
}
|
||||
return constructorDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ConstructorDescriptorImpl createPrimaryConstructorForObject(@NotNull ClassDescriptor containingClass) {
|
||||
ConstructorDescriptorImpl constructorDescriptor =
|
||||
new ConstructorDescriptorImpl(containingClass, Collections.<AnnotationDescriptor>emptyList(), true);
|
||||
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<ValueParameterDescriptor>emptyList(),
|
||||
getDefaultConstructorVisibility(containingClass));
|
||||
return constructorDescriptor;
|
||||
}
|
||||
|
||||
static final class UpperBoundCheckerTask {
|
||||
JetTypeReference upperBound;
|
||||
JetType upperBoundType;
|
||||
@@ -1103,14 +1091,14 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetType transformAnonymousTypeIfNeeded(
|
||||
private static JetType transformAnonymousTypeIfNeeded(
|
||||
@NotNull DeclarationDescriptorWithVisibility descriptor,
|
||||
@NotNull JetNamedDeclaration declaration,
|
||||
@NotNull JetType type,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
ClassifierDescriptor classifierDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
if (!DescriptorUtils.isAnonymous(classifierDescriptor)) {
|
||||
if (classifierDescriptor == null || !DescriptorUtils.isAnonymous(classifierDescriptor)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -1186,7 +1174,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
MutableValueParameterDescriptor valueParameterDescriptor =
|
||||
ValueParameterDescriptorImpl valueParameterDescriptor =
|
||||
resolveValueParameterDescriptor(scope, setterDescriptor, parameter, 0, type, trace);
|
||||
setterDescriptor.initialize(valueParameterDescriptor);
|
||||
}
|
||||
@@ -1197,12 +1185,7 @@ public class DescriptorResolver {
|
||||
trace.record(BindingContext.PROPERTY_ACCESSOR, setter, setterDescriptor);
|
||||
}
|
||||
else if (property.isVar()) {
|
||||
if (property.getDelegateExpression() != null) {
|
||||
setterDescriptor = createSetterForDelegatedProperty(propertyDescriptor);
|
||||
}
|
||||
else {
|
||||
setterDescriptor = createDefaultSetter(propertyDescriptor);
|
||||
}
|
||||
setterDescriptor = DefaultDescriptorFactory.createSetter(propertyDescriptor, property.getDelegateExpression() == null);
|
||||
}
|
||||
|
||||
if (!property.isVar()) {
|
||||
@@ -1214,27 +1197,6 @@ public class DescriptorResolver {
|
||||
return setterDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertySetterDescriptorImpl createDefaultSetter(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return createSetter(propertyDescriptor, false, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertySetterDescriptorImpl createSetterForDelegatedProperty(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return createSetter(propertyDescriptor, true, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static PropertySetterDescriptorImpl createSetter(@NotNull PropertyDescriptor propertyDescriptor, boolean hasBody, boolean isDefault) {
|
||||
PropertySetterDescriptorImpl setterDescriptor;
|
||||
setterDescriptor = new PropertySetterDescriptorImpl(
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
hasBody, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
setterDescriptor.initializeDefault();
|
||||
return setterDescriptor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PropertyGetterDescriptorImpl resolvePropertyGetterDescriptor(
|
||||
@NotNull JetScope scope,
|
||||
@@ -1267,36 +1229,12 @@ public class DescriptorResolver {
|
||||
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
||||
}
|
||||
else {
|
||||
if (property.getDelegateExpression() != null) {
|
||||
getterDescriptor = createGetterForDelegatedProperty(propertyDescriptor);
|
||||
}
|
||||
else {
|
||||
getterDescriptor = createDefaultGetter(propertyDescriptor);
|
||||
}
|
||||
getterDescriptor = DefaultDescriptorFactory.createGetter(propertyDescriptor, property.getDelegateExpression() == null);
|
||||
getterDescriptor.initialize(propertyDescriptor.getType());
|
||||
}
|
||||
return getterDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyGetterDescriptorImpl createDefaultGetter(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return createGetter(propertyDescriptor, false, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyGetterDescriptorImpl createGetterForDelegatedProperty(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
return createGetter(propertyDescriptor, true, false);
|
||||
}
|
||||
|
||||
private static PropertyGetterDescriptorImpl createGetter(@NotNull PropertyDescriptor propertyDescriptor, boolean hasBody, boolean isDefault) {
|
||||
PropertyGetterDescriptorImpl getterDescriptor;
|
||||
getterDescriptor = new PropertyGetterDescriptorImpl(
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
hasBody, isDefault, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
return getterDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ConstructorDescriptorImpl createConstructorDescriptor(
|
||||
@NotNull JetScope scope,
|
||||
@@ -1377,8 +1315,9 @@ public class DescriptorResolver {
|
||||
propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(),
|
||||
getExpectedThisObjectIfNeeded(classDescriptor), NO_RECEIVER_PARAMETER);
|
||||
|
||||
PropertyGetterDescriptorImpl getter = createDefaultGetter(propertyDescriptor);
|
||||
PropertySetterDescriptor setter = propertyDescriptor.isVar() ? createDefaultSetter(propertyDescriptor) : null;
|
||||
PropertyGetterDescriptorImpl getter = DefaultDescriptorFactory.createDefaultGetter(propertyDescriptor);
|
||||
PropertySetterDescriptor setter =
|
||||
propertyDescriptor.isVar() ? DefaultDescriptorFactory.createDefaultSetter(propertyDescriptor) : null;
|
||||
|
||||
propertyDescriptor.initialize(getter, setter);
|
||||
getter.initialize(propertyDescriptor.getType());
|
||||
@@ -1436,26 +1375,13 @@ public class DescriptorResolver {
|
||||
) {
|
||||
final ClassDescriptor enumClassDescriptor = (ClassDescriptor) classObject.getContainingDeclaration();
|
||||
assert DescriptorUtils.isEnumClass(enumClassDescriptor) : "values should be created in enum class: " + enumClassDescriptor;
|
||||
return createEnumClassObjectValuesMethod(classObject, DeferredType.create(trace, new RecursionIntolerantLazyValue<JetType>() {
|
||||
@Override
|
||||
protected JetType compute() {
|
||||
return KotlinBuiltIns.getInstance().getArrayType(enumClassDescriptor.getDefaultType());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleFunctionDescriptor createEnumClassObjectValuesMethod(
|
||||
@NotNull ClassDescriptor classObject,
|
||||
@NotNull JetType returnType
|
||||
) {
|
||||
SimpleFunctionDescriptorImpl values =
|
||||
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUES_METHOD_NAME,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
return values.initialize(null, classObject.getThisAsReceiverParameter(), Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<ValueParameterDescriptor>emptyList(),
|
||||
returnType, Modality.FINAL,
|
||||
Visibilities.PUBLIC, false);
|
||||
return DefaultDescriptorFactory
|
||||
.createEnumClassObjectValuesMethod(classObject, DeferredType.create(trace, new RecursionIntolerantLazyValue<JetType>() {
|
||||
@Override
|
||||
protected JetType compute() {
|
||||
return KotlinBuiltIns.getInstance().getArrayType(enumClassDescriptor.getDefaultType());
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -1466,35 +1392,13 @@ public class DescriptorResolver {
|
||||
) {
|
||||
final ClassDescriptor enumClassDescriptor = (ClassDescriptor) classObject.getContainingDeclaration();
|
||||
assert DescriptorUtils.isEnumClass(enumClassDescriptor) : "valueOf should be created in enum class: " + enumClassDescriptor;
|
||||
return createEnumClassObjectValueOfMethod(classObject, DeferredType.create(trace, new RecursionIntolerantLazyValue<JetType>() {
|
||||
@Override
|
||||
protected JetType compute() {
|
||||
return enumClassDescriptor.getDefaultType();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleFunctionDescriptor createEnumClassObjectValueOfMethod(
|
||||
@NotNull ClassDescriptor classObject,
|
||||
@NotNull JetType returnType
|
||||
) {
|
||||
SimpleFunctionDescriptorImpl values =
|
||||
new SimpleFunctionDescriptorImpl(classObject, Collections.<AnnotationDescriptor>emptyList(), VALUE_OF_METHOD_NAME,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
ValueParameterDescriptor parameterDescriptor = new ValueParameterDescriptorImpl(
|
||||
values,
|
||||
0,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Name.identifier("value"),
|
||||
KotlinBuiltIns.getInstance().getStringType(),
|
||||
false,
|
||||
null);
|
||||
return values.initialize(null, classObject.getThisAsReceiverParameter(),
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.singletonList(parameterDescriptor),
|
||||
returnType, Modality.FINAL,
|
||||
Visibilities.PUBLIC, false);
|
||||
return DefaultDescriptorFactory
|
||||
.createEnumClassObjectValueOfMethod(classObject, DeferredType.create(trace, new RecursionIntolerantLazyValue<JetType>() {
|
||||
@Override
|
||||
protected JetType compute() {
|
||||
return enumClassDescriptor.getDefaultType();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public static ReceiverParameterDescriptor createLazyReceiverParameterDescriptor(@NotNull final ClassDescriptor classDescriptor) {
|
||||
|
||||
@@ -24,17 +24,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.FilteringScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
@@ -48,6 +43,8 @@ import java.util.*;
|
||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
|
||||
public class DescriptorUtils {
|
||||
private DescriptorUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <D extends CallableDescriptor> D substituteBounds(@NotNull D functionDescriptor) {
|
||||
@@ -62,7 +59,8 @@ public class DescriptorUtils {
|
||||
return substitutedFunction;
|
||||
}
|
||||
|
||||
public static Modality convertModality(Modality modality, boolean makeNonAbstract) {
|
||||
@NotNull
|
||||
public static Modality convertModality(@NotNull Modality modality, boolean makeNonAbstract) {
|
||||
if (makeNonAbstract && modality == Modality.ABSTRACT) return Modality.OPEN;
|
||||
return modality;
|
||||
}
|
||||
@@ -129,7 +127,7 @@ public class DescriptorUtils {
|
||||
return FqName.ROOT.toUnsafe();
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("descriptor is not module descriptor and has null containingDeclaration: " + containingDeclaration);
|
||||
throw new IllegalStateException("descriptor is not module descriptor and has null containingDeclaration: " + descriptor);
|
||||
}
|
||||
|
||||
if (containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.CLASS_OBJECT) {
|
||||
@@ -146,8 +144,8 @@ public class DescriptorUtils {
|
||||
}
|
||||
|
||||
public static boolean isInSameModule(@NotNull DeclarationDescriptor first, @NotNull DeclarationDescriptor second) {
|
||||
ModuleDescriptor parentModule = DescriptorUtils.getParentOfType(first, ModuleDescriptorImpl.class, false);
|
||||
ModuleDescriptor fromModule = DescriptorUtils.getParentOfType(second, ModuleDescriptorImpl.class, false);
|
||||
ModuleDescriptor parentModule = getParentOfType(first, ModuleDescriptorImpl.class, false);
|
||||
ModuleDescriptor fromModule = getParentOfType(second, ModuleDescriptorImpl.class, false);
|
||||
assert parentModule != null && fromModule != null;
|
||||
return parentModule.equals(fromModule);
|
||||
}
|
||||
@@ -156,7 +154,7 @@ public class DescriptorUtils {
|
||||
public static DeclarationDescriptor findTopLevelParent(@NotNull DeclarationDescriptor declarationDescriptor) {
|
||||
DeclarationDescriptor descriptor = declarationDescriptor;
|
||||
if (declarationDescriptor instanceof PropertyAccessorDescriptor) {
|
||||
descriptor = ((PropertyAccessorDescriptor)descriptor).getCorrespondingProperty();
|
||||
descriptor = ((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty();
|
||||
}
|
||||
while (!(descriptor == null || isTopLevelDeclaration(descriptor))) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
@@ -165,12 +163,19 @@ public class DescriptorUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <D extends DeclarationDescriptor> D getParentOfType(@Nullable DeclarationDescriptor descriptor, @NotNull Class<D> aClass) {
|
||||
public static <D extends DeclarationDescriptor> D getParentOfType(
|
||||
@Nullable DeclarationDescriptor descriptor,
|
||||
@NotNull Class<D> aClass
|
||||
) {
|
||||
return getParentOfType(descriptor, aClass, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <D extends DeclarationDescriptor> D getParentOfType(@Nullable DeclarationDescriptor descriptor, @NotNull Class<D> aClass, boolean strict) {
|
||||
public static <D extends DeclarationDescriptor> D getParentOfType(
|
||||
@Nullable DeclarationDescriptor descriptor,
|
||||
@NotNull Class<D> aClass,
|
||||
boolean strict
|
||||
) {
|
||||
if (descriptor == null) return null;
|
||||
if (strict) {
|
||||
descriptor = descriptor.getContainingDeclaration();
|
||||
@@ -185,7 +190,11 @@ public class DescriptorUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isAncestor(@Nullable DeclarationDescriptor ancestor, @NotNull DeclarationDescriptor declarationDescriptor, boolean strict) {
|
||||
public static boolean isAncestor(
|
||||
@Nullable DeclarationDescriptor ancestor,
|
||||
@NotNull DeclarationDescriptor declarationDescriptor,
|
||||
boolean strict
|
||||
) {
|
||||
if (ancestor == null) return false;
|
||||
DeclarationDescriptor descriptor = strict ? declarationDescriptor.getContainingDeclaration() : declarationDescriptor;
|
||||
while (descriptor != null) {
|
||||
@@ -195,33 +204,6 @@ public class DescriptorUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static VariableDescriptor filterNonExtensionProperty(Collection<VariableDescriptor> variables) {
|
||||
for (VariableDescriptor variable : variables) {
|
||||
if (variable.getReceiverParameter() == null) {
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getFunctionExpectedReturnType(@NotNull FunctionDescriptor descriptor, @NotNull JetElement function) {
|
||||
JetType expectedType;
|
||||
if (function instanceof JetFunction) {
|
||||
if (((JetFunction) function).getReturnTypeRef() != null || ((JetFunction) function).hasBlockBody()) {
|
||||
expectedType = descriptor.getReturnType();
|
||||
}
|
||||
else {
|
||||
expectedType = TypeUtils.NO_EXPECTED_TYPE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
expectedType = descriptor.getReturnType();
|
||||
}
|
||||
return expectedType != null ? expectedType : TypeUtils.NO_EXPECTED_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isSubclass(@NotNull ClassDescriptor subClass, @NotNull ClassDescriptor superClass) {
|
||||
return isSubtypeOfClass(subClass.getDefaultType(), superClass.getOriginal());
|
||||
}
|
||||
@@ -239,7 +221,7 @@ public class DescriptorUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void addSuperTypes(JetType type, Set<JetType> set) {
|
||||
public static void addSuperTypes(@NotNull JetType type, @NotNull Set<JetType> set) {
|
||||
set.add(type);
|
||||
|
||||
for (JetType jetType : type.getConstructor().getSupertypes()) {
|
||||
@@ -251,19 +233,6 @@ public class DescriptorUtils {
|
||||
return namespaceDescriptor.getContainingDeclaration() instanceof ModuleDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<DeclarationDescriptor> getPathWithoutRootNsAndModule(@NotNull DeclarationDescriptor descriptor) {
|
||||
List<DeclarationDescriptor> path = Lists.newArrayList();
|
||||
DeclarationDescriptor current = descriptor;
|
||||
while (true) {
|
||||
if (current instanceof NamespaceDescriptor && isRootNamespace((NamespaceDescriptor) current)) {
|
||||
return Lists.reverse(path);
|
||||
}
|
||||
path.add(current);
|
||||
current = current.getContainingDeclaration();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFunctionLiteral(@NotNull FunctionDescriptor descriptor) {
|
||||
return descriptor instanceof AnonymousFunctionDescriptor;
|
||||
}
|
||||
@@ -272,7 +241,7 @@ public class DescriptorUtils {
|
||||
return isKindOf(descriptor, ClassKind.CLASS_OBJECT);
|
||||
}
|
||||
|
||||
public static boolean isAnonymous(@Nullable ClassifierDescriptor descriptor) {
|
||||
public static boolean isAnonymous(@NotNull ClassifierDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.OBJECT) && descriptor.getName().isSpecial();
|
||||
}
|
||||
|
||||
@@ -288,20 +257,16 @@ public class DescriptorUtils {
|
||||
return isKindOf(descriptor, ClassKind.ANNOTATION_CLASS);
|
||||
}
|
||||
|
||||
public static boolean isTrait(@NotNull DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.TRAIT);
|
||||
}
|
||||
|
||||
public static boolean isClass(@NotNull DeclarationDescriptor descriptor) {
|
||||
return isKindOf(descriptor, ClassKind.CLASS);
|
||||
}
|
||||
|
||||
public static boolean isKindOf(@NotNull JetType jetType, @NotNull ClassKind classKind) {
|
||||
ClassifierDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
return isKindOf(descriptor, classKind);
|
||||
}
|
||||
|
||||
public static boolean isKindOf(@Nullable DeclarationDescriptor descriptor, @NotNull ClassKind classKind) {
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
return ((ClassDescriptor) descriptor).getKind() == classKind;
|
||||
}
|
||||
return false;
|
||||
return descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() == classKind;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -319,11 +284,10 @@ public class DescriptorUtils {
|
||||
|
||||
@NotNull
|
||||
public static ClassDescriptor getClassDescriptorForType(@NotNull JetType type) {
|
||||
DeclarationDescriptor superClassDescriptor =
|
||||
type.getConstructor().getDeclarationDescriptor();
|
||||
assert superClassDescriptor instanceof ClassDescriptor
|
||||
: "Superclass descriptor of a type should be of type ClassDescriptor";
|
||||
return (ClassDescriptor)superClassDescriptor;
|
||||
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
assert descriptor instanceof ClassDescriptor
|
||||
: "Classifier descriptor of a type should be of type ClassDescriptor: " + type;
|
||||
return (ClassDescriptor) descriptor;
|
||||
}
|
||||
|
||||
public static boolean isNotAny(@NotNull DeclarationDescriptor superClassDescriptor) {
|
||||
@@ -346,24 +310,6 @@ public class DescriptorUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isIteratorWithoutRemoveImpl(@NotNull ClassDescriptor classDescriptor) {
|
||||
ClassDescriptor iteratorOfT = KotlinBuiltIns.getInstance().getIterator();
|
||||
JetType iteratorOfAny = TypeUtils.substituteParameters(iteratorOfT, Collections.singletonList(KotlinBuiltIns.getInstance().getAnyType()));
|
||||
boolean isIterator = JetTypeChecker.INSTANCE.isSubtypeOf(classDescriptor.getDefaultType(), iteratorOfAny);
|
||||
boolean hasRemove = hasMethod(classDescriptor, Name.identifier("remove"));
|
||||
return isIterator && !hasRemove;
|
||||
}
|
||||
|
||||
private static boolean hasMethod(ClassDescriptor classDescriptor, Name name) {
|
||||
Collection<FunctionDescriptor> removeFunctions = classDescriptor.getDefaultType().getMemberScope().getFunctions(name);
|
||||
for (FunctionDescriptor function : removeFunctions) {
|
||||
if (function.getValueParameters().isEmpty() && function.getTypeParameters().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Name getClassObjectName(@NotNull Name className) {
|
||||
return Name.special("<class-object-for-" + className.asString() + ">");
|
||||
@@ -446,35 +392,10 @@ public class DescriptorUtils {
|
||||
return receiverParameterDescriptor.getType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ReceiverValue safeGetValue(@Nullable ReceiverParameterDescriptor receiverParameterDescriptor) {
|
||||
if (receiverParameterDescriptor == null) {
|
||||
return ReceiverValue.NO_RECEIVER;
|
||||
}
|
||||
return receiverParameterDescriptor.getValue();
|
||||
}
|
||||
|
||||
|
||||
public static boolean isExternallyAccessible(PropertyDescriptor propertyDescriptor) {
|
||||
return propertyDescriptor.getVisibility() != Visibilities.PRIVATE || isClassObject(propertyDescriptor.getContainingDeclaration())
|
||||
|| isTopLevelDeclaration(propertyDescriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getVarargParameterType(@NotNull JetType elementType) {
|
||||
return getVarargParameterType(elementType, Variance.INVARIANT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getVarargParameterType(@NotNull JetType elementType, @NotNull Variance projectionKind) {
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
JetType primitiveArrayType = builtIns.getPrimitiveArrayJetTypeByPrimitiveJetType(elementType);
|
||||
if (primitiveArrayType != null) {
|
||||
return primitiveArrayType;
|
||||
}
|
||||
else {
|
||||
return builtIns.getArrayType(projectionKind, elementType);
|
||||
}
|
||||
JetType primitiveArrayType = KotlinBuiltIns.getInstance().getPrimitiveArrayJetTypeByPrimitiveJetType(elementType);
|
||||
return primitiveArrayType != null ? primitiveArrayType : KotlinBuiltIns.getInstance().getArrayType(Variance.INVARIANT, elementType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -544,24 +465,6 @@ public class DescriptorUtils {
|
||||
return allSuperclasses;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyDescriptor getPropertyDescriptor(@NotNull JetProperty property, @NotNull BindingContext bindingContext) {
|
||||
VariableDescriptor descriptor = bindingContext.get(BindingContext.VARIABLE, property);
|
||||
if (!(descriptor instanceof PropertyDescriptor)) {
|
||||
throw new UnsupportedOperationException("expect a property to have a property descriptor");
|
||||
}
|
||||
return (PropertyDescriptor) descriptor;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public static PropertyDescriptor getPropertyDescriptor(@NotNull JetParameter constructorParameter, @NotNull BindingContext bindingContext) {
|
||||
assert constructorParameter.getValOrVarNode() != null;
|
||||
PropertyDescriptor descriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, constructorParameter);
|
||||
assert descriptor != null;
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true iff {@code descriptor}'s first non-class container is a namespace
|
||||
*/
|
||||
|
||||
@@ -14,13 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors.impl;
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.TraceBasedRedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
@@ -67,38 +69,6 @@ public class FunctionDescriptorUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(FunctionDescriptor substitutedDescriptor, @NotNull FunctionDescriptor functionDescriptor, @NotNull TypeSubstitutor substitutor) {
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||
List<ValueParameterDescriptor> unsubstitutedValueParameters = functionDescriptor.getValueParameters();
|
||||
for (ValueParameterDescriptor unsubstitutedValueParameter : unsubstitutedValueParameters) {
|
||||
// TODO : Lazy?
|
||||
JetType substitutedType = substitutor.substitute(unsubstitutedValueParameter.getType(), Variance.IN_VARIANCE);
|
||||
JetType varargElementType = unsubstitutedValueParameter.getVarargElementType();
|
||||
JetType substituteVarargElementType = varargElementType == null ? null : substitutor.substitute(varargElementType, Variance.IN_VARIANCE);
|
||||
if (substitutedType == null) return null;
|
||||
result.add(new ValueParameterDescriptorImpl(
|
||||
substitutedDescriptor,
|
||||
unsubstitutedValueParameter,
|
||||
unsubstitutedValueParameter.getAnnotations(),
|
||||
substitutedType,
|
||||
substituteVarargElementType
|
||||
));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetType getSubstitutedReturnType(@NotNull FunctionDescriptor functionDescriptor, TypeSubstitutor substitutor) {
|
||||
return substitutor.substitute(functionDescriptor.getReturnType(), Variance.OUT_VARIANCE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FunctionDescriptor substituteFunctionDescriptor(@NotNull List<JetType> typeArguments, @NotNull FunctionDescriptor functionDescriptor) {
|
||||
Map<TypeConstructor, TypeProjection> substitutionContext = createSubstitutionContext(functionDescriptor, typeArguments);
|
||||
return functionDescriptor.substitute(TypeSubstitutor.create(substitutionContext));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
|
||||
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, new TraceBasedRedeclarationHandler(trace), "Function inner scope");
|
||||
@@ -186,7 +186,7 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
|
||||
namespaceDescriptor.initialize(scope);
|
||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
//
|
||||
moduleDescriptor.getModuleConfiguration().extendNamespaceScope(trace, namespaceDescriptor, scope);
|
||||
moduleDescriptor.getModuleConfiguration().extendNamespaceScope(namespaceDescriptor, scope);
|
||||
owner.addNamespace(namespaceDescriptor);
|
||||
if (expression != null) {
|
||||
trace.record(BindingContext.NAMESPACE, expression, namespaceDescriptor);
|
||||
|
||||
@@ -16,18 +16,20 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.LinkedMultiMap;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptorLite;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil;
|
||||
@@ -43,7 +45,6 @@ import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.CONFLICT;
|
||||
import static org.jetbrains.jet.lang.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE;
|
||||
|
||||
public class OverrideResolver {
|
||||
@@ -134,12 +135,12 @@ public class OverrideResolver {
|
||||
Collection<CallableMemberDescriptor> fromSupertypes = membersFromSupertypesByName.get(memberName);
|
||||
Collection<CallableMemberDescriptor> fromCurrent = membersFromCurrentByName.get(memberName);
|
||||
|
||||
generateOverridesInFunctionGroup(
|
||||
OverridingUtil.generateOverridesInFunctionGroup(
|
||||
memberName,
|
||||
fromSupertypes,
|
||||
fromCurrent,
|
||||
classDescriptor,
|
||||
new DescriptorSink() {
|
||||
new OverridingUtil.DescriptorSink() {
|
||||
@Override
|
||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||
if (fakeOverride instanceof PropertyDescriptor) {
|
||||
@@ -167,197 +168,23 @@ public class OverrideResolver {
|
||||
public static void resolveUnknownVisibilities(
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> descriptors,
|
||||
@NotNull BindingTrace trace) {
|
||||
for (CallableMemberDescriptor memberDescriptor : descriptors) {
|
||||
JetDeclaration declaration = null;
|
||||
if (memberDescriptor.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), memberDescriptor);
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
resolveUnknownVisibilityForMember(descriptor, trace);
|
||||
}
|
||||
}
|
||||
|
||||
public static void resolveUnknownVisibilityForMember(@NotNull CallableMemberDescriptor descriptor, @NotNull final BindingTrace trace) {
|
||||
OverridingUtil.resolveUnknownVisibilityForMember(descriptor, new OverridingUtil.NotInferredVisibilitySink() {
|
||||
@Override
|
||||
public void cannotInferVisibility(@NotNull CallableMemberDescriptor descriptor) {
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor);
|
||||
if (element instanceof JetDeclaration) {
|
||||
declaration = (JetDeclaration) element;
|
||||
trace.report(CANNOT_INFER_VISIBILITY.on((JetDeclaration) element));
|
||||
}
|
||||
}
|
||||
resolveUnknownVisibilityForMember(declaration, memberDescriptor, trace);
|
||||
}
|
||||
}
|
||||
|
||||
public interface DescriptorSink {
|
||||
void addToScope(@NotNull CallableMemberDescriptor fakeOverride);
|
||||
|
||||
void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent);
|
||||
}
|
||||
|
||||
public static void generateOverridesInFunctionGroup(
|
||||
@NotNull Name name, //DO NOT DELETE THIS PARAMETER: needed to make sure all descriptors have the same name
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> membersFromSupertypes,
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> membersFromCurrent,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> notOverridden = Sets.newLinkedHashSet(membersFromSupertypes);
|
||||
|
||||
for (CallableMemberDescriptor fromCurrent : membersFromCurrent) {
|
||||
Collection<CallableMemberDescriptor> bound =
|
||||
extractAndBindOverridesForMember(fromCurrent, membersFromSupertypes, current, sink);
|
||||
notOverridden.removeAll(bound);
|
||||
}
|
||||
|
||||
createAndBindFakeOverrides(current, notOverridden, sink);
|
||||
}
|
||||
|
||||
private static Collection<CallableMemberDescriptor> extractAndBindOverridesForMember(
|
||||
@NotNull CallableMemberDescriptor fromCurrent,
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> descriptorsFromSuper,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> bound = Lists.newArrayList();
|
||||
for (CallableMemberDescriptor fromSupertype : descriptorsFromSuper) {
|
||||
OverridingUtil.OverrideCompatibilityInfo.Result result =
|
||||
OverridingUtil.isOverridableBy(fromSupertype, fromCurrent).getResult();
|
||||
|
||||
boolean isVisible = Visibilities.isVisible(fromSupertype, current);
|
||||
switch (result) {
|
||||
case OVERRIDABLE:
|
||||
if (isVisible) {
|
||||
OverridingUtil.bindOverride(fromCurrent, fromSupertype);
|
||||
}
|
||||
bound.add(fromSupertype);
|
||||
break;
|
||||
case CONFLICT:
|
||||
if (isVisible) {
|
||||
sink.conflict(fromSupertype, fromCurrent);
|
||||
}
|
||||
bound.add(fromSupertype);
|
||||
break;
|
||||
case INCOMPATIBLE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bound;
|
||||
}
|
||||
|
||||
private static void createAndBindFakeOverrides(
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull Collection<CallableMemberDescriptor> notOverridden,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Queue<CallableMemberDescriptor> fromSuperQueue = new LinkedList<CallableMemberDescriptor>(notOverridden);
|
||||
while (!fromSuperQueue.isEmpty()) {
|
||||
CallableMemberDescriptor notOverriddenFromSuper = VisibilityUtil.findMemberWithMaxVisibility(fromSuperQueue);
|
||||
Collection<CallableMemberDescriptor> overridables = extractMembersOverridableInBothWays(notOverriddenFromSuper, fromSuperQueue,
|
||||
sink);
|
||||
createAndBindFakeOverride(overridables, current, sink);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isMoreSpecific(@NotNull CallableMemberDescriptor a, @NotNull CallableMemberDescriptor b) {
|
||||
if (a instanceof SimpleFunctionDescriptor) {
|
||||
assert b instanceof SimpleFunctionDescriptor : "b is " + b.getClass();
|
||||
|
||||
JetType aReturnType = a.getReturnType();
|
||||
assert aReturnType != null;
|
||||
JetType bReturnType = b.getReturnType();
|
||||
assert bReturnType != null;
|
||||
|
||||
return JetTypeChecker.INSTANCE.isSubtypeOf(aReturnType, bReturnType);
|
||||
}
|
||||
if (a instanceof PropertyDescriptor) {
|
||||
assert b instanceof PropertyDescriptor : "b is " + b.getClass();
|
||||
|
||||
if (((PropertyDescriptor) a).isVar() || ((PropertyDescriptor) b).isVar()) {
|
||||
return ((PropertyDescriptor) a).isVar();
|
||||
}
|
||||
|
||||
// both vals
|
||||
return JetTypeChecker.INSTANCE.isSubtypeOf(((PropertyDescriptor) a).getType(), ((PropertyDescriptor) b).getType());
|
||||
}
|
||||
throw new IllegalArgumentException("Unexpected callable: " + a.getClass());
|
||||
}
|
||||
|
||||
private static CallableMemberDescriptor selectMostSpecificMemberFromSuper(@NotNull Collection<CallableMemberDescriptor> overridables) {
|
||||
CallableMemberDescriptor result = null;
|
||||
for (CallableMemberDescriptor overridable : overridables) {
|
||||
if (result == null || isMoreSpecific(overridable, result)) {
|
||||
result = overridable;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void createAndBindFakeOverride(
|
||||
@NotNull Collection<CallableMemberDescriptor> overridables,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> visibleOverridables = filterVisibleFakeOverrides(current, overridables);
|
||||
Modality modality = getMinimalModality(visibleOverridables);
|
||||
boolean allInvisible = visibleOverridables.isEmpty();
|
||||
Collection<CallableMemberDescriptor> effectiveOverridden = allInvisible ? overridables : visibleOverridables;
|
||||
Visibility visibility = allInvisible ? Visibilities.INVISIBLE_FAKE : Visibilities.INHERITED;
|
||||
CallableMemberDescriptor mostSpecific = selectMostSpecificMemberFromSuper(effectiveOverridden);
|
||||
CallableMemberDescriptor fakeOverride =
|
||||
mostSpecific.copy(current, modality, visibility, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
|
||||
for (CallableMemberDescriptor descriptor : effectiveOverridden) {
|
||||
OverridingUtil.bindOverride(fakeOverride, descriptor);
|
||||
}
|
||||
sink.addToScope(fakeOverride);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Modality getMinimalModality(@NotNull Collection<CallableMemberDescriptor> descriptors) {
|
||||
Modality modality = Modality.ABSTRACT;
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
if (descriptor.getModality().compareTo(modality) < 0) {
|
||||
modality = descriptor.getModality();
|
||||
}
|
||||
}
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<CallableMemberDescriptor> filterVisibleFakeOverrides(
|
||||
@NotNull final ClassDescriptor current,
|
||||
@NotNull Collection<CallableMemberDescriptor> toFilter
|
||||
) {
|
||||
return Collections2.filter(toFilter, new Predicate<CallableMemberDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable CallableMemberDescriptor descriptor) {
|
||||
//nested class could capture private member, so check for private visibility added
|
||||
return descriptor.getVisibility() != Visibilities.PRIVATE && Visibilities.isVisible(descriptor, current);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<CallableMemberDescriptor> extractMembersOverridableInBothWays(
|
||||
@NotNull CallableMemberDescriptor overrider,
|
||||
@NotNull Queue<CallableMemberDescriptor> extractFrom,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> overridable = Lists.newArrayList();
|
||||
overridable.add(overrider);
|
||||
for (Iterator<CallableMemberDescriptor> iterator = extractFrom.iterator(); iterator.hasNext(); ) {
|
||||
CallableMemberDescriptor candidate = iterator.next();
|
||||
if (overrider == candidate) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
OverridingUtil.OverrideCompatibilityInfo.Result result1 =
|
||||
OverridingUtil.isOverridableBy(candidate, overrider).getResult();
|
||||
OverridingUtil.OverrideCompatibilityInfo.Result result2 =
|
||||
OverridingUtil.isOverridableBy(overrider, candidate).getResult();
|
||||
if (result1 == OVERRIDABLE && result2 == OVERRIDABLE) {
|
||||
overridable.add(candidate);
|
||||
iterator.remove();
|
||||
}
|
||||
else if (result1 == CONFLICT || result2 == CONFLICT) {
|
||||
sink.conflict(overrider, candidate);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
return overridable;
|
||||
}
|
||||
|
||||
private static <T extends DeclarationDescriptor> MultiMap<Name, T> groupDescriptorsByName(Collection<T> properties) {
|
||||
MultiMap<Name, T> r = new LinkedMultiMap<Name, T>();
|
||||
for (T property : properties) {
|
||||
@@ -893,78 +720,6 @@ public class OverrideResolver {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void resolveUnknownVisibilityForMember(@Nullable JetDeclaration member, @NotNull CallableMemberDescriptor memberDescriptor, @NotNull BindingTrace trace) {
|
||||
resolveUnknownVisibilityForOverriddenDescriptors(memberDescriptor.getOverriddenDescriptors(), trace);
|
||||
if (memberDescriptor.getVisibility() != Visibilities.INHERITED) {
|
||||
return;
|
||||
}
|
||||
|
||||
Visibility visibility = findMaxVisibility(memberDescriptor.getOverriddenDescriptors());
|
||||
if (visibility == null) {
|
||||
if (member != null) {
|
||||
trace.report(CANNOT_INFER_VISIBILITY.on(member));
|
||||
}
|
||||
visibility = Visibilities.PUBLIC;
|
||||
}
|
||||
|
||||
if (memberDescriptor instanceof PropertyDescriptorImpl) {
|
||||
((PropertyDescriptorImpl)memberDescriptor).setVisibility(visibility.normalize());
|
||||
for (PropertyAccessorDescriptor accessor : ((PropertyDescriptor) memberDescriptor).getAccessors()) {
|
||||
resolveUnknownVisibilityForMember(null, accessor, trace);
|
||||
}
|
||||
}
|
||||
else if (memberDescriptor instanceof FunctionDescriptorImpl) {
|
||||
((FunctionDescriptorImpl)memberDescriptor).setVisibility(visibility.normalize());
|
||||
}
|
||||
else {
|
||||
assert memberDescriptor instanceof PropertyAccessorDescriptorImpl;
|
||||
((PropertyAccessorDescriptorImpl) memberDescriptor).setVisibility(visibility.normalize());
|
||||
}
|
||||
}
|
||||
|
||||
private static void resolveUnknownVisibilityForOverriddenDescriptors(@NotNull Collection<? extends CallableMemberDescriptor> descriptors, @NotNull BindingTrace trace) {
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
if (descriptor.getVisibility() == Visibilities.INHERITED) {
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor);
|
||||
JetDeclaration declaration = (element instanceof JetDeclaration) ? (JetDeclaration) element : null;
|
||||
resolveUnknownVisibilityForMember(declaration, descriptor, trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Visibility findMaxVisibility(@NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
|
||||
if (descriptors.isEmpty()) {
|
||||
return Visibilities.INTERNAL;
|
||||
}
|
||||
Visibility maxVisibility = null;
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
Visibility visibility = descriptor.getVisibility();
|
||||
assert visibility != Visibilities.INHERITED;
|
||||
if (maxVisibility == null) {
|
||||
maxVisibility = visibility;
|
||||
continue;
|
||||
}
|
||||
Integer compareResult = Visibilities.compare(visibility, maxVisibility);
|
||||
if (compareResult == null) {
|
||||
maxVisibility = null;
|
||||
}
|
||||
else if (compareResult > 0) {
|
||||
maxVisibility = visibility;
|
||||
}
|
||||
}
|
||||
if (maxVisibility == null) {
|
||||
return null;
|
||||
}
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
Integer compareResult = Visibilities.compare(maxVisibility, descriptor.getVisibility());
|
||||
if (compareResult == null || compareResult < 0) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return maxVisibility;
|
||||
}
|
||||
|
||||
private void checkVisibility() {
|
||||
for (Map.Entry<JetDeclaration, CallableMemberDescriptor> entry : context.getMembers().entrySet()) {
|
||||
checkVisibilityForMember(entry.getKey(), entry.getValue());
|
||||
|
||||
@@ -16,20 +16,25 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.*;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PropertyAccessorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.CONFLICT;
|
||||
import static org.jetbrains.jet.lang.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE;
|
||||
|
||||
public class OverridingUtil {
|
||||
|
||||
private static final List<ExternalOverridabilityCondition> EXTERNAL_CONDITIONS =
|
||||
@@ -308,6 +313,257 @@ public class OverridingUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateOverridesInFunctionGroup(
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
@NotNull Name name, //DO NOT DELETE THIS PARAMETER: needed to make sure all descriptors have the same name
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> membersFromSupertypes,
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> membersFromCurrent,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> notOverridden = Sets.newLinkedHashSet(membersFromSupertypes);
|
||||
|
||||
for (CallableMemberDescriptor fromCurrent : membersFromCurrent) {
|
||||
Collection<CallableMemberDescriptor> bound =
|
||||
extractAndBindOverridesForMember(fromCurrent, membersFromSupertypes, current, sink);
|
||||
notOverridden.removeAll(bound);
|
||||
}
|
||||
|
||||
createAndBindFakeOverrides(current, notOverridden, sink);
|
||||
}
|
||||
|
||||
private static Collection<CallableMemberDescriptor> extractAndBindOverridesForMember(
|
||||
@NotNull CallableMemberDescriptor fromCurrent,
|
||||
@NotNull Collection<? extends CallableMemberDescriptor> descriptorsFromSuper,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> bound = Lists.newArrayList();
|
||||
for (CallableMemberDescriptor fromSupertype : descriptorsFromSuper) {
|
||||
OverrideCompatibilityInfo.Result result = isOverridableBy(fromSupertype, fromCurrent).getResult();
|
||||
|
||||
boolean isVisible = Visibilities.isVisible(fromSupertype, current);
|
||||
switch (result) {
|
||||
case OVERRIDABLE:
|
||||
if (isVisible) {
|
||||
bindOverride(fromCurrent, fromSupertype);
|
||||
}
|
||||
bound.add(fromSupertype);
|
||||
break;
|
||||
case CONFLICT:
|
||||
if (isVisible) {
|
||||
sink.conflict(fromSupertype, fromCurrent);
|
||||
}
|
||||
bound.add(fromSupertype);
|
||||
break;
|
||||
case INCOMPATIBLE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bound;
|
||||
}
|
||||
|
||||
private static void createAndBindFakeOverrides(
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull Collection<CallableMemberDescriptor> notOverridden,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Queue<CallableMemberDescriptor> fromSuperQueue = new LinkedList<CallableMemberDescriptor>(notOverridden);
|
||||
while (!fromSuperQueue.isEmpty()) {
|
||||
CallableMemberDescriptor notOverriddenFromSuper = VisibilityUtil.findMemberWithMaxVisibility(fromSuperQueue);
|
||||
Collection<CallableMemberDescriptor> overridables =
|
||||
extractMembersOverridableInBothWays(notOverriddenFromSuper, fromSuperQueue, sink);
|
||||
createAndBindFakeOverride(overridables, current, sink);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isMoreSpecific(@NotNull CallableMemberDescriptor a, @NotNull CallableMemberDescriptor b) {
|
||||
if (a instanceof SimpleFunctionDescriptor) {
|
||||
assert b instanceof SimpleFunctionDescriptor : "b is " + b.getClass();
|
||||
|
||||
JetType aReturnType = a.getReturnType();
|
||||
assert aReturnType != null;
|
||||
JetType bReturnType = b.getReturnType();
|
||||
assert bReturnType != null;
|
||||
|
||||
return JetTypeChecker.INSTANCE.isSubtypeOf(aReturnType, bReturnType);
|
||||
}
|
||||
if (a instanceof PropertyDescriptor) {
|
||||
assert b instanceof PropertyDescriptor : "b is " + b.getClass();
|
||||
|
||||
if (((PropertyDescriptor) a).isVar() || ((PropertyDescriptor) b).isVar()) {
|
||||
return ((PropertyDescriptor) a).isVar();
|
||||
}
|
||||
|
||||
// both vals
|
||||
return JetTypeChecker.INSTANCE.isSubtypeOf(((PropertyDescriptor) a).getType(), ((PropertyDescriptor) b).getType());
|
||||
}
|
||||
throw new IllegalArgumentException("Unexpected callable: " + a.getClass());
|
||||
}
|
||||
|
||||
private static CallableMemberDescriptor selectMostSpecificMemberFromSuper(@NotNull Collection<CallableMemberDescriptor> overridables) {
|
||||
CallableMemberDescriptor result = null;
|
||||
for (CallableMemberDescriptor overridable : overridables) {
|
||||
if (result == null || isMoreSpecific(overridable, result)) {
|
||||
result = overridable;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void createAndBindFakeOverride(
|
||||
@NotNull Collection<CallableMemberDescriptor> overridables,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> visibleOverridables = filterVisibleFakeOverrides(current, overridables);
|
||||
Modality modality = getMinimalModality(visibleOverridables);
|
||||
boolean allInvisible = visibleOverridables.isEmpty();
|
||||
Collection<CallableMemberDescriptor> effectiveOverridden = allInvisible ? overridables : visibleOverridables;
|
||||
Visibility visibility = allInvisible ? Visibilities.INVISIBLE_FAKE : Visibilities.INHERITED;
|
||||
CallableMemberDescriptor mostSpecific = selectMostSpecificMemberFromSuper(effectiveOverridden);
|
||||
CallableMemberDescriptor fakeOverride =
|
||||
mostSpecific.copy(current, modality, visibility, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
|
||||
for (CallableMemberDescriptor descriptor : effectiveOverridden) {
|
||||
bindOverride(fakeOverride, descriptor);
|
||||
}
|
||||
sink.addToScope(fakeOverride);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Modality getMinimalModality(@NotNull Collection<CallableMemberDescriptor> descriptors) {
|
||||
Modality modality = Modality.ABSTRACT;
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
if (descriptor.getModality().compareTo(modality) < 0) {
|
||||
modality = descriptor.getModality();
|
||||
}
|
||||
}
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<CallableMemberDescriptor> filterVisibleFakeOverrides(
|
||||
@NotNull final ClassDescriptor current,
|
||||
@NotNull Collection<CallableMemberDescriptor> toFilter
|
||||
) {
|
||||
return Collections2.filter(toFilter, new Predicate<CallableMemberDescriptor>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable CallableMemberDescriptor descriptor) {
|
||||
//nested class could capture private member, so check for private visibility added
|
||||
return descriptor != null &&
|
||||
descriptor.getVisibility() != Visibilities.PRIVATE &&
|
||||
Visibilities.isVisible(descriptor, current);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Collection<CallableMemberDescriptor> extractMembersOverridableInBothWays(
|
||||
@NotNull CallableMemberDescriptor overrider,
|
||||
@NotNull Queue<CallableMemberDescriptor> extractFrom,
|
||||
@NotNull DescriptorSink sink
|
||||
) {
|
||||
Collection<CallableMemberDescriptor> overridable = Lists.newArrayList();
|
||||
overridable.add(overrider);
|
||||
for (Iterator<CallableMemberDescriptor> iterator = extractFrom.iterator(); iterator.hasNext(); ) {
|
||||
CallableMemberDescriptor candidate = iterator.next();
|
||||
if (overrider == candidate) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
OverrideCompatibilityInfo.Result result1 = isOverridableBy(candidate, overrider).getResult();
|
||||
OverrideCompatibilityInfo.Result result2 = isOverridableBy(overrider, candidate).getResult();
|
||||
if (result1 == OVERRIDABLE && result2 == OVERRIDABLE) {
|
||||
overridable.add(candidate);
|
||||
iterator.remove();
|
||||
}
|
||||
else if (result1 == CONFLICT || result2 == CONFLICT) {
|
||||
sink.conflict(overrider, candidate);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
return overridable;
|
||||
}
|
||||
|
||||
public static void resolveUnknownVisibilityForMember(
|
||||
@NotNull CallableMemberDescriptor memberDescriptor,
|
||||
@NotNull NotInferredVisibilitySink sink
|
||||
) {
|
||||
for (CallableMemberDescriptor descriptor : memberDescriptor.getOverriddenDescriptors()) {
|
||||
if (descriptor.getVisibility() == Visibilities.INHERITED) {
|
||||
resolveUnknownVisibilityForMember(descriptor, sink);
|
||||
}
|
||||
}
|
||||
|
||||
if (memberDescriptor.getVisibility() != Visibilities.INHERITED) {
|
||||
return;
|
||||
}
|
||||
|
||||
Visibility visibility = findMaxVisibility(memberDescriptor.getOverriddenDescriptors());
|
||||
if (visibility == null) {
|
||||
sink.cannotInferVisibility(memberDescriptor);
|
||||
visibility = Visibilities.PUBLIC;
|
||||
}
|
||||
|
||||
if (memberDescriptor instanceof PropertyDescriptorImpl) {
|
||||
((PropertyDescriptorImpl) memberDescriptor).setVisibility(visibility.normalize());
|
||||
for (PropertyAccessorDescriptor accessor : ((PropertyDescriptor) memberDescriptor).getAccessors()) {
|
||||
resolveUnknownVisibilityForMember(accessor, sink);
|
||||
}
|
||||
}
|
||||
else if (memberDescriptor instanceof FunctionDescriptorImpl) {
|
||||
((FunctionDescriptorImpl) memberDescriptor).setVisibility(visibility.normalize());
|
||||
}
|
||||
else {
|
||||
assert memberDescriptor instanceof PropertyAccessorDescriptorImpl;
|
||||
((PropertyAccessorDescriptorImpl) memberDescriptor).setVisibility(visibility.normalize());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Visibility findMaxVisibility(@NotNull Collection<? extends CallableMemberDescriptor> descriptors) {
|
||||
if (descriptors.isEmpty()) {
|
||||
return Visibilities.INTERNAL;
|
||||
}
|
||||
Visibility maxVisibility = null;
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
Visibility visibility = descriptor.getVisibility();
|
||||
assert visibility != Visibilities.INHERITED;
|
||||
if (maxVisibility == null) {
|
||||
maxVisibility = visibility;
|
||||
continue;
|
||||
}
|
||||
Integer compareResult = Visibilities.compare(visibility, maxVisibility);
|
||||
if (compareResult == null) {
|
||||
maxVisibility = null;
|
||||
}
|
||||
else if (compareResult > 0) {
|
||||
maxVisibility = visibility;
|
||||
}
|
||||
}
|
||||
if (maxVisibility == null) {
|
||||
return null;
|
||||
}
|
||||
for (CallableMemberDescriptor descriptor : descriptors) {
|
||||
Integer compareResult = Visibilities.compare(maxVisibility, descriptor.getVisibility());
|
||||
if (compareResult == null || compareResult < 0) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return maxVisibility;
|
||||
}
|
||||
|
||||
public interface DescriptorSink {
|
||||
void addToScope(@NotNull CallableMemberDescriptor fakeOverride);
|
||||
|
||||
void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent);
|
||||
}
|
||||
|
||||
public interface NotInferredVisibilitySink {
|
||||
void cannotInferVisibility(@NotNull CallableMemberDescriptor descriptor);
|
||||
}
|
||||
|
||||
public static class OverrideCompatibilityInfo {
|
||||
|
||||
public enum Result {
|
||||
|
||||
@@ -17,7 +17,13 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetScript;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ExpressionPosition;
|
||||
@@ -29,6 +35,8 @@ import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
@@ -79,7 +87,24 @@ public class ScriptBodyResolver {
|
||||
if (returnType == null) {
|
||||
returnType = ErrorUtils.createErrorType("getBlockReturnedType returned null");
|
||||
}
|
||||
descriptor.initialize(returnType, declaration, trace.getBindingContext());
|
||||
|
||||
List<PropertyDescriptorImpl> properties = new ArrayList<PropertyDescriptorImpl>();
|
||||
List<SimpleFunctionDescriptor> functions = new ArrayList<SimpleFunctionDescriptor>();
|
||||
|
||||
BindingContext bindingContext = trace.getBindingContext();
|
||||
for (JetDeclaration jetDeclaration : declaration.getDeclarations()) {
|
||||
if (jetDeclaration instanceof JetProperty) {
|
||||
properties.add((PropertyDescriptorImpl) bindingContext.get(BindingContext.VARIABLE, jetDeclaration));
|
||||
}
|
||||
else if (jetDeclaration instanceof JetNamedFunction) {
|
||||
SimpleFunctionDescriptor function = bindingContext.get(BindingContext.FUNCTION, jetDeclaration);
|
||||
assert function != null;
|
||||
functions.add(function.copy(descriptor.getClassDescriptor(), function.getModality(), function.getVisibility(),
|
||||
CallableMemberDescriptor.Kind.DECLARATION, false));
|
||||
}
|
||||
}
|
||||
|
||||
descriptor.initialize(returnType, properties, functions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,9 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.NamespaceDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
@@ -29,6 +31,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespaceHeader;
|
||||
import org.jetbrains.jet.lang.psi.JetScript;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
@@ -39,7 +42,10 @@ import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.ref.JetTypeName;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ScriptHeaderResolver {
|
||||
|
||||
@@ -122,7 +128,9 @@ public class ScriptHeaderResolver {
|
||||
priority = 0;
|
||||
}
|
||||
|
||||
ScriptDescriptor scriptDescriptor = new ScriptDescriptor(ns, priority, script, outerScope);
|
||||
Name className = new FqName(ScriptNameUtil.classNameForScript((JetFile) script.getContainingFile()).replace('/', '.')).shortName();
|
||||
ScriptDescriptor scriptDescriptor = new ScriptDescriptor(ns, priority, outerScope, className);
|
||||
|
||||
//WriteThroughScope scriptScope = new WriteThroughScope(
|
||||
// outerScope, ns.getMemberScope(), new TraceBasedRedeclarationHandler(trace));
|
||||
WritableScopeImpl scriptScope = new WritableScopeImpl(outerScope, scriptDescriptor, RedeclarationHandler.DO_NOTHING, "script");
|
||||
|
||||
@@ -22,8 +22,6 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespaceHeader;
|
||||
|
||||
public class ScriptNameUtil {
|
||||
public static final String LAST_EXPRESSION_VALUE_FIELD_NAME = "rv";
|
||||
|
||||
private ScriptNameUtil() {
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WriteThroughScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.SubstitutionUtils;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
@@ -612,7 +615,7 @@ public class TypeHierarchyResolver {
|
||||
) {
|
||||
ConstructorDescriptorImpl constructorDescriptor = DescriptorResolver
|
||||
.createAndRecordPrimaryConstructorForObject(object, mutableClassDescriptor, trace);
|
||||
mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor, trace);
|
||||
mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor);
|
||||
return constructorDescriptor;
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ public class CallExpressionResolver {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetType getVariableType(@NotNull JetSimpleNameExpression nameExpression, @NotNull ReceiverValue receiver,
|
||||
private JetType getVariableType(@NotNull JetSimpleNameExpression nameExpression, @Nullable ReceiverValue receiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull ResolutionContext context, @NotNull boolean[] result
|
||||
) {
|
||||
TemporaryTraceAndCache temporaryForVariable = TemporaryTraceAndCache.create(
|
||||
@@ -218,9 +218,7 @@ public class CallExpressionResolver {
|
||||
return resolutionResult.isSingleResult() ? resolutionResult.getResultingDescriptor().getReturnType() : null;
|
||||
}
|
||||
|
||||
ResolutionContext newContext = receiver.exists()
|
||||
? context.replaceScope(receiver.getType().getMemberScope())
|
||||
: context;
|
||||
ResolutionContext newContext = receiver == null ? context : context.replaceScope(receiver.getType().getMemberScope());
|
||||
TemporaryTraceAndCache temporaryForNamespaceOrClassObject = TemporaryTraceAndCache.create(
|
||||
context, "trace to resolve as namespace or class object", nameExpression);
|
||||
JetType jetType = lookupNamespaceOrClassObject(nameExpression, newContext.replaceTraceAndCache(temporaryForNamespaceOrClassObject));
|
||||
@@ -241,7 +239,7 @@ public class CallExpressionResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetTypeInfo getSimpleNameExpressionTypeInfo(@NotNull JetSimpleNameExpression nameExpression, @NotNull ReceiverValue receiver,
|
||||
public JetTypeInfo getSimpleNameExpressionTypeInfo(@NotNull JetSimpleNameExpression nameExpression, @Nullable ReceiverValue receiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull ResolutionContext context
|
||||
) {
|
||||
boolean[] result = new boolean[1];
|
||||
@@ -278,7 +276,7 @@ public class CallExpressionResolver {
|
||||
|
||||
@NotNull
|
||||
public JetTypeInfo getCallExpressionTypeInfo(
|
||||
@NotNull JetCallExpression callExpression, @NotNull ReceiverValue receiver,
|
||||
@NotNull JetCallExpression callExpression, @Nullable ReceiverValue receiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull ResolutionContext context
|
||||
) {
|
||||
JetTypeInfo typeInfo = getCallExpressionTypeInfoWithoutFinalTypeCheck(
|
||||
@@ -291,7 +289,7 @@ public class CallExpressionResolver {
|
||||
|
||||
@NotNull
|
||||
public JetTypeInfo getCallExpressionTypeInfoWithoutFinalTypeCheck(
|
||||
@NotNull JetCallExpression callExpression, @NotNull ReceiverValue receiver,
|
||||
@NotNull JetCallExpression callExpression, @Nullable ReceiverValue receiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull ResolutionContext context
|
||||
) {
|
||||
boolean[] result = new boolean[1];
|
||||
@@ -335,8 +333,10 @@ public class CallExpressionResolver {
|
||||
return JetTypeInfo.create(null, context.dataFlowInfo);
|
||||
}
|
||||
|
||||
private void checkSuper(@NotNull ReceiverValue receiverValue, @NotNull OverloadResolutionResults<? extends CallableDescriptor> results,
|
||||
@NotNull BindingTrace trace, @NotNull JetExpression expression) {
|
||||
private static void checkSuper(
|
||||
@Nullable ReceiverValue receiverValue, @NotNull OverloadResolutionResults<?> results,
|
||||
@NotNull BindingTrace trace, @NotNull JetExpression expression
|
||||
) {
|
||||
if (!results.isSingleResult()) return;
|
||||
if (!(receiverValue instanceof ExpressionReceiver)) return;
|
||||
JetExpression receiver = ((ExpressionReceiver) receiverValue).getExpression();
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
@@ -186,7 +185,7 @@ public class CallResolver {
|
||||
JetValueArgumentList valueArgumentList = context.call.getValueArgumentList();
|
||||
PsiElement reportAbsenceOn = valueArgumentList == null ? context.call.getCallElement() : valueArgumentList;
|
||||
if (calleeExpression instanceof JetConstructorCalleeExpression) {
|
||||
assert !context.call.getExplicitReceiver().exists();
|
||||
assert context.call.getExplicitReceiver() == null;
|
||||
|
||||
JetConstructorCalleeExpression expression = (JetConstructorCalleeExpression) calleeExpression;
|
||||
functionReference = expression.getConstructorReferenceExpression();
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
@@ -101,7 +102,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
|
||||
|
||||
assert candidate.getDescriptor() instanceof VariableDescriptor;
|
||||
|
||||
boolean hasReceiver = candidate.getReceiverArgument().exists();
|
||||
boolean hasReceiver = candidate.getReceiverArgument() != null;
|
||||
Call variableCall = stripCallArguments(task);
|
||||
if (!hasReceiver) {
|
||||
CallCandidateResolutionContext<CallableDescriptor> context = CallCandidateResolutionContext.create(
|
||||
@@ -165,7 +166,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
|
||||
|
||||
private Call stripReceiver(@NotNull Call variableCall) {
|
||||
return new DelegatingCall(variableCall) {
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getExplicitReceiver() {
|
||||
return ReceiverValue.NO_RECEIVER;
|
||||
@@ -224,7 +225,7 @@ public class CallTransformer<D extends CallableDescriptor, F extends D> {
|
||||
this.receiverFromVariable = new ExpressionReceiver(task.reference, returnType);
|
||||
this.invokeExpression = (JetSimpleNameExpression) JetPsiFactory.createExpression(task.call.getCallElement().getProject(), "invoke");
|
||||
}
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getExplicitReceiver() {
|
||||
return context.receiverForVariableAsFunctionSecondCall;
|
||||
|
||||
@@ -25,7 +25,6 @@ import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.*;
|
||||
@@ -63,7 +62,7 @@ import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.PLACEHOLDER_
|
||||
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.RESOLVE_FUNCTION_ARGUMENTS;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.ResolveArgumentsMode.SKIP_FUNCTION_ARGUMENTS;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.CallTransformer.CallForImplicitInvoke;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.INDEPENDENT;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus.*;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
|
||||
@@ -185,7 +184,7 @@ public class CandidateResolver {
|
||||
|
||||
private static boolean checkOuterClassMemberIsAccessible(@NotNull CallCandidateResolutionContext<?> context) {
|
||||
// In "this@Outer.foo()" the error will be reported on "this@Outer" instead
|
||||
if (context.call.getExplicitReceiver().exists()) return true;
|
||||
if (context.call.getExplicitReceiver() != null) return true;
|
||||
|
||||
ClassDescriptor candidateThis = getDeclaringClass(context.candidateCall.getCandidateDescriptor());
|
||||
if (candidateThis == null || candidateThis.getKind().isObject()) return true;
|
||||
@@ -307,7 +306,8 @@ public class CandidateResolver {
|
||||
completeNestedCallsInference(context);
|
||||
List<JetType> argumentTypes = checkValueArgumentTypes(
|
||||
context, resolvedCall, context.trace, RESOLVE_FUNCTION_ARGUMENTS).argumentTypes;
|
||||
JetType receiverType = resolvedCall.getReceiverArgument().exists() ? resolvedCall.getReceiverArgument().getType() : null;
|
||||
ReceiverValue receiverArgument = resolvedCall.getReceiverArgument();
|
||||
JetType receiverType = receiverArgument != null ? receiverArgument.getType() : null;
|
||||
InferenceErrorData.ExtendedInferenceErrorData errorData = InferenceErrorData
|
||||
.create(resolvedCall.getCandidateDescriptor(), constraintSystem, argumentTypes, receiverType, context.expectedType);
|
||||
|
||||
@@ -574,7 +574,7 @@ public class CandidateResolver {
|
||||
// Error is already reported if something is missing
|
||||
ReceiverValue receiverArgument = candidateCall.getReceiverArgument();
|
||||
ReceiverParameterDescriptor receiverParameter = candidateWithFreshVariables.getReceiverParameter();
|
||||
if (receiverArgument.exists() && receiverParameter != null) {
|
||||
if (receiverArgument != null && receiverParameter != null) {
|
||||
JetType receiverType =
|
||||
context.candidateCall.isSafeCall()
|
||||
? TypeUtils.makeNotNullable(receiverArgument.getType())
|
||||
@@ -642,7 +642,7 @@ public class CandidateResolver {
|
||||
) {
|
||||
if (argumentExpression == null || type == null) return type;
|
||||
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(
|
||||
JetPsiUtil.unwrapFromBlock(argumentExpression), type, trace.getBindingContext());
|
||||
Set<JetType> possibleTypes = dataFlowInfoForArgument.getPossibleTypes(dataFlowValue);
|
||||
if (possibleTypes.isEmpty()) return type;
|
||||
@@ -784,15 +784,18 @@ public class CandidateResolver {
|
||||
|
||||
ReceiverParameterDescriptor receiverDescriptor = candidateDescriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor expectedThisObjectDescriptor = candidateDescriptor.getExpectedThisObject();
|
||||
ReceiverValue receiverArgument = candidateCall.getReceiverArgument();
|
||||
ReceiverValue thisObject = candidateCall.getThisObject();
|
||||
|
||||
ReceiverParameterDescriptor receiverParameterDescriptor;
|
||||
JetType receiverArgumentType;
|
||||
if (receiverDescriptor != null && candidateCall.getReceiverArgument().exists()) {
|
||||
if (receiverDescriptor != null && receiverArgument != null) {
|
||||
receiverParameterDescriptor = receiverDescriptor;
|
||||
receiverArgumentType = candidateCall.getReceiverArgument().getType();
|
||||
receiverArgumentType = receiverArgument.getType();
|
||||
}
|
||||
else if (expectedThisObjectDescriptor != null && candidateCall.getThisObject().exists()) {
|
||||
else if (expectedThisObjectDescriptor != null && thisObject != null) {
|
||||
receiverParameterDescriptor = expectedThisObjectDescriptor;
|
||||
receiverArgumentType = candidateCall.getThisObject().getType();
|
||||
receiverArgumentType = thisObject.getType();
|
||||
}
|
||||
else {
|
||||
return SUCCESS;
|
||||
@@ -812,11 +815,11 @@ public class CandidateResolver {
|
||||
@NotNull ResolvedCall<D> candidateCall,
|
||||
@NotNull BindingTrace trace,
|
||||
@Nullable ReceiverParameterDescriptor receiverParameter,
|
||||
@NotNull ReceiverValue receiverArgument,
|
||||
@Nullable ReceiverValue receiverArgument,
|
||||
boolean isExplicitReceiver,
|
||||
boolean implicitInvokeCheck
|
||||
) {
|
||||
if (receiverParameter == null || !receiverArgument.exists()) return SUCCESS;
|
||||
if (receiverParameter == null || receiverArgument == null) return SUCCESS;
|
||||
|
||||
JetType receiverArgumentType = receiverArgument.getType();
|
||||
JetType effectiveReceiverArgumentType = TypeUtils.makeNotNullable(receiverArgumentType);
|
||||
@@ -835,7 +838,7 @@ public class CandidateResolver {
|
||||
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
|
||||
return UNSAFE_CALL_ERROR;
|
||||
}
|
||||
DataFlowValue receiverValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(receiverArgument, bindingContext);
|
||||
DataFlowValue receiverValue = DataFlowValueFactory.createDataFlowValue(receiverArgument, bindingContext);
|
||||
if (safeAccess && !context.dataFlowInfo.getNullability(receiverValue).canBeNull()) {
|
||||
context.tracing.unnecessarySafeCall(trace, receiverArgumentType);
|
||||
}
|
||||
|
||||
@@ -25,14 +25,19 @@ import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.Call;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.ValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
@@ -198,7 +203,7 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
reportUnmappedParameters();
|
||||
checkReceiverArgument();
|
||||
|
||||
assert (candidateCall.getThisObject().exists() == (candidateCall.getResultingDescriptor().getExpectedThisObject() != null))
|
||||
assert (candidateCall.getThisObject() != null) == (candidateCall.getResultingDescriptor().getExpectedThisObject() != null)
|
||||
: "Shouldn't happen because of TaskPrioritizer: " + candidateCall.getCandidateDescriptor();
|
||||
}
|
||||
|
||||
@@ -263,11 +268,11 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
|
||||
ReceiverParameterDescriptor receiverParameter = candidate.getReceiverParameter();
|
||||
ReceiverValue receiverArgument = candidateCall.getReceiverArgument();
|
||||
if (receiverParameter != null &&!receiverArgument.exists()) {
|
||||
if (receiverParameter != null && receiverArgument == null) {
|
||||
tracing.missingReceiver(candidateCall.getTrace(), receiverParameter);
|
||||
setStatus(ERROR);
|
||||
}
|
||||
if (receiverParameter == null && receiverArgument.exists()) {
|
||||
else if (receiverParameter == null && receiverArgument != null) {
|
||||
tracing.noReceiverAllowed(candidateCall.getTrace());
|
||||
if (call.getCalleeExpression() instanceof JetSimpleNameExpression) {
|
||||
setStatus(STRONG_ERROR);
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.calls.autocasts;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.AbstractReceiverValue;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValueVisitor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public class AutoCastReceiver extends AbstractReceiverValue {
|
||||
@@ -41,11 +40,6 @@ public class AutoCastReceiver extends AbstractReceiverValue {
|
||||
return original;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull ReceiverValueVisitor<R, D> visitor, D data) {
|
||||
return original.accept(visitor, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + original + " as " + getType() + ")";
|
||||
|
||||
@@ -16,15 +16,19 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls.autocasts;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ThisReceiver;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.AUTOCAST_IMPOSSIBLE;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.AUTOCAST;
|
||||
@@ -37,59 +41,44 @@ public class AutoCastUtils {
|
||||
/**
|
||||
* @return variants @param receiverToCast may be cast to according to @param dataFlowInfo, @param receiverToCast itself is NOT included
|
||||
*/
|
||||
@NotNull
|
||||
public static List<ReceiverValue> getAutoCastVariants(
|
||||
@NotNull final BindingContext bindingContext,
|
||||
@NotNull final DataFlowInfo dataFlowInfo, @NotNull ReceiverValue receiverToCast
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull ReceiverValue receiverToCast
|
||||
) {
|
||||
return receiverToCast.accept(new ReceiverValueVisitor<List<ReceiverValue>, Object>() {
|
||||
@Override
|
||||
public List<ReceiverValue> visitNoReceiver(ReceiverValue noReceiver, Object data) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReceiverValue> visitTransientReceiver(TransientReceiver receiver, Object data) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReceiverValue> visitExtensionReceiver(ExtensionReceiver receiver, Object data) {
|
||||
return castThis(dataFlowInfo, receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReceiverValue> visitClassReceiver(ClassReceiver receiver, Object data) {
|
||||
return castThis(dataFlowInfo, receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReceiverValue> visitScriptReceiver(ScriptReceiver receiver, Object data) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReceiverValue> visitExpressionReceiver(ExpressionReceiver receiver, Object data) {
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(receiver.getExpression(), receiver.getType(),
|
||||
bindingContext);
|
||||
List<ReceiverValue> result = Lists.newArrayList();
|
||||
for (JetType possibleType : dataFlowInfo.getPossibleTypes(dataFlowValue)) {
|
||||
result.add(new AutoCastReceiver(receiver, possibleType, dataFlowValue.isStableIdentifier()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}, null);
|
||||
if (receiverToCast instanceof ThisReceiver) {
|
||||
ThisReceiver receiver = (ThisReceiver) receiverToCast;
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver);
|
||||
return collectAutoCastReceiverValues(dataFlowInfo, receiver, dataFlowValue);
|
||||
}
|
||||
else if (receiverToCast instanceof ExpressionReceiver) {
|
||||
ExpressionReceiver receiver = (ExpressionReceiver) receiverToCast;
|
||||
DataFlowValue dataFlowValue =
|
||||
DataFlowValueFactory.createDataFlowValue(receiver.getExpression(), receiver.getType(), bindingContext);
|
||||
return collectAutoCastReceiverValues(dataFlowInfo, receiver, dataFlowValue);
|
||||
}
|
||||
else if (receiverToCast instanceof AutoCastReceiver) {
|
||||
return getAutoCastVariants(bindingContext, dataFlowInfo, ((AutoCastReceiver) receiverToCast).getOriginal());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static List<ReceiverValue> castThis(@NotNull DataFlowInfo dataFlowInfo, @NotNull ThisReceiver receiver) {
|
||||
assert receiver.exists();
|
||||
List<ReceiverValue> result = Lists.newArrayList();
|
||||
for (JetType possibleType : dataFlowInfo.getPossibleTypes(DataFlowValueFactory.INSTANCE.createDataFlowValue(receiver))) {
|
||||
result.add(new AutoCastReceiver(receiver, possibleType, true));
|
||||
@NotNull
|
||||
private static List<ReceiverValue> collectAutoCastReceiverValues(
|
||||
@NotNull DataFlowInfo dataFlowInfo,
|
||||
@NotNull ReceiverValue receiver,
|
||||
@NotNull DataFlowValue dataFlowValue
|
||||
) {
|
||||
Set<JetType> possibleTypes = dataFlowInfo.getPossibleTypes(dataFlowValue);
|
||||
List<ReceiverValue> result = new ArrayList<ReceiverValue>(possibleTypes.size());
|
||||
for (JetType possibleType : possibleTypes) {
|
||||
result.add(new AutoCastReceiver(receiver, possibleType, dataFlowValue.isStableIdentifier()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void recordAutoCastIfNecessary(ReceiverValue receiver, @NotNull BindingTrace trace) {
|
||||
public static void recordAutoCastIfNecessary(@Nullable ReceiverValue receiver, @NotNull BindingTrace trace) {
|
||||
if (receiver instanceof AutoCastReceiver) {
|
||||
AutoCastReceiver autoCastReceiver = (AutoCastReceiver) receiver;
|
||||
ReceiverValue original = autoCastReceiver.getOriginal();
|
||||
|
||||
@@ -30,18 +30,18 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
||||
|
||||
public class DataFlowValueFactory {
|
||||
public static final DataFlowValueFactory INSTANCE = new DataFlowValueFactory();
|
||||
|
||||
private DataFlowValueFactory() {}
|
||||
|
||||
@NotNull
|
||||
public DataFlowValue createDataFlowValue(@NotNull JetExpression expression, @NotNull JetType type, @NotNull BindingContext bindingContext) {
|
||||
public static DataFlowValue createDataFlowValue(
|
||||
@NotNull JetExpression expression,
|
||||
@NotNull JetType type,
|
||||
@NotNull BindingContext bindingContext
|
||||
) {
|
||||
if (expression instanceof JetConstantExpression) {
|
||||
JetConstantExpression constantExpression = (JetConstantExpression) expression;
|
||||
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
|
||||
@@ -52,60 +52,34 @@ public class DataFlowValueFactory {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DataFlowValue createDataFlowValue(@NotNull ThisReceiver receiver) {
|
||||
public static DataFlowValue createDataFlowValue(@NotNull ThisReceiver receiver) {
|
||||
JetType type = receiver.getType();
|
||||
return new DataFlowValue(receiver, type, true, getImmanentNullability(type));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DataFlowValue createDataFlowValue(@NotNull VariableDescriptor variableDescriptor) {
|
||||
JetType type = variableDescriptor.getType();
|
||||
return new DataFlowValue(variableDescriptor, type, isStableVariable(variableDescriptor), getImmanentNullability(type));
|
||||
public static DataFlowValue createDataFlowValue(@NotNull ReceiverValue receiverValue, @NotNull BindingContext bindingContext) {
|
||||
if (receiverValue instanceof TransientReceiver || receiverValue instanceof ScriptReceiver) {
|
||||
JetType type = receiverValue.getType();
|
||||
boolean nullable = type.isNullable() || TypeUtils.hasNullableSuperType(type);
|
||||
return new DataFlowValue(receiverValue, type, nullable, Nullability.NOT_NULL);
|
||||
}
|
||||
else if (receiverValue instanceof ClassReceiver || receiverValue instanceof ExtensionReceiver) {
|
||||
return createDataFlowValue((ThisReceiver) receiverValue);
|
||||
}
|
||||
else if (receiverValue instanceof ExpressionReceiver) {
|
||||
return createDataFlowValue(((ExpressionReceiver) receiverValue).getExpression(), receiverValue.getType(), bindingContext);
|
||||
}
|
||||
else if (receiverValue instanceof AutoCastReceiver) {
|
||||
return createDataFlowValue(((AutoCastReceiver) receiverValue).getOriginal(), bindingContext);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Unsupported receiver value: " + receiverValue.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DataFlowValue createDataFlowValue(@NotNull ReceiverValue receiverValue, @NotNull BindingContext bindingContext) {
|
||||
return receiverValue.accept(new ReceiverValueVisitor<DataFlowValue, BindingContext>() {
|
||||
@Override
|
||||
public DataFlowValue visitNoReceiver(ReceiverValue noReceiver, BindingContext data) {
|
||||
throw new IllegalArgumentException("No DataFlowValue exists for ReceiverValue.NO_RECEIVER");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlowValue visitExtensionReceiver(ExtensionReceiver receiver, BindingContext data) {
|
||||
return createDataFlowValue(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlowValue visitExpressionReceiver(ExpressionReceiver receiver, BindingContext bindingContext) {
|
||||
return createDataFlowValue(receiver.getExpression(), receiver.getType(), bindingContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlowValue visitClassReceiver(ClassReceiver receiver, BindingContext data) {
|
||||
return createDataFlowValue(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlowValue visitTransientReceiver(TransientReceiver receiver, BindingContext data) {
|
||||
return createTransientDataFlowValue(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFlowValue visitScriptReceiver(ScriptReceiver receiver, BindingContext data) {
|
||||
return createTransientDataFlowValue(receiver);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DataFlowValue createTransientDataFlowValue(ReceiverValue receiver) {
|
||||
JetType type = receiver.getType();
|
||||
boolean nullable = type.isNullable() || TypeUtils.hasNullableSuperType(type);
|
||||
return new DataFlowValue(receiver, type, nullable, Nullability.NOT_NULL);
|
||||
}
|
||||
}, bindingContext);
|
||||
}
|
||||
|
||||
private Nullability getImmanentNullability(JetType type) {
|
||||
private static Nullability getImmanentNullability(@NotNull JetType type) {
|
||||
return type.isNullable() || TypeUtils.hasNullableSuperType(type) ? Nullability.UNKNOWN : Nullability.NOT_NULL;
|
||||
}
|
||||
|
||||
@@ -208,46 +182,19 @@ public class DataFlowValueFactory {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IdentifierInfo getIdForImplicitReceiver(@NotNull ReceiverValue receiverValue, @Nullable final JetExpression expression) {
|
||||
return receiverValue.accept(new ReceiverValueVisitor<IdentifierInfo, Void>() {
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitNoReceiver(ReceiverValue noReceiver, Void data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitTransientReceiver(TransientReceiver receiver, Void data) {
|
||||
assert false: "Transient receiver is implicit for an explicit expression: " + expression + ". Receiver: " + receiver;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitExtensionReceiver(ExtensionReceiver receiver, Void data) {
|
||||
return getIdForThisReceiver(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitExpressionReceiver(ExpressionReceiver receiver, Void data) {
|
||||
// there is an explicit "this" expression and it was analyzed earlier
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitClassReceiver(ClassReceiver receiver, Void data) {
|
||||
return getIdForThisReceiver(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitScriptReceiver(ScriptReceiver receiver, Void data) {
|
||||
return getIdForThisReceiver(receiver);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierInfo getIdForThisReceiver(@NotNull ThisReceiver thisReceiver) {
|
||||
return getIdForThisReceiver(thisReceiver.getDeclarationDescriptor());
|
||||
private static IdentifierInfo getIdForImplicitReceiver(@Nullable ReceiverValue receiverValue, @Nullable JetExpression expression) {
|
||||
if (receiverValue instanceof ThisReceiver) {
|
||||
return getIdForThisReceiver(((ThisReceiver) receiverValue).getDeclarationDescriptor());
|
||||
}
|
||||
else if (receiverValue instanceof AutoCastReceiver) {
|
||||
return getIdForImplicitReceiver(((AutoCastReceiver) receiverValue).getOriginal(), expression);
|
||||
}
|
||||
else {
|
||||
assert !(receiverValue instanceof TransientReceiver)
|
||||
: "Transient receiver is implicit for an explicit expression: " + expression + ". Receiver: " + receiverValue;
|
||||
// For ExpressionReceiver there is an explicit "this" expression and it was analyzed earlier
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.resolve.calls.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
@@ -46,13 +47,13 @@ public abstract class DelegatingResolvedCall<D extends CallableDescriptor> imple
|
||||
return resolvedCall.getResultingDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getReceiverArgument() {
|
||||
return resolvedCall.getReceiverArgument();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getThisObject() {
|
||||
return resolvedCall.getThisObject();
|
||||
|
||||
@@ -21,8 +21,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.ValueArgument;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -40,11 +38,11 @@ public interface ResolvedCall<D extends CallableDescriptor> {
|
||||
D getResultingDescriptor();
|
||||
|
||||
/** If the target was an extension function or property, this is the value for its receiver parameter */
|
||||
@NotNull
|
||||
@Nullable
|
||||
ReceiverValue getReceiverArgument();
|
||||
|
||||
/** If the target was a member of a class, this is the object of that class to call it on */
|
||||
@NotNull
|
||||
@Nullable
|
||||
ReceiverValue getThisObject();
|
||||
|
||||
/** Determines whether receiver argument or this object is substituted for explicit receiver */
|
||||
|
||||
@@ -200,13 +200,13 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@Nullable
|
||||
public ReceiverValue getReceiverArgument() {
|
||||
return receiverArgument;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@Nullable
|
||||
public ReceiverValue getThisObject() {
|
||||
return thisObject;
|
||||
}
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
package org.jetbrains.jet.lang.resolve.calls.model;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
|
||||
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
@@ -60,13 +61,13 @@ public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<Fun
|
||||
return functionCall.getResultingDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getReceiverArgument() {
|
||||
return variableCall.getReceiverArgument();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getThisObject() {
|
||||
return variableCall.getThisObject();
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
@@ -81,16 +80,19 @@ public class CallableDescriptorCollectors {
|
||||
}
|
||||
|
||||
private static class VariableCollector implements CallableDescriptorCollector<VariableDescriptor> {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VariableDescriptor> getNonExtensionsByName(JetScope scope, Name name) {
|
||||
VariableDescriptor descriptor = scope.getLocalVariable(name);
|
||||
if (descriptor == null) {
|
||||
descriptor = DescriptorUtils.filterNonExtensionProperty(scope.getProperties(name));
|
||||
if (descriptor != null) {
|
||||
return Collections.singleton(descriptor);
|
||||
}
|
||||
if (descriptor == null) return Collections.emptyList();
|
||||
return Collections.singleton(descriptor);
|
||||
for (VariableDescriptor variable : scope.getProperties(name)) {
|
||||
if (variable.getReceiverParameter() == null) {
|
||||
return Collections.singleton(variable);
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ResolutionCandidate<D extends CallableDescriptor> {
|
||||
private ExplicitReceiverKind explicitReceiverKind;
|
||||
private Boolean isSafeCall;
|
||||
|
||||
private ResolutionCandidate(@NotNull D descriptor, @NotNull ReceiverValue thisObject, @NotNull ReceiverValue receiverArgument,
|
||||
private ResolutionCandidate(@NotNull D descriptor, @Nullable ReceiverValue thisObject, @Nullable ReceiverValue receiverArgument,
|
||||
@NotNull ExplicitReceiverKind explicitReceiverKind, @Nullable Boolean isSafeCall) {
|
||||
this.candidateDescriptor = descriptor;
|
||||
this.thisObject = thisObject;
|
||||
@@ -52,8 +52,8 @@ public class ResolutionCandidate<D extends CallableDescriptor> {
|
||||
return new ResolutionCandidate<D>(descriptor, NO_RECEIVER, NO_RECEIVER, ExplicitReceiverKind.NO_EXPLICIT_RECEIVER, isSafeCall);
|
||||
}
|
||||
|
||||
public static <D extends CallableDescriptor> ResolutionCandidate<D> create(@NotNull D descriptor, @NotNull ReceiverValue thisObject,
|
||||
@NotNull ReceiverValue receiverArgument, @NotNull ExplicitReceiverKind explicitReceiverKind, boolean isSafeCall) {
|
||||
public static <D extends CallableDescriptor> ResolutionCandidate<D> create(@NotNull D descriptor, @Nullable ReceiverValue thisObject,
|
||||
@Nullable ReceiverValue receiverArgument, @NotNull ExplicitReceiverKind explicitReceiverKind, boolean isSafeCall) {
|
||||
return new ResolutionCandidate<D>(descriptor, thisObject, receiverArgument, explicitReceiverKind, isSafeCall);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ResolutionCandidate<D extends CallableDescriptor> {
|
||||
this.thisObject = thisObject;
|
||||
}
|
||||
|
||||
public void setReceiverArgument(@NotNull ReceiverValue receiverArgument) {
|
||||
public void setReceiverArgument(@Nullable ReceiverValue receiverArgument) {
|
||||
this.receiverArgument = receiverArgument;
|
||||
}
|
||||
|
||||
@@ -74,12 +74,12 @@ public class ResolutionCandidate<D extends CallableDescriptor> {
|
||||
return candidateDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public ReceiverValue getThisObject() {
|
||||
return thisObject;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public ReceiverValue getReceiverArgument() {
|
||||
return receiverArgument;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.isOrOverridesSynthesized;
|
||||
import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER;
|
||||
|
||||
public class TaskPrioritizer {
|
||||
@@ -63,7 +63,7 @@ public class TaskPrioritizer {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetSuperExpression getReceiverSuper(@NotNull ReceiverValue receiver) {
|
||||
public static JetSuperExpression getReceiverSuper(@Nullable ReceiverValue receiver) {
|
||||
if (receiver instanceof ExpressionReceiver) {
|
||||
ExpressionReceiver expressionReceiver = (ExpressionReceiver) receiver;
|
||||
JetExpression expression = expressionReceiver.getExpression();
|
||||
@@ -83,10 +83,10 @@ public class TaskPrioritizer {
|
||||
) {
|
||||
ReceiverValue explicitReceiver = context.call.getExplicitReceiver();
|
||||
JetScope scope;
|
||||
if (explicitReceiver.exists() && explicitReceiver.getType() instanceof NamespaceType) {
|
||||
if (explicitReceiver != null && explicitReceiver.getType() instanceof NamespaceType) {
|
||||
// Receiver is a namespace
|
||||
scope = explicitReceiver.getType().getMemberScope();
|
||||
explicitReceiver = NO_RECEIVER;
|
||||
explicitReceiver = null;
|
||||
}
|
||||
else {
|
||||
scope = context.scope;
|
||||
@@ -99,18 +99,18 @@ public class TaskPrioritizer {
|
||||
}
|
||||
|
||||
private static <D extends CallableDescriptor, F extends D> void doComputeTasks(
|
||||
@NotNull ReceiverValue receiver,
|
||||
@Nullable ReceiverValue receiver,
|
||||
@NotNull TaskPrioritizerContext<D, F> c
|
||||
) {
|
||||
ProgressIndicatorProvider.checkCanceled();
|
||||
|
||||
boolean resolveInvoke = c.context.call.getThisObject().exists();
|
||||
boolean resolveInvoke = c.context.call.getThisObject() != null;
|
||||
if (resolveInvoke) {
|
||||
addCandidatesForInvoke(receiver, c);
|
||||
return;
|
||||
}
|
||||
List<ReceiverValue> implicitReceivers = JetScopeUtils.getImplicitReceiversHierarchyValues(c.scope);
|
||||
if (receiver.exists()) {
|
||||
if (receiver != null) {
|
||||
addCandidatesForExplicitReceiver(receiver, implicitReceivers, c, /*resolveInvoke=*/false);
|
||||
return;
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class TaskPrioritizer {
|
||||
}
|
||||
|
||||
private static <D extends CallableDescriptor, F extends D> void addCandidatesForInvoke(
|
||||
@NotNull ReceiverValue explicitReceiver,
|
||||
@Nullable ReceiverValue explicitReceiver,
|
||||
@NotNull TaskPrioritizerContext<D, F> c
|
||||
) {
|
||||
List<ReceiverValue> implicitReceivers = JetScopeUtils.getImplicitReceiversHierarchyValues(c.scope);
|
||||
@@ -205,14 +205,14 @@ public class TaskPrioritizer {
|
||||
// For 'a.foo()' where foo has function type,
|
||||
// a is explicitReceiver, foo is variableReceiver.
|
||||
ReceiverValue variableReceiver = c.context.call.getThisObject();
|
||||
assert variableReceiver.exists() : "'Invoke' call hasn't got variable receiver";
|
||||
assert variableReceiver != null : "'Invoke' call hasn't got variable receiver";
|
||||
|
||||
// For invocation a.foo() explicit receiver 'a'
|
||||
// can be a receiver for 'foo' variable
|
||||
// or for 'invoke' function.
|
||||
|
||||
// (1) a.foo + foo.invoke()
|
||||
if (!explicitReceiver.exists()) {
|
||||
if (explicitReceiver == null) {
|
||||
addCandidatesForExplicitReceiver(variableReceiver, implicitReceivers, c, /*resolveInvoke=*/true);
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ public class TaskPrioritizer {
|
||||
//trait A
|
||||
//trait Foo { fun A.invoke() }
|
||||
|
||||
if (explicitReceiver.exists()) {
|
||||
if (explicitReceiver != null) {
|
||||
//a.foo()
|
||||
addCandidatesWhenInvokeIsMemberExtensionToExplicitReceiver(variableReceiver, explicitReceiver, c);
|
||||
return;
|
||||
@@ -292,13 +292,13 @@ public class TaskPrioritizer {
|
||||
ResolutionCandidate<D> candidate = ResolutionCandidate.create(descriptor);
|
||||
candidate.setReceiverArgument(receiverParameter);
|
||||
candidate.setExplicitReceiverKind(
|
||||
receiverParameter.exists() ? ExplicitReceiverKind.RECEIVER_ARGUMENT : ExplicitReceiverKind.NO_EXPLICIT_RECEIVER);
|
||||
receiverParameter != null ? ExplicitReceiverKind.RECEIVER_ARGUMENT : ExplicitReceiverKind.NO_EXPLICIT_RECEIVER);
|
||||
if (setImpliedThis(scope, candidate)) {
|
||||
result.add(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (receiverParameters.size() == 1 && !receiverParameters.iterator().next().exists()) {
|
||||
if (receiverParameters.size() == 1 && receiverParameters.iterator().next() == null) {
|
||||
for (D descriptor : descriptors) {
|
||||
if (descriptor.getExpectedThisObject() != null && descriptor.getReceiverParameter() == null) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
|
||||
@@ -23,8 +23,8 @@ import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.psi.Call.CallType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -82,7 +82,7 @@ public class CallMaker {
|
||||
this(callElement, explicitReceiver, callOperationNode, calleeExpression, valueArguments, CallType.DEFAULT);
|
||||
}
|
||||
|
||||
protected CallImpl(@NotNull PsiElement callElement, @NotNull ReceiverValue explicitReceiver, @Nullable ASTNode callOperationNode,
|
||||
protected CallImpl(@NotNull PsiElement callElement, @Nullable ReceiverValue explicitReceiver, @Nullable ASTNode callOperationNode,
|
||||
@Nullable JetExpression calleeExpression, @NotNull List<? extends ValueArgument> valueArguments, @NotNull CallType callType) {
|
||||
this.callElement = callElement;
|
||||
this.explicitReceiver = explicitReceiver;
|
||||
@@ -97,13 +97,13 @@ public class CallMaker {
|
||||
return callOperationNode;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getExplicitReceiver() {
|
||||
return explicitReceiver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getThisObject() {
|
||||
return ReceiverValue.NO_RECEIVER;
|
||||
@@ -159,13 +159,15 @@ public class CallMaker {
|
||||
}
|
||||
}
|
||||
|
||||
public static Call makeCallWithExpressions(@NotNull JetElement callElement, @NotNull ReceiverValue explicitReceiver,
|
||||
@NotNull
|
||||
public static Call makeCallWithExpressions(@NotNull JetElement callElement, @Nullable ReceiverValue explicitReceiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression,
|
||||
@NotNull List<JetExpression> argumentExpressions) {
|
||||
return makeCallWithExpressions(callElement, explicitReceiver, callOperationNode, calleeExpression, argumentExpressions, CallType.DEFAULT);
|
||||
}
|
||||
|
||||
public static Call makeCallWithExpressions(@NotNull JetElement callElement, @NotNull ReceiverValue explicitReceiver,
|
||||
@NotNull
|
||||
public static Call makeCallWithExpressions(@NotNull JetElement callElement, @Nullable ReceiverValue explicitReceiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression,
|
||||
@NotNull List<JetExpression> argumentExpressions, @NotNull CallType callType) {
|
||||
List<ValueArgument> arguments = Lists.newArrayList();
|
||||
@@ -175,11 +177,14 @@ public class CallMaker {
|
||||
return makeCall(callElement, explicitReceiver, callOperationNode, calleeExpression, arguments, callType);
|
||||
}
|
||||
|
||||
public static Call makeCall(JetElement callElement, ReceiverValue explicitReceiver, @Nullable ASTNode callOperationNode, JetExpression calleeExpression, List<? extends ValueArgument> arguments) {
|
||||
@NotNull
|
||||
public static Call makeCall(JetElement callElement, @Nullable ReceiverValue explicitReceiver, @Nullable ASTNode callOperationNode,
|
||||
JetExpression calleeExpression, List<? extends ValueArgument> arguments) {
|
||||
return makeCall(callElement, explicitReceiver, callOperationNode, calleeExpression, arguments, CallType.DEFAULT);
|
||||
}
|
||||
|
||||
public static Call makeCall(JetElement callElement, ReceiverValue explicitReceiver, @Nullable ASTNode callOperationNode,
|
||||
@NotNull
|
||||
public static Call makeCall(JetElement callElement, @Nullable ReceiverValue explicitReceiver, @Nullable ASTNode callOperationNode,
|
||||
JetExpression calleeExpression, List<? extends ValueArgument> arguments, CallType callType) {
|
||||
return new CallImpl(callElement, explicitReceiver, callOperationNode, calleeExpression, arguments, callType);
|
||||
}
|
||||
@@ -212,24 +217,25 @@ public class CallMaker {
|
||||
return new ExpressionValueArgument(expression, reportErrorsOn);
|
||||
}
|
||||
|
||||
public static Call makePropertyCall(@NotNull ReceiverValue explicitReceiver, @Nullable ASTNode callOperationNode, @NotNull JetSimpleNameExpression nameExpression) {
|
||||
public static Call makePropertyCall(@Nullable ReceiverValue explicitReceiver, @Nullable ASTNode callOperationNode, @NotNull JetSimpleNameExpression nameExpression) {
|
||||
return makeCallWithExpressions(nameExpression, explicitReceiver, callOperationNode, nameExpression, Collections.<JetExpression>emptyList());
|
||||
}
|
||||
|
||||
public static Call makeCall(@NotNull final ReceiverValue explicitReceiver, @Nullable final ASTNode callOperationNode, @NotNull final JetCallElement callElement) {
|
||||
@NotNull
|
||||
public static Call makeCall(@Nullable final ReceiverValue explicitReceiver, @Nullable final ASTNode callOperationNode, @NotNull final JetCallElement callElement) {
|
||||
return new Call() {
|
||||
@Override
|
||||
public ASTNode getCallOperationNode() {
|
||||
return callOperationNode;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getExplicitReceiver() {
|
||||
return explicitReceiver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getThisObject() {
|
||||
return ReceiverValue.NO_RECEIVER;
|
||||
|
||||
@@ -40,12 +40,12 @@ public class DelegatingCall implements Call {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@Nullable
|
||||
public ReceiverValue getExplicitReceiver() {
|
||||
return delegate.getExplicitReceiver();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getThisObject() {
|
||||
return delegate.getThisObject();
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFacto
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyClassDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.StorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.storage.LazyResolveStorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -57,7 +57,7 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
}
|
||||
};
|
||||
|
||||
private final StorageManager storageManager;
|
||||
private final LazyResolveStorageManager storageManager;
|
||||
|
||||
private final ModuleDescriptor module;
|
||||
private final LazyPackageDescriptor rootPackage;
|
||||
@@ -74,7 +74,7 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
|
||||
public ResolveSession(
|
||||
@NotNull Project project,
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull LazyResolveStorageManager storageManager,
|
||||
@NotNull ModuleDescriptorImpl rootDescriptor,
|
||||
@NotNull DeclarationProviderFactory declarationProviderFactory
|
||||
) {
|
||||
@@ -85,7 +85,7 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
|
||||
public ResolveSession(
|
||||
@NotNull Project project,
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull LazyResolveStorageManager storageManager,
|
||||
@NotNull ModuleDescriptorImpl rootDescriptor,
|
||||
@NotNull DeclarationProviderFactory declarationProviderFactory,
|
||||
@NotNull BindingTrace delegationTrace
|
||||
@@ -102,7 +102,7 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
@Deprecated // Internal use only
|
||||
public ResolveSession(
|
||||
@NotNull Project project,
|
||||
@NotNull StorageManager storageManager,
|
||||
@NotNull LazyResolveStorageManager storageManager,
|
||||
@NotNull ModuleDescriptorImpl rootDescriptor,
|
||||
@NotNull DeclarationProviderFactory declarationProviderFactory,
|
||||
@NotNull Function<FqName, Name> classifierAliases,
|
||||
@@ -138,7 +138,7 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public StorageManager getStorageManager() {
|
||||
public LazyResolveStorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.lazy.descriptors;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -39,7 +38,10 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValue;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescriptor, ClassMemberDeclarationProvider> {
|
||||
|
||||
@@ -101,12 +103,12 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
@NotNull final Collection<D> result,
|
||||
@NotNull final Class<? extends D> exactDescriptorClass
|
||||
) {
|
||||
OverrideResolver.generateOverridesInFunctionGroup(
|
||||
OverridingUtil.generateOverridesInFunctionGroup(
|
||||
name,
|
||||
fromSupertypes,
|
||||
Lists.newArrayList(result),
|
||||
thisDescriptor,
|
||||
new OverrideResolver.DescriptorSink() {
|
||||
new OverridingUtil.DescriptorSink() {
|
||||
@Override
|
||||
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
|
||||
assert exactDescriptorClass.isInstance(fakeOverride) : "Wrong descriptor type in an override: " +
|
||||
@@ -137,10 +139,9 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
// TODO: this should be handled by lazy function descriptors
|
||||
Set<FunctionDescriptor> functions = super.getFunctions(name);
|
||||
for (FunctionDescriptor functionDescriptor : functions) {
|
||||
if (functionDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) continue;
|
||||
PsiElement element =
|
||||
BindingContextUtils.callableDescriptorToDeclaration(resolveSession.getTrace().getBindingContext(), functionDescriptor);
|
||||
OverrideResolver.resolveUnknownVisibilityForMember((JetDeclaration) element, functionDescriptor, resolveSession.getTrace());
|
||||
if (functionDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||
OverrideResolver.resolveUnknownVisibilityForMember(functionDescriptor, resolveSession.getTrace());
|
||||
}
|
||||
}
|
||||
return functions;
|
||||
}
|
||||
@@ -192,12 +193,12 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
private void generateEnumClassObjectMethods(@NotNull Collection<? super FunctionDescriptor> result, @NotNull Name name) {
|
||||
if (!DescriptorUtils.isEnumClassObject(thisDescriptor)) return;
|
||||
|
||||
if (name.equals(DescriptorResolver.VALUES_METHOD_NAME)) {
|
||||
if (name.equals(DefaultDescriptorFactory.VALUES_METHOD_NAME)) {
|
||||
SimpleFunctionDescriptor valuesMethod = DescriptorResolver
|
||||
.createEnumClassObjectValuesMethod(thisDescriptor, resolveSession.getTrace());
|
||||
result.add(valuesMethod);
|
||||
}
|
||||
else if (name.equals(DescriptorResolver.VALUE_OF_METHOD_NAME)) {
|
||||
else if (name.equals(DefaultDescriptorFactory.VALUE_OF_METHOD_NAME)) {
|
||||
SimpleFunctionDescriptor valueOfMethod = DescriptorResolver
|
||||
.createEnumClassObjectValueOfMethod(thisDescriptor, resolveSession.getTrace());
|
||||
result.add(valueOfMethod);
|
||||
@@ -211,10 +212,9 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
Set<VariableDescriptor> properties = super.getProperties(name);
|
||||
for (VariableDescriptor variableDescriptor : properties) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) variableDescriptor;
|
||||
if (propertyDescriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) continue;
|
||||
PsiElement element =
|
||||
BindingContextUtils.callableDescriptorToDeclaration(resolveSession.getTrace().getBindingContext(), propertyDescriptor);
|
||||
OverrideResolver.resolveUnknownVisibilityForMember((JetDeclaration) element, propertyDescriptor, resolveSession.getTrace());
|
||||
if (propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
||||
OverrideResolver.resolveUnknownVisibilityForMember(propertyDescriptor, resolveSession.getTrace());
|
||||
}
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
@@ -291,8 +291,8 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
}
|
||||
}
|
||||
|
||||
result.addAll(getFunctions(DescriptorResolver.VALUES_METHOD_NAME));
|
||||
result.addAll(getFunctions(DescriptorResolver.VALUE_OF_METHOD_NAME));
|
||||
result.addAll(getFunctions(DefaultDescriptorFactory.VALUES_METHOD_NAME));
|
||||
result.addAll(getFunctions(DefaultDescriptorFactory.VALUE_OF_METHOD_NAME));
|
||||
|
||||
addDataClassMethods(result);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class LazyPackageDescriptor extends AbstractNamespaceDescriptorImpl imple
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), name);
|
||||
|
||||
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Package scope");
|
||||
resolveSession.getRootModuleDescriptor().getModuleConfiguration().extendNamespaceScope(resolveSession.getTrace(), this, scope);
|
||||
resolveSession.getRootModuleDescriptor().getModuleConfiguration().extendNamespaceScope(this, scope);
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
this.lazyScope = new LazyPackageMemberScope(resolveSession, declarationProvider, this);
|
||||
|
||||
@@ -14,13 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
package org.jetbrains.jet.lang.resolve.lazy.storage;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
public interface FqNamed {
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
|
||||
public interface LazyResolveStorageManager extends StorageManager {
|
||||
@NotNull
|
||||
FqName getFqName();
|
||||
BindingTrace createSafeTrace(@NotNull BindingTrace originalTrace);
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy.storage;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class LockBasedLazyResolveStorageManager extends LockBasedStorageManager implements LazyResolveStorageManager {
|
||||
@NotNull
|
||||
@Override
|
||||
public BindingTrace createSafeTrace(@NotNull BindingTrace originalTrace) {
|
||||
// It seems safe to have a separate lock for traces:
|
||||
// no other locks will be acquired inside the trace operations
|
||||
return new LockProtectedTrace(lock, originalTrace);
|
||||
}
|
||||
|
||||
private static class LockProtectedContext implements BindingContext {
|
||||
private final Object lock;
|
||||
private final BindingContext context;
|
||||
|
||||
private LockProtectedContext(Object lock, BindingContext context) {
|
||||
this.lock = lock;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
synchronized (lock) {
|
||||
return context.getDiagnostics();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
synchronized (lock) {
|
||||
return context.get(slice, key);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
|
||||
synchronized (lock) {
|
||||
return context.getKeys(slice);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@TestOnly
|
||||
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
|
||||
synchronized (lock) {
|
||||
return context.getSliceContents(slice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class LockProtectedTrace implements BindingTrace {
|
||||
private final Object lock;
|
||||
private final BindingTrace trace;
|
||||
private final BindingContext context;
|
||||
|
||||
public LockProtectedTrace(@NotNull Object lock, @NotNull BindingTrace trace) {
|
||||
this.lock = lock;
|
||||
this.trace = trace;
|
||||
this.context = new LockProtectedContext(lock, trace.getBindingContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindingContext getBindingContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
|
||||
synchronized (lock) {
|
||||
trace.record(slice, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K> void record(WritableSlice<K, Boolean> slice, K key) {
|
||||
synchronized (lock) {
|
||||
trace.record(slice, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
synchronized (lock) {
|
||||
return trace.get(slice, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
|
||||
synchronized (lock) {
|
||||
return trace.getKeys(slice);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(@NotNull Diagnostic diagnostic) {
|
||||
synchronized (lock) {
|
||||
trace.report(diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,29 +16,21 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy.storage;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ConcurrentWeakValueHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
import org.jetbrains.jet.utils.WrappedValues;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class LockBasedStorageManager implements StorageManager {
|
||||
|
||||
private final Object lock = new Object() {
|
||||
protected final Object lock = new Object() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LockBasedStorageManager centralized lock";
|
||||
@@ -103,14 +95,6 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public BindingTrace createSafeTrace(@NotNull BindingTrace originalTrace) {
|
||||
// It seems safe to have a separate lock for traces:
|
||||
// no other locks will be acquired inside the trace operations
|
||||
return new LockProtectedTrace(lock, originalTrace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T compute(@NotNull Computable<T> computable) {
|
||||
synchronized (lock) {
|
||||
@@ -228,101 +212,4 @@ public class LockBasedStorageManager implements StorageManager {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static class LockProtectedContext implements BindingContext {
|
||||
private final Object lock;
|
||||
private final BindingContext context;
|
||||
|
||||
private LockProtectedContext(Object lock, BindingContext context) {
|
||||
this.lock = lock;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Diagnostic> getDiagnostics() {
|
||||
synchronized (lock) {
|
||||
return context.getDiagnostics();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
synchronized (lock) {
|
||||
return context.get(slice, key);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
|
||||
synchronized (lock) {
|
||||
return context.getKeys(slice);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@TestOnly
|
||||
public <K, V> ImmutableMap<K, V> getSliceContents(@NotNull ReadOnlySlice<K, V> slice) {
|
||||
synchronized (lock) {
|
||||
return context.getSliceContents(slice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class LockProtectedTrace implements BindingTrace {
|
||||
private final Object lock;
|
||||
private final BindingTrace trace;
|
||||
private final BindingContext context;
|
||||
|
||||
public LockProtectedTrace(@NotNull Object lock, @NotNull BindingTrace trace) {
|
||||
this.lock = lock;
|
||||
this.trace = trace;
|
||||
this.context = new LockProtectedContext(lock, trace.getBindingContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindingContext getBindingContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
|
||||
synchronized (lock) {
|
||||
trace.record(slice, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K> void record(WritableSlice<K, Boolean> slice, K key) {
|
||||
synchronized (lock) {
|
||||
trace.record(slice, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
synchronized (lock) {
|
||||
return trace.get(slice, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public <K, V> Collection<K> getKeys(WritableSlice<K, V> slice) {
|
||||
synchronized (lock) {
|
||||
return trace.getKeys(slice);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void report(@NotNull Diagnostic diagnostic) {
|
||||
synchronized (lock) {
|
||||
trace.report(diagnostic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
|
||||
public interface StorageManager {
|
||||
/**
|
||||
@@ -56,9 +55,6 @@ public interface StorageManager {
|
||||
@NotNull
|
||||
<T> NullableLazyValue<T> createNullableLazyValueWithPostCompute(@NotNull Computable<T> computable, @NotNull Consumer<T> postCompute);
|
||||
|
||||
@NotNull
|
||||
BindingTrace createSafeTrace(@NotNull BindingTrace originalTrace);
|
||||
|
||||
<T> T compute(@NotNull Computable<T> computable);
|
||||
|
||||
enum ReferenceKind {
|
||||
|
||||
@@ -31,9 +31,4 @@ public abstract class AbstractReceiverValue implements ReceiverValue {
|
||||
public JetType getType() {
|
||||
return receiverType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,6 @@ public class ClassReceiver implements ThisReceiver {
|
||||
this.classDescriptor = classDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType() {
|
||||
@@ -45,11 +40,6 @@ public class ClassReceiver implements ThisReceiver {
|
||||
return classDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull ReceiverValueVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitClassReceiver(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Class{" + getType() + "}";
|
||||
|
||||
@@ -34,11 +34,6 @@ public class ExpressionReceiver extends AbstractReceiverValue implements Receive
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull ReceiverValueVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitExpressionReceiver(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getType() + " {" + expression + ": " + expression.getText() + "}";
|
||||
|
||||
@@ -36,11 +36,6 @@ public class ExtensionReceiver extends AbstractReceiverValue implements ThisRece
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull ReceiverValueVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitExtensionReceiver(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getType() + "Ext{" + descriptor + "}";
|
||||
|
||||
@@ -20,34 +20,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
public interface ReceiverValue {
|
||||
|
||||
ReceiverValue NO_RECEIVER = new ReceiverValue() {
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType() {
|
||||
throw new UnsupportedOperationException("NO_RECEIVER.getType()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull ReceiverValueVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitNoReceiver(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NO_RECEIVER";
|
||||
}
|
||||
};
|
||||
// This field exists for better readability of the client code
|
||||
ReceiverValue NO_RECEIVER = null;
|
||||
|
||||
@NotNull
|
||||
JetType getType();
|
||||
|
||||
boolean exists();
|
||||
|
||||
<R, D> R accept(@NotNull ReceiverValueVisitor<R, D> visitor, D data);
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.scopes.receivers;
|
||||
|
||||
public interface ReceiverValueVisitor<R, D> {
|
||||
R visitNoReceiver(ReceiverValue noReceiver, D data);
|
||||
|
||||
R visitTransientReceiver(TransientReceiver receiver, D data);
|
||||
|
||||
R visitExtensionReceiver(ExtensionReceiver receiver, D data);
|
||||
|
||||
R visitExpressionReceiver(ExpressionReceiver receiver, D data);
|
||||
|
||||
R visitClassReceiver(ClassReceiver receiver, D data);
|
||||
|
||||
R visitScriptReceiver(ScriptReceiver receiver, D data);
|
||||
}
|
||||
@@ -43,14 +43,4 @@ public class ScriptReceiver implements ThisReceiver {
|
||||
// not sure
|
||||
return KotlinBuiltIns.getInstance().getAnyType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull ReceiverValueVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitScriptReceiver(this, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,11 +28,6 @@ public class TransientReceiver extends AbstractReceiverValue {
|
||||
super(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(@NotNull ReceiverValueVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitTransientReceiver(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{Transient} : " + getType();
|
||||
|
||||
@@ -83,7 +83,7 @@ public final class JetTypeImpl extends AnnotatedImpl implements JetType {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return TypeUtils.toString(this);
|
||||
return JetTypeUtil.toString(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.types;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class JetTypeUtil {
|
||||
@NotNull
|
||||
public static String toString(@NotNull JetType type) {
|
||||
List<TypeProjection> arguments = type.getArguments();
|
||||
return type.getConstructor() +
|
||||
(arguments.isEmpty() ? "" : "<" + argumentsToString(arguments) + ">") +
|
||||
(type.isNullable() ? "?" : "");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static StringBuilder argumentsToString(@NotNull List<TypeProjection> arguments) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Iterator<TypeProjection> iterator = arguments.iterator(); iterator.hasNext();) {
|
||||
sb.append(iterator.next());
|
||||
if (iterator.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,10 @@ import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintResolutionListener;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemSolution;
|
||||
@@ -197,24 +200,6 @@ public class TypeUtils {
|
||||
new ChainedScope(null, scopes)); // TODO : check intersectibility, don't use a chanied scope
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toString(@NotNull JetType type) {
|
||||
List<TypeProjection> arguments = type.getArguments();
|
||||
return type.getConstructor() + (arguments.isEmpty() ? "" : "<" + argumentsToString(arguments) + ">") + (type.isNullable() ? "?" : "");
|
||||
}
|
||||
|
||||
private static StringBuilder argumentsToString(List<TypeProjection> arguments) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (Iterator<TypeProjection> iterator = arguments.iterator(); iterator.hasNext();) {
|
||||
TypeProjection argument = iterator.next();
|
||||
stringBuilder.append(argument);
|
||||
if (iterator.hasNext()) {
|
||||
stringBuilder.append(", ");
|
||||
}
|
||||
}
|
||||
return stringBuilder;
|
||||
}
|
||||
|
||||
private static class TypeUnifier {
|
||||
private static class TypeParameterUsage {
|
||||
private final TypeParameterDescriptor typeParameterDescriptor;
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
@@ -60,7 +59,9 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.utils.ThrowingList;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
@@ -183,7 +184,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
checkBinaryWithTypeRHS(expression, contextWithNoExpectedType, targetType, typeInfo.getType());
|
||||
dataFlowInfo = typeInfo.getDataFlowInfo();
|
||||
if (operationType == JetTokens.AS_KEYWORD) {
|
||||
DataFlowValue value = DataFlowValueFactory.INSTANCE.createDataFlowValue(left, typeInfo.getType(), context.trace.getBindingContext());
|
||||
DataFlowValue value = DataFlowValueFactory.createDataFlowValue(left, typeInfo.getType(), context.trace.getBindingContext());
|
||||
dataFlowInfo = dataFlowInfo.establishSubtyping(value, targetType);
|
||||
}
|
||||
}
|
||||
@@ -363,8 +364,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
}
|
||||
if (result != null) {
|
||||
if (DescriptorUtils.isKindOf(thisType, ClassKind.TRAIT)) {
|
||||
if (DescriptorUtils.isKindOf(result, ClassKind.CLASS)) {
|
||||
if (DescriptorUtils.isTrait(thisType.getConstructor().getDeclarationDescriptor())) {
|
||||
if (DescriptorUtils.isClass(result.getConstructor().getDeclarationDescriptor())) {
|
||||
context.trace.report(SUPERCLASS_NOT_ACCESSIBLE_FROM_TRAIT.on(expression));
|
||||
}
|
||||
}
|
||||
@@ -545,7 +546,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
@Nullable
|
||||
private static FunctionDescriptor resolveCallableNotCheckingArguments(
|
||||
@NotNull JetSimpleNameExpression reference,
|
||||
@NotNull ReceiverValue receiver,
|
||||
@Nullable ReceiverValue receiver,
|
||||
@NotNull ExpressionTypingContext context,
|
||||
@NotNull boolean[] result
|
||||
) {
|
||||
@@ -690,7 +691,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
context.trace.report(UNNECESSARY_NOT_NULL_ASSERTION.on(operationSign, baseType));
|
||||
}
|
||||
else {
|
||||
DataFlowValue value = DataFlowValueFactory.INSTANCE.createDataFlowValue(baseExpression, baseType, context.trace.getBindingContext());
|
||||
DataFlowValue value = DataFlowValueFactory.createDataFlowValue(baseExpression, baseType, context.trace.getBindingContext());
|
||||
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
|
||||
}
|
||||
return JetTypeInfo.create(TypeUtils.makeNotNullable(baseType), dataFlowInfo);
|
||||
@@ -718,7 +719,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
|
||||
private static boolean isKnownToBeNotNull(JetExpression expression, JetType jetType, ExpressionTypingContext context) {
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, jetType, context.trace.getBindingContext());
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, jetType, context.trace.getBindingContext());
|
||||
return !context.dataFlowInfo.getNullability(dataFlowValue).canBeNull();
|
||||
}
|
||||
|
||||
@@ -997,7 +998,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetType type = facade.getTypeInfo(expr, context).getType();
|
||||
if (type == null || ErrorUtils.isErrorType(type)) return;
|
||||
|
||||
DataFlowValue value = DataFlowValueFactory.INSTANCE.createDataFlowValue(expr, type, context.trace.getBindingContext());
|
||||
DataFlowValue value = DataFlowValueFactory.createDataFlowValue(expr, type, context.trace.getBindingContext());
|
||||
Nullability nullability = context.dataFlowInfo.getNullability(value);
|
||||
|
||||
boolean expressionIsAlways;
|
||||
|
||||
@@ -179,13 +179,13 @@ public class ControlStructureTypingUtils {
|
||||
return expression.getNode();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getExplicitReceiver() {
|
||||
return ReceiverValue.NO_RECEIVER;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverValue getThisObject() {
|
||||
return ReceiverValue.NO_RECEIVER;
|
||||
|
||||
@@ -542,7 +542,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
resultType = ErrorUtils.createErrorType(RETURN_NOT_ALLOWED_MESSAGE);
|
||||
}
|
||||
if (containingFunctionDescriptor != null) {
|
||||
expectedType = DescriptorUtils.getFunctionExpectedReturnType(containingFunctionDescriptor, (JetElement) containingFunction);
|
||||
expectedType = getFunctionExpectedReturnType(containingFunctionDescriptor, (JetElement) containingFunction);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -554,7 +554,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
else if (labelTargetElement != null) {
|
||||
SimpleFunctionDescriptor functionDescriptor = context.trace.get(FUNCTION, labelTargetElement);
|
||||
if (functionDescriptor != null) {
|
||||
expectedType = DescriptorUtils.getFunctionExpectedReturnType(functionDescriptor, labelTargetElement);
|
||||
expectedType = getFunctionExpectedReturnType(functionDescriptor, labelTargetElement);
|
||||
if (functionDescriptor != containingFunctionDescriptor) {
|
||||
// Qualified, non-local
|
||||
context.trace.report(RETURN_NOT_ALLOWED.on(expression));
|
||||
@@ -593,4 +593,21 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
context.labelResolver.resolveLabel(expression, context);
|
||||
return DataFlowUtils.checkType(KotlinBuiltIns.getInstance().getNothingType(), expression, context, context.dataFlowInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JetType getFunctionExpectedReturnType(@NotNull FunctionDescriptor descriptor, @NotNull JetElement function) {
|
||||
JetType expectedType;
|
||||
if (function instanceof JetFunction) {
|
||||
if (((JetFunction) function).getReturnTypeRef() != null || ((JetFunction) function).hasBlockBody()) {
|
||||
expectedType = descriptor.getReturnType();
|
||||
}
|
||||
else {
|
||||
expectedType = TypeUtils.NO_EXPECTED_TYPE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
expectedType = descriptor.getReturnType();
|
||||
}
|
||||
return expectedType != null ? expectedType : TypeUtils.NO_EXPECTED_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
|
||||
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.JetTypeInfo;
|
||||
@@ -87,8 +87,8 @@ public class DataFlowUtils {
|
||||
if (rhsType == null) return;
|
||||
|
||||
BindingContext bindingContext = context.trace.getBindingContext();
|
||||
DataFlowValue leftValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(left, lhsType, bindingContext);
|
||||
DataFlowValue rightValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(right, rhsType, bindingContext);
|
||||
DataFlowValue leftValue = DataFlowValueFactory.createDataFlowValue(left, lhsType, bindingContext);
|
||||
DataFlowValue rightValue = DataFlowValueFactory.createDataFlowValue(right, rhsType, bindingContext);
|
||||
|
||||
Boolean equals = null;
|
||||
if (operationToken == JetTokens.EQEQ || operationToken == JetTokens.EQEQEQ) {
|
||||
@@ -168,7 +168,7 @@ public class DataFlowUtils {
|
||||
return expressionType;
|
||||
}
|
||||
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.INSTANCE.createDataFlowValue(expression, expressionType, trace.getBindingContext());
|
||||
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, expressionType, trace.getBindingContext());
|
||||
for (JetType possibleType : dataFlowInfo.getPossibleTypes(dataFlowValue)) {
|
||||
if (JetTypeChecker.INSTANCE.isSubtypeOf(possibleType, expectedType)) {
|
||||
if (dataFlowValue.isStableIdentifier()) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user