Prettify JetClass and JetObjectDeclaration
This commit is contained in:
@@ -55,37 +55,18 @@ public open class JetClass : JetClassOrObject {
|
||||
return constructor.add(JetPsiFactory(getProject()).createParameterList("()")) as JetParameterList
|
||||
}
|
||||
|
||||
public fun getColon(): PsiElement? = findChildByType(JetTokens.COLON)
|
||||
|
||||
public fun getColon(): PsiElement? {
|
||||
return findChildByType(JetTokens.COLON)
|
||||
}
|
||||
public fun getProperties(): List<JetProperty> = getBody()?.getProperties().orEmpty()
|
||||
|
||||
public fun getProperties(): List<JetProperty> {
|
||||
val body = getBody() ?: return emptyList<JetProperty>()
|
||||
public fun isAnnotation(): Boolean = hasModifier(JetTokens.ANNOTATION_KEYWORD)
|
||||
|
||||
return body.getProperties()
|
||||
}
|
||||
public fun isInterface(): Boolean =
|
||||
getStub()?.isInterface()
|
||||
?: (findChildByType<PsiElement>(JetTokens.TRAIT_KEYWORD) != null || findChildByType<PsiElement>(JetTokens.INTERFACE_KEYWORD) != null)
|
||||
|
||||
public fun isInterface(): Boolean {
|
||||
val stub = getStub()
|
||||
if (stub != null) {
|
||||
return stub.isInterface()
|
||||
}
|
||||
|
||||
return findChildByType<PsiElement>(JetTokens.TRAIT_KEYWORD) != null || findChildByType<PsiElement>(JetTokens.INTERFACE_KEYWORD) != null
|
||||
}
|
||||
|
||||
public fun isEnum(): Boolean {
|
||||
return hasModifier(JetTokens.ENUM_KEYWORD)
|
||||
}
|
||||
|
||||
public fun isAnnotation(): Boolean {
|
||||
return hasModifier(JetTokens.ANNOTATION_KEYWORD)
|
||||
}
|
||||
|
||||
public fun isInner(): Boolean {
|
||||
return hasModifier(JetTokens.INNER_KEYWORD)
|
||||
}
|
||||
public fun isEnum(): Boolean = hasModifier(JetTokens.ENUM_KEYWORD)
|
||||
public fun isInner(): Boolean = hasModifier(JetTokens.INNER_KEYWORD)
|
||||
|
||||
override fun isEquivalentTo(another: PsiElement?): Boolean {
|
||||
if (super.isEquivalentTo(another)) {
|
||||
@@ -122,12 +103,7 @@ public open class JetClass : JetClassOrObject {
|
||||
return StringUtil.join(parts, ".")
|
||||
}
|
||||
|
||||
public fun getCompanionObjects(): List<JetObjectDeclaration> {
|
||||
val body = getBody() ?: return emptyList<JetObjectDeclaration>()
|
||||
return body.getAllCompanionObjects()
|
||||
}
|
||||
public fun getCompanionObjects(): List<JetObjectDeclaration> = getBody()?.getAllCompanionObjects().orEmpty()
|
||||
|
||||
public fun getClassOrInterfaceKeyword(): PsiElement? {
|
||||
return findChildByType(TokenSet.create(JetTokens.CLASS_KEYWORD, JetTokens.INTERFACE_KEYWORD))
|
||||
}
|
||||
public fun getClassOrInterfaceKeyword(): PsiElement? = findChildByType(TokenSet.create(JetTokens.CLASS_KEYWORD, JetTokens.INTERFACE_KEYWORD))
|
||||
}
|
||||
|
||||
@@ -48,12 +48,8 @@ public class JetObjectDeclaration : JetClassOrObject {
|
||||
return nameAsDeclaration?.getName()
|
||||
}
|
||||
|
||||
override fun getNameIdentifier(): PsiElement? {
|
||||
val nameAsDeclaration = getNameAsDeclaration()
|
||||
return nameAsDeclaration?.getNameIdentifier()
|
||||
}
|
||||
override fun getNameIdentifier(): PsiElement? = getNameAsDeclaration()?.getNameIdentifier()
|
||||
|
||||
throws(IncorrectOperationException::class)
|
||||
override fun setName(NonNls name: String): PsiElement {
|
||||
val declarationName = getNameAsDeclaration()
|
||||
if (declarationName == null) {
|
||||
@@ -68,37 +64,16 @@ public class JetObjectDeclaration : JetClassOrObject {
|
||||
}
|
||||
}
|
||||
|
||||
public fun isCompanion(): Boolean {
|
||||
val stub = getStub()
|
||||
if (stub != null) {
|
||||
return stub.isCompanion()
|
||||
}
|
||||
return hasModifier(JetTokens.COMPANION_KEYWORD)
|
||||
}
|
||||
public fun isCompanion(): Boolean = getStub()?.isCompanion() ?: hasModifier(JetTokens.COMPANION_KEYWORD)
|
||||
|
||||
override fun getTextOffset(): Int {
|
||||
val nameIdentifier = getNameIdentifier()
|
||||
if (nameIdentifier != null) {
|
||||
return nameIdentifier.getTextRange().getStartOffset()
|
||||
}
|
||||
else {
|
||||
return getObjectKeyword().getTextRange().getStartOffset()
|
||||
}
|
||||
}
|
||||
override fun getTextOffset(): Int = getNameIdentifier()?.getTextRange()?.getStartOffset()
|
||||
?: getObjectKeyword().getTextRange().getStartOffset()
|
||||
|
||||
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 isObjectLiteral(): Boolean = getStub()?.isObjectLiteral() ?: (getParent() is JetObjectLiteralExpression)
|
||||
|
||||
public fun getObjectKeyword(): PsiElement {
|
||||
return findChildByType(JetTokens.OBJECT_KEYWORD)
|
||||
}
|
||||
public fun getObjectKeyword(): PsiElement = findChildByType(JetTokens.OBJECT_KEYWORD)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user