J2K: Insert class body for anonymous classes
#KT-8952 Fixed
This commit is contained in:
@@ -42,7 +42,8 @@ enum class AccessorKind {
|
|||||||
class ClassBodyConverter(private val psiClass: PsiClass,
|
class ClassBodyConverter(private val psiClass: PsiClass,
|
||||||
private val converter: Converter,
|
private val converter: Converter,
|
||||||
private val isOpenClass: Boolean,
|
private val isOpenClass: Boolean,
|
||||||
private val isObject: Boolean) {
|
private val isObject: Boolean,
|
||||||
|
private val isAnonymousObject: Boolean = false) {
|
||||||
private val membersToRemove = HashSet<PsiMember>()
|
private val membersToRemove = HashSet<PsiMember>()
|
||||||
private val fieldCorrections = HashMap<PsiField, FieldCorrectionInfo>()
|
private val fieldCorrections = HashMap<PsiField, FieldCorrectionInfo>()
|
||||||
|
|
||||||
@@ -93,7 +94,7 @@ class ClassBodyConverter(private val psiClass: PsiClass,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ClassBody(null, null, convertedMembers.values().toList(), emptyList(), lBrace, rBrace, false)
|
return ClassBody(null, null, convertedMembers.values().toList(), emptyList(), lBrace, rBrace, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
val useCompanionObject = shouldGenerateCompanionObject(convertedMembers)
|
val useCompanionObject = shouldGenerateCompanionObject(convertedMembers)
|
||||||
@@ -120,6 +121,7 @@ class ClassBodyConverter(private val psiClass: PsiClass,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (primaryConstructorSignature != null
|
if (primaryConstructorSignature != null
|
||||||
|
&& !isAnonymousObject
|
||||||
&& primaryConstructorSignature.annotations.isEmpty
|
&& primaryConstructorSignature.annotations.isEmpty
|
||||||
&& primaryConstructorSignature.accessModifier == null
|
&& primaryConstructorSignature.accessModifier == null
|
||||||
&& primaryConstructorSignature.parameterList.parameters.isEmpty()
|
&& primaryConstructorSignature.parameterList.parameters.isEmpty()
|
||||||
@@ -128,7 +130,7 @@ class ClassBodyConverter(private val psiClass: PsiClass,
|
|||||||
primaryConstructorSignature = null // no "()" after class name is needed in this case
|
primaryConstructorSignature = null // no "()" after class name is needed in this case
|
||||||
}
|
}
|
||||||
|
|
||||||
return ClassBody(primaryConstructorSignature, constructorConverter?.baseClassParams, members, companionObjectMembers, lBrace, rBrace, psiClass.isEnum())
|
return ClassBody(primaryConstructorSignature, constructorConverter?.baseClassParams, members, companionObjectMembers, lBrace, rBrace, psiClass.isEnum(), isAnonymousObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Converter.convertMember(member: PsiMember,
|
private fun Converter.convertMember(member: PsiMember,
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ class Converter private constructor(
|
|||||||
// to convert fields and nested types - they are not allowed in Kotlin but we convert them and let user refactor code
|
// to convert fields and nested types - they are not allowed in Kotlin but we convert them and let user refactor code
|
||||||
var classBody = ClassBodyConverter(psiClass, this, isOpenClass = false, isObject = false).convertBody()
|
var classBody = ClassBodyConverter(psiClass, this, isOpenClass = false, isObject = false).convertBody()
|
||||||
classBody = ClassBody(constructorSignature, classBody.baseClassParams, classBody.members,
|
classBody = ClassBody(constructorSignature, classBody.baseClassParams, classBody.members,
|
||||||
classBody.companionObjectMembers, classBody.lBrace, classBody.rBrace, classBody.isEnumBody)
|
classBody.companionObjectMembers, classBody.lBrace, classBody.rBrace, classBody.isEnumBody, classBody.isAnonymousClassBody)
|
||||||
|
|
||||||
val annotationAnnotation = Annotation(Identifier("annotation").assignNoPrototype(), listOf(), withAt = false, newLineAfter = false).assignNoPrototype()
|
val annotationAnnotation = Annotation(Identifier("annotation").assignNoPrototype(), listOf(), withAt = false, newLineAfter = false).assignNoPrototype()
|
||||||
return Class(psiClass.declarationIdentifier(),
|
return Class(psiClass.declarationIdentifier(),
|
||||||
@@ -564,7 +564,7 @@ class Converter private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun convertAnonymousClassBody(anonymousClass: PsiAnonymousClass): AnonymousClassBody {
|
public fun convertAnonymousClassBody(anonymousClass: PsiAnonymousClass): AnonymousClassBody {
|
||||||
return AnonymousClassBody(ClassBodyConverter(anonymousClass, this, isOpenClass = false, isObject = false).convertBody(),
|
return AnonymousClassBody(ClassBodyConverter(anonymousClass, this, isOpenClass = false, isObject = false, isAnonymousObject = true).convertBody(),
|
||||||
anonymousClass.getBaseClassType().resolve()?.isInterface() ?: false).assignPrototype(anonymousClass)
|
anonymousClass.getBaseClassType().resolve()?.isInterface() ?: false).assignPrototype(anonymousClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,11 +31,12 @@ class ClassBody (
|
|||||||
val companionObjectMembers: List<Member>,
|
val companionObjectMembers: List<Member>,
|
||||||
val lBrace: LBrace,
|
val lBrace: LBrace,
|
||||||
val rBrace: RBrace,
|
val rBrace: RBrace,
|
||||||
val isEnumBody: Boolean) {
|
val isEnumBody: Boolean,
|
||||||
|
val isAnonymousClassBody: Boolean) {
|
||||||
|
|
||||||
fun appendTo(builder: CodeBuilder) {
|
fun appendTo(builder: CodeBuilder) {
|
||||||
val membersFiltered = members.filter { !it.isEmpty }
|
val membersFiltered = members.filter { !it.isEmpty }
|
||||||
if (membersFiltered.isEmpty() && companionObjectMembers.isEmpty()) return
|
if (!isAnonymousClassBody && membersFiltered.isEmpty() && companionObjectMembers.isEmpty()) return
|
||||||
|
|
||||||
builder append " " append lBrace append "\n"
|
builder append " " append lBrace append "\n"
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ interface WindowListener {
|
|||||||
void windowClosing ();
|
void windowClosing ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EmptyWindowListener {
|
||||||
|
}
|
||||||
|
|
||||||
|
open class EmptyWindowAdapter : EmptyWindowListener {}
|
||||||
|
|
||||||
class WindowAdapter implements WindowListener {
|
class WindowAdapter implements WindowListener {
|
||||||
public void windowClosing () {
|
public void windowClosing () {
|
||||||
}
|
}
|
||||||
@@ -29,5 +34,8 @@ public final class Client extends Frame {
|
|||||||
public void windowClosing () {
|
public void windowClosing () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
EmptyWindowListener b = new EmptyWindowListener() {};
|
||||||
|
EmptyWindowAdapter c = new EmptyWindowAdapter() {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,9 @@ interface WindowListener {
|
|||||||
public fun windowClosing()
|
public fun windowClosing()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface EmptyWindowListener
|
||||||
|
open class EmptyWindowAdapter
|
||||||
|
|
||||||
open class WindowAdapter : WindowListener {
|
open class WindowAdapter : WindowListener {
|
||||||
override fun windowClosing() {
|
override fun windowClosing() {
|
||||||
}
|
}
|
||||||
@@ -27,5 +30,12 @@ public class Client : Frame() {
|
|||||||
override fun windowClosing() {
|
override fun windowClosing() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
val b = object : EmptyWindowListener {
|
||||||
|
|
||||||
|
}
|
||||||
|
val c = object : EmptyWindowAdapter() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user