|
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 |
} |