Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*******************************************************************************
* Copyright (c) 2026 Vector Informatik GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Vector Informatik GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.ui.callhierarchy;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.eclipse.jdt.testplugin.JavaProjectHelper;

import org.eclipse.core.runtime.CoreException;

import org.eclipse.jface.preference.IPreferenceStore;

import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;

import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchyCore;
import org.eclipse.jdt.internal.corext.util.Messages;

import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.ui.tests.core.rules.ProjectTestSetup;

import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;

public class CallHierarchyViewPartContentDescriptionTest {

private static final String SCOPE_DESCRIPTION= JavaSearchScopeFactory.getInstance().getWorkspaceScopeDescription(true);

private static final IPreferenceStore PREFERENCE_STORE= PreferenceConstants.getPreferenceStore();

@Rule
public ProjectTestSetup pts= new ProjectTestSetup();

private IJavaProject fProject;

private CallHierarchyViewPart fViewPart;

@Before
public void setUp() throws CoreException {
fProject= pts.getProject();
IPackageFragmentRoot sourceFolder= JavaProjectHelper.addSourceContainer(fProject, "src");

IPackageFragment pack= sourceFolder.createPackageFragment("org.eclipse.test", false, null);
String str= """
package org.eclipse.test;
public class TestClass {}
""";
ICompilationUnit compilationUnit= pack.createCompilationUnit("TestClass.java", str, false, null);
IType type= compilationUnit.findPrimaryType();

IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
fViewPart= CallHierarchyUI.openView(new IMember[] { type }, window);
}

@After
public void tearDown() throws Exception {
JavaProjectHelper.clear(fProject, pts.getDefaultClasspath());

PREFERENCE_STORE.setToDefault(CallHierarchyCore.PREF_USE_FILTERS);
PREFERENCE_STORE.setToDefault(CallHierarchyCore.PREF_FILTERS_LIST);
PREFERENCE_STORE.setToDefault(CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY);
PREFERENCE_STORE.setToDefault(CallHierarchyCore.PREF_HIDE_TEST_CODE);
}

@Test
public void testContentDescriptionNoFilters() {
assertThat(fViewPart.getContentDescription()).endsWith(SCOPE_DESCRIPTION);
}

@Test
public void testContentDescriptionWithFilterPatterns() {
String filters= "A,B,C";

PREFERENCE_STORE.setValue(CallHierarchyCore.PREF_USE_FILTERS, true);
PREFERENCE_STORE.setValue(CallHierarchyCore.PREF_FILTERS_LIST, filters);

fViewPart.refresh();

String expected= SCOPE_DESCRIPTION + " " + Messages.format(CallHierarchyMessages.CallHierarchyViewPart_scopeDescriptionWithFilters_activeFilters, filters);
assertThat(fViewPart.getContentDescription()).endsWith(expected);
}

@Test
public void testContentDescriptionTestCodeOnly() {
PREFERENCE_STORE.setValue(CallHierarchyCore.PREF_SHOW_TEST_CODE_ONLY, true);

fViewPart.refresh();

String expected= CallHierarchyMessages.CallHierarchyViewPart_scopeDescriptionWithFilters_inTestCode + " " + SCOPE_DESCRIPTION;
assertThat(fViewPart.getContentDescription()).endsWith(expected);
}

@Test
public void testContentDescriptionMainCodeOnly() {
PREFERENCE_STORE.setValue(CallHierarchyCore.PREF_HIDE_TEST_CODE, true);

fViewPart.refresh();

String expected= CallHierarchyMessages.CallHierarchyViewPart_scopeDescriptionWithFilters_inMainCode + " " + SCOPE_DESCRIPTION;
assertThat(fViewPart.getContentDescription()).endsWith(expected);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.eclipse.jdt.ui.tests.core.source.SourceActionTests;

import org.eclipse.jdt.internal.ui.callhierarchy.CallHierarchyViewPartContentDescriptionTest;
import org.eclipse.jdt.internal.ui.callhierarchy.FiltersDialogTest;
import org.eclipse.jdt.internal.ui.compare.JavaIgnoreWhitespaceContributorTest;
import org.eclipse.jdt.internal.ui.compare.JavaTokenComparatorTest;
Expand Down Expand Up @@ -63,7 +64,8 @@
JDTFlagsTest18.class,
JavaTokenComparatorTest.class,
JavaIgnoreWhitespaceContributorTest.class,
FiltersDialogTest.class
FiltersDialogTest.class,
CallHierarchyViewPartContentDescriptionTest.class
})
public class CoreTestSuite {
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ private CallHierarchyMessages() {
public static String CallHierarchyViewPart_callsFromMembers_2;
public static String CallHierarchyViewPart_callsFromMembers_more;
public static String CallHierarchyViewPart_callsFromMethod;
public static String CallHierarchyViewPart_scopeDescriptionWithFilters_inMainCode;
public static String CallHierarchyViewPart_scopeDescriptionWithFilters_inTestCode;
public static String CallHierarchyViewPart_scopeDescriptionWithFilters_activeFilters;
public static String ExpandWithConstructorsConfigurationBlock_description;
public static String ExpandWithConstructorsConfigurationBlock_newType_button;
public static String ExpandWithConstructorsConfigurationBlock_newMember_button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ CallHierarchyViewPart_callsFromConstructors=Calls from constructors of ''{0}'' -
CallHierarchyViewPart_callsFromMembers_2=Calls from ''{0}'', ''{1}'' - in {2}
CallHierarchyViewPart_callsFromMembers_more=Calls from ''{0}'', ''{1}'', ... - in {2}
CallHierarchyViewPart_callsFromMethod=Calls from ''{0}'' - in {1}
CallHierarchyViewPart_scopeDescriptionWithFilters_inMainCode=main code of
CallHierarchyViewPart_scopeDescriptionWithFilters_inTestCode=test code of
CallHierarchyViewPart_scopeDescriptionWithFilters_activeFilters=(filter patterns: ''{0}'')
FocusOnSelectionAction_focusOnSelection_text=Fo&cus On Selection
FocusOnSelectionAction_focusOnSelection_description=Focus On Selection
FocusOnSelectionAction_focusOnSelection_tooltip=Focus On Selection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.StringJoiner;

import org.eclipse.help.IContextProvider;

Expand Down Expand Up @@ -1165,12 +1166,11 @@ private int getIncludeMask() {
*/
private String computeContentDescription(int includeMask) {
// see also HistoryAction.getElementLabel(IMember[])
String scopeDescription= fSearchScopeActions.getFullDescription(includeMask);

String scopeDescriptionWithFilters= computeScopeDescriptionWithFilters(includeMask);
if (fInputElements.length == 1) {
IMember element= fInputElements[0];
String elementName= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT);
String[] args= new String[] { elementName, scopeDescription };
String[] args= new String[] { elementName, scopeDescriptionWithFilters };
if (fCurrentCallMode == CALL_MODE_CALLERS) {
switch (element.getElementType()) {
case IJavaElement.TYPE:
Expand Down Expand Up @@ -1209,11 +1209,11 @@ private String computeContentDescription(int includeMask) {
return null;
case 2:
return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToMembers_2,
new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescription });
new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescriptionWithFilters });

default:
return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsToMembers_more,
new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescription });
new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescriptionWithFilters });
}
} else {
switch (fInputElements.length) {
Expand All @@ -1222,16 +1222,33 @@ private String computeContentDescription(int includeMask) {
return null;
case 2:
return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsFromMembers_2,
new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescription });
new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescriptionWithFilters });

