mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] navigation, presentation, and "go to symbol" provider for modules
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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 com.intellij.ide.util.gotoByName
|
||||
|
||||
import com.intellij.navigation.ChooseByNameContributor
|
||||
import com.intellij.navigation.NavigationItem
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.impl.java.stubs.index.JavaModuleNameIndex
|
||||
import com.intellij.psi.search.ProjectScope
|
||||
import com.intellij.util.ArrayUtil
|
||||
|
||||
class JavaModuleNavigationContributor : ChooseByNameContributor {
|
||||
private val index = JavaModuleNameIndex.getInstance()
|
||||
|
||||
override fun getNames(project: Project, includeNonProjectItems: Boolean): Array<out String> {
|
||||
val result = index.getAllKeys(project)
|
||||
return if (result.isEmpty()) ArrayUtil.EMPTY_STRING_ARRAY else result.toTypedArray()
|
||||
}
|
||||
|
||||
override fun getItemsByName(name: String, pattern: String, project: Project, includeNonProjectItems: Boolean): Array<out NavigationItem> {
|
||||
val scope = if (includeNonProjectItems) ProjectScope.getAllScope(project) else ProjectScope.getProjectScope(project)
|
||||
val result = index.get(name, project, scope)
|
||||
return if (result.isEmpty()) NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY else result.toTypedArray()
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
*
|
||||
* @since 2016.3
|
||||
*/
|
||||
public interface PsiJavaModule extends PsiElement {
|
||||
public interface PsiJavaModule extends NavigatablePsiElement {
|
||||
String MODULE_INFO_CLASS = "module-info";
|
||||
String MODULE_INFO_FILE = MODULE_INFO_CLASS + ".java";
|
||||
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.compiled;
|
||||
|
||||
import com.intellij.psi.JavaElementVisitor;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiJavaModule;
|
||||
import com.intellij.psi.PsiJavaModuleReference;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProviders;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.java.stubs.PsiJavaModuleStub;
|
||||
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.impl.source.tree.JavaElementType;
|
||||
@@ -56,6 +55,22 @@ public class ClsJavaModuleImpl extends ClsRepositoryPsiElement<PsiJavaModuleStub
|
||||
setMirror(getNameElement(), SourceTreeToPsiMap.<PsiJavaModule>treeToPsiNotNull(element).getNameElement());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getModuleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemPresentation getPresentation() {
|
||||
return ItemPresentationProviders.getItemPresentation(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getNavigationElement() {
|
||||
return getNameElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JavaElementVisitor) {
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
package com.intellij.psi.impl.source;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.JavaElementVisitor;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.psi.PsiJavaModule;
|
||||
import com.intellij.psi.PsiJavaModuleReference;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProviders;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.java.stubs.JavaStubElementTypes;
|
||||
import com.intellij.psi.impl.java.stubs.PsiJavaModuleStub;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -51,6 +50,22 @@ public class PsiJavaModuleImpl extends JavaStubPsiElement<PsiJavaModuleStub> imp
|
||||
return getNameElement().getReferenceText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getModuleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemPresentation getPresentation() {
|
||||
return ItemPresentationProviders.getItemPresentation(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getNavigationElement() {
|
||||
return getNameElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (visitor instanceof JavaElementVisitor) {
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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 com.intellij.psi.presentation.java;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProvider;
|
||||
import com.intellij.psi.PsiJavaModule;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class JavaModulePresentationProvider implements ItemPresentationProvider<PsiJavaModule> {
|
||||
@Override
|
||||
public ItemPresentation getPresentation(@NotNull final PsiJavaModule item) {
|
||||
return new ItemPresentation() {
|
||||
@Nullable
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return item.getModuleName();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getLocationString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Icon getIcon(boolean unused) {
|
||||
return AllIcons.FileTypes.Java;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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 com.intellij.navigation
|
||||
|
||||
import com.intellij.ide.util.gotoByName.GotoSymbolModel2
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
|
||||
class ModuleNavigationTest : LightCodeInsightFixtureTestCase() {
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = JAVA_9
|
||||
|
||||
fun testNavigation() {
|
||||
val file = myFixture.configureByText("module-info.java", "module my.mod.name { }")
|
||||
(file as PsiJavaFile).moduleDeclaration!!.navigate(true)
|
||||
assertThat(myFixture.editor.caretModel.offset).isEqualTo(file.text.indexOf("my.mod.name"))
|
||||
}
|
||||
|
||||
fun testGoToSymbol() {
|
||||
val file = myFixture.configureByText("module-info.java", "module my.mod.name { }")
|
||||
val items = GotoSymbolModel2(myFixture.project).getElementsByName("my.mod.name", false, "my.mod")
|
||||
assertThat(items).containsExactly((file as PsiJavaFile).moduleDeclaration!!)
|
||||
}
|
||||
}
|
||||
@@ -1464,6 +1464,7 @@
|
||||
|
||||
<gotoClassContributor implementation="com.intellij.ide.util.gotoByName.DefaultClassNavigationContributor"/>
|
||||
<gotoSymbolContributor implementation="com.intellij.ide.util.gotoByName.DefaultSymbolNavigationContributor"/>
|
||||
<gotoSymbolContributor implementation="com.intellij.ide.util.gotoByName.JavaModuleNavigationContributor"/>
|
||||
<scopeTreeExpander implementation="com.intellij.ide.scopeView.ClassesScopeTreeStructureExpander"/>
|
||||
<lang.implementationTextSelectioner language="JAVA"
|
||||
implementationClass="com.intellij.codeInsight.hint.JavaImplementationTextSelectioner"/>
|
||||
@@ -1652,6 +1653,8 @@
|
||||
implementationClass="com.intellij.psi.presentation.java.VariablePresentationProvider"/>
|
||||
<itemPresentationProvider forClass="com.intellij.psi.PsiParameter"
|
||||
implementationClass="com.intellij.psi.presentation.java.VariablePresentationProvider"/>
|
||||
<itemPresentationProvider forClass="com.intellij.psi.PsiJavaModule"
|
||||
implementationClass="com.intellij.psi.presentation.java.JavaModulePresentationProvider"/>
|
||||
|
||||
<iconLayerProvider implementation="com.intellij.compiler.CompilerIconLayerProvider"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user