本文整理匯總了Java中org.eclipse.jdt.core.dom.IMethodBinding類的典型用法代碼示例。如果您正苦於以下問題:Java IMethodBinding類的具體用法?Java IMethodBinding怎麽用?Java IMethodBinding使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IMethodBinding類屬於org.eclipse.jdt.core.dom包,在下文中一共展示了IMethodBinding類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initByIMethodBinding
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
public void initByIMethodBinding(IMethodBinding mBinding) {
IMethod iMethod = (IMethod) mBinding.getJavaElement();
try {
key = iMethod.getKey().substring(0, iMethod.getKey().indexOf("("))
+ iMethod.getSignature();
projectName = mBinding.getJavaElement().getJavaProject()
.getElementName();
} catch (Exception e) {
projectName = "";
}
packageName = mBinding.getDeclaringClass().getPackage().getName();
className = mBinding.getDeclaringClass().getName();
name = mBinding.getName();
parameters = new ArrayList<>();
ITypeBinding[] parameterBindings = mBinding.getParameterTypes();
for (int i = 0; i < parameterBindings.length; i++) {
parameters.add(parameterBindings[i].getName());
}
}
示例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(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;
}
示例3: visit
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
@Override
public final boolean visit(MethodInvocation node) {
IMethodBinding methodBinding = node.resolveMethodBinding();
if (methodBinding != null) {
handleTypeBinding(node, methodBinding.getDeclaringClass(), false);
handleMethodBinding(node, methodBinding);
}
return true;
}
示例4: getKeyFromMethodBinding
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
public static String getKeyFromMethodBinding(IMethodBinding binding) {
StringBuilder sb = new StringBuilder();
String className = binding.getDeclaringClass().getErasure().getQualifiedName();
sb.append(className);
sb.append('.');
String methodName = binding.isConstructor() ? "" : binding.getName();
sb.append(methodName);
//if (methodName.equals("allObjectsSorted")) {
// System.out.println();
//}
sb.append('(');
ITypeBinding[] parameters = binding.getParameterTypes();
for (int i = 0; i < parameters.length; i++) {
if (i > 0) {
sb.append(", ");
}
ITypeBinding type = parameters[i];
sb.append(type.getErasure().getName());
}
sb.append(')');
return sb.toString();
}
示例5: getKeyFromMethodBinding
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
public static String getKeyFromMethodBinding(IMethodBinding binding) {
StringBuilder sb = new StringBuilder();
String className = binding.getDeclaringClass().getErasure().getQualifiedName();
sb.append(className);
sb.append('#');
String methodName = binding.isConstructor() ? "" : binding.getName();
sb.append(methodName);
//if (methodName.equals("allObjectsSorted")) {
// System.out.println();
//}
sb.append('(');
ITypeBinding[] parameters = binding.getParameterTypes();
for (int i = 0; i < parameters.length; i++) {
if (i > 0) {
sb.append(", ");
}
ITypeBinding type = parameters[i];
sb.append(type.getErasure().getName());
}
sb.append(')');
return sb.toString();
}
示例6: visit
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
public boolean visit(CastExpression node) {
if (mtbStack.isEmpty()) // not part of a method
return true;
Expression expression = node.getExpression();
ITypeBinding type = node.getType().resolveBinding();
IMethodBinding mtb = mtbStack.peek();
String exprStr = expression.toString();
String typeStr = getQualifiedName(type);
String methodStr = getQualifiedName(mtb);
exprStr = edit_str(exprStr);
facts.add(Fact.makeCastFact(exprStr, typeStr, methodStr));
return true;
}
示例7: getSimpleName
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
private static String getSimpleName(IMethodBinding imb) {
try {
// imb = imb.getMethodDeclaration();
String name = imb.getName();
if (imb.isConstructor())
name = "<init>";
String args = "";
/*
* for (ITypeBinding itb : imb.getParameterTypes()) { if
* (args.length()>0) args+=","; args += getQualifiedName(itb); }
*/
args = "(" + args + ")";
return name + args;
} catch (NullPointerException e) {
return "";
}
}
示例8: getReturnDeclaredDomains
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
/**
* @return the list of formal domains for return type
* */
// TODO: Move method elsewhere. to TraceUtils?
public static List<DomainP> getReturnDeclaredDomains(QualifiedClassName C, IMethodBinding mb, AnnotationDatabase annoDB) {
AnnotationSummary methAnnots = annoDB.getSummaryForMethod(mb);
List<DomainP> listP = new ArrayList<DomainP>();
List<ICrystalAnnotation> annots = methAnnots.getReturn();
// XXX. Why do we have this check here? We might read from cache! There could be another annotation, e.g., @Deprecated
if (annots.size() > 0) {
listP = getFormalDomains(C, mb, annots);
} else {
String key = mb.getMethodDeclaration().getKey();
MethodAnnotationInfo methDecl = MethodAnnotationInfo.getBinding(key);
if (methDecl != null) {
AnnotationInfo anInfo = methDecl.getReturnAnnotation();
if (anInfo.getAnnotation().isEmpty()) {
anInfo = AnnotationInfo.Shared;
}
listP = Utils.getDomainP(C, anInfo);
}
}
return listP;
}
示例9: getBindingLabel
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
/**
* Returns the label for a Java element with the flags as defined by {@link JavaElementLabels}.
* @param binding The binding to render.
* @param flags The text flags as defined in {@link JavaElementLabels}
* @return the label of the binding
*/
public static String getBindingLabel(IBinding binding, long flags) {
StringBuffer buffer= new StringBuffer(60);
if (binding instanceof ITypeBinding) {
getTypeLabel(((ITypeBinding) binding), flags, buffer);
} else if (binding instanceof IMethodBinding) {
getMethodLabel(((IMethodBinding) binding), flags, buffer);
} else if (binding instanceof IVariableBinding) {
final IVariableBinding variable= (IVariableBinding) binding;
if (variable.isField()) {
getFieldLabel(variable, flags, buffer);
} else {
getLocalVariableLabel(variable, flags, buffer);
}
}
return Strings.markLTR(buffer.toString());
}
示例10: compareInTheSameType
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
private int compareInTheSameType(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) {
try {
IMethod firstMethod= (IMethod)firstMethodBinding.getJavaElement();
IMethod secondMethod= (IMethod)secondMethodBinding.getJavaElement();
if (firstMethod == null || secondMethod == null) {
return 0;
}
ISourceRange firstSourceRange= firstMethod.getSourceRange();
ISourceRange secondSourceRange= secondMethod.getSourceRange();
if (!SourceRange.isAvailable(firstSourceRange) || !SourceRange.isAvailable(secondSourceRange)) {
return firstMethod.getElementName().compareTo(secondMethod.getElementName());
} else {
return firstSourceRange.getOffset() - secondSourceRange.getOffset();
}
} catch (JavaModelException e) {
return 0;
}
}
示例11: asString
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
private static String asString(IMethodBinding method) {
StringBuffer result= new StringBuffer();
result.append(method.getDeclaringClass().getName());
result.append(':');
result.append(method.getName());
result.append('(');
ITypeBinding[] parameters= method.getParameterTypes();
int lastComma= parameters.length - 1;
for (int i= 0; i < parameters.length; i++) {
ITypeBinding parameter= parameters[i];
result.append(parameter.getName());
if (i < lastComma)
{
result.append(", "); //$NON-NLS-1$
}
}
result.append(')');
return result.toString();
}
示例12: findMethodInType
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
/**
* Finds the method specified by <code>methodName</code> and <code>parameters</code> in
* the given <code>type</code>. Returns <code>null</code> if no such method exists.
* @param type The type to search the method in
* @param methodName The name of the method to find
* @param parameters The parameter types of the method to find. If <code>null</code> is passed, only
* the name is matched and parameters are ignored.
* @return the method binding representing the method
*/
public static IMethodBinding findMethodInType(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
if (type.isPrimitive()) {
return null;
}
IMethodBinding[] methods= type.getDeclaredMethods();
for (int i= 0; i < methods.length; i++) {
if (parameters == null) {
if (methodName.equals(methods[i].getName())) {
return methods[i];
}
} else {
if (isEqualMethod(methods[i], methodName, parameters)) {
return methods[i];
}
}
}
return null;
}
示例13: findMethodInHierarchy
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
/**
* Finds the method specified by <code>methodName</code> and <code>parameters</code> in
* the type hierarchy denoted by the given type. Returns <code>null</code> if no such method
* exists. If the method is defined in more than one super type only the first match is
* returned. First the super class is examined and then the implemented interfaces.
*
* @param type The type to search the method in
* @param methodName The name of the method to find
* @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
* @return the method binding representing the method
*/
public static IMethodBinding findMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding[] parameters) {
IMethodBinding method= findMethodInType(type, methodName, parameters);
if (method != null) {
return method;
}
ITypeBinding superClass= type.getSuperclass();
if (superClass != null) {
method= findMethodInHierarchy(superClass, methodName, parameters);
if (method != null) {
return method;
}
}
ITypeBinding[] interfaces= type.getInterfaces();
for (int i= 0; i < interfaces.length; i++) {
method= findMethodInHierarchy(interfaces[i], methodName, parameters);
if (method != null) {
return method;
}
}
return null;
}
示例14: findMethodWithDeclaredParameterTypesInType
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
/**
* Finds the method specified by <code>methodName</code> and <code>parameters</code> in
* the given <code>type</code>. Returns <code>null</code> if no such method exists.
* <p>
* This variant of {@link #findMethodInType(ITypeBinding, String, String[])} looks for a method
* whose {@link IMethodBinding#getMethodDeclaration() declaration}'s parameters matches the
* given parameters.
* </p>
*
* @param type The type to search the method in
* @param methodName The name of the method to find
* @param parameters The parameter types of the method to find. If <code>null</code> is passed, only the name is matched and parameters are ignored.
* @return the method binding representing the method
*/
public static IMethodBinding findMethodWithDeclaredParameterTypesInType(ITypeBinding type, String methodName, String[] parameters) {
if (type.isPrimitive()) {
return null;
}
IMethodBinding[] methods= type.getDeclaredMethods();
for (int i= 0; i < methods.length; i++) {
if (parameters == null) {
if (methodName.equals(methods[i].getName())) {
return methods[i];
}
} else {
if (isEqualMethod(methods[i].getMethodDeclaration(), methodName, parameters)) {
return methods[i];
}
}
}
return null;
}
示例15: findOverriddenMethodInHierarchy
import org.eclipse.jdt.core.dom.IMethodBinding; //導入依賴的package包/類
/**
* Finds a method in the hierarchy of <code>type</code> that is overridden by <code>binding</code>.
* Returns <code>null</code> if no such method exists. If the method is defined in more than one super type only the first match is
* returned. First the super class is examined and then the implemented interfaces.
* @param type The type to search the method in
* @param binding The method that overrides
* @return the method binding overridden the method
*/
public static IMethodBinding findOverriddenMethodInHierarchy(ITypeBinding type, IMethodBinding binding) {
IMethodBinding method= findOverriddenMethodInType(type, binding);
if (method != null) {
return method;
}
ITypeBinding superClass= type.getSuperclass();
if (superClass != null) {
method= findOverriddenMethodInHierarchy(superClass, binding);
if (method != null) {
return method;
}
}
ITypeBinding[] interfaces= type.getInterfaces();
for (int i= 0; i < interfaces.length; i++) {
method= findOverriddenMethodInHierarchy(interfaces[i], binding);
if (method != null) {
return method;
}
}
return null;
}