/** * Safely computes completion proposals of all computers of this category through their * extension. If an extension is disabled, throws an exception or otherwise does not adhere to * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled. * * @param context the invocation context passed on to the extension * @param partition the partition type where to invocation occurred * @param monitor the progress monitor passed on to the extension * @return the list of computed completion proposals (element type: * {@link org.eclipse.jface.text.contentassist.ICompletionProposal}) */ public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) { fLastError= null; List<ICompletionProposal> result= new ArrayList<>(); List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition)); for (CompletionProposalComputerDescriptor desc : descriptors) { if (desc.getCategory() == this) result.addAll(desc.computeCompletionProposals(context, monitor)); if (fLastError == null && desc.getErrorMessage() != null) fLastError= desc.getErrorMessage(); } return result; }
if (!isEnabled()) return Collections.EMPTY_LIST; IJavaCompletionProposalComputer computer= getComputer(); if (computer == null) // not active yet return Collections.EMPTY_LIST; PerformanceStats stats= startMeter(context, computer); List proposals= computer.computeContextInformation(context, monitor); stopMeter(stats, COMPUTE_CONTEXT_INFORMATION); status= createAPIViolationStatus(COMPUTE_CONTEXT_INFORMATION); } catch (InvalidRegistryObjectException x) { status= createExceptionStatus(x); } catch (CoreException x) { status= createExceptionStatus(x); } catch (RuntimeException x) { status= createExceptionStatus(x); } finally { monitor.done();
private IStatus createExceptionStatus(RuntimeException x) { // misbehaving extension - log String blame= createBlameMessage(); String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_runtime_ex; return new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, blame + " " + reason, x); //$NON-NLS-1$ }
/** * Returns a cached instance of the computer as described in the * extension's xml. The computer is * {@link #createComputer() created} the first time that this method * is called and then cached. * * @return a new instance of the completion proposal computer as * described by this descriptor * @throws CoreException if the creation fails * @throws InvalidRegistryObjectException if the extension is not * valid any longer (e.g. due to plug-in unloading) */ private synchronized IJavaCompletionProposalComputer getComputer() throws CoreException, InvalidRegistryObjectException { if (fComputer == null && (fActivate || isPluginLoaded())) fComputer= createComputer(); return fComputer; }
if (!isEnabled()) return; IJavaCompletionProposalComputer computer= getComputer(); if (computer == null) // not active yet return; PerformanceStats stats= startMeter(SESSION_STARTED, computer); computer.sessionStarted(); stopMeter(stats, SESSION_ENDED); status= createExceptionStatus(x); } catch (CoreException x) { status= createExceptionStatus(x); } catch (RuntimeException x) { status= createExceptionStatus(x);
/** * Safely computes context information objects of all computers of this category through their * extension. If an extension is disabled, throws an exception or otherwise does not adhere to * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled. * * @param context the invocation context passed on to the extension * @param partition the partition type where to invocation occurred * @param monitor the progress monitor passed on to the extension * @return the list of computed context information objects (element type: * {@link org.eclipse.jface.text.contentassist.IContextInformation}) */ public List computeContextInformation(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) { fLastError= null; List result= new ArrayList(); List descriptors= new ArrayList(fRegistry.getProposalComputerDescriptors(partition)); for (Iterator it= descriptors.iterator(); it.hasNext();) { CompletionProposalComputerDescriptor desc= (CompletionProposalComputerDescriptor) it.next(); if (desc.getCategory() == this) result.addAll(desc.computeContextInformation(context, monitor)); if (fLastError == null) fLastError= desc.getErrorMessage(); } return result; }
IConfigurationElement element= (IConfigurationElement) iter.next(); try { CompletionProposalComputerDescriptor desc= new CompletionProposalComputerDescriptor(element, this, categories); Set partitions= desc.getPartitions(); for (Iterator it= partitions.iterator(); it.hasNext();) { String partition= (String) it.next();
private boolean isPluginLoaded() { Bundle bundle= getBundle(); return bundle != null && bundle.getState() == Bundle.ACTIVE; }
private void stopMeter(final PerformanceStats stats, String operation) { if (MEASURE_PERFORMANCE) { stats.endRun(); if (stats.isFailure()) { IStatus status= createPerformanceStatus(operation); fRegistry.informUser(this, status); return; } } if (fIsReportingDelay) { long current= System.currentTimeMillis(); if (current - fStart > MAX_DELAY) { IStatus status= createPerformanceStatus(operation); fRegistry.informUser(this, status); } } }
IExtension extension= element.getDeclaringExtension(); fId= extension.getUniqueIdentifier(); checkNotNull(fId, "id"); //$NON-NLS-1$ for (int i= 0; i < children.length; i++) { String type= children[i].getAttribute(TYPE); checkNotNull(type, TYPE); partitions.add(type); checkNotNull(fClass, CLASS);
/** * Safely computes context information objects of all computers of this category through their * extension. If an extension is disabled, throws an exception or otherwise does not adhere to * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled. * * @param context the invocation context passed on to the extension * @param partition the partition type where to invocation occurred * @param monitor the progress monitor passed on to the extension * @return the list of computed context information objects (element type: * {@link org.eclipse.jface.text.contentassist.IContextInformation}) */ public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) { fLastError= null; List<IContextInformation> result= new ArrayList<>(); List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition)); for (CompletionProposalComputerDescriptor desc : descriptors) { if (desc.getCategory() == this && (isIncluded() || isSeparateCommand())) result.addAll(desc.computeContextInformation(context, monitor)); if (fLastError == null) fLastError= desc.getErrorMessage(); } return result; }
/** * Returns a cached instance of the computer as described in the * extension's xml. If the computer is not yet created and * <code>canCreate</code> is <code>true</code> then {@link #createComputer()} * is called and the result cached. * * @param canCreate <code>true</code> if the proposal computer can be created * @return a new instance of the completion proposal computer as * described by this descriptor * @throws CoreException if the creation fails * @throws InvalidRegistryObjectException if the extension is not * valid any longer (e.g. due to plug-in unloading) */ private synchronized IJavaCompletionProposalComputer getComputer(boolean canCreate) throws CoreException, InvalidRegistryObjectException { if (fComputer == null && canCreate && !fTriedLoadingComputer && (fActivate || isPluginLoaded())) { fTriedLoadingComputer= true; fComputer= createComputer(); } return fComputer; }
IConfigurationElement element= iter.next(); try { CompletionProposalComputerDescriptor desc= new CompletionProposalComputerDescriptor(element, this, categories); Set<String> partitions= desc.getPartitions(); for (Iterator<String> it= partitions.iterator(); it.hasNext();) { String partition= it.next();
private boolean isPluginLoaded() { Bundle bundle= getBundle(); return bundle != null && bundle.getState() == Bundle.ACTIVE; }
private void stopMeter(final PerformanceStats stats, String operation) { if (MEASURE_PERFORMANCE) { stats.endRun(); if (stats.isFailure()) { IStatus status= createPerformanceStatus(operation); fRegistry.informUser(this, status); return; } } if (fIsReportingDelay) { long current= System.currentTimeMillis(); if (current - fStart > MAX_DELAY) { IStatus status= createPerformanceStatus(operation); fRegistry.informUser(this, status); } } }
IExtension extension= element.getDeclaringExtension(); fId= extension.getUniqueIdentifier(); checkNotNull(fId, "id"); //$NON-NLS-1$ for (int i= 0; i < children.length; i++) { String type= children[i].getAttribute(TYPE); checkNotNull(type, TYPE); partitions.add(type); checkNotNull(fClass, CLASS);
/** * Notifies the described extension of a proposal computation session end. * <p><em> * Note: This method is called every time code assist is invoked and * is <strong>not</strong> filtered by partition type. * </em></p> */ public void sessionEnded() { if (!isEnabled()) return; IStatus status; try { IJavaCompletionProposalComputer computer= getComputer(); if (computer == null) // not active yet return; PerformanceStats stats= startMeter(SESSION_ENDED, computer); computer.sessionEnded(); stopMeter(stats, SESSION_ENDED); return; } catch (InvalidRegistryObjectException x) { status= createExceptionStatus(x); } catch (CoreException x) { status= createExceptionStatus(x); } catch (RuntimeException x) { status= createExceptionStatus(x); } fRegistry.informUser(this, status); }
/** * Safely computes context information objects of all computers of this category through their * extension. If an extension is disabled, throws an exception or otherwise does not adhere to * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled. * * @param context the invocation context passed on to the extension * @param partition the partition type where to invocation occurred * @param monitor the progress monitor passed on to the extension * @return the list of computed context information objects (element type: * {@link org.eclipse.jface.text.contentassist.IContextInformation}) */ public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) { fLastError= null; List<IContextInformation> result= new ArrayList<>(); List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition)); for (CompletionProposalComputerDescriptor desc : descriptors) { if (desc.getCategory() == this && (isIncluded() || isSeparateCommand())) result.addAll(desc.computeContextInformation(context, monitor)); if (fLastError == null) fLastError= desc.getErrorMessage(); } return result; }
/** * Safely computes completion proposals of all computers of this category through their * extension. If an extension is disabled, throws an exception or otherwise does not adhere to * the contract described in {@link IJavaCompletionProposalComputer}, it is disabled. * * @param context the invocation context passed on to the extension * @param partition the partition type where to invocation occurred * @param monitor the progress monitor passed on to the extension * @return the list of computed completion proposals (element type: * {@link org.eclipse.jface.text.contentassist.ICompletionProposal}) */ public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) { fLastError= null; List<ICompletionProposal> result= new ArrayList<>(); List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition)); for (CompletionProposalComputerDescriptor desc : descriptors) { if (desc.getCategory() == this) result.addAll(desc.computeCompletionProposals(context, monitor)); if (fLastError == null && desc.getErrorMessage() != null) fLastError= desc.getErrorMessage(); } return result; }
private IStatus createExceptionStatus(CoreException x) { // unable to instantiate the extension - log String blame= createBlameMessage(); String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_instantiation; return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, blame + " " + reason, x); //$NON-NLS-1$ }