Search in sources :

Example 1 with IJavaStratumLineBreakpoint

use of org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint in project xtext-eclipse by eclipse.

the class XbaseBreakpointDetailPaneFactory method createDetailPane.

@Override
public IDetailPane createDetailPane(String paneID) {
    if (XBASE_DETAIL_PANE.equals(paneID)) {
        return new LineBreakpointDetailPane() {

            @Override
            public void display(IStructuredSelection selection) {
                super.display(selection);
                AbstractJavaBreakpointEditor editor = getEditor();
                Object input = null;
                if (selection != null && selection.size() == 1) {
                    input = selection.getFirstElement();
                }
                try {
                    if (input instanceof IJavaStratumLineBreakpoint) {
                        IJavaStratumLineBreakpoint stratumBreakpoint = (IJavaStratumLineBreakpoint) input;
                        URI uri = URI.createURI((String) stratumBreakpoint.getMarker().getAttribute(StratumBreakpointAdapterFactory.ORG_ECLIPSE_XTEXT_XBASE_SOURCE_URI));
                        IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
                        if (resourceServiceProvider != null) {
                            JavaBreakPointProvider javaBreakPointProvider = resourceServiceProvider.get(JavaBreakPointProvider.class);
                            input = javaBreakPointProvider.getBreakpointWithJavaLocation(stratumBreakpoint);
                        }
                    }
                    editor.setInput(input);
                } catch (CoreException e) {
                    JDIDebugUIPlugin.log(e);
                }
            }
        };
    } else {
        return super.createDetailPane(paneID);
    }
}
Also used : IJavaStratumLineBreakpoint(org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) CoreException(org.eclipse.core.runtime.CoreException) AbstractJavaBreakpointEditor(org.eclipse.jdt.internal.debug.ui.breakpoints.AbstractJavaBreakpointEditor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) URI(org.eclipse.emf.common.util.URI) LineBreakpointDetailPane(org.eclipse.jdt.internal.debug.ui.breakpoints.LineBreakpointDetailPane)

Example 2 with IJavaStratumLineBreakpoint

use of org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint in project xtext-eclipse by eclipse.

the class StratumBreakpointAdapterFactory method findExistingBreakpoint.

protected IJavaStratumLineBreakpoint findExistingBreakpoint(IResource res, SourceRelativeURI uri, final int line) throws CoreException {
    IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
    IBreakpoint[] breakpoints = manager.getBreakpoints();
    if (uri == null) {
        for (IBreakpoint breakpoint : breakpoints) {
            IMarker marker = breakpoint.getMarker();
            if (breakpoint instanceof IJavaStratumLineBreakpoint && marker.getResource().equals(res)) {
                final IJavaStratumLineBreakpoint stratumBreakpoint = (IJavaStratumLineBreakpoint) breakpoint;
                if (stratumBreakpoint.getLineNumber() == line) {
                    return stratumBreakpoint;
                }
            }
        }
    } else {
        String uriString = uri.toString();
        for (IBreakpoint breakpoint : breakpoints) {
            IMarker marker = breakpoint.getMarker();
            if (breakpoint instanceof IJavaStratumLineBreakpoint && marker.getResource().equals(res) && uriString.equals(marker.getAttribute(JarFileMarkerAnnotationModel.MARKER_URI))) {
                final IJavaStratumLineBreakpoint stratumBreakpoint = (IJavaStratumLineBreakpoint) breakpoint;
                if (stratumBreakpoint.getLineNumber() == line) {
                    return stratumBreakpoint;
                }
            }
        }
    }
    return null;
}
Also used : IJavaStratumLineBreakpoint(org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) IMarker(org.eclipse.core.resources.IMarker) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint)

Example 3 with IJavaStratumLineBreakpoint

use of org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint in project xtext-eclipse by eclipse.

the class StratumBreakpointAdapterFactory method toggleBreakpoints.

