Search in sources :

Example 46 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project eclipse.platform.text by eclipse.

the class ExtensionsRegistry method initialize.

/**
 * Initializes this registry. It retrieves all implementers of the given
 * extension point and remembers those implementers based on the
 * file name extensions in the given map.
 *
 * @param extensionPointName the name of the extension point
 * @param childElementName the name of the child elements
 * @param isContentTypeId the child element is a content type id
 * @param descriptors the map to be filled
 */
private void initialize(String extensionPointName, String childElementName, boolean isContentTypeId, Map<Object, Set<IConfigurationElement>> descriptors) {
    IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(FileBuffersPlugin.PLUGIN_ID, extensionPointName);
    if (extensionPoint == null) {
        log(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, 0, NLSUtility.format(FileBuffersMessages.ExtensionsRegistry_error_extensionPointNotFound, extensionPointName), null));
        return;
    }
    IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
    for (IConfigurationElement element : elements) {
        if (isContentTypeId)
            readContentType(childElementName, element, descriptors);
        else
            read(childElementName, element, descriptors);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 47 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project eclipse.platform.text by eclipse.

the class ExtensionsRegistry method doGetDocumentSetupParticipants.

/**
 * Returns the set of setup participants for the given content types.
 *
 * @param contentTypes the contentTypes to be used for lookup
 * @return the sharable set of document setup participants
 */
private List<IDocumentSetupParticipant> doGetDocumentSetupParticipants(IContentType[] contentTypes) {
    Set<IConfigurationElement> resultSet = new HashSet<>();
    int i = 0;
    while (i < contentTypes.length) {
        Set<IConfigurationElement> set = fSetupParticipantDescriptors.get(new ContentTypeAdapter(contentTypes[i++]));
        if (set != null)
            resultSet.addAll(set);
    }
    List<IDocumentSetupParticipant> participants = new ArrayList<>();
    Iterator<IConfigurationElement> e = resultSet.iterator();
    while (e.hasNext()) {
        IConfigurationElement entry = e.next();
        IDocumentSetupParticipant participant = getExtension(entry, fSetupParticipants, IDocumentSetupParticipant.class);
        if (participant != null)
            participants.add(participant);
    }
    return participants.isEmpty() ? null : participants;
}
Also used : ArrayList(java.util.ArrayList) IDocumentSetupParticipant(org.eclipse.core.filebuffers.IDocumentSetupParticipant) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) HashSet(java.util.HashSet)

Example 48 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project linuxtools by eclipse.

the class STSymbolManager method getBinaryParser.

/**
 * Retrieve the list of binary parsers defined for the given project.
 * @param project The project.
 * @return The binary parsers for this project.
 */
private List<IBinaryParser> getBinaryParser(IProject project) {
    List<IBinaryParser> parsers = new LinkedList<>();
    ICProjectDescription projDesc = CCorePlugin.getDefault().getProjectDescription(project);
    if (projDesc == null) {
        return parsers;
    }
    ICConfigurationDescription[] cfgs = projDesc.getConfigurations();
    String[] binaryParserIds = CoreModelUtil.getBinaryParserIds(cfgs);
    IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CCorePlugin.BINARY_PARSER_SIMPLE_ID);
    for (String id : binaryParserIds) {
        IExtension extension = extensionPoint.getExtension(id);
        if (extension != null) {
            IConfigurationElement[] element = extension.getConfigurationElements();
            for (IConfigurationElement element2 : element) {
                if (element2.getName().equalsIgnoreCase("cextension")) {
                    // $NON-NLS-1$
                    try {
                        // $NON-NLS-1$
                        IBinaryParser parser = (IBinaryParser) element2.createExecutableExtension("run");
                        if (parser != null) {
                            parsers.add(parser);
                        }
                    } catch (CoreException e) {
                    // TODO: handle exception ?
                    }
                }
            }
        }
    }
    return parsers;
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) LinkedList(java.util.LinkedList) IBinaryParser(org.eclipse.cdt.core.IBinaryParser) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) IExtension(org.eclipse.core.runtime.IExtension) ICConfigurationDescription(org.eclipse.cdt.core.settings.model.ICConfigurationDescription)

Example 49 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project linuxtools by eclipse.

the class ProviderFramework method getTabGroupProvider.

/**
 * Get a profiling tab that provides the specified type of profiling. This
 * looks through extensions of the extension point
 * <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code> that have a
 * specific type attribute.
 *
 * @param type A profiling type (eg. memory, snapshot, timing, etc.)
 * @return a tab that implements <code>ProfileLaunchConfigurationTabGroup</code>
 * and provides the necessary profiling type, or <code>null</code> if none could be found.
 * @since 2.0
 */
public static ProfileLaunchConfigurationTabGroup getTabGroupProvider(String type) {
    IConfigurationElement[] configs = getConfigurationElements();
    for (IConfigurationElement config : configs) {
        if (config.getName().equals("provider")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String currentType = config.getAttribute("type");
            // $NON-NLS-1$
            String shortcut = config.getAttribute("tabgroup");
            if (currentType != null && shortcut != null && currentType.equals(type)) {
                try {
                    Object obj = config.createExecutableExtension(// $NON-NLS-1$
                    "tabgroup");
                    if (obj instanceof ProfileLaunchConfigurationTabGroup) {
                        return (ProfileLaunchConfigurationTabGroup) obj;
                    }
                } catch (CoreException e) {
                // continue, perhaps another configuration will succeed
                }
            }
        }
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ProfileLaunchConfigurationTabGroup(org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 50 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project linuxtools by eclipse.

the class ProviderFramework method getConfigurationDelegateFromId.

/**
 * Get a launch configuration delegate that is associated with the specified id.
 * This looks through extensions of the extension point
 * <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code> that
 * have a specific delegate attribute.
 *
 * @param id a unique identifier
 * @return a launch configuration delegate that implements
 * <code>AbstractCLaunchDelegate</code> , or <code>null</code> if
 * none could be found.
 * @since 1.2
 */
public static AbstractCLaunchDelegate getConfigurationDelegateFromId(String id) {
    IConfigurationElement[] configs = getConfigurationElements();
    for (IConfigurationElement config : configs) {
        if (config.getName().equals("provider")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String currentId = config.getAttribute("id");
            // $NON-NLS-1$
            String tabgroup = config.getAttribute("delegate");
            if (currentId != null && tabgroup != null && currentId.equals(id)) {
                try {
                    Object obj = config.createExecutableExtension(// $NON-NLS-1$
                    "delegate");
                    if (obj instanceof AbstractCLaunchDelegate) {
                        return (AbstractCLaunchDelegate) obj;
                    }
                } catch (CoreException e) {
                // continue, perhaps another configuration will succeed
                }
            }
        }
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) AbstractCLaunchDelegate(org.eclipse.cdt.launch.AbstractCLaunchDelegate)

Aggregations

IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)189 CoreException (org.eclipse.core.runtime.CoreException)75 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)64 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)50 ArrayList (java.util.ArrayList)39 IExtension (org.eclipse.core.runtime.IExtension)30 IStatus (org.eclipse.core.runtime.IStatus)24 Status (org.eclipse.core.runtime.Status)24 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)11 List (java.util.List)9 Map (java.util.Map)9 Platform (org.eclipse.core.runtime.Platform)9 File (java.io.File)8 Collection (java.util.Collection)8 Stream (java.util.stream.Stream)8 LinkedList (java.util.LinkedList)7 Optional (java.util.Optional)5 IFile (org.eclipse.core.resources.IFile)5