default:
return Messages.format(CallHierarchyMessages.CallHierarchyViewPart_callsFromMembers_more,
new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescription });
new String[] { getShortLabel(fInputElements[0]), getShortLabel(fInputElements[1]), scopeDescriptionWithFilters });
}
}
}
}

private String computeScopeDescriptionWithFilters(int includeMask) {
StringJoiner joiner= new StringJoiner(" "); //$NON-NLS-1$
if (CallHierarchy.getDefault().isHideTestCode()) {
joiner.add(CallHierarchyMessages.CallHierarchyViewPart_scopeDescriptionWithFilters_inMainCode);
} else if (CallHierarchy.getDefault().isShowTestCode()) {
joiner.add(CallHierarchyMessages.CallHierarchyViewPart_scopeDescriptionWithFilters_inTestCode);
}
joiner.add(fSearchScopeActions.getFullDescription(includeMask));
if (CallHierarchy.getDefault().isFilterEnabled()) {
String filters= CallHierarchy.getDefault().getFilters().trim();
if (!filters.isEmpty()) {
joiner.add(Messages.format(CallHierarchyMessages.CallHierarchyViewPart_scopeDescriptionWithFilters_activeFilters, filters));
Comment thread
r-mennig marked this conversation as resolved.
}
}
return joiner.toString();
}

private static String getShortLabel(IMember member) {
return JavaElementLabels.getElementLabel(member, 0L);
}
Expand Down