77import java .util .Map ;
88import java .util .Set ;
99
10- import org .apache .log4j .Logger ;
1110import org .eclipse .emf .ecore .resource .Resource ;
1211import org .eclipse .emf .ecore .resource .Resource .Factory ;
1312import org .eclipse .xtext .resource .IResourceFactory ;
2221import com .google .common .collect .ImmutableList ;
2322import com .google .common .collect .ImmutableMap ;
2423import com .google .common .collect .ImmutableSet ;
24+ import com .google .common .collect .Iterables ;
2525import com .google .common .collect .Lists ;
2626import com .google .common .collect .Maps ;
2727import com .google .common .collect .Multimap ;
3131public class FileExtensionInfoRegistry implements IEmfFileExtensionInfo .Registry {
3232
3333 private abstract static class Data {
34+ protected LazyClass <Object > editor = null ;
3435 protected String languageID = null ;
3536 protected LazyClass <Factory > resFact = null ;
3637 protected LazyClass <IResourceServiceProvider > resSvP = null ;
3738 protected LazyClass <IResourceServiceProvider > resUISvP = null ;
3839 protected LazyClass <Module > runtimeModule = null ;
39- protected LazyClass <Module > uiModule = null ;
4040 protected LazyClass <Module > sharedModule = null ;
41- protected LazyClass <Object > editor = null ;
41+ protected LazyClass <Module > uiModule = null ;
4242
4343 abstract protected String getFileExtensionString ();
4444
@@ -144,8 +144,8 @@ public static class XtextFileExtensionInfo extends EmfFileExtensionInfo implemen
144144 private final LazyClass <IResourceServiceProvider > resourceServiceProvider ;
145145 private final LazyClass <IResourceServiceProvider > resourceUIServiceProvider ;
146146 private final LazyClass <Module > runtimeModule ;
147- private final LazyClass <Module > uiModule ;
148147 private final LazyClass <Module > sharedModule ;
148+ private final LazyClass <Module > uiModule ;
149149
150150 public XtextFileExtensionInfo (Set <String > fileExtensions , LazyClass <Factory > resourceFactory , String languageID ,
151151 LazyClass <IResourceServiceProvider > resourceServiceProvider , LazyClass <IResourceServiceProvider > resourceUIServiceProvider , LazyClass <Module > runtimeModule ,
@@ -176,6 +176,10 @@ public LazyClass<Module> getRuntimeModule() {
176176 return runtimeModule ;
177177 }
178178
179+ public LazyClass <Module > getSharedModule () {
180+ return sharedModule ;
181+ }
182+
179183 public LazyClass <Module > getUIModule () {
180184 return uiModule ;
181185 }
@@ -204,19 +208,13 @@ public String toString() {
204208 return result .toString ();
205209 }
206210
207- public LazyClass <Module > getSharedModule () {
208- return sharedModule ;
209- }
210-
211211 }
212212
213213 private static final String DEFAULT_RESOURCE_FACTORY = IResourceFactory .class .getName ();
214214 private static final String DEFAULT_RESOURCE_SERVICE_PROVIDER = IResourceServiceProvider .class .getName ();
215215 private static final String DEFAULT_RESOURCE_UI_SERVICE_PROVIDER = "org.eclipse.xtext.ui.resource.IResourceUIServiceProvider" ;
216216 private static final String DEFAULT_SHARED_STATE_MODULE = "org.eclipse.xtext.ui.shared.SharedStateModule" ;
217217
218- private final static Logger LOG = Logger .getLogger (FileExtensionInfoRegistry .class );
219-
220218 public static void main (String [] args ) {
221219 System .out .println (new FileExtensionInfoRegistry ());
222220 }
@@ -225,16 +223,20 @@ public static void main(String[] args) {
225223
226224 private final List <IEmfFileExtensionInfo > infos ;
227225
226+ private final List <String > issues ;
227+
228228 public FileExtensionInfoRegistry () {
229229 this (IExtensionInfo .Registry .INSTANCE );
230230 }
231231
232232 public FileExtensionInfoRegistry (IExtensionInfo .Registry registry ) {
233- this .infos = ImmutableList .copyOf (collectFileExtensionInfos (registry ));
233+ List <String > issues = Lists .newArrayList ();
234+ this .infos = ImmutableList .copyOf (collectFileExtensionInfos (registry , issues ));
234235 this .fileExtension2Info = ImmutableMap .copyOf (collectFileExtensionInfosByExt (infos ));
236+ this .issues = ImmutableList .copyOf (issues );
235237 }
236238
237- private List <IEmfFileExtensionInfo > collectFileExtensionInfos (IExtensionInfo .Registry registry ) {
239+ private List <IEmfFileExtensionInfo > collectFileExtensionInfos (IExtensionInfo .Registry registry , Collection < String > issues ) {
238240 List <ExtensionPointData > infos = Lists .newArrayList ();
239241 for (IExtensionInfo ext : registry .getExtensions ("org.eclipse.emf.ecore.extension_parser" ))
240242 infos .add (parseEmfExtensionParser (ext ));
@@ -259,12 +261,12 @@ private List<IEmfFileExtensionInfo> collectFileExtensionInfos(IExtensionInfo.Reg
259261 for (String ext : ext2info .keySet ()) {
260262 FileExtensionData merged = mergeByFileExt (ext , ext2info .get (ext ));
261263 if (merged .languageID == null )
262- allInfos .add (toEmfFileExtensionInfo (merged ));
264+ allInfos .add (toEmfFileExtensionInfo (merged , issues ));
263265 else
264266 name2xtextInfo .put (merged .languageID , merged );
265267 }
266268 for (String name : name2xtextInfo .keySet ())
267- allInfos .add (mergeByLang (name , name2xtextInfo .get (name )));
269+ allInfos .add (mergeByLang (name , name2xtextInfo .get (name ), issues ));
268270
269271 return allInfos ;
270272 }
@@ -285,7 +287,7 @@ public Collection<IEmfFileExtensionInfo> getFileExtensionInfos() {
285287 return infos ;
286288 }
287289
288- private <T > T merge (T o1 , T o2 , Collection <IExtensionInfo > traceIn , Set <IExtensionInfo > tracOut , String name , String context ) {
290+ private <T > T merge (T o1 , T o2 , Collection <IExtensionInfo > traceIn , Set <IExtensionInfo > tracOut , String name , String context , Collection < String > issues ) {
289291 if (o2 != null ) {
290292 Collection <IExtensionInfo > trace ;
291293 if (o2 instanceof LazyClass <?>) {
@@ -304,7 +306,7 @@ private <T> T merge(T o1, T o2, Collection<IExtensionInfo> traceIn, Set<IExtensi
304306 List <String > tr = Lists .newArrayList ();
305307 for (IExtensionInfo e : set )
306308 tr .add (e + " from " + e .getLocation ());
307- LOG . warn ( message + " " + context + " Traces:\n \t " + Joiner .on ("\n \t " ).join (tr ));
309+ issues . add ( "WARNING:" + message + " " + context + " Traces:\n \t " + Joiner .on ("\n \t " ).join (tr ));
308310 }
309311 }
310312 return o1 ;
@@ -317,19 +319,19 @@ private FileExtensionData mergeByFileExt(String fileExtension, Collection<Extens
317319 String context = "FileExtension: " + fileExtension ;
318320 for (ExtensionPointData info : infos ) {
319321 Collection <IExtensionInfo > trace = Collections .singleton (info .trace );
320- result .languageID = merge (result .languageID , info .languageID , trace , result .traces , "Xtext LanguageIDs" , context );
321- result .resFact = merge (result .resFact , info .resFact , trace , result .traces , "EMF Resource Factories" , context );
322- result .resSvP = merge (result .resSvP , info .resSvP , trace , result .traces , "Xtext Resource Service Provider" , context );
323- result .resUISvP = merge (result .resUISvP , info .resUISvP , trace , result .traces , "Xtext Resource UI Service Provider" , context );
324- result .runtimeModule = merge (result .runtimeModule , info .runtimeModule , trace , result .traces , "Xtext Runtime Modules" , context );
325- result .uiModule = merge (result .uiModule , info .uiModule , trace , result .traces , "Xtext UI Modules" , context );
326- result .sharedModule = merge (result .sharedModule , info .sharedModule , trace , result .traces , "Xtext Shared State Modules" , context );
327- result .editor = merge (result .editor , info .editor , trace , result .traces , null , context );
322+ result .languageID = merge (result .languageID , info .languageID , trace , result .traces , "Xtext LanguageIDs" , context , issues );
323+ result .resFact = merge (result .resFact , info .resFact , trace , result .traces , "EMF Resource Factories" , context , issues );
324+ result .resSvP = merge (result .resSvP , info .resSvP , trace , result .traces , "Xtext Resource Service Provider" , context , issues );
325+ result .resUISvP = merge (result .resUISvP , info .resUISvP , trace , result .traces , "Xtext Resource UI Service Provider" , context , issues );
326+ result .runtimeModule = merge (result .runtimeModule , info .runtimeModule , trace , result .traces , "Xtext Runtime Modules" , context , issues );
327+ result .uiModule = merge (result .uiModule , info .uiModule , trace , result .traces , "Xtext UI Modules" , context , issues );
328+ result .sharedModule = merge (result .sharedModule , info .sharedModule , trace , result .traces , "Xtext Shared State Modules" , context , issues );
329+ result .editor = merge (result .editor , info .editor , trace , result .traces , null , context , issues );
328330 }
329331 return result ;
330332 }
331333
332- private XtextFileExtensionInfo mergeByLang (String langID , Collection <FileExtensionData > infos ) {
334+ private XtextFileExtensionInfo mergeByLang (String langID , Collection <FileExtensionData > infos , Collection < String > issues ) {
333335 Set <IExtensionInfo > traces = Sets .newHashSet ();
334336 Set <String > fileExtensions = Sets .newHashSet ();
335337 LazyClass <Factory > resFact = null ;
@@ -343,13 +345,13 @@ private XtextFileExtensionInfo mergeByLang(String langID, Collection<FileExtensi
343345 String context = "XtextLanguageID: " + langID ;
344346 for (FileExtensionData info : infos ) {
345347 fileExtensions .add (info .fileExtension );
346- resFact = merge (resFact , info .resFact , info .traces , traces , "EMF Resource Factories" , context );
347- rsp = merge (rsp , info .resSvP , info .traces , traces , "Xtext Resource Service Provider" , context );
348- rUIsp = merge (rUIsp , info .resUISvP , info .traces , traces , "Xtext Resource UI Service Provider" , context );
349- runtimeModule = merge (runtimeModule , info .runtimeModule , info .traces , traces , "Xtext Runtime Modules" , context );
350- uiModule = merge (uiModule , info .uiModule , info .traces , traces , "Xtext UI Modules" , context );
351- sharedModule = merge (sharedModule , info .sharedModule , info .traces , traces , "Xtext Shared State Modules" , context );
352- editor = merge (editor , info .editor , info .traces , traces , null , context );
348+ resFact = merge (resFact , info .resFact , info .traces , traces , "EMF Resource Factories" , context , issues );
349+ rsp = merge (rsp , info .resSvP , info .traces , traces , "Xtext Resource Service Provider" , context , issues );
350+ rUIsp = merge (rUIsp , info .resUISvP , info .traces , traces , "Xtext Resource UI Service Provider" , context , issues );
351+ runtimeModule = merge (runtimeModule , info .runtimeModule , info .traces , traces , "Xtext Runtime Modules" , context , issues );
352+ uiModule = merge (uiModule , info .uiModule , info .traces , traces , "Xtext UI Modules" , context , issues );
353+ sharedModule = merge (sharedModule , info .sharedModule , info .traces , traces , "Xtext Shared State Modules" , context , issues );
354+ editor = merge (editor , info .editor , info .traces , traces , null , context , issues );
353355 }
354356
355357 if (resFact == null && runtimeModule != null )
@@ -402,22 +404,22 @@ private ExtensionPointData parseXtextResourceUIServiceProvider(IExtensionInfo in
402404 return result ;
403405 }
404406
405- private EmfFileExtensionInfo toEmfFileExtensionInfo (FileExtensionData info ) {
406- warnIfSet (info , info .resSvP , "resourceServiceProvider" );
407- warnIfSet (info , info .resUISvP , "resourceUIServiceProvider" );
408- warnIfSet (info , info .runtimeModule , "runtimeModule" );
407+ private EmfFileExtensionInfo toEmfFileExtensionInfo (FileExtensionData info , Collection < String > issues ) {
408+ warnIfSet (info , info .resSvP , "resourceServiceProvider" , issues );
409+ warnIfSet (info , info .resUISvP , "resourceUIServiceProvider" , issues );
410+ warnIfSet (info , info .runtimeModule , "runtimeModule" , issues );
409411 // warnIfSet(info, info.uiModule, "uiModule");
410412 return new EmfFileExtensionInfo (Collections .singleton (info .fileExtension ), info .resFact , info .traces );
411413 }
412414
413415 @ Override
414416 public String toString () {
415- return Joiner .on ("\n " ).join (infos );
417+ return Joiner .on ("\n " ).join (Iterables . concat ( issues , infos ) );
416418 }
417419
418- private void warnIfSet (FileExtensionData info , Object value , String name ) {
420+ private void warnIfSet (FileExtensionData info , Object value , String name , Collection < String > issues ) {
419421 if (value != null )
420- LOG . warn ( " Ignoring " + name + " '" + value + "' for fileExtension '" + info .fileExtension + "' from " + info .getLocations ());
422+ issues . add ( "WARNING: Ignoring " + name + " '" + value + "' for fileExtension '" + info .fileExtension + "' from " + info .getLocations ());
421423 }
422424
423425}
0 commit comments