Skip to content

Commit

Permalink
Fixed #1000613. Modified code to handle this special case.
Browse files Browse the repository at this point in the history
To be able to handle files which are not part of the workspace (like a
previous version from source control), Eclipse uses a non-existing
project. This one has to be handle correctly.
  • Loading branch information
Luc Bourlier committed Oct 12, 2011
1 parent 93537d2 commit b59088e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Expand Up @@ -142,8 +142,6 @@ class ScalaProject(val underlying: IProject) extends HasLogger {
def externalDepends = underlying.getReferencedProjects

lazy val javaProject = {
if (!underlying.exists())
underlying.create(null)
JavaCore.create(underlying)
}

Expand Down Expand Up @@ -364,10 +362,15 @@ class ScalaProject(val underlying: IProject) extends HasLogger {
}

def initialize(settings: Settings, filter: Settings#Setting => Boolean) = {
val env = new NameEnvironment(javaProject)

for ((src, dst) <- sourceOutputFolders(env))
settings.outputDirs.add(EclipseResource(src), EclipseResource(dst))

// if the workspace project doesn't exist, it is a virtual project used by Eclipse.
// As such the source folders don't exist.
if (underlying.exists()) {
val env = new NameEnvironment(javaProject)

for ((src, dst) <- sourceOutputFolders(env))
settings.outputDirs.add(EclipseResource(src), EclipseResource(dst))
}

// TODO Per-file encodings
val sfs = sourceFolders
Expand Down
Expand Up @@ -34,6 +34,7 @@ import org.eclipse.jdt.core.IParent
import org.eclipse.jdt.internal.core.JavaElement
import org.eclipse.jdt.internal.core.SourceRefElement
import scala.tools.eclipse.util.HasLogger
import org.eclipse.jdt.core.compiler.CharOperation

trait ScalaCompilationUnit extends Openable with env.ICompilationUnit with ScalaElement with IScalaCompilationUnit with IBufferChangedListener with HasLogger {
val project = ScalaPlugin.plugin.getScalaProject(getJavaProject.getProject)
Expand All @@ -58,7 +59,9 @@ trait ScalaCompilationUnit extends Openable with env.ICompilationUnit with Scala
}

def createSourceFile : BatchSourceFile = {
new BatchSourceFile(file, getContents)
// call getContent() only when the underlying resource exists, otherwise
// it logs an exception
new BatchSourceFile(file, if (getResource.exists) getContents else CharOperation.NO_CHAR)
}

def getProblemRequestor : IProblemRequestor = null
Expand Down

0 comments on commit b59088e

Please sign in to comment.