Bug 531763 - [9] replace provisional API in JavaModelAccess used by
jdt.debug
Change-Id: I30b3c13839cdae1d13dd0b9943177a15ea6d9af8
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaApplicationLaunchShortcut.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaApplicationLaunchShortcut.java
index f0a921f..f3274b5 100644
--- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaApplicationLaunchShortcut.java
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaApplicationLaunchShortcut.java
@@ -25,12 +25,14 @@
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.provisional.JavaModelAccess;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
@@ -48,12 +50,32 @@
* @since 3.3
*/
public class JavaApplicationLaunchShortcut extends JavaLaunchShortcut {
+ /**
+ * Test if a type is from a location marked as test code (from the perspective of the project where it is defined.)
+ *
+ * @param type
+ * the type that is examined
+ * @return false, if the corresponding class path entry is found and is not marked as test, otherwise true
+ * @throws JavaModelException
+ * when access to the classpath entry corresponding to the given type fails.
+ */
+ private static boolean isTestCode(IType type) throws JavaModelException {
+ IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type.getPackageFragment().getParent();
+ IJavaProject javaProject = packageFragmentRoot.getJavaProject();
+ if (javaProject != null) {
+ IClasspathEntry entry = javaProject.getClasspathEntryFor(packageFragmentRoot.getPath());
+ if (entry != null && !entry.isTest()) {
+ return false;
+ }
+ }
+ return true;
+ }
/**
- * Returns the Java elements corresponding to the given objects. Members are translated
- * to corresponding declaring types where possible.
+ * Returns the Java elements corresponding to the given objects. Members are translated to corresponding declaring types where possible.
*
- * @param objects selected objects
+ * @param objects
+ * selected objects
* @return corresponding Java elements
* @since 3.5
*/
@@ -90,7 +112,7 @@
wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(type.getTypeQualifiedName('.')));
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, type.getFullyQualifiedName());
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, type.getJavaProject().getElementName());
- if (!JavaModelAccess.isTestCode(type)) {
+ if (!isTestCode(type)) {
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_EXCLUDE_TEST_CODE, true);
}
wc.setMappedResources(new IResource[] {type.getUnderlyingResource()});
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractJavaLaunchConfigurationDelegate.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractJavaLaunchConfigurationDelegate.java
index 583cc55..a97cc4d 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractJavaLaunchConfigurationDelegate.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractJavaLaunchConfigurationDelegate.java
@@ -51,7 +51,6 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IModuleDescription;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.provisional.JavaModelAccess;
import org.eclipse.jdt.debug.core.IJavaDebugTarget;
import org.eclipse.jdt.debug.core.IJavaMethodBreakpoint;
import org.eclipse.jdt.debug.core.JDIDebugModel;
@@ -1188,7 +1187,7 @@
// TODO: revisit to examine other possible solutions
IJavaProject project = getJavaProject(configuration);
if (project != null) {
- for (String moduleName : JavaModelAccess.determineModulesOfProjectsWithNonEmptyClasspath(project)) {
+ for (String moduleName : project.determineModulesOfProjectsWithNonEmptyClasspath()) {
if (sb.length() > 0) {
sb.append(' ');
}