Pull constructor-related methods from JetClass to JetClassOrObject

This commit is contained in:
Denis Zharkov
2015-05-27 19:26:27 +03:00
parent 51534f4592
commit 8c6264bf2c
5 changed files with 19 additions and 47 deletions
@@ -39,20 +39,6 @@ public open class JetClass : JetClassOrObject {
return visitor.visitClass(this, data)
}
public fun getPrimaryConstructor(): JetPrimaryConstructor? {
return getStubOrPsiChild(JetStubElementTypes.PRIMARY_CONSTRUCTOR)
}
public fun getPrimaryConstructorParameterList(): JetParameterList? {
val primaryConstructor = getPrimaryConstructor()
return primaryConstructor?.getValueParameterList()
}
public fun getPrimaryConstructorParameters(): List<JetParameter> {
val list = getPrimaryConstructorParameterList() ?: return emptyList<JetParameter>()
return list.getParameters()
}
public fun createPrimaryConstructorIfAbsent(): JetPrimaryConstructor {
val constructor = getPrimaryConstructor()
if (constructor != null) return constructor
@@ -69,14 +55,6 @@ public open class JetClass : JetClassOrObject {
return constructor.add(JetPsiFactory(getProject()).createParameterList("()")) as JetParameterList
}
public fun getPrimaryConstructorModifierList(): JetModifierList? {
val primaryConstructor = getPrimaryConstructor()
return primaryConstructor?.getModifierList()
}
public fun hasExplicitPrimaryConstructor(): Boolean {
return getPrimaryConstructor() != null
}
public fun getColon(): PsiElement? {
return findChildByType(JetTokens.COLON)
@@ -149,19 +127,6 @@ public open class JetClass : JetClassOrObject {
return body.getAllCompanionObjects()
}
public fun hasPrimaryConstructor(): Boolean {
return hasExplicitPrimaryConstructor() || !hasSecondaryConstructors()
}
private fun hasSecondaryConstructors(): Boolean {
return !getSecondaryConstructors().isEmpty()
}
public fun getSecondaryConstructors(): List<JetSecondaryConstructor> {
val body = getBody()
return if (body != null) body.getSecondaryConstructors() else emptyList<JetSecondaryConstructor>()
}
public fun getClassOrInterfaceKeyword(): PsiElement? {
return findChildByType(TokenSet.create(JetTokens.CLASS_KEYWORD, JetTokens.INTERFACE_KEYWORD))
}
@@ -47,4 +47,17 @@ abstract public class JetClassOrObject : JetTypeParameterListOwnerStub<KotlinCla
override fun getDeclarations() = getBody()?.getDeclarations().orEmpty()
override fun getPresentation(): ItemPresentation? = ItemPresentationProviders.getItemPresentation(this)
public fun getPrimaryConstructor(): JetPrimaryConstructor? = getStubOrPsiChild(JetStubElementTypes.PRIMARY_CONSTRUCTOR)
public fun getPrimaryConstructorModifierList(): JetModifierList? = getPrimaryConstructor()?.getModifierList()
public fun getPrimaryConstructorParameterList(): JetParameterList? = getPrimaryConstructor()?.getValueParameterList()
public fun getPrimaryConstructorParameters(): List<JetParameter> = getPrimaryConstructorParameterList()?.getParameters().orEmpty()
public fun hasExplicitPrimaryConstructor(): Boolean = getPrimaryConstructor() != null
public fun hasPrimaryConstructor(): Boolean = hasExplicitPrimaryConstructor() || !hasSecondaryConstructors()
private fun hasSecondaryConstructors(): Boolean = !getSecondaryConstructors().isEmpty()
public fun getSecondaryConstructors(): List<JetSecondaryConstructor> = getBody()?.getSecondaryConstructors().orEmpty()
}
@@ -51,12 +51,6 @@ public class JetClassInfo extends JetClassOrObjectInfo<JetClass> {
return element.getTypeParameterList();
}
@NotNull
@Override
public List<? extends JetParameter> getPrimaryConstructorParameters() {
return element.getPrimaryConstructorParameters();
}
@NotNull
@Override
public ClassKind getClassKind() {
@@ -90,6 +90,12 @@ public abstract class JetClassOrObjectInfo<E extends JetClassOrObject> implement
return body == null ? Collections.<JetAnnotationEntry>emptyList() : body.getDanglingAnnotations();
}
@NotNull
@Override
public List<? extends JetParameter> getPrimaryConstructorParameters() {
return element.getPrimaryConstructorParameters();
}
@Override
public String toString() {
return "info for " + element.getText();
@@ -42,12 +42,6 @@ public class JetObjectInfo extends JetClassOrObjectInfo<JetObjectDeclaration> {
return null;
}
@NotNull
@Override
public List<? extends JetParameter> getPrimaryConstructorParameters() {
return Collections.emptyList();
}
@NotNull
@Override
public ClassKind getClassKind() {