KotlinCacheManager and LightClassGenerationSupport services added

This commit is contained in:
Andrey Breslav
2012-12-17 17:31:56 +04:00
parent b5aa44ae49
commit 7c4d1e6b09
12 changed files with 371 additions and 11 deletions
@@ -36,7 +36,6 @@ import com.intellij.psi.util.*;
import com.intellij.util.containers.Stack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.codegen.ClassBuilder;
import org.jetbrains.jet.codegen.ClassBuilderFactory;
import org.jetbrains.jet.codegen.ClassBuilderMode;
@@ -45,8 +44,6 @@ import org.jetbrains.jet.codegen.binding.PsiCodegenPredictor;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.GenerationStrategy;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
import org.jetbrains.jet.lang.resolve.java.JetJavaMirrorMarker;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -208,15 +205,15 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
// The context must reflect _all files in the module_. not only the current file
// Otherwise, the analyzer gets confused and can't, for example, tell which files come as sources and which
// must be loaded from .class files
AnalyzeExhaust exhaust = AnalyzerFacadeForJVM.shallowAnalyzeFiles(
JetFilesProvider.getInstance(project).sampleToAllFilesInModule().fun(file));
LightClassConstructionContext context = LightClassGenerationSupport.getInstance(project).analyzeRelevantCode(file);
if (exhaust.isError()) {
throw new IllegalStateException("failed to analyze: " + exhaust.getError(), exhaust.getError());
Throwable error = context.getError();
if (error != null) {
throw new IllegalStateException("failed to analyze: " + error, error);
}
try {
GenerationState state = new GenerationState(project, builderFactory, exhaust.getBindingContext(), Collections.singletonList(file));
GenerationState state = new GenerationState(project, builderFactory, context.getBindingContext(), Collections.singletonList(file));
GenerationStrategy strategy = new LightClassGenerationStrategy(this, stubStack, answer);
strategy.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
@@ -0,0 +1,41 @@
/*
* 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.asJava;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.BindingContext;
public class LightClassConstructionContext {
private final BindingContext bindingContext;
private final Throwable error;
public LightClassConstructionContext(@NotNull BindingContext bindingContext, @Nullable Throwable error) {
this.bindingContext = bindingContext;
this.error = error;
}
@NotNull
public BindingContext getBindingContext() {
return bindingContext;
}
@Nullable
public Throwable getError() {
return error;
}
}
@@ -0,0 +1,33 @@
/*
* 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.asJava;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile;
public abstract class LightClassGenerationSupport {
@NotNull
public static LightClassGenerationSupport getInstance(@NotNull Project project) {
return ServiceManager.getService(project, LightClassGenerationSupport.class);
}
@NotNull
public abstract LightClassConstructionContext analyzeRelevantCode(@NotNull JetFile file);
}