Minor, refactor: Move hasBody() to KtProperty
This commit is contained in:
@@ -298,4 +298,17 @@ public class KtProperty extends KtTypeParameterListOwnerStub<KotlinPropertyStub>
|
|||||||
// Suppress Java check for out-of-block
|
// Suppress Java check for out-of-block
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasBody() {
|
||||||
|
if (hasDelegateExpressionOrInitializer()) return true;
|
||||||
|
KtPropertyAccessor getter = getGetter();
|
||||||
|
if (getter != null && getter.hasBody()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
KtPropertyAccessor setter = getSetter();
|
||||||
|
if (setter != null && setter.hasBody()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -526,4 +526,10 @@ fun KtCallExpression.getOrCreateValueArgumentList(): KtValueArgumentList {
|
|||||||
valueArgumentList?.let { return it }
|
valueArgumentList?.let { return it }
|
||||||
return addAfter(KtPsiFactory(this).createCallArguments("()"),
|
return addAfter(KtPsiFactory(this).createCallArguments("()"),
|
||||||
typeArgumentList ?: calleeExpression) as KtValueArgumentList
|
typeArgumentList ?: calleeExpression) as KtValueArgumentList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun KtDeclaration.hasBody() = when (this) {
|
||||||
|
is KtFunction -> hasBody()
|
||||||
|
is KtProperty -> hasBody()
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|||||||
@@ -788,10 +788,9 @@ public class DescriptorResolver {
|
|||||||
KtModifierList modifierList = property.getModifierList();
|
KtModifierList modifierList = property.getModifierList();
|
||||||
boolean isVar = property.isVar();
|
boolean isVar = property.isVar();
|
||||||
|
|
||||||
boolean hasBody = hasBody(property);
|
|
||||||
Visibility visibility = resolveVisibilityFromModifiers(property, getDefaultVisibility(property, containingDeclaration));
|
Visibility visibility = resolveVisibilityFromModifiers(property, getDefaultVisibility(property, containingDeclaration));
|
||||||
Modality modality = containingDeclaration instanceof ClassDescriptor
|
Modality modality = containingDeclaration instanceof ClassDescriptor
|
||||||
? resolveMemberModalityFromModifiers(property, getDefaultModality(containingDeclaration, visibility, hasBody),
|
? resolveMemberModalityFromModifiers(property, getDefaultModality(containingDeclaration, visibility, property.hasBody()),
|
||||||
trace.getBindingContext(), containingDeclaration)
|
trace.getBindingContext(), containingDeclaration)
|
||||||
: Modality.FINAL;
|
: Modality.FINAL;
|
||||||
|
|
||||||
@@ -896,22 +895,6 @@ public class DescriptorResolver {
|
|||||||
return propertyDescriptor;
|
return propertyDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasBody(KtProperty property) {
|
|
||||||
boolean hasBody = property.hasDelegateExpressionOrInitializer();
|
|
||||||
if (!hasBody) {
|
|
||||||
KtPropertyAccessor getter = property.getGetter();
|
|
||||||
if (getter != null && getter.hasBody()) {
|
|
||||||
hasBody = true;
|
|
||||||
}
|
|
||||||
KtPropertyAccessor setter = property.getSetter();
|
|
||||||
if (!hasBody && setter != null && setter.hasBody()) {
|
|
||||||
hasBody = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hasBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
/*package*/ static KotlinType transformAnonymousTypeIfNeeded(
|
/*package*/ static KotlinType transformAnonymousTypeIfNeeded(
|
||||||
@NotNull DeclarationDescriptorWithVisibility descriptor,
|
@NotNull DeclarationDescriptorWithVisibility descriptor,
|
||||||
|
|||||||
@@ -33,14 +33,14 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getLambdaArgumentName
|
import org.jetbrains.kotlin.psi.psiUtil.getLambdaArgumentName
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.hasBody
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType
|
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType
|
||||||
import org.jetbrains.kotlin.psi.typeRefHelpers.setReceiverTypeReference
|
import org.jetbrains.kotlin.psi.typeRefHelpers.setReceiverTypeReference
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorResolver
|
|
||||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getValueArgumentsInParentheses
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
inline fun <reified T: PsiElement> PsiElement.replaced(newElement: T): T {
|
inline fun <reified T: PsiElement> PsiElement.replaced(newElement: T): T {
|
||||||
@@ -246,12 +246,7 @@ fun KtDeclaration.implicitModality(): KtModifierKeywordToken {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (klass is KtClass && klass.isInterface() && !hasModifier(KtTokens.PRIVATE_KEYWORD)) {
|
if (klass is KtClass && klass.isInterface() && !hasModifier(KtTokens.PRIVATE_KEYWORD)) {
|
||||||
val hasBody = when (this) {
|
return if (hasBody()) KtTokens.OPEN_KEYWORD else KtTokens.ABSTRACT_KEYWORD
|
||||||
is KtProperty -> DescriptorResolver.hasBody(this)
|
|
||||||
is KtFunction -> hasBody()
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
return if (hasBody) KtTokens.OPEN_KEYWORD else KtTokens.ABSTRACT_KEYWORD
|
|
||||||
}
|
}
|
||||||
return KtTokens.FINAL_KEYWORD
|
return KtTokens.FINAL_KEYWORD
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user