protected StatementTree addReturnStatement(WorkingCopy wc, MethodTree methodTree, ExpressionTree exprTree) { ReturnTree returnTree = wc.getTreeMaker().Return(exprTree); addStatement(wc, methodTree.getBody(), returnTree); return returnTree; }
/** * Creates a getter method for a field. * * @param clazz the class to create the getter within * @param field field to create getter for * @return the getter method * @since 0.20 */ public MethodTree createGetter(TypeElement clazz, VariableElement field) { assert clazz != null && field != null; TreeMaker make = copy.getTreeMaker(); CodeStyle cs = DiffContext.getCodeStyle(copy); Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC); boolean isStatic = field.getModifiers().contains(Modifier.STATIC); if (isStatic) { mods.add(Modifier.STATIC); } TypeMirror type = copy.getTypes().asMemberOf((DeclaredType)clazz.asType(), field); boolean isBoolean = type.getKind() == TypeKind.BOOLEAN; String getterName = CodeStyleUtils.computeGetterName(field.getSimpleName(), isBoolean, isStatic, cs); BlockTree body = make.Block(Collections.singletonList(make.Return(make.Identifier(field.getSimpleName()))), false); return make.Method(make.Modifiers(mods), getterName, make.Type(type), Collections.<TypeParameterTree>emptyList(), Collections.<VariableTree>emptyList(), Collections.<ExpressionTree>emptyList(), body, null); }
/** * Creates a getter method for a field. * * @param field field to create getter for * @return the getter method * @since 0.20 */ public MethodTree createGetter(VariableTree field) { assert field != null; TreeMaker make = copy.getTreeMaker(); CodeStyle cs = DiffContext.getCodeStyle(copy); Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC); boolean isStatic = field.getModifiers().getFlags().contains(Modifier.STATIC); if (isStatic) { mods.add(Modifier.STATIC); } Tree type = field.getType(); boolean isBoolean = type.getKind() == Tree.Kind.PRIMITIVE_TYPE && ((PrimitiveTypeTree) type).getPrimitiveTypeKind() == TypeKind.BOOLEAN; String getterName = CodeStyleUtils.computeGetterName(field.getName(), isBoolean, isStatic, cs); BlockTree body = make.Block(Collections.singletonList(make.Return(make.Identifier(field.getName()))), false); return make.Method(make.Modifiers(mods), getterName, type, Collections.<TypeParameterTree>emptyList(), Collections.<VariableTree>emptyList(), Collections.<ExpressionTree>emptyList(), body, null); }
ReturnTree returnExp = make.Return(make.Identifier(masterFieldName)); MethodTree getMethod = make.Method( make.Modifiers(Collections.singleton(Modifier.PUBLIC), Collections.EMPTY_LIST),
ReturnTree returnExp = make.Return(make.Identifier(detailFieldName)); MethodTree getMethod = make.Method( make.Modifiers(Collections.singleton(Modifier.PUBLIC), Collections.EMPTY_LIST),