@Override public String generate (TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { TypeOracle oracle = context.getTypeOracle(); assert (oracle != null); JClassType type = oracle.findType(typeName); if (type == null) { logger.log(ERROR, "Couldn't find type '" + typeName + "'"); throw new UnableToCompleteException(); } if (type.isInterface() == null) { logger.log(ERROR, "Type '" + typeName + "' must be an interface"); throw new UnableToCompleteException(); } ReflectionCacheSourceCreator source = new ReflectionCacheSourceCreator(logger, context, type); return source.create(); } }
@Override public String generate (TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException { TypeOracle oracle = context.getTypeOracle(); assert (oracle != null); JClassType type = oracle.findType(typeName); if (type == null) { logger.log(ERROR, "Couldn't find type '" + typeName + "'"); throw new UnableToCompleteException(); } if (type.isInterface() == null) { logger.log(ERROR, "Type '" + typeName + "' must be an interface"); throw new UnableToCompleteException(); } ReflectionCacheSourceCreator source = new ReflectionCacheSourceCreator(logger, context, type); return source.create(); } }
private void generateLookups () { TypeOracle typeOracle = context.getTypeOracle(); JPackage[] packages = typeOracle.getPackages();
private void generateLookups () { TypeOracle typeOracle = context.getTypeOracle(); JPackage[] packages = typeOracle.getPackages();
public SubstitutionReplacer(TreeLogger logger, ResourceContext context, Map<String, CssDef> substitutions) { this.context = context; this.dataResourceType = context.getGeneratorContext().getTypeOracle().findType( DataResource.class.getCanonicalName()); this.imageResourceType = context.getGeneratorContext().getTypeOracle().findType( ImageResource.class.getCanonicalName()); this.logger = logger; this.substitutions = substitutions; }
@VisibleForTesting ResourceUrlFunction(ResourceContext context, MethodByPathHelper methodByPathHelper) { this.context = context; this.methodByPathHelper = methodByPathHelper; this.dataResourceType = context.getGeneratorContext().getTypeOracle() .findType(DataResource.class.getCanonicalName()); this.imageResourceType = context.getGeneratorContext().getTypeOracle() .findType(ImageResource.class.getCanonicalName()); }
private SortedSet<JClassType> computeOperableTypes(ResourceContext context) { TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); JClassType baseInterface = typeOracle.findType(CssResource.class.getCanonicalName()); SortedSet<JClassType> toReturn = new TreeSet<>(new JClassOrderComparator()); JClassType[] cssResourceSubtypes = baseInterface.getSubtypes(); for (JClassType type : cssResourceSubtypes) { if (type.isInterface() != null) { toReturn.add(type); } } return toReturn; }
@VisibleForTesting ImageSpriteCreator(MutatingVisitController visitController, ResourceContext context, ErrorManager errorManager, MethodByPathHelper methodByPathHelper) { this.visitController = visitController; this.errorManager = errorManager; this.context = context; this.methodByPathHelper = methodByPathHelper; this.imageResourceType = context.getGeneratorContext().getTypeOracle().findType( ImageResource.class.getName()); this.resourceThisPrefix = context.getImplementationSimpleSourceName() + ".this"; }
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { JClassType gwtType = context.getGeneratorContext().getTypeOracle().findType( GWT.class.getName()); assert gwtType != null; return gwtType.getQualifiedSourceName() + ".create(" + method.getReturnType().getQualifiedSourceName() + ".class)"; } }
@Override public void createFields(TreeLogger logger, ResourceContext context, ClientBundleFields fields) throws UnableToCompleteException { data.append(']'); StringBuffer wrappedData = new StringBuffer(); if (shouldUseJsonp(context, logger)) { wrappedData.append(JSONP_CALLBACK_PREFIX); wrappedData.append(getMd5HashOfData()); wrappedData.append(".onSuccess(\n"); wrappedData.append(data.toString()); wrappedData.append(")"); } else { wrappedData = data; } urlExpression = context.deploy( context.getClientBundleType().getQualifiedSourceName().replace('.', '_') + "_jsonbundle.txt", "text/plain", Util.getBytes(wrappedData.toString()), true); TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); JClassType stringType = typeOracle.findType(String.class.getName()); assert stringType != null; externalTextUrlIdent = fields.define(stringType, "externalTextUrl", urlExpression, true, true); JClassType textResourceType = typeOracle.findType(TextResource.class.getName()); assert textResourceType != null; JType textResourceArrayType = typeOracle.getArrayType(textResourceType); externalTextCacheIdent = fields.define(textResourceArrayType, "externalTextCache", "new " + TextResource.class.getName() + "[" + currentIndex + "]", true, true); }
private Map<String, Map<String, String>> computeReplacements(JMethod method, TreeLogger logger, ResourceContext context) throws UnableToCompleteException { Map<String, Map<String, String>> replacementsWithPrefix = new HashMap<String, Map<String, String>>(); replacementsWithPrefix .put("", computeReplacementsForType(method.getReturnType().isInterface())); // Process the Import annotation if any Import imp = method.getAnnotation(Import.class); if (imp != null) { boolean fail = false; TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); for (Class<? extends CssResource> clazz : imp.value()) { JClassType importType = typeOracle.findType(clazz.getName().replace('$', '.')); assert importType != null : "TypeOracle does not have type " + clazz.getName(); // add this import type as a requirement for this generator context.getRequirements().addTypeHierarchy(importType); String prefix = getImportPrefix(importType); if (replacementsWithPrefix.put(prefix, computeReplacementsForType(importType)) != null) { logger.log(TreeLogger.ERROR, "Multiple imports that would use the prefix " + prefix); fail = true; } } if (fail) { throw new UnableToCompleteException(); } } return replacementsWithPrefix; }
@Override public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { JParameterizedType returnType = method.getReturnType().isParameterized(); assert returnType != null; JClassType args[] = returnType.getTypeArgs(); assert args.length == 1; ClassType override = method.getAnnotation(ClassType.class); JClassType toCreate; if (override != null) { toCreate = context.getGeneratorContext().getTypeOracle().findType( override.value().getName().replace('$', '.')); assert toCreate != null; } else { toCreate = args[0]; } JClassType gwtType = context.getGeneratorContext().getTypeOracle().findType( GWT.class.getName()); assert gwtType != null; return "new " + returnType.getParameterizedQualifiedSourceName() + "() {\n public " + toCreate.getQualifiedSourceName() + " create() {\n return " + gwtType.getQualifiedSourceName() + ".create(" + toCreate.getQualifiedSourceName() + ".class);}\n" + "public String getName() { return \"" + method.getName() + "\";}}"; } }
@Override public void render(TreeLogger logger, ResourceContext context, ClientBundleFields fields, RepeatStyle repeatStyle) throws UnableToCompleteException { JClassType stringType = context.getGeneratorContext().getTypeOracle().findType(String.class.getCanonicalName()); String contentsExpression = context.deploy( localized.getUrl(), null, image.isPreventInlining()); normalContentsFieldName = fields.define(stringType, "externalImage", contentsExpression, true, true); if (isRtl) { // Create a transformation to mirror about the Y-axis and translate AffineTransform tx = new AffineTransform(); tx.setTransform(-1, 0, 0, 1, rect.getWidth(), 0); rect.setTransform(tx); byte[] rtlData = ImageBundleBuilder.toPng(logger, rect); String rtlContentsUrlExpression = context.deploy(image.getName() + "_rtl.png", "image/png", rtlData, image.isPreventInlining()); rtlContentsFieldName = fields.define(stringType, "externalImage_rtl", rtlContentsUrlExpression, true, true); } }
TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); JClassType cssResourceInterface = typeOracle.findType(CssResource.class.getCanonicalName()); JClassType resourcePrototypeInterface = typeOracle.findType(ResourcePrototype.class
TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); JClassType superInterface = typeOracle.findType(getSuperclassInterfaceName()); JClassType baseInterface = typeOracle.findType(getBaseclassInterfaceName());
context.getGeneratorContext().getTypeOracle().findType(String.class.getCanonicalName());
JClassType imageResourceType = context.getGeneratorContext().getTypeOracle().findType( ImageResource.class.getName()); assert imageResourceType != null;
private Map<JMethod, String> optimize(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException { TypeOracle typeOracle = context.getGeneratorContext().getTypeOracle(); JClassType cssResourceSubtype = method.getReturnType().isInterface(); assert cssResourceSubtype != null;
/** * Creates a BeanHelper and writes an interface containing its instance. Also, * recursively creates any BeanHelpers on its constrained properties. * (Public for testing.) */ public BeanHelper createHelper(Class<?> clazz, TreeLogger logger, GeneratorContext context) throws UnableToCompleteException { JClassType beanType = context.getTypeOracle().findType(clazz.getCanonicalName()); return doCreateHelper(clazz, beanType, logger, context); }
static JClassType find(TreeLogger logger, GeneratorContext context, String type) throws UnableToCompleteException { JClassType rc = context.getTypeOracle().findType(type); if (rc == null) { logger.log(TreeLogger.ERROR, "TypeOracle could not find " + type); throw new UnableToCompleteException(); } return rc; } }