/** * Calls the SnippetsCompletionProcessor to contribute any relevant snippets for the offset. * * @param viewer * @param offset * @return */ protected Collection<ICompletionProposal> addSnippetProposals(ITextViewer viewer, int offset) { if (viewer != null && viewer.getSelectionProvider() != null) { PerformanceStats stats = null; if (PerformanceStats.isEnabled(SNIPPET_PERF)) { stats = PerformanceStats.getStats(SNIPPET_PERF, "SnippetsCompletionProcessor"); //$NON-NLS-1$ stats.startRun(); } ICompletionProposal[] snippets = new SnippetsCompletionProcessor().computeCompletionProposals(viewer, offset); if (stats != null) { stats.endRun(); } if (snippets == null) { return Collections.emptyList(); } return Arrays.asList(snippets); } return Collections.emptyList(); }
private IStatus stopMeter(final PerformanceStats stats, String operation) { if (MEASURE_PERFORMANCE) { stats.endRun(); if (stats.isFailure()) return createPerformanceStatus(operation); } return null; }
private PerformanceStats startMeter(String context, AbstractProposalSorter sorter) { final PerformanceStats stats; if (MEASURE_PERFORMANCE) { stats = PerformanceStats.getStats(PERFORMANCE_EVENT, sorter); stats.startRun(context); } else { stats = null; } return stats; }
private void makeActions() { final PerformanceStats stats= PerformanceStats.getStats(PERF_MAKE_ACTIONS, this); stats.startRun(); fActionSet= new PackageExplorerActionGroup(this); if (fWorkingSetModel != null) fActionSet.getWorkingSetActionGroup().setWorkingSetModel(fWorkingSetModel); stats.endRun(); }
private PerformanceStats startMeter(Object context, IJavaCompletionProposalComputer computer) { final PerformanceStats stats; if (MEASURE_PERFORMANCE) { stats= PerformanceStats.getStats(PERFORMANCE_EVENT, computer); stats.startRun(context.toString()); } else { stats= null; } if (fIsReportingDelay) { fStart= System.currentTimeMillis(); } return stats; }
private PerformanceStats startMeter(String context, AbstractProposalSorter sorter) { final PerformanceStats stats; if (MEASURE_PERFORMANCE) { stats= PerformanceStats.getStats(PERFORMANCE_EVENT, sorter); stats.startRun(context); } else { stats= null; } return stats; }
protected void codeComplete( org.eclipse.jdt.internal.compiler.env.ICompilationUnit cu, org.eclipse.jdt.internal.compiler.env.ICompilationUnit unitToSkip, int position, CompletionRequestor requestor, WorkingCopyOwner owner, ITypeRoot typeRoot, IProgressMonitor monitor) throws JavaModelException { if (requestor == null) { throw new IllegalArgumentException("Completion requestor cannot be null"); //$NON-NLS-1$ } PerformanceStats performanceStats = CompletionEngine.PERF ? PerformanceStats.getStats(JavaModelManager.COMPLETION_PERF, this) : null; if(performanceStats != null) { performanceStats.startRun(new String(cu.getFileName()) + " at " + position); //$NON-NLS-1$ } IBuffer buffer = getBuffer(); if (buffer == null) { return; } if (position < -1 || position > buffer.getLength()) { throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS)); } JavaProject project = (JavaProject) getJavaProject(); SearchableEnvironment environment = project.newSearchableNameEnvironment(owner); // set unit to skip environment.unitToSkip = unitToSkip; // code complete CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project, owner, monitor); engine.complete(cu, position, 0, typeRoot); if(performanceStats != null) { performanceStats.endRun(); } if (NameLookup.VERBOSE) { System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ } }
protected IJavaElement[] codeSelect(org.eclipse.jdt.internal.compiler.env.ICompilationUnit cu, int offset, int length, WorkingCopyOwner owner) throws JavaModelException { PerformanceStats performanceStats = SelectionEngine.PERF ? PerformanceStats.getStats(JavaModelManager.SELECTION_PERF, this) : null; if(performanceStats != null) { performanceStats.startRun(new String(cu.getFileName()) + " at [" + offset + "," + length + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } JavaProject project = (JavaProject)getJavaProject(); SearchableEnvironment environment = project.newSearchableNameEnvironment(owner); SelectionRequestor requestor= new SelectionRequestor(environment.nameLookup, this); IBuffer buffer = getBuffer(); if (buffer == null) { return requestor.getElements(); } int end= buffer.getLength(); if (offset < 0 || length < 0 || offset + length > end ) { throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS)); } // fix for 1FVXGDK SelectionEngine engine = new SelectionEngine(environment, requestor, project.getOptions(true), owner); engine.select(cu, offset, offset + length - 1); if(performanceStats != null) { performanceStats.endRun(); } if (NameLookup.VERBOSE) { System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " + environment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " + environment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ } return requestor.getElements(); }
private void notifyListeners( IJavaElementDelta deltaToNotify, int eventType, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { final ElementChangedEvent extraEvent = new ElementChangedEvent(deltaToNotify, eventType); for (int i = 0; i < listenerCount; i++) { if ((listenerMask[i] & eventType) != 0) { final IElementChangedListener listener = listeners[i]; long start = -1; if (VERBOSE) { System.out.print( "Listener #" + (i + 1) + "=" + listener.toString()); // $NON-NLS-1$//$NON-NLS-2$ start = System.currentTimeMillis(); } // wrap callbacks with Safe runnable for subsequent listeners to be called when some are // causing grief SafeRunner.run( new ISafeRunnable() { public void handleException(Throwable exception) { Util.log( exception, "Exception occurred in listener of Java element change notification"); // $NON-NLS-1$ } public void run() throws Exception { PerformanceStats stats = null; if (PERF) { // stats = PerformanceStats.getStats(JavaModelManager.DELTA_LISTENER_PERF, // listener); // stats.startRun(); } listener.elementChanged(extraEvent); if (PERF) { stats.endRun(); } } }); if (VERBOSE) { System.out.println( " -> " + (System.currentTimeMillis() - start) + "ms"); // $NON-NLS-1$ //$NON-NLS-2$ } } } }
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset, char activationChar, boolean autoActivated) { PerformanceStats stats = null; try { if (PerformanceStats.isEnabled(PERFORMANCE_EVENT_PREFIX)) { stats = PerformanceStats.getStats(PERFORMANCE_EVENT_PREFIX, this); stats.startRun(); } Collection<ICompletionProposal> rubleProposals = addRubleProposals(viewer, offset); Collection<ICompletionProposal> snippetProposals = addSnippetProposals(viewer, offset); Collection<ICompletionProposal> proposals = CollectionsUtil.union(rubleProposals, snippetProposals); ICompletionProposal[] others = this.doComputeCompletionProposals(viewer, offset, activationChar, autoActivated); // create empty array to simplify logic if (others == null) { others = NO_PROPOSALS; } if (IdeLog.isTraceEnabled(CommonEditorPlugin.getDefault(), IDebugScopes.CONTENT_ASSIST)) { IdeLog.logTrace(CommonEditorPlugin.getDefault(), MessageFormat.format( "Generated {0} ruble proposals, {0} snippet proposals, and {0} language proposals", //$NON-NLS-1$ rubleProposals.size(), snippetProposals.size(), others.length), IDebugScopes.CONTENT_ASSIST); } // Combine the two ICompletionProposal[] combined = new ICompletionProposal[proposals.size() + others.length]; proposals.toArray(combined); System.arraycopy(others, 0, combined, proposals.size(), others.length); if (IdeLog.isTraceEnabled(CommonEditorPlugin.getDefault(), IDebugScopes.CONTENT_ASSIST)) { IdeLog.logTrace(CommonEditorPlugin.getDefault(), MessageFormat.format("Combined {0} total proposals", combined.length), //$NON-NLS-1$ IDebugScopes.CONTENT_ASSIST); } // sort proposals using default mechanism sortProposals(combined); // selection currently is set to first item in list return combined; } finally { if (stats != null) { stats.endRun(); } } }