本文整理匯總了Java中org.eclipse.jdt.core.dom.IMethodBinding.getDeclaringClass方法的典型用法代碼示例。如果您正苦於以下問題:Java IMethodBinding.getDeclaringClass方法的具體用法?Java IMethodBinding.getDeclaringClass怎麽用?Java IMethodBinding.getDeclaringClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.core.dom.IMethodBinding
的用法示例。
在下文中一共展示了IMethodBinding.getDeclaringClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: visit
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
@Override
public boolean visit(MethodDeclaration node) {
if (isDeclarationTarget(DeclarationType.METHOD_DECLARATION)) {
IMethodBinding methodBinding = node.resolveBinding();
if (methodBinding != null) {
ITypeBinding declaringClass = methodBinding.getDeclaringClass();
typeDeclarationFound = declaringClass != null ? declaringClass
.getQualifiedName() : "";
methodParamasFound = methodBinding.getParameterTypes();
methodNameFound = methodBinding.getName();
if (matchTypeDeclaration()
&& TraceUtility
.match(methodNameToFind, methodNameFound)
&& TraceUtility.matchMethodParams(methodParamsToFind,
methodParamasFound)) {
TraceUtility.selectInEditor(node);
setEnclosingDeclaration(node);
}
}
}
return super.visit(node);
}
示例2: extractDataFromMethodBinding
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
/**
* Extracts the fully qualified name and parameters from a method binding
* and applies them to the name in a SourceCodeEntity.
* @param binding The method binding.
* @param sce SourceCodeEntity to which to apply changes. Name must be set
* to the entity's unqualified name.
*/
private void extractDataFromMethodBinding(IMethodBinding binding,
SourceCodeEntity sce) {
if (binding != null) {
//Get package and type name within which this method is declared.
ITypeBinding type = binding.getDeclaringClass();
if (type != null)
sce.name = type.getQualifiedName() + "." + sce.name;
else
sce.name = "?." + sce.name;
//Get method parameter types
String params = "";
for (ITypeBinding paramType : binding.getParameterTypes()) {
if (paramType != null)
params += paramType.getQualifiedName() + ",";
}
if (params.length() > 0) {
sce.name += "("
+ params.substring(0, params.length() - 1)
+ ")";
} else
sce.name += "()";
} else {
//If binding fails, mark the qualification as "?" to show it could
//not be determined.
sce.name = "?." + sce.name + "(?)";
}
}
示例3: extractDataFromVariableBinding
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
/**
* Extracts the fully qualified name from a variable binding and applies
* them to the name in a SourceCodeEntity.
* @param binding The variable binding.
* @param sce SourceCodeEntity to which to apply changes. Name must be set
* to the entity's unqualified name.
*/
private static void extractDataFromVariableBinding(
IVariableBinding binding, SourceCodeEntity sce) {
if (binding != null) {
//Type member variable.
ITypeBinding type = binding.getDeclaringClass();
if (type != null)
sce.name = type.getQualifiedName() + "." + sce.name;
//Variable declared in method.
else {
IMethodBinding method = binding.getDeclaringMethod();
if (method != null) {
type = method.getDeclaringClass();
if (type != null) {
sce.name = type.getQualifiedName() + "."
+ method.getName() + "." + sce.name;
} else
sce.name = "?." + method.getName() + "." + sce.name;
} else
sce.name = "?." + sce.name;
}
} else {
//If binding fails, mark the qualification as "?" to show it could
//not be determined.
sce.name = "?." + sce.name;
}
}
示例4: handleMethodBinding
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
private void handleMethodBinding(ASTNode node, IMethodBinding methodBinding) {
if (methodBinding == null) {
StructuralPropertyDescriptor locationInParent = node.getLocationInParent();
//System.out.println(locationInParent.getId() + " has no method binding");
} else {
ITypeBinding declaringClass = methodBinding.getDeclaringClass();
if (declaringClass != null && !this.ignoreType(declaringClass)) {
this.onMethodAccess(node, methodBinding);
}
}
}
示例5: isVisibleInHierarchy
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
public static boolean isVisibleInHierarchy(IMethodBinding member, IPackageBinding pack) {
int otherflags= member.getModifiers();
ITypeBinding declaringType= member.getDeclaringClass();
if (Modifier.isPublic(otherflags) || Modifier.isProtected(otherflags) || (declaringType != null && declaringType.isInterface())) {
return true;
} else if (Modifier.isPrivate(otherflags)) {
return false;
}
return declaringType != null && pack == declaringType.getPackage();
}
示例6: findNullnessDefault
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的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;
}
示例7: getInvocationType
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
/**
* Returns the binding of the type which declares the method being invoked.
*
* @param invocationNode the method invocation node
* @param methodBinding binding of the method being invoked
* @param invocationQualifier the qualifier used for method invocation, or <code>null</code> if
* none
* @return the binding of the type which declares the method being invoked, or <code>null</code>
* if the type cannot be resolved
*/
public static ITypeBinding getInvocationType(ASTNode invocationNode, IMethodBinding methodBinding, Expression invocationQualifier) {
ITypeBinding invocationType;
if (invocationNode instanceof MethodInvocation || invocationNode instanceof SuperMethodInvocation) {
if (invocationQualifier != null) {
invocationType= invocationQualifier.resolveTypeBinding();
if (invocationType != null && invocationNode instanceof SuperMethodInvocation) {
invocationType= invocationType.getSuperclass();
}
} else {
ITypeBinding enclosingType= getEnclosingType(invocationNode);
if (enclosingType != null && invocationNode instanceof SuperMethodInvocation) {
enclosingType= enclosingType.getSuperclass();
}
if (enclosingType != null) {
IMethodBinding methodInHierarchy= Bindings.findMethodInHierarchy(enclosingType, methodBinding.getName(), methodBinding.getParameterTypes());
if (methodInHierarchy != null) {
invocationType= enclosingType;
} else {
invocationType= methodBinding.getDeclaringClass();
}
} else {
// not expected
invocationType= methodBinding.getDeclaringClass();
}
}
} else {
invocationType= methodBinding.getDeclaringClass();
}
return invocationType;
}
示例8: checkMethodInHierarchy
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
/**
* Checks if the new method somehow conflicts with an already existing
* method in the hierarchy. The following checks are done:
* <ul>
* <li>if the new method overrides a method defined in the given type or in
* one of its super classes.</li>
* </ul>
*
* @param type
* @param methodName
* @param returnType
* @param parameters
* @return the status
*/
public static RefactoringStatus checkMethodInHierarchy(ITypeBinding type, String methodName, ITypeBinding returnType, ITypeBinding[] parameters) {
RefactoringStatus result = new RefactoringStatus();
IMethodBinding method = Bindings.findMethodInHierarchy(type, methodName, parameters);
if (method != null) {
boolean returnTypeClash = false;
ITypeBinding methodReturnType = method.getReturnType();
if (returnType != null && methodReturnType != null) {
String returnTypeKey = returnType.getKey();
String methodReturnTypeKey = methodReturnType.getKey();
if (returnTypeKey == null && methodReturnTypeKey == null) {
returnTypeClash = returnType != methodReturnType;
} else if (returnTypeKey != null && methodReturnTypeKey != null) {
returnTypeClash = !returnTypeKey.equals(methodReturnTypeKey);
}
}
ITypeBinding dc = method.getDeclaringClass();
if (returnTypeClash) {
result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_returnTypeClash, new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName()) }),
JavaStatusContext.create(method));
} else {
if (method.isConstructor()) {
result.addWarning(Messages.format(RefactoringCoreMessages.Checks_methodName_constructor, new Object[] { BasicElementLabels.getJavaElementName(dc.getName()) }));
} else {
result.addError(Messages.format(RefactoringCoreMessages.Checks_methodName_overrides, new Object[] { BasicElementLabels.getJavaElementName(methodName), BasicElementLabels.getJavaElementName(dc.getName()) }),
JavaStatusContext.create(method));
}
}
}
return result;
}
示例9: addQualifierToOuterProposal
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
private static void addQualifierToOuterProposal(IInvocationContext context, MethodInvocation invocationNode,
IMethodBinding binding, Collection<CUCorrectionProposal> proposals) {
ITypeBinding declaringType= binding.getDeclaringClass();
ITypeBinding parentType= Bindings.getBindingOfParentType(invocationNode);
ITypeBinding currType= parentType;
boolean isInstanceMethod= !Modifier.isStatic(binding.getModifiers());
while (currType != null && !Bindings.isSuperType(declaringType, currType)) {
if (isInstanceMethod && Modifier.isStatic(currType.getModifiers())) {
return;
}
currType= currType.getDeclaringClass();
}
if (currType == null || currType == parentType) {
return;
}
ASTRewrite rewrite= ASTRewrite.create(invocationNode.getAST());
String label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changetoouter_description,
ASTResolving.getTypeSignature(currType));
ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(),
rewrite, IProposalRelevance.QUALIFY_WITH_ENCLOSING_TYPE);
ImportRewrite imports= proposal.createImportRewrite(context.getASTRoot());
ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(invocationNode, imports);
AST ast= invocationNode.getAST();
String qualifier= imports.addImport(currType, importRewriteContext);
Name name= ASTNodeFactory.newName(ast, qualifier);
Expression newExpression;
if (isInstanceMethod) {
ThisExpression expr= ast.newThisExpression();
expr.setQualifier(name);
newExpression= expr;
} else {
newExpression= name;
}
rewrite.set(invocationNode, MethodInvocation.EXPRESSION_PROPERTY, newExpression, null);
proposals.add(proposal);
}
示例10: getEnclosingTypeVar
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
private Type getEnclosingTypeVar(IMethodBinding typeBindingVar) {
Type declaringType = null;
if (typeBindingVar != null) {
enclosingTypeVar = typeBindingVar.getDeclaringClass();
if (enclosingTypeVar != null) {
declaringType = typeInfo.getType(enclosingTypeVar.getQualifiedName());
}
}
return declaringType;
}
示例11: getVariableEnclosingClass
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
public String getVariableEnclosingClass(IVariableBinding varBinding) {
String type = "";
IMethodBinding declaringMethod = varBinding.getDeclaringMethod();
if (declaringMethod != null) {
ITypeBinding declaringClass = declaringMethod.getDeclaringClass();
if (declaringClass != null) {
type = declaringClass.getQualifiedName();
}
}
return type;
}
示例12: isMainMethod
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的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);
}
示例13: compare
import org.eclipse.jdt.core.dom.IMethodBinding; //導入方法依賴的package包/類
@Override
public int compare(IMethodBinding firstMethodBinding, IMethodBinding secondMethodBinding) {
if (firstMethodBinding == null || secondMethodBinding == null) {
return 0;
}
ITypeBinding firstMethodType= firstMethodBinding.getDeclaringClass();
ITypeBinding secondMethodType= secondMethodBinding.getDeclaringClass();
if (firstMethodType.equals(secondMethodType)) {
return compareInTheSameType(firstMethodBinding, secondMethodBinding);
}
if (firstMethodType.equals(fTypeBinding)) {
return 1;
}
if (secondMethodType.equals(fTypeBinding)) {
return -1;
}
ITypeBinding type= fTypeBinding;
int count= 0, firstCount= -1, secondCount= -1;
while ((type= type.getSuperclass()) != null) {
if (firstMethodType.equals(type)) {
firstCount= count;
}
if (secondMethodType.equals(type)) {
secondCount= count;
}
count++;
}
if (firstCount != -1 && secondCount != -1) {
return (firstCount - secondCount);
}
if (firstCount != -1 && secondCount == -1) {
return 1;
}
if (firstCount == -1 && secondCount != -1) {
return -1;
}
ITypeBinding[] interfaces= fTypeBinding.getInterfaces();
for (int i= 0; i < interfaces.length; i++) {
if (firstMethodType.equals(interfaces[i])) {
return 1;
}
if (secondMethodType.equals(interfaces[i])) {
return -1;
}
}
return 0;
}
示例14: 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;
}
示例15: 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);
}
}
}