private static Object doSourceLookup(Object object, ISourceLocator sourceLocator) { if (sourceLocator instanceof ISourceLookupDirector) { ISourceLookupDirector director = (ISourceLookupDirector) sourceLocator; return director.getSourceElement(object); } return null; }
/** * Returns the source element corresponding to the given object or <code>null</code> if none, in * the context of the given launch. * * @param launch provides source locator * @param object object to resolve source element for * @return corresponding source element or <code>null</code> * @throws CoreException */ public static Object resolveSourceElement(Object object, ILaunch launch) throws CoreException { ISourceLocator sourceLocator = launch.getSourceLocator(); if (sourceLocator instanceof ISourceLookupDirector) { ISourceLookupDirector director = (ISourceLookupDirector) sourceLocator; Object[] objects = director.findSourceElements(object); if (objects.length > 0) { return objects[0]; } } return null; }
private ISourceLocator getDefaultSourceLocator() { if (fDefaultSourceLocator == null) { try { fDefaultSourceLocator = DebugPlugin.getDefault().getLaunchManager().newSourceLocator(DEFAULT_SOURCE_LOCATOR_ID); if (fDefaultSourceLocator instanceof ISourceLookupDirector) { ISourceLookupDirector sourceLookupDirector = (ISourceLookupDirector) fDefaultSourceLocator; sourceLookupDirector.initializeParticipants(); sourceLookupDirector.setSourceContainers( new ISourceContainer[] { new DefaultSourceContainer() { /* * (non-Javadoc) * @see org.eclipse.debug.core.sourcelookup.containers. * DefaultSourceContainer#createSourceContainers() */ @Override protected ISourceContainer[] createSourceContainers() throws CoreException { ISourcePathComputer sourcePathComputer = null; ISourceLookupDirector director = getDirector(); if (director != null) { sourcePathComputer = director.getSourcePathComputer(); } if (sourcePathComputer != null) { return sourcePathComputer.computeSourceContainers(null, null); } return EMPTY_CONTAINERS; } } }); ISourcePathComputer sourcePathComputer = DebugPlugin.getDefault() .getLaunchManager() .getSourcePathComputer(DEFAULT_SOURCE_PATH_COMPUTER_ID); sourceLookupDirector.setSourcePathComputer(sourcePathComputer); } } catch (CoreException e) { IdeLog.logError(JSDebugUIPlugin.getDefault(), e); } } return fDefaultSourceLocator; }
@Override public boolean canAddSourceContainers(final ISourceLookupDirector director) { final ISourceContainer[] containers = director.getSourceContainers(); for (final ISourceContainer container : containers) { if (container.getType().getId().equals(AllRProjectsSourceContainer.TYPE_ID)) { return false; } } return true; }
/** * Removes types without browsers from the provided list of types. * * @param types the complete list of source container types * @return the list of source container types that have browsers */ private ISourceContainerType[] filterTypes(ISourceContainerType[] types) { ArrayList validTypes = new ArrayList(); for (int i = 0; i < types.length; i++) { ISourceContainerType type = types[i]; if (fDirector.supportsSourceContainerType(type)) { ISourceContainerBrowser sourceContainerBrowser = DebugUITools.getSourceContainerBrowser(type.getId()); if (sourceContainerBrowser != null && sourceContainerBrowser.canAddSourceContainers(fDirector)) { validTypes.add(type); } } } return (ISourceContainerType[]) validTypes.toArray(new ISourceContainerType[validTypes.size()]); }