Merge remote-tracking branch 'origin/master'
This commit is contained in:
+1
-1
@@ -57,7 +57,7 @@ public class JetExplicitlyImportedWeigher extends LookupElementWeigher {
|
||||
// Invalid name can be met for class object descriptor: Test.MyTest.A.<no name provided>.testOther
|
||||
if (FqName.isValid(fqName.toString())) {
|
||||
ImportPath importPath = new ImportPath(fqName.toString());
|
||||
if (ImportInsertHelper.doNeedImport(importPath, null, file)) {
|
||||
if (ImportInsertHelper.doNeedImport(importPath, file)) {
|
||||
return MyResult.notImported;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -101,8 +101,8 @@ public class JetImportOptimizer implements ImportOptimizer {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isUseful(importPath, anImport.getAliasName(), usedQualifiedNames)) {
|
||||
ImportInsertHelper.addImportDirective(importPath, anImport.getAliasName(), jetFile);
|
||||
if (isUseful(importPath, usedQualifiedNames)) {
|
||||
ImportInsertHelper.addImportDirective(importPath, jetFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,8 +111,8 @@ public class JetImportOptimizer implements ImportOptimizer {
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean isUseful(ImportPath importPath, @Nullable String aliasName, Collection<FqName> usedNames) {
|
||||
if (aliasName != null) {
|
||||
public static boolean isUseful(ImportPath importPath, Collection<FqName> usedNames) {
|
||||
if (importPath.hasAlias()) {
|
||||
// TODO: Add better analysis for aliases
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SpecifyTypeExplicitlyAction extends PsiElementBaseIntentionAction {
|
||||
addTypeAnnotation(project, function, type);
|
||||
}
|
||||
else {
|
||||
assert false;
|
||||
throw new IllegalStateException("Unexpected parent: " + parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.codegen.*;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.codegen.state.Progress;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.internal.Location;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
@@ -90,7 +91,8 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
|
||||
if (exhaust.isError()) {
|
||||
return printStackTraceToString(exhaust.getError());
|
||||
}
|
||||
state = new GenerationState(jetFile.getProject(), ClassBuilderFactories.TEXT, exhaust.getBindingContext(), Collections.singletonList(jetFile));
|
||||
state = new GenerationState(jetFile.getProject(), ClassBuilderFactories.TEXT, Progress.DEAF, exhaust.getBindingContext(),
|
||||
Collections.singletonList(jetFile), BuiltinToJavaTypesMapping.ENABLED, true, true, true);
|
||||
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
@@ -104,7 +106,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
|
||||
|
||||
final ClassFileFactory factory = state.getFactory();
|
||||
for (String filename : factory.files()) {
|
||||
answer.append("// ================ ");
|
||||
answer.append("// ================");
|
||||
answer.append(filename);
|
||||
answer.append(" =================\n");
|
||||
answer.append(factory.asText(filename)).append("\n\n");
|
||||
|
||||
@@ -211,7 +211,7 @@ public class JetSourceNavigationHelper {
|
||||
project,
|
||||
storageManager,
|
||||
new ModuleDescriptor(Name.special("<library module>")),
|
||||
DefaultModuleConfiguration.createStandardConfiguration(project),
|
||||
DefaultModuleConfiguration.createStandardConfiguration(),
|
||||
providerFactory);
|
||||
|
||||
for (JetNamedDeclaration candidate : candidates) {
|
||||
@@ -229,10 +229,10 @@ public class JetSourceNavigationHelper {
|
||||
|
||||
@Nullable
|
||||
private static JetClassOrObject getSourceForNamedClassOrObject(@NotNull JetClassOrObject decompiledClassOrObject) {
|
||||
FqName classFqName = JetPsiUtil.getFQName((JetNamedDeclaration) decompiledClassOrObject);
|
||||
FqName classFqName = JetPsiUtil.getFQName(decompiledClassOrObject);
|
||||
assert classFqName != null;
|
||||
|
||||
GlobalSearchScope librarySourcesScope = createLibrarySourcesScope((JetNamedDeclaration) decompiledClassOrObject);
|
||||
GlobalSearchScope librarySourcesScope = createLibrarySourcesScope(decompiledClassOrObject);
|
||||
if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
|
||||
@Override
|
||||
public boolean apply(@Nullable FqName fqName) {
|
||||
assert fqName != null;
|
||||
return ImportInsertHelper.doNeedImport(new ImportPath(fqName, false), null, (JetFile) file);
|
||||
return ImportInsertHelper.doNeedImport(new ImportPath(fqName, false), (JetFile) file);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class ImportInsertHelper {
|
||||
* @param file File where directive should be added.
|
||||
*/
|
||||
public static void addImportDirective(@NotNull FqName importFqn, @NotNull JetFile file) {
|
||||
addImportDirective(new ImportPath(importFqn, false), null, file);
|
||||
addImportDirective(new ImportPath(importFqn, false), file);
|
||||
}
|
||||
|
||||
public static void addImportDirectiveOrChangeToFqName(@NotNull FqName importFqn, @NotNull JetFile file, int refOffset, @NotNull PsiElement targetElement) {
|
||||
@@ -109,15 +109,15 @@ public class ImportInsertHelper {
|
||||
return;
|
||||
}
|
||||
}
|
||||
addImportDirective(new ImportPath(importFqn, false), null, file);
|
||||
addImportDirective(new ImportPath(importFqn, false), file);
|
||||
}
|
||||
|
||||
public static void addImportDirective(@NotNull ImportPath importPath, @Nullable String aliasName, @NotNull JetFile file) {
|
||||
if (!doNeedImport(importPath, aliasName, file)) {
|
||||
public static void addImportDirective(@NotNull ImportPath importPath, @NotNull JetFile file) {
|
||||
if (!doNeedImport(importPath, file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importPath, aliasName);
|
||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importPath);
|
||||
List<JetImportDirective> importDirectives = file.getImportDirectives();
|
||||
|
||||
if (!importDirectives.isEmpty()) {
|
||||
@@ -125,34 +125,36 @@ public class ImportInsertHelper {
|
||||
lastDirective.getParent().addAfter(newDirective, lastDirective);
|
||||
}
|
||||
else {
|
||||
file.getNamespaceHeader().getParent().addAfter(newDirective, file.getNamespaceHeader());
|
||||
JetNamespaceHeader header = file.getNamespaceHeader();
|
||||
if (header == null) {
|
||||
throw new IllegalStateException("Scripts are not supported: " + file.getName());
|
||||
}
|
||||
|
||||
header.getParent().addAfter(newDirective, file.getNamespaceHeader());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that import is useless.
|
||||
*/
|
||||
private static boolean isImportedByDefault(@NotNull ImportPath importPath, @Nullable String aliasName, @NotNull FqName filePackageFqn) {
|
||||
private static boolean isImportedByDefault(@NotNull ImportPath importPath, @NotNull FqName filePackageFqn) {
|
||||
if (importPath.fqnPart().isRoot()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aliasName != null) {
|
||||
return false;
|
||||
}
|
||||
if (!importPath.isAllUnder() && !importPath.hasAlias()) {
|
||||
// Single element import without .* and alias is useless
|
||||
if (QualifiedNamesUtil.isOneSegmentFQN(importPath.fqnPart())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Single element import without .* and alias is useless
|
||||
if (!importPath.isAllUnder() && QualifiedNamesUtil.isOneSegmentFQN(importPath.fqnPart())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// There's no need to import a declaration from the package of current file
|
||||
if (!importPath.isAllUnder() && filePackageFqn.equals(importPath.fqnPart().parent())) {
|
||||
return true;
|
||||
// There's no need to import a declaration from the package of current file
|
||||
if (filePackageFqn.equals(importPath.fqnPart().parent())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isImportedWithKotlinDefault(importPath)) return true;
|
||||
|
||||
if (isImportedWithJavaDefault(importPath)) return true;
|
||||
|
||||
return false;
|
||||
@@ -176,13 +178,13 @@ public class ImportInsertHelper {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean doNeedImport(@NotNull ImportPath importPath, @Nullable String aliasName, @NotNull JetFile file) {
|
||||
if (QualifiedNamesUtil.getFirstSegment(importPath.fqnPart().getFqName()).equals(JavaDescriptorResolver.JAVA_ROOT.getName())) {
|
||||
public static boolean doNeedImport(@NotNull ImportPath importPath, @NotNull JetFile file) {
|
||||
if (importPath.fqnPart().firstSegmentIs(JavaDescriptorResolver.JAVA_ROOT)) {
|
||||
FqName withoutJavaRoot = QualifiedNamesUtil.withoutFirstSegment(importPath.fqnPart());
|
||||
importPath = new ImportPath(withoutJavaRoot, importPath.isAllUnder());
|
||||
importPath = new ImportPath(withoutJavaRoot, importPath.isAllUnder(), importPath.getAlias());
|
||||
}
|
||||
|
||||
if (isImportedByDefault(importPath, null, JetPsiUtil.getFQName(file))) {
|
||||
if (isImportedByDefault(importPath, JetPsiUtil.getFQName(file))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -192,10 +194,8 @@ public class ImportInsertHelper {
|
||||
// Check if import is already present
|
||||
for (JetImportDirective directive : importDirectives) {
|
||||
ImportPath existentImportPath = JetPsiUtil.getImportPath(directive);
|
||||
if (directive.getAliasName() == null && aliasName == null) {
|
||||
if (existentImportPath != null && QualifiedNamesUtil.isImported(existentImportPath, importPath)) {
|
||||
return false;
|
||||
}
|
||||
if (existentImportPath != null && QualifiedNamesUtil.isImported(existentImportPath, importPath)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.plugin.search;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -33,15 +34,18 @@ import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.indexing.FileBasedIndex;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.asJava.KotlinLightClass;
|
||||
import org.jetbrains.jet.asJava.LightClassUtil;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetAnnotationEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.KotlinCacheManager;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.KotlinDeclarationsCache;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetAnnotationsIndex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -70,10 +74,12 @@ public class KotlinAnnotatedElementsSearcher extends AnnotatedElementsSearcher {
|
||||
@Override
|
||||
public void run() {
|
||||
//TODO LazyResolve
|
||||
AnalyzeExhaust analyzeExhaust = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile((JetFile) elt.getContainingFile());
|
||||
Project project = elt.getProject();
|
||||
KotlinDeclarationsCache declarations = KotlinCacheManager.getInstance(project).getDeclarationsFromProject(project);
|
||||
BindingContext context = declarations.getBindingContext();
|
||||
|
||||
JetDeclaration parentOfType = PsiTreeUtil.getParentOfType(elt, JetDeclaration.class);
|
||||
if (parentOfType == null) return;
|
||||
BindingContext context = analyzeExhaust.getBindingContext();
|
||||
AnnotationDescriptor annotationDescriptor = context.get(BindingContext.ANNOTATION, (JetAnnotationEntry) elt);
|
||||
if (annotationDescriptor == null) return;
|
||||
|
||||
|
||||
@@ -107,7 +107,9 @@ public class KotlinRuntimeLibraryUtil {
|
||||
|
||||
public static void addJdkAnnotations(@NotNull Module module) {
|
||||
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
|
||||
assert sdk != null;
|
||||
if (sdk == null) {
|
||||
return;
|
||||
}
|
||||
File annotationsIoFile = PathUtil.getKotlinPathsForIdeaPlugin().getJdkAnnotationsPath();
|
||||
if (annotationsIoFile.exists()) {
|
||||
VirtualFile jdkAnnotationsJar = LocalFileSystem.getInstance().findFileByIoFile(annotationsIoFile);
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package first
|
||||
|
||||
import second.testFun
|
||||
|
||||
fun test() {
|
||||
te<caret>
|
||||
}
|
||||
|
||||
// EXIST: testFun
|
||||
@@ -0,0 +1,3 @@
|
||||
package second
|
||||
|
||||
fun testFun() : Int = 12
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Import Class" "false"
|
||||
|
||||
// KT-3165 Weird stack overflow in IDE
|
||||
// ERROR: Unresolved reference: Bar
|
||||
// ERROR: Unresolved reference: SomeImpossibleName
|
||||
|
||||
import Foo.Bar
|
||||
|
||||
class Foo
|
||||
|
||||
fun f() {
|
||||
<caret>SomeImpossibleName
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Import Class" "false"
|
||||
|
||||
// KT-3165 Weird stack overflow in IDE
|
||||
// ERROR: Unresolved reference: Bar
|
||||
// ERROR: Unresolved reference: SomeImpossibleName
|
||||
|
||||
import Foo.Bar
|
||||
|
||||
class Foo
|
||||
|
||||
fun f() {
|
||||
<caret>SomeImpossibleName
|
||||
}
|
||||
@@ -54,6 +54,6 @@ public abstract class JetCompletionMultiTestBase extends CompletionTestCase {
|
||||
}
|
||||
|
||||
protected void doFileTest() {
|
||||
doFileTest(1, getFileNameList());
|
||||
doFileTest(0, getFileNameList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ package org.jetbrains.jet.completion;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
public class JetMultifileBasicCompletionTest extends JetCompletionMultiTestBase {
|
||||
public void testCompleteImportedFunction() {
|
||||
doFileTest();
|
||||
}
|
||||
|
||||
public void testCompletionOnImportedFunction() {
|
||||
doFileTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user