Skip to content
Browse files

Don't read classfile bytes if the classfile is not part of a Scala pr…

…oject. This may cause large delays when the class files are on a network mounted file system.

Fixed #1000742, Fixed #1000233, Fixed #1000643.
(cherry picked from commit e35df9d)
(cherry picked from commit 726dd67)
  • Loading branch information...
1 parent 530ee27 commit fb5cd1d83edd9c5d619ccf00c968ae45b2658efd @dragos dragos committed Nov 10, 2011
View
15 ...ts/src/scala/tools/eclipse/contribution/weaving/jdt/cfprovider/ClassFileProviderAspect.aj
@@ -146,17 +146,18 @@ public privileged aspect ClassFileProviderAspect {
byte[] bytes;
try {
- bytes = javaClassFile.getBytes();
+ for (IClassFileProvider provider : ClassFileProviderRegistry.getInstance().getProviders()) {
+ if (provider.isInteresting(javaClassFile)) {
+ bytes = javaClassFile.getBytes();
+ ClassFile cf = provider.create(bytes, parent, name);
+ if (cf != null)
+ return cf;
+ }
+ }
} catch(Throwable t) {
return javaClassFile;
}
- for (IClassFileProvider provider : ClassFileProviderRegistry.getInstance().getProviders()) {
- ClassFile cf = provider.create(bytes, parent, name);
- if (cf != null)
- return cf;
- }
-
return javaClassFile;
}
View
11 ...pects/src/scala/tools/eclipse/contribution/weaving/jdt/cfprovider/IClassFileProvider.java
@@ -5,10 +5,21 @@
package scala.tools.eclipse.contribution.weaving.jdt.cfprovider;
+import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.internal.core.ClassFile;
import org.eclipse.jdt.internal.core.PackageFragment;
@SuppressWarnings("restriction")
public interface IClassFileProvider {
public ClassFile create(byte[] contents, PackageFragment parent, String name);
+
+ /** Is this classfile interesting for this provider? Gives a fast-path when the
+ * provider is not interested in a classfile (for instance, when the file does not
+ * belongs to a project with the desired nature). Answering 'false' saves the
+ * costly operation of loading the bytes in memory (needed for the call to 'create').
+ *
+ * @param file the classfile under inspection
+ * @return false if the file is definitely not interesting for this class file provider.
+ */
+ public boolean isInteresting(IClassFile file);
}
View
17 org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaClassFileProvider.scala
@@ -3,17 +3,17 @@
*/
// $Id$
-package scala.tools.eclipse.javaelements
+package scala.tools.eclipse
+package javaelements
import java.io.ByteArrayInputStream
-
import org.eclipse.jdt.internal.core.{ ClassFile, PackageFragment }
-
import scala.tools.eclipse.contribution.weaving.jdt.cfprovider.IClassFileProvider
-
import scala.tools.eclipse.ScalaClassFileDescriber
+import org.eclipse.jdt.core.IClassFile
+import scala.tools.eclipse.util.HasLogger
-class ScalaClassFileProvider extends IClassFileProvider {
+class ScalaClassFileProvider extends IClassFileProvider with HasLogger {
override def create(contents : Array[Byte], parent : PackageFragment, name : String) : ClassFile =
ScalaClassFileDescriber.isScala(new ByteArrayInputStream(contents)) match {
case Some(sourceFile) =>
@@ -27,4 +27,11 @@ class ScalaClassFileProvider extends IClassFileProvider {
}
case _ => null
}
+
+ override def isInteresting(classFile: IClassFile): Boolean = {
+ val res = ScalaPlugin.plugin.isScalaProject(Option(classFile.getJavaProject()).map(_.getProject()).getOrElse(null))
+ if (!res)
+ logger.debug("Not interested in %s in project %s".format(classFile, classFile.getJavaProject()))
+ res
+ }
}

0 comments on commit fb5cd1d

Please sign in to comment.
Something went wrong with that request. Please try again.