Skip to content

Commit

Permalink
Also load marker types from extensions eclipse-platform#2193
Browse files Browse the repository at this point in the history
  • Loading branch information
travkin79 committed Aug 16, 2024
1 parent 1c02e45 commit 076a240
Showing 1 changed file with 37 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Stream;

Expand Down Expand Up @@ -97,7 +98,7 @@ private void addGroupsFrom(IConfigurationElement element, Collection<MarkerGroup
* @return boolean
*/
public boolean allTypesSelected(Collection<MarkerType> selectedTypes) {
return selectedTypes.containsAll(markerTypes);
return selectedTypes.containsAll(getMarkerTypes());
}

/**
Expand Down Expand Up @@ -205,23 +206,41 @@ public Collection<MarkerGroup> getMarkerGroups() {
* @return Collection of {@link MarkerType}
*/
public Collection<MarkerType> getMarkerTypes() {
if (markerTypes == null) {
markerTypes = new HashSet<>();
IConfigurationElement[] markerTypeElements = configurationElement.getChildren(MarkerSupportRegistry.MARKER_TYPE_REFERENCE);
for (IConfigurationElement configElement : markerTypeElements) {
String elementName = configElement.getAttribute(MarkerSupportInternalUtilities.ATTRIBUTE_ID);
MarkerType[] types = MarkerTypesModel.getInstance().getType(elementName).getAllSubTypes();
markerTypes.addAll(Arrays.asList(types));
markerTypes.add(MarkerTypesModel.getInstance().getType(elementName));
}
if (markerTypes.isEmpty()) {
MarkerType[] types = MarkerTypesModel.getInstance().getType(IMarker.PROBLEM).getAllSubTypes();
markerTypes.addAll(Arrays.asList(types));
Set<MarkerType> markerTypes = new HashSet<>();
addMarkerTypesFrom(configurationElement, markerTypes);

Iterator<IConfigurationElement> extensions = generatorExtensions.iterator();
while (extensions.hasNext()) {
IConfigurationElement extensionElement = extensions.next();
String extendingMarkerContentGeneratorId = extensionElement
.getAttribute(MarkerSupportInternalUtilities.ATTRIBUTE_ID);
if (extendingMarkerContentGeneratorId != null && !extendingMarkerContentGeneratorId.isBlank()) {
ContentGeneratorDescriptor descriptor = MarkerSupportRegistry.getInstance()
.getContentGenDescriptor(extendingMarkerContentGeneratorId);
if (descriptor != null) {
markerTypes.addAll(descriptor.getMarkerTypes());
}
}
}
return markerTypes;
}

private void addMarkerTypesFrom(IConfigurationElement markerContentGeneratorConfigElement,
Collection<MarkerType> markerTypes) {
IConfigurationElement[] markerTypeElements = markerContentGeneratorConfigElement
.getChildren(MarkerSupportRegistry.MARKER_TYPE_REFERENCE);
for (IConfigurationElement configElement : markerTypeElements) {
String elementName = configElement.getAttribute(MarkerSupportInternalUtilities.ATTRIBUTE_ID);
MarkerType[] types = MarkerTypesModel.getInstance().getType(elementName).getAllSubTypes();
markerTypes.addAll(Arrays.asList(types));
markerTypes.add(MarkerTypesModel.getInstance().getType(elementName));
}
if (markerTypes.isEmpty()) {
MarkerType[] types = MarkerTypesModel.getInstance().getType(IMarker.PROBLEM).getAllSubTypes();
markerTypes.addAll(Arrays.asList(types));
}
}

/**
* Return the name for the receiver.
*
Expand All @@ -247,14 +266,12 @@ public MarkerType getType(String typeId) {
* @return Map of {@link String} to {@link MarkerType}
*/
public Map<String, MarkerType> getTypesTable() {
if (allTypesTable == null) {
allTypesTable = new HashMap<>();
Map<String, MarkerType> allTypesTable = new HashMap<>();

Iterator<MarkerType> allIterator = markerTypes.iterator();
while (allIterator.hasNext()) {
MarkerType next = allIterator.next();
allTypesTable.put(next.getId(), next);
}
Iterator<MarkerType> allIterator = getMarkerTypes().iterator();
while (allIterator.hasNext()) {
MarkerType next = allIterator.next();
allTypesTable.put(next.getId(), next);
}
return allTypesTable;
}
Expand Down

0 comments on commit 076a240

Please sign in to comment.