private static boolean isInstantiableWithNewOperator (JClassType t) { if (!t.isDefaultInstantiable() || t instanceof JArrayType || t instanceof JEnumType) return false; try { JConstructor constructor = t.getConstructor(new JType[0]); return constructor != null && constructor.isPublic(); } catch (NotFoundException e) { return false; } }
public static int getModifiers(JConstructor ctor) { int mod; if (ctor.isPublic()) mod = Modifier.PUBLIC; else if (ctor.isPrivate()) mod = Modifier.PRIVATE; else if (ctor.isProtected()) mod = Modifier.PROTECTED; else mod = 0;//Package Protected if (ctor.isVarArgs()) mod |= 0x80; return mod; }
public String getOrMakeConstructorFactory(TreeLogger logger, ReflectionGeneratorContext ctx, JConstructor ctor, com.google.gwt.core.ext.typeinfo.JType classType, ReflectionManifest manifest, boolean declaredOnly) throws UnableToCompleteException { // get cached manifest for this type String clsName = classType.getQualifiedSourceName(); TypeOracle oracle = ctx.getGeneratorContext().getTypeOracle(); JClassType cls = oracle.findType(clsName); if (cls == null) { logger.log(Type.ERROR, "Unable to find enclosing class "+clsName); throw new UnableToCompleteException(); } String constructorFactoryName = getConstructorFactoryName(cls, ctor.getParameters()); JClassType factory; String pkgName = ctor.getEnclosingType().getPackage().getName(); factory = oracle.findType(pkgName, constructorFactoryName); if (factory == null) { return generateConstructorFactory(logger, ctx, ctor, constructorFactoryName, manifest); } else return (pkgName.length()==0?"":pkgName+".")+ constructorFactoryName; }
@Override public MetaParameter[] getParameters() { return Arrays.stream(constructor.getParameters()) .map(p -> new GWTParameter(oracle, p, this)) .toArray(s -> new MetaParameter[s]); }
if ( constructor.isPublic() && constructor.getParameters().length == nbParam ) { MapperType[] parameters = getParameters( mappedType, constructor, isSerializers ); if ( null == parameters ) {
throws UnableToCompleteException { final JClassType type = ctor.getEnclosingType(); final String pkg = type.getPackage().getName(); factory = factory.replace('.', '_'); appendClassArray(instantiator, ctor.getParameters(), ctx); instantiator.print(", "); appendClassArray(instantiator, ctor.getThrows(), ctx); createInvokerMethod(cb, type, type, "new", ctor.getParameters(), true, ctor.isPublic());
if (ctor.getEnclosingType().getQualifiedSourceName().equals(typeName)) { GwtRetention retention = ctor.getAnnotation(GwtRetention.class); if (retention == null) retention = strategy.fieldRetention(); declaredConstructors.put(ctor.getJsniSignature(), new ReflectionUnit<JConstructor>(ctor, retention));
if ( constructor.getParameters().length == 0 ) { creatorDefaultConstructor = constructor; continue; JConstructor mixinConstructor = mixinClass.get().findConstructor( constructor.getParameterTypes() ); if ( null != mixinConstructor ) { constructors.add( mixinConstructor ); .get( 0 ), JsonProperty.class ); if ( (isAnnotationPresent( JsonCreator.class, constructors ) && ((isAllParametersAnnotatedWithJsonProperty) || (constructor .getParameters().length == 1))) || isAllParametersAnnotatedWithJsonProperty ) { creatorConstructor = constructor; creators = constructors;
private static void extractConstructors(TreeLogger logger, KeepConstructor keepCtor, JClassType injectionType, ReflectionManifest manifest) { boolean keepCtors = keepCtor != null; boolean keepAnnos = manifest.anno != null; Set<String> seen = new HashSet<String>(); Set<? extends JClassType> allTypes = injectionType.getFlattenedSupertypeHierarchy(); for(JClassType nextClass : allTypes) { for (JConstructor ctor : nextClass.getConstructors()) { if (keepCtors || ctor.getAnnotation(KeepConstructor.class) != null){ // do not include overridden constructors if (seen.add(ctor.getJsniSignature())) { final Annotation[] annos; if (keepAnnos || ctor.getAnnotation(KeepAnnotation.class) != null) { annos = ctor.getAnnotations(); } else { // only keep annotations annotated with KeepAnnotation. final List<Annotation> keepers = new ArrayList<Annotation>(); for (Annotation anno : ctor.getAnnotations()) { if (anno.annotationType().getAnnotation(KeepAnnotation.class) != null) keepers.add(anno); } annos = keepers.toArray(new Annotation[keepers.size()]); } manifest.constructors.put(ctor, annos); } } } nextClass = nextClass.getSuperclass(); } }
/** * Check for a constructor which is compatible with the supplied argument * types. * * @param type * @param argTypes * @return true if a constructor compatible with the supplied arguments exists */ public static boolean hasCompatibleConstructor(JClassType type, JType... argTypes) { // Note that this does not return the constructor, since that is a more // complicated decision about finding the best matching arguments where // more than one are compatible. for (JConstructor ctor : type.getConstructors()) { if (typesAreCompatible(ctor.getParameterTypes(), argTypes, ctor.isVarArgs())) { return true; } } return false; }
public GwtRetention getRetention(JConstructor ctor) { GwtRetention retention = ctor.getAnnotation(GwtRetention.class); if (retention == null) { retention = strategy.constructorRetention(); } return retention; }
public GWTConstructor(final TypeOracle oracle, final JConstructor c) { this.constructor = c; this.annotations = c.getAnnotations(); this.declaringClass = GWTClass.newInstance(oracle, c.getEnclosingType()); this.oracle = oracle; }
@Override public boolean isVarArgs() { return constructor.isVarArgs(); }
@Override public boolean isPrivate() { return constructor.isPrivate(); }
public static JConstructor findConstructor(final TreeLogger logger, final JClassType type, final List<String> params, final boolean declared) { loop: for (final JConstructor ctor : type.getConstructors()) { final JType[] types = ctor.getParameterTypes(); if (types.length == params.size()) { for (int i = 0, m = types.length; i < m; i++ ) { String typeName = types[i].getErasedType().getQualifiedBinaryName(); while (typeName.startsWith("[")) { typeName = typeName.substring(1)+"[]"; } if (!params.get(i).equals(typeName)) { logger.log(Type.DEBUG, "constructor with different signature; " +"("+params+") mismatches at index "+i+" with value "+typeName); continue loop; } } return ctor; } } return declared || type.getSuperclass() == null ? null: findConstructor(logger, type.getSuperclass(), params, declared); }
@Override public boolean isProtected() { return constructor.isProtected(); }
public JMethodCall getConstructorProvider(final TreeLogger logger, final ReflectionGeneratorContext ctx, final JConstructor ctor, final boolean declared) throws UnableToCompleteException { final JClassLiteral classLit = ctx.getClazz(); final UnifyAstView ast = ctx.getAst(); final String clsName = classLit.getRefType().getName(); final ReflectionManifest manifest = ReflectionManifest.getReflectionManifest(logger, clsName, ast.getGeneratorContext()); final String factoryCls = getOrMakeConstructorFactory(logger, ctx, ctor, ctor.getEnclosingType(), manifest, declared); ctx.finish(logger); final JDeclaredType factory = ast.searchForTypeBySource(factoryCls); // pull out the static accessor method for (final JMethod factoryMethod : factory.getMethods()) { if (factoryMethod.isStatic() && factoryMethod.getName().equals("instantiate")) { return new JMethodCall(factoryMethod.getSourceInfo(), null, factoryMethod); } } logger.log(Type.ERROR, "Unable to find static initializer for Constructor subclass "+factoryCls); throw new UnableToCompleteException(); }
public static int getModifiers(final JConstructor ctor) { int mod; if (ctor.isPublic()) { mod = Modifier.PUBLIC; } else if (ctor.isPrivate()) { mod = Modifier.PRIVATE; } else if (ctor.isProtected()) { mod = Modifier.PROTECTED; } else { mod = 0;//Package Protected } if (ctor.isVarArgs()) { mod |= 0x80; } return mod; }
public String getOrMakeConstructorFactory(final TreeLogger logger, final ReflectionGeneratorContext ctx, final JConstructor ctor, final com.google.gwt.core.ext.typeinfo.JType classType, final ReflectionManifest manifest, final boolean declaredOnly) throws UnableToCompleteException { // get cached manifest for this type final String clsName = classType.getQualifiedSourceName(); final TypeOracle oracle = ctx.getGeneratorContext().getTypeOracle(); final JClassType cls = oracle.findType(clsName); if (cls == null) { logger.log(Type.ERROR, "Unable to find enclosing class "+clsName); throw new UnableToCompleteException(); } final String constructorFactoryName = ConstructorGenerator.getConstructorFactoryName(cls, ctor.getParameters()); JClassType factory; final String pkgName = ctor.getEnclosingType().getPackage().getName(); factory = oracle.findType(pkgName, constructorFactoryName); if (factory == null) { return generateConstructorFactory(logger, ctx, ctor, constructorFactoryName, manifest); } else { return (pkgName.length()==0?"":pkgName+".")+ constructorFactoryName; } }