MInor corrections after code review
This commit is contained in:
@@ -216,8 +216,8 @@ class ConstructorConverter(
|
|||||||
accessModifiers,
|
accessModifiers,
|
||||||
default)
|
default)
|
||||||
.assignPrototypes(
|
.assignPrototypes(
|
||||||
PrototypeInfo(parameter, CommentsAndSpacesInheritance(spacesBefore = SpacesInheritance.LINE_BREAKS)),
|
PrototypeInfo(parameter, CommentsAndSpacesInheritance.LINE_BREAKS),
|
||||||
PrototypeInfo(field, CommentsAndSpacesInheritance(spacesBefore = SpacesInheritance.NONE))
|
PrototypeInfo(field, CommentsAndSpacesInheritance.NO_SPACES)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -244,19 +244,18 @@ class Converter private constructor(
|
|||||||
|
|
||||||
private fun convertAnnotationType(psiClass: PsiClass): Class {
|
private fun convertAnnotationType(psiClass: PsiClass): Class {
|
||||||
val paramModifiers = Modifiers(listOf(Modifier.PUBLIC)).assignNoPrototype()
|
val paramModifiers = Modifiers(listOf(Modifier.PUBLIC)).assignNoPrototype()
|
||||||
val noBlankLinesInheritance = CommentsAndSpacesInheritance(spacesBefore = SpacesInheritance.NONE)
|
|
||||||
val annotationMethods = psiClass.getMethods().filterIsInstance<PsiAnnotationMethod>()
|
val annotationMethods = psiClass.getMethods().filterIsInstance<PsiAnnotationMethod>()
|
||||||
val (methodsNamedValue, otherMethods) = annotationMethods.partition { it.getName() == "value" }
|
val (methodsNamedValue, otherMethods) = annotationMethods.partition { it.getName() == "value" }
|
||||||
|
|
||||||
fun createParameter(type: Type, method: PsiAnnotationMethod): Parameter {
|
fun createParameter(type: Type, method: PsiAnnotationMethod): Parameter {
|
||||||
type.assignPrototype(method.getReturnTypeElement(), noBlankLinesInheritance)
|
type.assignPrototype(method.getReturnTypeElement(), CommentsAndSpacesInheritance.NO_SPACES)
|
||||||
|
|
||||||
return Parameter(method.declarationIdentifier(),
|
return Parameter(method.declarationIdentifier(),
|
||||||
type,
|
type,
|
||||||
Parameter.VarValModifier.Val,
|
Parameter.VarValModifier.Val,
|
||||||
convertAnnotations(method),
|
convertAnnotations(method),
|
||||||
paramModifiers,
|
paramModifiers,
|
||||||
annotationConverter.convertAnnotationMethodDefault(method)).assignPrototype(method, noBlankLinesInheritance)
|
annotationConverter.convertAnnotationMethodDefault(method)).assignPrototype(method, CommentsAndSpacesInheritance.NO_SPACES)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun convertType(psiType: PsiType?): Type {
|
fun convertType(psiType: PsiType?): Type {
|
||||||
@@ -320,7 +319,7 @@ class Converter private constructor(
|
|||||||
}
|
}
|
||||||
val body = field.getInitializingClass()?.let { convertAnonymousClassBody(it) }
|
val body = field.getInitializingClass()?.let { convertAnonymousClassBody(it) }
|
||||||
return EnumConstant(name, annotations, modifiers, params, body)
|
return EnumConstant(name, annotations, modifiers, params, body)
|
||||||
.assignPrototype(field, CommentsAndSpacesInheritance(spacesBefore = SpacesInheritance.LINE_BREAKS))
|
.assignPrototype(field, CommentsAndSpacesInheritance.LINE_BREAKS)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val isVal = isVal(referenceSearcher, field)
|
val isVal = isVal(referenceSearcher, field)
|
||||||
@@ -339,7 +338,8 @@ class Converter private constructor(
|
|||||||
isVal,
|
isVal,
|
||||||
typeToDeclare != null,
|
typeToDeclare != null,
|
||||||
shouldGenerateDefaultInitializer(referenceSearcher, field),
|
shouldGenerateDefaultInitializer(referenceSearcher, field),
|
||||||
if (correction != null) correction.setterAccess else modifiers.accessModifier()).assignPrototype(field)
|
if (correction != null) correction.setterAccess else modifiers.accessModifier()
|
||||||
|
).assignPrototype(field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,7 +545,7 @@ class Converter private constructor(
|
|||||||
Nullability.Nullable -> type = type.toNullableType()
|
Nullability.Nullable -> type = type.toNullableType()
|
||||||
}
|
}
|
||||||
return Parameter(parameter.declarationIdentifier(), type, varValModifier,
|
return Parameter(parameter.declarationIdentifier(), type, varValModifier,
|
||||||
convertAnnotations(parameter), modifiers, defaultValue).assignPrototype(parameter, CommentsAndSpacesInheritance(spacesBefore = SpacesInheritance.LINE_BREAKS))
|
convertAnnotations(parameter), modifiers, defaultValue).assignPrototype(parameter, CommentsAndSpacesInheritance.LINE_BREAKS)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun convertIdentifier(identifier: PsiIdentifier?): Identifier {
|
public fun convertIdentifier(identifier: PsiIdentifier?): Identifier {
|
||||||
@@ -556,7 +556,7 @@ class Converter private constructor(
|
|||||||
|
|
||||||
public fun convertModifiers(owner: PsiModifierListOwner): Modifiers {
|
public fun convertModifiers(owner: PsiModifierListOwner): Modifiers {
|
||||||
return Modifiers(MODIFIERS_MAP.filter { owner.hasModifierProperty(it.first) }.map { it.second })
|
return Modifiers(MODIFIERS_MAP.filter { owner.hasModifierProperty(it.first) }.map { it.second })
|
||||||
.assignPrototype(owner.getModifierList(), CommentsAndSpacesInheritance(spacesBefore = SpacesInheritance.NONE))
|
.assignPrototype(owner.getModifierList(), CommentsAndSpacesInheritance.NO_SPACES)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun convertAnonymousClassBody(anonymousClass: PsiAnonymousClass): AnonymousClassBody {
|
public fun convertAnonymousClassBody(anonymousClass: PsiAnonymousClass): AnonymousClassBody {
|
||||||
|
|||||||
@@ -485,11 +485,10 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
|||||||
val parameters = resolved?.getParameterList()?.getParameters()
|
val parameters = resolved?.getParameterList()?.getParameters()
|
||||||
val expectedTypes = parameters?.map { it.getType() } ?: listOf()
|
val expectedTypes = parameters?.map { it.getType() } ?: listOf()
|
||||||
|
|
||||||
val commentsAndSpacesInheritance = CommentsAndSpacesInheritance(spacesBefore = SpacesInheritance.LINE_BREAKS)
|
val commentsAndSpacesInheritance = CommentsAndSpacesInheritance.LINE_BREAKS
|
||||||
|
|
||||||
return if (arguments.size() == expectedTypes.size()) {
|
return if (arguments.size() == expectedTypes.size()) {
|
||||||
arguments.indices.map { i ->
|
arguments.mapIndexed { i, argument ->
|
||||||
val argument = arguments[i]
|
|
||||||
val converted = codeConverter.convertExpression(argument, expectedTypes[i])
|
val converted = codeConverter.convertExpression(argument, expectedTypes[i])
|
||||||
val result = if (parameters != null && i == arguments.lastIndex && parameters[i].isVarArgs() && argument.getType() is PsiArrayType)
|
val result = if (parameters != null && i == arguments.lastIndex && parameters[i].isVarArgs() && argument.getType() is PsiArrayType)
|
||||||
StarExpression(converted)
|
StarExpression(converted)
|
||||||
|
|||||||
@@ -54,7 +54,12 @@ data class CommentsAndSpacesInheritance(
|
|||||||
val commentsBefore: Boolean = true,
|
val commentsBefore: Boolean = true,
|
||||||
val commentsAfter: Boolean = true,
|
val commentsAfter: Boolean = true,
|
||||||
val commentsInside: Boolean = true
|
val commentsInside: Boolean = true
|
||||||
)
|
) {
|
||||||
|
companion object {
|
||||||
|
val NO_SPACES = CommentsAndSpacesInheritance(spacesBefore = SpacesInheritance.NONE)
|
||||||
|
val LINE_BREAKS = CommentsAndSpacesInheritance(spacesBefore = SpacesInheritance.LINE_BREAKS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun Element.canonicalCode(): String {
|
fun Element.canonicalCode(): String {
|
||||||
val builder = CodeBuilder(null)
|
val builder = CodeBuilder(null)
|
||||||
|
|||||||
Reference in New Issue
Block a user