本文整理汇总了Java中org.eclipse.jdt.core.dom.SuperMethodInvocation.setName方法的典型用法代码示例。如果您正苦于以下问题:Java SuperMethodInvocation.setName方法的具体用法?Java SuperMethodInvocation.setName怎么用?Java SuperMethodInvocation.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.SuperMethodInvocation
的用法示例。
在下文中一共展示了SuperMethodInvocation.setName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHashCodeMethod
import org.eclipse.jdt.core.dom.SuperMethodInvocation; //导入方法依赖的package包/类
private MethodDeclaration createHashCodeMethod() throws CoreException {
MethodDeclaration hashCodeMethod= fAst.newMethodDeclaration();
hashCodeMethod.modifiers().addAll(ASTNodeFactory.newModifiers(fAst, Modifier.PUBLIC));
hashCodeMethod.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
hashCodeMethod.setConstructor(false);
hashCodeMethod.setReturnType2(fAst.newPrimitiveType(PrimitiveType.INT));
Block body= fAst.newBlock();
hashCodeMethod.setBody(body);
// PRIME NUMBER
VariableDeclarationFragment frag= fAst.newVariableDeclarationFragment();
frag.setName(fAst.newSimpleName(VARIABLE_NAME_PRIME));
frag.setInitializer(fAst.newNumberLiteral(PRIME_NUMBER));
VariableDeclarationStatement primeNumberDeclaration= fAst.newVariableDeclarationStatement(frag);
primeNumberDeclaration.modifiers().add(fAst.newModifier(ModifierKeyword.FINAL_KEYWORD));
primeNumberDeclaration.setType(fAst.newPrimitiveType(PrimitiveType.INT));
body.statements().add(primeNumberDeclaration);
// RESULT
VariableDeclarationFragment fragment= fAst.newVariableDeclarationFragment();
fragment.setName(fAst.newSimpleName(VARIABLE_NAME_RESULT));
VariableDeclarationStatement resultDeclaration= fAst.newVariableDeclarationStatement(fragment);
resultDeclaration.setType(fAst.newPrimitiveType(PrimitiveType.INT));
body.statements().add(resultDeclaration);
if (needsNoSuperCall(fType, METHODNAME_HASH_CODE, new ITypeBinding[0])) {
fragment.setInitializer(fAst.newNumberLiteral(INITIAL_HASHCODE_VALUE));
} else {
SuperMethodInvocation invoc= fAst.newSuperMethodInvocation();
invoc.setName(fAst.newSimpleName(METHODNAME_HASH_CODE));
fragment.setInitializer(invoc);
}
if (isMemberType()) {
body.statements().add(createAddOuterHashCode());
}
for (int i= 0; i < fFields.length; i++) {
if (fFields[i].getType().isPrimitive()) {
Statement[] sts= createAddSimpleHashCode(fFields[i].getType(), new IHashCodeAccessProvider() {
public Expression getThisAccess(String name) {
return getThisAccessForHashCode(name);
}
}, fFields[i].getName(), false);
for (int j= 0; j < sts.length; j++) {
body.statements().add(sts[j]);
}
} else if (fFields[i].getType().isArray())
body.statements().add(createAddArrayHashCode(fFields[i]));
else
body.statements().add(createAddQualifiedHashCode(fFields[i]));
}
// the last return:
ReturnStatement endReturn= fAst.newReturnStatement();
endReturn.setExpression(fAst.newSimpleName(VARIABLE_NAME_RESULT));
body.statements().add(endReturn);
// method comment
if (fSettings != null) {
ITypeBinding object= fAst.resolveWellKnownType(JAVA_LANG_OBJECT);
IMethodBinding[] objms= object.getDeclaredMethods();
IMethodBinding objectMethod= null;
for (int i= 0; i < objms.length; i++) {
if (objms[i].getName().equals(METHODNAME_HASH_CODE) && objms[i].getParameterTypes().length == 0)
objectMethod= objms[i];
}
createMethodComment(hashCodeMethod, objectMethod);
}
return hashCodeMethod;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:79,代码来源:GenerateHashCodeEqualsOperation.java
示例2: createSuperMethodInvocation
import org.eclipse.jdt.core.dom.SuperMethodInvocation; //导入方法依赖的package包/类
protected SuperMethodInvocation createSuperMethodInvocation(ASTRewrite rewrite, MethodDeclaration method) {
Assert.isNotNull(rewrite);
Assert.isNotNull(method);
AST ast = rewrite.getAST();
SuperMethodInvocation invocation = ast.newSuperMethodInvocation();
invocation.setName((SimpleName) rewrite.createCopyTarget(method.getName()));
return invocation;
}
示例3: processElement
import org.eclipse.jdt.core.dom.SuperMethodInvocation; //导入方法依赖的package包/类
/**
*
* @param templateElement the template element, see constants in {@link ToStringTemplateParser}
* @param member the member
* @return <code>String</code> or <code>Expression</code> switching
*/
protected Object processElement(String templateElement, Object member) {
Object result= templateElement;
if (templateElement == ToStringTemplateParser.OBJECT_NAME_VARIABLE) {
result= fContext.getTypeBinding().getName();
}
if (templateElement == ToStringTemplateParser.OBJECT_GET_NAME_VARIABLE) {
//this.getClass().getName()
MethodInvocation getClassInvocation= fAst.newMethodInvocation();
if (fContext.isKeywordThis())
getClassInvocation.setExpression(fAst.newThisExpression());
getClassInvocation.setName(fAst.newSimpleName("getClass")); //$NON-NLS-1$
MethodInvocation getNameInvocation= fAst.newMethodInvocation();
getNameInvocation.setExpression(getClassInvocation);
getNameInvocation.setName(fAst.newSimpleName("getName")); //$NON-NLS-1$
result= getNameInvocation;
}
if (templateElement == ToStringTemplateParser.OBJECT_SUPER_TOSTRING_VARIABLE) {
//super.toString()
SuperMethodInvocation superToStringInvocation= fAst.newSuperMethodInvocation();
superToStringInvocation.setName(fAst.newSimpleName(METHODNAME_TO_STRING));
result= superToStringInvocation;
}
if (templateElement == ToStringTemplateParser.OBJECT_HASHCODE_VARIABLE) {
//this.hashCode()
MethodInvocation hashCodeInvocation= fAst.newMethodInvocation();
if (fContext.isKeywordThis())
hashCodeInvocation.setExpression(fAst.newThisExpression());
hashCodeInvocation.setName(fAst.newSimpleName("hashCode")); //$NON-NLS-1$
result= hashCodeInvocation;
}
if (templateElement == ToStringTemplateParser.OBJECT_SYSTEM_HASHCODE_VARIABLE) {
//system.identityHashCode(this)
result= createMethodInvocation(addImport("java.lang.System"), "identityHashCode", fAst.newThisExpression()); //$NON-NLS-1$ //$NON-NLS-2$
}
if (templateElement == ToStringTemplateParser.MEMBER_NAME_VARIABLE || templateElement == ToStringTemplateParser.MEMBER_NAME_PARENTHESIS_VARIABLE) {
result= getMemberName(member, templateElement);
}
if (templateElement == ToStringTemplateParser.MEMBER_VALUE_VARIABLE) {
result= createMemberAccessExpression(member, false, fContext.isSkipNulls());
}
if (result instanceof StringLiteral)
return ((StringLiteral)result).getLiteralValue();
else
return result;
}