Convert JetClassOrObject and inheritors: J2K

This commit is contained in:
Denis Zharkov
2015-05-27 17:55:09 +03:00
parent bfa667f569
commit 5b1a5deae4
6 changed files with 245 additions and 323 deletions
@@ -14,246 +14,207 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.psi; package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode
import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.ItemPresentationProviders; import com.intellij.navigation.ItemPresentationProviders
import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile
import com.intellij.psi.tree.TokenSet; import com.intellij.psi.tree.TokenSet
import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.IncorrectOperationException; import com.intellij.util.IncorrectOperationException
import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.JetNodeTypes
import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.JetNodeTypes; import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.lexer.JetTokens; import org.jetbrains.kotlin.psi.stubs.KotlinClassStub
import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
import org.jetbrains.kotlin.psi.stubs.KotlinClassStub;
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes;
import java.util.ArrayList; import java.util.ArrayList
import java.util.Collections; import java.util.Collections
import java.util.List;
public class JetClass extends JetTypeParameterListOwnerStub<KotlinClassStub> implements JetClassOrObject { public open class JetClass : JetTypeParameterListOwnerStub<KotlinClassStub>, JetClassOrObject {
public JetClass(@NotNull ASTNode node) { public constructor(node: ASTNode) : super(node) {
super(node);
} }
public JetClass(@NotNull KotlinClassStub stub) { public constructor(stub: KotlinClassStub) : super(stub, JetStubElementTypes.CLASS) {
super(stub, JetStubElementTypes.CLASS);
} }
@NotNull override fun getDeclarations(): List<JetDeclaration> {
@Override val body = getBody() ?: return emptyList<JetDeclaration>()
public List<JetDeclaration> getDeclarations() {
JetClassBody body = getBody();
if (body == null) return Collections.emptyList();
return body.getDeclarations(); return body.getDeclarations()
} }
@Override override fun <R, D> accept(visitor: JetVisitor<R, D>, data: D): R {
public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) { return visitor.visitClass(this, data)
return visitor.visitClass(this, data);
} }
@Nullable public fun getPrimaryConstructor(): JetPrimaryConstructor? {
public JetPrimaryConstructor getPrimaryConstructor() { return getStubOrPsiChild(JetStubElementTypes.PRIMARY_CONSTRUCTOR)
return getStubOrPsiChild(JetStubElementTypes.PRIMARY_CONSTRUCTOR);
} }
@Nullable public fun getPrimaryConstructorParameterList(): JetParameterList? {
public JetParameterList getPrimaryConstructorParameterList() { val primaryConstructor = getPrimaryConstructor()
JetPrimaryConstructor primaryConstructor = getPrimaryConstructor(); return primaryConstructor?.getValueParameterList()
return primaryConstructor != null ? primaryConstructor.getValueParameterList() : null;
} }
@NotNull public fun getPrimaryConstructorParameters(): List<JetParameter> {
public List<JetParameter> getPrimaryConstructorParameters() { val list = getPrimaryConstructorParameterList() ?: return emptyList<JetParameter>()
JetParameterList list = getPrimaryConstructorParameterList(); return list.getParameters()
if (list == null) return Collections.emptyList();
return list.getParameters();
} }
@NotNull public fun createPrimaryConstructorIfAbsent(): JetPrimaryConstructor {
public JetPrimaryConstructor createPrimaryConstructorIfAbsent() { val constructor = getPrimaryConstructor()
JetPrimaryConstructor constructor = getPrimaryConstructor(); if (constructor != null) return constructor
if (constructor != null) return constructor; var anchor: PsiElement? = getTypeParameterList()
PsiElement anchor = getTypeParameterList(); if (anchor == null) anchor = getNameIdentifier()
if (anchor == null) anchor = getNameIdentifier(); if (anchor == null) anchor = getLastChild()
if (anchor == null) anchor = getLastChild(); return addAfter(JetPsiFactory(getProject()).createPrimaryConstructor(), anchor) as JetPrimaryConstructor
return (JetPrimaryConstructor) addAfter(new JetPsiFactory(getProject()).createPrimaryConstructor(), anchor);
} }
@NotNull public fun createPrimaryConstructorParameterListIfAbsent(): JetParameterList {
public JetParameterList createPrimaryConstructorParameterListIfAbsent() { val constructor = createPrimaryConstructorIfAbsent()
JetPrimaryConstructor constructor = createPrimaryConstructorIfAbsent(); val parameterList = constructor.getValueParameterList()
JetParameterList parameterList = constructor.getValueParameterList(); if (parameterList != null) return parameterList
if (parameterList != null) return parameterList; return constructor.add(JetPsiFactory(getProject()).createParameterList("()")) as JetParameterList
return (JetParameterList) constructor.add(new JetPsiFactory(getProject()).createParameterList("()"));
} }
@Override override fun getDelegationSpecifierList(): JetDelegationSpecifierList? {
@Nullable return getStubOrPsiChild(JetStubElementTypes.DELEGATION_SPECIFIER_LIST)
public JetDelegationSpecifierList getDelegationSpecifierList() {
return getStubOrPsiChild(JetStubElementTypes.DELEGATION_SPECIFIER_LIST);
} }
@Override override fun getDelegationSpecifiers(): List<JetDelegationSpecifier> {
@NotNull val list = getDelegationSpecifierList()
public List<JetDelegationSpecifier> getDelegationSpecifiers() { return if (list != null) list.getDelegationSpecifiers() else emptyList<JetDelegationSpecifier>()
JetDelegationSpecifierList list = getDelegationSpecifierList();
return list != null ? list.getDelegationSpecifiers() : Collections.<JetDelegationSpecifier>emptyList();
} }
@Nullable public fun getPrimaryConstructorModifierList(): JetModifierList? {
public JetModifierList getPrimaryConstructorModifierList() { val primaryConstructor = getPrimaryConstructor()
JetPrimaryConstructor primaryConstructor = getPrimaryConstructor(); return primaryConstructor?.getModifierList()
return primaryConstructor != null ? primaryConstructor.getModifierList() : null;
} }
@Override override fun getAnonymousInitializers(): List<JetClassInitializer> {
@NotNull val body = getBody() ?: return emptyList<JetClassInitializer>()
public List<JetClassInitializer> getAnonymousInitializers() {
JetClassBody body = getBody();
if (body == null) return Collections.emptyList();
return body.getAnonymousInitializers(); return body.getAnonymousInitializers()
} }
public boolean hasExplicitPrimaryConstructor() { public fun hasExplicitPrimaryConstructor(): Boolean {
return getPrimaryConstructor() != null; return getPrimaryConstructor() != null
} }
@Override override fun getNameAsDeclaration(): JetObjectDeclarationName? {
public JetObjectDeclarationName getNameAsDeclaration() { return findChildByType<PsiElement>(JetNodeTypes.OBJECT_DECLARATION_NAME) as JetObjectDeclarationName
return (JetObjectDeclarationName) findChildByType(JetNodeTypes.OBJECT_DECLARATION_NAME);
} }
@Override override fun getBody(): JetClassBody? {
public JetClassBody getBody() { return getStubOrPsiChild(JetStubElementTypes.CLASS_BODY)
return getStubOrPsiChild(JetStubElementTypes.CLASS_BODY);
} }
@Nullable public fun getColon(): PsiElement? {
public PsiElement getColon() { return findChildByType(JetTokens.COLON)
return findChildByType(JetTokens.COLON);
} }
public List<JetProperty> getProperties() { public fun getProperties(): List<JetProperty> {
JetClassBody body = getBody(); val body = getBody() ?: return emptyList<JetProperty>()
if (body == null) return Collections.emptyList();
return body.getProperties(); return body.getProperties()
} }
public boolean isInterface() { public fun isInterface(): Boolean {
KotlinClassStub stub = getStub(); val stub = getStub()
if (stub != null) { if (stub != null) {
return stub.isInterface(); return stub.isInterface()
} }
return findChildByType(JetTokens.TRAIT_KEYWORD) != null || return findChildByType<PsiElement>(JetTokens.TRAIT_KEYWORD) != null || findChildByType<PsiElement>(JetTokens.INTERFACE_KEYWORD) != null
findChildByType(JetTokens.INTERFACE_KEYWORD) != null;
} }
public boolean isEnum() { public fun isEnum(): Boolean {
return hasModifier(JetTokens.ENUM_KEYWORD); return hasModifier(JetTokens.ENUM_KEYWORD)
} }
public boolean isAnnotation() { public fun isAnnotation(): Boolean {
return hasModifier(JetTokens.ANNOTATION_KEYWORD); return hasModifier(JetTokens.ANNOTATION_KEYWORD)
} }
public boolean isInner() { public fun isInner(): Boolean {
return hasModifier(JetTokens.INNER_KEYWORD); return hasModifier(JetTokens.INNER_KEYWORD)
} }
@Override override fun isEquivalentTo(another: PsiElement?): Boolean {
public boolean isEquivalentTo(PsiElement another) { if (super<JetTypeParameterListOwnerStub>.isEquivalentTo(another)) {
if (super.isEquivalentTo(another)) { return true
return true;
} }
if (another instanceof JetClass) { if (another is JetClass) {
String fq1 = getQualifiedName(); val fq1 = getQualifiedName()
String fq2 = ((JetClass) another).getQualifiedName(); val fq2 = another.getQualifiedName()
return fq1 != null && fq2 != null && fq1.equals(fq2); return fq1 != null && fq2 != null && fq1 == fq2
} }
return false; return false
} }
@Nullable private fun getQualifiedName(): String? {
private String getQualifiedName() { val stub = getStub()
KotlinClassStub stub = getStub();
if (stub != null) { if (stub != null) {
FqName fqName = stub.getFqName(); val fqName = stub.getFqName()
return fqName == null ? null : fqName.asString(); return fqName?.asString()
} }
List<String> parts = new ArrayList<String>(); val parts = ArrayList<String>()
JetClassOrObject current = this; var current: JetClassOrObject? = this
while (current != null) { while (current != null) {
parts.add(current.getName()); parts.add(current.getName())
current = PsiTreeUtil.getParentOfType(current, JetClassOrObject.class); current = PsiTreeUtil.getParentOfType<JetClassOrObject>(current, javaClass<JetClassOrObject>())
} }
PsiFile file = getContainingFile(); val file = getContainingFile()
if (!(file instanceof JetFile)) return null; if (file !is JetFile) return null
String fileQualifiedName = ((JetFile) file).getPackageFqName().asString(); val fileQualifiedName = file.getPackageFqName().asString()
if (!fileQualifiedName.isEmpty()) { if (!fileQualifiedName.isEmpty()) {
parts.add(fileQualifiedName); parts.add(fileQualifiedName)
} }
Collections.reverse(parts); Collections.reverse(parts)
return StringUtil.join(parts, "."); return StringUtil.join(parts, ".")
} }
@Override override fun getPresentation(): ItemPresentation? {
public ItemPresentation getPresentation() { return ItemPresentationProviders.getItemPresentation(this)
return ItemPresentationProviders.getItemPresentation(this);
} }
@Override override fun isTopLevel(): Boolean {
public boolean isTopLevel() { return getContainingFile() == getParent()
return getContainingFile() == getParent();
} }
@Override override fun isLocal(): Boolean {
public boolean isLocal() { val stub = getStub()
KotlinClassStub stub = getStub();
if (stub != null) { if (stub != null) {
return stub.isLocal(); return stub.isLocal()
} }
return JetPsiUtil.isLocal(this); return JetPsiUtil.isLocal(this)
} }
@NotNull public fun getCompanionObjects(): List<JetObjectDeclaration> {
public List<JetObjectDeclaration> getCompanionObjects() { val body = getBody() ?: return emptyList<JetObjectDeclaration>()
JetClassBody body = getBody(); return body.getAllCompanionObjects()
if (body == null) {
return Collections.emptyList();
}
return body.getAllCompanionObjects();
} }
public boolean hasPrimaryConstructor() { public fun hasPrimaryConstructor(): Boolean {
return hasExplicitPrimaryConstructor() || !hasSecondaryConstructors(); return hasExplicitPrimaryConstructor() || !hasSecondaryConstructors()
} }
private boolean hasSecondaryConstructors() { private fun hasSecondaryConstructors(): Boolean {
return !getSecondaryConstructors().isEmpty(); return !getSecondaryConstructors().isEmpty()
} }
@NotNull public fun getSecondaryConstructors(): List<JetSecondaryConstructor> {
public List<JetSecondaryConstructor> getSecondaryConstructors() { val body = getBody()
JetClassBody body = getBody(); return if (body != null) body.getSecondaryConstructors() else emptyList<JetSecondaryConstructor>()
return body != null ? body.getSecondaryConstructors() : Collections.<JetSecondaryConstructor>emptyList();
} }
@Nullable public fun getClassOrInterfaceKeyword(): PsiElement? {
public PsiElement getClassOrInterfaceKeyword() { return findChildByType(TokenSet.create(JetTokens.CLASS_KEYWORD, JetTokens.INTERFACE_KEYWORD))
return findChildByType(TokenSet.create(JetTokens.CLASS_KEYWORD, JetTokens.INTERFACE_KEYWORD));
} }
} }
@@ -14,40 +14,27 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.psi; package org.jetbrains.kotlin.psi
import com.intellij.psi.PsiNameIdentifierOwner; import com.intellij.psi.PsiNameIdentifierOwner
import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.name.Name
import org.jetbrains.annotations.Nullable;
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 { public fun getDelegationSpecifiers(): List<JetDelegationSpecifier>
@Nullable
JetDelegationSpecifierList getDelegationSpecifierList();
@NotNull public fun getAnonymousInitializers(): List<JetClassInitializer>
List<JetDelegationSpecifier> getDelegationSpecifiers();
@NotNull override fun getNameAsName(): Name?
List<JetClassInitializer> getAnonymousInitializers();
@Override override fun getModifierList(): JetModifierList?
@Nullable
Name getNameAsName();
@Override public fun getNameAsDeclaration(): JetObjectDeclarationName?
@Nullable
JetModifierList getModifierList();
@Nullable public fun getBody(): JetClassBody?
JetObjectDeclarationName getNameAsDeclaration();
@Nullable public fun isTopLevel(): Boolean
JetClassBody getBody();
boolean isTopLevel(); public fun isLocal(): Boolean
boolean isLocal();
} }
@@ -14,176 +14,150 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.kotlin.psi; package org.jetbrains.kotlin.psi
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode
import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentation
import com.intellij.navigation.ItemPresentationProviders; import com.intellij.navigation.ItemPresentationProviders
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement
import com.intellij.util.IncorrectOperationException; import com.intellij.util.IncorrectOperationException
import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.JetNodeTypes
import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
import org.jetbrains.kotlin.JetNodeTypes; import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken; import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.lexer.JetTokens; import org.jetbrains.kotlin.psi.stubs.KotlinObjectStub
import org.jetbrains.kotlin.name.SpecialNames; import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
import org.jetbrains.kotlin.psi.stubs.KotlinObjectStub;
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes;
import java.util.Collections; import java.util.Collections
import java.util.List;
public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectStub> implements JetClassOrObject { public class JetObjectDeclaration : JetNamedDeclarationStub<KotlinObjectStub>, JetClassOrObject {
public JetObjectDeclaration(@NotNull ASTNode node) { public constructor(node: ASTNode) : super(node) {
super(node);
} }
public JetObjectDeclaration(@NotNull KotlinObjectStub stub) { public constructor(stub: KotlinObjectStub) : super(stub, JetStubElementTypes.OBJECT_DECLARATION) {
super(stub, JetStubElementTypes.OBJECT_DECLARATION);
} }
@Override override fun getName(): String? {
public String getName() { val stub = getStub()
KotlinObjectStub stub = getStub();
if (stub != null) { if (stub != null) {
return stub.getName(); return stub.getName()
} }
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration(); val nameAsDeclaration = getNameAsDeclaration()
if (nameAsDeclaration == null && isCompanion()) { if (nameAsDeclaration == null && isCompanion()) {
//NOTE: a hack in PSI that simplifies writing frontend code //NOTE: a hack in PSI that simplifies writing frontend code
return SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT.toString(); return SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT.toString()
} }
return nameAsDeclaration == null ? null : nameAsDeclaration.getName(); return nameAsDeclaration?.getName()
} }
@Override override fun isTopLevel(): Boolean {
public boolean isTopLevel() { val stub = getStub()
KotlinObjectStub stub = getStub();
if (stub != null) { if (stub != null) {
return stub.isTopLevel(); return stub.isTopLevel()
} }
return getParent() instanceof JetFile; return getParent() is JetFile
} }
@Override override fun getNameIdentifier(): PsiElement? {
public PsiElement getNameIdentifier() { val nameAsDeclaration = getNameAsDeclaration()
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration(); return nameAsDeclaration?.getNameIdentifier()
return nameAsDeclaration == null ? null : nameAsDeclaration.getNameIdentifier();
} }
@Override throws(IncorrectOperationException::class)
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { override fun setName(NonNls name: String): PsiElement {
JetObjectDeclarationName declarationName = getNameAsDeclaration(); val declarationName = getNameAsDeclaration()
if (declarationName == null) { if (declarationName == null) {
JetPsiFactory psiFactory = new JetPsiFactory(getProject()); val psiFactory = JetPsiFactory(getProject())
PsiElement result = addAfter(psiFactory.createObjectDeclarationName(name), getObjectKeyword()); val result = addAfter(psiFactory.createObjectDeclarationName(name), getObjectKeyword())
addAfter(psiFactory.createWhiteSpace(), getObjectKeyword()); addAfter(psiFactory.createWhiteSpace(), getObjectKeyword())
return result; 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<JetDelegationSpecifier> getDelegationSpecifiers() {
JetDelegationSpecifierList list = getDelegationSpecifierList();
return list != null ? list.getDelegationSpecifiers() : Collections.<JetDelegationSpecifier>emptyList();
}
@Override
@NotNull
public List<JetClassInitializer> 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();
} }
else { else {
return getObjectKeyword().getTextRange().getStartOffset(); return declarationName.setName(name)
} }
} }
@Override override fun getNameAsDeclaration(): JetObjectDeclarationName? {
@NotNull return findChildByType<PsiElement>(JetNodeTypes.OBJECT_DECLARATION_NAME) as JetObjectDeclarationName
public List<JetDeclaration> getDeclarations() {
JetClassBody body = getBody();
if (body == null) return Collections.emptyList();
return body.getDeclarations();
} }
@Override public fun isCompanion(): Boolean {
public <R, D> R accept(@NotNull JetVisitor<R, D> visitor, D data) { val stub = getStub()
return visitor.visitObjectDeclaration(this, data);
}
public boolean isObjectLiteral() {
KotlinObjectStub stub = getStub();
if (stub != null) { if (stub != null) {
return stub.isObjectLiteral(); return stub.isCompanion()
} }
return getParent() instanceof JetObjectLiteralExpression; return hasModifier(JetTokens.COMPANION_KEYWORD)
} }
@NotNull override fun hasModifier(modifier: JetModifierKeywordToken): Boolean {
public PsiElement getObjectKeyword() { val modifierList = getModifierList()
return findChildByType(JetTokens.OBJECT_KEYWORD); return modifierList != null && modifierList.hasModifier(modifier)
} }
@Override override fun getDelegationSpecifierList(): JetDelegationSpecifierList? {
public ItemPresentation getPresentation() { return getStubOrPsiChild(JetStubElementTypes.DELEGATION_SPECIFIER_LIST)
return ItemPresentationProviders.getItemPresentation(this); }
override fun getDelegationSpecifiers(): List<JetDelegationSpecifier> {
val list = getDelegationSpecifierList()
return if (list != null) list.getDelegationSpecifiers() else emptyList<JetDelegationSpecifier>()
}
override fun getAnonymousInitializers(): List<JetClassInitializer> {
val body = getBody() ?: return emptyList<JetClassInitializer>()
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<JetDeclaration> {
val body = getBody() ?: return emptyList<JetDeclaration>()
return body.getDeclarations()
}
override fun <R, D> accept(visitor: JetVisitor<R, D>, 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)
} }
} }
@@ -201,7 +201,7 @@ private fun addDebugExpressionBeforeContextElement(codeFragment: JetCodeFragment
} }
} }
contextElement is JetClassOrObject -> { contextElement is JetClassOrObject -> {
insertNewInitializer(contextElement.getBody()) insertNewInitializer(contextElement.getBody()!!)
} }
contextElement is JetFunctionLiteral -> { contextElement is JetFunctionLiteral -> {
val block = contextElement.getBodyExpression()!! val block = contextElement.getBodyExpression()!!
@@ -68,7 +68,7 @@ class DeprecatedEnumEntrySuperConstructorSyntaxFix(element: JetEnumEntry): JetIn
val list = entry.getInitializerList()!! val list = entry.getInitializerList()!!
transformInitializerList(list) transformInitializerList(list)
// Delete everything between name identifier and initializer (colon with whitespaces) // Delete everything between name identifier and initializer (colon with whitespaces)
val name = entry.getNameAsDeclaration() val name = entry.getNameAsDeclaration()!!
entry.deleteChildRange(name.getNextSibling()!!, list.getPrevSibling()!!) entry.deleteChildRange(name.getNextSibling()!!, list.getPrevSibling()!!)
} }
} }
@@ -848,8 +848,8 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
val adjustedDeclaration = when (declaration) { val adjustedDeclaration = when (declaration) {
is JetNamedFunction, is JetProperty -> { is JetNamedFunction, is JetProperty -> {
val klass = psiFactory.createClass("class Foo {}") val klass = psiFactory.createClass("class Foo {}")
klass.getBody().add(declaration) klass.getBody()!!.add(declaration)
(declaration.replace(klass) as JetClass).getBody().getDeclarations().first() (declaration.replace(klass) as JetClass).getBody()!!.getDeclarations().first()
} }
else -> declaration else -> declaration
} }