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