List of usage examples for com.google.gwt.core.ext.typeinfo JParameter getEnclosingMethod
JAbstractMethod getEnclosingMethod();
From source file:com.gwtplatform.dispatch.rest.rebind.parameter.HttpParameterFactory.java
License:Apache License
private void error(JParameter parameter, String message) { JAbstractMethod method = parameter.getEnclosingMethod(); String typeName = method.getEnclosingType().getQualifiedSourceName(); String methodName = method.getName(); String parameterName = parameter.getName(); logger.error(String.format(message, typeName, methodName, parameterName)); }
From source file:fr.onevu.gwt.uibinder.rebind.JClassTypeAdapter.java
License:Apache License
/** * Creates an array of mock GWT parameters for the given array of java * parameters.// www .ja va 2 s .co m * * @param parameterTypes the types of the parameters * @param parameterAnnotations the list of annotations for each parameter * @param method the method or constructor to which the parameters belong * @return an array of GWT parameters */ @SuppressWarnings("unchecked") protected JParameter[] adaptParameters(Class<?>[] parameterTypes, Annotation[][] parameterAnnotations, JAbstractMethod method) { JParameter[] parameters = new JParameter[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { final Class<?> realParameterType = parameterTypes[i]; JParameter parameter = createMock(JParameter.class); parameters[i] = parameter; // TODO(rdamazio): getName() has no plain java equivalent. // Perhaps compiling with -g:vars ? expect(parameter.getEnclosingMethod()).andStubReturn(method); expect(parameter.getType()).andStubAnswer(new IAnswer<JType>() { public JType answer() throws Throwable { return adaptType(realParameterType); } }); // Add annotation behaviour final Annotation[] annotations = parameterAnnotations[i]; expect(parameter.isAnnotationPresent(isA(Class.class))).andStubAnswer(new IAnswer<Boolean>() { public Boolean answer() throws Throwable { Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) EasyMock .getCurrentArguments()[0]; for (Annotation annotation : annotations) { if (annotation.equals(annotationClass)) { return true; } } return false; } }); expect(parameter.getAnnotation(isA(Class.class))).andStubAnswer(new IAnswer<Annotation>() { public Annotation answer() throws Throwable { Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) EasyMock .getCurrentArguments()[0]; for (Annotation annotation : annotations) { if (annotation.equals(annotationClass)) { return annotation; } } return null; } }); EasyMock.replay(parameter); } return parameters; }
From source file:org.cruxframework.crux.core.rebind.ioc.IocContainerRebind.java
License:Apache License
@SuppressWarnings("deprecation") private static String getParameterInjectionExpression(JParameter parameter, String iocContainerVariable, Map<String, IocConfig<?>> configurations) { JType parameterType = parameter.getType(); if (parameterType.isClassOrInterface() != null) { String fieldTypeName = parameterType.getQualifiedSourceName(); IocConfigImpl<?> iocConfig = (IocConfigImpl<?>) configurations.get(fieldTypeName); if (iocConfig != null) { Inject inject = getInjectAnnotation(parameter); if (inject.scope().equals(org.cruxframework.crux.core.client.ioc.Inject.Scope.DEFAULT)) { return iocContainerVariable + ".get" + fieldTypeName.replace('.', '_') + "(" + Scope.class.getCanonicalName() + "." + iocConfig.getScope().name() + ", null)"; }/* w w w . j a v a 2 s .c o m*/ return iocContainerVariable + ".get" + fieldTypeName.replace('.', '_') + "(" + Scope.class.getCanonicalName() + "." + getScopeName(inject.scope()) + ", " + EscapeUtils.quote(inject.subscope()) + ")"; } else { return "GWT.create(" + fieldTypeName + ".class)"; } } else { throw new IoCException("Error injecting parameter [" + parameter.getName() + "] from method [" + parameter.getEnclosingMethod().getReadableDeclaration() + "]. Primitive fields can not be handled by ioc container."); } }
From source file:org.cruxframework.crux.core.rebind.ioc.IocContainerRebind.java
License:Apache License
private static Inject getInjectAnnotation(JParameter parameter) { Inject result = parameter.getAnnotation(Inject.class); if (result == null) { result = parameter.getEnclosingMethod().getAnnotation(Inject.class); }/*from w w w . j a v a 2 s . co m*/ return result; }
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 www . j a v a 2 s .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; } } 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 www . j a va 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; } } 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(); } }