Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 54117 | Differences between
and this patch

Collapse All | Expand All

(-).project (-10 / +2 lines)
Lines 3-25 Link Here
3
	<name>org.eclipse.jdt.debug.ui</name>
3
	<name>org.eclipse.jdt.debug.ui</name>
4
	<comment></comment>
4
	<comment></comment>
5
	<projects>
5
	<projects>
6
		<project>org.eclipse.compare</project>
6
		<project>EBay</project>
7
		<project>org.eclipse.core.resources</project>
7
		<project>org.eclipse.core.expressions</project>
8
		<project>org.eclipse.core.runtime.compatibility</project>
9
		<project>org.eclipse.core.variables</project>
8
		<project>org.eclipse.core.variables</project>
10
		<project>org.eclipse.debug.core</project>
9
		<project>org.eclipse.debug.core</project>
11
		<project>org.eclipse.debug.ui</project>
10
		<project>org.eclipse.debug.ui</project>
12
		<project>org.eclipse.jdt.core</project>
13
		<project>org.eclipse.jdt.debug</project>
11
		<project>org.eclipse.jdt.debug</project>
14
		<project>org.eclipse.jdt.launching</project>
12
		<project>org.eclipse.jdt.launching</project>
15
		<project>org.eclipse.jdt.ui</project>
16
		<project>org.eclipse.jface.text</project>
13
		<project>org.eclipse.jface.text</project>
17
		<project>org.eclipse.search</project>
14
		<project>org.eclipse.search</project>
18
		<project>org.eclipse.ui</project>
19
		<project>org.eclipse.ui.editors</project>
20
		<project>org.eclipse.ui.ide</project>
21
		<project>org.eclipse.ui.views</project>
22
		<project>org.eclipse.ui.workbench.texteditor</project>
23
	</projects>
15
	</projects>
24
	<buildSpec>
16
	<buildSpec>
25
		<buildCommand>
17
		<buildCommand>
(-)plugin.xml (-22 / +50 lines)
Lines 22-27 Link Here
22
      <import plugin="org.eclipse.ui"/>
22
      <import plugin="org.eclipse.ui"/>
23
      <import plugin="org.eclipse.core.resources"/>
23
      <import plugin="org.eclipse.core.resources"/>
24
      <import plugin="org.eclipse.core.variables"/>
24
      <import plugin="org.eclipse.core.variables"/>
25
      <import plugin="org.eclipse.core.expressions"/>
25
      <import plugin="org.eclipse.jdt.core"/>
26
      <import plugin="org.eclipse.jdt.core"/>
26
      <import plugin="org.eclipse.search"/>
27
      <import plugin="org.eclipse.search"/>
27
      <import plugin="org.eclipse.debug.core"/>
28
      <import plugin="org.eclipse.debug.core"/>
Lines 38-43 Link Here
38
   <extension-point id="vmInstallTypePage" name="%vmInstallTypePage" schema="schema/vmInstallTypePage.exsd"/>
39
   <extension-point id="vmInstallTypePage" name="%vmInstallTypePage" schema="schema/vmInstallTypePage.exsd"/>
39
40
40
<!-- Extensions -->
41
<!-- Extensions -->
42
   <extension point="org.eclipse.core.expressions.propertyTesters">
43
      <propertyTester
44
      		namespace="org.eclipse.jdt.debug.ui"
45
            properties="hasMainType, isApplet"
46
            type="org.eclipse.core.resources.IResource"
47
            class="org.eclipse.jdt.internal.debug.ui.launcher.ResourceExtender"
48
            id="org.eclipse.jdt.debug.IResourceExtender">
49
      </propertyTester>
50
   </extension>
41
   <extension
51
   <extension
42
         point="org.eclipse.debug.core.watchExpressionDelegates">
52
         point="org.eclipse.debug.core.watchExpressionDelegates">
43
         <watchExpressionDelegate
53
         <watchExpressionDelegate
Lines 1904-1922 Link Here
1904
            icon="icons/full/ctool16/java_app.gif"
