Example usage for org.eclipse.jdt.core.dom SuperMethodInvocation resolveMethodBinding

List of usage examples for org.eclipse.jdt.core.dom SuperMethodInvocation resolveMethodBinding

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom SuperMethodInvocation resolveMethodBinding.

Prototype

public IMethodBinding resolveMethodBinding() 

Source Link

Document

Resolves and returns the binding for the method invoked by this expression.

Usage

From source file:astview.ASTViewContentProvider.java

License:Open Source License

private Object[] getNodeChildren(ASTNode node) {
    ArrayList<Object> res = new ArrayList<>();

    if (node instanceof Expression) {
        Expression expression = (Expression) node;
        ITypeBinding expressionTypeBinding = expression.resolveTypeBinding();
        res.add(createExpressionTypeBinding(node, expressionTypeBinding));

        // expressions:
        if (expression instanceof Name) {
            IBinding binding = ((Name) expression).resolveBinding();
            if (binding != expressionTypeBinding)
                res.add(createBinding(expression, binding));
        } else if (expression instanceof MethodInvocation) {
            MethodInvocation methodInvocation = (MethodInvocation) expression;
            IMethodBinding binding = methodInvocation.resolveMethodBinding();
            res.add(createBinding(expression, binding));
            String inferred = String.valueOf(methodInvocation.isResolvedTypeInferredFromExpectedType());
            res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$
        } else if (expression instanceof SuperMethodInvocation) {
            SuperMethodInvocation superMethodInvocation = (SuperMethodInvocation) expression;
            IMethodBinding binding = superMethodInvocation.resolveMethodBinding();
            res.add(createBinding(expression, binding));
            String inferred = String.valueOf(superMethodInvocation.isResolvedTypeInferredFromExpectedType());
            res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$
        } else if (expression instanceof ClassInstanceCreation) {
            ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
            IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
            res.add(createBinding(expression, binding));
            String inferred = String.valueOf(classInstanceCreation.isResolvedTypeInferredFromExpectedType());
            res.add(new GeneralAttribute(expression, "ResolvedTypeInferredFromExpectedType", inferred)); //$NON-NLS-1$
        } else if (expression instanceof FieldAccess) {
            IVariableBinding binding = ((FieldAccess) expression).resolveFieldBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof SuperFieldAccess) {
            IVariableBinding binding = ((SuperFieldAccess) expression).resolveFieldBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof Annotation) {
            IAnnotationBinding binding = ((Annotation) expression).resolveAnnotationBinding();
            res.add(createBinding(expression, binding));
        } else if (expression instanceof LambdaExpression) {
            ASTAttribute bindingAttribute;
            try {
                IMethodBinding binding = ((LambdaExpression) expression).resolveMethodBinding();
                bindingAttribute = createBinding(expression, binding);
            } catch (RuntimeException e) {
                bindingAttribute = new Error(res, ">binding: Error: " + e.getMessage(), e);
            }//from   w  w w  . j  av  a 2 s .co m
            res.add(bindingAttribute);
        } else if (expression instanceof MethodReference) {
            IMethodBinding binding = ((MethodReference) expression).resolveMethodBinding();
            res.add(createBinding(expression, binding));
        }
        // Expression attributes:
        res.add(new GeneralAttribute(expression,
                "Boxing: " + expression.resolveBoxing() + "; Unboxing: " + expression.resolveUnboxing())); //$NON-NLS-1$ //$NON-NLS-2$
        res.add(new GeneralAttribute(expression, "ConstantExpressionValue", //$NON-NLS-1$
                expression.resolveConstantExpressionValue()));

        // references:
    } else if (node instanceof ConstructorInvocation) {
        IMethodBinding binding = ((ConstructorInvocation) node).resolveConstructorBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof SuperConstructorInvocation) {
        IMethodBinding binding = ((SuperConstructorInvocation) node).resolveConstructorBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof MethodRef) {
        IBinding binding = ((MethodRef) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof MemberRef) {
        IBinding binding = ((MemberRef) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof Type) {
        IBinding binding = ((Type) node).resolveBinding();
        res.add(createBinding(node, binding));

        // declarations:
    } else if (node instanceof AbstractTypeDeclaration) {
        IBinding binding = ((AbstractTypeDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof AnnotationTypeMemberDeclaration) {
        IBinding binding = ((AnnotationTypeMemberDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof EnumConstantDeclaration) {
        IBinding binding = ((EnumConstantDeclaration) node).resolveVariable();
        res.add(createBinding(node, binding));
        IBinding binding2 = ((EnumConstantDeclaration) node).resolveConstructorBinding();
        res.add(createBinding(node, binding2));
    } else if (node instanceof MethodDeclaration) {
        IBinding binding = ((MethodDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof VariableDeclaration) {
        IBinding binding = ((VariableDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof AnonymousClassDeclaration) {
        IBinding binding = ((AnonymousClassDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof ImportDeclaration) {
        IBinding binding = ((ImportDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof PackageDeclaration) {
        IBinding binding = ((PackageDeclaration) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof TypeParameter) {
        IBinding binding = ((TypeParameter) node).resolveBinding();
        res.add(createBinding(node, binding));
    } else if (node instanceof MemberValuePair) {
        IBinding binding = ((MemberValuePair) node).resolveMemberValuePairBinding();
        res.add(createBinding(node, binding));
    }

    @SuppressWarnings("unchecked")
    List<StructuralPropertyDescriptor> list = node.structuralPropertiesForType();
    for (int i = 0; i < list.size(); i++) {
        StructuralPropertyDescriptor curr = list.get(i);
        res.add(new NodeProperty(node, curr));
    }

    return res.toArray();
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final SuperMethodInvocation pNode) {
    this.addCallRelation(pNode, pNode.resolveMethodBinding(), true);
    return true;//from  ww  w .jav  a2  s.  c  o  m
}

From source file:ca.uvic.chisel.javasketch.internal.ast.ASTMessageFinder.java

License:Open Source License

public boolean visit(SuperMethodInvocation node) {
    if (!(message instanceof ICall))
        return false;
    if (containsMessage(node)) {
        ICall call = (ICall) message;/*w  ww  .  ja  v  a 2 s.  c  o m*/

        IMethodBinding binding = node.resolveMethodBinding();
        if (binding != null) {
            binding = binding.getMethodDeclaration();
            if (binding != null) {
                IJavaElement element = binding.getJavaElement();
                if (element instanceof IMethod) {
                    try {
                        IMethod jm = (IMethod) element;
                        //get the target method.
                        ITraceClassMethod am = call.getTarget().getActivation().getMethod();
                        String types[] = Signature.getParameterTypes(am.getSignature());
                        IMethod testMethod = jm.getDeclaringType().getMethod(am.getName(), types);
                        if (jm.isSimilar(testMethod)) {
                            this.node = node;
                            try {
                                if (document.getLineOfOffset(node.getStartPosition()) != (call.codeLine() - 1))
                                    //look for a better match.
                                    return true;
                            } catch (BadLocationException e) {
                            }
                            return false;
                        }
                    } catch (NullPointerException e) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

    return false;
}

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

private static Name createSuperMethodInvName(ASTNode node) {
    StringBuilder sb = new StringBuilder();
    SuperMethodInvocation superInvocation = (SuperMethodInvocation) node;
    IMethodBinding superMethodInvBinding = superInvocation.resolveMethodBinding();
    sb.append(methodNameHelper(null, superMethodInvBinding, true));
    return CsMethodName.newMethodName(sb.toString());
}

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

/**
 * //  w w  w .  jav  a2s  .  c  om
 * @param method
 *            Expects a MethodDeclaration, MethodInvocation or a
 *            SuperMethodInvocation node.
 * @return Returns an array of all parameterNames.
 */
protected static String[] createParameterNames(ASTNode method) {
    if (method instanceof MethodDeclaration) {
        MethodDeclaration methodDecl = (MethodDeclaration) method;
        return createParameterNames(methodDecl, methodDecl.resolveBinding());
    } else if (method instanceof MethodInvocation) {
        MethodInvocation methodInv = (MethodInvocation) method;
        return createParameterNames(null, methodInv.resolveMethodBinding());
    } else if (method instanceof SuperMethodInvocation) {
        SuperMethodInvocation superMethodInv = (SuperMethodInvocation) method;
        return createParameterNames(null, superMethodInv.resolveMethodBinding());
    }
    return null;
}

From source file:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

public boolean visit(SuperMethodInvocation node) {
    IMethodBinding mmtb = node.resolveMethodBinding();
    if (this.mtbStack.isEmpty()) {
        return true;
    }//from   w ww. j av a  2s. com
    try {
        this.facts.add(Fact.makeCallsFact(getQualifiedName((IMethodBinding) this.mtbStack.peek()),
                getQualifiedName(mmtb)));
    } catch (Exception localException) {
        System.err.println("Cannot resolve method invocation \"" + node.getName().toString() + "\"");
    }
    return true;
}

From source file:com.architexa.diagrams.jdt.extractors.TypeRefExtractor.java

License:Open Source License

@Override
public boolean visit(SuperMethodInvocation invokedMethod) {
    addMethodRefs(invokedMethod.resolveMethodBinding());
    return true;
}

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.SuperMethodInvocation node) {
    IMethodBinding binding = node.resolveMethodBinding();
    Expression target = new SuperExpression(null);
    List<Expression> arguments = translateArguments(binding, node.arguments());
    SimpleIdentifier name = translateSimpleName(node.getName());
    return done(methodInvocation(target, name, arguments));
}

From source file:com.google.devtools.j2cpp.types.BindingMapBuilder.java

License:Open Source License

@Override
public boolean visit(SuperMethodInvocation node) {
    put(node, node.resolveMethodBinding());
    return true;
}

From source file:com.ibm.wala.cast.java.translator.jdt.JDTJava2CAstTranslator.java

License:Open Source License

private CAstNode visit(SuperMethodInvocation n, WalkContext context) {
    CAstNode target;//  w  ww.  j  a  v  a 2  s.  com
    if (n.getQualifier() == null)
        target = makeNode(context, fFactory, n, CAstNode.SUPER);
    else {
        TypeReference owningTypeRef = fIdentityMapper.getTypeRef(n.getQualifier().resolveTypeBinding());
        target = makeNode(context, fFactory, n, CAstNode.SUPER, fFactory.makeConstant(owningTypeRef));
    }
    // GENERICS getMethodDeclaration()
    return createMethodInvocation(n, n.resolveMethodBinding().getMethodDeclaration(), target, n.arguments(),
            context);
}