Skip to content

Commit

Permalink
Merge pull request #118 from skyluc/issue/unreleased_file_handle_1000909
Browse files Browse the repository at this point in the history
Clean file handle on refreshing changed files
  • Loading branch information
Luc Bourlier committed Jun 15, 2012
2 parents 0ae24d2 + bfb6d58 commit 9205509
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions org.scala-ide.sdt.core/src/scala/tools/eclipse/ScalaProject.scala
Expand Up @@ -41,6 +41,7 @@ import java.io.InputStream
import java.io.InputStreamReader
import scala.tools.eclipse.util.Trim
import org.eclipse.jdt.launching.JavaRuntime
import org.eclipse.jdt.internal.core.util.Util

trait BuildSuccessListener {
def buildSuccessful(): Unit
Expand Down Expand Up @@ -669,24 +670,7 @@ class ScalaProject private (val underlying: IProject) extends ClasspathManagemen
def shutDownPresentationCompiler() {
presentationCompiler.invalidate()
}

/**
* Return the full content of the given file in a Char array.
*
* Need to replace this with an utility method. I cannot believe it doesn't
* exist somewhere else.
*/
private def readFully(file: IFile): Array[Char] = {
val reader= new InputStreamReader(file.getContents, file.getCharset())
val buf= new ListBuffer[Char]
var c= reader.read
while (c >= 0) {
buf+= c.asInstanceOf[Char]
c= reader.read
}
buf.toArray
}


/**
* Tell the presentation compiler to refresh the given files,
* if they are not managed by the presentation compiler already.
Expand All @@ -697,7 +681,9 @@ class ScalaProject private (val underlying: IProject) extends ClasspathManagemen
// When a compilation unit is moved (e.g. using the Move refactoring) between packages,
// an ElementChangedEvent is fired but with the old IFile name. Ignoring the file does
// not seem to cause any bad effects later on, so we simply ignore these files -- Mirko
case file if file.exists => new BatchSourceFile(EclipseResource(file), readFully(file))
// using an Util class from jdt.internal to read the file, Eclipse doesn't seem to
// provide an API way to do it -- Luc
case file if file.exists => new BatchSourceFile(EclipseResource(file), Util.getResourceContentsAsCharArray(file))
}

withPresentationCompiler {compiler =>
Expand Down

0 comments on commit 9205509

Please sign in to comment.