/* */ package org.eclipse.jdt.internal.corext.codemanipulation;
/* */
/* */ import org.eclipse.core.runtime.CoreException;
/* */ import org.eclipse.jdt.core.Flags;
/* */ import org.eclipse.jdt.core.IField;
/* */ import org.eclipse.jdt.core.IJavaProject;
/* */ import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.ISourceRange;
/* */ import org.eclipse.jdt.core.IType;
/* */ import org.eclipse.jdt.core.JavaModelException;
/* */ import org.eclipse.jdt.core.NamingConventions;
/* */ import org.eclipse.jdt.core.Signature;
/* */ import org.eclipse.jdt.core.dom.AST;
/* */ import org.eclipse.jdt.core.dom.ASTNode;
/* */ import org.eclipse.jdt.core.dom.Assignment;
/* */ import org.eclipse.jdt.core.dom.Assignment.Operator;
/* */ import org.eclipse.jdt.core.dom.CastExpression;
/* */ import org.eclipse.jdt.core.dom.Expression;
/* */ import org.eclipse.jdt.core.dom.ITypeBinding;
/* */ import org.eclipse.jdt.core.dom.IVariableBinding;
/* */ import org.eclipse.jdt.core.dom.InfixExpression;
/* */ import org.eclipse.jdt.core.dom.NumberLiteral;
/* */ import org.eclipse.jdt.core.dom.ParenthesizedExpression;
/* */ import org.eclipse.jdt.core.dom.PostfixExpression;
/* */ import org.eclipse.jdt.core.dom.PrefixExpression;
/* */ import org.eclipse.jdt.core.dom.PrimitiveType;
/* */ import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
/* */ import org.eclipse.jdt.internal.corext.dom.ASTNodes;
/* */ import org.eclipse.jdt.internal.corext.dom.NecessaryParenthesesChecker;
/* */ import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
/* */ import org.eclipse.jdt.internal.corext.util.JdtFlags;
/* */ import org.eclipse.jdt.ui.CodeGeneration;
/* */
/* */ public class GetterSetterUtil
/* */ {
/* 48 */ private static final String[] EMPTY = new String[0];
/* */
/* */ public static String getGetterName(IField field, String[] excludedNames)
/* */ throws JavaModelException
/* */ {
/* 55 */ boolean useIs = StubUtility.useIsForBooleanGetters(field.getJavaProject());
/* 56 */ return getGetterName(field, excludedNames, useIs);
/* */ }
/* */
/* */ private static String getGetterName(IField field, String[] excludedNames, boolean useIsForBoolGetters) throws JavaModelException {
/* 60 */ if (excludedNames == null) {
/* 61 */ excludedNames = EMPTY;
/* */ }
/* 63 */ return getGetterName(field.getJavaProject(), field.getElementName(), field.getFlags(), (useIsForBoolGetters) && (JavaModelUtil.isBoolean(field)), excludedNames);
/* */ }
/* */
/* */ public static String getGetterName(IVariableBinding variableType, IJavaProject project, String[] excludedNames, boolean isBoolean) {
/* 67 */ boolean useIs = (StubUtility.useIsForBooleanGetters(project)) && (isBoolean);
/* 68 */ return getGetterName(project, variableType.getName(), variableType.getModifiers(), useIs, excludedNames);
/* */ }
/* */
/* */ public static String getGetterName(IJavaProject project, String fieldName, int flags, boolean isBoolean, String[] excludedNames) {
/* 72 */ return NamingConventions.suggestGetterName(project, fieldName, flags, isBoolean, excludedNames);
/* */ }
/* */
/* */ public static String getSetterName(IVariableBinding variableType, IJavaProject project, String[] excludedNames, boolean isBoolean) {
/* 76 */ return getSetterName(project, variableType.getName(), variableType.getModifiers(), isBoolean, excludedNames);
/* */ }
/* */
/* */ public static String getSetterName(IJavaProject project, String fieldName, int flags, boolean isBoolean, String[] excludedNames) {
/* 80 */ boolean useIs = StubUtility.useIsForBooleanGetters(project);
/* 81 */ return NamingConventions.suggestSetterName(project, fieldName, flags, (useIs) && (isBoolean), excludedNames);
/* */ }
/* */
/* */ public static String getSetterName(IField field, String[] excludedNames) throws JavaModelException {
/* 85 */ if (excludedNames == null) {
/* 86 */ excludedNames = EMPTY;
/* */ }
/* 88 */ return getSetterName(field.getJavaProject(), field.getElementName(), field.getFlags(), JavaModelUtil.isBoolean(field), excludedNames);
/* */ }
/* */
/* */ public static IMethod getGetter(IField field) throws JavaModelException {
/* 92 */ String getterName = getGetterName(field, EMPTY, true);
/* 93 */ IMethod primaryCandidate = JavaModelUtil.findMethod(getterName, new String[0], false, field.getDeclaringType());
/* 94 */ if ((!JavaModelUtil.isBoolean(field)) || ((primaryCandidate != null) && (primaryCandidate.exists()))) {
/* 95 */ return primaryCandidate;
/* */ }
/* 97 */ String secondCandidateName = getGetterName(field, EMPTY, false);
/* 98 */ return JavaModelUtil.findMethod(secondCandidateName, new String[0], false, field.getDeclaringType());
/* */ }
/* */
/* */ public static IMethod getSetter(IField field) throws JavaModelException {
/* 102 */ String[] args = { field.getTypeSignature() };
/* 103 */ return JavaModelUtil.findMethod(getSetterName(field, EMPTY), args, false, field.getDeclaringType());
/* */ }
/* */
/* */ public static String getSetterStub(IField field, String setterName, boolean addComments, int flags)
/* */ throws CoreException
/* */ {
/* 118 */ String fieldName = field.getElementName();
/* 119 */ IType parentType = field.getDeclaringType();
/* */
/* 121 */ String returnSig = field.getTypeSignature();
/* 122 */ String typeName = Signature.toString(returnSig);
/* */
/* 124 */ IJavaProject project = field.getJavaProject();
/* */
/* 126 */ String accessorName = StubUtility.getBaseName(field);
/* 127 */ String argname = StubUtility.suggestArgumentName(project, accessorName, EMPTY);
/* */
/* 129 */ boolean isStatic = Flags.isStatic(flags);
/* 130 */ boolean isSync = Flags.isSynchronized(flags);
/* 131 */ boolean isFinal = Flags.isFinal(flags);
/* */
/* 133 */ String lineDelim = "\n";
/* 134 */ StringBuffer buf = new StringBuffer();
/* 135 */ if (addComments) {
/* 136 */ String comment = CodeGeneration.getSetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), setterName, field.getElementName(), typeName, argname, accessorName, lineDelim);
ISourceRange sr= field.getJavadocRange();
if (null != sr) {
String filedComment= field.getSource();
filedComment= filedComment.substring(0, sr.getLength()).replaceAll("[\n,\r,*,/,\t]", "").trim(); //$NON-NLS-1$ //$NON-NLS-2$
comment= comment.replace("#{bare_field_comment}", filedComment); //$NON-NLS-1$
}
/* 137 */ if (comment != null) {
/* 138 */ buf.append(comment);
/* 139 */ buf.append(lineDelim);
/* */ }
/* */ }
/* 142 */ buf.append(JdtFlags.getVisibilityString(flags));
/* 143 */ buf.append(' ');
/* 144 */ if (isStatic)
/* 145 */ buf.append("static ");
/* 146 */ if (isSync)
/* 147 */ buf.append("synchronized ");
/* 148 */ if (isFinal) {
/* 149 */ buf.append("final ");
/* */ }
/* 151 */ buf.append("void ");
/* 152 */ buf.append(setterName);
/* 153 */ buf.append('(');
/* 154 */ buf.append(typeName);
/* 155 */ buf.append(' ');
/* 156 */ buf.append(argname);
/* 157 */ buf.append(") {");
/* 158 */ buf.append(lineDelim);
/* */
/* 160 */ boolean useThis = StubUtility.useThisForFieldAccess(project);
/* 161 */ if ((argname.equals(fieldName)) || ((useThis) && (!isStatic))) {
/* 162 */ if (isStatic)
/* 163 */ fieldName = parentType.getElementName()
没有合适的资源?快使用搜索试试~ 我知道了~
Eclipse中setter/getter方法自动添加属性注释
共9个文件
jar:3个
prefs:2个
classpath:1个
5星 · 超过95%的资源 需积分: 21 67 下载量 46 浏览量
2015-10-16
16:58:33
上传
评论
收藏 13.35MB ZIP 举报
温馨提示
eclipse中setter/getter方法自动添加属性注释,详情参考http://blog.csdn.net/yuxinabc/article/details/49179113
资源推荐
资源详情
资源评论
收起资源包目录
aaa.zip (9个子文件)
aaa
.project 379B
src
org
eclipse
jdt
internal
corext
codemanipulation
GetterSetterUtil.java 17KB
.settings
org.eclipse.jdt.core.prefs 598B
org.eclipse.core.resources.prefs 57B
libs
org.eclipse.equinox.common_3.6.100.v20120522-1841.jar 104KB
org.eclipse.jdt.ui_3.8.2.v20130107-165834.jar 9.86MB
org.eclipse.jdt.core_3.8.3.v20130121-145325.jar 4.59MB
.classpath 578B
bin
org
eclipse
jdt
internal
corext
codemanipulation
GetterSetterUtil.class 15KB
共 9 条
- 1
资源评论
- 呆萌的_-_2018-09-27挺不错的嗯
- 会飞的蛋蛋2020-05-25谢谢分享!!!
- jingweizong88112017-10-19挺不错的嗯
yuxinabc
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功