本文整理汇总了Java中org.eclipse.jdt.ui.CodeGeneration.getGetterComment方法的典型用法代码示例。如果您正苦于以下问题:Java CodeGeneration.getGetterComment方法的具体用法?Java CodeGeneration.getGetterComment怎么用?Java CodeGeneration.getGetterComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.ui.CodeGeneration
的用法示例。
在下文中一共展示了CodeGeneration.getGetterComment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGetter
import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private MethodDeclaration createGetter(ParameterInfo pi, String declaringType, CompilationUnitRewrite cuRewrite) throws CoreException {
AST ast= cuRewrite.getAST();
ICompilationUnit cu= cuRewrite.getCu();
IJavaProject project= cu.getJavaProject();
MethodDeclaration methodDeclaration= ast.newMethodDeclaration();
String fieldName= pi.getNewName();
String getterName= getGetterName(pi, ast, project);
String lineDelim= StubUtility.getLineDelimiterUsed(cu);
String bareFieldname= NamingConventions.getBaseName(NamingConventions.VK_INSTANCE_FIELD, fieldName, project);
if (createComments(project)) {
String comment= CodeGeneration.getGetterComment(cu, declaringType, getterName, fieldName, pi.getNewTypeName(), bareFieldname, lineDelim);
if (comment != null)
methodDeclaration.setJavadoc((Javadoc) cuRewrite.getASTRewrite().createStringPlaceholder(comment, ASTNode.JAVADOC));
}
methodDeclaration.setName(ast.newSimpleName(getterName));
methodDeclaration.setReturnType2(importBinding(pi.getNewTypeBinding(), cuRewrite));
methodDeclaration.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
Block block= ast.newBlock();
methodDeclaration.setBody(block);
boolean useThis= StubUtility.useThisForFieldAccess(project);
if (useThis) {
fieldName= "this." + fieldName; //$NON-NLS-1$
}
String bodyContent= CodeGeneration.getGetterMethodBodyContent(cu, declaringType, getterName, fieldName, lineDelim);
ASTNode getterBody= cuRewrite.getASTRewrite().createStringPlaceholder(bodyContent, ASTNode.EXPRESSION_STATEMENT);
block.statements().add(getterBody);
return methodDeclaration;
}
示例2: createGetterMethod
import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private MethodDeclaration createGetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException {
FieldDeclaration field= (FieldDeclaration)ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
Type type= field.getType();
MethodDeclaration result= ast.newMethodDeclaration();
result.setName(ast.newSimpleName(fGetterName));
result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
Type returnType= DimensionRewrite.copyTypeAndAddDimensions(type, fFieldDeclaration.extraDimensions(), rewriter);
result.setReturnType2(returnType);
Block block= ast.newBlock();
result.setBody(block);
String body= CodeGeneration.getGetterMethodBodyContent(fField.getCompilationUnit(), getTypeName(field.getParent()), fGetterName, fField.getElementName(), lineDelimiter);
if (body != null) {
ASTNode getterNode= rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
block.statements().add(getterNode);
} else {
ReturnStatement rs= ast.newReturnStatement();
rs.setExpression(ast.newSimpleName(fField.getElementName()));
block.statements().add(rs);
}
if (fGenerateJavadoc) {
String string= CodeGeneration.getGetterComment(
fField.getCompilationUnit() , getTypeName(field.getParent()), fGetterName,
fField.getElementName(), ASTNodes.asString(type),
StubUtility.getBaseName(fField),
lineDelimiter);
if (string != null) {
Javadoc javadoc= (Javadoc)fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
result.setJavadoc(javadoc);
}
}
return result;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:35,代码来源:SelfEncapsulateFieldRefactoring.java
示例3: getGetterStub
import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
/**
* Create a stub for a getter of the given field using getter/setter templates. The resulting code
* has to be formatted and indented.
*
* @param field The field to create a getter for
* @param getterName The chosen name for the getter
* @param addComments If <code>true</code>, comments will be added.
* @param flags The flags signaling visibility, if static, synchronized or final
* @return Returns the generated stub.
* @throws CoreException when stub creation failed
*/
public static String getGetterStub(
IField field, String getterName, boolean addComments, int flags) throws CoreException {
String fieldName = field.getElementName();
IType parentType = field.getDeclaringType();
boolean isStatic = Flags.isStatic(flags);
boolean isSync = Flags.isSynchronized(flags);
boolean isFinal = Flags.isFinal(flags);
String typeName = Signature.toString(field.getTypeSignature());
String accessorName = StubUtility.getBaseName(field);
String lineDelim =
"\n"; // Use default line delimiter, as generated stub has to be formatted anyway
// //$NON-NLS-1$
StringBuffer buf = new StringBuffer();
if (addComments) {
String comment =
CodeGeneration.getGetterComment(
field.getCompilationUnit(),
parentType.getTypeQualifiedName('.'),
getterName,
field.getElementName(),
typeName,
accessorName,
lineDelim);
if (comment != null) {
buf.append(comment);
buf.append(lineDelim);
}
}
buf.append(JdtFlags.getVisibilityString(flags));
buf.append(' ');
if (isStatic) buf.append("static "); // $NON-NLS-1$
if (isSync) buf.append("synchronized "); // $NON-NLS-1$
if (isFinal) buf.append("final "); // $NON-NLS-1$
buf.append(typeName);
buf.append(' ');
buf.append(getterName);
buf.append("() {"); // $NON-NLS-1$
buf.append(lineDelim);
boolean useThis = StubUtility.useThisForFieldAccess(field.getJavaProject());
if (useThis && !isStatic) {
fieldName = "this." + fieldName; // $NON-NLS-1$
}
String body =
CodeGeneration.getGetterMethodBodyContent(
field.getCompilationUnit(),
parentType.getTypeQualifiedName('.'),
getterName,
fieldName,
lineDelim);
if (body != null) {
buf.append(body);
}
buf.append("}"); // $NON-NLS-1$
buf.append(lineDelim);
return buf.toString();
}
示例4: createGetterMethod
import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private MethodDeclaration createGetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter)
throws CoreException {
FieldDeclaration field =
(FieldDeclaration) ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
Type type = field.getType();
MethodDeclaration result = ast.newMethodDeclaration();
result.setName(ast.newSimpleName(fGetterName));
result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
Type returnType =
DimensionRewrite.copyTypeAndAddDimensions(
type, fFieldDeclaration.extraDimensions(), rewriter);
result.setReturnType2(returnType);
Block block = ast.newBlock();
result.setBody(block);
String body =
CodeGeneration.getGetterMethodBodyContent(
fField.getCompilationUnit(),
getTypeName(field.getParent()),
fGetterName,
fField.getElementName(),
lineDelimiter);
if (body != null) {
ASTNode getterNode = rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
block.statements().add(getterNode);
} else {
ReturnStatement rs = ast.newReturnStatement();
rs.setExpression(ast.newSimpleName(fField.getElementName()));
block.statements().add(rs);
}
if (fGenerateJavadoc) {
String string =
CodeGeneration.getGetterComment(
fField.getCompilationUnit(),
getTypeName(field.getParent()),
fGetterName,
fField.getElementName(),
ASTNodes.asString(type),
StubUtility.getBaseName(fField),
lineDelimiter);
if (string != null) {
Javadoc javadoc = (Javadoc) fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
result.setJavadoc(javadoc);
}
}
return result;
}
示例5: getGetterStub
import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
/**
* Create a stub for a getter of the given field using getter/setter templates. The resulting code
* has to be formatted and indented.
* @param field The field to create a getter for
* @param getterName The chosen name for the getter
* @param addComments If <code>true</code>, comments will be added.
* @param flags The flags signaling visibility, if static, synchronized or final
* @return Returns the generated stub.
* @throws CoreException when stub creation failed
*/
public static String getGetterStub(IField field, String getterName, boolean addComments, int flags) throws CoreException {
String fieldName= field.getElementName();
IType parentType= field.getDeclaringType();
boolean isStatic= Flags.isStatic(flags);
boolean isSync= Flags.isSynchronized(flags);
boolean isFinal= Flags.isFinal(flags);
String typeName= Signature.toString(field.getTypeSignature());
String accessorName= StubUtility.getBaseName(field);
String lineDelim= "\n"; // Use default line delimiter, as generated stub has to be formatted anyway //$NON-NLS-1$
StringBuffer buf= new StringBuffer();
if (addComments) {
String comment= CodeGeneration.getGetterComment(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, field.getElementName(), typeName, accessorName, lineDelim);
if (comment != null) {
buf.append(comment);
buf.append(lineDelim);
}
}
buf.append(JdtFlags.getVisibilityString(flags));
buf.append(' ');
if (isStatic)
buf.append("static "); //$NON-NLS-1$
if (isSync)
buf.append("synchronized "); //$NON-NLS-1$
if (isFinal)
buf.append("final "); //$NON-NLS-1$
buf.append(typeName);
buf.append(' ');
buf.append(getterName);
buf.append("() {"); //$NON-NLS-1$
buf.append(lineDelim);
boolean useThis= StubUtility.useThisForFieldAccess(field.getJavaProject());
if (useThis && !isStatic) {
fieldName= "this." + fieldName; //$NON-NLS-1$
}
String body= CodeGeneration.getGetterMethodBodyContent(field.getCompilationUnit(), parentType.getTypeQualifiedName('.'), getterName, fieldName, lineDelim);
if (body != null) {
buf.append(body);
}
buf.append("}"); //$NON-NLS-1$
buf.append(lineDelim);
return buf.toString();
}
示例6: createGetterMethod
import org.eclipse.jdt.ui.CodeGeneration; //导入方法依赖的package包/类
private MethodDeclaration createGetterMethod(AST ast, ASTRewrite rewriter, String lineDelimiter) throws CoreException {
FieldDeclaration field= (FieldDeclaration)ASTNodes.getParent(fFieldDeclaration, FieldDeclaration.class);
Type type= field.getType();
MethodDeclaration result= ast.newMethodDeclaration();
result.setName(ast.newSimpleName(fGetterName));
result.modifiers().addAll(ASTNodeFactory.newModifiers(ast, createModifiers()));
Type returnType;
if (fFieldDeclaration.getExtraDimensions() > 0) {
if (type instanceof ArrayType) {
ArrayType arrayType= (ArrayType)type;
returnType= (Type)rewriter.createCopyTarget(arrayType.getElementType());
returnType= ast.newArrayType(returnType, fFieldDeclaration.getExtraDimensions() + arrayType.getDimensions());
} else {
returnType= (Type)rewriter.createCopyTarget(type);
returnType= ast.newArrayType(returnType, fFieldDeclaration.getExtraDimensions());
}
} else
returnType= (Type)rewriter.createCopyTarget(type);
result.setReturnType2(returnType);
Block block= ast.newBlock();
result.setBody(block);
String body= CodeGeneration.getGetterMethodBodyContent(fField.getCompilationUnit(), getTypeName(field.getParent()), fGetterName, fField.getElementName(), lineDelimiter);
if (body != null) {
ASTNode getterNode= rewriter.createStringPlaceholder(body, ASTNode.BLOCK);
block.statements().add(getterNode);
} else {
ReturnStatement rs= ast.newReturnStatement();
rs.setExpression(ast.newSimpleName(fField.getElementName()));
block.statements().add(rs);
}
if (fGenerateJavadoc) {
String string= CodeGeneration.getGetterComment(
fField.getCompilationUnit() , getTypeName(field.getParent()), fGetterName,
fField.getElementName(), ASTNodes.asString(type),
StubUtility.getBaseName(fField),
lineDelimiter);
if (string != null) {
Javadoc javadoc= (Javadoc)fRewriter.createStringPlaceholder(string, ASTNode.JAVADOC);
result.setJavadoc(javadoc);
}
}
return result;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:47,代码来源:SelfEncapsulateFieldRefactoring.java