Search in sources :

Example 1 with JavaEditor

use of org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor in project webtools.sourceediting by eclipse.

the class RunCodeHandler method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands
	 * .ExecutionEvent)
	 */
public Object execute(final ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof JavaEditor)) {
        return null;
    }
    doExecute((IFile) HandlerUtil.getActiveEditor(event).getEditorInput().getAdapter(IFile.class));
    return null;
}
Also used : IEditorPart(org.eclipse.ui.IEditorPart) JavaEditor(org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor)

Example 2 with JavaEditor

use of org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor in project webtools.sourceediting by eclipse.

the class ContentAssistTestUtilities method getProposals.

/**
 * <p>
 * Invoke content assist on the given editor at the given offset, for the given number of pages
 * and return the results of each page
 * </p>
 */
private static ICompletionProposal[][] getProposals(AbstractTextEditor editor, int offset, int pageCount) throws Exception {
    ICompletionProposal[][] pages = null;
    /* if JS editor
		 * else if HTML editor */
    if (editor instanceof JavaEditor) {
        // setup the viewer
        ISourceViewer viewer = ((JavaEditor) editor).getViewer();
        JavaScriptSourceViewerConfiguration configuration = new JavaScriptSourceViewerConfiguration(JavaScriptPlugin.getDefault().getJavaTextTools().getColorManager(), JavaScriptPlugin.getDefault().getCombinedPreferenceStore(), editor, IJavaScriptPartitions.JAVA_PARTITIONING);
        ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
        // get the processor
        String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
        IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
        // fire content assist session about to start
        Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionBeginEvent", new Class[] { boolean.class });
        privateFireSessionBeginEventMethod.setAccessible(true);
        privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] { Boolean.TRUE });
        // get content assist suggestions
        pages = new ICompletionProposal[pageCount][];
        for (int p = 0; p < pageCount; ++p) {
            pages[p] = processor.computeCompletionProposals(viewer, offset);
        }
        // fire content assist session ending
        Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
        privateFireSessionEndEventMethod.setAccessible(true);
        privateFireSessionEndEventMethod.invoke(contentAssistant, null);
    } else if (editor instanceof StructuredTextEditor) {
        // setup the viewer
        StructuredTextViewer viewer = ((StructuredTextEditor) editor).getTextViewer();
        StructuredTextViewerConfigurationHTML configuration = new StructuredTextViewerConfigurationHTML();
        ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer);
        viewer.configure(configuration);
        viewer.setSelectedRange(offset, 0);
        // get the processor
        String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
        IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
        // fire content assist session about to start
        Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionBeginEvent", new Class[] { boolean.class });
        privateFireSessionBeginEventMethod.setAccessible(true);
        privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] { Boolean.TRUE });
        // get content assist suggestions
        pages = new ICompletionProposal[pageCount][];
        for (int p = 0; p < pageCount; ++p) {
            pages[p] = processor.computeCompletionProposals(viewer, offset);
        }
        // fire content assist session ending
        Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null);
        privateFireSessionEndEventMethod.setAccessible(true);
        privateFireSessionEndEventMethod.invoke(contentAssistant, null);
    }
    return pages;
}
Also used : StructuredTextViewerConfigurationHTML(org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) Method(java.lang.reflect.Method) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) JavaEditor(org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) JavaScriptSourceViewerConfiguration(org.eclipse.wst.jsdt.ui.text.JavaScriptSourceViewerConfiguration) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Aggregations

JavaEditor (org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaEditor)2 Method (java.lang.reflect.Method)1 ContentAssistant (org.eclipse.jface.text.contentassist.ContentAssistant)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 IContentAssistProcessor (org.eclipse.jface.text.contentassist.IContentAssistProcessor)1 IContentAssistant (org.eclipse.jface.text.contentassist.IContentAssistant)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 IEditorPart (org.eclipse.ui.IEditorPart)1 StructuredTextViewerConfigurationHTML (org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML)1 JavaScriptSourceViewerConfiguration (org.eclipse.wst.jsdt.ui.text.JavaScriptSourceViewerConfiguration)1 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)1 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)1