Pass module to GenerationState
- get rid of a hack there which was used to obtain any module, to be used in ReflectionTypes - delete unused getError() in LightClassConstructionContext which was always null - fix some minor warnings
This commit is contained in:
+10
-9
@@ -29,7 +29,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.asJava.KotlinLightClassForExplicitDeclaration;
|
||||
import org.jetbrains.jet.asJava.LightClassConstructionContext;
|
||||
import org.jetbrains.jet.asJava.LightClassGenerationSupport;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
@@ -79,16 +82,14 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
@NotNull
|
||||
@Override
|
||||
public LightClassConstructionContext getContextForPackage(@NotNull Collection<JetFile> files) {
|
||||
if (files.isEmpty()) {
|
||||
return new LightClassConstructionContext(BindingContext.EMPTY, null);
|
||||
}
|
||||
assert !files.isEmpty() : "No files in package";
|
||||
|
||||
List<JetFile> sortedFiles = new ArrayList<JetFile>(files);
|
||||
Collections.sort(sortedFiles, jetFileComparator);
|
||||
|
||||
ResolveSessionForBodies session = ResolvePackage.getLazyResolveSession(sortedFiles.get(0));
|
||||
forceResolvePackageDeclarations(files, session);
|
||||
return new LightClassConstructionContext(session.getBindingContext(), null);
|
||||
return new LightClassConstructionContext(session.getBindingContext(), session.getModuleDescriptor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -102,16 +103,16 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
|
||||
if (descriptor == null) {
|
||||
LOG.warn("No class descriptor in context for class: " + JetPsiUtil.getElementTextWithContext(classOrObject));
|
||||
return new LightClassConstructionContext(BindingContext.EMPTY, null);
|
||||
return new LightClassConstructionContext(BindingContext.EMPTY, session.getModuleDescriptor());
|
||||
}
|
||||
|
||||
ForceResolveUtil.forceResolveAllContents(descriptor);
|
||||
|
||||
return new LightClassConstructionContext(bindingContext, null);
|
||||
return new LightClassConstructionContext(bindingContext, session.getModuleDescriptor());
|
||||
}
|
||||
|
||||
ForceResolveUtil.forceResolveAllContents(session.getClassDescriptor(classOrObject));
|
||||
return new LightClassConstructionContext(session.getBindingContext(), null);
|
||||
return new LightClassConstructionContext(session.getBindingContext(), session.getModuleDescriptor());
|
||||
}
|
||||
|
||||
private static void forceResolvePackageDeclarations(@NotNull Collection<JetFile> files, @NotNull KotlinCodeAnalyzer session) {
|
||||
@@ -164,7 +165,7 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetFile> findFilesForPackage(@NotNull final FqName fqName, @NotNull GlobalSearchScope searchScope) {
|
||||
public Collection<JetFile> findFilesForPackage(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) {
|
||||
return PackageIndexUtil.findFilesWithExactPackage(fqName, kotlinSources(searchScope), project);
|
||||
}
|
||||
|
||||
|
||||
@@ -201,7 +201,8 @@ public class JetPositionManager implements PositionManager {
|
||||
analyzeExhaust.throwIfError();
|
||||
|
||||
GenerationState state = new GenerationState(file.getProject(), ClassBuilderFactories.THROW_EXCEPTION,
|
||||
analyzeExhaust.getBindingContext(), new ArrayList<JetFile>(packageFiles));
|
||||
analyzeExhaust.getModuleDescriptor(), analyzeExhaust.getBindingContext(),
|
||||
new ArrayList<JetFile>(packageFiles));
|
||||
state.beforeCompile();
|
||||
return new Result<JetTypeMapper>(state.getTypeMapper(), PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
|
||||
@@ -187,6 +187,7 @@ class KotlinEvaluator(val codeFragment: JetCodeFragment,
|
||||
val state = GenerationState(
|
||||
file.getProject(),
|
||||
ClassBuilderFactories.BINARIES,
|
||||
analyzeExhaust.getModuleDescriptor(),
|
||||
bindingContext,
|
||||
listOf(file)
|
||||
)
|
||||
|
||||
@@ -108,7 +108,8 @@ public class BytecodeToolWindow extends JPanel implements Disposable {
|
||||
if (exhaust.isError()) {
|
||||
return printStackTraceToString(exhaust.getError());
|
||||
}
|
||||
state = new GenerationState(jetFile.getProject(), ClassBuilderFactories.TEST, Progress.DEAF, exhaust.getBindingContext(),
|
||||
state = new GenerationState(jetFile.getProject(), ClassBuilderFactories.TEST, Progress.DEAF,
|
||||
exhaust.getModuleDescriptor(), exhaust.getBindingContext(),
|
||||
Collections.singletonList(jetFile), true, true,
|
||||
GenerationState.GenerateClassFilter.GENERATE_ALL,
|
||||
enableInline.isSelected());
|
||||
|
||||
@@ -74,7 +74,8 @@ public class DebuggerUtils {
|
||||
// TODO: this code is not entirely correct, because it takes a session for only one file
|
||||
AnalyzeExhaust analyzeExhaust = ResolvePackage.getAnalysisResultsForElements(files);
|
||||
|
||||
return PsiCodegenPredictor.getFileForCodegenNamedClass(analyzeExhaust.getBindingContext(), allPackageFiles, className.getInternalName());
|
||||
return PsiCodegenPredictor.getFileForCodegenNamedClass(analyzeExhaust.getModuleDescriptor(), analyzeExhaust.getBindingContext(),
|
||||
allPackageFiles, className.getInternalName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user