diff --git a/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java b/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java index 983d82e69c4f..08739782ecc5 100644 --- a/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java +++ b/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/JavaClassTreeElement.java @@ -1,18 +1,4 @@ -/* - * 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-2020 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.ide.structureView.impl.java; import com.intellij.ide.structureView.StructureViewTreeElement; @@ -44,11 +30,10 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase { @Override @NotNull public Collection getChildrenBase() { - return getClassChildren(); + return getClassChildren(getElement()); } - private Collection getClassChildren() { - final PsiClass aClass = getElement(); + static Collection getClassChildren(PsiClass aClass) { if (aClass == null) return Collections.emptyList(); LinkedHashSet members = getOwnChildren(aClass); diff --git a/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/PsiFieldTreeElement.java b/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/PsiFieldTreeElement.java index 75d1cc2f767b..e8e61e174de3 100644 --- a/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/PsiFieldTreeElement.java +++ b/java/java-structure-view/src/com/intellij/ide/structureView/impl/java/PsiFieldTreeElement.java @@ -1,24 +1,12 @@ -/* - * Copyright 2000-2014 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-2020 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.ide.structureView.impl.java; import com.intellij.ide.structureView.StructureViewTreeElement; import com.intellij.ide.util.treeView.smartTree.SortableTreeElement; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.PsiEnumConstant; +import com.intellij.psi.PsiEnumConstantInitializer; import com.intellij.psi.PsiField; import com.intellij.psi.PsiSubstitutor; import org.jetbrains.annotations.NotNull; @@ -36,6 +24,13 @@ public class PsiFieldTreeElement extends JavaClassTreeElementBase impl @Override @NotNull public Collection getChildrenBase() { + PsiField field = getField(); + if (field instanceof PsiEnumConstant) { + PsiEnumConstantInitializer initializingClass = ((PsiEnumConstant)field).getInitializingClass(); + if (initializingClass != null) { + return JavaClassTreeElement.getClassChildren(initializingClass); + } + } return Collections.emptyList(); } diff --git a/java/java-tests/testData/ide/navigationToolbar/enumMember.java b/java/java-tests/testData/ide/navigationToolbar/enumMember.java new file mode 100644 index 000000000000..2c02e7185db5 --- /dev/null +++ b/java/java-tests/testData/ide/navigationToolbar/enumMember.java @@ -0,0 +1,7 @@ +enum EnumMember { + BAR { + void foo() { + + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/ide/navigationToolbar/simple.java b/java/java-tests/testData/ide/navigationToolbar/simple.java new file mode 100644 index 000000000000..0e861bb5fcf0 --- /dev/null +++ b/java/java-tests/testData/ide/navigationToolbar/simple.java @@ -0,0 +1,5 @@ +class Simple { + public void foo() { + + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/ide/navigationToolbar/JavaNavBarTest.java b/java/java-tests/testSrc/com/intellij/ide/navigationToolbar/JavaNavBarTest.java new file mode 100644 index 000000000000..2ebfe360908f --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/ide/navigationToolbar/JavaNavBarTest.java @@ -0,0 +1,39 @@ +// Copyright 2000-2020 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.ide.navigationToolbar; + +import com.intellij.JavaTestUtil; +import com.intellij.openapi.editor.ex.EditorEx; +import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author yole + */ +public class JavaNavBarTest extends LightJavaCodeInsightFixtureTestCase { + @Override + protected String getTestDataPath() { + return JavaTestUtil.getJavaTestDataPath() + "/ide/navigationToolbar"; + } + + public void testSimple() { + myFixture.configureByFile("simple.java"); + assertNavBarModel("src", "Simple", "foo"); + } + + public void testEnumMember() { + myFixture.configureByFile("enumMember.java"); + assertNavBarModel("src", "EnumMember", "BAR", "foo"); + } + + public void assertNavBarModel(String... expectedItems) { + NavBarModel model = new NavBarModel(myFixture.getProject()); + model.updateModel(((EditorEx)myFixture.getEditor()).getDataContext()); + List items = new ArrayList<>(); + for (int i = 0; i < model.size(); i++) { + items.add(NavBarPresentation.calcPresentableText(model.get(i), false)); + } + assertSameElements(items, expectedItems); + } +}