1914
            icon="icons/full/ctool16/java_app.gif"
1905
            helpContextId="org.eclipse.jdt.debug.ui.shortcut_local_java_application"
1915
            helpContextId="org.eclipse.jdt.debug.ui.shortcut_local_java_application"
1906
            modes="run, debug"
1916
            modes="run, debug"
1907
            nameFilter="*.java"
1908
            filterClass="org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut"
1909
            class="org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut"
1917
            class="org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut"
1910
            id="org.eclipse.jdt.debug.ui.localJavaShortcut">
1918
            id="org.eclipse.jdt.debug.ui.localJavaShortcut">
1911
         <contextLabel
1919
         <contextualLaunch>
1912
         	mode="run"
1920
           <enablement>
1913
         	label="%ContextualRunJavaApplication.label"/>
1921
             <with variable="selection">
1914
  		 <contextLabel
1922
               <count value="1"/>
1915
  		 	mode="debug"
1923
               <iterate>
1916
  		 	label="%ContextualDebugJavaApplication.label"/>
1924
                 <or>
1917
         <filter
1925
                   <test property="org.eclipse.debug.ui.matchesPattern" value="*.java"/>
1918
         	name="ContextualLaunchActionFilter"
1926
                   <test property="org.eclipse.debug.ui.matchesPattern" value="*.class"/>
1919
         	value="supportsContextualLaunch"/>
1927
                 </or>
1928
                 <test property="org.eclipse.jdt.debug.ui.hasMainType"/>
1929
               </iterate>
1930
             </with>
1931
           </enablement>
1932
           <contextLabel
1933
         	  mode="run"
1934
         	  label="%ContextualRunJavaApplication.label"/>
1935
  		   <contextLabel
1936
  		 	  mode="debug"
1937
  		 	  label="%ContextualDebugJavaApplication.label"/>
1938
  		 </contextualLaunch>
1920
         <perspective
1939
         <perspective
1921
               id="org.eclipse.jdt.ui.JavaPerspective">
1940
               id="org.eclipse.jdt.ui.JavaPerspective">
1922
         </perspective>
1941
         </perspective>
Lines 1935-1953 Link Here
1935
            icon="icons/full/ctool16/java_applet.gif"
1954
            icon="icons/full/ctool16/java_applet.gif"
1936
            helpContextId="org.eclipse.jdt.debug.ui.shortcut_java_applet"
1955
            helpContextId="org.eclipse.jdt.debug.ui.shortcut_java_applet"
1937
            modes="run, debug"
1956
            modes="run, debug"
1938
            nameFilter="*.java"
1939
            filterClass="org.eclipse.jdt.internal.debug.ui.launcher.JavaAppletLaunchShortcut"
1940
            class="org.eclipse.jdt.internal.debug.ui.launcher.JavaAppletLaunchShortcut"
1957
            class="org.eclipse.jdt.internal.debug.ui.launcher.JavaAppletLaunchShortcut"
1941
            id="org.eclipse.jdt.debug.ui.javaAppletShortcut">
1958
            id="org.eclipse.jdt.debug.ui.javaAppletShortcut">
1942
         <filter
1959
         <contextualLaunch>
1943
         	name="ContextualLaunchActionFilter"
1960
           <enablement>
1944
         	value="supportsContextualLaunch"/>
1961
             <with variable="selection">
1945
         <contextLabel
1962
               <count value="1"/>
1946
         	mode="run"
1963
               <iterate>
1947
         	label="%ContextualRunJavaApplet.label"/>
1964
                 <or>
1948
  		 <contextLabel
1965
                   <test property="org.eclipse.debug.ui.matchesPattern" value="*.java"/>
1949
  		 	mode="debug"
1966
                   <test property="org.eclipse.debug.ui.matchesPattern" value="*.class"/>
1950
  		 	label="%ContextualDebugJavaApplet.label"/>
1967
                 </or>
