replace JavaPsiFacade with own
This commit is contained in:
+105
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.lang.resolve.java;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.intellij.core.CoreJavaFileManager;
|
||||||
|
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.psi.PsiClass;
|
||||||
|
import com.intellij.psi.PsiElementFinder;
|
||||||
|
import com.intellij.psi.PsiPackage;
|
||||||
|
import com.intellij.psi.impl.JavaPsiFacadeImpl;
|
||||||
|
import com.intellij.psi.impl.file.impl.JavaFileManager;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO Temporary class until {@link JavaPsiFacadeImpl} hacked.
|
||||||
|
*
|
||||||
|
* @author Stepan Koltsov
|
||||||
|
*
|
||||||
|
* @see JavaPsiFacadeImpl
|
||||||
|
*/
|
||||||
|
public class JavaPsiFacadeKotlinHacks {
|
||||||
|
public interface KotlinFinderMarker {}
|
||||||
|
|
||||||
|
private final JavaFileManager javaFileManager;
|
||||||
|
private final List<PsiElementFinder> extensionPsiElementFinders;
|
||||||
|
|
||||||
|
public JavaPsiFacadeKotlinHacks(@NotNull Project project) {
|
||||||
|
this.javaFileManager = findJavaFileManager(project);
|
||||||
|
this.extensionPsiElementFinders = Lists.newArrayList();
|
||||||
|
for (PsiElementFinder finder : project.getExtensions(PsiElementFinder.EP_NAME)) {
|
||||||
|
if (!(finder instanceof KotlinFinderMarker)) {
|
||||||
|
this.extensionPsiElementFinders.add(finder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private JavaFileManager findJavaFileManager(@NotNull Project project) {
|
||||||
|
JavaFileManager javaFileManager = project.getComponent(JavaFileManager.class);
|
||||||
|
if (javaFileManager != null) {
|
||||||
|
return javaFileManager;
|
||||||
|
}
|
||||||
|
javaFileManager = project.getComponent(CoreJavaFileManager.class);
|
||||||
|
if (javaFileManager != null) {
|
||||||
|
// TODO: why it is not found by JavaFileManager?
|
||||||
|
return javaFileManager;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("JavaFileManager component is not found in project");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public PsiPackage findPackage(@NotNull String qualifiedName) {
|
||||||
|
PsiPackage psiPackage = javaFileManager.findPackage(qualifiedName);
|
||||||
|
if (psiPackage != null) {
|
||||||
|
return psiPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PsiElementFinder finder : extensionPsiElementFinders) {
|
||||||
|
psiPackage = finder.findPackage(qualifiedName);
|
||||||
|
if (psiPackage != null) {
|
||||||
|
return psiPackage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return psiPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PsiClass findClass(@NotNull final String qualifiedName, @NotNull GlobalSearchScope scope) {
|
||||||
|
ProgressIndicatorProvider.checkCanceled(); // We hope this method is being called often enough to cancel daemon processes smoothly
|
||||||
|
|
||||||
|
PsiClass aClass = javaFileManager.findClass(qualifiedName, scope);
|
||||||
|
if (aClass != null) {
|
||||||
|
return aClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PsiElementFinder finder : extensionPsiElementFinders) {
|
||||||
|
aClass = finder.findClass(qualifiedName, scope);
|
||||||
|
if (aClass != null) {
|
||||||
|
return aClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-3
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve.java;
|
|||||||
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.JavaPsiFacade;
|
|
||||||
import com.intellij.psi.PsiAnnotation;
|
import com.intellij.psi.PsiAnnotation;
|
||||||
import com.intellij.psi.PsiClass;
|
import com.intellij.psi.PsiClass;
|
||||||
import com.intellij.psi.PsiPackage;
|
import com.intellij.psi.PsiPackage;
|
||||||
@@ -46,7 +45,7 @@ public class PsiClassFinderForJvm implements PsiClassFinder {
|
|||||||
|
|
||||||
private AltClassFinder altClassFinder;
|
private AltClassFinder altClassFinder;
|
||||||
private GlobalSearchScope javaSearchScope;
|
private GlobalSearchScope javaSearchScope;
|
||||||
private JavaPsiFacade javaFacade;
|
private JavaPsiFacadeKotlinHacks javaFacade;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public void setProject(@NotNull Project project) {
|
public void setProject(@NotNull Project project) {
|
||||||
@@ -67,7 +66,7 @@ public class PsiClassFinderForJvm implements PsiClassFinder {
|
|||||||
return myBaseScope.contains(file) && file.getFileType() != JetFileType.INSTANCE;
|
return myBaseScope.contains(file) && file.getFileType() != JetFileType.INSTANCE;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.javaFacade = JavaPsiFacade.getInstance(project);
|
this.javaFacade = new JavaPsiFacadeKotlinHacks(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.codegen.JetTypeMapper;
|
import org.jetbrains.jet.codegen.JetTypeMapper;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.FqName;
|
import org.jetbrains.jet.lang.resolve.FqName;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JavaPsiFacadeKotlinHacks;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||||
@@ -41,7 +42,7 @@ import java.util.List;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
public class JavaElementFinder extends PsiElementFinder {
|
public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacadeKotlinHacks.KotlinFinderMarker {
|
||||||
private final Project project;
|
private final Project project;
|
||||||
private final PsiManager psiManager;
|
private final PsiManager psiManager;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user