logger = logger.branch(TreeLogger.DEBUG, "Computing CSS class replacements"); replacementsByClassAndMethod.put(type, replacements); for (JMethod method : type.getOverridableMethods()) { String name = method.getName(); if (ignoredMethods.contains(name)) { continue; ClassName classNameOverride = method.getAnnotation(ClassName.class); if (classNameOverride != null) { name = classNameOverride.value(); if (method.getEnclosingType() == type) { Shared shared = type.getAnnotation(Shared.class); if (shared != null) { replacementsForSharedMethods.put(method, obfuscatedClassName); if (logger.isLoggable(TreeLogger.SPAM)) { logger.log(TreeLogger.SPAM, "Mapped " + type.getQualifiedSourceName() + "." + name + " to " + obfuscatedClassName);
if (m.isMethod() != null) { stub.isMethod = true; stub.returnType = getType(m.isMethod().getReturnType()); stub.isStatic = m.isMethod().isStatic(); stub.isAbstract = m.isMethod().isAbstract(); stub.isNative = m.isMethod().isAbstract(); stub.isFinal = m.isMethod().isFinal(); } else { if (m.isPrivate() || m.isDefaultAccess()) { logger.log(Type.INFO, "Skipping non-visible constructor for class " + c.getName()); continue; if (m.getEnclosingType().isFinal() && !m.isPublic()) { logger.log(Type.INFO, "Skipping non-public constructor for final class" + c.getName()); continue; pbn("new Parameter[] {"); for (JParameter p : m.getParameters()) { stub.parameterTypes.add(getType(p.getType())); stub.jnsi += p.getType().getErasedType().getJNISignature(); String paramName = (p.getName() + "__" + p.getType().getErasedType().getJNISignature()).replaceAll( "[/;\\[\\]]", "_"); String paramInstantiation = "new Parameter(\"" + p.getName() + "\", " + getType(p.getType()) + ", \""
String name = toImplement.getName(); if (ignoredMethods.contains(name)) { continue; logger.log(TreeLogger.ERROR, "@def shadows CSS class name: " + name + ". Fix by renaming the @def name or the CSS class name."); throw new UnableToCompleteException(); if (defs.contains(toImplement.getName()) && toImplement.getParameters().length == 0) { writeDefAssignment(logger, sw, toImplement, sheet); } else if (toImplement.getReturnType().getQualifiedSourceName() .equals("java.lang.String") && toImplement.getParameters().length == 0) { writeClassAssignment(sw, toImplement, obfuscatedClassNames); } else { logger.log(TreeLogger.ERROR, "Don't know how to implement method " + toImplement.getName()); throw new UnableToCompleteException();
if (type.getQualifiedSourceName().contains("-")) { nesting--; return; String name = type.getQualifiedSourceName(); try { ConfigurationProperty prop; if (types.contains(type.getErasedType())) { nesting--; return; JField[] fields = c.getFields(); if (fields != null) { for (JField field : fields) { gatherTypes(c.getSuperclass(), types); JClassType[] interfaces = c.getImplementedInterfaces(); if (interfaces != null) { for (JClassType i : interfaces) { if (methods != null) { for (JMethod m : methods) { gatherTypes(m.getReturnType().getErasedType(), types); if (m.getParameterTypes() != null) { for (JType p : m.getParameterTypes()) { gatherTypes(p.getErasedType(), types);
private static String key(JMethod method) { return method.getEnclosingType().getQualifiedSourceName() + "." + method.getName(); }
public String getOrMakeMethodFactory(TreeLogger logger, GeneratorContext ctx, com.google.gwt.core.ext.typeinfo.JMethod method, com.google.gwt.core.ext.typeinfo.JType classType, ReflectionManifest manifest, boolean declaredOnly) throws UnableToCompleteException { // get cached manifest for this type String clsName = classType.getQualifiedSourceName(); TypeOracle oracle = ctx.getTypeOracle(); String name = method.getName(); JClassType cls = oracle.findType(clsName); if (cls == null) { logger.log(Type.ERROR, "Unable to find enclosing class "+clsName); throw new UnableToCompleteException(); } String methodFactoryName = getMethodFactoryName(cls, name, method.getParameters()); JClassType factory; String pkgName = method.getEnclosingType().getPackage().getName(); factory = oracle.findType(pkgName, methodFactoryName); if (factory == null) { return generateMethodFactory(logger, ctx, method, methodFactoryName, manifest); } else return (pkgName.length()==0?"":pkgName+".")+ methodFactoryName; }
isReturnTypeString(userMethod.getReturnType().isClass())) { methodToClassName.put(userMethod, substitutionMap.get(className)); return writeClassMethod(logger, userMethod, substitutionMap, sw); String methodName = userMethod.getName(); logger.log(Type.ERROR, "The return type of the method [" + userMethod.getName() + "] must " + "be java.lang.String."); throw new UnableToCompleteException(); logger.log(Type.ERROR, "The following method [" + userMethod.getName() + "()] doesn't match a constant" + " nor a style class. You could fix that by adding ." + className + " {}" );
protected String toStringExpression(JParameter arg) throws UnableToCompleteException { Attribute attribute = getAnnotation(arg, Attribute.class); if (attribute != null) { if (arg.getType().isClass().getField(attribute.value()) != null && arg.getType().isClass().getField(attribute.value()).isPublic()) { return "(" + arg.getName() + "." + attribute.value() + "+ \"\")"; } String publicGetter = "get" + attribute.value().substring(0, 1).toUpperCase() + attribute.value().substring(1); for (JMethod jMethod : arg.getType().isClass().getMethods()) { if (jMethod.getName().equals(publicGetter)) { return "(" + arg.getName() + "." + publicGetter + "()" + "+ \"\")"; } } getLogger().log(ERROR, "Neither public argument " + attribute.value() + " nor public getter " + publicGetter + " found!"); throw new UnableToCompleteException(); } return toStringExpression(arg.getType(), arg.getName()); }
@Override public void prepare(TreeLogger logger, ResourceContext context, ClientBundleRequirements requirements, JMethod method) throws UnableToCompleteException { if (method.getReturnType().isInterface() == null) { logger.log(TreeLogger.ERROR, "Return type must be an interface"); throw new UnableToCompleteException(); } URL[] resourceUrls = findResources(logger, context, method, gssOptions.isEnabled()); if (resourceUrls.length == 0) { logger.log(TreeLogger.ERROR, "At least one source must be specified"); throw new UnableToCompleteException(); } CssParsingResult cssParsingResult = parseResources(Lists.newArrayList(resourceUrls), context, logger); cssParsingResultMap.put(method, cssParsingResult); for (String permutationAxis : cssParsingResult.permutationAxes) { try { context.getRequirements().addPermutationAxis(permutationAxis); } catch (BadPropertyValueException e) { logger.log(TreeLogger.ERROR, "Unknown deferred-binding property " + permutationAxis, e); throw new UnableToCompleteException(); } } }
/** * Given a JMethod, find the a ResourceGenerator class that will be able to * provide an implementation of the method. */ private Class<? extends ResourceGenerator> findResourceGenerator( TreeLogger logger, JMethod method) throws UnableToCompleteException { JClassType resourceType = method.getReturnType().isClassOrInterface(); assert resourceType != null; ResourceGeneratorType annotation = resourceType.findAnnotationInTypeHierarchy(ResourceGeneratorType.class); if (annotation == null) { logger.log(TreeLogger.ERROR, "No @" + ResourceGeneratorType.class.getName() + " was specifed for type " + resourceType.getQualifiedSourceName() + " or its supertypes"); throw new UnableToCompleteException(); } return annotation.value(); }
ResourceContext context, JMethod method, String[] defaultSuffixes) throws UnableToCompleteException { logger = logger.branch(TreeLogger.DEBUG, "Finding resources"); Source resourceAnnotation = method.getAnnotation(Source.class); URL[] toReturn; if (defaultSuffixes != null) { for (String extension : defaultSuffixes) { if (logger.isLoggable(TreeLogger.SPAM)) { logger.log(TreeLogger.SPAM, "Trying default extension " + extension); getPathRelativeToPackage(method.getEnclosingType().getPackage(), method.getName() + extension), locale); getPathRelativeToPackage(method.getEnclosingType().getPackage(), resource), locale); throw new UnableToCompleteException();
private void writeCommandDefinition(TreeLogger logger, SourceWriter srcWriter, JMethod method, JParameter callbackParameter) throws UnableToCompleteException { srcWriter.print("CommandDefinition commandDefinition = new CommandDefinition("); srcWriter.print("\"%s\", ", this.serviceType.getQualifiedSourceName()); srcWriter.print("\"%s\", ", method.getName()); if (callbackParameter != null) { JParameterizedType parameterizedCallback = callbackParameter.getType().isParameterized(); if (parameterizedCallback != null) { srcWriter.print("\"%s\" ", parameterizedCallback.getTypeArgs()[0].getQualifiedSourceName()); } else { logger.branch(TreeLogger.ERROR, "Callback argument type for method " + method.getName() + " is not parametrized", null); throw new UnableToCompleteException(); } } else { srcWriter.print("\"%s\" ", method.getReturnType().getQualifiedSourceName()); } for (JParameter parameter : method.getParameters()) { if (!parameter.equals(callbackParameter)) { srcWriter.print(", \"%s\"", parameter.getType().getQualifiedSourceName()); } } srcWriter.println(");"); }
if (method.getParameterTypes().length != 1) { logger.log(Type.ERROR, String.format("Method %s.%s annotated with @Subscribe must take exactly one argument.", target.getName(), method.getName())); throw new UnableToCompleteException(); } else if (method.isPrivate()) { logger.log(Type.ERROR, String.format("Method %s.%s annotated with @Subscribe must not be private.", target.getName(), method.getName())); throw new UnableToCompleteException(); if (method.getParameterTypes()[0].getQualifiedSourceName().equals( MultiEvent.class.getCanonicalName())) { if (method.getParameters()[0].getAnnotation(EventTypes.class) == null) { logger.log(Type.ERROR, String.format("MultiEvent in method %s.%s must be annotated with @EventTypes.", target.getName(), method.getName())); throw new UnableToCompleteException(); Class<?>[] classes = method.getParameters()[0].getAnnotation(EventTypes.class).value(); for (Class<?> c1 : classes) { for (Class<?> c2 : classes) { c2.getSimpleName(), c1.getSimpleName(), target.getName(), method.getName())); if (method.getParameters()[0].getAnnotation(EventTypes.class) != null) { "@EventTypes must not be applied to a non-MultiEvent parameter in method %s.%s.",
private static boolean isJUnitTestMethod(JMethod m) { return m.isPublic() && m.getName().startsWith("test") && m.getParameters().length == 0 && m.getReturnType().getQualifiedBinaryName().equals(Void.TYPE.getName()); } }
private boolean writeClassMethod(TreeLogger logger, JMethod userMethod, Map<String, String> substitutionMap, SourceWriter sw) throws UnableToCompleteException { if (userMethod.getParameters().length > 0) { logger.log(Type.ERROR, "The method [" + userMethod.getName() + "] shouldn't contain any " + "parameters"); throw new UnableToCompleteException(); } String name = getClassName(userMethod); String value = substitutionMap.get(name); if (value == null) { logger.log(Type.ERROR, "The following style class [" + name + "] is missing from the source" + " CSS file"); return false; } else { writeSimpleGetter(userMethod, "\"" + value + "\"", sw); } return true; }
@Override public void prepare(TreeLogger logger, ResourceContext context, ClientBundleRequirements requirements, JMethod method) throws UnableToCompleteException { URL[] urls = ResourceGeneratorUtil.findResources(logger, context, method); if (urls.length != 1) { logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null); throw new UnableToCompleteException(); } URL resource = urls[0]; String toWrite = Util.readURLAsString(resource); // This de-duplicates strings in the bundle. if (!hashes.containsKey(toWrite)) { hashes.put(toWrite, currentIndex++); if (!first) { data.append(",\n"); } else { first = false; } data.append('"'); data.append(Generator.escape(toWrite)); data.append('"'); } // Store the (possibly n:1) mapping of resource function to bundle index. offsets.put(method.getName(), hashes.get(toWrite)); }
unfilledRequiredParams.put(param.getName(), param.getType()); "In %s, cannot apply message attribute to non-string " + "constructor argument %s.", paramType.getSimpleSourceName(), key); } else { JMethod setter = ownerFieldClass.getSetter(key); JParameter[] params = setter == null ? null : setter.getParameters(); || !isString(writer, params[0].getType())) { writer.die(elem, "No method found to apply message attribute %s", key); } else { if (value == null) { writer.die(elem, "Unable to parse %s as constructor argument " + "of type %s", attribute, paramType.getSimpleSourceName()); String initializer; if (writer.getDesignTime().isDesignTime()) { String typeName = factoryMethod.getReturnType().getQualifiedSourceName(); initializer = writer.getDesignTime().getProvidedFactory(typeName, factoryMethod.getName(), UiBinderWriter.asCommaSeparatedList(args)); } else { initializer = String.format("owner.%s(%s)", factoryMethod.getName(), UiBinderWriter.asCommaSeparatedList(args));
public void setDeclarationMethod(JClassType contextType, JMethod declarationMethod) { toReturn.declarationMethod = declarationMethod; JClassType returnClass = declarationMethod.getReturnType().isClassOrInterface(); JsonRpcWireName annotation = returnClass == null ? null : returnClass.getAnnotation(JsonRpcWireName.class); if (annotation == null) { StringBuilder sb = new StringBuilder("("); for (JType type : declarationMethod.getParameterTypes()) { sb.append(type.getJNISignature()); } // Return type ignored sb.append(")V"); toReturn.operation = new OperationKey(contextType.getQualifiedBinaryName(), declarationMethod.getName(), sb .toString()).get(); } else { toReturn.operation = annotation.value(); toReturn.apiVersion = annotation.version(); } }
public void setMethod(JMethod method) { setName(method.getName()); setReturnType(method.getReturnType().isClassOrInterface()); if (method.getParameters().length == 1) { setWrappedType(method.getParameters()[0].getType().isClassOrInterface()); } }
logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null); throw new UnableToCompleteException(); MimeType mimeTypeAnnotation = method.getAnnotation(MimeType.class); String mimeType = mimeTypeAnnotation != null ? mimeTypeAnnotation.value() : null; DoNotEmbed doNotEmbed = method.getAnnotation(DoNotEmbed.class); boolean forceExternal = (doNotEmbed != null); sw.println('"' + method.getName() + "\","); sw.println(UriUtils.class.getName() + ".fromTrustedString(" + outputUrlExpression + ")"); sw.outdent();