1968
                 <test property="org.eclipse.jdt.debug.ui.isApplet"/>
1969
               </iterate>
1970
             </with>
1971
           </enablement>
1972
           <contextLabel
1973
         	  mode="run"
1974
         	  label="%ContextualRunJavaApplet.label"/>
1975
  		   <contextLabel
1976
  		 	  mode="debug"
1977
  		 	  label="%ContextualDebugJavaApplet.label"/>
1978
  		 </contextualLaunch>
1951
         <perspective
1979
         <perspective
1952
               id="org.eclipse.jdt.ui.JavaPerspective">
1980
               id="org.eclipse.jdt.ui.JavaPerspective">
1953
         </perspective>
1981
         </perspective>
(-).externalToolBuilders/Build Snippet Support JAR.launch (+3 lines)
Lines 1-9 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
2
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
3
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
4
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
3
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;launchConfigurationWorkingSet factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;workingSet&quot; editPageId=&quot;org.eclipse.ui.resourceWorkingSetPage&quot;&gt;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.jdt.debug.ui/Snippet Support&quot; type=&quot;2&quot;/&gt;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.jdt.debug.ui/scripts/buildExtraJAR.xml&quot; type=&quot;1&quot;/&gt;&#10;&lt;/launchConfigurationWorkingSet&gt;&#10;}"/>
5
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;launchConfigurationWorkingSet factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;workingSet&quot; editPageId=&quot;org.eclipse.ui.resourceWorkingSetPage&quot;&gt;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.jdt.debug.ui/Snippet Support&quot; type=&quot;2&quot;/&gt;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.jdt.debug.ui/scripts/buildExtraJAR.xml&quot; type=&quot;1&quot;/&gt;&#10;&lt;/launchConfigurationWorkingSet&gt;&#10;}"/>
4
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
6
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
5
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;launchConfigurationWorkingSet factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;workingSet&quot;&gt;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.jdt.debug.ui&quot; type=&quot;4&quot;/&gt;&#10;&lt;/launchConfigurationWorkingSet&gt;&#10;}"/>
7
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;launchConfigurationWorkingSet factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; name=&quot;workingSet&quot;&gt;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.jdt.debug.ui&quot; type=&quot;4&quot;/&gt;&#10;&lt;/launchConfigurationWorkingSet&gt;&#10;}"/>
6
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.jdt.debug.ui/scripts/buildExtraJAR.xml}"/>
8
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.jdt.debug.ui/scripts/buildExtraJAR.xml}"/>
7
<booleanAttribute key="org.eclipse.debug.ui.ATTR_RUN_IN_BACKGROUND" value="false"/>
9
<booleanAttribute key="org.eclipse.debug.ui.ATTR_RUN_IN_BACKGROUND" value="false"/>
10
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
8
<stringAttribute key="org.eclipse.debug.ui.target_run_perspective" value="perspective_none"/>
11
<stringAttribute key="org.eclipse.debug.ui.target_run_perspective" value="perspective_none"/>
9
</launchConfiguration>
12
</launchConfiguration>
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaAppletLaunchShortcut.java (-50 / +2 lines)
Lines 13-25 Link Here
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Collections;
15
import java.util.Collections;
16
import java.util.HashSet;
17
import java.util.List;
16
import java.util.List;
18
import java.util.Set;
19
17
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.debug.core.DebugPlugin;
19
import org.eclipse.debug.core.DebugPlugin;
24
import org.eclipse.debug.core.ILaunchConfiguration;
20
import org.eclipse.debug.core.ILaunchConfiguration;
25
import org.eclipse.debug.core.ILaunchConfigurationType;
21
import org.eclipse.debug.core.ILaunchConfigurationType;
Lines 27-41 Link Here
27
import org.eclipse.debug.core.ILaunchManager;
23
import org.eclipse.debug.core.ILaunchManager;
28
import org.eclipse.debug.ui.DebugUITools;
24
import org.eclipse.debug.ui.DebugUITools;
29
import org.eclipse.debug.ui.IDebugModelPresentation;
25
import org.eclipse.debug.ui.IDebugModelPresentation;
30
import org.eclipse.debug.ui.ILaunchFilter;
31
import org.eclipse.debug.ui.ILaunchShortcut;
26
import org.eclipse.debug.ui.ILaunchShortcut;
32
import org.eclipse.jdt.core.IJavaElement;
27
import org.eclipse.jdt.core.IJavaElement;
33
import org.eclipse.jdt.core.IType;
28
import org.eclipse.jdt.core.IType;
34
import org.eclipse.jdt.core.JavaModelException;
35
import org.eclipse.jdt.debug.ui.JavaUISourceLocator;
29
import org.eclipse.jdt.debug.ui.JavaUISourceLocator;
36
import org.eclipse.jdt.debug.ui.launchConfigurations.AppletParametersTab;
30
import org.eclipse.jdt.debug.ui.launchConfigurations.AppletParametersTab;
37
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
31
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
38
import org.eclipse.jdt.internal.debug.ui.console.StringMatcher;
39
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
32
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
40
import org.eclipse.jdt.ui.JavaElementLabelProvider;
33
import org.eclipse.jdt.ui.JavaElementLabelProvider;
41
import org.eclipse.jface.dialogs.MessageDialog;
34
import org.eclipse.jface.dialogs.MessageDialog;
Lines 51-57 Link Here
51
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
44
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
52
import org.eclipse.ui.editors.text.WorkspaceOperationRunner;
45
import org.eclipse.ui.editors.text.WorkspaceOperationRunner;
53
46
54
public class JavaAppletLaunchShortcut implements ILaunchShortcut, ILaunchFilter {
47
public class JavaAppletLaunchShortcut implements ILaunchShortcut {
55
48
56
	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
49
	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
57
50
Lines 268-313 Link Here
268
		}
261
		}
