Renamed LazyElement -> DeferredElement

This commit is contained in:
Valentin Kipyatkov
2014-10-29 16:35:38 +03:00
committed by valentin
parent 17622f8259
commit 567bb6fd1a
15 changed files with 44 additions and 44 deletions
@@ -68,8 +68,8 @@ class AnnotationConverter(private val converter: Converter) {
public fun convertAnnotation(annotation: PsiAnnotation, brackets: Boolean, newLineAfter: Boolean): Annotation? {
val qualifiedName = annotation.getQualifiedName()
if (qualifiedName == CommonClassNames.JAVA_LANG_DEPRECATED && annotation.getParameterList().getAttributes().isEmpty()) {
val lazyExpression = converter.lazyElement<Expression> { LiteralExpression("\"\"").assignNoPrototype() }
return Annotation(Identifier("deprecated").assignNoPrototype(), listOf(null to lazyExpression), brackets, newLineAfter).assignPrototype(annotation) //TODO: insert comment
val deferredExpression = converter.deferredElement<Expression> { LiteralExpression("\"\"").assignNoPrototype() }
return Annotation(Identifier("deprecated").assignNoPrototype(), listOf(null to deferredExpression), brackets, newLineAfter).assignPrototype(annotation) //TODO: insert comment
}
val nameRef = annotation.getNameReferenceElement()
@@ -86,14 +86,14 @@ class AnnotationConverter(private val converter: Converter) {
val isVarArg = method == lastMethod /* converted to vararg in Kotlin */
val attrValues = convertAttributeValue(value, expectedType, isVarArg, it.getName() == null)
attrValues.map { attrName to converter.lazyElement(it) }
attrValues.map { attrName to converter.deferredElement(it) }
}
return Annotation(name, arguments, brackets, newLineAfter).assignPrototype(annotation)
}
public fun convertAnnotationMethodDefault(method: PsiAnnotationMethod): LazyElement<Expression>? {
public fun convertAnnotationMethodDefault(method: PsiAnnotationMethod): DeferredElement<Expression>? {
val value = method.getDefaultValue() ?: return null
return converter.lazyElement(convertAttributeValue(value, method.getReturnType(), false, false).single())
return converter.deferredElement(convertAttributeValue(value, method.getReturnType(), false, false).single())
}
private fun convertAttributeValue(value: PsiAnnotationMemberValue?, expectedType: PsiType?, isVararg: Boolean, isUnnamed: Boolean): List<(CodeConverter) -> Expression> {
@@ -149,7 +149,7 @@ class ConstructorConverter(private val psiClass: PsiClass,
}
}
public var baseClassParams: List<LazyElement<Expression>> = listOf()
public var baseClassParams: List<DeferredElement<Expression>> = listOf()
private set
public fun convertConstructor(constructor: PsiMethod,
@@ -193,7 +193,7 @@ class ConstructorConverter(private val psiClass: PsiClass,
}
return FactoryFunction(constructor.declarationIdentifier(), annotations, correctFactoryFunctionAccess(modifiers),
factoryFunctionType, params, typeParameterList, converter.lazyElement(::convertBody))
factoryFunctionType, params, typeParameterList, converter.deferredElement(::convertBody))
}
}
@@ -267,7 +267,7 @@ class ConstructorConverter(private val psiClass: PsiClass,
val methodCall = (statement as? PsiExpressionStatement)?.getExpression() as? PsiMethodCallExpression
if (methodCall != null && methodCall.isSuperConstructorCall()) {
baseClassParams = methodCall.getArgumentList().getExpressions().map {
correctedConverter.lazyElement { codeConverter -> codeConverter.correct().convertExpression(it) }
correctedConverter.deferredElement { codeConverter -> codeConverter.correct().convertExpression(it) }
}
}
@@ -275,7 +275,7 @@ class ConstructorConverter(private val psiClass: PsiClass,
val parameter = params[i]
val indexFromEnd = params.size - i - 1
val defaultValue = if (indexFromEnd < lastParamDefaults.size)
correctedConverter.lazyElement { codeConverter -> codeConverter.correct().convertExpression(lastParamDefaults[indexFromEnd], parameter.getType()) }
correctedConverter.deferredElement { codeConverter -> codeConverter.correct().convertExpression(lastParamDefaults[indexFromEnd], parameter.getType()) }
else
null
if (!parameterToField.containsKey(parameter)) {
@@ -297,7 +297,7 @@ class ConstructorConverter(private val psiClass: PsiClass,
defaultValue).assignPrototypes(listOf(parameter, field), CommentsAndSpacesInheritance(blankLinesBefore = false))
}
}).assignPrototype(primaryConstructor.getParameterList())
return PrimaryConstructor(annotations, modifiers, parameterList, converter.lazyElement(bodyGenerator)).assignPrototype(primaryConstructor)
return PrimaryConstructor(annotations, modifiers, parameterList, converter.deferredElement(bodyGenerator)).assignPrototype(primaryConstructor)
}
private fun findBackingFieldForConstructorParameter(parameter: PsiParameter, constructor: PsiMethod): Pair<PsiField, PsiStatement>? {
+18 -18
View File
@@ -42,7 +42,7 @@ class Converter private(private val elementToConvert: PsiElement,
// state which is shared between all converter's based on this one
private class CommonState {
val importsToAdd = LinkedHashSet<String>()
val lazyElements = ArrayList<LazyElement<*>>()
val deferredElements = ArrayList<DeferredElement<*>>()
val usageProcessings = ArrayList<UsageProcessing>()
val postUnfoldActions = ArrayList<() -> Unit>()
}
@@ -83,7 +83,7 @@ class Converter private(private val elementToConvert: PsiElement,
val element = convertTopElement(elementToConvert) ?: return null
return object: IntermediateResult {
override fun finishConversion(usageProcessings: Collection<UsageProcessing>): String {
unfoldLazyElements(usageProcessings)
unfoldDeferredElements(usageProcessings)
val builder = CodeBuilder(elementToConvert)
builder.append(element)
@@ -108,22 +108,22 @@ class Converter private(private val elementToConvert: PsiElement,
else -> null
}
private fun unfoldLazyElements(usageProcessings: Collection<UsageProcessing>) {
private fun unfoldDeferredElements(usageProcessings: Collection<UsageProcessing>) {
val codeConverter = createDefaultCodeConverter().withSpecialExpressionConverter(UsageProcessingExpressionConverter(usageProcessings))
// we use loop with index because new lazy elements can be added during unfolding
// we use loop with index because new deferred elements can be added during unfolding
var i = 0
while (i < commonState.lazyElements.size) {
val lazyElement = commonState.lazyElements[i++]
lazyElement.unfold(codeConverter.withConverter(this.withState(lazyElement.converterState)))
while (i < commonState.deferredElements.size) {
val deferredElement = commonState.deferredElements[i++]
deferredElement.unfold(codeConverter.withConverter(this.withState(deferredElement.converterState)))
}
commonState.postUnfoldActions.forEach { it() }
}
public fun<TResult : Element> lazyElement(generator: (CodeConverter) -> TResult): LazyElement<TResult> {
val element = LazyElement(generator, personalState)
commonState.lazyElements.add(element)
public fun<TResult : Element> deferredElement(generator: (CodeConverter) -> TResult): DeferredElement<TResult> {
val element = DeferredElement(generator, personalState)
commonState.deferredElements.add(element)
return element
}
@@ -131,7 +131,7 @@ class Converter private(private val elementToConvert: PsiElement,
commonState.usageProcessings.add(processing)
}
public fun addPostUnfoldLazyElementsAction(action: () -> Unit) {
public fun addPostUnfoldDeferredElementsAction(action: () -> Unit) {
commonState.postUnfoldActions.add(action)
}
@@ -146,7 +146,7 @@ class Converter private(private val elementToConvert: PsiElement,
}
}.filterNotNull()
addPostUnfoldLazyElementsAction {
addPostUnfoldDeferredElementsAction {
assert(importList != null)
if (importsToAdd.isNotEmpty()) {
importList!!.imports = importList.imports + importsToAdd.map { Import(it).assignNoPrototype() }
@@ -254,7 +254,7 @@ class Converter private(private val elementToConvert: PsiElement,
}
public fun convertInitializer(initializer: PsiClassInitializer): Initializer {
return Initializer(lazyElement { codeConverter -> codeConverter.convertBlock(initializer.getBody()) },
return Initializer(deferredElement { codeConverter -> codeConverter.convertBlock(initializer.getBody()) },
convertModifiers(initializer)).assignPrototype(initializer)
}
@@ -273,7 +273,7 @@ class Converter private(private val elementToConvert: PsiElement,
annotations,
modifiers,
typeConverter.convertType(field.getType(), Nullability.NotNull),
lazyElement { codeConverter -> ExpressionList(codeConverter.convertExpressions(argumentList?.getExpressions() ?: array())).assignPrototype(argumentList) })
deferredElement { codeConverter -> ExpressionList(codeConverter.convertExpressions(argumentList?.getExpressions() ?: array())).assignPrototype(argumentList) })
}
else {
val isVal = isVal(referenceSearcher, field)
@@ -288,7 +288,7 @@ class Converter private(private val elementToConvert: PsiElement,
annotations,
modifiers,
propertyType,
lazyElement { codeConverter -> codeConverter.convertExpression(field.getInitializer(), field.getType()) },
deferredElement { codeConverter -> codeConverter.convertExpression(field.getInitializer(), field.getType()) },
isVal,
typeToDeclare != null,
shouldGenerateDefaultInitializer(referenceSearcher, field),
@@ -369,7 +369,7 @@ class Converter private(private val elementToConvert: PsiElement,
var params = convertParameterList(method.getParameterList())
val typeParameterList = convertTypeParameterList(method.getTypeParameterList())
var body = lazyElement { (codeConverter: CodeConverter) ->
var body = deferredElement { (codeConverter: CodeConverter) ->
val body = codeConverter.withMethodReturnType(method.getReturnType()).convertBlock(method.getBody())
postProcessBody(body)
}
@@ -480,7 +480,7 @@ class Converter private(private val elementToConvert: PsiElement,
nullability: Nullability = Nullability.Default,
varValModifier: Parameter.VarValModifier = Parameter.VarValModifier.None,
modifiers: Modifiers = Modifiers.Empty(),
defaultValue: LazyElement<Expression>? = null): Parameter {
defaultValue: DeferredElement<Expression>? = null): Parameter {
var type = typeConverter.convertVariableType(parameter)
when (nullability) {
Nullability.NotNull -> type = type.toNotNullType()
@@ -516,7 +516,7 @@ class Converter private(private val elementToConvert: PsiElement,
if (types.isEmpty()) return Annotations.Empty()
val arguments = types.indices.map { index ->
val convertedType = typeConverter.convertType(types[index], Nullability.NotNull)
null to lazyElement<Expression> { MethodCallExpression.buildNotNull(null, "javaClass", listOf(), listOf(convertedType)).assignPrototype(refElements[index]) }
null to deferredElement<Expression> { MethodCallExpression.buildNotNull(null, "javaClass", listOf(), listOf(convertedType)).assignPrototype(refElements[index]) }
}
val annotation = Annotation(Identifier("throws").assignNoPrototype(), arguments, false, true)
return Annotations(listOf(annotation.assignPrototype(throwsList))).assignPrototype(throwsList)
@@ -18,7 +18,7 @@ package org.jetbrains.jet.j2k.ast
import org.jetbrains.jet.j2k.*
class Annotation(val name: Identifier, val arguments: List<Pair<Identifier?, LazyElement<Expression>>>, val brackets: Boolean, val newLineAfter: Boolean) : Element() {
class Annotation(val name: Identifier, val arguments: List<Pair<Identifier?, DeferredElement<Expression>>>, val brackets: Boolean, val newLineAfter: Boolean) : Element() {
private fun CodeBuilder.surroundWithBrackets(action: () -> Unit) {
if (brackets) append("[")
action()
+1 -1
View File
@@ -24,7 +24,7 @@ open class Class(
modifiers: Modifiers,
val typeParameterList: TypeParameterList,
val extendsTypes: List<Type>,
val baseClassParams: List<LazyElement<Expression>>,
val baseClassParams: List<DeferredElement<Expression>>,
val implementsTypes: List<Type>,
val body: ClassBody
) : Member(annotations, modifiers) {
@@ -22,7 +22,7 @@ abstract class Member(val annotations: Annotations, val modifiers: Modifiers) :
class ClassBody (
val primaryConstructorSignature: PrimaryConstructorSignature?,
val baseClassParams: List<LazyElement<Expression>>,
val baseClassParams: List<DeferredElement<Expression>>,
val members: List<Member>,
val classObjectMembers: List<Member>,
val factoryFunctions: List<FactoryFunction>,
@@ -22,7 +22,7 @@ import com.intellij.util.IncorrectOperationException
class PrimaryConstructor(annotations: Annotations,
modifiers: Modifiers,
val parameterList: ParameterList,
val body: LazyElement<Block>)
val body: DeferredElement<Block>)
: Member(annotations, modifiers) {
override fun generateCode(builder: CodeBuilder) { throw IncorrectOperationException() }
@@ -34,7 +34,7 @@ class PrimaryConstructor(annotations: Annotations,
val signature = PrimaryConstructorSignature(annotations, modifiers, parameterList)
// assign prototypes later because we don't know yet whether the body is empty or not
converter.addPostUnfoldLazyElementsAction {
converter.addPostUnfoldDeferredElementsAction {
val inheritance = CommentsAndSpacesInheritance(blankLinesBefore = false, commentsAfter = body.isEmpty, commentsInside = body.isEmpty)
signature.assignPrototypesFrom(this, inheritance)
}
@@ -66,5 +66,5 @@ class FactoryFunction(name: Identifier,
returnType: Type,
parameterList: ParameterList,
typeParameterList: TypeParameterList,
body: LazyElement<Block>)
body: DeferredElement<Block>)
: Function(name, annotations, modifiers, returnType, typeParameterList, parameterList, body, false)
+3 -3
View File
@@ -88,8 +88,8 @@ object EmptyElementPrototypes {
public fun set(thisRef: Element, desc: PropertyMetadata, value: List<PrototypeInfo>?) { }
}
// this class should never be created directly - Converter.lazyElement() should be used!
class LazyElement<TResult : Element>(
// this class should never be created directly - Converter.deferredElement() should be used!
class DeferredElement<TResult : Element>(
private var generator: (CodeConverter) -> TResult,
public val converterState: Converter.PersonalState
) : Element() {
@@ -114,7 +114,7 @@ class LazyElement<TResult : Element>(
private val resultNotNull: TResult
get() {
assert(result != null) { "No code generated for lazy element $this. Possible reason is that it has been created directly instead of Converter.lazyElement() call." }
assert(result != null) { "No code generated for deferred element $this. Possible reason is that it has been created directly instead of Converter.lazyElement() call." }
return result!!
}
+1 -1
View File
@@ -24,7 +24,7 @@ class Enum(
modifiers: Modifiers,
typeParameterList: TypeParameterList,
extendsTypes: List<Type>,
baseClassParams: List<LazyElement<Expression>>,
baseClassParams: List<DeferredElement<Expression>>,
implementsTypes: List<Type>,
body: ClassBody
) : Class(name, annotations, modifiers, typeParameterList, extendsTypes, baseClassParams, implementsTypes, body) {
@@ -23,7 +23,7 @@ class EnumConstant(
annotations: Annotations,
modifiers: Modifiers,
val type: Type,
val params: LazyElement<ExpressionList>
val params: DeferredElement<ExpressionList>
) : Member(annotations, modifiers) {
override fun generateCode(builder: CodeBuilder) {
@@ -25,7 +25,7 @@ open class Function(
val returnType: Type,
val typeParameterList: TypeParameterList,
val parameterList: ParameterList,
val body: LazyElement<Block>?,
val body: DeferredElement<Block>?,
val isInTrait: Boolean
) : Member(annotations, modifiers) {
@@ -18,7 +18,7 @@ package org.jetbrains.jet.j2k.ast
import org.jetbrains.jet.j2k.*
class Initializer(val body: LazyElement<Block>, modifiers: Modifiers) : Member(Annotations.Empty(), modifiers) {
class Initializer(val body: DeferredElement<Block>, modifiers: Modifiers) : Member(Annotations.Empty(), modifiers) {
override fun generateCode(builder: CodeBuilder) {
builder.append(body)
}
@@ -23,7 +23,7 @@ class Parameter(val identifier: Identifier,
val varVal: Parameter.VarValModifier,
val annotations: Annotations,
val modifiers: Modifiers,
val defaultValue: LazyElement<Expression>? = null) : Element() {
val defaultValue: DeferredElement<Expression>? = null) : Element() {
public enum class VarValModifier {
None
Val
@@ -23,7 +23,7 @@ class Property(
annotations: Annotations,
modifiers: Modifiers,
val type: Type,
private val initializer: LazyElement<Expression>,
private val initializer: DeferredElement<Expression>,
val isVal: Boolean,
val explicitType: Boolean,
private val defaultInitializer: Boolean,
+1 -1
View File
@@ -23,7 +23,7 @@ class Trait(name: Identifier,
modifiers: Modifiers,
typeParameterList: TypeParameterList,
extendsTypes: List<Type>,
baseClassParams: List<LazyElement<Expression>>,
baseClassParams: List<DeferredElement<Expression>>,
implementsTypes: List<Type>,
body: ClassBody
) : Class(name, annotations, modifiers, typeParameterList, extendsTypes, baseClassParams, implementsTypes, body) {