|
Lines 14-22
Link Here
|
| 14 |
import java.lang.reflect.InvocationTargetException; |
14 |
import java.lang.reflect.InvocationTargetException; |
| 15 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
| 16 |
import java.util.Collections; |
16 |
import java.util.Collections; |
|
|
17 |
import java.util.HashSet; |
| 17 |
import java.util.List; |
18 |
import java.util.List; |
|
|
19 |
import java.util.Set; |
| 18 |
|
20 |
|
|
|
21 |
import org.eclipse.core.resources.IResource; |
| 19 |
import org.eclipse.core.runtime.CoreException; |
22 |
import org.eclipse.core.runtime.CoreException; |
|
|
23 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 20 |
import org.eclipse.debug.core.DebugPlugin; |
24 |
import org.eclipse.debug.core.DebugPlugin; |
| 21 |
import org.eclipse.debug.core.ILaunchConfiguration; |
25 |
import org.eclipse.debug.core.ILaunchConfiguration; |
| 22 |
import org.eclipse.debug.core.ILaunchConfigurationType; |
26 |
import org.eclipse.debug.core.ILaunchConfigurationType; |
|
Lines 25-34
Link Here
|
| 25 |
import org.eclipse.debug.ui.DebugUITools; |
29 |
import org.eclipse.debug.ui.DebugUITools; |
| 26 |
import org.eclipse.debug.ui.IDebugModelPresentation; |
30 |
import org.eclipse.debug.ui.IDebugModelPresentation; |
| 27 |
import org.eclipse.debug.ui.ILaunchShortcut; |
31 |
import org.eclipse.debug.ui.ILaunchShortcut; |
|
|
32 |
import org.eclipse.jdt.core.IClassFile; |
| 33 |
import org.eclipse.jdt.core.ICompilationUnit; |
| 28 |
import org.eclipse.jdt.core.IJavaElement; |
34 |
import org.eclipse.jdt.core.IJavaElement; |
| 29 |
import org.eclipse.jdt.core.IType; |
35 |
import org.eclipse.jdt.core.IType; |
|
|
36 |
import org.eclipse.jdt.core.JavaCore; |
| 37 |
import org.eclipse.jdt.core.JavaModelException; |
| 38 |
import org.eclipse.jdt.core.Signature; |
| 30 |
import org.eclipse.jdt.debug.ui.JavaUISourceLocator; |
39 |
import org.eclipse.jdt.debug.ui.JavaUISourceLocator; |
|
|
40 |
import org.eclipse.jdt.internal.corext.util.JavaModelUtil; |
| 31 |
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
41 |
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; |
|
|
42 |
import org.eclipse.jdt.internal.debug.ui.console.StringMatcher; |
| 32 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
43 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
| 33 |
import org.eclipse.jface.dialogs.ErrorDialog; |
44 |
import org.eclipse.jface.dialogs.ErrorDialog; |
| 34 |
import org.eclipse.jface.dialogs.MessageDialog; |
45 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
Lines 38-43
Link Here
|
| 38 |
import org.eclipse.jface.window.Window; |
49 |
import org.eclipse.jface.window.Window; |
| 39 |
import org.eclipse.swt.widgets.Display; |
50 |
import org.eclipse.swt.widgets.Display; |
| 40 |
import org.eclipse.swt.widgets.Shell; |
51 |
import org.eclipse.swt.widgets.Shell; |
|
|
52 |
import org.eclipse.ui.IActionFilter; |
| 41 |
import org.eclipse.ui.IEditorInput; |
53 |
import org.eclipse.ui.IEditorInput; |
| 42 |
import org.eclipse.ui.IEditorPart; |
54 |
import org.eclipse.ui.IEditorPart; |
| 43 |
import org.eclipse.ui.dialogs.ElementListSelectionDialog; |
55 |
import org.eclipse.ui.dialogs.ElementListSelectionDialog; |
|
Lines 45-51
Link Here
|
| 45 |
/** |
57 |
/** |
| 46 |
* Performs single click launching for local Java applications. |
58 |
* Performs single click launching for local Java applications. |
| 47 |
*/ |
59 |
*/ |
| 48 |
public class JavaApplicationLaunchShortcut implements ILaunchShortcut { |
60 |
public class JavaApplicationLaunchShortcut implements ILaunchShortcut, IActionFilter { |
| 49 |
|
61 |
|
| 50 |
/** |
62 |
/** |
| 51 |
* @param search the java elements to search for a main type |
63 |
* @param search the java elements to search for a main type |
|
Lines 258-261
Link Here
|
| 258 |
} |
270 |
} |
| 259 |
} |
271 |
} |
| 260 |
|
272 |
|
|
|
273 |
/* (non-Javadoc) |
| 274 |
* @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String) |
| 275 |
*/ |
| 276 |
public boolean testAttribute(Object target, String name, String value) { |
| 277 |
if ("ContextualLaunchActionFilter".equals(name)) { |
| 278 |
return hasMain2(target); |
| 279 |
} else if ("NameMatches".equals(name)) { |
| 280 |
return nameMatches(target, value); |
| 281 |
} |
| 282 |
return false; |
| 283 |
} |
| 284 |
|
| 285 |
/** |
| 286 |
* @param target |
| 287 |
* @param value |
| 288 |
* @return |
| 289 |
*/ |
| 290 |
private boolean nameMatches(Object target, String value) { |
| 291 |
try { |
| 292 |
Object[] selections = ((IStructuredSelection) target).toArray(); |
| 293 |
IResource resource = (IResource) selections[0]; |
| 294 |
String filename = resource.getName(); |
| 295 |
StringMatcher sm = new StringMatcher(value, true, false); |
| 296 |
return sm.match(filename); |
| 297 |
} catch (ClassCastException e) { |
| 298 |
return false; |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
private boolean hasMain(Object target) { |
| 303 |
if (target != null && target instanceof IStructuredSelection) { |
| 304 |
Object[] selections = ((IStructuredSelection )target).toArray(); |
| 305 |
IResource resource = (IResource)selections[0]; |
| 306 |
IType[] types= null; |
| 307 |
try { |
| 308 |
final Set result= new HashSet(); |
| 309 |
MainMethodFinder.collectTypes(resource, new NullProgressMonitor(), result); |
| 310 |
if (result.size() > 0) { |
| 311 |
return true; |
| 312 |
} |
| 313 |
} catch (JavaModelException e) { |
| 314 |
return false; |
| 315 |
} |
| 316 |
} |
| 317 |
return false; |
| 318 |
} |
| 319 |
|
| 320 |
private boolean hasMain2(Object target) { |
| 321 |
if (target != null && target instanceof IStructuredSelection) { |
| 322 |
Object[] selections = ((IStructuredSelection )target).toArray(); |
| 323 |
IResource resource = (IResource)selections[0]; |
| 324 |
IJavaElement element = JavaCore.create(resource); |
| 325 |
if (element instanceof ICompilationUnit) { |
| 326 |
ICompilationUnit cu = (ICompilationUnit) element; |
| 327 |
IType mainType= cu.getType(Signature.getQualifier(cu.getElementName())); |
| 328 |
try { |
| 329 |
if (mainType.exists() && JavaModelUtil.hasMainMethod(mainType)) { |
| 330 |
return true; |
| 331 |
} |
| 332 |
} catch (JavaModelException e) { |
| 333 |
return false; |
| 334 |
} |
| 335 |
} else if (element instanceof IClassFile) { |
| 336 |
IType mainType; |
| 337 |
try { |
| 338 |
mainType = ((IClassFile)element).getType(); |
| 339 |
if (JavaModelUtil.hasMainMethod(mainType)) { |
| 340 |
return true; |
| 341 |
} |
| 342 |
} catch (JavaModelException e) { |
| 343 |
return false; |
| 344 |
} |
| 345 |
} |
| 346 |
} |
| 347 |
return false; |
| 348 |
} |
| 261 |
} |
349 |
} |