private void addBreakpointToMap(IBreakpoint breakpoint) throws CoreException { Assert.isTrue(supportsBreakpoint(breakpoint) && breakpoint instanceof ILineBreakpoint); if (breakpoint instanceof ILineBreakpoint) { ILineBreakpoint lineBreakpoint = (ILineBreakpoint) breakpoint; IResource resource = lineBreakpoint.getMarker().getResource(); IPath location = resource.getLocation(); String path = location.toOSString(); String name = location.lastSegment(); int lineNumber = lineBreakpoint.getLineNumber(); Source source = new Source().setName(name).setPath(path); List<SourceBreakpoint> sourceBreakpoints = targetBreakpoints.computeIfAbsent(source, s -> new ArrayList<>()); sourceBreakpoints.add(new SourceBreakpoint().setLine(lineNumber)); } }
private void deleteBreakpointFromMap(IBreakpoint breakpoint) throws CoreException { Assert.isTrue(supportsBreakpoint(breakpoint) && breakpoint instanceof ILineBreakpoint); if (breakpoint instanceof ILineBreakpoint) { ILineBreakpoint lineBreakpoint = (ILineBreakpoint) breakpoint; IResource resource = lineBreakpoint.getMarker().getResource(); IPath location = resource.getLocation(); String path = location.toOSString(); String name = location.lastSegment(); int lineNumber = lineBreakpoint.getLineNumber(); for (Entry<Source, List<SourceBreakpoint>> entry : targetBreakpoints.entrySet()) { Source source = entry.getKey(); if (Objects.equals(name, source.name) && Objects.equals(path, source.path)) { List<SourceBreakpoint> bps = entry.getValue(); for (Iterator<SourceBreakpoint> iterator = bps.iterator(); iterator.hasNext();) { SourceBreakpoint sourceBreakpoint = (SourceBreakpoint) iterator.next(); if (Objects.equals(lineNumber, sourceBreakpoint.line)) { iterator.remove(); } } } } } }
@Override public IEditorInput getEditorInput(Object element) { if (element instanceof ILineBreakpoint) { return new FileEditorInput((IFile) ((ILineBreakpoint) element).getMarker().getResource()); } IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(element.toString())); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IFile[] files = root.findFilesForLocationURI(fileStore.toURI()); if (files != null) { for (IFile file : files) { if (file.exists()) { return new FileEditorInput(file); } } } return new FileStoreEditorInput(fileStore); }
@Override public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { ITextEditor textEditor = getEditor(part); if (textEditor != null) { IResource resource = textEditor.getEditorInput().getAdapter(IResource.class); ITextSelection textSelection = (ITextSelection) selection; int lineNumber = textSelection.getStartLine(); IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager() .getBreakpoints(DSPPlugin.ID_DSP_DEBUG_MODEL); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (breakpoint instanceof ILineBreakpoint && resource.equals(breakpoint.getMarker().getResource())) { if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) { // remove breakpoint.delete(); return; } } } // create line breakpoint (doc line numbers start at 0) DSPLineBreakpoint lineBreakpoint = new DSPLineBreakpoint(resource, lineNumber + 1); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint); } }
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { ITextEditor textEditor = getEditor(part); if (textEditor != null) { IResource resource = (IResource) textEditor.getEditorInput().getAdapter(IResource.class); ITextSelection textSelection = (ITextSelection) selection; int lineNumber = textSelection.getStartLine(); IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints( getDebugModelId()); for (int i = 0; i < breakpoints.length; i++) { IBreakpoint breakpoint = breakpoints[i]; if (resource.equals(breakpoint.getMarker().getResource())) { if (((ILineBreakpoint) breakpoint).getLineNumber() == lineNumber + 1) { // remove breakpoint.delete(); return; } } } // Line numbers start with 0 in V8, with 1 in Eclipse. ChromiumLineBreakpoint lineBreakpoint = new ChromiumLineBreakpoint(resource, lineNumber + 1, getDebugModelId()); DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint); } }
@Override public String getEditorId(IEditorInput input, Object element) { IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); if (element instanceof IFile) { IFile file = (IFile)element; return registry.getDefaultEditor(file.getName()).getId(); } else if (element instanceof ILineBreakpoint) { String fileName = ((ILineBreakpoint)element).getMarker().getResource().getName(); return registry.getDefaultEditor(fileName).getId(); } else if (element instanceof IStorage) { IStorage storage = (IStorage)element; return registry.getDefaultEditor(storage.getName()).getId(); } else if (element instanceof URL) { URL url = (URL)element; return registry.getDefaultEditor(url.getFile()).getId(); } return null; }
@Override public IEditorInput getEditorInput(Object element) { if (element instanceof IFile) { return new FileEditorInput((IFile)element); } if (element instanceof ILineBreakpoint) { return new FileEditorInput((IFile)((ILineBreakpoint)element).getMarker().getResource()); } if (element instanceof URL) { return new URLEditorInput((URL)element); } if (element instanceof IStorage) { return new StorageEditorInput((IStorage)element); } return null; }
@Override public boolean supportsBreakpoint(IBreakpoint breakpoint) { if (!isTerminated() && breakpoint instanceof ILineBreakpoint) { return true; } return false; }
@Override public IEditorInput getEditorInput(Object element) { if (element instanceof IFile) { return new FileEditorInput((IFile) element); } else if (element instanceof ILineBreakpoint) { return new FileEditorInput((IFile) ((ILineBreakpoint) element).getMarker().getResource()); } else { System.err.printf("Unexpected class in MontoDebugModelPresentation.getEditorInput(%s)\n", element.getClass().getName()); return null; } }
@Override public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException { System.out.println("MontoToggleBreakpointsTarget.toggleLineBreakpoints()"); if (part != null && part instanceof UniversalEditor) { UniversalEditor universalEditor = (UniversalEditor) part; if (universalEditor.getParseController() instanceof MontoParseController) { MontoParseController montoParseController = (MontoParseController) universalEditor.getParseController(); IResource resource = (IResource) universalEditor.getEditorInput().getAdapter(IResource.class); ITextSelection textSelection = (ITextSelection) selection; int lineNumber = textSelection.getStartLine(); // delete old breakpoints in lineNumber IBreakpoint[] oldBreakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(Activator.PLUGIN_ID); boolean deletedBreakPoints = false; for (IBreakpoint oldBreakpoint : oldBreakpoints) { if (resource.equals(oldBreakpoint.getMarker().getResource()) && ((ILineBreakpoint) oldBreakpoint).getLineNumber() == (lineNumber + 1)) { deletedBreakPoints = true; oldBreakpoint.delete(); } } if (!deletedBreakPoints) { // create new one DebugPlugin.getDefault().getBreakpointManager().addBreakpoint( new MontoLineBreakpoint(resource, lineNumber + 1, montoParseController.getSource())); } } } }
public static IEditorInput toEditorInput(Object element) { if (element instanceof IFile) { return new FileEditorInput((IFile) element); } if (element instanceof ILineBreakpoint) { return new FileEditorInput( (IFile) ((ILineBreakpoint) element).getMarker().getResource()); } return null; }
public String getEditorId( IEditorInput input, Object element ) { if ( element instanceof ScriptLocalFileStorage || element instanceof ILineBreakpoint ) { return EDITOR_ID; } return null; }