2020import java .util .HashMap ;
2121import java .util .HashSet ;
2222import java .util .Iterator ;
23+ import java .util .List ;
2324import java .util .Map ;
25+ import java .util .Set ;
2426import java .util .TreeSet ;
2527import java .util .stream .Stream ;
2628
@@ -43,12 +45,9 @@ public class ContentGeneratorDescriptor {
4345 private static final String MARKER_FIELD_REFERENCE = "markerFieldReference" ; //$NON-NLS-1$
4446
4547 private IConfigurationElement configurationElement ;
46- private MarkerField [] allFields ;
47- private Collection <MarkerType > markerTypes ;
48- private MarkerField [] initialVisible ;
49- private Collection <MarkerGroup > groups ;
48+ private MarkerField [] allFieldsWithoutExtensions ;
49+ private MarkerField [] initialVisibleWithoutExtensions ;
5050 private Collection <IConfigurationElement > generatorExtensions = new ArrayList <>();
51- private Map <String , MarkerType > allTypesTable ;
5251
5352 /**
5453 * Create a new ContentGeneratorDescriptor
@@ -60,13 +59,13 @@ public ContentGeneratorDescriptor(IConfigurationElement element) {
6059 /**
6160 * Add the groups defined in the receiver to the collection of groups.
6261 */
63- private void addDefinedGroups (Collection <MarkerGroup > groupss ) {
62+ private void addDefinedGroups (Collection <MarkerGroup > groups ) {
6463 // Add the ones in the receiver.
65- addGroupsFrom (configurationElement , groupss );
64+ addGroupsFrom (configurationElement , groups );
6665 // Add the extensions
6766 Iterator <IConfigurationElement > extensions = generatorExtensions .iterator ();
6867 while (extensions .hasNext ()) {
69- addGroupsFrom (extensions .next (), groupss );
68+ addGroupsFrom (extensions .next (), groups );
7069 }
7170 }
7271
@@ -96,7 +95,7 @@ private void addGroupsFrom(IConfigurationElement element, Collection<MarkerGroup
9695 * @return boolean
9796 */
9897 public boolean allTypesSelected (Collection <MarkerType > selectedTypes ) {
99- return selectedTypes .containsAll (markerTypes );
98+ return selectedTypes .containsAll (getMarkerTypes () );
10099 }
101100
102101 /**
@@ -105,7 +104,26 @@ public boolean allTypesSelected(Collection<MarkerType> selectedTypes) {
105104 * @return {@link MarkerField}[]
106105 */
107106 public MarkerField [] getAllFields () {
108- return allFields ;
107+ List <MarkerField > allFieldsList = new ArrayList <>(Arrays .asList (allFieldsWithoutExtensions ));
108+
109+ getExtensionsDescriptorsStream ().flatMap (descriptor -> Arrays .stream (descriptor .getAllFields ()))
110+ .forEach (field -> allFieldsList .add (field ));
111+
112+ return allFieldsList .toArray (new MarkerField [allFieldsList .size ()]);
113+ }
114+
115+ private Stream <ContentGeneratorDescriptor > getExtensionsDescriptorsStream () {
116+ if (generatorExtensions != null ) {
117+ final MarkerSupportRegistry registry = MarkerSupportRegistry .getInstance ();
118+
119+ return generatorExtensions .stream ()
120+ .map (extensionConfigElem -> extensionConfigElem
121+ .getAttribute (MarkerSupportInternalUtilities .ATTRIBUTE_ID ))
122+ .filter (id -> id != null && !id .isBlank ())
123+ .map (contentGeneratorId -> registry .getContentGenDescriptor (contentGeneratorId ))
124+ .filter (generator -> generator != null );
125+ }
126+ return Stream .empty ();
109127 }
110128
111129 /**
@@ -156,7 +174,12 @@ public String getId() {
156174 * @return {@link MarkerField}[]
157175 */
158176 public MarkerField [] getInitialVisible () {
159- return initialVisible ;
177+ List <MarkerField > allVisibleFieldsList = new ArrayList <>(Arrays .asList (initialVisibleWithoutExtensions ));
178+
179+ getExtensionsDescriptorsStream ().flatMap (descriptor -> Arrays .stream (descriptor .getInitialVisible ()))
180+ .forEach (field -> allVisibleFieldsList .add (field ));
181+
182+ return allVisibleFieldsList .toArray (new MarkerField [allVisibleFieldsList .size ()]);
160183 }
161184
162185 /**
@@ -165,16 +188,15 @@ public MarkerField[] getInitialVisible() {
165188 * @return Collection of {@link MarkerGroup}
166189 */
167190 public Collection <MarkerGroup > getMarkerGroups () {
168- if ( groups == null ) {
169- groups = new TreeSet <>( (mg1 , mg2 ) -> mg1 .getMarkerField ().getName ().compareTo (mg2 .getMarkerField ().getName ()));
191+ Collection < MarkerGroup > groups = new TreeSet <>(
192+ (mg1 , mg2 ) -> mg1 .getMarkerField ().getName ().compareTo (mg2 .getMarkerField ().getName ()));
170193
171- // Add the groups defined in the receiver
172- addDefinedGroups (groups );
194+ // Add the groups defined in the receiver
195+ addDefinedGroups (groups );
173196
174- if (getId ().equals (MarkerSupportRegistry .PROBLEMS_GENERATOR )) {
175- // Add the groups that reference the receiver.
176- groups .addAll (MarkerSupportRegistry .getInstance ().getMarkerGroups ());
177- }
197+ if (getId ().equals (MarkerSupportRegistry .PROBLEMS_GENERATOR )) {
198+ // Add the groups that reference the receiver.
199+ groups .addAll (MarkerSupportRegistry .getInstance ().getMarkerGroups ());
178200 }
179201 return groups ;
180202 }
@@ -185,23 +207,46 @@ public Collection<MarkerGroup> getMarkerGroups() {
185207 * @return Collection of {@link MarkerType}
186208 */
187209 public Collection <MarkerType > getMarkerTypes () {
188- if (markerTypes == null ) {
189- markerTypes = new HashSet <>();
190- IConfigurationElement [] markerTypeElements = configurationElement .getChildren (MarkerSupportRegistry .MARKER_TYPE_REFERENCE );
191- for (IConfigurationElement configElement : markerTypeElements ) {
192- String elementName = configElement .getAttribute (MarkerSupportInternalUtilities .ATTRIBUTE_ID );
193- MarkerType [] types = MarkerTypesModel .getInstance ().getType (elementName ).getAllSubTypes ();
194- markerTypes .addAll (Arrays .asList (types ));
195- markerTypes .add (MarkerTypesModel .getInstance ().getType (elementName ));
196- }
197- if (markerTypes .isEmpty ()) {
198- MarkerType [] types = MarkerTypesModel .getInstance ().getType (IMarker .PROBLEM ).getAllSubTypes ();
199- markerTypes .addAll (Arrays .asList (types ));
200- }
210+ Set <MarkerType > markerTypes = collectMarkerTypesWithoutExtensions ();
211+ addMarkerTypesFromExtensions (markerTypes );
212+ return markerTypes ;
213+ }
214+
215+ private Set <MarkerType > collectMarkerTypesWithoutExtensions () {
216+ Set <MarkerType > markerTypes = new HashSet <>();
217+
218+ IConfigurationElement [] markerTypeElements = configurationElement
219+ .getChildren (MarkerSupportRegistry .MARKER_TYPE_REFERENCE );
220+ for (IConfigurationElement configElement : markerTypeElements ) {
221+ String elementName = configElement .getAttribute (MarkerSupportInternalUtilities .ATTRIBUTE_ID );
222+ MarkerType [] types = MarkerTypesModel .getInstance ().getType (elementName ).getAllSubTypes ();
223+ markerTypes .addAll (Arrays .asList (types ));
224+ markerTypes .add (MarkerTypesModel .getInstance ().getType (elementName ));
201225 }
226+ if (markerTypes .isEmpty ()) {
227+ MarkerType [] types = MarkerTypesModel .getInstance ().getType (IMarker .PROBLEM ).getAllSubTypes ();
228+ markerTypes .addAll (Arrays .asList (types ));
229+ }
230+
202231 return markerTypes ;
203232 }
204233
234+ private void addMarkerTypesFromExtensions (Collection <MarkerType > markerTypes ) {
235+ Iterator <IConfigurationElement > extensions = generatorExtensions .iterator ();
236+ while (extensions .hasNext ()) {
237+ IConfigurationElement extensionElement = extensions .next ();
238+ String extendingMarkerContentGeneratorId = extensionElement
239+ .getAttribute (MarkerSupportInternalUtilities .ATTRIBUTE_ID );
240+ if (extendingMarkerContentGeneratorId != null && !extendingMarkerContentGeneratorId .isBlank ()) {
241+ ContentGeneratorDescriptor descriptor = MarkerSupportRegistry .getInstance ()
242+ .getContentGenDescriptor (extendingMarkerContentGeneratorId );
243+ if (descriptor != null ) {
244+ markerTypes .addAll (descriptor .getMarkerTypes ());
245+ }
246+ }
247+ }
248+ }
249+
205250 /**
206251 * Return the name for the receiver.
207252 *
@@ -227,14 +272,12 @@ public MarkerType getType(String typeId) {
227272 * @return Map of {@link String} to {@link MarkerType}
228273 */
229274 public Map <String , MarkerType > getTypesTable () {
230- if (allTypesTable == null ) {
231- allTypesTable = new HashMap <>();
275+ Map <String , MarkerType > allTypesTable = new HashMap <>();
232276
233- Iterator <MarkerType > allIterator = markerTypes .iterator ();
234- while (allIterator .hasNext ()) {
235- MarkerType next = allIterator .next ();
236- allTypesTable .put (next .getId (), next );
237- }
277+ Iterator <MarkerType > allIterator = getMarkerTypes ().iterator ();
278+ while (allIterator .hasNext ()) {
279+ MarkerType next = allIterator .next ();
280+ allTypesTable .put (next .getId (), next );
238281 }
239282 return allTypesTable ;
240283 }
@@ -264,11 +307,11 @@ public void initializeFromConfigurationElement(
264307 }
265308 }
266309
267- allFields = new MarkerField [allFieldList .size ()];
268- allFieldList .toArray (allFields );
310+ allFieldsWithoutExtensions = new MarkerField [allFieldList .size ()];
311+ allFieldList .toArray (allFieldsWithoutExtensions );
269312
270- initialVisible = new MarkerField [initialVisibleList .size ()];
271- initialVisibleList .toArray (initialVisible );
313+ initialVisibleWithoutExtensions = new MarkerField [initialVisibleList .size ()];
314+ initialVisibleList .toArray (initialVisibleWithoutExtensions );
272315
273316 }
274317
0 commit comments