@Test public void testGetter(@TuneProvider Tune tune) { FieldSpec.Builder builder = FieldSpec.builder(TypeName.INT, "test"); FieldSpec fieldSpec = builder.build(); FieldModel model = mock(FieldModel.class); when(model.getFieldType()).thenReturn(FieldType.INTEGER); TypeSpec.Builder classBuilder = TypeSpec.classBuilder("Klazz"); new GetterHandler(tune, null, new DefaultRuleSet(tune, null)).process(classBuilder, fieldSpec, model); TypeSpec spec = classBuilder.build(); assertEquals(1, spec.methodSpecs.size()); MethodSpec methodSpec = spec.methodSpecs.get(0); assertTrue(methodSpec.hasModifier(Modifier.PUBLIC)); assertEquals(TypeName.INT, methodSpec.returnType); assertEquals("getTest", methodSpec.name); }
public void process(TypeSpec.Builder typeBuilder, FieldSpec fieldSpec, FieldModel fieldModel) { String methodName = getGetterSetterName(fieldSpec.name, false, fieldModel.getFieldType() == FieldType.BOOLEAN, fieldModel.isPrimitive()); MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) .addModifiers(Modifier.PUBLIC) .returns(fieldSpec.type) .addStatement("return $L", fieldSpec.name); ruleSet.getGetterRequiredRule().process(builder, fieldModel, null); ruleSet.getGetterNotRequiredRule().process(builder, fieldModel, null); typeBuilder.addMethod(builder.build()); }
GetterHandler { public void process(TypeSpec.Builder typeBuilder, FieldSpec fieldSpec, FieldModel fieldModel) { String methodName = getGetterSetterName(fieldSpec.name, false, fieldModel.getFieldType() == FieldType.BOOLEAN, fieldModel.isPrimitive()); MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) .addModifiers(Modifier.PUBLIC) .returns(fieldSpec.type) .addStatement("return $L", fieldSpec.name); ruleSet.getGetterRequiredRule().process(builder, fieldModel, null); ruleSet.getGetterNotRequiredRule().process(builder, fieldModel, null); typeBuilder.addMethod(builder.build()); } }
GetterHandler { public void process(TypeSpec.Builder typeBuilder, FieldSpec fieldSpec, FieldModel fieldModel) { String methodName = getGetterSetterName(fieldSpec.name, false, fieldModel.getFieldType() == FieldType.BOOLEAN, fieldModel.isPrimitive()); MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) .addModifiers(Modifier.PUBLIC) .returns(fieldSpec.type) .addStatement("return $L", fieldSpec.name); ruleSet.getGetterRequiredRule().process(builder, fieldModel, null); ruleSet.getGetterNotRequiredRule().process(builder, fieldModel, null); typeBuilder.addMethod(builder.build()); } GetterHandler(Tune tune, MetaInfo metaInfo, RuleSet ruleSet); }
GetterHandler { public void process(TypeSpec.Builder typeBuilder, FieldSpec fieldSpec, FieldModel fieldModel) { String methodName = getGetterSetterName(fieldSpec.name, false, fieldModel.getFieldType() == FieldType.BOOLEAN, fieldModel.isPrimitive()); MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) .addModifiers(Modifier.PUBLIC) .returns(fieldSpec.type) .addStatement("return $L", fieldSpec.name); ruleSet.getGetterRequiredRule().process(builder, fieldModel, null); ruleSet.getGetterNotRequiredRule().process(builder, fieldModel, null); typeBuilder.addMethod(builder.build()); } GetterHandler(Tune tune, MetaInfo metaInfo, RuleSet ruleSet); void process(TypeSpec.Builder typeBuilder, FieldSpec fieldSpec, FieldModel fieldModel); }
GetterHandler { public void process(TypeSpec.Builder typeBuilder, FieldSpec fieldSpec, FieldModel fieldModel) { String methodName = getGetterSetterName(fieldSpec.name, false, fieldModel.getFieldType() == FieldType.BOOLEAN, fieldModel.isPrimitive()); MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) .addModifiers(Modifier.PUBLIC) .returns(fieldSpec.type) .addStatement("return $L", fieldSpec.name); ruleSet.getGetterRequiredRule().process(builder, fieldModel, null); ruleSet.getGetterNotRequiredRule().process(builder, fieldModel, null); typeBuilder.addMethod(builder.build()); } GetterHandler(Tune tune, MetaInfo metaInfo, RuleSet ruleSet); void process(TypeSpec.Builder typeBuilder, FieldSpec fieldSpec, FieldModel fieldModel);  }