List of usage examples for com.google.gwt.dev CompilerContext getModule
public ModuleDef getModule()
From source file:org.cruxframework.crux.core.rebind.context.ContextUtil.java
License:Apache License
/** * A Hack to read the module being compiled by GWT. *///from w w w .jav a2 s .com public static ModuleDef getCurrentModule(GeneratorContext context) { if (context instanceof StandardGeneratorContext) { StandardGeneratorContext stdContext = (StandardGeneratorContext) context; try { Field compilerContextField = StandardGeneratorContext.class.getDeclaredField("compilerContext"); compilerContextField.setAccessible(true); CompilerContext compilerContext = (CompilerContext) compilerContextField.get(stdContext); return compilerContext.getModule(); } catch (Exception e) { throw new CruxGeneratorException("Can not retrieve the current module being compiled.", e); } } else if (context instanceof DelegatingGeneratorContext) { DelegatingGeneratorContext delContext = (DelegatingGeneratorContext) context; try { Field baseContextField = StandardGeneratorContext.class.getDeclaredField("baseContext"); baseContextField.setAccessible(true); context = (GeneratorContext) baseContextField.get(delContext); return getCurrentModule(context); } catch (Exception e) { throw new CruxGeneratorException("Can not retrieve the current module being compiled.", e); } } throw new CruxGeneratorException( "Can not retrieve the current module being compiled. Unknow GeneratorContext type."); }