Get rid of assumption that primary ctr is a child of JetClass
As it can be contained within JetObjectDeclaration
This commit is contained in:
@@ -674,7 +674,7 @@ public class JetFlowInformationProvider {
|
||||
}
|
||||
else if (owner instanceof JetPrimaryConstructor) {
|
||||
if (!((JetParameter) element).hasValOrVar() &&
|
||||
!((JetPrimaryConstructor) owner).getContainingClass().isAnnotation()) {
|
||||
!((JetPrimaryConstructor) owner).getContainingClassOrObject().isAnnotation()) {
|
||||
report(Errors.UNUSED_PARAMETER.on((JetParameter) element, variableDescriptor), ctxt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,8 +59,6 @@ public open class JetClass : JetClassOrObject {
|
||||
|
||||
public fun getProperties(): List<JetProperty> = getBody()?.getProperties().orEmpty()
|
||||
|
||||
public fun isAnnotation(): Boolean = hasModifier(JetTokens.ANNOTATION_KEYWORD)
|
||||
|
||||
public fun isInterface(): Boolean =
|
||||
getStub()?.isInterface()
|
||||
?: (findChildByType<PsiElement>(JetTokens.TRAIT_KEYWORD) != null || findChildByType<PsiElement>(JetTokens.INTERFACE_KEYWORD) != null)
|
||||
|
||||
@@ -60,4 +60,6 @@ abstract public class JetClassOrObject : JetTypeParameterListOwnerStub<KotlinCla
|
||||
private fun hasSecondaryConstructors(): Boolean = !getSecondaryConstructors().isEmpty()
|
||||
|
||||
public fun getSecondaryConstructors(): List<JetSecondaryConstructor> = getBody()?.getSecondaryConstructors().orEmpty()
|
||||
|
||||
public fun isAnnotation(): Boolean = hasModifier(JetTokens.ANNOTATION_KEYWORD)
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public final class JetNamedDeclarationUtil {
|
||||
return getFQName((JetNamedDeclaration) parent);
|
||||
}
|
||||
else if (namedDeclaration instanceof JetParameter) {
|
||||
JetClass constructorClass = JetPsiUtil.getClassIfParameterIsProperty((JetParameter) namedDeclaration);
|
||||
JetClassOrObject constructorClass = JetPsiUtil.getClassIfParameterIsProperty((JetParameter) namedDeclaration);
|
||||
if (constructorClass != null) {
|
||||
return getFQName(constructorClass);
|
||||
}
|
||||
|
||||
@@ -71,17 +71,9 @@ public class JetPrimaryConstructor extends JetDeclarationStub<KotlinPlaceHolderS
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetClass getContainingClassOrNull() {
|
||||
JetClassOrObject classOrObject = (JetClassOrObject) getParent();
|
||||
return classOrObject instanceof JetClass ? (JetClass) classOrObject : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetClass getContainingClass() {
|
||||
JetClass classOrNull = getContainingClassOrNull();
|
||||
assert classOrNull != null : "This method should be called when parent is JetClass";
|
||||
return classOrNull;
|
||||
public JetClassOrObject getContainingClassOrObject() {
|
||||
return (JetClassOrObject) getParent();
|
||||
}
|
||||
|
||||
public boolean hasConstructorKeyword() {
|
||||
|
||||
@@ -447,11 +447,11 @@ public class JetPsiUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetClass getClassIfParameterIsProperty(@NotNull JetParameter jetParameter) {
|
||||
public static JetClassOrObject getClassIfParameterIsProperty(@NotNull JetParameter jetParameter) {
|
||||
if (jetParameter.hasValOrVar()) {
|
||||
PsiElement grandParent = jetParameter.getParent().getParent();
|
||||
if (grandParent instanceof JetPrimaryConstructor) {
|
||||
return ((JetPrimaryConstructor) grandParent).getContainingClassOrNull();
|
||||
return ((JetPrimaryConstructor) grandParent).getContainingClassOrObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -143,7 +143,7 @@ public class LazyDeclarationResolver {
|
||||
public DeclarationDescriptor visitParameter(@NotNull JetParameter parameter, Void data) {
|
||||
PsiElement grandFather = parameter.getParent().getParent();
|
||||
if (grandFather instanceof JetPrimaryConstructor) {
|
||||
JetClass jetClass = ((JetPrimaryConstructor) grandFather).getContainingClass();
|
||||
JetClassOrObject jetClass = ((JetPrimaryConstructor) grandFather).getContainingClassOrObject();
|
||||
// This is a primary constructor parameter
|
||||
ClassDescriptor classDescriptor = getClassDescriptor(jetClass);
|
||||
if (parameter.hasValOrVar()) {
|
||||
@@ -183,7 +183,7 @@ public class LazyDeclarationResolver {
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor visitPrimaryConstructor(@NotNull JetPrimaryConstructor constructor, Void data) {
|
||||
JetClass klass = constructor.getContainingClass();
|
||||
JetClassOrObject klass = constructor.getContainingClassOrObject();
|
||||
getClassDescriptor(klass).getConstructors();
|
||||
return getBindingContext().get(BindingContext.CONSTRUCTOR, klass);
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ public class LightClassUtil {
|
||||
@Nullable
|
||||
private static PsiClass getWrappingClass(@NotNull JetDeclaration declaration) {
|
||||
if (declaration instanceof JetParameter) {
|
||||
JetClass constructorClass = JetPsiUtil.getClassIfParameterIsProperty((JetParameter) declaration);
|
||||
JetClassOrObject constructorClass = JetPsiUtil.getClassIfParameterIsProperty((JetParameter) declaration);
|
||||
if (constructorClass != null) {
|
||||
return getPsiClass(constructorClass);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public fun JetParameter.toPsiParameter(): PsiParameter? {
|
||||
val method: PsiMethod? = when (owner) {
|
||||
is JetFunction -> LightClassUtil.getLightClassMethod(owner)
|
||||
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(owner)
|
||||
is JetPrimaryConstructor -> LightClassUtil.getPsiClass(owner.getContainingClass())?.getConstructors()?.let { constructors ->
|
||||
is JetPrimaryConstructor -> LightClassUtil.getPsiClass(owner.getContainingClassOrObject())?.getConstructors()?.let { constructors ->
|
||||
if (constructors.isNotEmpty()) constructors[0] else null
|
||||
}
|
||||
else -> null
|
||||
|
||||
@@ -76,8 +76,8 @@ public abstract class AbstractDescriptorRendererTest : KotlinTestWithEnvironment
|
||||
is JetNamedFunction ->
|
||||
addCorrespondingParameterDescriptor(getDescriptor(declaringElement, resolveSession) as FunctionDescriptor, parameter)
|
||||
is JetPrimaryConstructor -> {
|
||||
val jetClass: JetClass = declaringElement.getContainingClass()
|
||||
val classDescriptor = getDescriptor(jetClass, resolveSession) as ClassDescriptor
|
||||
val jetClassOrObject: JetClassOrObject = declaringElement.getContainingClassOrObject()
|
||||
val classDescriptor = getDescriptor(jetClassOrObject, resolveSession) as ClassDescriptor
|
||||
addCorrespondingParameterDescriptor(classDescriptor.getUnsubstitutedPrimaryConstructor(), parameter)
|
||||
}
|
||||
else -> super.visitParameter(parameter)
|
||||
|
||||
@@ -40,7 +40,7 @@ public open class ChangeVisibilityModifierIntention protected constructor(
|
||||
// val descriptor = element.resolveToDescriptor() as? DeclarationDescriptorWithVisibility ?: return null
|
||||
val bindingContext = element.analyze()
|
||||
var descriptor = (if (element is JetPrimaryConstructor) //TODO: temporary code
|
||||
((element.getParent() as JetClass).resolveToDescriptor() as ClassDescriptor).getUnsubstitutedPrimaryConstructor()
|
||||
(element.getContainingClassOrObject().resolveToDescriptor() as ClassDescriptor).getUnsubstitutedPrimaryConstructor()
|
||||
else
|
||||
bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, element]) as? DeclarationDescriptorWithVisibility ?: return null
|
||||
if (descriptor is ValueParameterDescriptor) {
|
||||
|
||||
Reference in New Issue
Block a user