mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
[java] avoid traversing vfs during indexing to check for automatic module name in MANIFEST.MF(IDEA-293456)
GitOrigin-RevId: db5ee5c486ac4fc57c7c8a30a2002ec1295fd93f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4a8cc01513
commit
a69b28077f
@@ -32,6 +32,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
@@ -162,11 +163,21 @@ public final class JavaFileManagerImpl implements JavaFileManager, Disposable {
|
||||
|
||||
List<PsiJavaModule> results = new ArrayList<>(JavaModuleNameIndex.getInstance().get(moduleName, myManager.getProject(), excludingScope));
|
||||
|
||||
Set<VirtualFile> roots = new HashSet<>();
|
||||
for (VirtualFile manifest : JavaSourceModuleNameIndex.getFilesByKey(moduleName, excludingScope)) {
|
||||
results.add(LightJavaModule.create(myManager, manifest.getParent().getParent(), moduleName));
|
||||
VirtualFile root = manifest.getParent().getParent();
|
||||
roots.add(root);
|
||||
results.add(LightJavaModule.create(myManager, root, moduleName));
|
||||
}
|
||||
|
||||
for (VirtualFile root : JavaAutoModuleNameIndex.getFilesByKey(moduleName, excludingScope)) {
|
||||
if (roots.contains(root)) { //already found by MANIFEST attribute
|
||||
continue;
|
||||
}
|
||||
VirtualFile manifest = root.findFileByRelativePath(JarFile.MANIFEST_NAME);
|
||||
if (manifest != null && LightJavaModule.claimedModuleName(manifest) != null) {
|
||||
continue;
|
||||
}
|
||||
results.add(LightJavaModule.create(myManager, root, moduleName));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
@@ -54,6 +54,7 @@ import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.impl.java.stubs.index.JavaAutoModuleNameIndex;
|
||||
import com.intellij.psi.impl.java.stubs.index.JavaModuleNameIndex;
|
||||
import com.intellij.psi.impl.java.stubs.index.JavaSourceModuleNameIndex;
|
||||
import com.intellij.psi.impl.light.LightJavaModule;
|
||||
import com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl;
|
||||
import com.intellij.psi.impl.source.PsiLabelReference;
|
||||
import com.intellij.psi.scope.ElementClassFilter;
|
||||
@@ -70,17 +71,7 @@ import org.jetbrains.annotations.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.patterns.PsiJavaPatterns.elementType;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.or;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiAnnotation;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiClass;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiElement;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiExpressionStatement;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiMethod;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiNameValuePair;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiParameter;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.psiReferenceExpression;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.string;
|
||||
import static com.intellij.patterns.PsiJavaPatterns.*;
|
||||
|
||||
public final class JavaCompletionContributor extends CompletionContributor implements DumbAware {
|
||||
private static final ElementPattern<PsiElement> UNEXPECTED_REFERENCE_AFTER_DOT = or(
|
||||
@@ -1288,15 +1279,24 @@ public final class JavaCompletionContributor extends CompletionContributor imple
|
||||
if (requires) {
|
||||
Module module = ModuleUtilCore.findModuleForFile(originalFile);
|
||||
if (module != null) {
|
||||
scope = GlobalSearchScope.projectScope(project);
|
||||
scope = GlobalSearchScope.allScope(project);
|
||||
Set<String> names = new HashSet<>();
|
||||
for (String name : JavaSourceModuleNameIndex.getAllKeys(project)) {
|
||||
if (JavaSourceModuleNameIndex.getFilesByKey(name, scope).size() > 0) {
|
||||
Collection<VirtualFile> roots = JavaSourceModuleNameIndex.getFilesByKey(name, scope);
|
||||
if (roots.size() > 0) {
|
||||
names.add(name);
|
||||
for (VirtualFile manifest : roots) {
|
||||
names.add(LightJavaModule.moduleName(manifest.getParent().getParent().getNameWithoutExtension()));
|
||||
}
|
||||
addAutoModuleReference(name, parent, filter, result);
|
||||
}
|
||||
}
|
||||
VirtualFile[] roots = ModuleRootManager.getInstance(module).orderEntries().withoutSdk().librariesOnly().getClassesRoots();
|
||||
scope = GlobalSearchScope.filesScope(project, Arrays.asList(roots));
|
||||
for (String name : JavaAutoModuleNameIndex.getAllKeys(project)) {
|
||||
if (names.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
if (JavaAutoModuleNameIndex.getFilesByKey(name, scope).size() > 0) {
|
||||
addAutoModuleReference(name, parent, filter, result);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.impl.java.stubs.index;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -23,7 +23,11 @@ class JavaAutoModuleFilterScope extends DelegatingGlobalSearchScope {
|
||||
if (!file.isDirectory()) {
|
||||
root = file.getParent().getParent();
|
||||
Project project = getProject();
|
||||
if (project == null || !root.equals(ProjectFileIndex.getInstance(project).getSourceRootForFile(file))) {
|
||||
if (project == null) {
|
||||
return false;
|
||||
}
|
||||
ProjectFileIndex fileIndex = ProjectFileIndex.getInstance(project);
|
||||
if (!root.equals(fileIndex.getSourceRootForFile(file)) && !root.equals(fileIndex.getClassRootForFile(file))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.impl.java.stubs.index;
|
||||
|
||||
import com.intellij.ide.highlighter.ArchiveFileType;
|
||||
@@ -28,7 +28,7 @@ public class JavaAutoModuleNameIndex extends ScalarIndexExtension<String> {
|
||||
}
|
||||
};
|
||||
|
||||
private final DataIndexer<String, Void, FileContent> myIndexer = data -> singletonMap(LightJavaModule.moduleName(data.getFile()), null);
|
||||
private final DataIndexer<String, Void, FileContent> myIndexer = data -> singletonMap(LightJavaModule.moduleName(data.getFile().getNameWithoutExtension()), null);
|
||||
|
||||
@Override
|
||||
public boolean indexDirectories() {
|
||||
@@ -42,7 +42,7 @@ public class JavaAutoModuleNameIndex extends ScalarIndexExtension<String> {
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 5;
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.impl.java.stubs.index;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaClassFileType;
|
||||
@@ -29,7 +29,7 @@ public final class JavaSourceModuleNameIndex extends ScalarIndexExtension<String
|
||||
new DefaultFileTypeSpecificInputFilter(FileTypeRegistry.getInstance().getFileTypeByExtension("MF")) {
|
||||
@Override
|
||||
public boolean acceptInput(@NotNull VirtualFile f) {
|
||||
return f.isInLocalFileSystem() && "MANIFEST.MF".equalsIgnoreCase(f.getName());
|
||||
return "MANIFEST.MF".equalsIgnoreCase(f.getName());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ public final class JavaSourceModuleNameIndex extends ScalarIndexExtension<String
|
||||
|
||||
@Override
|
||||
public int getVersion() {
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user