mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
helper method for getting extension elements of a cextension.
This commit is contained in:
parent
918addbcbc
commit
e73afe6adb
3 changed files with 90 additions and 28 deletions
|
@ -11,17 +11,20 @@
|
|||
package org.eclipse.cdt.core;
|
||||
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
|
||||
public interface ICExtensionReference {
|
||||
|
||||
/**
|
||||
* Return the extension point of this reference.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getExtension();
|
||||
|
||||
/**
|
||||
* Return the extension ID of this reference.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getID();
|
||||
|
@ -32,12 +35,53 @@ public interface ICExtensionReference {
|
|||
public void setExtensionData(String key, String value);
|
||||
|
||||
/**
|
||||
* Gets a value of the key from the .cdtproject file set by setExtensionData()
|
||||
* Gets a value of the key from the .cdtproject file set by
|
||||
* setExtensionData()
|
||||
*/
|
||||
public String getExtensionData(String key);
|
||||
|
||||
/**
|
||||
* Creates the executable extension for the reference.
|
||||
* Creates and returns a new instance of the cextension executable
|
||||
* identified by the <run> attribute of the cextension.
|
||||
* <p>
|
||||
* The ICExtension is instantiated using its 0-argument public
|
||||
* constructor. If the class implements the
|
||||
* <code>IExecutableExtension</code> interface, the method
|
||||
* <code>setInitializationData</code> is called, passing to the object
|
||||
* the configuration information that was used to create it.
|
||||
* </p>
|
||||
* <p>
|
||||
* Unlike other methods on this object, invoking this method may activate
|
||||
* the plug-in.
|
||||
* </p>
|
||||
*
|
||||
* @return the executable ICExtension instance
|
||||
* @exception CoreException if an instance of the executable extension
|
||||
* could not be created for any reason.
|
||||
* @see IExecutableExtension#setInitializationData
|
||||
*/
|
||||
public ICExtension createExtension() throws CoreException;
|
||||
|
||||
/**
|
||||
* Returns all configuration elements that are children of the
|
||||
* cextension element. Returns an empty array if this configuration
|
||||
* element has no children.
|
||||
* <p>
|
||||
* Each child corresponds to a nested XML element in the configuration
|
||||
* markup. For example, the configuration markup
|
||||
*
|
||||
* <pre>
|
||||
* <view>
|
||||
* &nbsp&nbsp&nbsp&nbsp<verticalHint>top</verticalHint>
|
||||
* &nbsp&nbsp&nbsp&nbsp<horizontalHint>left</horizontalHint>
|
||||
* </view>
|
||||
* </pre>
|
||||
*
|
||||
* corresponds to a configuration element, named <code>"view"</code>,
|
||||
* with two children.
|
||||
* </p>
|
||||
*
|
||||
* @return the child configuration elements
|
||||
*/
|
||||
public IConfigurationElement[] getExtensionElements() throws CoreException;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import java.io.FileInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -60,12 +59,12 @@ public class CDescriptor implements ICDescriptor {
|
|||
private HashMap extInfoMap = new HashMap(4);
|
||||
private Document dataDoc;
|
||||
|
||||
static final String CEXTENSION_NAME = "cextension"; //$NON-NLS-1$
|
||||
static final String DESCRIPTION_FILE_NAME = ".cdtproject"; //$NON-NLS-1$
|
||||
private static final char[][] NO_CHAR_CHAR = new char[0][];
|
||||
private static final String PROJECT_DESCRIPTION = "cdtproject"; //$NON-NLS-1$
|
||||
private static final String PROJECT_EXTENSION = "extension"; //$NON-NLS-1$
|
||||
private static final String PROJECT_EXTENSION_ATTRIBUTE = "attribute"; //$NON-NLS-1$
|
||||
private static final String PATH_ENTRY = "cpathentry"; //$NON-NLS-1$
|
||||
private static final String PROJECT_DATA = "data"; //$NON-NLS-1$
|
||||
private static final String PROJECT_DATA_ITEM = "item"; //$NON-NLS-1$
|
||||
private static final String PROJECT_DATA_ID = "id"; //$NON-NLS-1$
|
||||
|
@ -318,7 +317,6 @@ public class CDescriptor implements ICDescriptor {
|
|||
|
||||
private void readProjectDescription(Node node) {
|
||||
Node childNode;
|
||||
ArrayList pathEntries = new ArrayList();
|
||||
NodeList list = node.getChildNodes();
|
||||
for (int i = 0; i < list.getLength(); i++) {
|
||||
childNode = list.item(i);
|
||||
|
@ -397,7 +395,7 @@ public class CDescriptor implements ICDescriptor {
|
|||
}
|
||||
IConfigurationElement element[] = extension.getConfigurationElements();
|
||||
for (int i = 0; i < element.length; i++) {
|
||||
if (element[i].getName().equalsIgnoreCase("cextension")) { //$NON-NLS-1$
|
||||
if (element[i].getName().equalsIgnoreCase(CEXTENSION_NAME)) {
|
||||
cExtension = (InternalCExtension) element[i].createExecutableExtension("run"); //$NON-NLS-1$
|
||||
cExtension.setExtenionReference(ext);
|
||||
cExtension.setProject(fProject);
|
||||
|
@ -407,6 +405,22 @@ public class CDescriptor implements ICDescriptor {
|
|||
return (ICExtension) cExtension;
|
||||
}
|
||||
|
||||
protected IConfigurationElement[] getConfigurationElement(ICExtensionReference ext) throws CoreException {
|
||||
IPluginRegistry pluginRegistry = Platform.getPluginRegistry();
|
||||
IExtensionPoint extensionPoint = pluginRegistry.getExtensionPoint(ext.getExtension());
|
||||
IExtension extension = extensionPoint.getExtension(ext.getID());
|
||||
if ( extension == null) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1, CCorePlugin.getResourceString("CDescriptor.exception.providerNotFound"), null)); //$NON-NLS-1$
|
||||
}
|
||||
IConfigurationElement element[] = extension.getConfigurationElements();
|
||||
for (int i = 0; i < element.length; i++) {
|
||||
if (element[i].getName().equalsIgnoreCase(CEXTENSION_NAME)) {
|
||||
return element[i].getChildren();
|
||||
}
|
||||
}
|
||||
return new IConfigurationElement[0];
|
||||
}
|
||||
|
||||
// The project data allows for the storage of any structured information
|
||||
// into the cdtproject file.
|
||||
private Document getProjectDataDoc() throws CoreException {
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core;
|
|||
import org.eclipse.cdt.core.ICExtension;
|
||||
import org.eclipse.cdt.core.ICExtensionReference;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IConfigurationElement;
|
||||
|
||||
public class CExtensionReference implements ICExtensionReference {
|
||||
private CDescriptor fDescriptor;
|
||||
|
@ -49,4 +50,7 @@ public class CExtensionReference implements ICExtensionReference {
|
|||
return fDescriptor.createExtensions(this);
|
||||
}
|
||||
|
||||
public IConfigurationElement[] getExtensionElements() throws CoreException {
|
||||
return fDescriptor.getConfigurationElement(this);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue