public static boolean equals(final MetaConstructor a, final MetaConstructor b) { if (a.getParameters().length != b.getParameters().length) { return false; } for (int i = 0; i < a.getParameters().length; i++) { if (!equals(a.getParameters()[i], b.getParameters()[i])) { return false; } } return a.getDeclaringClass().equals(b.getDeclaringClass()); }
@Override public boolean isDefaultInstantiable() { if (isInterface() || isAbstract()) { return false; } final MetaConstructor c = getConstructor(new MetaClass[0]); return c != null && c.isPublic(); }
private List<MetaConstructor> getInjectableConstructors(final MetaClass type) { final Collection<Class<? extends Annotation>> injectAnnotations = injectionContext.getAnnotationsForElementType(WiringElementType.InjectionPoint); final List<MetaConstructor> cons = new ArrayList<>(); for (final MetaConstructor con : type.getConstructors()) { for (final Class<? extends Annotation> anno : injectAnnotations) { if (con.isAnnotationPresent(anno)) { cons.add(con); } } } return cons; }
private MetaConstructor getAccessibleNoArgConstructor(final MetaClass type) { final MetaConstructor noArgConstr = type.getDeclaredConstructor(new MetaClass[0]); if (noArgConstr != null && (noArgConstr.isPublic() || noArgConstr.isProtected())) { return noArgConstr; } else { return null; } }
if (classTarget && (meth.isStatic())) continue; final boolean isVarArgs = meth.isVarArgs(); if ((parmTypes = meth.getParameters()).length != arguments.length && !isVarArgs) { continue;
if (c.getParameters().length != 0) { for (int i = 0; i < c.getParameters().length; i++) { final Annotation[] annotations = c.getParameters()[i].getAnnotations(); if (annotations.length == 0) { hasMapsTos.add(false); final MapsTo mapsTo = (MapsTo) a; final String key = mapsTo.value(); simpleConstructorMapping.mapParmToIndex(key, i, c.getParameters()[i].getType()); throw new InvalidMappingException("Not all parameters of constructor " + c.asConstructor() + " have a @" + MapsTo.class.getSimpleName() + " annotation"); if (defaultConstructor == null || !defaultConstructor.isPublic()) { throw new InvalidMappingException("there is no custom mapping or default no-arg constructor to map: " + toMap.getFullyQualifiedName());
protected static MetaConstructor _getConstructor(final MetaConstructor[] constructors, final MetaClass... parmTypes) { MetaConstructor candidate = null; int bestScore = 0; int score; for (final MetaConstructor constructor : constructors) { score = 0; if (constructor.getParameters().length == parmTypes.length) { if (parmTypes.length == 0) { score = 1; } else { for (int i = 0; i < parmTypes.length; i++) { if (constructor.getParameters()[i].getType().isAssignableFrom(parmTypes[i])) { score++; if (constructor.getParameters()[i].getType().equals(parmTypes[i])) { score++; } } } } } if (score > bestScore) { bestScore = score; candidate = constructor; } } return candidate; }
@Override public void makeConstructorAccessible(final ClassStructureBuilder<?> classBuilder, final MetaConstructor constructor) { final DefParameters methodDefParms = DefParameters.from(constructor); Annotation[] annotations = NO_ANNOTATIONS; for (MetaParameter p : constructor.getParameters()) { if (p.getType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } } classBuilder.publicMethod(constructor.getReturnType(), PrivateAccessUtil.getPrivateMethodName(constructor)) .annotatedWith(annotations) .parameters(methodDefParms) .modifiers(Modifier.Static, Modifier.JSNI) .body() ._(StringStatement.of(JSNIUtil.methodAccess(constructor))) .finish(); }
if (ctor.isAnnotationPresent(annoType)) { annotated.add(ctor); for (final MetaParameter param : ctor.getParameters()) { if (param.isAnnotationPresent(annoType)) { annotated.add(param);
@Override public void makeConstructorAccessible(final ClassStructureBuilder<?> classBuilder, final MetaConstructor constructor) { final DefParameters methodDefParms = DefParameters.from(constructor); final String cachedMethod = initCachedMethod(classBuilder, constructor); final Object[] args = new Object[methodDefParms.getParameters().size()]; int i = 0; for (final Parameter p : methodDefParms.getParameters()) { args[i++] = Refs.get(p.getName()); } final BlockBuilder<? extends ClassStructureBuilder> body = classBuilder.publicMethod(constructor.getReturnType(), PrivateAccessUtil.getPrivateMethodName(constructor)) .parameters(methodDefParms) .modifiers(Modifier.Static) .body(); final Statement tryBuilder = Stmt.try_() .append( Stmt.nestedCall( Stmt.castTo(constructor.getReturnType(), Stmt.loadVariable(cachedMethod).invoke("newInstance", (Object) args))).returnValue()) .finish() .catch_(Throwable.class, "e") .append(Stmt.loadVariable("e").invoke("printStackTrace")) .append(Stmt.throw_(RuntimeException.class, Refs.get("e"))) .finish(); body.append(tryBuilder).finish(); }
final Constructor constructor = ((ConstructorMapping) cMapping).getMember().asConstructor(); constructor.setAccessible(true); newInstance = constructor.newInstance(parms);
if (c.getParameters().length != 0) { for (int i = 0; i < c.getParameters().length; i++) { final Annotation[] annotations = c.getParameters()[i].getAnnotations(); if (annotations.length == 0) { hasMapsTos.add(false); final MapsTo mapsTo = (MapsTo) a; final String key = mapsTo.value(); simpleConstructorMapping.mapParmToIndex(key, i, c.getParameters()[i].getType()); throw new InvalidMappingException("Not all parameters of constructor " + c.asConstructor() + " have a @" + MapsTo.class.getSimpleName() + " annotation"); if (defaultConstructor == null || !defaultConstructor.isPublic()) { throw new InvalidMappingException("there is no custom mapping or default no-arg constructor to map: " + toMap.getFullyQualifiedName());
protected static MetaConstructor _getConstructor(final MetaConstructor[] constructors, final MetaClass... parmTypes) { MetaConstructor candidate = null; int bestScore = 0; int score; for (final MetaConstructor constructor : constructors) { score = 0; if (constructor.getParameters().length == parmTypes.length) { if (parmTypes.length == 0) { score = 1; } else { for (int i = 0; i < parmTypes.length; i++) { if (constructor.getParameters()[i].getType().isAssignableFrom(parmTypes[i])) { score++; if (constructor.getParameters()[i].getType().equals(parmTypes[i])) { score++; } } } } } if (score > bestScore) { bestScore = score; candidate = constructor; } } return candidate; }
@Override public void makeConstructorAccessible(final ClassStructureBuilder<?> classBuilder, final MetaConstructor constructor) { final DefParameters methodDefParms = DefParameters.from(constructor); Annotation[] annotations = NO_ANNOTATIONS; for (MetaParameter p : constructor.getParameters()) { if (p.getType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } } classBuilder.publicMethod(constructor.getReturnType(), PrivateAccessUtil.getPrivateMethodName(constructor)) .annotatedWith(annotations) .parameters(methodDefParms) .modifiers(Modifier.Static, Modifier.JSNI) .body() ._(StringStatement.of(JSNIUtil.methodAccess(constructor))) .finish(); }
if (ctor.isAnnotationPresent(annoType)) { annotated.add(ctor); for (final MetaParameter param : ctor.getParameters()) { if (param.isAnnotationPresent(annoType)) { annotated.add(param);
if (classTarget && (meth.isStatic())) continue; final boolean isVarArgs = meth.isVarArgs(); if ((parmTypes = meth.getParameters()).length != arguments.length && !isVarArgs) { continue;
if (injectableConstructors.size() == 1) { final MetaConstructor injectConstructor = injectableConstructors.get(0); final boolean instantiable = injectConstructor.isPublic() || !isJavaScriptObject(type); if (!instantiable) { problems.add(String.format("Cannot access constructor for %s.", type.getFullyQualifiedName())); } else if (noArgConstructor == null || !(noArgConstructor.isPublic() || noArgConstructor.isProtected())) { log.debug("The class {} must be proxiable but does not have an accessible no-argument constructor", type.getFullyQualifiedName()); final boolean injectConstructorProxiable = injectConstructor.isPublic() || injectConstructor.isProtected(); if (!injectConstructorProxiable) { problems.add(String.format( final boolean instantiable = noArgConstructor != null && (noArgConstructor.isPublic() || !isJavaScriptObject(type)); final boolean proxiable = noArgConstructor != null && (noArgConstructor.isPublic() || noArgConstructor.isProtected()); final boolean passesProxiability = scopeDoesNotRequireProxy(type) || proxiable;
@Override public void makeConstructorAccessible(final ClassStructureBuilder<?> classBuilder, final MetaConstructor constructor) { final DefParameters methodDefParms = DefParameters.from(constructor); final String cachedMethod = initCachedMethod(classBuilder, constructor); final Object[] args = new Object[methodDefParms.getParameters().size()]; int i = 0; for (final Parameter p : methodDefParms.getParameters()) { args[i++] = Refs.get(p.getName()); } final BlockBuilder<? extends ClassStructureBuilder> body = classBuilder.publicMethod(constructor.getReturnType(), PrivateAccessUtil.getPrivateMethodName(constructor)) .parameters(methodDefParms) .modifiers(Modifier.Static) .body(); final Statement tryBuilder = Stmt.try_() .append( Stmt.nestedCall( Stmt.castTo(constructor.getReturnType(), Stmt.loadVariable(cachedMethod).invoke("newInstance", (Object) args))).returnValue()) .finish() .catch_(Throwable.class, "e") .append(Stmt.loadVariable("e").invoke("printStackTrace")) .append(Stmt.throw_(RuntimeException.class, Refs.get("e"))) .finish(); body.append(tryBuilder).finish(); }
final Constructor constructor = ((ConstructorMapping) cMapping).getMember().asConstructor(); constructor.setAccessible(true); newInstance = constructor.newInstance(parms);
public static boolean equals(final MetaConstructor a, final MetaConstructor b) { if (a.getParameters().length != b.getParameters().length) { return false; } for (int i = 0; i < a.getParameters().length; i++) { if (!equals(a.getParameters()[i], b.getParameters()[i])) { return false; } } return a.getDeclaringClass().equals(b.getDeclaringClass()); }