mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] recognizes claimed name in automatic modules
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -34,7 +34,7 @@ public class JavaAutoModuleNameIndex extends ScalarIndexExtension<String> {
|
||||
file -> file.isDirectory() && file.getParent() == null && "jar".equalsIgnoreCase(file.getExtension());
|
||||
|
||||
private final DataIndexer<String, Void, FileContent> myIndexer =
|
||||
data -> singletonMap(LightJavaModule.moduleName(data.getFile().getNameWithoutExtension()), null);
|
||||
data -> singletonMap(LightJavaModule.moduleName(data.getFile()), null);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.psi.impl.light;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProviders;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.AtomicNotNullLazyValue;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -34,8 +35,12 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -49,7 +54,7 @@ public class LightJavaModule extends LightElement implements PsiJavaModule {
|
||||
private LightJavaModule(@NotNull PsiManager manager, @NotNull VirtualFile jarRoot) {
|
||||
super(manager, JavaLanguage.INSTANCE);
|
||||
myJarRoot = jarRoot;
|
||||
myRefElement = new LightJavaModuleReferenceElement(manager, moduleName(jarRoot.getNameWithoutExtension()));
|
||||
myRefElement = new LightJavaModuleReferenceElement(manager, moduleName(jarRoot));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -253,6 +258,22 @@ public class LightJavaModule extends LightElement implements PsiJavaModule {
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String moduleName(@NotNull VirtualFile jarRoot) {
|
||||
VirtualFile manifest = jarRoot.findFileByRelativePath(JarFile.MANIFEST_NAME);
|
||||
if (manifest != null) {
|
||||
try (InputStream stream = manifest.getInputStream()) {
|
||||
String claimed = new Manifest(stream).getMainAttributes().getValue("Automatic-Module-Name");
|
||||
if (claimed != null) return claimed;
|
||||
}
|
||||
catch (IOException e) {
|
||||
Logger.getInstance(LightJavaModule.class).warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
return moduleName(jarRoot.getNameWithoutExtension());
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a name deriving for automatic modules as described in ModuleFinder.of(Path...) method documentation.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user