Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove copied code from JavaModelUtils #1912

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2018 IBM Corporation and others.
* Copyright (c) 2006, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -108,18 +108,14 @@ public ITestKind getKind(String testKindId) {
public static String getContainerTestKindId(IJavaElement element) {
if (element != null) {
IJavaProject project= element.getJavaProject();
if (CoreTestSearchEngine.is50OrHigher(project)) {
if (CoreTestSearchEngine.is18OrHigher(project)) {
if (isRunWithJUnitPlatform(element)) {
return JUNIT4_TEST_KIND_ID;
}
if (CoreTestSearchEngine.hasJUnit5TestAnnotation(project)) {
return JUNIT5_TEST_KIND_ID;
}
}
if (CoreTestSearchEngine.hasJUnit4TestAnnotation(project)) {
return JUNIT4_TEST_KIND_ID;
}
if (isRunWithJUnitPlatform(element)) {
return JUNIT4_TEST_KIND_ID;
}
if (CoreTestSearchEngine.hasJUnit5TestAnnotation(project)) {
return JUNIT5_TEST_KIND_ID;
}
if (CoreTestSearchEngine.hasJUnit4TestAnnotation(project)) {
return JUNIT4_TEST_KIND_ID;
}
}
return JUNIT3_TEST_KIND_ID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -268,49 +268,4 @@ public static void findSuiteMethods(IJavaElement element, Set<IType> result, IPr
SearchParticipant[] participants= new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() };
new SearchEngine().search(suitePattern, participants, scope, requestor, pm);
}


// --- copied from org.eclipse.jdt.internal.corext.util.JavaModelUtil: ---
/**
* @param version1 the first version
* @param version2 the second version
* @return <code>true</code> iff version1 is less than version2
*/
public static boolean isVersionLessThan(String version1, String version2) {
return JavaCore.compareJavaVersions(version1, version2) < 0;
}


public static boolean is50OrHigher(String compliance) {
return !isVersionLessThan(compliance, JavaCore.VERSION_1_5);
}

/**
* Checks if the given project or workspace has source compliance 5.0 or greater.
*
* @param project the project to test or <code>null</code> to test the workspace settings
* @return <code>true</code> if the given project or workspace has source compliance 5.0 or greater.
*/
public static boolean is50OrHigher(IJavaProject project) {
String source= project != null ? project.getOption(JavaCore.COMPILER_SOURCE, true) : JavaCore.getOption(JavaCore.COMPILER_SOURCE);
return is50OrHigher(source);
}

public static boolean is18OrHigher(String compliance) {
return !isVersionLessThan(compliance, JavaCore.VERSION_1_8);
}

/**
* Checks if the given project or workspace has source compliance 1.8 or greater.
*
* @param project the project to test or <code>null</code> to test the workspace settings
* @return <code>true</code> if the given project or workspace has source compliance 1.8 or
* greater.
*/
public static boolean is18OrHigher(IJavaProject project) {
String source= project != null ? project.getOption(JavaCore.COMPILER_SOURCE, true) : JavaCore.getOption(JavaCore.COMPILER_SOURCE);
return is18OrHigher(source);
}
// ---

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2016 IBM Corporation and others.
* Copyright (c) 2007, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -30,7 +30,6 @@

import org.eclipse.jdt.internal.junit.JUnitCorePlugin;
import org.eclipse.jdt.internal.junit.buildpath.BuildPathSupport;
import org.eclipse.jdt.internal.junit.util.JUnitStubUtility;

import org.eclipse.jdt.ui.ISharedImages;
import org.eclipse.jdt.ui.JavaUI;
Expand Down Expand Up @@ -182,10 +181,10 @@ public ClasspathFixProposal[] getFixImportProposals(IJavaProject project, String
}
if (res != 0) {
ArrayList<JUnitClasspathFixProposal> proposals= new ArrayList<>();
if ((res & JUNIT5) != 0 && JUnitStubUtility.is18OrHigher(project)) {
if ((res & JUNIT5) != 0) {
proposals.add(new JUnitClasspathFixProposal(project, 5, 15));
}
if ((res & JUNIT4) != 0 && JUnitStubUtility.is50OrHigher(project)) {
if ((res & JUNIT4) != 0) {
proposals.add(new JUnitClasspathFixProposal(project, 4, 15));
}
if ((res & JUNIT3) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ public final class JUnitMessages extends NLS {

public static String JUnitLaunchConfigurationTab_error_invalidProjectName;

public static String JUnitLaunchConfigurationTab_error_JDK15_required;

public static String JUnitLaunchConfigurationTab_error_JDK18_required;

public static String JUnitLaunchConfigurationTab_error_noContainer;

public static String JUnitLaunchConfigurationTab_error_notJavaProject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ JUnitLaunchConfigurationTab_excludetag_empty_error=Enter a tag to exclude
JUnitContainerWizardPage_error_title=JUnit Library
JUnitContainerWizardPage_combo_label=&JUnit library version:
JUnitLaunchConfigurationTab_error_invalidProjectName=''{0}'' is not a valid project name
JUnitLaunchConfigurationTab_error_JDK15_required=JUnit 4 requires a JDK version of 1.5 or higher
JUnitLaunchConfigurationTab_error_JDK18_required=JUnit 5 requires a JDK version of 1.8 or higher
JUnitContainerWizardPage_wizard_title=JUnit Library
JUnitContainerWizardPage_option_junit3=JUnit 3
JUnitContainerWizardPage_option_junit4=JUnit 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -60,7 +60,6 @@
import org.eclipse.jdt.internal.junit.JUnitCorePlugin;
import org.eclipse.jdt.internal.junit.Messages;
import org.eclipse.jdt.internal.junit.util.ExceptionHandler;
import org.eclipse.jdt.internal.junit.util.JUnitStubUtility;

import org.eclipse.jdt.ui.CodeStyleConfiguration;
import org.eclipse.jdt.ui.ISharedImages;
Expand Down Expand Up @@ -214,10 +213,6 @@ private ImportRewrite getImportRewrite(CompilationUnit astRoot, String typeToImp
}

private boolean isInsideJUnit4Test(IInvocationContext context) {
if (!JUnitStubUtility.is50OrHigher(context.getCompilationUnit().getJavaProject())) {
return false;
}

ASTNode node= context.getCoveringNode();
while (node != null && !(node instanceof BodyDeclaration)) {
node= node.getParent();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -357,22 +357,6 @@ public static boolean isVisible(IMember member, IPackageFragment pack) throws Ja
return (pack != null && otherpack != null && pack.getElementName().equals(otherpack.getElementName()));
}

public static boolean is50OrHigher(IJavaProject project) {
return CoreTestSearchEngine.is50OrHigher(project);
}

public static boolean is50OrHigher(String compliance) {
return CoreTestSearchEngine.is50OrHigher(compliance);
}

public static boolean is18OrHigher(IJavaProject project) {
return CoreTestSearchEngine.is18OrHigher(project);
}

public static boolean is18OrHigher(String compliance) {
return CoreTestSearchEngine.is18OrHigher(compliance);
}

public static String[] getParameterTypeNamesForSeeTag(IMethod overridden) {
try {
ASTParser parser= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -26,13 +26,9 @@ private WizardMessages() {

public static String NewTestCaseWizardPageOne__error_junit4NotOnbuildpath;
public static String NewTestCaseWizardPageOne__error_junit5NotOnbuildpath;
public static String NewTestCaseWizardPageOne_error_java5required;
public static String NewTestCaseWizardPageOne_error_java8required;
public static String NewTestCaseWizardPageOne_junit3_radio_label;
public static String NewTestCaseWizardPageOne_junit4_radio_label;
public static String NewTestCaseWizardPageOne_junit5_radio_label;
public static String NewTestCaseWizardPageOne_linkedtext_java5required;
public static String NewTestCaseWizardPageOne_linkedtext_java8required;
public static String NewTestCaseWizardPageOne_methodStub_setUpBeforeClass;
public static String NewTestCaseWizardPageOne_methodStub_tearDownAfterClass;
public static String NewTestCaseWizardPageOne_not_yet_implemented_string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2000, 2022 IBM Corporation and others.
# Copyright (c) 2000, 2025 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -54,8 +54,6 @@ NewTestCaseWizardPageOne__error_junit5NotOnbuildpath=JUnit 5 library is not on t
NewTestCaseWizardPageOne_error_superclass_is_interface=Superclass is an interface.
NewTestCaseWizardPageOne_error_superclass_not_implementing_test_interface=Superclass does not implement the ''{0}'' interface.
NewTestCaseWizardPageOne_error_superclass_empty=Super class name is empty.
NewTestCaseWizardPageOne_error_java5required=JUnit 4 requires a project with 1.5 compliance or more.
NewTestCaseWizardPageOne_error_java8required=JUnit 5 requires a project with 1.8 compliance or more.
NewTestCaseWizardPageOne_error_class_to_test_not_valid=Class under test is not valid.
NewTestCaseWizardPageOne_error_class_to_test_not_exist=Class under test does not exist in current project.
NewTestCaseWizardPageOne_warning_class_to_test_is_interface=Warning: Class under test ''{0}'' is an interface.
Expand Down Expand Up @@ -150,8 +148,6 @@ UpdateTestSuite_error=Error occurred
UpdateTestSuite_update=Update JUnit Test Suite
UpdateTestSuite_could_not_update=The test suite could not be updated

NewTestCaseWizardPageOne_linkedtext_java5required=JUnit 4 requires a Java 5 project. <a href="c">Configure</a> project compliance and the project build path.
NewTestCaseWizardPageOne_linkedtext_java8required=JUnit 5 requires a Java 8 project. <a href="c">Configure</a> project compliance and the project build path.
NewTestCaseWizardPageOne_not_yet_implemented_string=Not yet implemented
NewTestCaseWizardPageOne_junit3_radio_label=New JUnit &3 test
NewTestCaseWizardPageOne_junit4_radio_label=New JUnit &4 test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -98,14 +98,10 @@
import org.eclipse.jdt.internal.junit.ui.JUnitMessages;
import org.eclipse.jdt.internal.junit.ui.JUnitPlugin;
import org.eclipse.jdt.internal.junit.util.CoreTestSearchEngine;
import org.eclipse.jdt.internal.junit.util.JUnitStubUtility;
import org.eclipse.jdt.internal.junit.util.LayoutUtil;
import org.eclipse.jdt.internal.junit.util.TestSearchEngine;

import org.eclipse.jdt.launching.AbstractVMInstall;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.JavaRuntime;

import org.eclipse.jdt.ui.IJavaElementSearchConstants;
import org.eclipse.jdt.ui.JavaElementComparator;
Expand Down Expand Up @@ -1000,8 +996,6 @@ private void validatePage() {
JUnitPlugin.log(e);
}
}

validateTestLoaderJVM();
}

private void validateJavaProject(IJavaProject javaProject) {
Expand All @@ -1025,33 +1019,6 @@ private void validateJavaProject(IJavaProject javaProject) {

}

private void validateTestLoaderJVM() {
if (fLaunchConfiguration == null)
return;

TestKind testKind= getSelectedTestKind();
if (testKind == null || TestKindRegistry.JUNIT3_TEST_KIND_ID.equals(testKind.getId()))
return;
try {
String path= fLaunchConfiguration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String) null);
if (path != null) {
IVMInstall vm= JavaRuntime.getVMInstall(Path.fromPortableString(path));
if (vm instanceof AbstractVMInstall) {
String compliance= ((AbstractVMInstall) vm).getJavaVersion();
if (compliance != null) {
String testKindId= testKind.getId();
if (TestKindRegistry.JUNIT4_TEST_KIND_ID.equals(testKindId) && !JUnitStubUtility.is50OrHigher(compliance)) {
setErrorMessage(JUnitMessages.JUnitLaunchConfigurationTab_error_JDK15_required);
} else if (TestKindRegistry.JUNIT5_TEST_KIND_ID.equals(testKindId) && !JUnitStubUtility.is18OrHigher(compliance)) {
setErrorMessage(JUnitMessages.JUnitLaunchConfigurationTab_error_JDK18_required);
}
}
}
}
} catch (CoreException e) {
}
}

private void setEnableContainerTestGroup(boolean enabled) {
fContainerSearchButton.setEnabled(enabled);
fContainerText.setEnabled(enabled);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -293,11 +293,7 @@ public void init(IStructuredSelection selection) {
isJunit4= CoreTestSearchEngine.hasJUnit4TestAnnotation(project);
if (!isJunit4) {
if (!CoreTestSearchEngine.hasTestCaseType(project)) {
if (JUnitStubUtility.is18OrHigher(project)) {
isJunit5= true;
} else if (JUnitStubUtility.is50OrHigher(project)) {
isJunit4= true;
}
isJunit5= true;
}
}
}
Expand Down Expand Up @@ -708,28 +704,9 @@ private void updateBuildPathMessage() {
return;
}

String message= null;
IPackageFragmentRoot root= getPackageFragmentRoot();
if (root != null) {
IJavaProject project= root.getJavaProject();
if (project.exists()) {
if (fJUnitVersion == JUnitVersion.VERSION_4) {
if (!JUnitStubUtility.is50OrHigher(project)) {
message= WizardMessages.NewTestCaseWizardPageOne_linkedtext_java5required;
}
} else if (fJUnitVersion == JUnitVersion.VERSION_5) {
if (!JUnitStubUtility.is18OrHigher(project)) {
message= WizardMessages.NewTestCaseWizardPageOne_linkedtext_java8required;
}
}
}
}
fLink.setVisible(message != null);
fImage.setVisible(message != null);
fLink.setVisible(false);
fImage.setVisible(false);

if (message != null) {
fLink.setText(message);
}
}


Expand Down Expand Up @@ -1260,20 +1237,12 @@ protected IStatus validateIfJUnitProject() {
if (fJUnitVersion != null) {
switch (fJUnitVersion) {
case VERSION_5:
if (!JUnitStubUtility.is18OrHigher(project)) {
status.setError(WizardMessages.NewTestCaseWizardPageOne_error_java8required);
return status;
}
if (project.findType(JUnitCorePlugin.JUNIT5_TESTABLE_ANNOTATION_NAME) == null) {
status.setWarning(WizardMessages.NewTestCaseWizardPageOne__error_junit5NotOnbuildpath);
return status;
}
break;
case VERSION_4:
if (!JUnitStubUtility.is50OrHigher(project)) {
status.setError(WizardMessages.NewTestCaseWizardPageOne_error_java5required);
return status;
}
if (project.findType(JUnitCorePlugin.JUNIT4_ANNOTATION_NAME) == null) {
status.setWarning(WizardMessages.NewTestCaseWizardPageOne__error_junit4NotOnbuildpath);
return status;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -193,7 +193,7 @@ public void init(IStructuredSelection selection) {
if (jelem != null && jelem.getElementType() != IJavaElement.JAVA_MODEL) {
IJavaProject project= jelem.getJavaProject();
isJunit4= CoreTestSearchEngine.hasJUnit4TestAnnotation(project);
if (!isJunit4 && !CoreTestSearchEngine.hasTestCaseType(project) && JUnitStubUtility.is50OrHigher(project)) {
if (!isJunit4 && !CoreTestSearchEngine.hasTestCaseType(project)) {
isJunit4= true;
}
isJunit5= CoreTestSearchEngine.hasJUnit5TestAnnotation(project);
Expand Down
Loading
Loading