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