use of org.eclipse.core.runtime.IConfigurationElement in project eclipse.platform.text by eclipse.
the class HyperlinkDetectorTargetDescriptor method createDescriptors.
private static HyperlinkDetectorTargetDescriptor[] createDescriptors(IConfigurationElement[] elements) {
List<HyperlinkDetectorTargetDescriptor> result = new ArrayList<>(elements.length);
for (int i = 0; i < elements.length; i++) {
IConfigurationElement element = elements[i];
if (TARGET_ELEMENT.equals(element.getName())) {
HyperlinkDetectorTargetDescriptor desc = new HyperlinkDetectorTargetDescriptor(element);
if (desc.isValid())
result.add(desc);
else {
String message = NLSUtility.format(EditorMessages.Editor_error_HyperlinkDetectorTarget_invalidExtension_message, new String[] { desc.getId(), element.getContributor().getName() });
TextEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, message, null));
}
} else {
String message = NLSUtility.format(EditorMessages.Editor_error_HyperlinkDetectorTarget_invalidElementName_message, new String[] { element.getContributor().getName(), element.getName() });
TextEditorPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, message, null));
}
}
return result.toArray(new HyperlinkDetectorTargetDescriptor[result.size()]);
}
use of org.eclipse.core.runtime.IConfigurationElement in project eclipse.platform.text by eclipse.
the class AbstractMarkerAnnotationModel method installMarkerUpdaters.
/**
* Installs all marker updaters for this marker annotation model.
*/
private void installMarkerUpdaters() {
// initialize lists - indicates that the initialization happened
fInstantiatedMarkerUpdaters = new ArrayList<>(2);
HashMap<String, Integer> markerUpdaterOrderMap = new HashMap<>(2);
LinkedList<IConfigurationElement> markerUpdaterSpecificationsLinkedList = new LinkedList<>();
// populate list
// $NON-NLS-1$
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(EditorsUI.PLUGIN_ID, "markerUpdaters");
if (extensionPoint != null) {
IConfigurationElement[] elements = extensionPoint.getConfigurationElements();
for (int i = 0; i < elements.length; i++) {
markerUpdaterSpecificationsLinkedList.add(elements[i]);
markerUpdaterOrderMap.put(elements[i].getAttribute(ID), Integer.valueOf(i));
}
// start sorting based on required-updater definition
HashMap<String, ArrayList<String>> markerUpdaterRequiredByOrderMap = new HashMap<>(2);
for (int i = 0; i < elements.length; i++) {
// Required marker should execute before other updater markers
// $NON-NLS-1$
IConfigurationElement[] requiredUpdaters = elements[i].getChildren("required-updater");
if (requiredUpdaters.length > 0) {
// ArrayList requiredUpdaters= new ArrayList(2);
for (int j = 0; j < requiredUpdaters.length; j++) {
// If required updaters have been defined
String requiredID = requiredUpdaters[j].getAttribute(ID);
// If required ID is not a valid id
if (requiredID == null || (markerUpdaterOrderMap.get(requiredID) == null)) {
// ID missing or invalid - log the message and move to next contribution
String msg = NLSUtility.format(TextEditorMessages.AbstractMarkerAnnotationModel_updaterInvalidDefinition, new Object[] { elements[i].getAttribute(ID), requiredID });
EditorsPlugin.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, msg));
continue;
}
// Updating requiredByUpdaters to identify and log error for cyclic Dependency like A required B, B required C, C required D and D required A
// or A requires B and B requires A
ArrayList<String> requiredByUpdaters;
if (markerUpdaterRequiredByOrderMap.get(requiredID) == null) {
requiredByUpdaters = new ArrayList<>(2);
} else {
requiredByUpdaters = markerUpdaterRequiredByOrderMap.get(requiredID);
}
// Build up extended required id list to identify Case 2
if (markerUpdaterRequiredByOrderMap.get(elements[i].getAttribute(ID)) != null) {
ArrayList<String> requiredByList = markerUpdaterRequiredByOrderMap.get(elements[i].getAttribute(ID));
requiredByUpdaters.addAll(requiredByList);
}
if (requiredByUpdaters.contains(requiredID)) {
// log error if marker ID is in the required list of required ID
String msg = NLSUtility.format(TextEditorMessages.AbstractMarkerAnnotationModel_markerUpdaterCyclicDefinition, new Object[] { elements[i].getAttribute(ID), requiredID });
EditorsPlugin.log(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, msg));
continue;
}
requiredByUpdaters.add(elements[i].getAttribute(ID));
markerUpdaterRequiredByOrderMap.put(requiredID, requiredByUpdaters);
Integer requiredLocation = markerUpdaterOrderMap.get(requiredID);
if (requiredLocation.intValue() > markerUpdaterOrderMap.get(elements[i].getAttribute(ID)).intValue()) {
// If required marker is not ordered before
int newLocation = (markerUpdaterOrderMap.get(elements[i].getAttribute(ID)).intValue() == 0) ? 0 : (markerUpdaterOrderMap.get(elements[i].getAttribute(ID)).intValue() - 1);
IConfigurationElement requiredMarker = markerUpdaterSpecificationsLinkedList.remove(requiredLocation.intValue());
// Put the required location before the marker
markerUpdaterSpecificationsLinkedList.add(newLocation, requiredMarker);
markerUpdaterOrderMap.put(requiredID, Integer.valueOf(newLocation));
markerUpdaterOrderMap.put(elements[i].getAttribute(ID), Integer.valueOf(newLocation + 1));
}
}
}
}
fMarkerUpdaterSpecifications = new ArrayList<>(markerUpdaterSpecificationsLinkedList);
// end sorting
}
}
use of org.eclipse.core.runtime.IConfigurationElement in project eclipse.platform.text by eclipse.
the class DocumentProviderRegistry method read.
/**
* Reads the comma-separated value of the given configuration element
* for the given attribute name and remembers the configuration element
* in the given map under the individual tokens of the attribute value.
*
* @param map the map
* @param element the configuration element
* @param attributeName the attribute name
*/
private void read(Map<String, Set<IConfigurationElement>> map, IConfigurationElement element, String attributeName) {
String value = element.getAttribute(attributeName);
if (value != null) {
// $NON-NLS-1$
StringTokenizer tokenizer = new StringTokenizer(value, ",");
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken().trim();
Set<IConfigurationElement> s = map.get(token);
if (s == null) {
s = new HashSet<>();
map.put(token, s);
}
s.add(element);
}
}
}
use of org.eclipse.core.runtime.IConfigurationElement in project eclipse.platform.text by eclipse.
the class RulerColumnRegistry method reload.
/**
* Reloads the extensions to the extension point.
* <p>
* This method can be called more than once in order to reload from
* a changed extension registry.
* </p>
*/
public void reload() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
List<IConfigurationElement> elements = new ArrayList<>(Arrays.asList(registry.getConfigurationElementsFor(TextEditorPlugin.PLUGIN_ID, EXTENSION_POINT)));
List<RulerColumnDescriptor> descriptors = new ArrayList<>();
Map<String, RulerColumnDescriptor> descriptorMap = new HashMap<>();
for (Iterator<IConfigurationElement> iter = elements.iterator(); iter.hasNext(); ) {
IConfigurationElement element = iter.next();
try {
RulerColumnDescriptor desc = new RulerColumnDescriptor(element, this);
String id = desc.getId();
if (descriptorMap.containsKey(id)) {
noteDuplicateId(desc);
continue;
}
descriptors.add(desc);
descriptorMap.put(id, desc);
} catch (InvalidRegistryObjectException x) {
/*
* Element is not valid any longer as the contributing plug-in was unloaded or for
* some other reason. Do not include the extension in the list and inform the user
* about it.
*/
noteInvalidExtension(element, x);
} catch (CoreException x) {
warnUser(x.getStatus());
}
}
sort(descriptors);
synchronized (this) {
fDescriptors = Collections.unmodifiableList(descriptors);
fDescriptorMap = Collections.unmodifiableMap(descriptorMap);
}
}
use of org.eclipse.core.runtime.IConfigurationElement in project eclipse.platform.text by eclipse.
the class GenericContentTypeRelatedExtension method buildEnabledWhen.
/**
* Returns the expression {@link Expression} declared in the
* <code>enabledWhen</code> element.
*
* @param configElement the configuration element
* @return the expression {@link Expression} declared in the enabledWhen
* element.
* @throws CoreException when enabledWhen expression is not valid.
*/
private static Expression buildEnabledWhen(IConfigurationElement configElement) throws CoreException {
final IConfigurationElement[] children = configElement.getChildren(ENABLED_WHEN_ATTRIBUTE);
if (children.length > 0) {
IConfigurationElement[] subChildren = children[0].getChildren();
if (subChildren.length != 1) {
throw new CoreException(new Status(IStatus.ERROR, GenericEditorPlugin.BUNDLE_ID, // $NON-NLS-1$
"One <enabledWhen> element is accepted. Disabling " + configElement.getAttribute(ID_ATTRIBUTE)));
}
final ElementHandler elementHandler = ElementHandler.getDefault();
final ExpressionConverter converter = ExpressionConverter.getDefault();
return elementHandler.create(converter, subChildren[0]);
}
return null;
}
Aggregations