List of usage examples for com.google.gwt.core.ext.typeinfo JAbstractMethod getParameters
JParameter[] getParameters();
From source file:com.artemis.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private void printMethods(JClassType c, String varName, String methodType, JAbstractMethod[] methodTypes) { if (methodTypes != null) { pb(varName + "." + methodType.toLowerCase() + "s = new " + methodType + "[] {"); for (JAbstractMethod m : methodTypes) { MethodStub stub = new MethodStub(); stub.isPublic = m.isPublic(); stub.enclosingType = getType(c); if (m.isMethod() != null) { stub.isMethod = true;/*from w w w. ja v a2 s .c o m*/ 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; } stub.isConstructor = true; stub.returnType = stub.enclosingType; } stub.jnsi = ""; stub.methodId = nextId(); stub.name = m.getName(); methodStubs.add(stub); String methodAnnotations = getAnnotations(m.getDeclaredAnnotations()); pb("new " + methodType + "(\"" + m.getName() + "\", "); pb(stub.enclosingType + ", "); pb(stub.returnType + ", "); pb("new Parameter[] {"); if (m.getParameters() != null) { for (JParameter p : m.getParameters()) { stub.parameterTypes.add(getType(p.getType())); stub.jnsi += p.getType().getErasedType().getJNISignature(); pb("new Parameter(\"" + p.getName() + "\", " + getType(p.getType()) + ", \"" + p.getType().getJNISignature() + "\"), "); } } pb("}, "); pb(stub.isAbstract + ", " + stub.isFinal + ", " + stub.isStatic + ", " + m.isDefaultAccess() + ", " + m.isPrivate() + ", " + m.isProtected() + ", " + m.isPublic() + ", " + stub.isNative + ", " + m.isVarArgs() + ", " + stub.isMethod + ", " + stub.isConstructor + ", " + stub.methodId + ", " + methodAnnotations + "),"); } pb("};"); } }
From source file:com.badlogic.gwtref.gen.ReflectionCacheSourceCreator.java
License:Apache License
private void createTypeInvokables(JClassType c, String varName, String methodType, JAbstractMethod[] methodTypes) { if (methodTypes != null && methodTypes.length > 0) { pb(varName + "." + methodType.toLowerCase() + "s = new " + methodType + "[] {"); for (JAbstractMethod m : methodTypes) { MethodStub stub = new MethodStub(); stub.isPublic = m.isPublic(); stub.enclosingType = getType(c); if (m.isMethod() != null) { stub.isMethod = true;/*from w w w. ja v a2s. co m*/ 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; } stub.isConstructor = true; stub.returnType = stub.enclosingType; } stub.jnsi = ""; stub.methodId = nextInvokableId++; stub.name = m.getName(); methodStubs.add(stub); pbn(" new " + methodType + "(\"" + m.getName() + "\", "); pbn(stub.enclosingType + ", "); pbn(stub.returnType + ", "); if (m.getParameters() != null && m.getParameters().length > 0) { 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 + "(), "); } pbn("}, "); } else { pbn("EMPTY_PARAMETERS,"); } pb(stub.isAbstract + ", " + stub.isFinal + ", " + stub.isStatic + ", " + m.isDefaultAccess() + ", " + m.isPrivate() + ", " + m.isProtected() + ", " + m.isPublic() + ", " + stub.isNative + ", " + m.isVarArgs() + ", " + stub.isMethod + ", " + stub.isConstructor + ", " + stub.methodId + "," + getAnnotations(m.getDeclaredAnnotations()) + "),"); } pb("};"); } }
From source file:com.github.nmorel.gwtjackson.rebind.bean.BeanProcessor.java
License:Apache License
private static <T extends Annotation> boolean isAllParametersAnnotatedWith(JAbstractMethod method, Class<T> annotation) { for (JParameter parameter : method.getParameters()) { if (!parameter.isAnnotationPresent(annotation)) { return false; }//from ww w. j ava2 s . c o m } return true; }
From source file:com.github.nmorel.gwtjackson.rebind.RebindConfiguration.java
License:Apache License
private MapperType[] getParameters(JType mappedType, JAbstractMethod method, boolean isSerializers) { if (!isSerializers && typeOracle.isEnumSupertype(mappedType)) { // For enums, the constructor requires the enum class. We just return an empty array and will handle it later if (method.getParameters().length == 1 && Class.class.getName().equals(method.getParameters()[0].getType().getQualifiedSourceName())) { return new MapperType[0]; } else {/*from w ww . j av a 2 s . c o m*/ // Not a valid method to create enum deserializer return null; } } MapperType[] parameters = new MapperType[method.getParameters().length]; for (int i = 0; i < method.getParameters().length; i++) { JParameter parameter = method.getParameters()[i]; if (isSerializers) { if (typeOracle.isKeySerializer(parameter.getType())) { parameters[i] = MapperType.KEY_SERIALIZER; } else if (typeOracle.isJsonSerializer(parameter.getType())) { parameters[i] = MapperType.JSON_SERIALIZER; } else { // the parameter is unknown, we ignore this method return null; } } else { if (typeOracle.isKeyDeserializer(parameter.getType())) { parameters[i] = MapperType.KEY_DESERIALIZER; } else if (typeOracle.isJsonDeserializer(parameter.getType())) { parameters[i] = MapperType.JSON_DESERIALIZER; } else { // the parameter is unknown, we ignore this method return null; } } } return parameters; }
From source file:fr.onevu.gwt.uibinder.elementparsers.BeanParser.java
License:Apache License
/** * Generates code to initialize all bean attributes on the given element. * Includes support for <ui:attribute /> children that will apply to * setters/*from w ww . j a v a2 s . com*/ * * @throws UnableToCompleteException */ public void parse(XMLElement elem, String fieldName, JClassType type, UiBinderWriter writer) throws UnableToCompleteException { writer.getDesignTime().handleUIObject(writer, elem, fieldName); final Map<String, String> setterValues = new HashMap<String, String>(); final Map<String, String> localizedValues = fetchLocalizedAttributeValues(elem, writer); final Map<String, String> requiredValues = new HashMap<String, String>(); final Map<String, JType> unfilledRequiredParams = new HashMap<String, JType>(); final OwnerFieldClass ownerFieldClass = OwnerFieldClass.getFieldClass(type, writer.getLogger(), context); /* * Handle @UiFactory and @UiConstructor, but only if the user hasn't * provided an instance via @UiField(provided = true) */ JAbstractMethod creator = null; OwnerField uiField = writer.getOwnerClass().getUiField(fieldName); if ((uiField == null) || (!uiField.isProvided())) { // See if there's a factory method creator = writer.getOwnerClass().getUiFactoryMethod(type); if (creator == null) { // If not, see if there's a @UiConstructor creator = ownerFieldClass.getUiConstructor(); } if (creator != null) { for (JParameter param : creator.getParameters()) { unfilledRequiredParams.put(param.getName(), param.getType()); } } } // Work through the localized attribute values and assign them // to appropriate constructor params or setters (which had better be // ready to accept strings) for (Entry<String, String> property : localizedValues.entrySet()) { String key = property.getKey(); String value = property.getValue(); JType paramType = unfilledRequiredParams.get(key); if (paramType != null) { if (!isString(writer, paramType)) { writer.die(elem, "In %s, cannot apply message attribute to non-string " + "constructor argument %s.", paramType.getSimpleSourceName(), key); } requiredValues.put(key, value); unfilledRequiredParams.remove(key); } else { JMethod setter = ownerFieldClass.getSetter(key); JParameter[] params = setter == null ? null : setter.getParameters(); if (setter == null || !(params.length == 1) || !isString(writer, params[0].getType())) { writer.die(elem, "No method found to apply message attribute %s", key); } else { setterValues.put(key, value); } } } // Now go through the element and dispatch its attributes, remembering // that constructor arguments get first dibs for (int i = elem.getAttributeCount() - 1; i >= 0; i--) { // Backward traversal b/c we're deleting attributes from the xml element XMLAttribute attribute = elem.getAttribute(i); // Ignore xmlns attributes if (attribute.getName().startsWith("xmlns:")) { continue; } String propertyName = attribute.getLocalName(); if (setterValues.keySet().contains(propertyName) || requiredValues.containsKey(propertyName)) { writer.die(elem, "Duplicate attribute name: %s", propertyName); } if (unfilledRequiredParams.keySet().contains(propertyName)) { JType paramType = unfilledRequiredParams.get(propertyName); String value = elem.consumeAttributeWithDefault(attribute.getName(), null, paramType); if (value == null) { writer.die(elem, "Unable to parse %s as constructor argument " + "of type %s", attribute, paramType.getSimpleSourceName()); } requiredValues.put(propertyName, value); unfilledRequiredParams.remove(propertyName); } else { JMethod setter = ownerFieldClass.getSetter(propertyName); if (setter == null) { writer.die(elem, "Class %s has no appropriate set%s() method", elem.getLocalName(), initialCap(propertyName)); } String n = attribute.getName(); String value = elem.consumeAttributeWithDefault(n, null, getParamTypes(setter)); if (value == null) { writer.die(elem, "Unable to parse %s.", attribute); } setterValues.put(propertyName, value); } } if (!unfilledRequiredParams.isEmpty()) { StringBuilder b = new StringBuilder(String.format("%s missing required attribute(s):", elem)); for (String name : unfilledRequiredParams.keySet()) { b.append(" ").append(name); } writer.die(elem, b.toString()); } if (creator != null) { String[] args = makeArgsList(requiredValues, creator); if (creator instanceof JMethod) { // Factory method JMethod factoryMethod = (JMethod) creator; 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)); } writer.setFieldInitializer(fieldName, initializer); } else { // Annotated Constructor writer.setFieldInitializerAsConstructor(fieldName, args); } } for (Map.Entry<String, String> entry : setterValues.entrySet()) { String propertyName = entry.getKey(); String value = entry.getValue(); writer.addStatement("%s.set%s(%s);", fieldName, initialCap(propertyName), value); } }
From source file:fr.onevu.gwt.uibinder.elementparsers.BeanParser.java
License:Apache License
private String[] makeArgsList(final Map<String, String> valueMap, JAbstractMethod method) { JParameter[] params = method.getParameters(); String[] args = new String[params.length]; int i = 0;/* w ww . j a v a2 s . c o m*/ for (JParameter param : params) { args[i++] = valueMap.get(param.getName()); } return args; }
From source file:fr.onevu.gwt.uibinder.elementparsers.UiChildParser.java
License:Apache License
/** * Go through all of the given method's required parameters and consume them * from the given element's attributes. If a parameter is not present in the * element, it will be passed null. Unexpected attributes are an error. * /* www . j a va 2 s . c om*/ * @param element The element to find the necessary attributes for the * parameters to the method. * @param method The method to gather parameters for. * @return The list of parameters to send to the function. * @throws UnableToCompleteException */ private String[] makeArgsList(XMLElement element, JAbstractMethod method, XMLElement toAdd) throws UnableToCompleteException { JParameter[] params = method.getParameters(); String[] args = new String[params.length]; args[0] = writer.parseElementToField(toAdd).getNextReference(); // First parameter is the child widget for (int index = 1; index < params.length; index++) { JParameter param = params[index]; String defaultValue = null; if (param.getType().isPrimitive() != null) { defaultValue = param.getType().isPrimitive().getUninitializedFieldExpression(); } String value = element.consumeAttributeWithDefault(param.getName(), defaultValue, param.getType()); args[index] = value; } if (element.getAttributeCount() > 0) { writer.die(element, "Unexpected attributes"); } return args; }
From source file:org.jboss.errai.ioc.rebind.ioc.codegen.meta.impl.gwt.GWTParameter.java
License:Apache License
GWTParameter(JParameter parameter, MetaMethod declaredBy) {
this.parameter = parameter;
this.declaredBy = declaredBy;
try {/*from w w w . j a v a 2 s .co m*/
Class<?> cls = Class.forName(parameter.getEnclosingMethod().getEnclosingType().getQualifiedSourceName(),
false, Thread.currentThread().getContextClassLoader());
JAbstractMethod jMethod = parameter.getEnclosingMethod();
int index = -1;
for (int i = 0; i < jMethod.getParameters().length; i++) {
if (jMethod.getParameters()[i].getName().equals(parameter.getName())) {
index = i;
}
}
Method method = null;
try {
method = cls.getDeclaredMethod(jMethod.getName(), InjectUtil.jParmToClass(jMethod.getParameters()));
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
annotations = method.getParameterAnnotations()[index];
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
From source file:org.jboss.errai.ioc.rebind.ioc.codegen.meta.impl.gwt.GWTParameter.java
License:Apache License
GWTParameter(JParameter parameter, MetaConstructor declaredBy) {
this.parameter = parameter;
this.declaredBy = declaredBy;
try {/*from ww w . ja v a 2s . c om*/
Class<?> cls = Class.forName(parameter.getEnclosingMethod().getEnclosingType().getQualifiedSourceName(),
false, Thread.currentThread().getContextClassLoader());
JAbstractMethod jMethod = parameter.getEnclosingMethod();
int index = -1;
for (int i = 0; i < jMethod.getParameters().length; i++) {
if (jMethod.getParameters()[i].getName().equals(parameter.getName())) {
index = i;
}
}
Constructor c = null;
try {
c = cls.getConstructor(InjectUtil.jParmToClass(jMethod.getParameters()));
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
annotations = c.getParameterAnnotations()[index];
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}