mirror of https://github.com/sbt/sbt.git
Cut valid text corrected
This commit is contained in:
parent
232c28ecd1
commit
742188393b
|
|
@ -7,6 +7,7 @@ import scala.reflect.runtime.universe._
|
|||
|
||||
object SessionSettingsNoBlankies {
|
||||
|
||||
private val FAKE_FILE = new File("fake")
|
||||
val REVERSE_ORDERING_INT = Ordering[Int].reverse
|
||||
|
||||
def oldLinesToNew(content: List[String], lineMap: SortedMap[Int, List[(Int, List[String])]]): List[String] =
|
||||
|
|
@ -49,16 +50,25 @@ object SessionSettingsNoBlankies {
|
|||
content.take(from - 1) ++ newLines ++ content.drop(to - 1)
|
||||
}
|
||||
|
||||
private def cutExpression(l: List[String], name: String): List[String] = l match {
|
||||
private[sbt] def cutExpression(l: List[String], name: String): List[String] = l match {
|
||||
case h +: t =>
|
||||
val array = h.split(";").filter(_.contains(name))
|
||||
array.mkString(";") +: t
|
||||
val statements = SplitExpressionsNoBlankies(FAKE_FILE, l).settingsTrees
|
||||
val lastIndex = statements.lastIndexWhere {
|
||||
tuple => extractSettingName(tuple._2) == name
|
||||
}
|
||||
val (statement, tree) = statements(lastIndex)
|
||||
|
||||
if (tree.pos.end >= h.length) {
|
||||
l
|
||||
} else {
|
||||
statement +: t
|
||||
}
|
||||
case _ =>
|
||||
l
|
||||
}
|
||||
|
||||
private def toTreeStringMap(lines: List[String]) = {
|
||||
val split = SplitExpressionsNoBlankies(new File("fake"), lines)
|
||||
val split = SplitExpressionsNoBlankies(FAKE_FILE, lines)
|
||||
val trees = split.settingsTrees
|
||||
val seq = trees.map {
|
||||
case (statement, tree) =>
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ case class SplitExpressionsNoBlankies(file: File, lines: Seq[String]) {
|
|||
def parseStatementAgain(t: Tree, originalStatement: String): String = {
|
||||
val statement = util.Try(toolbox.parse(originalStatement)) match {
|
||||
case util.Failure(th) =>
|
||||
val missingText = tryWithNextStatement(modifiedContent, t.pos.end, t.pos.line, fileName, th)
|
||||
val missingText = findMissingText(modifiedContent, t.pos.end, t.pos.line, fileName, th)
|
||||
originalStatement + missingText
|
||||
case _ =>
|
||||
originalStatement
|
||||
|
|
@ -105,8 +105,9 @@ private[sbt] object BugInParser {
|
|||
* @param th - original exception
|
||||
* @return
|
||||
*/
|
||||
private[sbt] def tryWithNextStatement(content: String, positionEnd: Int, positionLine: Int, fileName: String, th: Throwable): String = {
|
||||
findFirstNotBlankNotCommentedIndex(content, positionEnd) match {
|
||||
private[sbt] def findMissingText(content: String, positionEnd: Int, positionLine: Int, fileName: String, th: Throwable): String = {
|
||||
// val scanner = new syntaxAnalyzer.UnitScanner(new CompilationUnit(source))
|
||||
findClosingBracketIndex(content, positionEnd) match {
|
||||
case Some(index) =>
|
||||
content.substring(positionEnd, index + 1)
|
||||
case _ =>
|
||||
|
|
@ -120,8 +121,8 @@ private[sbt] object BugInParser {
|
|||
* @param from - start index
|
||||
* @return first not commented index or None
|
||||
*/
|
||||
private def findFirstNotBlankNotCommentedIndex(content: String, from: Int): Option[Int] = {
|
||||
val index = content.indexWhere(c => !c.isWhitespace, from)
|
||||
private[sbt] def findClosingBracketIndex(content: String, from: Int): Option[Int] = {
|
||||
val index = content.indexWhere(c => c == '}' || c == ')', from)
|
||||
if (index == -1) {
|
||||
None
|
||||
} else {
|
||||
|
|
@ -130,11 +131,11 @@ private[sbt] object BugInParser {
|
|||
val nextChar = content.charAt(index + 1)
|
||||
if (nextChar == '/') {
|
||||
val endOfLine = content.indexOf('\n', index)
|
||||
findFirstNotBlankNotCommentedIndex(content, endOfLine)
|
||||
findClosingBracketIndex(content, endOfLine)
|
||||
} else {
|
||||
//if (nextChar == '*')
|
||||
val endOfCommented = content.indexOf("*/", index + 1)
|
||||
findFirstNotBlankNotCommentedIndex(content, endOfCommented + 2)
|
||||
findClosingBracketIndex(content, endOfCommented + 2)
|
||||
}
|
||||
} else {
|
||||
Some(index)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class ErrorSpec extends AbstractSpec with ScalaCheck {
|
|||
| } /* */ //
|
||||
|}
|
||||
""".stripMargin
|
||||
BugInParser.tryWithNextStatement(buildSbt, buildSbt.length, 2, "fake.txt", new MessageOnlyException("fake")) must throwA[MessageOnlyException]
|
||||
BugInParser.findMissingText(buildSbt, buildSbt.length, 2, "fake.txt", new MessageOnlyException("fake")) must throwA[MessageOnlyException]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue