Support properties declared as primary constructor parameters
This commit is contained in:
+11
-1
@@ -186,7 +186,10 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
for (JetDeclaration declaration : declarationProvider.getAllDeclarations()) {
|
for (JetDeclaration declaration : declarationProvider.getAllDeclarations()) {
|
||||||
if (declaration instanceof JetClassOrObject) {
|
if (declaration instanceof JetClassOrObject) {
|
||||||
JetClassOrObject classOrObject = (JetClassOrObject) declaration;
|
JetClassOrObject classOrObject = (JetClassOrObject) declaration;
|
||||||
getClassifier(classOrObject.getNameAsName());
|
Name name = classOrObject.getNameAsName();
|
||||||
|
if (name != null) {
|
||||||
|
getClassifier(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (declaration instanceof JetFunction) {
|
else if (declaration instanceof JetFunction) {
|
||||||
JetFunction function = (JetFunction) declaration;
|
JetFunction function = (JetFunction) declaration;
|
||||||
@@ -196,6 +199,13 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
|||||||
JetProperty property = (JetProperty) declaration;
|
JetProperty property = (JetProperty) declaration;
|
||||||
getProperties(property.getNameAsSafeName());
|
getProperties(property.getNameAsSafeName());
|
||||||
}
|
}
|
||||||
|
else if (declaration instanceof JetParameter) {
|
||||||
|
JetParameter parameter = (JetParameter) declaration;
|
||||||
|
Name name = parameter.getNameAsName();
|
||||||
|
if (name != null) {
|
||||||
|
getProperties(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException("Unsupported declaration kind: " + declaration);
|
throw new IllegalArgumentException("Unsupported declaration kind: " + declaration);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -21,10 +21,7 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
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.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -64,6 +61,9 @@ public abstract class AbstractPsiBasedDeclarationProvider implements Declaration
|
|||||||
JetClassOrObject classOrObject = (JetClassOrObject) declaration;
|
JetClassOrObject classOrObject = (JetClassOrObject) declaration;
|
||||||
classesAndObjects.put(classOrObject.getNameAsName(), classOrObject);
|
classesAndObjects.put(classOrObject.getNameAsName(), classOrObject);
|
||||||
}
|
}
|
||||||
|
else if (declaration instanceof JetParameter) {
|
||||||
|
// Do nothing, just put it into allDeclarations is enough
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException("Unknown declaration: " + declaration);
|
throw new IllegalArgumentException("Unknown declaration: " + declaration);
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-2
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.diagnostics.Errors;
|
|||||||
import org.jetbrains.jet.lang.psi.JetClass;
|
import org.jetbrains.jet.lang.psi.JetClass;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||||
@@ -104,10 +105,25 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
protected void getNonDeclaredProperties(@NotNull Name name, @NotNull final Set<VariableDescriptor> result) {
|
protected void getNonDeclaredProperties(@NotNull Name name, @NotNull final Set<VariableDescriptor> result) {
|
||||||
System.err.println("Parameter of the primary constructor");
|
JetClassOrObject classOrObject = declarationProvider.getOwnerClassOrObject();
|
||||||
|
if (classOrObject instanceof JetClass) {
|
||||||
|
JetClass jetClass = (JetClass) classOrObject;
|
||||||
|
|
||||||
|
for (JetParameter parameter : jetClass.getPrimaryConstructorParameters()) {
|
||||||
|
if (parameter.getValOrVarNode() != null) {
|
||||||
|
PropertyDescriptor propertyDescriptor =
|
||||||
|
resolveSession.getInjector().getDescriptorResolver().resolvePrimaryConstructorParameterToAProperty(
|
||||||
|
thisDescriptor,
|
||||||
|
thisDescriptor.getScopeForClassHeaderResolution(),
|
||||||
|
parameter, resolveSession.getTrace()
|
||||||
|
);
|
||||||
|
result.add(propertyDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Inherited fake overrides
|
|
||||||
Collection<PropertyDescriptor> fromSupertypes = Lists.newArrayList();
|
Collection<PropertyDescriptor> fromSupertypes = Lists.newArrayList();
|
||||||
for (JetType supertype : thisDescriptor.getTypeConstructor().getSupertypes()) {
|
for (JetType supertype : thisDescriptor.getTypeConstructor().getSupertypes()) {
|
||||||
fromSupertypes.addAll((Set) supertype.getMemberScope().getProperties(name));
|
fromSupertypes.addAll((Set) supertype.getMemberScope().getProperties(name));
|
||||||
|
|||||||
+10
-3
@@ -17,9 +17,7 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.lazy;
|
package org.jetbrains.jet.lang.resolve.lazy;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassObject;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
@@ -49,6 +47,15 @@ public class PsiBasedClassMemberDeclarationProvider extends AbstractPsiBasedDecl
|
|||||||
putToIndex(declaration);
|
putToIndex(declaration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (classOrObject instanceof JetClass) {
|
||||||
|
JetClass jetClass = (JetClass) classOrObject;
|
||||||
|
for (JetParameter parameter : jetClass.getPrimaryConstructorParameters()) {
|
||||||
|
if (parameter.getValOrVarNode() != null) {
|
||||||
|
putToIndex(parameter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user