for (JMethod m : methods) { gatherTypes(m.getReturnType().getErasedType(), types); if (m.getParameterTypes() != null) { for (JType p : m.getParameterTypes()) { gatherTypes(p.getErasedType(), types);
for (JMethod m : methods) { gatherTypes(m.getReturnType().getErasedType(), types); if (m.getParameterTypes() != null) { for (JType p : m.getParameterTypes()) { gatherTypes(p.getErasedType(), types);
private boolean isBeanFormat(final JMethod method) { if (method.getParameterTypes().length == 0) { // This, if anything, is a getter. return method.getReturnType() != JPrimitiveType.VOID; } return method.getParameterTypes().length == 1; }
public ArrayList<JMethod> getMethodsNamed( TreeLogger logger, String name, boolean declaredOnly, GeneratorContext ctx) { ArrayList<JMethod> list = new ArrayList<JMethod>(); JClassType from = type; HashSet<String> seen = new HashSet<String>(); while (from != null) { for (JMethod method : from.getMethods()) { if (method.getName().equals(name)) { if (seen.add(ReflectionUtilType.toJsniClassLits(method.getParameterTypes()))) list.add(method); } } if (declaredOnly) return list; from = from.getSuperclass(); } return list; }
public ArrayList<JMethod> getMethodsNamed( final TreeLogger logger, final String name, final boolean declaredOnly, final GeneratorContext ctx) { final ArrayList<JMethod> list = new ArrayList<JMethod>(); JClassType from = type; final HashSet<String> seen = new HashSet<String>(); while (from != null) { for (final JMethod method : from.getMethods()) { if (method.getName().equals(name)) { if (seen.add(ReflectionUtilType.toJsniClassLits(method.getParameterTypes()))) { list.add(method); } } } if (declaredOnly) { return list; } from = from.getSuperclass(); } return list; }
private String getFirstParameterType(JMethod method) { // If the parameter type is primitive, box it JType type = method.getParameterTypes()[0]; if (type.isPrimitive() != null) { if (type.isPrimitive() == JPrimitiveType.BOOLEAN) { return Boolean.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.BYTE) { return Byte.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.CHAR) { return Character.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.DOUBLE) { return Double.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.FLOAT) { return Float.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.INT) { return Integer.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.LONG) { return Long.class.getName(); } else if (type.isPrimitive() == JPrimitiveType.SHORT) { return Short.class.getName(); } } // Otherwise return the fully-qualified type name return type.getQualifiedSourceName(); }
@Override public Set<JType> findStorageTypes() throws UnableToCompleteException{ Set<JType> serializables = new HashSet<>(); JClassType remoteSvcIntf = typeOracle.findType(RemoteService.class.getName()); JClassType[] remoteSvcTypes = remoteSvcIntf.getSubtypes(); for(JClassType remoteSvcType : remoteSvcTypes){ for(JMethod method : remoteSvcType.getMethods()){ JType type = method.getReturnType(); if(JPrimitiveType.VOID != type){ addIfIsValidType(serializables, type); } for(JType param : method.getParameterTypes()){ addIfIsValidType(serializables, param); } } } return serializables; }
private Optional<MethodSpec> buildInitAnySetterDeserializerMethod( PropertyInfo anySetterPropertyInfo ) throws UnableToCompleteException { FieldAccessor fieldAccessor = anySetterPropertyInfo.getSetterAccessor().get(); JType type = fieldAccessor.getMethod().get().getParameterTypes()[1]; JDeserializerType deserializerType; try { deserializerType = getJsonDeserializerFromType( type ); } catch ( UnsupportedTypeException e ) { logger.log( Type.WARN, "Method '" + fieldAccessor.getMethod().get() .getName() + "' annotated with @JsonAnySetter has an unsupported type" ); return Optional.absent(); } return Optional.of( MethodSpec.methodBuilder( "initAnySetterDeserializer" ) .addModifiers( Modifier.PROTECTED ) .addAnnotation( Override.class ) .returns( ParameterizedTypeName.get( ClassName.get( AnySetterDeserializer.class ), typeName( beanInfo.getType() ), DEFAULT_WILDCARD ) ) .addStatement( "return $L", buildDeserializer( anySetterPropertyInfo, type, deserializerType ) ) .build() ); }
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 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(); } }
/** * Scans a class to validate that it contains a single method called render, * which has a {@code void} return type, and its first parameter is of type * {@code SafeHtmlBuilder}. */ private void validateRenderParameters(JClassType owner) throws UnableToCompleteException { JMethod[] methods = owner.getInheritableMethods(); JMethod renderMethod = null; for (JMethod jMethod : methods) { if (jMethod.getName().equals("render")) { if (renderMethod == null) { renderMethod = jMethod; } else { die("%s declares more than one method named render", owner.getQualifiedSourceName()); } } } if (renderMethod == null || renderMethod.getParameterTypes().length < 1 || !renderMethod.getParameterTypes()[0].getErasedType().getQualifiedSourceName().equals( SafeHtmlBuilder.class.getCanonicalName())) { die("%s does not declare a render(SafeHtmlBuilder ...) method", owner.getQualifiedSourceName()); } if (!JPrimitiveType.VOID.equals(renderMethod.getReturnType())) { die("%s#render(SafeHtmlBuilder ...) does not return void", owner.getQualifiedSourceName()); } }
/** * Scans a class to validate that it contains a single method called render, * which has a {@code void} return type, and its first parameter is of type * {@code SafeHtmlBuilder}. */ private void validateRenderParameters(JClassType owner) throws UnableToCompleteException { JMethod[] methods = owner.getInheritableMethods(); JMethod renderMethod = null; for (JMethod jMethod : methods) { if (jMethod.getName().equals("render")) { if (renderMethod == null) { renderMethod = jMethod; } else { die("%s declares more than one method named render", owner.getQualifiedSourceName()); } } } if (renderMethod == null || renderMethod.getParameterTypes().length < 1 || !renderMethod.getParameterTypes()[0].getErasedType().getQualifiedSourceName().equals( SafeHtmlBuilder.class.getCanonicalName())) { die("%s does not declare a render(SafeHtmlBuilder ...) method", owner.getQualifiedSourceName()); } if (!JPrimitiveType.VOID.equals(renderMethod.getReturnType())) { die("%s#render(SafeHtmlBuilder ...) does not return void", owner.getQualifiedSourceName()); } }
/** * Scans a class to validate that it contains a single method called render, * which has a {@code void} return type, and its first parameter is of type * {@code SafeHtmlBuilder}. */ private void validateRenderParameters(JClassType owner) throws UnableToCompleteException { JMethod[] methods = owner.getInheritableMethods(); JMethod renderMethod = null; for (JMethod jMethod : methods) { if (jMethod.getName().equals("render")) { if (renderMethod == null) { renderMethod = jMethod; } else { die("%s declares more than one method named render", owner.getQualifiedSourceName()); } } } if (renderMethod == null || renderMethod.getParameterTypes().length < 1 || !renderMethod.getParameterTypes()[0].getErasedType().getQualifiedSourceName().equals( SafeHtmlBuilder.class.getCanonicalName())) { die("%s does not declare a render(SafeHtmlBuilder ...) method", owner.getQualifiedSourceName()); } if (!JPrimitiveType.VOID.equals(renderMethod.getReturnType())) { die("%s#render(SafeHtmlBuilder ...) does not return void", owner.getQualifiedSourceName()); } }
/** * Scans a class to validate that it contains a single method called render, * which has a {@code void} return type, and its first parameter is of type * {@code SafeHtmlBuilder}. */ private void validateRenderParameters(JClassType owner) throws UnableToCompleteException { JMethod[] methods = owner.getInheritableMethods(); JMethod renderMethod = null; for (JMethod jMethod : methods) { if (jMethod.getName().equals("render")) { if (renderMethod == null) { renderMethod = jMethod; } else { die("%s declares more than one method named render", owner.getQualifiedSourceName()); } } } if (renderMethod == null || renderMethod.getParameterTypes().length < 1 || !renderMethod.getParameterTypes()[0].getErasedType().getQualifiedSourceName().equals( SafeHtmlBuilder.class.getCanonicalName())) { die("%s does not declare a render(SafeHtmlBuilder ...) method", owner.getQualifiedSourceName()); } if (!JPrimitiveType.VOID.equals(renderMethod.getReturnType())) { die("%s#render(SafeHtmlBuilder ...) does not return void", owner.getQualifiedSourceName()); } }
@Override public void endVisit(RequestMethod x) { // Request<Foo> -> Foo maybeVisit(x.getDataType()); // InstanceRequest<Proxy, Foo> -> Proxy if (x.getInstanceType() != null) { x.getInstanceType().accept(this); } // Request<Void> doSomething(Foo foo, Bar bar) -> Foo, Bar for (JType param : x.getDeclarationMethod().getParameterTypes()) { maybeVisit(param.isClassOrInterface()); } // setFoo(Foo foo) -> Foo for (JMethod method : x.getExtraSetters()) { maybeVisit(method.getParameterTypes()[0].isClassOrInterface()); } }
throws UnableToCompleteException { String eventTypeName = jMethod.getParameterTypes()[0].getQualifiedSourceName();
@Override public void endVisit(RequestMethod x) { // Request<Foo> -> Foo maybeVisit(x.getDataType()); // InstanceRequest<Proxy, Foo> -> Proxy if (x.getInstanceType() != null) { x.getInstanceType().accept(this); } // Request<Void> doSomething(Foo foo, Bar bar) -> Foo, Bar for (JType param : x.getDeclarationMethod().getParameterTypes()) { maybeVisit(param.isClassOrInterface()); } // setFoo(Foo foo) -> Foo for (JMethod method : x.getExtraSetters()) { maybeVisit(method.getParameterTypes()[0].isClassOrInterface()); } }
throws UnableToCompleteException { String eventTypeName = jMethod.getParameterTypes()[0].getQualifiedSourceName();
JType[] types = method.getParameterTypes(); if (types.length == params.size()) { for (int i = 0, m = types.length; i < m; i++ ) {
public String generate(TreeLogger treeLogger, GeneratorContext generatorContext, String requestedClass) throws UnableToCompleteException { oracle = generatorContext.getTypeOracle(); JClassType clazz = oracle.findType(requestedClass); xmlBuilderType = oracle.findType(XmlBuilder.class.getName()); stringType = oracle.findType(String.class.getName()); String t[] = generateClassName(clazz); SourceWriter sw = getSourceWriter(treeLogger, generatorContext, t[0], t[1], requestedClass); if (sw != null) { for (JMethod method : clazz.getInheritableMethods()) { // skip method from JsonBuilder if (xmlBuilderType.findMethod(method.getName(), method.getParameterTypes()) != null) { continue; } generateMethod(sw, method, treeLogger); } sw.commit(treeLogger); } return t[2]; }