AnalyzerFacadeForJS implements interface AnalyzerFacade.
Delete analyzer*WithCache methods from AnalyzerFacadeForJVM. Introduce JsModuleDetector. Move AnalyzerFacadeWithCache to idea module. Make it static, make it acquire facade through AnalyzerFacadeProvider.
This commit is contained in:
-13
@@ -20,11 +20,9 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
@@ -103,15 +101,4 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
return analyzeFilesWithJavaIntegration(project, files, Predicates.<PsiFile>alwaysFalse(),
|
||||
JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalyzeExhaust analyzeFileWithCache(@NotNull final JetFile file,
|
||||
@NotNull final Function<JetFile, Collection<JetFile>> declarationProvider) {
|
||||
return AnalyzerFacadeWithCache.getInstance(INSTANCE).analyzeFileWithCache(file, declarationProvider);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalyzeExhaust analyzeProjectWithCache(@NotNull final Project project, @NotNull final Collection<JetFile> files) {
|
||||
return AnalyzerFacadeWithCache.getInstance(INSTANCE).analyzeProjectWithCache(project, files);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.jetbrains.jet.types;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.di.InjectorForTests;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -63,8 +63,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
List<JetDeclaration> declarations = file.getDeclarations();
|
||||
JetDeclaration aClass = declarations.get(0);
|
||||
assert aClass instanceof JetClass;
|
||||
AnalyzeExhaust bindingContext =
|
||||
AnalyzerFacadeForJVM.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER);
|
||||
AnalyzeExhaust bindingContext = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(file, JetControlFlowDataTraceFactory.EMPTY);
|
||||
DeclarationDescriptor classDescriptor =
|
||||
bindingContext.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, aClass);
|
||||
WritableScopeImpl scope = new WritableScopeImpl(libraryScope, root, RedeclarationHandler.DO_NOTHING);
|
||||
|
||||
@@ -26,13 +26,11 @@ import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.compiler.TipsManager;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.JetVisibilityChecker;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.plugin.project;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
|
||||
@@ -32,8 +31,7 @@ public final class AnalyzeSingleFileUtil {
|
||||
|
||||
@NotNull
|
||||
public static AnalyzeExhaust analyzeSingleFileWithCache(@NotNull JetFile file) {
|
||||
return AnalyzerFacadeProvider.getAnalyzerFacadeWithCacheForFile(file)
|
||||
.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER);
|
||||
return AnalyzerFacadeWithCache.analyzeFileWithCache(file, AnalyzerFacadeWithCache.SINGLE_DECLARATION_PROVIDER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -19,9 +19,9 @@ package org.jetbrains.jet.plugin.project;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -33,21 +33,17 @@ public final class AnalyzerFacadeProvider {
|
||||
|
||||
@NotNull
|
||||
public static AnalyzerFacade getAnalyzerFacadeForFile(@NotNull JetFile file) {
|
||||
if (JsModuleDetector.isJsProject(file.getProject())) {
|
||||
return AnalyzerFacadeForJS.INSTANCE;
|
||||
}
|
||||
return AnalyzerFacadeForJVM.INSTANCE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalyzerFacadeWithCache getAnalyzerFacadeWithCacheForFile(@NotNull JetFile file) {
|
||||
return AnalyzerFacadeWithCache.getInstance(getAnalyzerFacadeForFile(file));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalyzerFacade getAnalyzerFacadeForProject(@NotNull Project project) {
|
||||
if (JsModuleDetector.isJsProject(project)) {
|
||||
return AnalyzerFacadeForJS.INSTANCE;
|
||||
}
|
||||
return AnalyzerFacadeForJVM.INSTANCE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalyzerFacadeWithCache getAnalyzerFacadeWithCacheForProject(@NotNull Project project) {
|
||||
return AnalyzerFacadeWithCache.getInstance(getAnalyzerFacadeForProject(project));
|
||||
}
|
||||
}
|
||||
|
||||
+18
-32
@@ -14,9 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.analyzer;
|
||||
package org.jetbrains.jet.plugin.project;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
@@ -29,6 +28,7 @@ import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
@@ -41,9 +41,9 @@ import java.util.Collections;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class AnalyzerFacadeWithCache implements AnalyzerFacade {
|
||||
public final class AnalyzerFacadeWithCache {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache");
|
||||
private static final Logger LOG = Logger.getInstance("org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache");
|
||||
|
||||
private final static Key<CachedValue<AnalyzeExhaust>> ANALYZE_EXHAUST = Key.create("ANALYZE_EXHAUST");
|
||||
private static final Object lock = new Object();
|
||||
@@ -54,16 +54,9 @@ public class AnalyzerFacadeWithCache implements AnalyzerFacade {
|
||||
}
|
||||
};
|
||||
|
||||
public static AnalyzerFacadeWithCache getInstance(@NotNull AnalyzerFacade facade) {
|
||||
return new AnalyzerFacadeWithCache(facade);
|
||||
private AnalyzerFacadeWithCache() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final AnalyzerFacade facade;
|
||||
|
||||
private AnalyzerFacadeWithCache(@NotNull AnalyzerFacade facade) {
|
||||
this.facade = facade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze project with string cache for given file. Given file will be fully analyzed.
|
||||
@@ -73,8 +66,8 @@ public class AnalyzerFacadeWithCache implements AnalyzerFacade {
|
||||
* @return
|
||||
*/
|
||||
@NotNull
|
||||
public AnalyzeExhaust analyzeFileWithCache(@NotNull final JetFile file,
|
||||
@NotNull final Function<JetFile, Collection<JetFile>> declarationProvider) {
|
||||
public static AnalyzeExhaust analyzeFileWithCache(@NotNull final JetFile file,
|
||||
@NotNull final Function<JetFile, Collection<JetFile>> declarationProvider) {
|
||||
// Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously
|
||||
synchronized (lock) {
|
||||
CachedValue<AnalyzeExhaust> bindingContextCachedValue = file.getUserData(ANALYZE_EXHAUST);
|
||||
@@ -84,10 +77,11 @@ public class AnalyzerFacadeWithCache implements AnalyzerFacade {
|
||||
@Override
|
||||
public Result<AnalyzeExhaust> compute() {
|
||||
try {
|
||||
AnalyzeExhaust exhaust = facade.analyzeFiles(file.getProject(),
|
||||
declarationProvider.fun(file),
|
||||
Predicates.<PsiFile>equalTo(file),
|
||||
JetControlFlowDataTraceFactory.EMPTY);
|
||||
AnalyzeExhaust exhaust = AnalyzerFacadeProvider.getAnalyzerFacadeForFile(file)
|
||||
.analyzeFiles(file.getProject(),
|
||||
declarationProvider.fun(file),
|
||||
Predicates.<PsiFile>equalTo(file),
|
||||
JetControlFlowDataTraceFactory.EMPTY);
|
||||
return new Result<AnalyzeExhaust>(exhaust, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
@@ -122,7 +116,7 @@ public class AnalyzerFacadeWithCache implements AnalyzerFacade {
|
||||
* Analyze project with string cache for the whole project. All given files will be analyzed only for descriptors.
|
||||
*/
|
||||
@NotNull
|
||||
public AnalyzeExhaust analyzeProjectWithCache(@NotNull final Project project, @NotNull final Collection<JetFile> files) {
|
||||
public static AnalyzeExhaust analyzeProjectWithCache(@NotNull final Project project, @NotNull final Collection<JetFile> files) {
|
||||
// Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously
|
||||
synchronized (lock) {
|
||||
CachedValue<AnalyzeExhaust> bindingContextCachedValue = project.getUserData(ANALYZE_EXHAUST);
|
||||
@@ -132,10 +126,11 @@ public class AnalyzerFacadeWithCache implements AnalyzerFacade {
|
||||
@Override
|
||||
public Result<AnalyzeExhaust> compute() {
|
||||
try {
|
||||
AnalyzeExhaust analyzeExhaust = facade.analyzeFiles(project,
|
||||
files,
|
||||
Predicates.<PsiFile>alwaysFalse(),
|
||||
JetControlFlowDataTraceFactory.EMPTY);
|
||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeProvider.getAnalyzerFacadeForProject(project)
|
||||
.analyzeFiles(project,
|
||||
files,
|
||||
Predicates.<PsiFile>alwaysFalse(),
|
||||
JetControlFlowDataTraceFactory.EMPTY);
|
||||
return new Result<AnalyzeExhaust>(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
@@ -159,13 +154,4 @@ public class AnalyzerFacadeWithCache implements AnalyzerFacade {
|
||||
return bindingContextCachedValue.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnalyzeExhaust analyzeFiles(@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
return facade.analyzeFiles(project, files, filesToAnalyzeCompletely, flowDataTraceFactory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.plugin.project;
|
||||
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*
|
||||
* This class has utility functions to determine whether the project (or module) is js project.
|
||||
*/
|
||||
public final class JsModuleDetector {
|
||||
|
||||
public static final String INDICATION_FILE_NAME = "k2js.txt";
|
||||
|
||||
private JsModuleDetector() {
|
||||
}
|
||||
|
||||
public static boolean isJsProject(@NotNull Project project) {
|
||||
return findIndicationFileInContextRoots(project) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static VirtualFile findIndicationFileInContextRoots(@NotNull Project project) {
|
||||
VirtualFile[] roots = ProjectRootManager.getInstance(project).getContentRoots();
|
||||
for (VirtualFile root : roots) {
|
||||
for (VirtualFile child : root.getChildren()) {
|
||||
if (child.getFileType().equals(FileTypes.PLAIN_TEXT) && child.getName().equals(INDICATION_FILE_NAME)) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
||||
|
||||
import static org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache.analyzeFileWithCache;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -36,13 +38,11 @@ public final class WholeProjectAnalyzerFacade {
|
||||
|
||||
@NotNull
|
||||
public static AnalyzeExhaust analyzeProjectWithCacheOnAFile(@NotNull JetFile file) {
|
||||
return AnalyzerFacadeProvider.getAnalyzerFacadeWithCacheForFile(file)
|
||||
.analyzeFileWithCache(file, JetFilesProvider.getInstance(file.getProject()).sampleToAllFilesInModule());
|
||||
return analyzeFileWithCache(file, JetFilesProvider.getInstance(file.getProject()).sampleToAllFilesInModule());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalyzeExhaust analyzeProjectWithCache(@NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return AnalyzerFacadeProvider.getAnalyzerFacadeWithCacheForProject(project)
|
||||
.analyzeProjectWithCache(project, JetFilesProvider.getInstance(project).allInScope(scope));
|
||||
return AnalyzerFacadeWithCache.analyzeProjectWithCache(project, JetFilesProvider.getInstance(project).allInScope(scope));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
@@ -32,9 +31,7 @@ import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
|
||||
|
||||
import static org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil.getContextForSingleFile;
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.quickfix;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.lang.DefaultModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
@@ -28,13 +27,11 @@ import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzeSingleFileUtil;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,14 +22,12 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
@@ -59,7 +57,7 @@ public class QuickFixUtil {
|
||||
public static JetType getDeclarationReturnType(JetNamedDeclaration declaration) {
|
||||
PsiFile file = declaration.getContainingFile();
|
||||
if (!(file instanceof JetFile)) return null;
|
||||
BindingContext bindingContext = getContextForSingleFile((JetFile) file);
|
||||
BindingContext bindingContext = getContextForSingleFile((JetFile)file);
|
||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
if (!(descriptor instanceof CallableDescriptor)) return null;
|
||||
JetType type = ((CallableDescriptor)descriptor).getReturnType();
|
||||
|
||||
@@ -19,11 +19,9 @@ package org.jetbrains.jet.plugin.refactoring;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
@@ -70,7 +68,7 @@ public class JetNameSuggester {
|
||||
public static String[] suggestNames(JetExpression expression, JetNameValidator validator) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
BindingContext bindingContext = getContextForSingleFile((JetFile) expression.getContainingFile());
|
||||
BindingContext bindingContext = getContextForSingleFile((JetFile)expression.getContainingFile());
|
||||
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
if (jetType != null) {
|
||||
addNamesForType(result, jetType, validator);
|
||||
|
||||
@@ -28,10 +28,8 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.NamespaceType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
|
||||
-2
@@ -34,11 +34,9 @@ import com.intellij.refactoring.introduce.inplace.OccurrencesChooser;
|
||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.NamespaceType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
|
||||
@@ -22,6 +22,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJs;
|
||||
import org.jetbrains.jet.lang.DefaultModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
@@ -34,7 +36,9 @@ import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.config.IDEAConfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -44,11 +48,23 @@ import java.util.List;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class AnalyzerFacadeForJS {
|
||||
public enum AnalyzerFacadeForJS implements AnalyzerFacade {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
private AnalyzerFacadeForJS() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnalyzeExhaust analyzeFiles(@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
BindingContext context = analyzeFiles(files, new IDEAConfig(project));
|
||||
return new AnalyzeExhaust(context, JetStandardLibrary.getInstance());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BindingContext analyzeFilesAndCheckErrors(@NotNull List<JetFile> files,
|
||||
@NotNull Config config) {
|
||||
@@ -58,7 +74,7 @@ public final class AnalyzerFacadeForJS {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static BindingContext analyzeFiles(@NotNull List<JetFile> files,
|
||||
public static BindingContext analyzeFiles(@NotNull Collection<JetFile> files,
|
||||
@NotNull Config config) {
|
||||
Project project = config.getProject();
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
@@ -76,7 +92,7 @@ public final class AnalyzerFacadeForJS {
|
||||
return bindingTraceContext.getBindingContext();
|
||||
}
|
||||
|
||||
private static void checkForErrors(@NotNull List<JetFile> allFiles, @NotNull BindingContext bindingContext) {
|
||||
private static void checkForErrors(@NotNull Collection<JetFile> allFiles, @NotNull BindingContext bindingContext) {
|
||||
AnalyzingUtils.throwExceptionOnErrors(bindingContext);
|
||||
for (JetFile file : allFiles) {
|
||||
AnalyzingUtils.checkForSyntacticErrors(file);
|
||||
@@ -84,7 +100,7 @@ public final class AnalyzerFacadeForJS {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<JetFile> withJsLibAdded(@NotNull List<JetFile> files, @NotNull Config config) {
|
||||
public static Collection<JetFile> withJsLibAdded(@NotNull Collection<JetFile> files, @NotNull Config config) {
|
||||
List<JetFile> allFiles = new ArrayList<JetFile>();
|
||||
allFiles.addAll(files);
|
||||
allFiles.addAll(config.getLibFiles());
|
||||
@@ -103,6 +119,8 @@ public final class AnalyzerFacadeForJS {
|
||||
};
|
||||
}
|
||||
|
||||
//TODO: exclude?
|
||||
@NotNull
|
||||
public static BindingContext analyzeNamespace(@NotNull JetFile file) {
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
Project project = file.getProject();
|
||||
|
||||
@@ -45,6 +45,11 @@ public final class IDEAConfig extends Config {
|
||||
this.pathToLibZip = pathToLibZip;
|
||||
}
|
||||
|
||||
public IDEAConfig(@NotNull Project project) {
|
||||
//TODO: testing purposes. Should not get anywhere near production
|
||||
this(project, "C:\\Dev\\Projects\\Kotlin\\clean_jet\\js\\js.libraries\\src\\k2jslib.zip");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetFile> getLibFiles() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.k2js.facade;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.backend.js.ast.JsProgram;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -33,10 +34,7 @@ import org.jetbrains.k2js.utils.JetFileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getNamespaceName;
|
||||
|
||||
@@ -108,7 +106,8 @@ public final class K2JSTranslator {
|
||||
public JsProgram generateProgram(@NotNull List<JetFile> filesToTranslate) {
|
||||
JetStandardLibrary.initialize(config.getProject());
|
||||
BindingContext bindingContext = AnalyzerFacadeForJS.analyzeFilesAndCheckErrors(filesToTranslate, config);
|
||||
return Translation.generateAst(bindingContext, AnalyzerFacadeForJS.withJsLibAdded(filesToTranslate, config));
|
||||
Collection<JetFile> files = AnalyzerFacadeForJS.withJsLibAdded(filesToTranslate, config);
|
||||
return Translation.generateAst(bindingContext, Lists.newArrayList(files));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user