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;
}
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;
}
Aggregations