本文整理匯總了Java中org.eclipse.jdt.core.dom.ITypeBinding.getDeclaringMethod方法的典型用法代碼示例。如果您正苦於以下問題:Java ITypeBinding.getDeclaringMethod方法的具體用法?Java ITypeBinding.getDeclaringMethod怎麽用?Java ITypeBinding.getDeclaringMethod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.ITypeBinding
的用法示例。
在下文中一共展示了ITypeBinding.getDeclaringMethod方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findNullnessDefault
import org.eclipse.jdt.core.dom.ITypeBinding; //導入方法依賴的package包/類
/**
* Answer the annotation binding representing a nullness default
* effective at the point denoted by 'contextBinding'.
* @param contextBinding method binding or type binding denoting the location of interest
* @param javaProject the containing java project, consulted for the actual name of
* the annotation used for nullness defaults (default: <code>@NonNullByDefault</code>).
* @return binding for the effective nullness default annotation
* or null if no nullness default is effective at the context location.
*/
public static IAnnotationBinding findNullnessDefault(IBinding contextBinding, IJavaProject javaProject) {
if (JavaCore.ENABLED.equals(javaProject.getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true))) {
String annotationName= javaProject.getOption(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, true);
while (contextBinding != null) {
for (IAnnotationBinding annotation : contextBinding.getAnnotations()) {
ITypeBinding annotationType= annotation.getAnnotationType();
if (annotationType != null && annotationType.getQualifiedName().equals(annotationName)) {
return annotation;
}
}
// travel out:
switch (contextBinding.getKind()) {
case IBinding.METHOD:
IMethodBinding methodBinding= (IMethodBinding) contextBinding;
contextBinding= methodBinding.getDeclaringMember();
if (contextBinding == null) {
contextBinding= methodBinding.getDeclaringClass();
}
break;
case IBinding.VARIABLE:
IVariableBinding variableBinding= (IVariableBinding) contextBinding;
contextBinding= variableBinding.getDeclaringMethod();
if (contextBinding == null) {
contextBinding= variableBinding.getDeclaringClass();
}
break;
case IBinding.TYPE:
ITypeBinding currentClass= (ITypeBinding) contextBinding;
contextBinding= currentClass.getDeclaringMember();
if (contextBinding == null) {
contextBinding= currentClass.getDeclaringMethod();
if (contextBinding == null) {
contextBinding= currentClass.getDeclaringClass();
if (contextBinding == null) {
contextBinding= currentClass.getPackage();
}
}
}
break;
default:
contextBinding= null;
break;
}
}
}
return null;
}