/** * Will it comment later :) * * @throws NotFoundException */ public static JClassType getDeclaredFieldClassType(JClassType classType, String property) throws NotFoundException { JType fieldType = getDeclaredFieldType(classType, property); if (fieldType instanceof JClassType) { return ((JClassType) fieldType); } return null; }
public String create(TreeLogger logger, GeneratorContext context) throws UnableToCompleteException { this.logger = logger; this.context = context; return generateServiceProvider(classType); }
public RebindResult create(TreeLogger logger, GeneratorContext context) throws UnableToCompleteException { this.logger = logger; this.context = context; return generateServiceWrapper(typeName); }
String typeName) throws UnableToCompleteException { if (GeneratorChain.customGenerators == null || GeneratorChain.context != context) { fillUpGeneratorChainMap(logger, context); GeneratorChain.context = context; List<AbstractGenerator> replacers = GeneratorChain.getReplaceByChain(context, typeName); for (AbstractGenerator replacer : replacers) { if (replacer.isGenerate(logger, context, typeName, replacer .getConditions())) { actualTypeName = replacer.doGenerate(logger, context, actualTypeName); .getThirdPartyGenerators(); for (Entry<Generator, AbstractGenerator> entry : thirdPartyGens .entrySet()) { AbstractGenerator aGen = (AbstractGenerator) entry.getValue(); if (superClass != null && !("".equals(superClass))) { aGen.setSuperclassName(superClass); } else { aGen.setSuperclassName(actualTypeName); if (aGen.isGenerate(logger, context, actualTypeName, aGen.getConditions())) { superClass = gen.generate(logger, context, actualTypeName); List<AbstractGenerator> generators = GeneratorChain.getGeneratorChain( context, typeName); superClass = generateByCustomGenerators(logger, context, typeName, superClass, actualTypeName, generators);
GenPredicGroup myConds = new GenPredicGroup(); myConds.setOperator((op != null) ? op : GenPredicGroup.EOperator.ALL); Iterator<Condition> it = conds.iterator(); while (it.hasNext()) { if (myConds.getMyGroups() == null) { myConds.setMyGroups(new ArrayList<GenPredicGroup>()); myConds.getMyGroups().add( getGroupConditions(((CompoundCondition) cond) .getConditions(), actualOp)); } else { if (myConds.getGeneratorPredicts() == null) { myConds .setGeneratorPredicts(new ArrayList<GeneratorPredicate>()); myConds.getGeneratorPredicts().add(getGP(cond));
/** * gets GeneratorPredicate from condition * * @param cond * Condition * @return GeneratorPredicate */ private GeneratorPredicate getGP(Condition cond) { GeneratorPredicate gp = new GeneratorPredicate(); // ===================when assignable to if (cond instanceof ConditionWhenTypeAssignableTo) { gp.setEPredict(EPredicts.ASSIGNABLE); gp.setName(GeneratorPredicate.CLASS); gp.setValue(((ConditionWhenTypeAssignableTo) cond) .getAssignableToTypeName()); // ===================when type is } else if (cond instanceof ConditionWhenTypeIs) { gp.setEPredict(EPredicts.TYPEIS); gp.setName(GeneratorPredicate.CLASS); gp.setValue((String) getPrivateField(cond, "exactTypeName")); // ===================when property is } else if (cond instanceof ConditionWhenPropertyIs) { gp.setEPredict(EPredicts.PROPERTY); gp.setName((String) getPrivateField( ((ConditionWhenPropertyIs) cond), "propName")); gp.setValue((String) getPrivateField( ((ConditionWhenPropertyIs) cond), "value")); } return gp; }
private String generateByCustomGenerators(TreeLogger logger, GeneratorContext context, String typeName, String superClass, String actualTypeName, List<AbstractGenerator> awaitingGeneratos) throws UnableToCompleteException { // AbstractGenerator processedGenerator = null; for (AbstractGenerator generator : awaitingGeneratos) { if (superClass != null && !("".equals(superClass))) { generator.setSuperclassName(superClass); } else { generator.setSuperclassName(actualTypeName); } if (generator.isGenerate(logger, context, actualTypeName, generator .getConditions())) { superClass = generator.doGenerate(logger, context, actualTypeName); // processedGenerator = generator; // break; } } // if (processedGenerator != null) { // awaitingGeneratos.remove(processedGenerator); // superClass = generateByCustomGenerators(logger, context, typeName, superClass, actualTypeName, awaitingGeneratos); // } return superClass; }
private GenPredicGroup addPredicsToExisting(Rule rul, GenPredicGroup previousConds) { List<GenPredicGroup> list = new ArrayList<GenPredicGroup>(); GenPredicGroup gpg = getGroupConditions(rul .getRootCondition().getConditions(), null); list.add(gpg); list.add(previousConds); GenPredicGroup newGroup = new GenPredicGroup(); newGroup.setMyGroups(list); newGroup.setOperator(EOperator.ANY); return newGroup; }
public static JMethod getGetter(JClassType beanType, String fieldName) throws NotFoundException { JMethod method = null; try { try { method = beanType.getMethod("get" + getterSetterDeterminator(fieldName), new JType[0]); } catch (NotFoundException e) { method = beanType.getMethod("is" + getterSetterDeterminator(fieldName), new JType[0]); } } catch (NotFoundException e) { JClassType superClass = beanType.getSuperclass(); if (superClass != null) { try { method = getGetter(superClass, fieldName); } catch (NotFoundException e1) { JClassType[] interfaces = beanType.getImplementedInterfaces(); if (interfaces != null && interfaces.length > 0) { for (JClassType intrface : interfaces) { method = getGetter(intrface, fieldName); if (method != null) { break; } } } } } } return method; }
/** * Searches class and all its superclasses for a field. * * @param classType * @param fieldName * @return field or method containing representing the field * @throws NotFoundException */ public static Object getDeclaredDirectField(JClassType classType, String fieldName) throws NotFoundException { JField field = classType.getField(fieldName); JClassType superClass = classType.getSuperclass(); JMethod getter = null; if (field == null) { try { getter = getGetter(classType, fieldName); } catch (Exception e) {} } if (field == null && getter == null && superClass != null) { return getDeclaredDirectField(superClass, fieldName); } if (field != null) { return field; } else if (getter != null) { return getter; } throw new NotFoundException( "Unable to identify a property descriptor (field or method) for classType = " + classType + ", field = " + fieldName); }
RemoteServiceProviderCreator providerCreator = new RemoteServiceProviderCreator(remoteService); providerCreator.create(proxyLogger, ctx); RemoteServiceWrapperCreator wrapperCreator = new RemoteServiceWrapperCreator(remoteService); return wrapperCreator.create(proxyLogger, ctx);
public static JMethod getSetter(JClassType beanType, String fieldName, JType fieldType) throws NotFoundException { JMethod method = null; try { method = beanType.getMethod("set" + getterSetterDeterminator(fieldName), new JType[] { fieldType }); if (method.isPrivate()) method = null; } catch (NotFoundException e) { JClassType superClass = beanType.getSuperclass(); if (superClass != null) { try { method = getSetter(superClass, fieldName, fieldType); } catch (NotFoundException e1) { JClassType[] interfaces = beanType.getImplementedInterfaces(); if (interfaces != null && interfaces.length > 0) { for (JClassType intrface : interfaces) { method = getSetter(intrface, fieldName, fieldType); if (method != null) { break; } } } } } } return method; }
/** * Tries to find parametrized type in interface of a class. * * @param classType * A class having parametrized interface. * @param parametrizedType * Interface where parametrized type is present. * @param position * Position in a list of parametrized types in interface. * @return Generics type in interface implemented by a class type. * @throws NotFoundException */ public static JClassType getGenericsFromInterfaceType(JClassType classType, JClassType parametrizedType, int position) throws NotFoundException { JClassType type = getGenericsFromInterfaceHierarchy(classType, parametrizedType, position); if (type != null) return type; if (classType.getSuperclass() != null) { return getGenericsFromInterfaceType(classType.getSuperclass(), parametrizedType, position); } throw new NotFoundException("Unable to find generics in type " + classType + ", where parametrized type is " + parametrizedType + " on position " + position); }
return getGenericsFromSuperclassType(superclassType/*
protected void generateSetBeanAttributes(SourceWriter source, JMethod[] methods, String simpleName) { // create the set attribute method source.println("public void setBeanAttribute(String attr, Object value) {"); source.indent(); for (int i = 0; i < methods.length; i++) { if (isExcludedMethod(methods[i])) { // there was a method but was excluded continue; } JMethod methode = methods[i]; if (isSetter(methode)) { JType paramType = methode.getParameters()[0].getType(); source.println("if (attr.equals(\"" + RebindUtils.toFieldName(methode.getName()) + "\")) { "); source.indent(); source.println("this." + methode.getName() + "(" + castFromString(paramType, "value") + ");"); source.outdent(); source.print("} else "); } } source.println("if (attr.equals(\"" + BEAN_WRAPPER_CONTENT + "\")) {"); source.indent(); source.println("this." + BEAN_WRAPPER_CONTENT + " = (" + simpleName + ") value;"); source.outdent(); source.println("} else "); source.print("{"); source.println("}"); source.outdent(); source.println("}"); }
private JClassType resolveClassType(JClassType classType, String property) throws IntrospectionException { JClassType listBeanClassType; try { listBeanClassType = RebindUtils.getDeclaredFieldClassType(classType, property); } catch (NotFoundException e) { throw new RuntimeException("Cannot find class type for property " + property + " in bean " + classType.getQualifiedSourceName(), e); } if (listBeanClassType == null) { throw new IntrospectionException("Cannot find class type for property " + property + " in bean " + classType.getQualifiedSourceName()); } return listBeanClassType; }
/** * Will it comment it aprox. 2 minutes before getDeclaredFieldClassType * method * * @throws NotFoundException */ public static JType getDeclaredFieldType(JClassType classType, String property) throws NotFoundException { Object propertyRepresentation = RebindUtils.getDeclaredField(classType, property); if (propertyRepresentation == null) { return null; } if (propertyRepresentation instanceof JField) { return ((JField) propertyRepresentation).getType(); } else if (propertyRepresentation instanceof JMethod) { return ((JMethod) propertyRepresentation).getReturnType(); } else { throw new NotFoundException("Unsupported property type = " + propertyRepresentation.getClass().getName() + ", classType = " + classType + ", property = " + property); } }
/** * Tries to find parametrized type in interface hierarchy of a class. * * @param classType * A class having parametrized interface. * @param parametrizedType * Interface where parametrized type is present. * @param position * Position in a list of parametrized types in interface. * @return Generics type in interface implemented by a class type or null if * not found */ private static JClassType getGenericsFromInterfaceHierarchy(JClassType classType, JClassType parametrizedType, int position) { for (JClassType type : classType.getImplementedInterfaces()) { if (type instanceof JParameterizedType) { JParameterizedType paramType = (JParameterizedType) type; if (paramType.getErasedType().equals(parametrizedType.getErasedType())) { return paramType.getTypeArgs()[position]; } } // seach parent interfaces JClassType result = getGenericsFromInterfaceHierarchy(type, parametrizedType, position); if (result != null) return result; } return null; }
String simpleClassName = classType.getSimpleSourceName(); String className = simpleClassName + PROVIDER_SUFFIX; SourceWriter sourceWriter = getServiceProviderSourceWriter(packageName, className, classType);
JType returnType = methods[i].getReturnType(); if (isGetter(methods[i])) { source.println("if (attr.equals(\"" + RebindUtils.toFieldName(methodName) + "\")) {"); source.indent(); source.println("return " + castToString(returnType, "this." + methodName + "()") + ";");