269
		return (IStructuredSelection)selection;
262
		return (IStructuredSelection)selection;
270
	}
263
	}
271
	/* (non-Javadoc)
264
272
	 * @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String)
273
	 */
274
	public boolean testAttribute(IResource target, String name, String value) {
275
		if ("ContextualLaunchActionFilter".equals(name)) { //$NON-NLS-1$
276
			return isApplet(target);
277
		} else if ("NameMatches".equals(name)) { //$NON-NLS-1$
278
			return nameMatches(target, value);
279
		}
280
		return false;
281
	}
282
	/**
283
	 * Test if the name of the target resource matches a pattern.
284
	 * 
285
	 * @param target selected resource from workspace
286
	 * @param value regular expression pattern to test
287
	 * @return true if the pattern matches the resource name, false otherwise
288
	 */
289
	private boolean nameMatches(IResource resource, String pattern) {
290
		String filename = resource.getName();
291
		StringMatcher sm = new StringMatcher(pattern, true, false);
292
		return sm.match(filename);
293
	}
294
	/**
295
	 * Check if the specified resource is an Applet.
296
	 * @return <code>true</code> if the target resource is an Applet,
297
	 * <code>false</code> otherwise.
298
	 */
299
	private boolean isApplet(IResource resource) {
300
		if (resource != null) {
301
			try {
302
				Set result= new HashSet();
303
				AppletLaunchConfigurationUtils.collectTypes(resource, new NullProgressMonitor(), result);
304
				if (result.size() > 0) {
305
					return true;
306
				}
307
			} catch (JavaModelException e) {
308
				return false;
309
			}
310
		}
311
		return false;
312
	}