@Override
public void toggleBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
    if (!(part instanceof XtextEditor) || !(selection instanceof ITextSelection)) {
        return;
    }
    try {
        final XtextEditor xtextEditor = (XtextEditor) part;
        final IEditorInput editorInput = xtextEditor.getEditorInput();
        final IResource breakpointResource = breakpointUtil.getBreakpointResource(editorInput);
        final SourceRelativeURI breakpointUri = breakpointUtil.getBreakpointURI(editorInput);
        final int offset = ((ITextSelection) selection).getOffset();
        final int line = xtextEditor.getDocument().getLineOfOffset(offset) + 1;
        Data data = xtextEditor.getDocument().readOnly(new IUnitOfWork<Data, XtextResource>() {

            @Override
            public Data exec(XtextResource state) throws Exception {
                IResourceServiceProvider provider = state.getResourceServiceProvider();
                IStratumBreakpointSupport breakpointSupport = provider.get(IStratumBreakpointSupport.class);
                Data result = new Data();
                result.name = state.getURI().lastSegment();
                result.valid = breakpointSupport != null && breakpointSupport.isValidLineForBreakPoint(state, line);
                result.types = getClassNamePattern(state);
                result.lang = provider.get(LanguageInfo.class);
                result.sourceUri = state.getURI();
                if (editorInput.getAdapter(IClassFile.class) != null) {
                    result.classHandle = ((IClassFile) editorInput.getAdapter(IClassFile.class)).getHandleIdentifier();
                }
                return result;
            }
        });
        IJavaStratumLineBreakpoint existingBreakpoint = findExistingBreakpoint(breakpointResource, breakpointUri, line);
        if (existingBreakpoint != null) {
            existingBreakpoint.delete();
            return;
        }
        if (!data.valid || data.types == null)
            return;
        if (log.isDebugEnabled()) {
            log.debug("Types the breakpoint listens for : " + data.types);
        }
        final IRegion information = xtextEditor.getDocument().getLineInformation(line - 1);
        final int charStart = information.getOffset();
        final int charEnd = information.getOffset() + information.getLength();
        final String shortName = data.lang.getShortName();
        Map<String, Object> attributes = Maps.newHashMap();
        if (breakpointUri != null)
            attributes.put(JarFileMarkerAnnotationModel.MARKER_URI, breakpointUri.toString());
        attributes.put(ORG_ECLIPSE_JDT_DEBUG_CORE_SOURCE_NAME, data.name);
        attributes.put(ORG_ECLIPSE_XTEXT_XBASE_SOURCE_URI, data.sourceUri.toString());
        if (data.classHandle != null)
            attributes.put(ORG_ECLIPSE_XTEXT_XBASE_CLASS_HANDLE, data.classHandle);
        final IJavaStratumLineBreakpoint breakpoint = new XbaseLineBreakpoint(breakpointResource, shortName, data.types, line, charStart, charEnd, attributes);
        // make sure the class name pattern gets updated on change
        final IMarker marker = breakpoint.getMarker();
        final IWorkspace ws = marker.getResource().getWorkspace();
        IResourceChangeListener listener = new IResourceChangeListener() {

            @Override
            public void resourceChanged(IResourceChangeEvent event) {
                if (!marker.exists())
                    ws.removeResourceChangeListener(this);
                IResourceDelta delta = event.getDelta();
                if (delta == null)
                    return;
                final IResourceDelta findMember = event.getDelta().findMember(marker.getResource().getFullPath());
                if (findMember == null)
                    return;
                IResource res = findMember.getResource();
                if (res == null || !res.exists())
                    return;
                if (event.getType() == IResourceChangeEvent.PRE_DELETE) {
                    ws.removeResourceChangeListener(this);
                } else if (event.getType() == IResourceChangeEvent.POST_CHANGE && (findMember.getFlags() & IResourceDelta.CONTENT) != 0) {
                    String classNamePattern = getClassNamePattern(event.getResource());
                    try {
                        breakpoint.getMarker().setAttribute("org.eclipse.jdt.debug.pattern", classNamePattern);
                    } catch (CoreException e) {
                        log.info(e.getMessage(), e);
                    }
                }
            }
        };
        ws.addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE);
    } catch (BadLocationException e) {
        log.info(e.getMessage(), e);
    }
}
Also used : IClassFile(org.eclipse.jdt.core.IClassFile) XtextResource(org.eclipse.xtext.resource.XtextResource) IRegion(org.eclipse.jface.text.IRegion) IJavaStratumLineBreakpoint(org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IStratumBreakpointSupport(org.eclipse.xtext.debug.IStratumBreakpointSupport) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ITextSelection(org.eclipse.jface.text.ITextSelection) IJavaStratumLineBreakpoint(org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IMarker(org.eclipse.core.resources.IMarker) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource) BadLocationException(org.eclipse.jface.text.BadLocationException) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 4 with IJavaStratumLineBreakpoint

use of org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint in project xtext-eclipse by eclipse.

the class ConditionPage method createTypeSpecificEditors.

@Override
protected void createTypeSpecificEditors(Composite parent) {
    try {
        IJavaBreakpoint breakpoint = getBreakpoint();
        IMarker marker = breakpoint.getMarker();
        Object sourceUri = marker.getAttribute(StratumBreakpointAdapterFactory.ORG_ECLIPSE_XTEXT_XBASE_SOURCE_URI);
        if (sourceUri != null) {
            setTitle("Condition");
            final JavaBreakpointConditionEditor editor = new JavaBreakpointConditionEditor();
            editor.createControl(parent);
            editor.addPropertyListener(new IPropertyListener() {

                @Override
                public void propertyChanged(Object source, int propId) {
                    IStatus status = editor.getStatus();
                    if (status.isOK()) {
                        if (fPrevMessage != null) {
                            removeErrorMessage(fPrevMessage);
                            fPrevMessage = null;
                        }
                    } else {
                        fPrevMessage = status.getMessage();
                        addErrorMessage(fPrevMessage);
                    }
                }
            });
            URI uri = URI.createURI(String.valueOf(sourceUri));
            JavaBreakPointProvider breakPointProvider = registry.getResourceServiceProvider(uri).get(JavaBreakPointProvider.class);
            editor.setInput(breakPointProvider.getBreakpointWithJavaLocation((IJavaStratumLineBreakpoint) breakpoint));
            // set this editor only if it was correctly initialized
            this.editor = editor;
        }
    } catch (CoreException e) {
        setErrorMessage(e.getMessage());
    }
}
Also used : IJavaStratumLineBreakpoint(org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint) IJavaBreakpoint(org.eclipse.jdt.debug.core.IJavaBreakpoint) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) JavaBreakpointConditionEditor(org.eclipse.jdt.debug.ui.breakpoints.JavaBreakpointConditionEditor) IMarker(org.eclipse.core.resources.IMarker) URI(org.eclipse.emf.common.util.URI) IPropertyListener(org.eclipse.ui.IPropertyListener) IJavaStratumLineBreakpoint(org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint) IJavaBreakpoint(org.eclipse.jdt.debug.core.IJavaBreakpoint)

Aggregations

IJavaStratumLineBreakpoint (org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint)4 IMarker (org.eclipse.core.resources.IMarker)3 CoreException (org.eclipse.core.runtime.CoreException)3 IBreakpoint (org.eclipse.debug.core.model.IBreakpoint)2 URI (org.eclipse.emf.common.util.URI)2 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)2 IResource (org.eclipse.core.resources.IResource)1 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IStatus (org.eclipse.core.runtime.IStatus)1 IBreakpointManager (org.eclipse.debug.core.IBreakpointManager)1 IClassFile (org.eclipse.jdt.core.IClassFile)1 IJavaBreakpoint (org.eclipse.jdt.debug.core.IJavaBreakpoint)1 JavaBreakpointConditionEditor (org.eclipse.jdt.debug.ui.breakpoints.JavaBreakpointConditionEditor)1 AbstractJavaBreakpointEditor (org.eclipse.jdt.internal.debug.ui.breakpoints.AbstractJavaBreakpointEditor)1 LineBreakpointDetailPane (org.eclipse.jdt.internal.debug.ui.breakpoints.LineBreakpointDetailPane)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IRegion (org.eclipse.jface.text.IRegion)1