private static String addParamPrefixSuffix(CharSequence name, CodeStyle cs) { return CodeStyleUtils.addPrefixSuffix(name, cs.getParameterNamePrefix(), cs.getParameterNameSuffix()); }
/** * Check whether given type has a getter method for the given field. * @param type to inspect * @param field to search getter for * @param codeStyle * @return true if getter method exists * * @since 0.136 */ public boolean hasGetter(TypeElement type, VariableElement field, CodeStyle codeStyle) { boolean isBoolean = field.asType().getKind() == TypeKind.BOOLEAN; boolean isStatic = field.getModifiers().contains(Modifier.STATIC); String name = CodeStyleUtils.computeGetterName(field.getSimpleName(), isBoolean, isStatic, codeStyle); return delegate.alreadyDefinedIn(name, field.asType(), com.sun.tools.javac.util.List.<TypeMirror>nil(), type); }
/** * Computes the method name that should be used to write the property value. * * @param fieldName the name of the property * @param isStatic true if the property is static * @param cs the CodeSyle to use * @return the setter name */ @NonNull public static String computeSetterName(CharSequence fieldName, boolean isStatic, CodeStyle cs) { StringBuilder name = new StringBuilder(getCapitalizedName(removeFieldPrefixSuffix(fieldName, isStatic, cs))); name.insert(0, "set"); //NOI18N return name.toString(); }
if (!name.contentEquals(ERROR)) { boolean isStatic = variableElement.getModifiers().contains(Modifier.STATIC); String setterName = CodeStyleUtils.computeSetterName(name, isStatic, codeStyle); String getterName = CodeStyleUtils.computeGetterName(name, variableElement.asType().getKind() == TypeKind.BOOLEAN, isStatic, codeStyle); if ((prefix == null || startsWith(env, getterName)) && !eu.hasGetter(te, variableElement, codeStyle)) { results.add(itemFactory.createGetterSetterMethodItem(env.getController(), variableElement, asMemberOf(variableElement, clsType, types), anchorOffset, getterName, false));
/** * Check whether given type has a setter method for the given field. * @param type to inspect * @param field to search setter for * @param codeStyle * @return true if setter method exists * * @since 0.136 */ public boolean hasSetter(TypeElement type, VariableElement field, CodeStyle codeStyle) { boolean isStatic = field.getModifiers().contains(Modifier.STATIC); String name = CodeStyleUtils.computeSetterName(field.getSimpleName(), isStatic, codeStyle); return delegate.alreadyDefinedIn(name, info.getTypes().getNoType(TypeKind.VOID), com.sun.tools.javac.util.List.<TypeMirror>of(field.asType()), type); }
private static String removeParamPrefixSuffix(VariableElement var, CodeStyle cs) { return CodeStyleUtils.removePrefixSuffix(var.getSimpleName(), cs.getParameterNamePrefix(), cs.getParameterNameSuffix()); }
sb.append(capitalize ? getCapitalizedName(name) : name);
return getDecapitalizedName(result); } else { return result;
/** * Creates a setter method for a field. * * @param clazz the class to create the setter within * @param field field to create setter for * @return the setter method * @since 0.20 */ public MethodTree createSetter(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); } CharSequence name = field.getSimpleName(); assert name.length() > 0; TypeMirror type = copy.getTypes().asMemberOf((DeclaredType)clazz.asType(), field); String setterName = CodeStyleUtils.computeSetterName(field.getSimpleName(), isStatic, cs); String paramName = addParamPrefixSuffix(removeFieldPrefixSuffix(field, cs), cs); List<VariableTree> params = Collections.singletonList(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), paramName, make.Type(type), null)); BlockTree body = make.Block(Collections.singletonList(make.ExpressionStatement(make.Assignment(make.MemberSelect(isStatic? make.Identifier(field.getEnclosingElement().getSimpleName()) : make.Identifier("this"), name), make.Identifier(paramName)))), false); //NOI18N return make.Method(make.Modifiers(mods), setterName, make.Type(copy.getTypes().getNoType(TypeKind.VOID)), Collections.<TypeParameterTree>emptyList(), params, Collections.<ExpressionTree>emptyList(), body, null); }
private static String removeFieldPrefixSuffix(VariableElement var, CodeStyle cs) { boolean isStatic = var.getModifiers().contains(Modifier.STATIC); return CodeStyleUtils.removePrefixSuffix(var.getSimpleName(), isStatic ? cs.getStaticFieldNamePrefix() : cs.getFieldNamePrefix(), isStatic ? cs.getStaticFieldNameSuffix() : cs.getFieldNameSuffix()); }
/** * Creates a setter method for a field. * * @param clazz the class to create the setter within * @param field field to create setter for * @return the setter method * @since 0.20 */ public MethodTree createSetter(ClassTree clazz, VariableTree field) { assert clazz != null && field != null; TreeMaker make = copy.getTreeMaker(); Set<Modifier> mods = EnumSet.of(Modifier.PUBLIC); boolean isStatic = field.getModifiers().getFlags().contains(Modifier.STATIC); if (isStatic) mods.add(Modifier.STATIC); CharSequence name = field.getName(); assert name.length() > 0; CodeStyle cs = DiffContext.getCodeStyle(copy); String propName = removeFieldPrefixSuffix(field, cs); String setterName = CodeStyleUtils.computeSetterName(field.getName(), isStatic, cs); String paramName = addParamPrefixSuffix(propName, cs); List<VariableTree> params = Collections.singletonList(make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), paramName, field.getType(), null)); BlockTree body = make.Block(Collections.singletonList(make.ExpressionStatement(make.Assignment(make.MemberSelect(isStatic? make.Identifier(clazz.getSimpleName()) : make.Identifier("this"), name), make.Identifier(paramName)))), false); //NOI18N return make.Method(make.Modifiers(mods), setterName, make.Type(copy.getTypes().getNoType(TypeKind.VOID)), Collections.<TypeParameterTree>emptyList(), params, Collections.<ExpressionTree>emptyList(), body, null); }
/** * 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); }
name = CodeStyleUtils.addPrefixSuffix(name, namePrefix, nameSuffix); while (isClashing(name, type, locals)) { if (isPrimitive) { char c = name.charAt(namePrefix != null ? namePrefix.length() : 0); name = CodeStyleUtils.addPrefixSuffix(Character.toString(++c), namePrefix, nameSuffix); if (c == 'z' || c == 'Z') { //NOI18N isPrimitive = false; name = CodeStyleUtils.addPrefixSuffix(baseName + cnt++, namePrefix, nameSuffix);
/** * Computes the method name that should be used to read the property value. * * @param fieldName the name of the property * @param isBoolean true if the property is of boolean type * @param isStatic true if the property is static * @param cs the CodeSyle to use * @return the getter name */ @NonNull public static String computeGetterName(CharSequence fieldName, boolean isBoolean, boolean isStatic, CodeStyle cs) { StringBuilder sb = new StringBuilder(getCapitalizedName(removeFieldPrefixSuffix(fieldName, isStatic, cs))); sb.insert(0, isBoolean ? "is" : "get"); //NOI18N String getterName = sb.toString(); return getterName; }
private static String removeFieldPrefixSuffix(CharSequence fieldName, boolean isStatic, CodeStyle cs) { return removePrefixSuffix(fieldName, isStatic ? cs.getStaticFieldNamePrefix() : cs.getFieldNamePrefix(), isStatic ? cs.getStaticFieldNameSuffix() : cs.getFieldNameSuffix()); } }
/** * 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); }
private static String removeFieldPrefixSuffix(VariableTree var, CodeStyle cs) { boolean isStatic = var.getModifiers().getFlags().contains(Modifier.STATIC); return CodeStyleUtils.removePrefixSuffix(var.getName(), isStatic ? cs.getStaticFieldNamePrefix() : cs.getFieldNamePrefix(), isStatic ? cs.getStaticFieldNameSuffix() : cs.getFieldNameSuffix()); }