313
}
265
}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaApplicationLaunchShortcut.java (-67 / +1 lines)
Lines 16-22 Link Here
16
import java.util.Collections;
16
import java.util.Collections;
17
import java.util.List;
17
import java.util.List;
18
18
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.DebugPlugin;
Lines 26-46 Link Here
26
import org.eclipse.debug.core.ILaunchManager;
25
import org.eclipse.debug.core.ILaunchManager;
27
import org.eclipse.debug.ui.DebugUITools;
26
import org.eclipse.debug.ui.DebugUITools;
28
import org.eclipse.debug.ui.IDebugModelPresentation;
27
import org.eclipse.debug.ui.IDebugModelPresentation;
29
import org.eclipse.debug.ui.ILaunchFilter;
30
import org.eclipse.debug.ui.ILaunchShortcut;
28
import org.eclipse.debug.ui.ILaunchShortcut;
31
import org.eclipse.jdt.core.IClassFile;
32
import org.eclipse.jdt.core.ICompilationUnit;
33
import org.eclipse.jdt.core.IJavaElement;
29
import org.eclipse.jdt.core.IJavaElement;
34
import org.eclipse.jdt.core.IType;
30
import org.eclipse.jdt.core.IType;
35
import org.eclipse.jdt.core.JavaCore;
36
import org.eclipse.jdt.core.JavaModelException;
37
import org.eclipse.jdt.core.Signature;
38
import org.eclipse.jdt.core.search.IJavaSearchScope;
31
import org.eclipse.jdt.core.search.IJavaSearchScope;
39
import org.eclipse.jdt.core.search.SearchEngine;
32
import org.eclipse.jdt.core.search.SearchEngine;
40
import org.eclipse.jdt.debug.ui.JavaUISourceLocator;
33
import org.eclipse.jdt.debug.ui.JavaUISourceLocator;
41
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
42
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
34
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
43
import org.eclipse.jdt.internal.debug.ui.console.StringMatcher;
44
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
35
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
45
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
36
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
46
import org.eclipse.jface.dialogs.ErrorDialog;
37
import org.eclipse.jface.dialogs.ErrorDialog;
Lines 58-64 Link Here
58
/**
49
/**
59
 * Performs single click launching for local Java applications.
50
 * Performs single click launching for local Java applications.
60
 */
51
 */
