@Override public Collection<MetaClass> provideTypesToExpose() { final Set<MetaClass> types = new HashSet<MetaClass>(); for (final MetaClass metaClass : ClassScanner.getTypesAnnotatedWith(Remote.class)) { for (final MetaMethod method : metaClass.getDeclaredMethods()) { if (!method.getReturnType().isVoid()) { types.add(method.getReturnType().getErased()); } for (final MetaParameter parameter : method.getParameters()) { final MetaClass type = parameter.getType(); types.add(type.getErased()); final MetaParameterizedType parameterizedType = type.getParameterizedType(); if (parameterizedType != null) { for (final MetaType tp : parameterizedType.getTypeParameters()) { if (tp instanceof MetaClass) { types.add(((MetaClass) tp).getErased()); } } } } } } return types; } }
private void generateMethod(ClassStructureBuilder<?> classBuilder, MetaMethod method) { final List<Class<?>> interceptors = interceptorProvider.getInterceptors(remote, method); final boolean intercepted = !interceptors.isEmpty(); final Parameter[] parms = DefParameters.from(method).getParameters().toArray(new Parameter[0]); final Parameter[] finalParms = new Parameter[parms.length]; final List<Statement> parmVars = new ArrayList<Statement>(); for (int i = 0; i < parms.length; i++) { finalParms[i] = Parameter.of(parms[i].getType().getErased(), parms[i].getName(), true); parmVars.add(Stmt.loadVariable(parms[i].getName())); } final Statement parameters = (intercepted) ? new StringStatement("getParameters()", MetaClassFactory.get(Object[].class)) : Stmt.newArray(Object.class).initialize(parmVars.toArray()); final BlockBuilder<?> methodBlock = classBuilder.publicMethod(method.getReturnType().getErased(), method.getName(), finalParms); if (intercepted) { methodBlock.append(generateInterceptorLogic(classBuilder, method, generateRequest(classBuilder, method, parameters, true), parmVars, interceptors)); } else { methodBlock.append(generateRequest(classBuilder, method, parameters, false)); } final Statement returnStmt = ProxyUtil.generateProxyMethodReturnStatement(method); if (returnStmt != null) { methodBlock.append(returnStmt); } methodBlock.finish(); }
private boolean isRawType(final MetaClass type) { // Guaranteed to be true for all raw types in all MetaClass impls return type == type.getErased(); }
private void linkInjectableReference(final InjectableReference injectableReference) { final Collection<InjectableReference> candidates = directInjectableReferencesByAssignableTypes .get(injectableReference.type.getErased()); logger.debug("Found {} candidate references.", candidates.size()); for (final InjectableReference candidate : candidates) { if (GraphUtil.candidateSatisfiesInjectable(injectableReference, candidate)) { logger.trace("Candidate has been linked: {}", candidate); injectableReference.linked.add(candidate); } } }
/** * Mark a class "literalizable". Meaning that all classes that are assignable to this type, are candidates for * reification to code snapshots for this context and all subcontexts. See {@link SnapshotMaker} for further details. * * @param clazz * the class, interface or superclass to be considered literalizable. */ public void addLiteralizableClass(final MetaClass clazz) { checkThread(); literalizableClasses.add(clazz.getErased()); }
/** * Mark a class "literalizable". Meaning that all classes that are assignable to this type, are candidates for * reification to code snapshots for this context and all subcontexts. See {@link SnapshotMaker} for further details. * * @param clazz * the class, interface or superclass to be considered literalizable. */ public void addLiteralizableClass(final MetaClass clazz) { checkThread(); literalizableClasses.add(clazz.getErased()); }
private void resolveTypeSpecialization(final InjectableImpl specialization, final Set<InjectableImpl> toBeRemoved) { final MetaClass specializedType = specialization.type.getSuperClass().getErased(); for (final InjectableReference injectable : directInjectableReferencesByAssignableTypes.get(specializedType)) { if (injectable.type.equals(specializedType)) { if (!injectable.linked.isEmpty()) { updateSpecializedReferenceLinks(specialization, toBeRemoved, injectable); break; } } } }
private void processAssignableTypes(final InjectableReference injectableReference) { for (final MetaClass assignable : injectableReference.type.getAllSuperTypesAndInterfaces()) { try { directInjectableReferencesByAssignableTypes.put(assignable.getErased(), injectableReference); } catch (final Throwable t) { throw new RuntimeException("Error occurred adding the assignable type " + assignable.getFullyQualifiedName(), t); } } }
protected SimpleMapping(final String key, final MetaClass targetType) { if (key == null) { throw new NullPointerException("key is null"); } this.type = targetType.asBoxed(); this.targetType = targetType.getErased().asBoxed(); this.key = key; }
protected SimpleMapping(final String key, final MetaClass targetType) { if (key == null) { throw new NullPointerException("key is null"); } this.type = targetType.asBoxed(); this.targetType = targetType.getErased().asBoxed(); this.key = key; }
private static boolean _hasInterface(final MetaClass[] from, final MetaClass to) { for (final MetaClass interfaceType : from) { if (to.getFullyQualifiedName().equals(interfaceType.getErased().getFullyQualifiedName())) return true; else if (_hasInterface(interfaceType.getInterfaces(), to)) return true; } return false; }
private MetaClass[] getErasedParamterTypes(final MetaMethod method) { final MetaClass[] paramTypes = new MetaClass[method.getParameters().length]; for (int i = 0; i < paramTypes.length; i++) { paramTypes[i] = method.getParameters()[i].getType().getErased(); } return paramTypes; }
private static boolean _hasInterface(final MetaClass[] from, final MetaClass to) { for (final MetaClass interfaceType : from) { if (to.getFullyQualifiedName().equals(interfaceType.getErased().getFullyQualifiedName())) return true; else if (_hasInterface(interfaceType.getInterfaces(), to)) return true; } return false; }
private MetaClass[] getErasedParamterTypes(final MetaMethod method) { final MetaClass[] paramTypes = new MetaClass[method.getParameters().length]; for (int i = 0; i < paramTypes.length; i++) { paramTypes[i] = method.getParameters()[i].getType().getErased(); } return paramTypes; }
private Parameter[] getParametersForDeclaration(final MetaMethod method) { final MetaParameter[] metaParams = method.getParameters(); final Parameter[] params = new Parameter[metaParams.length]; for (int i = 0; i < params.length; i++) { params[i] = Parameter.of(metaParams[i].getType().getErased(), metaParams[i].getName()); } return params; }
private boolean needsLazyInit(MetaClass type) { MetaClass compType = type.getOuterComponentType().getErased(); return (!compType.asUnboxed().isPrimitive() && !compType.equals(MetaClassFactory.get(String.class)) && !context .getDefinitionsFactory().hasBuiltInDefinition(compType)); }
private boolean needsLazyInit(MetaClass type) { MetaClass compType = type.getOuterComponentType().getErased(); return (!compType.asUnboxed().isPrimitive() && !compType.equals(MetaClassFactory.get(String.class)) && !context .getDefinitionsFactory().hasBuiltInDefinition(compType)); }
@Test public void testEraseNonGenericType() throws Exception { final MetaClass child = getMetaClass(Child.class); assertSame(child, child.getErased()); }
@Test public void testEraseParameterizedTopLevelType() throws Exception { final MetaClass parameterized = getMetaClass(ParameterizedClass.class); assertEquals("ParameterizedClass", parameterized.getName()); assertEquals("org.jboss.errai.codegen.test.model.ParameterizedClass", parameterized.getFullyQualifiedName()); assertNull(parameterized.getParameterizedType()); // I think this would be correct, but right now we get the raw type name //assertEquals("org.jboss.errai.codegen.test.model.ParameterizedClass<T>", parameterized.getFullyQualifiedNameWithTypeParms()); assertEquals("org.jboss.errai.codegen.test.model.ParameterizedClass", parameterized.getErased().getFullyQualifiedNameWithTypeParms()); }
@Test public void testFieldWithStringTypeParam() throws Exception { final MetaClass metaClass = getMetaClass(ClassWithGenericCollections.class); final MetaField field = metaClass.getDeclaredField("hasStringParam"); assertNotNull(field); assertEquals("Collection", field.getType().getName()); assertEquals("java.util.Collection", field.getType().getFullyQualifiedName()); assertEquals("<java.lang.String>", field.getType().getParameterizedType().toString()); assertEquals("java.util.Collection<java.lang.String>", field.getType().getFullyQualifiedNameWithTypeParms()); assertEquals("java.util.Collection", field.getType().getErased().getFullyQualifiedNameWithTypeParms()); assertEquals( Arrays.asList(getMetaClass(String.class)), Arrays.asList(field.getType().getParameterizedType().getTypeParameters())); }