Skip to content

Commit edd6abc

Browse files
committed
Add check for release < JRE in JavaSearchPage
- modify JavaSearchPage.updateOKStatus() to check if release set is less than the default JRE in which case, issue a warning message on the page - fixes eclipse-jdt#2017
1 parent 3965fae commit edd6abc

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/JavaSearchPage.java

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.internal.ui.search;
1515

16+
import java.text.MessageFormat;
1617
import java.util.ArrayList;
1718
import java.util.List;
1819

@@ -78,6 +79,9 @@
7879

7980
import org.eclipse.jdt.internal.corext.util.Messages;
8081

82+
import org.eclipse.jdt.launching.IVMInstall2;
83+
import org.eclipse.jdt.launching.JavaRuntime;
84+
8185
import org.eclipse.jdt.ui.search.ElementQuerySpecification;
8286
import org.eclipse.jdt.ui.search.PatternQuerySpecification;
8387
import org.eclipse.jdt.ui.search.QuerySpecification;
@@ -283,6 +287,7 @@ public static SearchPatternData create(IDialogSettings settings) {
283287
private Button[] fLimitTo;
284288
private Button[] fIncludeMasks;
285289
private Group fLimitToGroup;
290+
private Label fMessageLabel;
286291

287292
private int fMatchLocations;
288293
private Link fMatchLocationsLink;
@@ -540,6 +545,9 @@ public void createControl(Composite parent) {
540545
Control includeMask= createIncludeMask(result);
541546
includeMask.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));
542547

548+
Control messageLabel= createMessageLabel(result);
549+
messageLabel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1));
550+
543551
//createParticipants(result);
544552

545553
SelectionAdapter javaElementInitializer= new SelectionAdapter() {
@@ -588,6 +596,18 @@ public void widgetSelected(SelectionEvent e) {
588596
}*/
589597

590598

599+
private Control createMessageLabel(Composite parent) {
600+
Composite result= new Composite(parent, SWT.NONE);
601+
GridLayout layout= new GridLayout(1, false);
602+
layout.marginWidth= 5;
603+
layout.marginHeight= 5;
604+
result.setLayout(layout);
605+
606+
fMessageLabel= new Label(result, SWT.NONE);
607+
fMessageLabel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 1, 1));
608+
return result;
609+
}
610+
591611
private Control createExpression(Composite parent) {
592612
Composite result= new Composite(parent, SWT.NONE);
593613
GridLayout layout= new GridLayout(2, false);
@@ -637,6 +657,20 @@ public void widgetSelected(SelectionEvent e) {
637657
final void updateOKStatus() {
638658
boolean isValidPattern= isValidSearchPattern();
639659
boolean isValidMask= getIncludeMask() != 0;
660+
fMessageLabel.setText(""); //$NON-NLS-1$
661+
if ((getIncludeMask() & JavaSearchScopeFactory.JRE) != 0) {
662+
String release= JavaCore.getOption(JavaCore.COMPILER_RELEASE);
663+
if (release.equals(JavaCore.ENABLED)) {
664+
String compliance= JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE);
665+
if (compliance != null) {
666+
if (JavaRuntime.getVMInstall(JavaRuntime.newDefaultJREContainerPath()) instanceof IVMInstall2 jreInstall) {
667+
if (JavaCore.compareJavaVersions(compliance, jreInstall.getJavaVersion()) < 0) {
668+
fMessageLabel.setText(MessageFormat.format(SearchMessages.JavaSearchPage_release_warning_message, compliance, jreInstall.getJavaVersion()));
669+
}
670+
}
671+
}
672+
}
673+
}
640674
getContainer().setPerformActionEnabled(isValidPattern && isValidMask);
641675
}
642676

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -154,6 +154,7 @@ private SearchMessages() {
154154
public static String JavaSearchPage_match_location_link_label;
155155
public static String JavaSearchPage_match_location_link_label_tooltip;
156156
public static String JavaSearchPage_match_locations_label;
157+
public static String JavaSearchPage_release_warning_message;
157158
public static String JavaElementAction_typeSelectionDialog_title;
158159
public static String JavaElementAction_typeSelectionDialog_message;
159160
public static String JavaElementAction_error_open_message;

org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/search/SearchMessages.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2000, 2022 IBM Corporation and others.
2+
# Copyright (c) 2000, 2025 IBM Corporation and others.
33
#
44
# This program and the accompanying materials
55
# are made available under the terms of the Eclipse Public License 2.0
@@ -157,6 +157,7 @@ JavaSearchOperation_pluralOccurrencesPostfix=''{0}'' - {1} occurrences in {2}
157157
JavaSearchPage_match_location_link_label=(<a>{0} of {1} selected</a>)
158158
JavaSearchPage_match_location_link_label_tooltip=Configure the selected match locations
159159
JavaSearchPage_match_locations_label=M&atch locations
160+
JavaSearchPage_release_warning_message=Warning: cannot reliably get source code for release {0} from JRE {1}
160161
JavaElementAction_typeSelectionDialog_title=Search
161162
JavaElementAction_typeSelectionDialog_message=&Select the type to search:
162163
JavaElementAction_error_open_message=An exception occurred while opening the type.

0 commit comments

Comments
 (0)