本文整理匯總了Java中org.eclipse.jdt.core.dom.IMethodBinding.getMethodDeclaration方法的典型用法代碼示例。如果您正苦於以下問題:Java IMethodBinding.getMethodDeclaration方法的具體用法?Java IMethodBinding.getMethodDeclaration怎麽用?Java IMethodBinding.getMethodDeclaration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.IMethodBinding
的用法示例。
在下文中一共展示了IMethodBinding.getMethodDeclaration方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handle
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
// add the expression's subtree (e.g: foo(..).bar() should handle foo(..) first)
DSubTree Texp = new DOMExpression(creation.getExpression()).handle();
tree.addNodes(Texp.getNodes());
// evaluate arguments first
for (Object o : creation.arguments()) {
DSubTree Targ = new DOMExpression((Expression) o).handle();
tree.addNodes(Targ.getNodes());
}
IMethodBinding binding = creation.resolveConstructorBinding();
// get to the generic declaration, if this binding is an instantiation
while (binding != null && binding.getMethodDeclaration() != binding)
binding = binding.getMethodDeclaration();
MethodDeclaration localMethod = Utils.checkAndGetLocalMethod(binding);
if (localMethod != null) {
DSubTree Tmethod = new DOMMethodDeclaration(localMethod).handle();
tree.addNodes(Tmethod.getNodes());
}
else if (Utils.isRelevantCall(binding))
tree.addNode(new DAPICall(binding, Visitor.V().getLineNumber(creation)));
return tree;
}
示例2: handle
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
// add the expression's subtree (e.g: foo(..).bar() should handle foo(..) first)
DSubTree Texp = new DOMExpression(invocation.getExpression()).handle();
tree.addNodes(Texp.getNodes());
// evaluate arguments first
for (Object o : invocation.arguments()) {
DSubTree Targ = new DOMExpression((Expression) o).handle();
tree.addNodes(Targ.getNodes());
}
IMethodBinding binding = invocation.resolveMethodBinding();
// get to the generic declaration, if this binding is an instantiation
while (binding != null && binding.getMethodDeclaration() != binding)
binding = binding.getMethodDeclaration();
MethodDeclaration localMethod = Utils.checkAndGetLocalMethod(binding);
if (localMethod != null) {
Stack<MethodDeclaration> callStack = Visitor.V().callStack;
if (! callStack.contains(localMethod)) {
callStack.push(localMethod);
DSubTree Tmethod = new DOMMethodDeclaration(localMethod).handle();
callStack.pop();
tree.addNodes(Tmethod.getNodes());
}
}
else if (Utils.isRelevantCall(binding))
tree.addNode(new DAPICall(binding, Visitor.V().getLineNumber(invocation)));
return tree;
}
示例3: findMethod
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
/**
* Finds a method for the given <code>IMethodBinding</code>. Returns
* <code>null</code> if the type doesn't contain a corresponding method.
* @param method the method to find
* @param type the type to look in
* @return the corresponding IMethod or <code>null</code>
* @throws JavaModelException if an error occurs in the Java model
* @deprecated Use {@link #findMethodInHierarchy(ITypeBinding, String, String[])} or {@link JavaModelUtil}
*/
@Deprecated
public static IMethod findMethod(IMethodBinding method, IType type) throws JavaModelException {
method= method.getMethodDeclaration();
IMethod[] candidates= type.getMethods();
for (int i= 0; i < candidates.length; i++) {
IMethod candidate= candidates[i];
if (candidate.getElementName().equals(method.getName()) && sameParameters(method, candidate)) {
return candidate;
}
}
return null;
}
示例4: getDeclaration
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
private static IBinding getDeclaration(IBinding binding) {
if (binding instanceof ITypeBinding) {
return ((ITypeBinding) binding).getTypeDeclaration();
} else if (binding instanceof IMethodBinding) {
IMethodBinding methodBinding= (IMethodBinding) binding;
if (methodBinding.isConstructor()) { // link all constructors with their type
return methodBinding.getDeclaringClass().getTypeDeclaration();
} else {
return methodBinding.getMethodDeclaration();
}
} else if (binding instanceof IVariableBinding) {
return ((IVariableBinding) binding).getVariableDeclaration();
}
return binding;
}
示例5: visit
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
@Override
public boolean visit(ITypeBinding type) {
IMethodBinding[] methods= type.getDeclaredMethods();
for (int i= 0; i < methods.length; i++) {
IMethodBinding candidate= methods[i];
if (candidate.getMethodDeclaration() == fOriginalMethod.getMethodDeclaration()) {
continue;
}
ITypeBinding candidateDeclaringType= candidate.getDeclaringClass();
if (fDeclaringType != candidateDeclaringType) {
int modifiers= candidate.getModifiers();
if (candidateDeclaringType.isInterface() && Modifier.isStatic(modifiers)) {
continue;
}
if (Modifier.isPrivate(modifiers)) {
continue;
}
}
if (fOriginalMethod.getName().equals(candidate.getName()) && !fOriginalMethod.overrides(candidate)) {
ITypeBinding[] originalParameterTypes= fOriginalMethod.getParameterTypes();
ITypeBinding[] candidateParameterTypes= candidate.getParameterTypes();
boolean couldBeAmbiguous;
if (originalParameterTypes.length == candidateParameterTypes.length) {
couldBeAmbiguous= true;
} else if (fOriginalMethod.isVarargs() || candidate.isVarargs() ) {
int candidateMinArgumentCount= candidateParameterTypes.length;
if (candidate.isVarargs()) {
candidateMinArgumentCount--;
}
couldBeAmbiguous= fArgumentCount >= candidateMinArgumentCount;
} else {
couldBeAmbiguous= false;
}
if (couldBeAmbiguous) {
ITypeBinding parameterType= ASTResolving.getParameterTypeBinding(candidate, fArgIndex);
if (parameterType != null && parameterType.getFunctionalInterfaceMethod() != null) {
if (!fExpressionIsExplicitlyTyped) {
/* According to JLS8 15.12.2.2, implicitly typed lambda expressions are not "pertinent to applicability"
* and hence potentially applicable methods are always "applicable by strict invocation",
* regardless of whether argument expressions are compatible with the method's parameter types or not.
* If there are multiple such methods, 15.12.2.5 results in an ambiguous method invocation.
*/
return false;
}
/* Explicitly typed lambda expressions are pertinent to applicability, and hence
* compatibility with the corresponding method parameter type is checked. And since this check
* separates functional interface methods by their void-compatibility state, functional interfaces
* with a different void compatibility are not applicable any more and hence can't cause
* an ambiguous method invocation.
*/
ITypeBinding origParamType= ASTResolving.getParameterTypeBinding(fOriginalMethod, fArgIndex);
boolean originalIsVoidCompatible= Bindings.isVoidType(origParamType.getFunctionalInterfaceMethod().getReturnType());
boolean candidateIsVoidCompatible= Bindings.isVoidType(parameterType.getFunctionalInterfaceMethod().getReturnType());
if (originalIsVoidCompatible == candidateIsVoidCompatible) {
return false;
}
}
}
}
}
return true;
}
示例6: addIncompatibleReturnTypeProposals
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
public static void addIncompatibleReturnTypeProposals(IInvocationContext context, IProblemLocation problem,
Collection<CUCorrectionProposal> proposals) throws JavaModelException {
CompilationUnit astRoot= context.getASTRoot();
ASTNode selectedNode= problem.getCoveringNode(astRoot);
if (selectedNode == null) {
return;
}
MethodDeclaration decl= ASTResolving.findParentMethodDeclaration(selectedNode);
if (decl == null) {
return;
}
IMethodBinding methodDeclBinding= decl.resolveBinding();
if (methodDeclBinding == null) {
return;
}
ITypeBinding returnType= methodDeclBinding.getReturnType();
IMethodBinding overridden= Bindings.findOverriddenMethod(methodDeclBinding, false);
if (overridden == null || overridden.getReturnType() == returnType) {
return;
}
ICompilationUnit cu= context.getCompilationUnit();
IMethodBinding methodDecl= methodDeclBinding.getMethodDeclaration();
ITypeBinding overriddenReturnType= overridden.getReturnType();
if (! JavaModelUtil.is50OrHigher(context.getCompilationUnit().getJavaProject())) {
overriddenReturnType= overriddenReturnType.getErasure();
}
proposals.add(new TypeChangeCorrectionProposal(cu, methodDecl, astRoot, overriddenReturnType, false, IProposalRelevance.CHANGE_RETURN_TYPE));
ICompilationUnit targetCu= cu;
IMethodBinding overriddenDecl= overridden.getMethodDeclaration();
ITypeBinding overridenDeclType= overriddenDecl.getDeclaringClass();
if (overridenDeclType.isFromSource()) {
targetCu= ASTResolving.findCompilationUnitForBinding(cu, astRoot, overridenDeclType);
if (targetCu != null && ASTResolving.isUseableTypeInContext(returnType, overriddenDecl, false)) {
TypeChangeCorrectionProposal proposal= new TypeChangeCorrectionProposal(targetCu, overriddenDecl, astRoot, returnType, false, IProposalRelevance.CHANGE_RETURN_TYPE_OF_OVERRIDDEN);
if (overridenDeclType.isInterface()) {
proposal.setDisplayName(Messages.format(CorrectionMessages.TypeMismatchSubProcessor_changereturnofimplemented_description, BasicElementLabels.getJavaElementName(overriddenDecl.getName())));
} else {
proposal.setDisplayName(Messages.format(CorrectionMessages.TypeMismatchSubProcessor_changereturnofoverridden_description, BasicElementLabels.getJavaElementName(overriddenDecl.getName())));
}
proposals.add(proposal);
}
}
}
示例7: getMethodComment
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
/**
* Returns the comment for a method or constructor using the comment code templates (constructor / method / overriding method).
* <code>null</code> is returned if the template is empty.
* @param cu The compilation unit to which the method belongs. The compilation unit does not need to exist.
* @param declaringTypeName Name of the type to which the method belongs. For inner types the name must be qualified and include the outer
* types names (dot separated). See {@link org.eclipse.jdt.core.IType#getTypeQualifiedName(char)}.
* @param decl The MethodDeclaration AST node that will be added as new
* method. The node does not need to exist in an AST (no parent needed) and does not need to resolve.
* See {@link org.eclipse.jdt.core.dom.AST#newMethodDeclaration()} for how to create such a node.
* @param overridden The binding of the method to which to add an "@see" link or
* <code>null</code> if no link should be created.
* @param lineDelimiter The line delimiter to be used.
* @return Returns the generated method comment or <code>null</code> if the
* code template is empty. The returned content is unformatted and not indented (formatting required).
* @throws CoreException Thrown when the evaluation of the code template fails.
*/
public static String getMethodComment(ICompilationUnit cu, String declaringTypeName, MethodDeclaration decl, IMethodBinding overridden, String lineDelimiter) throws CoreException {
if (overridden != null) {
overridden= overridden.getMethodDeclaration();
String declaringClassQualifiedName= overridden.getDeclaringClass().getQualifiedName();
String linkToMethodName= overridden.getName();
String[] parameterTypesQualifiedNames= StubUtility.getParameterTypeNamesForSeeTag(overridden);
return StubUtility.getMethodComment(cu, declaringTypeName, decl, overridden.isDeprecated(), linkToMethodName, declaringClassQualifiedName, parameterTypesQualifiedNames, false, lineDelimiter);
} else {
return StubUtility.getMethodComment(cu, declaringTypeName, decl, false, null, null, null, false, lineDelimiter);
}
}