Merge branch 'master' of ssh://git.labs.intellij.net/jet
This commit is contained in:
+3
@@ -85,6 +85,9 @@ public class JavaClassMembersScope implements JetScope {
|
||||
}
|
||||
|
||||
for (PsiField field : psiClass.getAllFields()) {
|
||||
if (field.hasModifierProperty(PsiModifier.STATIC) != staticMembers) {
|
||||
continue;
|
||||
}
|
||||
VariableDescriptor variableDescriptor = semanticServices.getDescriptorResolver().resolveFieldToVariableDescriptor(containingDeclaration, field);
|
||||
allDescriptors.add(variableDescriptor);
|
||||
}
|
||||
|
||||
@@ -11,4 +11,7 @@ public interface CallableMemberDescriptor extends CallableDescriptor, MemberDesc
|
||||
@NotNull
|
||||
@Override
|
||||
Set<? extends CallableMemberDescriptor> getOverriddenDescriptors();
|
||||
|
||||
@NotNull
|
||||
CallableMemberDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract);
|
||||
}
|
||||
|
||||
+7
-1
@@ -28,7 +28,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public FunctionDescriptorImpl initialize(@Nullable JetType receiverType, @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, @Nullable JetType unsubstitutedReturnType, Modality modality, Visibility visibility) {
|
||||
public FunctionDescriptorImpl initialize(@Nullable JetType receiverType, @NotNull List<TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, @Nullable JetType unsubstitutedReturnType, Modality modality, @NotNull Visibility visibility) {
|
||||
assert receiverType == null;
|
||||
return super.initialize(null, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType, modality, visibility);
|
||||
}
|
||||
@@ -78,4 +78,10 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO
|
||||
isPrimary);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstructorDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
throw new UnsupportedOperationException("Constructors should not be copied for overriding");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,8 @@ public interface FunctionDescriptor extends CallableMemberDescriptor {
|
||||
@Override
|
||||
@NotNull
|
||||
Set<? extends FunctionDescriptor> getOverriddenDescriptors();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract);
|
||||
}
|
||||
|
||||
+15
-20
@@ -5,6 +5,7 @@ import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
|
||||
@@ -175,24 +176,18 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
|
||||
return visitor.visitFunctionDescriptor(this, data);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean equals(Object obj) {
|
||||
// if (obj == null) return false;
|
||||
// if (obj.getClass() != FunctionDescriptorImpl.class) return false;
|
||||
// FunctionDescriptorImpl other = (FunctionDescriptorImpl) obj;
|
||||
// if (!eq(this.getName(), other.getName())) return false;
|
||||
// if (!eq(this.getContainingDeclaration(), other.getContainingDeclaration())) return false;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private static boolean eq(Object a, Object b) {
|
||||
// if (a == null) return b == null;
|
||||
// if (b == null) return false;
|
||||
// return a.equals(b);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int hashCode() {
|
||||
// return super.hashCode(); // TODO
|
||||
// }
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
FunctionDescriptorImpl copy = new FunctionDescriptorImpl(newOwner, Lists.newArrayList(getAnnotations()), getName());
|
||||
copy.initialize(
|
||||
getReceiver().exists() ? getReceiver().getType() : null,
|
||||
DescriptorUtils.copyTypeParameters(copy, typeParameters),
|
||||
DescriptorUtils.copyValueParameters(copy, unsubstitutedValueParameters),
|
||||
unsubstitutedReturnType,
|
||||
DescriptorUtils.convertModality(modality, makeNonAbstract),
|
||||
visibility
|
||||
);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ public enum Modality {
|
||||
OPEN(true),
|
||||
ABSTRACT(true);
|
||||
|
||||
private final boolean open;
|
||||
private final boolean overridable;
|
||||
|
||||
private Modality(boolean open) {
|
||||
this.open = open;
|
||||
private Modality(boolean overridable) {
|
||||
this.overridable = overridable;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return open;
|
||||
public boolean isOverridable() {
|
||||
return overridable;
|
||||
}
|
||||
|
||||
public static Modality convertFromFlags(boolean _abstract, boolean open) {
|
||||
|
||||
+1
-1
@@ -172,7 +172,7 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
||||
this.typeConstructor = new TypeConstructorImpl(
|
||||
this,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO : pass annotations from the class?
|
||||
!modality.isOpen(),
|
||||
!modality.isOverridable(),
|
||||
getName(),
|
||||
typeParameters,
|
||||
supertypes);
|
||||
|
||||
+6
@@ -76,4 +76,10 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
|
||||
public PropertyDescriptor getCorrespondingProperty() {
|
||||
return correspondingProperty;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyAccessorDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
throw new UnsupportedOperationException("Accessors must be copied by the corresponding property");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -168,5 +169,27 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@Override
|
||||
public Set<? extends PropertyDescriptor> getOverriddenDescriptors() {
|
||||
return overriddenProperties;
|
||||
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||
newOwner,
|
||||
Lists.newArrayList(getAnnotations()),
|
||||
DescriptorUtils.convertModality(modality, makeNonAbstract), visibility, isVar,
|
||||
receiver.exists() ? receiver.getType() : null, getName(), getInType(), getOutType());
|
||||
PropertyGetterDescriptor newGetter = getter == null ? null : new PropertyGetterDescriptor(
|
||||
propertyDescriptor, Lists.newArrayList(getter.getAnnotations()),
|
||||
DescriptorUtils.convertModality(getter.getModality(), makeNonAbstract), getter.getVisibility(),
|
||||
getter.getReturnType(),
|
||||
getter.hasBody(), getter.isDefault());
|
||||
PropertySetterDescriptor newSetter = setter == null ? null : new PropertySetterDescriptor(
|
||||
DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(),
|
||||
propertyDescriptor,
|
||||
Lists.newArrayList(setter.getAnnotations()),
|
||||
setter.hasBody(), setter.isDefault());;
|
||||
propertyDescriptor.initialize(DescriptorUtils.copyTypeParameters(propertyDescriptor, getTypeParameters()), newGetter, newSetter);
|
||||
return propertyDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
||||
private final Set<PropertyGetterDescriptor> overriddenGetters = Sets.newHashSet();
|
||||
private JetType returnType;
|
||||
|
||||
public PropertyGetterDescriptor(@NotNull Modality modality, @NotNull Visibility visibility, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, @Nullable JetType returnType, boolean hasBody, boolean isDefault) {
|
||||
public PropertyGetterDescriptor(@NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, @NotNull Modality modality, @NotNull Visibility visibility, @Nullable JetType returnType, boolean hasBody, boolean isDefault) {
|
||||
super(modality, visibility, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody, isDefault);
|
||||
this.returnType = returnType == null ? correspondingProperty.getOutType() : returnType;
|
||||
}
|
||||
|
||||
@@ -64,5 +64,4 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitPropertySetterDescriptor(this, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -157,4 +158,9 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public TypeParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
|
||||
return new TypeParameterDescriptor(newOwner, Lists.newArrayList(getAnnotations()), variance, getName(), index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,7 @@ public interface ValueParameterDescriptor extends VariableDescriptor {
|
||||
|
||||
@Override
|
||||
ValueParameterDescriptor getOriginal();
|
||||
|
||||
@NotNull
|
||||
ValueParameterDescriptor copy(DeclarationDescriptor newOwner);
|
||||
}
|
||||
|
||||
+8
-1
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -96,9 +97,15 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitValueParameterDescriptor(this, data);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isVar() {
|
||||
return isVar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
|
||||
return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), getName(), getInType(), getOutType(), hasDefaultValue, isVararg);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -31,4 +31,10 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
public VariableDescriptor getVariableDescriptor() {
|
||||
return variableDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VariableAsFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
throw new UnsupportedOperationException("Should not be copied for overriding");
|
||||
}
|
||||
}
|
||||
@@ -140,6 +140,7 @@ public interface Errors {
|
||||
SimpleDiagnosticFactory MANY_CLASS_OBJECTS = SimpleDiagnosticFactory.create(ERROR, "Only one class object is allowed per class");
|
||||
SimpleDiagnosticFactory CLASS_OBJECT_NOT_ALLOWED = SimpleDiagnosticFactory.create(ERROR, "A class object is not allowed here");
|
||||
SimpleDiagnosticFactory DELEGATION_IN_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Traits cannot use delegation");
|
||||
SimpleDiagnosticFactory DELEGATION_NOT_TO_TRAIT = SimpleDiagnosticFactory.create(ERROR, "Only traits can be delegated to");
|
||||
SimpleDiagnosticFactory NO_CONSTRUCTOR = SimpleDiagnosticFactory.create(ERROR, "This class does not have a constructor");
|
||||
SimpleDiagnosticFactory NOT_A_CLASS = SimpleDiagnosticFactory.create(ERROR, "Not a class");
|
||||
SimpleDiagnosticFactory ILLEGAL_ESCAPE_SEQUENCE = SimpleDiagnosticFactory.create(ERROR, "Illegal escape sequence");
|
||||
@@ -314,6 +315,7 @@ public interface Errors {
|
||||
}
|
||||
};
|
||||
|
||||
ParameterizedDiagnosticFactory2<PropertyDescriptor, PropertyDescriptor> VAR_OVERRIDDEN_BY_VAL = new ParameterizedDiagnosticFactory2<PropertyDescriptor, PropertyDescriptor>(ERROR, "Var-property {0} cannot be overridden by val-property {1}", DescriptorRenderer.TEXT);
|
||||
|
||||
ParameterizedDiagnosticFactory2<JetClassOrObject, CallableMemberDescriptor> ABSTRACT_MEMBER_NOT_IMPLEMENTED = new ParameterizedDiagnosticFactory2<JetClassOrObject, CallableMemberDescriptor>(ERROR, "Class ''{0}'' must be declared abstract or implement abstract member {1}") {
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.lang.psi;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -11,6 +12,11 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.JetNodeTypes.PROPERTY_ACCESSOR;
|
||||
import static org.jetbrains.jet.lexer.JetTokens.EQ;
|
||||
import static org.jetbrains.jet.lexer.JetTokens.VAL_KEYWORD;
|
||||
import static org.jetbrains.jet.lexer.JetTokens.VAR_KEYWORD;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
@@ -69,7 +75,7 @@ public class JetProperty extends JetTypeParameterListOwner implements JetModifie
|
||||
|
||||
@NotNull
|
||||
public List<JetPropertyAccessor> getAccessors() {
|
||||
return findChildrenByType(JetNodeTypes.PROPERTY_ACCESSOR);
|
||||
return findChildrenByType(PROPERTY_ACCESSOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -92,7 +98,12 @@ public class JetProperty extends JetTypeParameterListOwner implements JetModifie
|
||||
|
||||
@Nullable
|
||||
public JetExpression getInitializer() {
|
||||
PsiElement eq = findChildByType(JetTokens.EQ);
|
||||
PsiElement eq = findChildByType(EQ);
|
||||
return PsiTreeUtil.getNextSiblingOfType(eq, JetExpression.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ASTNode getValOrVarNode() {
|
||||
return getNode().findChildByType(TokenSet.create(VAL_KEYWORD, VAR_KEYWORD));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public interface BindingContext {
|
||||
WritableSlice<JetExpression, DeclarationDescriptor> VARIABLE_ASSIGNMENT = Slices.createSimpleSlice("VARIABLE_ASSIGNMENT");
|
||||
WritableSlice<JetExpression, Boolean> PROCESSED = Slices.createSimpleSetSlice("PROCESSED");
|
||||
WritableSlice<JetElement, Boolean> STATEMENT = Slices.createRemovableSetSlice("STATEMENT");
|
||||
WritableSlice<CallableMemberDescriptor, Boolean> DELEGATED = Slices.createRemovableSetSlice("DELEGATED");
|
||||
|
||||
WritableSlice<PropertyDescriptor, Boolean> BACKING_FIELD_REQUIRED = new Slices.SetSlice<PropertyDescriptor>("BACKING_FIELD_REQUIRED", RewritePolicy.DO_NOTHING) {
|
||||
@Override
|
||||
|
||||
@@ -136,6 +136,15 @@ public class BodyResolver {
|
||||
}
|
||||
JetType supertype = context.getTrace().getBindingContext().get(BindingContext.TYPE, specifier.getTypeReference());
|
||||
recordSupertype(specifier.getTypeReference(), supertype);
|
||||
if (supertype != null) {
|
||||
DeclarationDescriptor declarationDescriptor = supertype.getConstructor().getDeclarationDescriptor();
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
||||
if (classDescriptor.getKind() != ClassKind.TRAIT) {
|
||||
context.getTrace().report(DELEGATION_NOT_TO_TRAIT.on(specifier.getTypeReference()));
|
||||
}
|
||||
}
|
||||
}
|
||||
JetExpression delegateExpression = specifier.getDelegateExpression();
|
||||
if (delegateExpression != null) {
|
||||
JetScope scope = scopeForConstructor == null
|
||||
|
||||
@@ -708,16 +708,16 @@ public class ClassDescriptorResolver {
|
||||
}
|
||||
|
||||
getterDescriptor = new PropertyGetterDescriptor(
|
||||
resolveModalityFromModifiers(trace, getter.getModifierList(), propertyDescriptor.getModality()),
|
||||
propertyDescriptor, annotations, resolveModalityFromModifiers(trace, getter.getModifierList(), propertyDescriptor.getModality()),
|
||||
resolveVisibilityFromModifiers(trace, getter.getModifierList(), propertyDescriptor.getVisibility()),
|
||||
propertyDescriptor, annotations, returnType, getter.getBodyExpression() != null, false);
|
||||
returnType, getter.getBodyExpression() != null, false);
|
||||
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
||||
}
|
||||
else {
|
||||
getterDescriptor = new PropertyGetterDescriptor(
|
||||
propertyDescriptor.getModality(),
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getOutType(), false, true);
|
||||
propertyDescriptor.getOutType(), false, true);
|
||||
}
|
||||
return getterDescriptor;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class DelegationResolver {
|
||||
private final TopDownAnalysisContext context;
|
||||
|
||||
public DelegationResolver(TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
addDelegatedMembers();
|
||||
}
|
||||
|
||||
private void addDelegatedMembers() {
|
||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||
addDelegatedMembers(entry.getKey(), entry.getValue());
|
||||
}
|
||||
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
||||
addDelegatedMembers(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void addDelegatedMembers(JetClassOrObject jetClass, MutableClassDescriptor classDescriptor) {
|
||||
for (JetDelegationSpecifier delegationSpecifier : jetClass.getDelegationSpecifiers()) {
|
||||
if (delegationSpecifier instanceof JetDelegatorByExpressionSpecifier) {
|
||||
JetDelegatorByExpressionSpecifier specifier = (JetDelegatorByExpressionSpecifier) delegationSpecifier;
|
||||
JetType type = context.getTrace().get(BindingContext.TYPE, specifier.getTypeReference());
|
||||
if (type != null) {
|
||||
for (DeclarationDescriptor declarationDescriptor : type.getMemberScope().getAllDescriptors()) {
|
||||
if (declarationDescriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) declarationDescriptor;
|
||||
if (propertyDescriptor.getModality().isOverridable()) {
|
||||
PropertyDescriptor copy = propertyDescriptor.copy(classDescriptor, true);
|
||||
classDescriptor.addPropertyDescriptor(copy);
|
||||
context.getTrace().record(DELEGATED, copy);
|
||||
}
|
||||
}
|
||||
else if (declarationDescriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) declarationDescriptor;
|
||||
if (functionDescriptor.getModality().isOverridable()) {
|
||||
FunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true);
|
||||
classDescriptor.addFunctionDescriptor(copy);
|
||||
context.getTrace().record(DELEGATED, copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -89,4 +90,25 @@ public class DescriptorUtils {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static List<ValueParameterDescriptor> copyValueParameters(DeclarationDescriptor newOwner, List<ValueParameterDescriptor> parameters) {
|
||||
List<ValueParameterDescriptor> result = Lists.newArrayList();
|
||||
for (ValueParameterDescriptor parameter : parameters) {
|
||||
result.add(parameter.copy(newOwner));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<TypeParameterDescriptor> copyTypeParameters(DeclarationDescriptor newOwner, List<TypeParameterDescriptor> parameters) {
|
||||
List<TypeParameterDescriptor> result = Lists.newArrayList();
|
||||
for (TypeParameterDescriptor parameter : parameters) {
|
||||
result.add(parameter.copy(newOwner));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Modality convertModality(Modality modality, boolean makeNonAbstract) {
|
||||
if (makeNonAbstract && modality == Modality.ABSTRACT) return Modality.OPEN;
|
||||
return modality;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.*;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -18,6 +17,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -105,6 +105,7 @@ public class OverrideResolver {
|
||||
// Check if everything that must be overridden, actually is
|
||||
|
||||
// Everything from supertypes
|
||||
Map<CallableMemberDescriptor, CallableMemberDescriptor> implementedWithDelegationBy = Maps.newHashMap();
|
||||
Set<CallableMemberDescriptor> inheritedFunctions = Sets.newLinkedHashSet();
|
||||
for (JetType supertype : classDescriptor.getSupertypes()) {
|
||||
for (DeclarationDescriptor descriptor : supertype.getMemberScope().getAllDescriptors()) {
|
||||
@@ -123,7 +124,7 @@ public class OverrideResolver {
|
||||
for (CallableMemberDescriptor one : filteredMembers) {
|
||||
if (factoredMembers.values().contains(one)) continue;
|
||||
for (CallableMemberDescriptor another : filteredMembers) {
|
||||
if (one == another) continue;
|
||||
// if (one == another) continue;
|
||||
factoredMembers.put(one, one);
|
||||
if (OverridingUtil.isOverridableBy(one, another).isSuccess()
|
||||
|| OverridingUtil.isOverridableBy(another, one).isSuccess()) {
|
||||
@@ -154,7 +155,7 @@ public class OverrideResolver {
|
||||
}
|
||||
|
||||
// Members actually present (declared) in the class
|
||||
Set<CallableDescriptor> actuallyOverridden = Sets.newHashSet();
|
||||
Set<CallableMemberDescriptor> actuallyOverridden = Sets.newHashSet(implementedWithDelegationBy.keySet());
|
||||
for (CallableMemberDescriptor member : classDescriptor.getCallableMembers()) {
|
||||
actuallyOverridden.addAll(member.getOverriddenDescriptors());
|
||||
}
|
||||
@@ -171,63 +172,68 @@ public class OverrideResolver {
|
||||
nameIdentifier = ((JetObjectDeclaration) klass).getNameIdentifier();
|
||||
}
|
||||
|
||||
// for (CallableMemberDescriptor memberDescriptor : manyImpl) {
|
||||
// context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor));
|
||||
// break;
|
||||
// }
|
||||
for (CallableMemberDescriptor memberDescriptor : manyImpl) {
|
||||
context.getTrace().report(MANY_IMPL_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (classDescriptor.getModality() == Modality.ABSTRACT) {
|
||||
return;
|
||||
}
|
||||
|
||||
// for (CallableMemberDescriptor memberDescriptor : abstractNoImpl) {
|
||||
// context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor));
|
||||
// break;
|
||||
// }
|
||||
for (CallableMemberDescriptor memberDescriptor : abstractNoImpl) {
|
||||
context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, memberDescriptor));
|
||||
break;
|
||||
}
|
||||
|
||||
Set<FunctionDescriptor> allOverriddenFunctions = Sets.newHashSet();
|
||||
Collection<DeclarationDescriptor> allDescriptors = classDescriptor.getDefaultType().getMemberScope().getAllDescriptors();
|
||||
for (DeclarationDescriptor descriptor : allDescriptors) {
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
if (functionDescriptor.getModality() != Modality.ABSTRACT) {
|
||||
for (FunctionDescriptor overriddenDescriptor : functionDescriptor.getOverriddenDescriptors()) {
|
||||
allOverriddenFunctions.add(overriddenDescriptor.getOriginal());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean foundError = false;
|
||||
for (DeclarationDescriptor descriptor : allDescriptors) {
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
if (functionDescriptor.getModality() == Modality.ABSTRACT && !allOverriddenFunctions.contains(functionDescriptor.getOriginal()) && !foundError && nameIdentifier != null) {
|
||||
DeclarationDescriptor declarationDescriptor = functionDescriptor.getContainingDeclaration();
|
||||
if (declarationDescriptor != classDescriptor) {
|
||||
// context.getTrace().getErrorHandler().genericError(nameIdentifier.getNode(), "Class '" + klass.getName() + "' must be declared abstract or implement abstract method '" +
|
||||
// functionDescriptor.getName() + "' declared in " + declarationDescriptor.getName());
|
||||
context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, functionDescriptor));
|
||||
foundError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set<FunctionDescriptor> allOverriddenFunctions = Sets.newHashSet();
|
||||
// Collection<DeclarationDescriptor> allDescriptors = classDescriptor.getDefaultType().getMemberScope().getAllDescriptors();
|
||||
// for (DeclarationDescriptor descriptor : allDescriptors) {
|
||||
// if (descriptor instanceof FunctionDescriptor) {
|
||||
// FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
// if (functionDescriptor.getModality() != Modality.ABSTRACT) {
|
||||
// for (FunctionDescriptor overriddenDescriptor : functionDescriptor.getOverriddenDescriptors()) {
|
||||
// allOverriddenFunctions.add(overriddenDescriptor.getOriginal());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// boolean foundError = false;
|
||||
// for (DeclarationDescriptor descriptor : allDescriptors) {
|
||||
// if (descriptor instanceof FunctionDescriptor) {
|
||||
// FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
// if (functionDescriptor.getModality() == Modality.ABSTRACT && !allOverriddenFunctions.contains(functionDescriptor.getOriginal()) && !foundError && nameIdentifier != null) {
|
||||
// DeclarationDescriptor declarationDescriptor = functionDescriptor.getContainingDeclaration();
|
||||
// if (declarationDescriptor != classDescriptor) {
|
||||
//// context.getTrace().getErrorHandler().genericError(nameIdentifier.getNode(), "Class '" + klass.getName() + "' must be declared abstract or implement abstract method '" +
|
||||
//// functionDescriptor.getName() + "' declared in " + declarationDescriptor.getName());
|
||||
// context.getTrace().report(ABSTRACT_MEMBER_NOT_IMPLEMENTED.on(nameIdentifier, klass, functionDescriptor));
|
||||
// foundError = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private void checkOverride(CallableMemberDescriptor declared) {
|
||||
JetNamedDeclaration member = (JetNamedDeclaration) context.getTrace().get(BindingContext.DESCRIPTOR_TO_DECLARATION, declared);
|
||||
assert member != null;
|
||||
if (member == null) {
|
||||
assert context.getTrace().get(DELEGATED, declared);
|
||||
return;
|
||||
}
|
||||
|
||||
JetModifierList modifierList = member.getModifierList();
|
||||
ASTNode overrideNode = modifierList != null ? modifierList.getModifierNode(JetTokens.OVERRIDE_KEYWORD) : null;
|
||||
boolean hasOverrideModifier = overrideNode != null;
|
||||
|
||||
boolean finalOverriddenError = false;
|
||||
boolean typeMismatchError = false;
|
||||
boolean kindMismatchError = false;
|
||||
for (CallableMemberDescriptor overridden : declared.getOverriddenDescriptors()) {
|
||||
if (overridden != null) {
|
||||
if (hasOverrideModifier) {
|
||||
if (!overridden.getModality().isOpen() && !finalOverriddenError) {
|
||||
if (!overridden.getModality().isOverridable() && !finalOverriddenError) {
|
||||
// context.getTrace().getErrorHandler().genericError(overrideNode, "Method " + overridden.getName() + " in " + overridden.getContainingDeclaration().getName() + " is final and cannot be overridden");
|
||||
context.getTrace().report(OVERRIDING_FINAL_MEMBER.on(overrideNode, overridden, overridden.getContainingDeclaration()));
|
||||
finalOverriddenError = true;
|
||||
@@ -237,6 +243,11 @@ public class OverrideResolver {
|
||||
context.getTrace().report(RETURN_TYPE_MISMATCH_ON_OVERRIDE.on(member, declared, overridden));
|
||||
typeMismatchError = true;
|
||||
}
|
||||
|
||||
if (checkPropertyKind(overridden, true) && checkPropertyKind(declared, false) && !kindMismatchError) {
|
||||
context.getTrace().report(VAR_OVERRIDDEN_BY_VAL.on(member, ((JetProperty) member).getValOrVarNode(), (PropertyDescriptor) declared, (PropertyDescriptor) overridden));
|
||||
kindMismatchError = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -253,4 +264,12 @@ public class OverrideResolver {
|
||||
context.getTrace().report(VIRTUAL_MEMBER_HIDDEN.on(member, nameIdentifier, declared, overridden, overridden.getContainingDeclaration()));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkPropertyKind(CallableMemberDescriptor descriptor, boolean isVar) {
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
return propertyDescriptor.isVar() == isVar;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,12 @@ public class OverridingUtil {
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo isOverridableBy(@NotNull CallableDescriptor superDescriptor, @NotNull CallableDescriptor subDescriptor) {
|
||||
if (superDescriptor instanceof FunctionDescriptor) {
|
||||
if (subDescriptor instanceof PropertyDescriptor) return OverrideCompatibilityInfo.memberKindMismatch();
|
||||
}
|
||||
if (superDescriptor instanceof PropertyDescriptor) {
|
||||
if (subDescriptor instanceof FunctionDescriptor) return OverrideCompatibilityInfo.memberKindMismatch();
|
||||
}
|
||||
if (!superDescriptor.getName().equals(subDescriptor.getName())) {
|
||||
return OverrideCompatibilityInfo.nameMismatch();
|
||||
}
|
||||
@@ -192,6 +198,11 @@ public class OverridingUtil {
|
||||
return new OverrideCompatibilityInfo(false, "valueParameterTypeMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo memberKindMismatch() {
|
||||
return new OverrideCompatibilityInfo(false, "memberKindMismatch"); // TODO
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static OverrideCompatibilityInfo returnTypeMismatch(JetType substitutedSuperReturnType, JetType unsubstitutedSubReturnType) {
|
||||
return new OverrideCompatibilityInfo(true, "returnTypeMismatch: " + unsubstitutedSubReturnType + " >< " + substitutedSuperReturnType); // TODO
|
||||
|
||||
@@ -65,6 +65,7 @@ public class TopDownAnalyzer {
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace);
|
||||
new TypeHierarchyResolver(context).process(outerScope, owner, declarations);
|
||||
new DeclarationResolver(context).process();
|
||||
new DelegationResolver(context).process();
|
||||
new OverrideResolver(context).process();
|
||||
new BodyResolver(context).resolveBehaviorDeclarationBodies();
|
||||
}
|
||||
@@ -78,6 +79,7 @@ public class TopDownAnalyzer {
|
||||
context.getNamespaceDescriptors().put(namespace, standardLibraryNamespace);
|
||||
new TypeHierarchyResolver(context).process(outerScope, standardLibraryNamespace, namespace.getDeclarations());
|
||||
new DeclarationResolver(context).process();
|
||||
new DelegationResolver(context).process();
|
||||
OverrideResolver overrideResolver = new OverrideResolver(context) {
|
||||
@Override
|
||||
protected void checkOverridesInAClass(MutableClassDescriptor classDescriptor, JetClassOrObject klass) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Foo1() : java.util.ArrayList<Int>()
|
||||
|
||||
open class Bar() {
|
||||
fun v() : Int = 1
|
||||
val v : Int = 1
|
||||
}
|
||||
|
||||
class Barr() : Bar() {}
|
||||
@@ -0,0 +1,38 @@
|
||||
//namespace override
|
||||
|
||||
trait T {
|
||||
fun foo()
|
||||
val v : Int
|
||||
}
|
||||
|
||||
open class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>Br<!>(t : T) : T {
|
||||
|
||||
}
|
||||
|
||||
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>Br3<!>(t : T) : Br(t) {
|
||||
|
||||
}
|
||||
|
||||
open class Br1(t : T) : T by t {
|
||||
|
||||
}
|
||||
|
||||
class Br2(t : T) : Br1(t) {
|
||||
|
||||
}
|
||||
|
||||
trait G<T> {
|
||||
fun foo(t : T) : T
|
||||
}
|
||||
|
||||
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>GC<!>() : G<Int> {
|
||||
|
||||
}
|
||||
|
||||
open class GC1(g : G<Int>) : G<Int> by g {
|
||||
|
||||
}
|
||||
|
||||
open class GC2(g : G<Int>) : GC1(g) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
open class Foo() {
|
||||
|
||||
}
|
||||
|
||||
class Barrr() : <!DELEGATION_NOT_TO_TRAIT!>Foo<!> by Foo() {}
|
||||
|
||||
trait T {}
|
||||
|
||||
class Br(t : T) : T by t {}
|
||||
|
||||
open enum class E() {}
|
||||
|
||||
class Test2(e : E) : <!DELEGATION_NOT_TO_TRAIT!>E<!> by e {}
|
||||
@@ -0,0 +1,15 @@
|
||||
open class Var() {
|
||||
open var v : Int = 1
|
||||
}
|
||||
|
||||
trait VarT {
|
||||
var v : Int
|
||||
}
|
||||
|
||||
class Val() : Var(), VarT {
|
||||
override <!VAR_OVERRIDDEN_BY_VAL!>val<!> v : Int = 1
|
||||
}
|
||||
|
||||
class Var2() : Var() {
|
||||
override var v : Int = 1
|
||||
}
|
||||
Reference in New Issue
Block a user