Commit 7f14bdea authored by Roman Shevchenko's avatar Roman Shevchenko
Browse files

[java] fixes module-info.class -> .java navigation in libraries

parent b3522362
Showing with 13 additions and 19 deletions
+13 -19
......@@ -21,6 +21,7 @@ import com.intellij.openapi.roots.impl.LibraryScopeCache;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.jrt.JrtFileSystem;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
......@@ -40,6 +41,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
/**
......@@ -103,6 +105,7 @@ public class JavaPsiImplementationHelperImpl extends JavaPsiImplementationHelper
@Override
public PsiElement getClsFileNavigationElement(@NotNull PsiJavaFile clsFile) {
Function<VirtualFile, VirtualFile> finder = null;
Predicate<PsiFile> filter = null;
PsiClass[] classes = clsFile.getClasses();
if (classes.length > 0) {
......@@ -110,12 +113,17 @@ public class JavaPsiImplementationHelperImpl extends JavaPsiImplementationHelper
String packageName = clsFile.getPackageName();
String relativePath = packageName.isEmpty() ? sourceFileName : packageName.replace('.', '/') + '/' + sourceFileName;
finder = root -> root.findFileByRelativePath(relativePath);
filter = PsiClassOwner.class::isInstance;
}
else {
PsiJavaModule module = clsFile.getModuleDeclaration();
if (module != null) {
String moduleName = module.getName();
finder = root -> moduleName.equals(root.getName()) ? root.findChild(PsiJavaModule.MODULE_INFO_FILE) : null;
finder = root -> !JrtFileSystem.isModuleRoot(root) || moduleName.equals(root.getName()) ? root.findChild(PsiJavaModule.MODULE_INFO_FILE) : null;
filter = psi -> {
PsiJavaModule candidate = psi instanceof PsiJavaFile ? ((PsiJavaFile)psi).getModuleDeclaration() : null;
return candidate != null && moduleName.equals(candidate.getName());
};
}
}
......@@ -124,8 +132,8 @@ public class JavaPsiImplementationHelperImpl extends JavaPsiImplementationHelper
return findSourceRoots(clsFile.getContainingFile().getVirtualFile())
.map(finder)
.filter(source -> source != null && source.isValid())
.map(clsFile.getManager()::findFile)
.filter(PsiClassOwner.class::isInstance)
.map(PsiManager.getInstance(myProject)::findFile)
.filter(filter)
.findFirst()
.orElse(clsFile);
}
......
/*
* 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.
* 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.
*/
// Copyright 2000-2018 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.
package com.intellij.psi.impl.compiled;
import com.intellij.navigation.ItemPresentation;
......@@ -171,7 +157,7 @@ public class ClsJavaModuleImpl extends ClsRepositoryPsiElement<PsiJavaModuleStub
}
}
return getNameIdentifier();
return this;
}
@Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment