Remove PsiClassFinder
Inline the implementation into JavaClassFinderImpl
This commit is contained in:
+2
-7
@@ -25,7 +25,6 @@ import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedErrorReporter;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedMethodSignatureChecker;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedExternalAnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.PsiClassFinderImpl;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileKotlinClassFinder;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaAnnotationResolver;
|
||||
@@ -57,7 +56,6 @@ public class InjectorForJavaDescriptorResolver {
|
||||
private final PsiBasedMethodSignatureChecker psiBasedMethodSignatureChecker;
|
||||
private final PsiBasedExternalAnnotationResolver psiBasedExternalAnnotationResolver;
|
||||
private final JavaDescriptorResolver javaDescriptorResolver;
|
||||
private final PsiClassFinderImpl psiClassFinder;
|
||||
private final VirtualFileKotlinClassFinder virtualFileKotlinClassFinder;
|
||||
private final VirtualFileFinder virtualFileFinder;
|
||||
private final JavaAnnotationResolver javaAnnotationResolver;
|
||||
@@ -88,7 +86,6 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.psiBasedMethodSignatureChecker = new PsiBasedMethodSignatureChecker();
|
||||
this.psiBasedExternalAnnotationResolver = new PsiBasedExternalAnnotationResolver();
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver();
|
||||
this.psiClassFinder = new PsiClassFinderImpl();
|
||||
this.virtualFileKotlinClassFinder = new VirtualFileKotlinClassFinder();
|
||||
this.virtualFileFinder = com.intellij.openapi.components.ServiceManager.getService(project, VirtualFileFinder.class);
|
||||
this.javaAnnotationResolver = new JavaAnnotationResolver();
|
||||
@@ -106,7 +103,7 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.javaPropertyResolver = new JavaPropertyResolver();
|
||||
this.javaSupertypeResolver = new JavaSupertypeResolver();
|
||||
|
||||
this.javaClassFinder.setPsiClassFinder(psiClassFinder);
|
||||
this.javaClassFinder.setProject(project);
|
||||
|
||||
traceBasedExternalSignatureResolver.setAnnotationResolver(javaAnnotationResolver);
|
||||
traceBasedExternalSignatureResolver.setTrace(bindingTrace);
|
||||
@@ -121,8 +118,6 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.javaDescriptorResolver.setClassResolver(javaClassResolver);
|
||||
this.javaDescriptorResolver.setNamespaceResolver(javaNamespaceResolver);
|
||||
|
||||
psiClassFinder.setProject(project);
|
||||
|
||||
virtualFileKotlinClassFinder.setVirtualFileFinder(virtualFileFinder);
|
||||
|
||||
javaAnnotationResolver.setArgumentResolver(javaAnnotationArgumentResolver);
|
||||
@@ -194,7 +189,7 @@ public class InjectorForJavaDescriptorResolver {
|
||||
javaSupertypeResolver.setClassResolver(javaClassResolver);
|
||||
javaSupertypeResolver.setTypeTransformer(javaTypeTransformer);
|
||||
|
||||
psiClassFinder.initialize();
|
||||
javaClassFinder.initialize();
|
||||
|
||||
}
|
||||
|
||||
|
||||
+2
-7
@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.PsiClassFinderImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaClassFinderImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedExternalSignatureResolver;
|
||||
@@ -89,7 +88,6 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
private final ModuleDescriptorImpl moduleDescriptor;
|
||||
private final JavaBridgeConfiguration javaBridgeConfiguration;
|
||||
private final JavaDescriptorResolver javaDescriptorResolver;
|
||||
private final PsiClassFinderImpl psiClassFinder;
|
||||
private final JavaToKotlinClassMap javaToKotlinClassMap;
|
||||
private final JavaClassFinderImpl javaClassFinder;
|
||||
private final TraceBasedExternalSignatureResolver traceBasedExternalSignatureResolver;
|
||||
@@ -150,7 +148,6 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
this.javaBridgeConfiguration = new JavaBridgeConfiguration();
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver();
|
||||
this.psiClassFinder = new PsiClassFinderImpl();
|
||||
this.javaToKotlinClassMap = org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap.getInstance();
|
||||
this.javaClassFinder = new JavaClassFinderImpl();
|
||||
this.traceBasedExternalSignatureResolver = new TraceBasedExternalSignatureResolver();
|
||||
@@ -230,9 +227,7 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
javaDescriptorResolver.setClassResolver(javaClassResolver);
|
||||
javaDescriptorResolver.setNamespaceResolver(javaNamespaceResolver);
|
||||
|
||||
psiClassFinder.setProject(project);
|
||||
|
||||
javaClassFinder.setPsiClassFinder(psiClassFinder);
|
||||
javaClassFinder.setProject(project);
|
||||
|
||||
traceBasedExternalSignatureResolver.setAnnotationResolver(javaAnnotationResolver);
|
||||
traceBasedExternalSignatureResolver.setTrace(bindingTrace);
|
||||
@@ -385,7 +380,7 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
javaSupertypeResolver.setClassResolver(javaClassResolver);
|
||||
javaSupertypeResolver.setTypeTransformer(javaTypeTransformer);
|
||||
|
||||
psiClassFinder.initialize();
|
||||
javaClassFinder.initialize();
|
||||
|
||||
}
|
||||
|
||||
|
||||
+57
-6
@@ -16,8 +16,13 @@
|
||||
|
||||
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.PsiClass;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass;
|
||||
@@ -25,28 +30,74 @@ import org.jetbrains.jet.lang.resolve.java.structure.JavaPackage;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaClassImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaPackageImpl;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class JavaClassFinderImpl implements JavaClassFinder {
|
||||
private PsiClassFinder psiClassFinder;
|
||||
@NotNull
|
||||
private Project project;
|
||||
|
||||
private GlobalSearchScope javaSearchScope;
|
||||
private JavaPsiFacadeKotlinHacks javaFacade;
|
||||
|
||||
@Inject
|
||||
public void setPsiClassFinder(@NotNull PsiClassFinder psiClassFinder) {
|
||||
this.psiClassFinder = psiClassFinder;
|
||||
public void setProject(@NotNull Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
javaSearchScope = new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JavaClass findClass(@NotNull FqName fqName) {
|
||||
PsiClass psiClass = psiClassFinder.findPsiClass(fqName);
|
||||
return psiClass == null ? null : new JavaClassImpl(psiClass);
|
||||
PsiClass psiClass = javaFacade.findClass(fqName.asString(), javaSearchScope);
|
||||
if (psiClass == null) return null;
|
||||
|
||||
JavaClassImpl javaClass = new JavaClassImpl(psiClass);
|
||||
|
||||
if (!fqName.equals(javaClass.getFqName())) {
|
||||
throw new IllegalStateException("Requested " + fqName + ", got " + javaClass.getFqName());
|
||||
}
|
||||
|
||||
if (javaClass.getOriginKind() == JavaClass.OriginKind.KOTLIN_LIGHT_CLASS) {
|
||||
throw new IllegalStateException("Kotlin light classes should not be found by JavaPsiFacade, resolving: " + fqName);
|
||||
}
|
||||
|
||||
return javaClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JavaPackage findPackage(@NotNull FqName fqName) {
|
||||
PsiPackage psiPackage = psiClassFinder.findPsiPackage(fqName);
|
||||
PsiPackage psiPackage = javaFacade.findPackage(fqName.asString());
|
||||
return psiPackage == null ? null : new JavaPackageImpl(psiPackage);
|
||||
}
|
||||
}
|
||||
|
||||
-100
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiPackage;
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.resolve.java.jetAsJava.JetJavaMirrorMarker;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class PsiClassFinderImpl implements PsiClassFinder {
|
||||
@NotNull
|
||||
private Project project;
|
||||
|
||||
private GlobalSearchScope javaSearchScope;
|
||||
private JavaPsiFacadeKotlinHacks javaFacade;
|
||||
|
||||
@Inject
|
||||
public void setProject(@NotNull Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
javaSearchScope = new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiClass findPsiClass(@NotNull FqName qualifiedName) {
|
||||
PsiClass original = javaFacade.findClass(qualifiedName.asString(), javaSearchScope);
|
||||
|
||||
if (original != null) {
|
||||
String classQualifiedName = original.getQualifiedName();
|
||||
FqName actualQualifiedName = classQualifiedName != null ? new FqName(classQualifiedName) : null;
|
||||
if (!qualifiedName.equals(actualQualifiedName)) {
|
||||
throw new IllegalStateException("requested " + qualifiedName + ", got " + actualQualifiedName);
|
||||
}
|
||||
}
|
||||
|
||||
if (original instanceof JetJavaMirrorMarker) {
|
||||
throw new IllegalStateException("JetJavaMirrorMaker is not possible in resolve.java, resolving: " + qualifiedName);
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiPackage findPsiPackage(@NotNull FqName qualifiedName) {
|
||||
return javaFacade.findPackage(qualifiedName.asString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user