From bc2a46a3dac664e5e4089dca81aa1bf68a2a7931 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 13 Dec 2012 18:31:04 +0400 Subject: [PATCH] A workaround for exception caused by a jar with the same content occurring twice on the classpath --- .../lang/resolve/java/PsiClassFinderImpl.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiClassFinderImpl.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiClassFinderImpl.java index 46738479bf0..17fb7bff9d3 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiClassFinderImpl.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiClassFinderImpl.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.lang.resolve.java; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiAnnotation; import com.intellij.psi.PsiClass; @@ -55,6 +56,23 @@ public class PsiClassFinderImpl implements PsiClassFinder { public boolean contains(VirtualFile file) { return myBaseScope.contains(file) && file.getFileType() != JetFileType.INSTANCE; } + + @Override + public int compare(VirtualFile file1, VirtualFile file2) { + // TODO: this is a hackish workaround for the following problem: + // since we are working with the allScope(), if the same class FqName + // to be on the class path twice, because it is included into different libraries + // (e.g. junit-4.0.jar is used as a separate library and as a part of idea_full) + // the two libraries are attached to different modules, the parent compare() + // can't tell which one comes first, so they can come in random order + // To fix this, we sort additionally by the full path, to make the ordering deterministic + // TODO: Delete this hack when proper scopes are used + int compare = super.compare(file1, file2); + if (compare == 0) { + return Comparing.compare(file1.getPath(), file2.getPath()); + } + return compare; + } }; javaFacade = new JavaPsiFacadeKotlinHacks(project); }