61
public class JavaApplicationLaunchShortcut implements ILaunchShortcut, ILaunchFilter {
52
public class JavaApplicationLaunchShortcut implements ILaunchShortcut {
62
	
53
	
63
	/**
54
	/**
64
	 * @param search the java elements to search for a main type
55
	 * @param search the java elements to search for a main type
Lines 296-356 Link Here
296
		}
287
		}
297
	}
288
	}
298
289
299
	/* (non-Javadoc)
300
	 * @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String)
301
	 */
302
	public boolean testAttribute(IResource target, String name, String value) {
303
		if ("ContextualLaunchActionFilter".equals(name)) { //$NON-NLS-1$
304
			return hasMain(target);
305
		} else if ("NameMatches".equals(name)) { //$NON-NLS-1$
306
			return nameMatches(target, value);
307
		}
308
		return false;
309
	}
310
	
311
	/**
312
	 * Test if the name of the target resource matches a pattern.
313
	 * 
314
	 * @param target selected resource from workspace
315
	 * @param value regular expression pattern to test
316
	 * @return true if the pattern matches the resource name, false otherwise
317
	 */
318
	private boolean nameMatches(IResource target, String regexp) {
319
		String filename = target.getName();
320
		StringMatcher sm = new StringMatcher(regexp, true, false);
321
		return sm.match(filename);
322
	}
323
	
324
	/**
325
	 * Look for a Java main() method in the specified resource.
326
	 * @return true if the target resource has a <code>main</code> method,
327
	 * <code>false</code> otherwise.
328
	 */
329
	private boolean hasMain(IResource target) {
330
		if (target != null) {
331
			IJavaElement element = JavaCore.create(target);
332
			if (element instanceof ICompilationUnit) {
333
				ICompilationUnit cu = (ICompilationUnit) element;
334
				IType mainType= cu.getType(Signature.getQualifier(cu.getElementName()));
335
				try {
336
					if (mainType.exists() && JavaModelUtil.hasMainMethod(mainType)) {
337
						return true;
338
					}
339
				} catch (JavaModelException e) {
340
					return false;
341
				}
342
			} else if (element instanceof IClassFile) {
343
				IType mainType;
344
				try {
345
					mainType = ((IClassFile)element).getType();
346
					if (JavaModelUtil.hasMainMethod(mainType)) {
347
						return true;
348
					}
349
				} catch (JavaModelException e) {
350
					return false;
351
				}
352
			}
353
		}
354
		return false;
355
	}
356
}
290
}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/ResourceExtender.java (+104 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 International Business Machines Corp. and others.
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v0.5 
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/cpl-v05.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.launcher;
12
13
import java.util.HashSet;
14
import java.util.Set;
15
16
import org.eclipse.core.expressions.PropertyTester;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.jdt.core.IClassFile;
20
import org.eclipse.jdt.core.ICompilationUnit;
21
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IType;
23
import org.eclipse.jdt.core.JavaCore;
24
import org.eclipse.jdt.core.JavaModelException;
25
import org.eclipse.jdt.core.Signature;
26
import org.eclipse.jdt.internal.corext.Assert;
27
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
28
29
/**
30
 * ResourceExtender provides propertyTester(s) for IResource types
31
 * for use in XML Expression Language syntax.
32
 */
33
public class ResourceExtender extends PropertyTester {
34
35
	private static final String PROPERTY_IS_APPLET= "isApplet";	 //$NON-NLS-1$
36
	private static final String PROPERTY_HAS_MAIN_TYPE= "hasMainType";	 //$NON-NLS-1$
37
38
	/* (non-Javadoc)
39
	 * @see org.eclipse.jdt.internal.corext.refactoring.participants.properties.IPropertyEvaluator#test(java.lang.Object, java.lang.String, java.lang.String)
40
	 */
41
	public boolean test(Object receiver, String method, Object[] args, Object expectedValue) {
42
		IResource resource= (IResource)receiver;
43
		if (PROPERTY_IS_APPLET.equals(method)) { //$NON-NLS-1$
44
			return isApplet(resource);
45
		} else if (PROPERTY_HAS_MAIN_TYPE.equals(method)) {
46
			return hasMain(resource);
47
		}
48
		Assert.isTrue(false);
49
		return false;
50
	}
51
52
	/**
53
	 * Check if the specified resource is an Applet.
54
	 * @return <code>true</code> if the target resource is an Applet,
55
	 * <code>false</code> otherwise.
56
	 */
57
	private boolean isApplet(IResource resource) {
58
		if (resource != null) {
59
			try {
60
				Set result= new HashSet();
61
				AppletLaunchConfigurationUtils.collectTypes(resource, new NullProgressMonitor(), result);
62
				if (result.size() > 0) {
63
					return true;
64
				}
65
			} catch (JavaModelException e) {
66
				return false;
67
			}
68
		}
69
		return false;
70
	}
71
	
72
	/**
73
	 * Look for a Java main() method in the specified resource.
74
	 * @return true if the target resource has a <code>main</code> method,
75
	 * <code>false</code> otherwise.
76
	 */
77
	private boolean hasMain(IResource target) {
78
		if (target != null) {
79
			IJavaElement element = JavaCore.create(target);
80
			if (element instanceof ICompilationUnit) {
81
				ICompilationUnit cu = (ICompilationUnit) element;
82
				IType mainType= cu.getType(Signature.getQualifier(cu.getElementName()));
83
				try {
84
					if (mainType.exists() && JavaModelUtil.hasMainMethod(mainType)) {
85
						return true;
86
					}
87
				} catch (JavaModelException e) {
88
					return false;
89
				}
90
			} else if (element instanceof IClassFile) {
91
				IType mainType;
92
				try {
93
					mainType = ((IClassFile)element).getType();
94
					if (JavaModelUtil.hasMainMethod(mainType)) {
95
						return true;
96
					}
97
				} catch (JavaModelException e) {
98
					return false;
99
				}
100
			}
101
		}
102
		return false;
103
	}
104
}

Return to bug 54117