private String createTypeGenerator (JType t) { sb.setLength(0); int id = nextTypeId++; typeNames2typeIds.put(t.getErasedType().getQualifiedSourceName(), id); JClassType c = t.isClass(); String name = t.getErasedType().getQualifiedSourceName(); String superClass = null; if (c != null && (isVisible(c.getSuperclass()))) superClass = c.getSuperclass().getErasedType().getQualifiedSourceName() + ".class"; String assignables = null; String interfaces = null; boolean used = false; for (JType i : c.getFlattenedSupertypeHierarchy()) { if (!isVisible(i) || i.equals(t) || "java.lang.Object".equals(i.getErasedType().getQualifiedSourceName())) continue; if (used) assignables += ", "; assignables += i.getErasedType().getQualifiedSourceName() + ".class"; used = true; c = t.isInterface(); if (!isVisible(i) || i.equals(t)) continue; if (used) interfaces += ", "; interfaces += i.getErasedType().getQualifiedSourceName() + ".class"; used = true; if( c == null && t.isArray() != null){ c = t.isArray();
private String getElementTypes (JField f) { StringBuilder b = new StringBuilder(); JParameterizedType params = f.getType().isParameterized(); if (params != null) { JClassType[] typeArgs = params.getTypeArgs(); b.append("new Class[] {"); for (JClassType typeArg : typeArgs) { if (typeArg.isWildcard() != null) b.append("null"); else if (!isVisible(typeArg)) b.append("null"); else if (typeArg.isClassOrInterface() != null) b.append(typeArg.isClassOrInterface().getQualifiedSourceName()).append(".class"); else if (typeArg.isParameterized() != null) b.append(typeArg.isParameterized().getQualifiedBinaryName()).append(".class"); else b.append("null"); b.append(", "); } b.append("}"); return b.toString(); } return "null"; }
private String getType (JType type) { if (!isVisible(type)) return null; return type.getErasedType().getQualifiedSourceName() + ".class"; }
if (type.getQualifiedSourceName().contains("-")) { nesting--; return; String name = type.getQualifiedSourceName(); try { ConfigurationProperty prop; if (types.contains(type.getErasedType())) { nesting--; return; types.add(type.getErasedType()); out(type.getErasedType().getQualifiedSourceName(), nesting); JField[] fields = c.getFields(); if (fields != null) { for (JField field : fields) { gatherTypes(field.getType().getErasedType(), types); 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);
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()) + ", \"" + p.getType().getJNISignature() + "\")"; parameterName2ParameterInstantiation.put(paramName, paramInstantiation); pbn(paramName + "(), ");
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(");"); }
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 + " {}"
@Override public JClassType execute() throws UnableToCompleteException { for (JMethod method : callbackType.getOverridableMethods()) { getLogger().log(DEBUG, "checking method: " + method.getName()); if (method.getName().equals("onSuccess")) { JParameter[] parameters = method.getParameters(); getLogger().log(DEBUG, "checking method params: " + parameters.length); if (parameters.length == 2) { getLogger().log(DEBUG, "checking first param: " + parameters[0].getType()); if (parameters[0].getType() == METHOD_TYPE) { getLogger().log(DEBUG, "checking 2nd param: " + parameters[1].getType()); JType param2Type = parameters[1].getType(); JClassType type = param2Type.isClassOrInterface(); if (type == null) { getLogger().log(ERROR, "The type of the callback not supported: " + param2Type.getJNISignature()); throw new UnableToCompleteException(); } getLogger().log(DEBUG, "match: " + type); return type; } } } } getLogger().log(ERROR, "The type of the callback could not be determined: " + callbackType.getParameterizedQualifiedSourceName()); throw new UnableToCompleteException(); } });
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()); }
public Builder setDeclaredMethod(JMethod method) { toReturn.methodName = method.getName(); JClassType returnClass = method.getReturnType().isClassOrInterface(); toReturn.interfaceName = returnClass.getQualifiedSourceName(); toReturn.packageName = returnClass.getPackage().getName(); toReturn.simpleSourceName = returnClass.getName().replace('.', '_') + "Impl"; toReturn.dialect = returnClass.isAnnotationPresent(JsonRpcService.class) ? Dialect.JSON_RPC : Dialect.STANDARD; return this; }
/** * 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(); }
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();
public String getOrMakeFieldFactory(TreeLogger logger, GeneratorContext ctx, com.google.gwt.core.ext.typeinfo.JField field, 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 = field.getName(); JClassType cls = oracle.findType(clsName); if (cls == null) { logger.log(Type.ERROR, "Unable to find enclosing class "+clsName); throw new UnableToCompleteException(); } String fieldFactoryName = getFieldFactoryName(cls, name); JClassType factory; String pkgName = field.getEnclosingType().getPackage().getName(); factory = oracle.findType(pkgName, fieldFactoryName); if (factory == null) { return generateFieldFactory(logger, ctx, field, fieldFactoryName, manifest); } else return (pkgName.length()==0?"":pkgName+".")+ fieldFactoryName; }
private void writeRendererDispatcherExtraParameters(IndentedWriter w, JMethod sourceMethod) { for (int i = 3; i < sourceMethod.getParameters().length; i++) { JParameter param = sourceMethod.getParameters()[i]; // private int a; // private String b; w.write("private %s %s;", param.getType().getParameterizedQualifiedSourceName(), param.getName()); } }
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 {
for (String pathElement : pathElements) { JClassType referenceType = currentType.isClassOrInterface(); if (referenceType == null) { throw new NotFoundException("Cannot resolve member " + pathElement + " on type " + currentType.getQualifiedSourceName()); + pathElement + " in type " + currentType.getQualifiedSourceName()); currentType = currentMethod.getReturnType(); JPrimitiveType expectedIsPrimitive = expectedReturnType.isPrimitive(); JClassType expectedIsClassType = expectedReturnType.isClassOrInterface(); boolean error = false; if (!expectedIsPrimitive.equals(currentMethod.getReturnType())) { error = true; JClassType returnIsClassType = currentMethod.getReturnType().isClassOrInterface(); if (returnIsClassType == null) { error = true; } else if (!expectedIsClassType.isAssignableFrom(returnIsClassType)) { error = true; + expectedReturnType.getQualifiedSourceName() + " found " + currentMethod.getReturnType().getQualifiedSourceName());
public void setMethod(JMethod method) { setName(method.getName()); setReturnType(method.getReturnType().isClassOrInterface()); if (method.getParameters().length == 1) { setWrappedType(method.getParameters()[0].getType().isClassOrInterface()); } }
String getRunAsync(JClassType originalType) { JMethod[] methods = originalType.getOverridableMethods(); for (JMethod method : methods) { if ("load".equals(method.getName())) { return method.getParameters()[0].getType() .getQualifiedSourceName(); } } return null; }
private static String computeInternalSignature(JMethod method) { StringBuffer sb = new StringBuffer(); sb.setLength(0); sb.append(method.getName()); JParameter[] params = method.getParameters(); for (JParameter param : params) { sb.append("/"); JType paramType = param.getType(); sb.append(paramType.getErasedType().getQualifiedSourceName()); } return sb.toString(); }