This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T> Iterable<Iterable<T>>.flatten() = object: Iterable<T> { | |
val collection = this@flatten.Ifilter { it.isEmpty() }.iterator() | |
var element = collection.nextOrNull()?.iterator() | |
override fun iterator() = iterate { | |
if (element.hasNext()) | |
return@iterate element!!.next() | |
else if (collection.hasNext()) { | |
element = collection.next().iterator() | |
return@iterate element!!.next() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getS(){ | |
double z; | |
int x = 5; | |
System.out.print("Hello!" + 2); | |
x = x*22 - 4; | |
double y = Math.acos(x * Math.random()); | |
System.out.println("X=" + x); | |
System.out.print("Hello!" + 2); | |
x = x*22 - 4; | |
System.out.println("X=" + x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var leftPsi: PsiElement? = clone.firstPsi | |
val result = generateSequence (clone.firstPsi) { it.findNextSibling(end) } | |
.filter { ! it.haveSibling(end) } | |
.map { | |
val result = leftPsi!! to it | |
leftPsi = it.findNextSibling(end) | |
result | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2002-2017 the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2002-2017 the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.suhininalex.clones.index | |
import com.intellij.psi.PsiElement | |
import com.suhininalex.clones.core.utils.isNoiseElement | |
import com.suhininalex.clones.core.utils.nextLeafElement | |
import com.suhininalex.clones.core.utils.prevLeafElement | |
fun PsiElement.nextElements(): Sequence<PsiElement> = | |
generateSequence (this) { it.nextLeafElement() } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
infix fun Int.clip(range: IntRange): Int { | |
return when { | |
this < range.start -> range.start | |
this > range.endInclusive -> range.endInclusive | |
else -> this | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun FileTextRange.intersects(other: FileTextRange, gap: Int = 0): Boolean { | |
return when { | |
file != other.file -> false | |
range intersects other.range -> false | |
else -> extendLines(1).range intersects other.range | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun findTextRanges(project: Project, hash: HashValue): List<FileTextRange> { | |
return FileBasedIndex.getInstance() | |
.getValuesWithFiles(NAME, hash, GlobalSearchScope.projectScope(project)) | |
.flatMap { (file, ranges) -> ranges.map { FileTextRange(file, it) } } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun process(content: FileContent): Map<HashValue, TextRanges> { | |
Logger.log("[Indexing] ${content.psiFile.name}") | |
return content.psiFile | |
.findIndexableElements() | |
.flatMap { it.createHashFragments(content.file) } | |
.groupBy { it.hash } | |
.mapValues { (_, values) -> values.map { it.range } } | |
} |
OlderNewer