本文整理汇总了Java中org.eclipse.jdt.core.dom.MethodDeclaration.resolveBinding方法的典型用法代码示例。如果您正苦于以下问题:Java MethodDeclaration.resolveBinding方法的具体用法?Java MethodDeclaration.resolveBinding怎么用?Java MethodDeclaration.resolveBinding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.MethodDeclaration
的用法示例。
在下文中一共展示了MethodDeclaration.resolveBinding方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInterfaceMethodModifiers
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
private int getInterfaceMethodModifiers(ASTNode targetTypeDecl, boolean createAbstractMethod) {
// for interface and annotation members copy the modifiers from an existing member
if (targetTypeDecl instanceof TypeDeclaration) {
TypeDeclaration type= (TypeDeclaration) targetTypeDecl;
MethodDeclaration[] methodDecls= type.getMethods();
if (methodDecls.length > 0) {
if (createAbstractMethod) {
for (MethodDeclaration methodDeclaration : methodDecls) {
IMethodBinding methodBinding= methodDeclaration.resolveBinding();
if (methodBinding != null && JdtFlags.isAbstract(methodBinding)) {
return methodDeclaration.getModifiers();
}
}
}
return methodDecls[0].getModifiers() & Modifier.PUBLIC;
}
List<BodyDeclaration> bodyDecls= type.bodyDeclarations();
if (bodyDecls.size() > 0) {
return bodyDecls.get(0).getModifiers() & Modifier.PUBLIC;
}
}
return 0;
}
示例2: getMethodParameters
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
/**
* returns the method Parameters as a list of ast.VariableDeclarataion
* */
public static List<ast.VariableDeclaration> getMethodParameters(MethodDeclaration md) {
List<ast.VariableDeclaration> params = new ArrayList<ast.VariableDeclaration>();
IMethodBinding methodBinding = md.resolveBinding();
if(methodBinding != null ) {
ITypeBinding[] typeParameters = methodBinding.getTypeParameters();
List<SingleVariableDeclaration> svdList = md.parameters();
for (SingleVariableDeclaration svd : svdList) {
ast.Type type = getType(svd.getType().resolveBinding());
ast.VariableDeclaration vd = VariableDeclaration.createFrom(svd);
vd.varType = type;
vd.varName = svd.getName().getFullyQualifiedName();
params.add(vd);
}
}
return params;
}
示例3: visit
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的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);
}
示例4: visit
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
@Override
public boolean visit(MethodDeclaration methodDeclaration) {
IBinding binding = methodDeclaration.resolveBinding();
if (binding == null)
return false;
currentMethod = (IMethod) binding.getJavaElement();
if (currentMethod != null) {
methodDetails = new MethodDetails();
String handleIdentifier = currentMethod.getHandleIdentifier();
allDetails.put(handleIdentifier, methodDetails);
methodDetails.setModifiers(methodDeclaration.getModifiers());
methodDetails.setParameters(getParameters(methodDeclaration.parameters()));
Type returnType2 = methodDeclaration.getReturnType2();
if (returnType2 != null) {
ITypeBinding typeBinding = returnType2.resolveBinding();
IJavaElement returnType = typeBinding.getJavaElement();
if (returnType instanceof IType) {
methodDetails.setReturnType((IType) returnType);
}
}
}
return true;
}
示例5: 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);
}
示例6: findEnclosingMethodBinding
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
/**
*
* @param node: ASTNode corresponding to the TAC instruction that is being analyzed
* @return The method binding of the enclosing method of the TAC instruction that is being analyzed
*/
public static IMethodBinding findEnclosingMethodBinding(ASTNode node) {
while(!(node instanceof MethodDeclaration)){
if(node instanceof FieldDeclaration){
return null;
}
node=node.getParent();
}
MethodDeclaration enclosingMethod = (MethodDeclaration)node;
IMethodBinding enclosingMethodBinding = enclosingMethod.resolveBinding();
return enclosingMethodBinding;
}
示例7: addIncompatibleReturnTypeProposals
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的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);
}
}
}
示例8: transfer
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
@Override
public OOGContext transfer(edu.cmu.cs.crystal.tac.model.ReturnInstruction instr, OOGContext value) {
super.transfer(instr, value);
ASTNode node = instr.getNode();
String enclosingClassName = findEnclosingClassName(node);
//Finding the enclosing method this instruction
node = instr.getNode();
while(!(node instanceof MethodDeclaration)){
node=node.getParent();
}
MethodDeclaration methDecl = (MethodDeclaration)node;
// Finding returned variable
Variable returnedVariable = instr.getReturnedVariable();
Set<OType> returnedVariableTypeMapping = this.tm.getTypeMapping(returnedVariable);
if(returnedVariableTypeMapping==null){
boolean isMainClass = enclosingClassName.equals(Config.MAINCLASS);
returnedVariableTypeMapping = this.tm.initTypeMapping(isMainClass,returnedVariable);
this.tm.putTypeMapping(returnedVariable, returnedVariableTypeMapping);
}
//Finding AU of the method that returns the returned variable
IMethodBinding methodBinding = methDecl.resolveBinding();
Variable methodVar = null;
if(!methodBinding.getReturnType().isPrimitive()){
methodVar = this.tm.getVarBindingMap(methodBinding);
}
Set<OType> methodTypeMapping = null;
if(methodVar!=null){
methodTypeMapping = this.tm.getTypeMapping(methodVar);
}
if(methodTypeMapping!=null && returnedVariableTypeMapping!=null){
// Do the intersection between set of typings of methodAU and returned variable
returnedVariableTypeMapping.retainAll(methodTypeMapping);
methodTypeMapping.retainAll(returnedVariableTypeMapping);
this.tm.putTypeMapping(returnedVariable, returnedVariableTypeMapping);
this.tm.putTypeMapping(methodVar, methodTypeMapping);
if(returnedVariableTypeMapping.size()==0 || methodTypeMapping.size()==0){
emptySetAction(instr, "Adaptation failed for the method return: ");
return value;
}
}
return value;
}
示例9: transfer
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
@Override
public OOGContext transfer(edu.cmu.cs.crystal.tac.model.ReturnInstruction instr, OOGContext value) {
super.transfer(instr, value);
//Set of variables of the instruction in case of a conflict
Set<Variable> varSet = new HashSet<Variable>();
// Skip over the ones you do not to re-analyze...
if(skipExprs.contains(instr)) {
return super.transfer(instr, value);
}
boolean isPossible = true;
ASTNode node = instr.getNode();
String enclosingClassName = Utils.findEnclosingClassName(node);
//Finding the enclosing method this instruction
node = instr.getNode();
while(!(node instanceof MethodDeclaration)){
node=node.getParent();
}
MethodDeclaration methDecl = (MethodDeclaration)node;
// Finding returned variable
Variable returnedVariable = instr.getReturnedVariable();
varSet.add(returnedVariable);
ITypeBinding returnVariableType = returnedVariable.resolveType();
Set<OType> returnedVariableTypeMapping = null;
if(returnVariableType.isPrimitive() || returnVariableType.isNullType()){
isPossible = false;
}
else{
returnedVariableTypeMapping = this.tm.getTypeMapping(returnedVariable);
if(returnedVariableTypeMapping==null){
boolean isMainClass = enclosingClassName.equals(Config.MAINCLASS);
returnedVariableTypeMapping = this.tm.initTypeMapping(isMainClass,returnedVariable, false, true);
this.tm.putTypeMapping(returnedVariable, returnedVariableTypeMapping);
}
}
//Finding AU of the method that returns the returned variable
IMethodBinding methodBinding = methDecl.resolveBinding();
Variable methodVar = null;
if(!methodBinding.getReturnType().isPrimitive()){
methodVar = this.tm.getVarBindingMap(methodBinding);
}
Set<OType> methodTypeMapping = null;
if(methodVar!=null){
varSet.add(methodVar);
methodTypeMapping = this.tm.getTypeMapping(methodVar);
}
if(methodTypeMapping!=null && returnedVariableTypeMapping!=null && isPossible){
// Do the intersection between set of typings of methodAU and returned variable
returnedVariableTypeMapping.retainAll(methodTypeMapping);
methodTypeMapping.retainAll(returnedVariableTypeMapping);
this.tm.putTypeMapping(returnedVariable, returnedVariableTypeMapping);
this.tm.putTypeMapping(methodVar, methodTypeMapping);
updateOverriddenMethodMapping(methodBinding,methodTypeMapping,value);
if(returnedVariableTypeMapping.size()==0 || methodTypeMapping.size()==0){
emptySetAction(instr, "Adaptation failed for the method return: ",varSet);
return value;
}
}
return value;
}
示例10: isOverridden
import org.eclipse.jdt.core.dom.MethodDeclaration; //导入方法依赖的package包/类
protected boolean isOverridden(MethodDeclaration node) {
final IMethodBinding methodBinding = node.resolveBinding();
final ITypeBinding declaringClass = methodBinding.getDeclaringClass();
return isDefinedInTypeOrSuperType(methodBinding, declaringClass);
}