Search in sources :

Example 1 with IBreakpointProvider

use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.

the class BreakpointRulerAction method getResource.

public static final IResource getResource(IEditorInput input) {
    IResource resource = null;
    if (input instanceof IFileEditorInput)
        resource = ((IFileEditorInput) input).getFile();
    if (resource == null)
        resource = input.getAdapter(IFile.class);
    if (resource == null)
        resource = input.getAdapter(IResource.class);
    IEditorPart editorPart = null;
    if (resource == null) {
        IWorkbench workbench = SSEUIPlugin.getDefault().getWorkbench();
        if (workbench != null) {
            IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
            if (window != null) {
                IPartService service = window.getPartService();
                if (service != null) {
                    Object part = service.getActivePart();
                    if (part != null && part instanceof IEditorPart) {
                        editorPart = (IEditorPart) part;
                        if (editorPart != null) {
                            IStructuredModel model = null;
                            ITextEditor textEditor = null;
                            try {
                                if (editorPart instanceof ITextEditor) {
                                    textEditor = (ITextEditor) editorPart;
                                }
                                if (textEditor == null) {
                                    textEditor = editorPart.getAdapter(ITextEditor.class);
                                }
                                if (textEditor != null) {
                                    IDocument textDocument = textEditor.getDocumentProvider().getDocument(input);
                                    model = StructuredModelManager.getModelManager().getExistingModelForRead(textDocument);
                                    if (model != null) {
                                        resource = BreakpointProviderBuilder.getInstance().getResource(input, model.getContentTypeIdentifier(), getFileExtension(input));
                                    }
                                }
                                if (resource == null) {
                                    IBreakpointProvider[] providers = BreakpointProviderBuilder.getInstance().getBreakpointProviders(editorPart, null, getFileExtension(input));
                                    for (int i = 0; i < providers.length && resource == null; i++) {
                                        resource = providers[i].getResource(input);
                                    }
                                }
                            } catch (Exception e) {
                                Logger.logException(e);
                            } finally {
                                if (model != null) {
                                    model.releaseFromRead();
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return resource;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEditorPart(org.eclipse.ui.IEditorPart) IPartService(org.eclipse.ui.IPartService) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) CoreException(org.eclipse.core.runtime.CoreException) BadLocationException(org.eclipse.jface.text.BadLocationException) IWorkbench(org.eclipse.ui.IWorkbench) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IBreakpointProvider(org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider) IResource(org.eclipse.core.resources.IResource) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with IBreakpointProvider

use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.

the class BreakpointProviderBuilder method getBreakpointProviders.

/**
 * Returns an array of breakpoint providers for a specified content type
 * handler
 *
 * @param handler
 *            a content type handler
 * @param ext
 *            file extension
 * @return IBreakpointProvider[]
 */
public IBreakpointProvider[] getBreakpointProviders(IEditorPart editorpart, String contentTypeID, String ext) {
    initCache();
    // Get breakpoint providers for this content type handler
    IBreakpointProvider[] providers1 = new IBreakpointProvider[0];
    IContentType contentType = Platform.getContentTypeManager().getContentType(contentTypeID);
    List holdProviders = new ArrayList(2);
    while (contentType != null) {
        IBreakpointProvider[] providers = (IBreakpointProvider[]) map.get(contentType.getId());
        if (providers == null) {
            providers = createBreakpointProviders(ATT_CONTENT_TYPES, contentType.getId());
            if (providers != null) {
                map.put(contentType.getId(), providers);
            }
        }
        // providers were retrieved from cache or newly created
        if (providers != null) {
            holdProviders.addAll(Arrays.asList(providers));
        }
        contentType = contentType.getBaseType();
    }
    providers1 = (IBreakpointProvider[]) holdProviders.toArray(new IBreakpointProvider[holdProviders.size()]);
    // Get breakpoint providers for this extension
    IBreakpointProvider[] providers2 = new IBreakpointProvider[0];
    if (ext != null) {
        providers2 = (IBreakpointProvider[]) map.get(ext);
        if (providers2 == null) {
            providers2 = createBreakpointProviders(ATT_EXTENSIONS, ext);
            if (providers2 != null) {
                map.put(ext, providers2);
            }
        }
    }
    // create single hash set to remove duplication
    Set s = new HashSet();
    s.addAll(Arrays.asList(providers1));
    s.addAll(Arrays.asList(providers2));
    // create IBreakpointProvider[] to return
    IBreakpointProvider[] providers = new IBreakpointProvider[s.size()];
    Iterator itr = s.iterator();
    int i = 0;
    ISourceEditingTextTools tools = null;
    if (editorpart != null && itr.hasNext())
        tools = editorpart.getAdapter(ISourceEditingTextTools.class);
    while (itr.hasNext()) {
        providers[i] = (IBreakpointProvider) itr.next();
        providers[i].setSourceEditingTextTools(tools);
        i++;
    }
    return providers;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IContentType(org.eclipse.core.runtime.content.IContentType) ArrayList(java.util.ArrayList) List(java.util.List) ISourceEditingTextTools(org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools) IBreakpointProvider(org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider) HashSet(java.util.HashSet)

Example 3 with IBreakpointProvider

use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.

the class BreakpointProviderBuilder method getResource.

/**
 * Returns corresponding resource from given parameters
 *
 * @param input
 * @param handler
 * @param ext
 * @return IResource
 */
public IResource getResource(IEditorInput input, String contentType, String ext) {
    IBreakpointProvider[] providers = getBreakpointProviders(null, contentType, ext);
    IResource res = null;
    for (int i = 0; i < providers.length; i++) {
        res = providers[i].getResource(input);
        if (res != null) {
            break;
        }
    }
    return res;
}
Also used : IBreakpointProvider(org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider) IResource(org.eclipse.core.resources.IResource)

Example 4 with IBreakpointProvider

use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.

the class BreakpointProviderBuilder method createBreakpointProviders.

/*
	 * Creates an array of breakpoint providers matching the given key to the
	 * value of the IConfigurationElement attribute "attrName" @return
	 * IBreakpointProvider[]
	 */
protected IBreakpointProvider[] createBreakpointProviders(String attrName, String key) {
    if (cache == null)
        return new IBreakpointProvider[0];
    final int num = cache.size();
    if (num == 0)
        return new IBreakpointProvider[0];
    IBreakpointProvider[] bp = new IBreakpointProvider[num];
    int j = 0;
    for (int i = 0; i < num; i++) {
        Object obj = cache.get(i);
        if (!(obj instanceof IConfigurationElement))
            continue;
        IConfigurationElement element = (IConfigurationElement) obj;
        if (!TAG_PROVIDER.equals(element.getName()))
            continue;
        boolean doCreate = false;
        String attrValues = element.getAttribute(attrName);
        if (attrValues != null) {
            // $NON-NLS-1$
            StringTokenizer tokenizer = new StringTokenizer(attrValues, ",");
            while (tokenizer.hasMoreTokens()) {
                String type = tokenizer.nextToken();
                if (type.trim().equalsIgnoreCase(key.trim())) {
                    doCreate = true;
                    break;
                }
            }
        }
        if (doCreate) {
            IBreakpointProvider b = createBreakpointProvider(element);
            if (b != null) {
                bp[j] = b;
                j++;
            }
        }
    }
    IBreakpointProvider[] bp2 = new IBreakpointProvider[j];
    for (int i = 0; i < j; i++) {
        bp2[i] = bp[i];
    }
    return bp2;
}
Also used : StringTokenizer(com.ibm.icu.util.StringTokenizer) IBreakpointProvider(org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 5 with IBreakpointProvider

use of org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider in project webtools.sourceediting by eclipse.

the class ToggleBreakpointAction method createBreakpoints.

protected boolean createBreakpoints(int lineNumber) {
    /*
		 * Note: we'll always allow processing to continue, even for a "read
		 * only" IStorageEditorInput, for the ActiveScript debugger. But this
		 * means sometimes the ActiveScript provider might get an input from
		 * CVS or something that is not related to debugging.
		 */
    ITextEditor editor = getTextEditor();
    IEditorInput input = editor.getEditorInput();
    IDocument document = editor.getDocumentProvider().getDocument(input);
    if (document == null)
        return false;
    String contentType = getContentType(document);
    IBreakpointProvider[] providers = BreakpointProviderBuilder.getInstance().getBreakpointProviders(editor, contentType, getFileExtension(input));
    int pos = -1;
    ISourceEditingTextTools tools = editor.getAdapter(ISourceEditingTextTools.class);
    if (tools != null) {
        pos = tools.getCaretOffset();
    }
    final int n = providers.length;
    List<IStatus> errors = new ArrayList<>(0);
    for (int i = 0; i < n; i++) {
        try {
            if (Debug.debugBreakpoints)
                // $NON-NLS-1$
                System.out.println(providers[i].getClass().getName() + " adding breakpoint to line " + lineNumber);
            IStatus status = providers[i].addBreakpoint(document, input, lineNumber, pos);
            if (status != null && !status.isOK()) {
                errors.add(status);
            }
        } catch (CoreException e) {
            errors.add(e.getStatus());
        } catch (Exception t) {
            // $NON-NLS-1$
            Logger.logException("exception while adding breakpoint", t);
        }
    }
    IStatus status = null;
    if (errors.size() > 0) {
        Shell shell = editor.getSite().getShell();
        if (errors.size() > 1) {
            // $NON-NLS-1$
            status = new MultiStatus(SSEUIPlugin.ID, IStatus.OK, errors.toArray(new IStatus[0]), SSEUIMessages.ManageBreakpoints_error_adding_message1, null);
        } else {
            status = errors.get(0);
        }
        if ((status.getSeverity() > IStatus.INFO) || (Platform.inDebugMode() && !status.isOK())) {
            Platform.getLog(SSEUIPlugin.getDefault().getBundle()).log(status);
        }
        /*
			 * Show for conditions more severe than INFO or when no
			 * breakpoints were created
			 */
        if (status.getSeverity() > IStatus.INFO && getBreakpoints(getMarkers()).length < 1) {
            // $NON-NLS-1$ //$NON-NLS-2$
            ErrorDialog.openError(shell, SSEUIMessages.ManageBreakpoints_error_adding_title1, status.getMessage(), status);
            return false;
        }
    }
    /*
		 * Although no errors were reported, no breakpoints exist on this line
		 * after having run the existing providers. Run the fallback action.
		 */
    if ((status == null || status.getSeverity() < IStatus.WARNING) && fFallbackAction != null && !hasMarkers()) {
        if (fFallbackAction instanceof ISelectionListener) {
            ((ISelectionListener) fFallbackAction).selectionChanged(null, null);
        }
        fFallbackAction.run();
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) CoreException(org.eclipse.core.runtime.CoreException) ISelectionListener(org.eclipse.ui.ISelectionListener) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) ISourceEditingTextTools(org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools) IBreakpointProvider(org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IBreakpointProvider (org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.IBreakpointProvider)5 ArrayList (java.util.ArrayList)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 IBreakpoint (org.eclipse.debug.core.model.IBreakpoint)2 IDocument (org.eclipse.jface.text.IDocument)2 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)2 ISourceEditingTextTools (org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools)2 StringTokenizer (com.ibm.icu.util.StringTokenizer)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 IContentType (org.eclipse.core.runtime.content.IContentType)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorInput (org.eclipse.ui.IEditorInput)1