Migrate kotlin sources, maven projects and stdlib to new lambda syntax

This commit is contained in:
Stanislav Erokhin
2015-04-01 16:36:44 +03:00
parent e0988de707
commit b703f59e04
74 changed files with 136 additions and 140 deletions
@@ -156,7 +156,7 @@ private class PerFileAnalysisCache(val file: JetFile, val resolveSession: Resolv
val analyzableParent = KotlinResolveDataProvider.findAnalyzableParent(element)
return synchronized(this) { (): AnalysisResult ->
return synchronized<AnalysisResult>(this) {
val cached = lookUp(analyzableParent)
if (cached != null) return@synchronized cached
@@ -53,12 +53,12 @@ fun createModuleResolverProvider(
val modulesToCreateResolversFor = allModuleInfos.filter(moduleFilter)
fun createResolverForProject(): ResolverForProject<IdeaModuleInfo, ResolverForModule> {
val modulesContent = {(module: IdeaModuleInfo) ->
val modulesContent = { module: IdeaModuleInfo ->
ModuleContent(syntheticFilesByModule[module] ?: listOf(), module.contentScope())
}
val jvmPlatformParameters = JvmPlatformParameters {
(javaClass: JavaClass) ->
javaClass: JavaClass ->
val psiClass = (javaClass as JavaClassImpl).getPsi()
psiClass.getModuleInfo()
}
@@ -40,7 +40,7 @@ class ModuleTypeCacheManager private (project: Project) {
private val cachedValue = CachedValuesManager.getManager(project).createParameterizedCachedValue(
{
(module: Module?) ->
module: Module? ->
val moduleType = if (module != null) computeType(module) else null
CachedValueProvider.Result.create<ModuleType>(moduleType, vfsModificationTracker)
}, false)
@@ -49,7 +49,7 @@ public fun HierarchySearchRequest<PsiElement>.searchOverriders(): Query<PsiMetho
return psiMethods
.map { psiMethod -> KotlinPsiMethodOverridersSearch.search(copy(psiMethod)) }
.reduce {(query1, query2) -> MergeQuery(query1, query2)}
.reduce { query1, query2 -> MergeQuery(query1, query2)}
}
public object KotlinPsiMethodOverridersSearch : HierarchySearch<PsiMethod>(PsiMethodOverridingHierarchyTraverser) {
@@ -167,7 +167,7 @@ private fun processClassDelegationCallsToSpecifiedConstructor(
// Check if reference resolves to extension function whose receiver is the same as declaration's parent (or its superclass)
// Used in extension search
fun PsiReference.isExtensionOfDeclarationClassUsage(declaration: JetNamedDeclaration): Boolean =
checkUsageVsOriginalDescriptor(declaration) { (usageDescriptor, targetDescriptor) ->
checkUsageVsOriginalDescriptor(declaration) { usageDescriptor, targetDescriptor ->
when {
usageDescriptor == targetDescriptor -> false
usageDescriptor !is FunctionDescriptor -> false
@@ -187,17 +187,17 @@ fun PsiReference.isExtensionOfDeclarationClassUsage(declaration: JetNamedDeclara
// Check if reference resolves to the declaration with the same parent
// Used in overload search
fun PsiReference.isUsageInContainingDeclaration(declaration: JetNamedDeclaration): Boolean =
checkUsageVsOriginalDescriptor(declaration) { (usageDescriptor, targetDescriptor) ->
checkUsageVsOriginalDescriptor(declaration) { usageDescriptor, targetDescriptor ->
usageDescriptor != targetDescriptor
&& usageDescriptor.getContainingDeclaration() == targetDescriptor.getContainingDeclaration()
}
fun PsiReference.isCallableOverrideUsage(declaration: JetNamedDeclaration): Boolean {
val decl2Desc = {(declaration: JetDeclaration) ->
val decl2Desc = { declaration: JetDeclaration ->
if (declaration is JetParameter && declaration.hasValOrVarNode()) declaration.propertyDescriptor else declaration.descriptor
}
return checkUsageVsOriginalDescriptor(declaration, decl2Desc) { (usageDescriptor, targetDescriptor) ->
return checkUsageVsOriginalDescriptor(declaration, decl2Desc) { usageDescriptor, targetDescriptor ->
usageDescriptor is CallableDescriptor && targetDescriptor is CallableDescriptor
&& OverrideResolver.overrides(usageDescriptor, targetDescriptor)
}
@@ -56,7 +56,7 @@ public object ProjectRootsUtil {
includeLibrarySource: Boolean,
includeLibraryClasses: Boolean
): Boolean {
return runReadAction {(): Boolean ->
return runReadAction {
val virtualFile = when (element) {
is PsiDirectory -> element.getVirtualFile()
else -> element.getContainingFile()?.getVirtualFile()
@@ -100,7 +100,7 @@ fun rethrowWithCancelIndicator(exception: ProcessCanceledException): ProcessCanc
return exception
}
fun PrefixMatcher.asNameFilter() = { (name: Name) ->
fun PrefixMatcher.asNameFilter() = { name: Name ->
if (name.isSpecial()) {
false
}
@@ -48,7 +48,7 @@ object KeywordValues {
}
if (!skipTrueFalse) {
val booleanInfoClassifier = { (info: ExpectedInfo) ->
val booleanInfoClassifier = { info: ExpectedInfo ->
if (info.type == KotlinBuiltIns.getInstance().getBooleanType()) ExpectedInfoClassification.matches(TypeSubstitutor.EMPTY) else ExpectedInfoClassification.notMatches
}
collection.addLookupElements(null, expectedInfos, booleanInfoClassifier, { LookupElementBuilder.create("true").bold().assignSmartCompletionPriority(SmartCompletionItemPriority.TRUE) })
@@ -45,7 +45,7 @@ object LambdaItems {
for (functionType in distinctTypes) {
val lookupString = buildLambdaPresentation(functionType)
val lookupElement = LookupElementBuilder.create(lookupString)
.withInsertHandler({ (context, lookupElement) ->
.withInsertHandler({ context, lookupElement ->
val offset = context.getStartOffset()
val placeholder = "{}"
context.getDocument().replaceString(offset, context.getTailOffset(), placeholder)
@@ -76,7 +76,7 @@ class MultipleArgumentsItemProvider(val bindingContext: BindingContext,
return LookupElementBuilder
.create(variables.map { IdeDescriptorRenderers.SOURCE_CODE.renderName(it.getName()) }.joinToString(", "))
.withInsertHandler { (context, lookupElement) ->
.withInsertHandler { context, lookupElement ->
if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
val offset = context.getOffsetMap().getOffset(SmartCompletion.MULTIPLE_ARGUMENTS_REPLACEMENT_OFFSET)
if (offset != -1) {
@@ -146,7 +146,7 @@ class SmartCompletion(
val result = ArrayList<LookupElement>()
val types = descriptor.fuzzyTypes(smartCastTypes)
val infoClassifier = { (expectedInfo: ExpectedInfo) -> types.classifyExpectedInfo(expectedInfo) }
val infoClassifier = { expectedInfo: ExpectedInfo -> types.classifyExpectedInfo(expectedInfo) }
result.addLookupElements(descriptor, expectedInfos, infoClassifier) { descriptor ->
lookupElementFactory.createLookupElement(descriptor, resolutionFacade, bindingContext, true)
@@ -199,7 +199,7 @@ class SmartCompletion(
if (shouldCompleteThisItems(prefixMatcher)) {
val items = thisExpressionItems(bindingContext, place, prefixMatcher.getPrefix())
for ((factory, type) in items) {
val classifier = { (expectedInfo: ExpectedInfo) -> type.classifyExpectedInfo(expectedInfo) }
val classifier = { expectedInfo: ExpectedInfo -> type.classifyExpectedInfo(expectedInfo) }
addLookupElements(null, expectedInfos, classifier) {
factory().assignSmartCompletionPriority(SmartCompletionItemPriority.THIS)
}
@@ -158,7 +158,7 @@ class TypeInstantiationItems(
itemText = "object: " + itemText + "{...}"
lookupString = "object"
allLookupStrings = setOf(lookupString, lookupElement.getLookupString())
insertHandler = InsertHandler<LookupElement> {(context, item) ->
insertHandler = InsertHandler<LookupElement> { context, item ->
val editor = context.getEditor()
val startOffset = context.getStartOffset()
val text = "object: $typeText$constructorParenthesis {}"
@@ -499,7 +499,7 @@ public fun createJavaMethod(template: PsiMethod, targetClass: PsiClass): PsiMeth
copyModifierListItems(template.getModifierList(), method.getModifierList())
copyTypeParameters(template, method) { (method, typeParameterList) ->
copyTypeParameters(template, method) { method, typeParameterList ->
method.addAfter(typeParameterList, method.getModifierList())
}
@@ -566,7 +566,7 @@ fun createJavaClass(klass: JetClass, targetClass: PsiClass): PsiMember {
javaClass.getModifierList().setModifierProperty(PsiModifier.ABSTRACT, false)
}
copyTypeParameters(template, javaClass) { (klass, typeParameterList) ->
copyTypeParameters(template, javaClass) { klass, typeParameterList ->
klass.addAfter(typeParameterList, klass.getNameIdentifier())
}
@@ -70,10 +70,10 @@ public class CheckPartialBodyResolveAction : AnAction() {
progressIndicator?.setText("Checking resolve $i of ${files.size()}...")
progressIndicator?.setText2(file.getVirtualFile().getPath())
val partialResolveDump = dumpResolve(file) {(element, resolutionFacade) ->
val partialResolveDump = dumpResolve(file) { element, resolutionFacade ->
resolutionFacade.analyze(element, BodyResolveMode.PARTIAL)
}
val goldDump = dumpResolve(file) {(element, resolutionFacade) ->
val goldDump = dumpResolve(file) { element, resolutionFacade ->
resolutionFacade.analyze(element)
}
if (partialResolveDump != goldDump) {
@@ -214,7 +214,7 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Mult
var value: CachedValue<JetTypeMapper>? = myTypeMappers.get(key)
if (value == null) {
value = CachedValuesManager.getManager(file.getProject()).createCachedValue<JetTypeMapper>(
{() ->
{
val typeMapper = createTypeMapper(file)
CachedValueProvider.Result<JetTypeMapper>(typeMapper, PsiModificationTracker.MODIFICATION_COUNT)
}, false)
@@ -268,7 +268,7 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Mult
TestOnly
public fun addTypeMapper(file: JetFile, typeMapper: JetTypeMapper) {
val value = CachedValuesManager.getManager(file.getProject()).createCachedValue<JetTypeMapper>(
{ () -> CachedValueProvider.Result<JetTypeMapper>(typeMapper, PsiModificationTracker.MODIFICATION_COUNT) }, false)
{ CachedValueProvider.Result<JetTypeMapper>(typeMapper, PsiModificationTracker.MODIFICATION_COUNT) }, false)
val key = createKeyForTypeMapper(file)
myTypeMappers.put(key, value)
}
@@ -47,7 +47,7 @@ class KotlinCodeFragmentFactory: CodeFragmentFactory() {
}
codeFragment.putCopyableUserData(JetCodeFragment.RUNTIME_TYPE_EVALUATOR, {
(expression: JetExpression): JetType? ->
expression: JetExpression ->
val debuggerContext = DebuggerManagerEx.getInstanceEx(project).getContext()
val debuggerSession = debuggerContext.getDebuggerSession()
@@ -53,8 +53,7 @@ class KotlinEvaluateExpressionCache(val project: Project) {
): CompiledDataDescriptor {
val evaluateExpressionCache = getInstance(codeFragment.getProject())
return synchronized(evaluateExpressionCache.cachedCompiledData) {
(): CompiledDataDescriptor ->
return synchronized<CompiledDataDescriptor>(evaluateExpressionCache.cachedCompiledData) {
val cache = evaluateExpressionCache.cachedCompiledData.getValue()!!
val text = "${codeFragment.importsToString()}\n${codeFragment.getText()}"
@@ -73,7 +72,7 @@ class KotlinEvaluateExpressionCache(val project: Project) {
}
private fun canBeEvaluatedInThisContext(compiledData: CompiledDataDescriptor, context: EvaluationContextImpl): Boolean {
return compiledData.parameters.all { (p): Boolean ->
return compiledData.parameters.all { p ->
val (name, jetType) = p
val value = context.findLocalVariable(name, asmType = null, checkType = false, failIfNotFound = false)
if (value == null) return@all false
@@ -69,7 +69,6 @@ private fun defineClasses(
private object FunctionImplBytes {
val bytes: ByteArray by Delegates.lazy {
(): ByteArray ->
val inputStream = this.javaClass.getClassLoader().getResourceAsStream("kotlin/jvm/internal/FunctionImpl.class")
if (inputStream != null) {
try {
@@ -81,7 +81,7 @@ class KotlinSpacingBuilder(val codeStyleSettings: CodeStyleSettings) {
}
fun emptyLinesIfLineBreakInLeft(emptyLines: Int, numberOfLineFeedsOtherwise: Int = 1, numSpacesOtherwise: Int = 0) {
newRule {(parent: ASTBlock, left: ASTBlock, right: ASTBlock) ->
newRule { parent: ASTBlock, left: ASTBlock, right: ASTBlock ->
val dependentSpacingRule = DependentSpacingRule(Trigger.HAS_LINE_FEEDS).registerData(Anchor.MIN_LINE_FEEDS, emptyLines + 1)
LineFeedDependantSpacing(
numSpacesOtherwise, numSpacesOtherwise,
@@ -93,7 +93,7 @@ class KotlinSpacingBuilder(val codeStyleSettings: CodeStyleSettings) {
}
fun spacing(spacing: Spacing) {
newRule { (parent, left, right) -> spacing }
newRule { parent, left, right -> spacing }
}
fun customRule(block: (parent: ASTBlock, left: ASTBlock, right: ASTBlock) -> Spacing?) {
@@ -63,7 +63,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
emptyLines = 0, numSpacesOtherwise = 1, numberOfLineFeedsOtherwise = 0)
val parameterWithDocCommentRule = {
(parent: ASTBlock, left: ASTBlock, right: ASTBlock) ->
parent: ASTBlock, left: ASTBlock, right: ASTBlock ->
if (right.getNode().getFirstChildNode().getElementType() == JetTokens.DOC_COMMENT) {
Spacing.createSpacing(0, 0, 1, true, settings.KEEP_BLANK_LINES_IN_DECLARATIONS)
}
@@ -248,12 +248,12 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
}
fun leftBraceRule(blockType: IElementType = BLOCK) = {
(parent: ASTBlock, left: ASTBlock, right: ASTBlock) ->
parent: ASTBlock, left: ASTBlock, right: ASTBlock ->
spacingForLeftBrace(right.getNode(), blockType)
}
val leftBraceRuleIfBlockIsWrapped = {
(parent: ASTBlock, left: ASTBlock, right: ASTBlock) ->
parent: ASTBlock, left: ASTBlock, right: ASTBlock ->
spacingForLeftBrace(right.getNode()!!.getFirstChildNode())
}
@@ -41,6 +41,6 @@ class KotlinOverrideTreeStructure(project: Project, val element: PsiElement) : H
return javaTreeStructures
.stream()
.map (::buildChildrenByTreeStructure)
.reduce { (a, b) -> ContainerUtil.union(a.toSet(), b.toSet()).copyToArray() }
.reduce { a, b -> ContainerUtil.union(a.toSet(), b.toSet()).copyToArray() }
}
}
@@ -47,7 +47,7 @@ fun getOverriddenPropertyTooltip(property: JetProperty): String? {
val consumer = AdapterProcessor<PsiMethod, PsiClass>(
CommonProcessors.UniqueProcessor<PsiClass>(PsiElementProcessorAdapter(overriddenInClassesProcessor)),
Function { (method: PsiMethod?): PsiClass? -> method?.getContainingClass() }
Function { method: PsiMethod? -> method?.getContainingClass() }
)
for (method in LightClassUtil.getLightClassPropertyMethods(property)) {
@@ -117,7 +117,7 @@ object KDocRenderer {
public fun MarkdownNode.toHtml(): String {
val sb = StringBuilder()
visit {(node, processChildren) ->
visit { node, processChildren ->
val nodeType = node.type
val nodeText = node.text
when (nodeType) {
@@ -76,14 +76,14 @@ public class ExtractKotlinFunctionHandler(
EXTRACT_FUNCTION,
editor,
file,
{(elements, parent) -> parent.getExtractionContainers(elements.size() == 1, allContainersEnabled) },
{ elements, parent -> parent.getExtractionContainers(elements.size() == 1, allContainersEnabled) },
continuation
)
}
override fun invoke(project: Project, editor: Editor, file: PsiFile, dataContext: DataContext?) {
if (file !is JetFile) return
selectElements(editor, file) { (elements, targetSibling) -> doInvoke(editor, file, elements, targetSibling) }
selectElements(editor, file) { elements, targetSibling -> doInvoke(editor, file, elements, targetSibling) }
}
override fun invoke(project: Project, elements: Array<out PsiElement>, dataContext: DataContext?) {
@@ -435,7 +435,7 @@ fun TypeParameter.collectReferencedTypes(bindingContext: BindingContext): List<J
}
private fun JetType.isExtractable(targetScope: JetScope?): Boolean {
return collectReferencedTypes(true).fold(true) { (extractable, typeToCheck) ->
return collectReferencedTypes(true).fold(true) { extractable, typeToCheck ->
val parameterTypeDescriptor = typeToCheck.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor
val typeParameter = parameterTypeDescriptor?.let {
DescriptorToSourceUtils.descriptorToDeclaration(it)
@@ -452,7 +452,7 @@ private fun JetType.processTypeIfExtractable(
targetScope: JetScope?,
processTypeArguments: Boolean = true
): Boolean {
return collectReferencedTypes(processTypeArguments).fold(true) { (extractable, typeToCheck) ->
return collectReferencedTypes(processTypeArguments).fold(true) { extractable, typeToCheck ->
val parameterTypeDescriptor = typeToCheck.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor
val typeParameter = parameterTypeDescriptor?.let {
DescriptorToSourceUtils.descriptorToDeclaration(it)
@@ -58,10 +58,10 @@ public class KotlinIntroducePropertyHandler(
operationName = INTRODUCE_PROPERTY,
editor = editor,
file = file,
getContainers = {(elements, parent) ->
getContainers = { elements, parent ->
parent.getExtractionContainers(strict = true, includeAll = true).filter { it is JetClassBody || it is JetFile }
}
) { (elements, targetSibling) ->
) { elements, targetSibling ->
val adjustedElements = (elements.singleOrNull() as? JetBlockExpression)?.getStatements() ?: elements
if (adjustedElements.isNotEmpty()) {
val options = ExtractionOptions(extractAsProperty = true)
@@ -105,7 +105,7 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() {
val oldGetterName = PropertyCodegen.getterName(element.getNameAsName())
val oldSetterName = PropertyCodegen.setterName(element.getNameAsName())
val refKindUsages = usages.toList().groupBy { (usage: UsageInfo): UsageKind ->
val refKindUsages = usages.toList().groupBy { usage: UsageInfo ->
val refElement = usage.getReference()?.resolve()
if (refElement is PsiMethod) {
when (refElement.getName()) {
@@ -112,7 +112,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
elements
.map { element -> findUsagesByJavaProcessor(element, true)?.getInsideDeletedCondition() }
.filterNotNull()
.fold(insideDeleted) {(condition1, condition2) -> Conditions.or(condition1, condition2) }
.fold(insideDeleted) { condition1, condition2 -> Conditions.or(condition1, condition2) }
fun findUsagesByJavaProcessor(jetDeclaration: JetDeclaration): NonCodeUsageSearchInfo {
return NonCodeUsageSearchInfo(
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange.Match
private val SIGNIFICANT_FILTER = { (e: PsiElement) -> e !is PsiWhiteSpace && e !is PsiComment && e.getTextLength() > 0 }
private val SIGNIFICANT_FILTER = { e: PsiElement -> e !is PsiWhiteSpace && e !is PsiComment && e.getTextLength() > 0 }
public trait JetPsiRange {
public object Empty : JetPsiRange {
@@ -225,12 +225,12 @@ public class JetPsiUnifier(
if (args1.size != args2.size) return UNMATCHED
if (rc1.getCall().getValueArguments().size != args1.size || rc2.getCall().getValueArguments().size != args2.size) return null
return (args1.stream() zip args2.stream()).fold(MATCHED) { (s, p) ->
return (args1.stream() zip args2.stream()).fold(MATCHED) { s, p ->
val (arg1, arg2) = p
s and when {
arg1 == arg2 -> MATCHED
arg1 == null || arg2 == null -> UNMATCHED
else -> (arg1.getArguments().stream() zip arg2.getArguments().stream()).fold(MATCHED) { (s, p) ->
else -> (arg1.getArguments().stream() zip arg2.getArguments().stream()).fold(MATCHED) { s, p ->
s and matchArguments(p.first, p.second)
}
}
@@ -737,7 +737,7 @@ public class JetPsiUnifier(
val patternElements = pattern.elements
if (targetElements.size != patternElements.size) return UNMATCHED
return (targetElements.stream() zip patternElements.stream()).fold(MATCHED) {(s, p) ->
return (targetElements.stream() zip patternElements.stream()).fold(MATCHED) { s, p ->
if (s != UNMATCHED) s and doUnify(p.first, p.second) else s
}
}
@@ -54,7 +54,7 @@ public abstract class AbstractKotlinCoverageOutputFilesTest(): JetLightCodeInsig
private fun createEmptyFile(dir: VirtualFile, relativePath: String) {
var currentDir = dir
val segments = relativePath.split('/')
segments.forEachIndexed {(i, s) ->
segments.forEachIndexed { i, s ->
if (i < segments.size() - 1) {
currentDir = currentDir.createChildDirectory(null, s)
} else {
@@ -110,7 +110,7 @@ abstract class KotlinDebuggerTestBase : KotlinDebuggerTestCase() {
}
protected fun SuspendContextImpl.printContext() {
runReadAction {(): Unit ->
runReadAction {
if (this.getFrameProxy() == null) {
return@runReadAction println("Context thread is null", ProcessOutputTypes.SYSTEM)
}