From 5b1a5deae43aeb668418856af7d77bb22e47b419 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 27 May 2015 17:55:09 +0300 Subject: [PATCH] Convert JetClassOrObject and inheritors: J2K --- .../src/org/jetbrains/kotlin/psi/JetClass.kt | 277 ++++++++---------- .../jetbrains/kotlin/psi/JetClassOrObject.kt | 39 +-- .../kotlin/psi/JetObjectDeclaration.kt | 244 +++++++-------- .../extractFunctionForDebuggerUtil.kt | 2 +- ...catedEnumEntrySuperConstructorSyntaxFix.kt | 2 +- .../callableBuilder/CallableBuilder.kt | 4 +- 6 files changed, 245 insertions(+), 323 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClass.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClass.kt index 5b467baa367..a760263dc3a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClass.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClass.kt @@ -14,246 +14,207 @@ * limitations under the License. */ -package org.jetbrains.kotlin.psi; +package org.jetbrains.kotlin.psi -import com.intellij.lang.ASTNode; -import com.intellij.navigation.ItemPresentation; -import com.intellij.navigation.ItemPresentationProviders; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.psi.tree.TokenSet; -import com.intellij.psi.util.PsiTreeUtil; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.JetNodeTypes; -import org.jetbrains.kotlin.lexer.JetTokens; -import org.jetbrains.kotlin.name.FqName; -import org.jetbrains.kotlin.psi.stubs.KotlinClassStub; -import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes; +import com.intellij.lang.ASTNode +import com.intellij.navigation.ItemPresentation +import com.intellij.navigation.ItemPresentationProviders +import com.intellij.openapi.util.text.StringUtil +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.intellij.psi.tree.TokenSet +import com.intellij.psi.util.PsiTreeUtil +import com.intellij.util.IncorrectOperationException +import org.jetbrains.kotlin.JetNodeTypes +import org.jetbrains.kotlin.lexer.JetTokens +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.psi.stubs.KotlinClassStub +import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.ArrayList +import java.util.Collections -public class JetClass extends JetTypeParameterListOwnerStub implements JetClassOrObject { +public open class JetClass : JetTypeParameterListOwnerStub, JetClassOrObject { - public JetClass(@NotNull ASTNode node) { - super(node); + public constructor(node: ASTNode) : super(node) { } - public JetClass(@NotNull KotlinClassStub stub) { - super(stub, JetStubElementTypes.CLASS); + public constructor(stub: KotlinClassStub) : super(stub, JetStubElementTypes.CLASS) { } - @NotNull - @Override - public List getDeclarations() { - JetClassBody body = getBody(); - if (body == null) return Collections.emptyList(); + override fun getDeclarations(): List { + val body = getBody() ?: return emptyList() - return body.getDeclarations(); + return body.getDeclarations() } - @Override - public R accept(@NotNull JetVisitor visitor, D data) { - return visitor.visitClass(this, data); + override fun accept(visitor: JetVisitor, data: D): R { + return visitor.visitClass(this, data) } - @Nullable - public JetPrimaryConstructor getPrimaryConstructor() { - return getStubOrPsiChild(JetStubElementTypes.PRIMARY_CONSTRUCTOR); + public fun getPrimaryConstructor(): JetPrimaryConstructor? { + return getStubOrPsiChild(JetStubElementTypes.PRIMARY_CONSTRUCTOR) } - @Nullable - public JetParameterList getPrimaryConstructorParameterList() { - JetPrimaryConstructor primaryConstructor = getPrimaryConstructor(); - return primaryConstructor != null ? primaryConstructor.getValueParameterList() : null; + public fun getPrimaryConstructorParameterList(): JetParameterList? { + val primaryConstructor = getPrimaryConstructor() + return primaryConstructor?.getValueParameterList() } - @NotNull - public List getPrimaryConstructorParameters() { - JetParameterList list = getPrimaryConstructorParameterList(); - if (list == null) return Collections.emptyList(); - return list.getParameters(); + public fun getPrimaryConstructorParameters(): List { + val list = getPrimaryConstructorParameterList() ?: return emptyList() + return list.getParameters() } - @NotNull - public JetPrimaryConstructor createPrimaryConstructorIfAbsent() { - JetPrimaryConstructor constructor = getPrimaryConstructor(); - if (constructor != null) return constructor; - PsiElement anchor = getTypeParameterList(); - if (anchor == null) anchor = getNameIdentifier(); - if (anchor == null) anchor = getLastChild(); - return (JetPrimaryConstructor) addAfter(new JetPsiFactory(getProject()).createPrimaryConstructor(), anchor); + public fun createPrimaryConstructorIfAbsent(): JetPrimaryConstructor { + val constructor = getPrimaryConstructor() + if (constructor != null) return constructor + var anchor: PsiElement? = getTypeParameterList() + if (anchor == null) anchor = getNameIdentifier() + if (anchor == null) anchor = getLastChild() + return addAfter(JetPsiFactory(getProject()).createPrimaryConstructor(), anchor) as JetPrimaryConstructor } - @NotNull - public JetParameterList createPrimaryConstructorParameterListIfAbsent() { - JetPrimaryConstructor constructor = createPrimaryConstructorIfAbsent(); - JetParameterList parameterList = constructor.getValueParameterList(); - if (parameterList != null) return parameterList; - return (JetParameterList) constructor.add(new JetPsiFactory(getProject()).createParameterList("()")); + public fun createPrimaryConstructorParameterListIfAbsent(): JetParameterList { + val constructor = createPrimaryConstructorIfAbsent() + val parameterList = constructor.getValueParameterList() + if (parameterList != null) return parameterList + return constructor.add(JetPsiFactory(getProject()).createParameterList("()")) as JetParameterList } - @Override - @Nullable - public JetDelegationSpecifierList getDelegationSpecifierList() { - return getStubOrPsiChild(JetStubElementTypes.DELEGATION_SPECIFIER_LIST); + override fun getDelegationSpecifierList(): JetDelegationSpecifierList? { + return getStubOrPsiChild(JetStubElementTypes.DELEGATION_SPECIFIER_LIST) } - @Override - @NotNull - public List getDelegationSpecifiers() { - JetDelegationSpecifierList list = getDelegationSpecifierList(); - return list != null ? list.getDelegationSpecifiers() : Collections.emptyList(); + override fun getDelegationSpecifiers(): List { + val list = getDelegationSpecifierList() + return if (list != null) list.getDelegationSpecifiers() else emptyList() } - @Nullable - public JetModifierList getPrimaryConstructorModifierList() { - JetPrimaryConstructor primaryConstructor = getPrimaryConstructor(); - return primaryConstructor != null ? primaryConstructor.getModifierList() : null; + public fun getPrimaryConstructorModifierList(): JetModifierList? { + val primaryConstructor = getPrimaryConstructor() + return primaryConstructor?.getModifierList() } - @Override - @NotNull - public List getAnonymousInitializers() { - JetClassBody body = getBody(); - if (body == null) return Collections.emptyList(); + override fun getAnonymousInitializers(): List { + val body = getBody() ?: return emptyList() - return body.getAnonymousInitializers(); + return body.getAnonymousInitializers() } - public boolean hasExplicitPrimaryConstructor() { - return getPrimaryConstructor() != null; + public fun hasExplicitPrimaryConstructor(): Boolean { + return getPrimaryConstructor() != null } - @Override - public JetObjectDeclarationName getNameAsDeclaration() { - return (JetObjectDeclarationName) findChildByType(JetNodeTypes.OBJECT_DECLARATION_NAME); + override fun getNameAsDeclaration(): JetObjectDeclarationName? { + return findChildByType(JetNodeTypes.OBJECT_DECLARATION_NAME) as JetObjectDeclarationName } - @Override - public JetClassBody getBody() { - return getStubOrPsiChild(JetStubElementTypes.CLASS_BODY); + override fun getBody(): JetClassBody? { + return getStubOrPsiChild(JetStubElementTypes.CLASS_BODY) } - @Nullable - public PsiElement getColon() { - return findChildByType(JetTokens.COLON); + public fun getColon(): PsiElement? { + return findChildByType(JetTokens.COLON) } - public List getProperties() { - JetClassBody body = getBody(); - if (body == null) return Collections.emptyList(); + public fun getProperties(): List { + val body = getBody() ?: return emptyList() - return body.getProperties(); + return body.getProperties() } - public boolean isInterface() { - KotlinClassStub stub = getStub(); + public fun isInterface(): Boolean { + val stub = getStub() if (stub != null) { - return stub.isInterface(); + return stub.isInterface() } - return findChildByType(JetTokens.TRAIT_KEYWORD) != null || - findChildByType(JetTokens.INTERFACE_KEYWORD) != null; + return findChildByType(JetTokens.TRAIT_KEYWORD) != null || findChildByType(JetTokens.INTERFACE_KEYWORD) != null } - public boolean isEnum() { - return hasModifier(JetTokens.ENUM_KEYWORD); + public fun isEnum(): Boolean { + return hasModifier(JetTokens.ENUM_KEYWORD) } - public boolean isAnnotation() { - return hasModifier(JetTokens.ANNOTATION_KEYWORD); + public fun isAnnotation(): Boolean { + return hasModifier(JetTokens.ANNOTATION_KEYWORD) } - public boolean isInner() { - return hasModifier(JetTokens.INNER_KEYWORD); + public fun isInner(): Boolean { + return hasModifier(JetTokens.INNER_KEYWORD) } - @Override - public boolean isEquivalentTo(PsiElement another) { - if (super.isEquivalentTo(another)) { - return true; + override fun isEquivalentTo(another: PsiElement?): Boolean { + if (super.isEquivalentTo(another)) { + return true } - if (another instanceof JetClass) { - String fq1 = getQualifiedName(); - String fq2 = ((JetClass) another).getQualifiedName(); - return fq1 != null && fq2 != null && fq1.equals(fq2); + if (another is JetClass) { + val fq1 = getQualifiedName() + val fq2 = another.getQualifiedName() + return fq1 != null && fq2 != null && fq1 == fq2 } - return false; + return false } - @Nullable - private String getQualifiedName() { - KotlinClassStub stub = getStub(); + private fun getQualifiedName(): String? { + val stub = getStub() if (stub != null) { - FqName fqName = stub.getFqName(); - return fqName == null ? null : fqName.asString(); + val fqName = stub.getFqName() + return fqName?.asString() } - List parts = new ArrayList(); - JetClassOrObject current = this; + val parts = ArrayList() + var current: JetClassOrObject? = this while (current != null) { - parts.add(current.getName()); - current = PsiTreeUtil.getParentOfType(current, JetClassOrObject.class); + parts.add(current.getName()) + current = PsiTreeUtil.getParentOfType(current, javaClass()) } - PsiFile file = getContainingFile(); - if (!(file instanceof JetFile)) return null; - String fileQualifiedName = ((JetFile) file).getPackageFqName().asString(); + val file = getContainingFile() + if (file !is JetFile) return null + val fileQualifiedName = file.getPackageFqName().asString() if (!fileQualifiedName.isEmpty()) { - parts.add(fileQualifiedName); + parts.add(fileQualifiedName) } - Collections.reverse(parts); - return StringUtil.join(parts, "."); + Collections.reverse(parts) + return StringUtil.join(parts, ".") } - @Override - public ItemPresentation getPresentation() { - return ItemPresentationProviders.getItemPresentation(this); + override fun getPresentation(): ItemPresentation? { + return ItemPresentationProviders.getItemPresentation(this) } - @Override - public boolean isTopLevel() { - return getContainingFile() == getParent(); + override fun isTopLevel(): Boolean { + return getContainingFile() == getParent() } - @Override - public boolean isLocal() { - KotlinClassStub stub = getStub(); + override fun isLocal(): Boolean { + val stub = getStub() if (stub != null) { - return stub.isLocal(); + return stub.isLocal() } - return JetPsiUtil.isLocal(this); + return JetPsiUtil.isLocal(this) } - @NotNull - public List getCompanionObjects() { - JetClassBody body = getBody(); - if (body == null) { - return Collections.emptyList(); - } - return body.getAllCompanionObjects(); + public fun getCompanionObjects(): List { + val body = getBody() ?: return emptyList() + return body.getAllCompanionObjects() } - public boolean hasPrimaryConstructor() { - return hasExplicitPrimaryConstructor() || !hasSecondaryConstructors(); + public fun hasPrimaryConstructor(): Boolean { + return hasExplicitPrimaryConstructor() || !hasSecondaryConstructors() } - private boolean hasSecondaryConstructors() { - return !getSecondaryConstructors().isEmpty(); + private fun hasSecondaryConstructors(): Boolean { + return !getSecondaryConstructors().isEmpty() } - @NotNull - public List getSecondaryConstructors() { - JetClassBody body = getBody(); - return body != null ? body.getSecondaryConstructors() : Collections.emptyList(); + public fun getSecondaryConstructors(): List { + val body = getBody() + return if (body != null) body.getSecondaryConstructors() else emptyList() } - @Nullable - public PsiElement getClassOrInterfaceKeyword() { - return findChildByType(TokenSet.create(JetTokens.CLASS_KEYWORD, JetTokens.INTERFACE_KEYWORD)); + public fun getClassOrInterfaceKeyword(): PsiElement? { + return findChildByType(TokenSet.create(JetTokens.CLASS_KEYWORD, JetTokens.INTERFACE_KEYWORD)) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassOrObject.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassOrObject.kt index b16767d9971..432c2c02973 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassOrObject.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetClassOrObject.kt @@ -14,40 +14,27 @@ * limitations under the License. */ -package org.jetbrains.kotlin.psi; +package org.jetbrains.kotlin.psi -import com.intellij.psi.PsiNameIdentifierOwner; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.name.Name; +import com.intellij.psi.PsiNameIdentifierOwner +import org.jetbrains.kotlin.name.Name -import java.util.List; +public interface JetClassOrObject : PsiNameIdentifierOwner, JetDeclarationContainer, JetElement, JetModifierListOwner, JetNamedDeclaration { + public fun getDelegationSpecifierList(): JetDelegationSpecifierList? -public interface JetClassOrObject extends PsiNameIdentifierOwner, JetDeclarationContainer, JetElement, JetModifierListOwner, JetNamedDeclaration { - @Nullable - JetDelegationSpecifierList getDelegationSpecifierList(); + public fun getDelegationSpecifiers(): List - @NotNull - List getDelegationSpecifiers(); + public fun getAnonymousInitializers(): List - @NotNull - List getAnonymousInitializers(); + override fun getNameAsName(): Name? - @Override - @Nullable - Name getNameAsName(); + override fun getModifierList(): JetModifierList? - @Override - @Nullable - JetModifierList getModifierList(); + public fun getNameAsDeclaration(): JetObjectDeclarationName? - @Nullable - JetObjectDeclarationName getNameAsDeclaration(); + public fun getBody(): JetClassBody? - @Nullable - JetClassBody getBody(); + public fun isTopLevel(): Boolean - boolean isTopLevel(); - - boolean isLocal(); + public fun isLocal(): Boolean } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetObjectDeclaration.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetObjectDeclaration.kt index 7c3dc41e03f..75ae7f1578b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetObjectDeclaration.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetObjectDeclaration.kt @@ -14,176 +14,150 @@ * limitations under the License. */ -package org.jetbrains.kotlin.psi; +package org.jetbrains.kotlin.psi -import com.intellij.lang.ASTNode; -import com.intellij.navigation.ItemPresentation; -import com.intellij.navigation.ItemPresentationProviders; -import com.intellij.psi.PsiElement; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.JetNodeTypes; -import org.jetbrains.kotlin.lexer.JetModifierKeywordToken; -import org.jetbrains.kotlin.lexer.JetTokens; -import org.jetbrains.kotlin.name.SpecialNames; -import org.jetbrains.kotlin.psi.stubs.KotlinObjectStub; -import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes; +import com.intellij.lang.ASTNode +import com.intellij.navigation.ItemPresentation +import com.intellij.navigation.ItemPresentationProviders +import com.intellij.psi.PsiElement +import com.intellij.util.IncorrectOperationException +import org.jetbrains.annotations.NonNls +import org.jetbrains.kotlin.JetNodeTypes +import org.jetbrains.kotlin.lexer.JetModifierKeywordToken +import org.jetbrains.kotlin.lexer.JetTokens +import org.jetbrains.kotlin.name.SpecialNames +import org.jetbrains.kotlin.psi.stubs.KotlinObjectStub +import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes -import java.util.Collections; -import java.util.List; +import java.util.Collections -public class JetObjectDeclaration extends JetNamedDeclarationStub implements JetClassOrObject { - public JetObjectDeclaration(@NotNull ASTNode node) { - super(node); +public class JetObjectDeclaration : JetNamedDeclarationStub, JetClassOrObject { + public constructor(node: ASTNode) : super(node) { } - public JetObjectDeclaration(@NotNull KotlinObjectStub stub) { - super(stub, JetStubElementTypes.OBJECT_DECLARATION); + public constructor(stub: KotlinObjectStub) : super(stub, JetStubElementTypes.OBJECT_DECLARATION) { } - @Override - public String getName() { - KotlinObjectStub stub = getStub(); + override fun getName(): String? { + val stub = getStub() if (stub != null) { - return stub.getName(); + return stub.getName() } - JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration(); + val nameAsDeclaration = getNameAsDeclaration() if (nameAsDeclaration == null && isCompanion()) { - //NOTE: a hack in PSI that simplifies writing frontend code - return SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT.toString(); + //NOTE: a hack in PSI that simplifies writing frontend code + return SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT.toString() } - return nameAsDeclaration == null ? null : nameAsDeclaration.getName(); + return nameAsDeclaration?.getName() } - @Override - public boolean isTopLevel() { - KotlinObjectStub stub = getStub(); + override fun isTopLevel(): Boolean { + val stub = getStub() if (stub != null) { - return stub.isTopLevel(); + return stub.isTopLevel() } - return getParent() instanceof JetFile; + return getParent() is JetFile } - @Override - public PsiElement getNameIdentifier() { - JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration(); - return nameAsDeclaration == null ? null : nameAsDeclaration.getNameIdentifier(); + override fun getNameIdentifier(): PsiElement? { + val nameAsDeclaration = getNameAsDeclaration() + return nameAsDeclaration?.getNameIdentifier() } - @Override - public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { - JetObjectDeclarationName declarationName = getNameAsDeclaration(); + throws(IncorrectOperationException::class) + override fun setName(NonNls name: String): PsiElement { + val declarationName = getNameAsDeclaration() if (declarationName == null) { - JetPsiFactory psiFactory = new JetPsiFactory(getProject()); - PsiElement result = addAfter(psiFactory.createObjectDeclarationName(name), getObjectKeyword()); - addAfter(psiFactory.createWhiteSpace(), getObjectKeyword()); + val psiFactory = JetPsiFactory(getProject()) + val result = addAfter(psiFactory.createObjectDeclarationName(name), getObjectKeyword()) + addAfter(psiFactory.createWhiteSpace(), getObjectKeyword()) - return result; - } else { - return declarationName.setName(name); - } - } - - @Override - @Nullable - public JetObjectDeclarationName getNameAsDeclaration() { - return (JetObjectDeclarationName) findChildByType(JetNodeTypes.OBJECT_DECLARATION_NAME); - } - - public boolean isCompanion() { - KotlinObjectStub stub = getStub(); - if (stub != null) { - return stub.isCompanion(); - } - return hasModifier(JetTokens.COMPANION_KEYWORD); - } - - @Override - public boolean hasModifier(@NotNull JetModifierKeywordToken modifier) { - JetModifierList modifierList = getModifierList(); - return modifierList != null && modifierList.hasModifier(modifier); - } - - @Override - @Nullable - public JetDelegationSpecifierList getDelegationSpecifierList() { - return getStubOrPsiChild(JetStubElementTypes.DELEGATION_SPECIFIER_LIST); - } - - @Override - @NotNull - public List getDelegationSpecifiers() { - JetDelegationSpecifierList list = getDelegationSpecifierList(); - return list != null ? list.getDelegationSpecifiers() : Collections.emptyList(); - } - - @Override - @NotNull - public List getAnonymousInitializers() { - JetClassBody body = getBody(); - if (body == null) return Collections.emptyList(); - - return body.getAnonymousInitializers(); - } - - @Override - public JetClassBody getBody() { - return getStubOrPsiChild(JetStubElementTypes.CLASS_BODY); - } - - @Override - public boolean isLocal() { - KotlinObjectStub stub = getStub(); - if (stub != null) { - return stub.isLocal(); - } - return JetPsiUtil.isLocal(this); - } - - @Override - public int getTextOffset() { - PsiElement nameIdentifier = getNameIdentifier(); - if (nameIdentifier != null) { - return nameIdentifier.getTextRange().getStartOffset(); + return result } else { - return getObjectKeyword().getTextRange().getStartOffset(); + return declarationName.setName(name) } } - @Override - @NotNull - public List getDeclarations() { - JetClassBody body = getBody(); - if (body == null) return Collections.emptyList(); - - return body.getDeclarations(); + override fun getNameAsDeclaration(): JetObjectDeclarationName? { + return findChildByType(JetNodeTypes.OBJECT_DECLARATION_NAME) as JetObjectDeclarationName } - @Override - public R accept(@NotNull JetVisitor visitor, D data) { - return visitor.visitObjectDeclaration(this, data); - } - - public boolean isObjectLiteral() { - KotlinObjectStub stub = getStub(); + public fun isCompanion(): Boolean { + val stub = getStub() if (stub != null) { - return stub.isObjectLiteral(); + return stub.isCompanion() } - return getParent() instanceof JetObjectLiteralExpression; + return hasModifier(JetTokens.COMPANION_KEYWORD) } - @NotNull - public PsiElement getObjectKeyword() { - return findChildByType(JetTokens.OBJECT_KEYWORD); + override fun hasModifier(modifier: JetModifierKeywordToken): Boolean { + val modifierList = getModifierList() + return modifierList != null && modifierList.hasModifier(modifier) } - @Override - public ItemPresentation getPresentation() { - return ItemPresentationProviders.getItemPresentation(this); + override fun getDelegationSpecifierList(): JetDelegationSpecifierList? { + return getStubOrPsiChild(JetStubElementTypes.DELEGATION_SPECIFIER_LIST) + } + + override fun getDelegationSpecifiers(): List { + val list = getDelegationSpecifierList() + return if (list != null) list.getDelegationSpecifiers() else emptyList() + } + + override fun getAnonymousInitializers(): List { + val body = getBody() ?: return emptyList() + + return body.getAnonymousInitializers() + } + + override fun getBody(): JetClassBody? { + return getStubOrPsiChild(JetStubElementTypes.CLASS_BODY) + } + + override fun isLocal(): Boolean { + val stub = getStub() + if (stub != null) { + return stub.isLocal() + } + return JetPsiUtil.isLocal(this) + } + + override fun getTextOffset(): Int { + val nameIdentifier = getNameIdentifier() + if (nameIdentifier != null) { + return nameIdentifier.getTextRange().getStartOffset() + } + else { + return getObjectKeyword().getTextRange().getStartOffset() + } + } + + override fun getDeclarations(): List { + val body = getBody() ?: return emptyList() + + return body.getDeclarations() + } + + override fun accept(visitor: JetVisitor, data: D): R { + return visitor.visitObjectDeclaration(this, data) + } + + public fun isObjectLiteral(): Boolean { + val stub = getStub() + if (stub != null) { + return stub.isObjectLiteral() + } + return getParent() is JetObjectLiteralExpression + } + + public fun getObjectKeyword(): PsiElement { + return findChildByType(JetTokens.OBJECT_KEYWORD) + } + + override fun getPresentation(): ItemPresentation? { + return ItemPresentationProviders.getItemPresentation(this) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt index 4bfc675fdad..8268e109bed 100644 --- a/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt @@ -201,7 +201,7 @@ private fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment } } contextElement is JetClassOrObject -> { - insertNewInitializer(contextElement.getBody()) + insertNewInitializer(contextElement.getBody()!!) } contextElement is JetFunctionLiteral -> { val block = contextElement.getBodyExpression()!! diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntrySuperConstructorSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntrySuperConstructorSyntaxFix.kt index ed548cad2be..6ac30ab803c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntrySuperConstructorSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/DeprecatedEnumEntrySuperConstructorSyntaxFix.kt @@ -68,7 +68,7 @@ class DeprecatedEnumEntrySuperConstructorSyntaxFix(element: JetEnumEntry): JetIn val list = entry.getInitializerList()!! transformInitializerList(list) // Delete everything between name identifier and initializer (colon with whitespaces) - val name = entry.getNameAsDeclaration() + val name = entry.getNameAsDeclaration()!! entry.deleteChildRange(name.getNextSibling()!!, list.getPrevSibling()!!) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index 682e5af6979..c1d2e92a1ad 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -848,8 +848,8 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val adjustedDeclaration = when (declaration) { is JetNamedFunction, is JetProperty -> { val klass = psiFactory.createClass("class Foo {}") - klass.getBody().add(declaration) - (declaration.replace(klass) as JetClass).getBody().getDeclarations().first() + klass.getBody()!!.add(declaration) + (declaration.replace(klass) as JetClass).getBody()!!.getDeclarations().first() } else -> declaration }