/** Create & return a new configuration based on the specified <code>IType</code>. */ protected ILaunchConfiguration createConfiguration(IType type) { String launcherName = MainLauncher.this.getLauncherName(); ILaunchConfigurationType configType = MainLauncher.this.getLaunchConfigurationType(); ILaunchConfigurationWorkingCopy wc = null; try { wc = configType.newInstance(null, launcherName); } catch (CoreException exception) { JDIDebugUIPlugin.log(exception); return null; } wc.setAttribute( IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, type.getFullyQualifiedName()); wc.setAttribute( IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, type.getJavaProject().getElementName()); MainLauncher.this.setAdditionalAttributes(wc); ILaunchConfiguration config = null; try { config = wc.doSave(); } catch (CoreException exception) { JDIDebugUIPlugin.log(exception); } return config; }
/* (non-Javadoc) * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) */ public Image getImage(Object element) { String key = null; IStatus status = Status.OK_STATUS; if (element instanceof LibraryStandin) { LibraryStandin library = (LibraryStandin) element; IPath sourcePath = library.getSystemLibrarySourcePath(); if (sourcePath != null && !Path.EMPTY.equals(sourcePath)) { key = ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE_WITH_SOURCE; } else { key = ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE; } status = library.validate(); } else if (element instanceof SubElement) { if (((SubElement) element).getType() == SubElement.SOURCE_PATH) { key = ISharedImages.IMG_OBJS_JAR_WITH_SOURCE; } else { key = ISharedImages.IMG_OBJS_JAVADOCTAG; } } if (key != null) { if (!status.isOK()) { ImageDescriptor base = JavaUI.getSharedImages().getImageDescriptor(key); JDIImageDescriptor descriptor = new JDIImageDescriptor(base, JDIImageDescriptor.IS_OUT_OF_SYNCH); return JDIDebugUIPlugin.getImageDescriptorRegistry().get(descriptor); } return JavaUI.getSharedImages().getImage(key); } return null; }
/* (non-Javadoc) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) */ @Override public void performApply(ILaunchConfigurationWorkingCopy configuration) { if (isDirty()) { boolean def = fDefaultButton.getSelection(); if (def) { configuration.setAttribute( IJavaLaunchConfigurationConstants.ATTR_DEFAULT_SOURCE_PATH, (String) null); configuration.setAttribute( IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH, (List<String>) null); } else { configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_SOURCE_PATH, def); try { IRuntimeClasspathEntry[] entries = fPathViewer.getEntries(); List<String> mementos = new ArrayList<String>(entries.length); for (int i = 0; i < entries.length; i++) { mementos.add(entries[i].getMemento()); } configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH, mementos); } catch (CoreException e) { JDIDebugUIPlugin.statusDialog( LauncherMessages.SourceLookupBlock_Unable_to_save_source_lookup_path_1, e.getStatus()); } } boolean dup = fDuplicatesButton.getSelection(); if (dup) { configuration.setAttribute(JavaUISourceLocator.ATTR_FIND_ALL_SOURCE_ELEMENTS, true); } else { configuration.setAttribute( JavaUISourceLocator.ATTR_FIND_ALL_SOURCE_ELEMENTS, (String) null); } } }
/** * Exception breakpoint detail pane. * * @since 3.6 */ public class ExceptionBreakpointDetailPane extends AbstractDetailPane { /** Identifier for this detail pane editor */ public static final String DETAIL_PANE_EXCEPTION_BREAKPOINT = JDIDebugUIPlugin.getUniqueIdentifier() + ".DETAIL_PANE_EXCEPTION_BREAKPOINT"; // $NON-NLS-1$ public ExceptionBreakpointDetailPane() { super( BreakpointMessages.ExceptionBreakpointDetailPane_0, BreakpointMessages.ExceptionBreakpointDetailPane_0, DETAIL_PANE_EXCEPTION_BREAKPOINT); addAutosaveProperties( new int[] { StandardJavaBreakpointEditor.PROP_HIT_COUNT_ENABLED, StandardJavaBreakpointEditor.PROP_SUSPEND_POLICY, StandardJavaBreakpointEditor.PROP_TRIGGER_POINT, ExceptionBreakpointEditor.PROP_CAUGHT, ExceptionBreakpointEditor.PROP_UNCAUGHT, ExceptionBreakpointEditor.PROP_SUBCLASSES }); } /* (non-Javadoc) * @see org.eclipse.jdt.internal.debug.ui.breakpoints.AbstractDetailPane#createEditor(org.eclipse.swt.widgets.Composite) */ @Override protected AbstractJavaBreakpointEditor createEditor(Composite parent) { return new ExceptionBreakpointEditor(); } }
/* (non-Javadoc) * @see org.eclipse.jdt.debug.ui.launchConfigurations.JavaLaunchShortcut#createConfiguration(org.eclipse.jdt.core.IType) */ @Override protected ILaunchConfiguration createConfiguration(IType type) { ILaunchConfiguration config = null; ILaunchConfigurationWorkingCopy wc = null; try { ILaunchConfigurationType configType = getConfigurationType(); 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()); wc.setMappedResources(new IResource[] {type.getUnderlyingResource()}); config = wc.doSave(); } catch (CoreException exception) { MessageDialog.openError( JDIDebugUIPlugin.getActiveWorkbenchShell(), LauncherMessages.JavaLaunchShortcut_3, exception.getStatus().getMessage()); } return config; }
/* * @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument) */ @Override public void setup(IDocument document) { if (document != null) { JavaTextTools tools = JDIDebugUIPlugin.getDefault().getJavaTextTools(); tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING); } }
/** Overridden, copied and changed to alter the generated launch configuration name. */ @Override public ILaunchConfiguration createConfiguration(IType type) { ILaunchConfiguration config = null; try { config = BootLaunchConfigurationDelegate.createConf(type); } catch (CoreException exception) { MessageDialog.openError( JDIDebugUIPlugin.getActiveWorkbenchShell(), LauncherMessages.JavaLaunchShortcut_3, exception.getStatus().getMessage()); } return config; }
protected void report(final String message) { JDIDebugUIPlugin.getStandardDisplay() .asyncExec( new Runnable() { public void run() { if (fStatusLine != null) { fStatusLine.setMessage(true, message, null); } if (message != null && JDIDebugUIPlugin.getActiveWorkbenchShell() != null) { Display.getCurrent().beep(); } } }); }
/* (non-Javadoc) * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration) */ @Override public void initializeFrom(ILaunchConfiguration config) { boolean useDefault = true; setErrorMessage(null); try { useDefault = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_SOURCE_PATH, true); } catch (CoreException e) { JDIDebugUIPlugin.log(e); } if (config == getLaunchConfiguration()) { // same as previously viewed launch config if (!useDefault && !fDefaultButton.getSelection()) { // If an explicit classpath is being used, it must be the same as before. // No need to refresh setDirty(false); return; } } setLaunchConfiguration(config); fDefaultButton.setSelection(useDefault); try { IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedSourceLookupPath(config); fPathViewer.setEntries(entries); } catch (CoreException e) { setErrorMessage(e.getMessage()); } fPathViewer.setEnabled(!useDefault); fPathViewer.setLaunchConfiguration(config); try { fDuplicatesButton.setSelection( config.getAttribute(JavaUISourceLocator.ATTR_FIND_ALL_SOURCE_ELEMENTS, false)); } catch (CoreException e) { JDIDebugUIPlugin.log(e); } setDirty(false); }
protected ILaunchConfiguration findLaunchConfiguration( IType type, ILaunchConfigurationType configType) { try { ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configType); for (int i = 0; i < configs.length; i++) { if (getLauncherName().equals(configs[i].getName())) { return configs[i]; } } } catch (CoreException e) { JDIDebugUIPlugin.log(e); } return super.findLaunchConfiguration(type, configType); }
static { IPreferenceStore preferenceStore = JDIDebugUIPlugin.getDefault().getPreferenceStore(); preferenceStore.addPropertyChangeListener( new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(IJavaDebugUIConstants.PREF_SHOW_MONITOR_THREAD_INFO)) { fgDisplayMonitors = JDIDebugUIPreferenceInitializer.getBoolean(event); } else if (event.getProperty().equals(IJavaDebugUIConstants.PREF_SHOW_THREAD_GROUPS)) { fgDisplayThreadGroups = JDIDebugUIPreferenceInitializer.getBoolean(event); } } }); fgDisplayMonitors = preferenceStore.getBoolean(IJavaDebugUIConstants.PREF_SHOW_MONITOR_THREAD_INFO); fgDisplayThreadGroups = preferenceStore.getBoolean(IJavaDebugUIConstants.PREF_SHOW_THREAD_GROUPS); }
private void addPackage() { Shell shell = fAddPackageButton.getDisplay().getActiveShell(); ElementListSelectionDialog dialog = null; try { IJavaProject project = fEditor.getJavaProject(); List<IJavaElement> projects = new ArrayList<IJavaElement>(); projects.add(project); IPackageFragmentRoot[] roots = project.getAllPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; projects.add(root.getParent()); } dialog = JDIDebugUIPlugin.createAllPackagesDialog( shell, projects.toArray(new IJavaProject[projects.size()]), false); } catch (JavaModelException jme) { String title = SnippetMessages.getString("SelectImportsDialog.Add_package_as_import_7"); // $NON-NLS-1$ String message = SnippetMessages.getString( "SelectImportsDialog.Could_not_open_package_selection_dialog_8"); //$NON-NLS-1$ ExceptionHandler.handle(jme, title, message); return; } if (dialog == null) { return; } dialog.setTitle( SnippetMessages.getString("SelectImportsDialog.Add_package_as_import_7")); // $NON-NLS-1$ dialog.setMessage( SnippetMessages.getString( "SelectImportsDialog.&Select_a_package_to_add_as_an_Import_10")); //$NON-NLS-1$ dialog.setMultipleSelection(true); if (dialog.open() == IDialogConstants.CANCEL_ID) { return; } Object[] packages = dialog.getResult(); if (packages != null) { for (int i = 0; i < packages.length; i++) { IJavaElement pkg = (IJavaElement) packages[i]; String filter = pkg.getElementName(); filter += ".*"; // $NON-NLS-1$ fImportContentProvider.addImport(filter); } } }
/** * Returns the smallest enclosing <code>IType</code> if the specified object is a main method, or * <code>null</code> * * @param o the object to inspect * @return the smallest enclosing <code>IType</code> of the specified object if it is a main * method or <code>null</code> if it is not */ private IType isMainMethod(Object o) { if (o instanceof IAdaptable) { IAdaptable adapt = (IAdaptable) o; IJavaElement element = (IJavaElement) adapt.getAdapter(IJavaElement.class); if (element != null && element.getElementType() == IJavaElement.METHOD) { try { IMethod method = (IMethod) element; if (method.isMainMethod()) { return method.getDeclaringType(); } } catch (JavaModelException jme) { JDIDebugUIPlugin.log(jme); } } } return null; }
@Override public Font getFont(Object element) { if (fVMList.getChecked(element)) { if (bold == null) { Font dialogFont = JFaceResources.getDialogFont(); FontData[] fontData = dialogFont.getFontData(); for (int i = 0; i < fontData.length; i++) { FontData data = fontData[i]; data.setStyle(SWT.BOLD); } Display display = JDIDebugUIPlugin.getStandardDisplay(); bold = new Font(display, fontData); } return bold; } return null; }
/* * (non-Javadoc) * * @see org.eclipse.jface.action.IAction#run() */ public void run() { try { /* * Test if there are any markers at the current position. * if there are any, remove breakpointmarker, otherwise create a * new one. */ List list = getMarkers(); if (list.isEmpty()) { // create new markers IDocument document = getDocument(); int lineNumber = getVerticalRulerInfo().getLineOfLastMouseButtonActivity(); if (lineNumber >= document.getNumberOfLines()) { return; } try { IRegion line = document.getLineInformation(lineNumber); ITextSelection selection = new TextSelection(document, line.getOffset(), line.getLength()); // fBreakpointAdapter.toggleLineBreakpoints(fTextEditor, selection); fBreakpointAdapter.toggleBreakpoints(fTextEditor, selection); } catch (BadLocationException e) { // likely document is folded so you cannot get the line information of the folded line } } else { // remove existing breakpoints of any type IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); Iterator iterator = list.iterator(); while (iterator.hasNext()) { IMarker marker = (IMarker) iterator.next(); IBreakpoint breakpoint = manager.getBreakpoint(marker); if (breakpoint != null) { breakpoint.delete(); } } } } catch (CoreException e) { // JDIDebugUIPlugin.errorDialog(ActionMessages.getString("ManageBreakpointRulerAction.error.adding.message1"), e); //$NON-NLS-1$ // JDIDebugUIPlugin.errorDialog(ActionMessages.ManageBreakpointRulerAction_error_adding_message1, e); // This message may not make sense FIXME JDIDebugUIPlugin.errorDialog( ActionMessages.ManageMethodBreakpointActionDelegate_methodNonAvailable, e); } }
/** Calls out to {@link MacVMSearch} to find all installed JREs in the standard Mac OS location */ private void doMacSearch() { final List<VMStandin> added = new ArrayList<VMStandin>(); IRunnableWithProgress r = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException { Set<String> exists = new HashSet<String>(); for (IVMInstall vm : fVMs) { exists.add(vm.getId()); } SubMonitor localmonitor = SubMonitor.convert(monitor, JREMessages.MacVMSearch_0, 5); VMStandin[] standins = null; try { standins = MacInstalledJREs.getInstalledJREs(localmonitor); for (int i = 0; i < standins.length; i++) { if (!exists.contains(standins[i].getId())) { added.add(standins[i]); } } } catch (CoreException ce) { JDIDebugUIPlugin.log(ce); } monitor.done(); } }; try { ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell()); progress.run(true, true, r); } catch (InvocationTargetException e) { JDIDebugUIPlugin.log(e); } catch (InterruptedException e) { // canceled return; } for (VMStandin vm : added) { vmAdded(vm); } }
/** The "default" button has been toggled */ protected void handleDefaultButtonSelected() { setDirty(true); boolean def = fDefaultButton.getSelection(); if (def) { try { ILaunchConfiguration config = getLaunchConfiguration(); ILaunchConfigurationWorkingCopy wc = null; if (config.isWorkingCopy()) { wc = (ILaunchConfigurationWorkingCopy) config; } else { wc = config.getWorkingCopy(); } performApply(wc); IRuntimeClasspathEntry[] defs = JavaRuntime.computeUnresolvedSourceLookupPath(wc); fPathViewer.setEntries(defs); } catch (CoreException e) { JDIDebugUIPlugin.log(e); } } fPathViewer.setEnabled(!def); updateLaunchConfigurationDialog(); }
private String extractNameFromJavaElement(final IJavaElement javaElement) { String name = null; if (javaElement != null) { final String[] nameRef = new String[1]; try { getLaunchConfigurationDialog() .run( true, true, new IRunnableWithProgress() { @SuppressWarnings("synthetic-access") @Override public void run(IProgressMonitor pm) throws InvocationTargetException { try { final IJavaProject javaProject = javaElement.getJavaProject(); final IType agentType = javaProject.findType("io.sarl.lang.core.Agent"); // $NON-NLS-1$ final IType[] types = agentType.newTypeHierarchy(pm).getAllSubtypes(agentType); if (types != null && types.length > 0) { nameRef[0] = types[0].getFullyQualifiedName(); } } catch (JavaModelException e) { setErrorMessage(e.getLocalizedMessage()); JDIDebugUIPlugin.log(e); } } }); } catch (Exception e) { setErrorMessage(e.getLocalizedMessage()); JDIDebugUIPlugin.log(e); } name = nameRef[0]; } return Strings.nullToEmpty(name); }
private IType[] searchAgentNames() { final IType[][] res = new IType[1][]; res[0] = new IType[0]; final String projectName = this.fProjText.getText(); final IStatus status = ResourcesPlugin.getWorkspace().validateName(projectName, IResource.PROJECT); if (status.isOK()) { try { getLaunchConfigurationDialog() .run( true, true, new IRunnableWithProgress() { @SuppressWarnings("synthetic-access") @Override public void run(IProgressMonitor pm) throws InvocationTargetException { try { final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); final IJavaProject javaProject = JavaCore.create(project); final IType agentType = javaProject.findType("io.sarl.lang.core.Agent"); // $NON-NLS-1$ res[0] = agentType.newTypeHierarchy(pm).getAllSubtypes(agentType); } catch (JavaModelException e) { setErrorMessage(e.getLocalizedMessage()); JDIDebugUIPlugin.log(e); } } }); } catch (Exception e) { setErrorMessage(e.getLocalizedMessage()); JDIDebugUIPlugin.log(e); } } return res[0]; }
/** * Returns a list of markers that exist at the current ruler location. * * @return a list of markers that exist at the current ruler location */ protected List getMarkers() { List breakpoints = new ArrayList(); IResource resource = getResource(); IDocument document = getDocument(); AbstractMarkerAnnotationModel model = getAnnotationModel(); if (model != null) { try { IMarker[] markers = null; if (resource instanceof IFile) markers = resource.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); else { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); markers = root.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); } if (markers != null) { IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager(); for (int i = 0; i < markers.length; i++) { IBreakpoint breakpoint = breakpointManager.getBreakpoint(markers[i]); if (breakpoint != null && breakpointManager.isRegistered(breakpoint) && includesRulerLine(model.getMarkerPosition(markers[i]), document)) breakpoints.add(markers[i]); } } } catch (CoreException x) { JDIDebugUIPlugin.log(x.getStatus()); } } return breakpoints; }
/** Search for installed VMs in the file system */ protected void search() { if (Platform.OS_MACOSX.equals(Platform.getOS())) { doMacSearch(); return; } // choose a root directory for the search DirectoryDialog dialog = new DirectoryDialog(getShell()); dialog.setMessage(JREMessages.InstalledJREsBlock_9); dialog.setText(JREMessages.InstalledJREsBlock_10); String path = dialog.open(); if (path == null) { return; } // ignore installed locations final Set<File> exstingLocations = new HashSet<File>(); for (IVMInstall vm : fVMs) { exstingLocations.add(vm.getInstallLocation()); } // search final File rootDir = new File(path); final List<File> locations = new ArrayList<File>(); final List<IVMInstallType> types = new ArrayList<IVMInstallType>(); IRunnableWithProgress r = new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) { monitor.beginTask(JREMessages.InstalledJREsBlock_11, IProgressMonitor.UNKNOWN); search(rootDir, locations, types, exstingLocations, monitor); monitor.done(); } }; try { ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell()) { /* * Overridden createCancelButton to replace Cancel label with Stop label * More accurately reflects action taken when button pressed. * Bug [162902] */ @Override protected void createCancelButton(Composite parent) { cancel = createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.STOP_LABEL, true); if (arrowCursor == null) { arrowCursor = new Cursor(cancel.getDisplay(), SWT.CURSOR_ARROW); } cancel.setCursor(arrowCursor); setOperationCancelButtonEnabled(enableCancelButton); } }; progress.run(true, true, r); } catch (InvocationTargetException e) { JDIDebugUIPlugin.log(e); } catch (InterruptedException e) { // canceled return; } if (locations.isEmpty()) { String messagePath = path.replaceAll("&", "&&"); // @see bug 29855 //$NON-NLS-1$//$NON-NLS-2$ MessageDialog.openInformation( getShell(), JREMessages.InstalledJREsBlock_12, NLS.bind(JREMessages.InstalledJREsBlock_13, new String[] {messagePath})); // } else { Iterator<IVMInstallType> iter2 = types.iterator(); for (File location : locations) { IVMInstallType type = iter2.next(); AbstractVMInstall vm = new VMStandin(type, createUniqueId(type)); String name = location.getName(); String nameCopy = new String(name); int i = 1; while (isDuplicateName(nameCopy)) { nameCopy = name + '(' + i++ + ')'; } vm.setName(nameCopy); vm.setInstallLocation(location); if (type instanceof AbstractVMInstallType) { // set default java doc location AbstractVMInstallType abs = (AbstractVMInstallType) type; vm.setJavadocLocation(abs.getDefaultJavadocLocation(location)); vm.setVMArgs(abs.getDefaultVMArguments(location)); } vmAdded(vm); } } }