本文整理汇总了Java中org.eclipse.jdt.core.dom.MethodDeclaration.getName方法的典型用法代码示例。如果您正苦于以下问题:Java MethodDeclaration.getName方法的具体用法?Java MethodDeclaration.getName怎么用?Java MethodDeclaration.getName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.MethodDeclaration
的用法示例。
在下文中一共展示了MethodDeclaration.getName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isMainMethod
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
/**
* @param md
* @return
*/
public static boolean isMainMethod(MethodDeclaration md) {
IMethodBinding resolveBinding = md.resolveBinding();
if (resolveBinding == null)
return false;
ITypeBinding declClassBinding = resolveBinding.getDeclaringClass();
if (declClassBinding == null)
return false;
String declaringClass = declClassBinding.getQualifiedName();
SimpleName name = md.getName();
if (name == null)
return false;
String mName = name.toString();
return declaringClass.equals(MAINCLASS) && mName.equals(MAINMETHOD);
}
示例2: addMissingReturnTypeProposals
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
public static void addMissingReturnTypeProposals(IInvocationContext context, IProblemLocation problem, Collection<CUCorrectionProposal> proposals) {
ICompilationUnit cu= context.getCompilationUnit();
CompilationUnit astRoot= context.getASTRoot();
ASTNode selectedNode= problem.getCoveringNode(astRoot);
if (selectedNode == null) {
return;
}
BodyDeclaration decl= ASTResolving.findParentBodyDeclaration(selectedNode);
if (decl instanceof MethodDeclaration) {
MethodDeclaration methodDeclaration= (MethodDeclaration) decl;
ReturnStatementCollector eval= new ReturnStatementCollector();
decl.accept(eval);
AST ast= astRoot.getAST();
ITypeBinding typeBinding= eval.getTypeBinding(decl.getAST());
typeBinding= Bindings.normalizeTypeBinding(typeBinding);
if (typeBinding == null) {
typeBinding= ast.resolveWellKnownType("void"); //$NON-NLS-1$
}
if (typeBinding.isWildcardType()) {
typeBinding= ASTResolving.normalizeWildcardType(typeBinding, true, ast);
}
ASTRewrite rewrite= ASTRewrite.create(ast);
String label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_missingreturntype_description, BindingLabelProvider.getBindingLabel(typeBinding, BindingLabelProvider.DEFAULT_TEXTFLAGS));
LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, cu, rewrite, IProposalRelevance.MISSING_RETURN_TYPE);
ImportRewrite imports= proposal.createImportRewrite(astRoot);
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(decl, imports);
Type type= imports.addImport(typeBinding, ast, importRewriteContext, TypeLocation.RETURN_TYPE);
rewrite.set(methodDeclaration, MethodDeclaration.RETURN_TYPE2_PROPERTY, type, null);
rewrite.set(methodDeclaration, MethodDeclaration.CONSTRUCTOR_PROPERTY, Boolean.FALSE, null);
Javadoc javadoc= methodDeclaration.getJavadoc();
if (javadoc != null && typeBinding != null) {
TagElement newTag= ast.newTagElement();
newTag.setTagName(TagElement.TAG_RETURN);
TextElement commentStart= ast.newTextElement();
newTag.fragments().add(commentStart);
JavadocTagsSubProcessor.insertTag(rewrite.getListRewrite(javadoc, Javadoc.TAGS_PROPERTY), newTag, null);
proposal.addLinkedPosition(rewrite.track(commentStart), false, "comment_start"); //$NON-NLS-1$
}
String key= "return_type"; //$NON-NLS-1$
proposal.addLinkedPosition(rewrite.track(type), true, key);
if (typeBinding != null) {
ITypeBinding[] bindings= ASTResolving.getRelaxingTypes(ast, typeBinding);
for (int i= 0; i < bindings.length; i++) {
proposal.addLinkedPositionProposal(key, bindings[i]);
}
}
proposals.add(proposal);
// change to constructor
ASTNode parentType= ASTResolving.findParentType(decl);
if (parentType instanceof AbstractTypeDeclaration) {
boolean isInterface= parentType instanceof TypeDeclaration && ((TypeDeclaration) parentType).isInterface();
if (!isInterface) {
String constructorName= ((AbstractTypeDeclaration) parentType).getName().getIdentifier();
ASTNode nameNode= methodDeclaration.getName();
label= Messages.format(CorrectionMessages.ReturnTypeSubProcessor_wrongconstructorname_description, BasicElementLabels.getJavaElementName(constructorName));
proposals.add(new ReplaceCorrectionProposal(label, cu, nameNode.getStartPosition(), nameNode.getLength(), constructorName, IProposalRelevance.CHANGE_TO_CONSTRUCTOR));
}
}
}
}