Example usage for org.eclipse.jdt.core.dom IMethodBinding isEqualTo

List of usage examples for org.eclipse.jdt.core.dom IMethodBinding isEqualTo

Introduction

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

Prototype

public boolean isEqualTo(IBinding binding);

Source Link

Document

Returns whether this binding has the same key as that of the given binding.

Usage

From source file:com.google.devtools.j2cpp.translate.JavaToIOSMethodTranslator.java

License:Open Source License

@Override
public boolean visit(MethodDeclaration node) {
    if (node.getBody() != null) {
        visit(node.getBody());//  w  w  w. j a  va2s  . co m
    }
    IMethodBinding binding = Types.getMethodBinding(node);
    for (IMethodBinding overridable : overridableMethods) {
        if (!binding.isConstructor() && (binding.isEqualTo(overridable) || binding.overrides(overridable))) {
            JavaMethod md = getDescription(overridable);
            String key = md.getKey();
            String value = methodMappings.get(key);
            if (value != null) {
                IOSMethod iosMethod = new IOSMethod(value, binding, ast);
                node.setName(ast.newSimpleName(iosMethod.getName()));
                Types.addBinding(node.getName(), iosMethod.resolveBinding());
                Types.addMappedIOSMethod(binding, iosMethod);

                // Map parameters, if any.
                @SuppressWarnings("unchecked")
                List<SingleVariableDeclaration> parameters = node.parameters();
                int n = parameters.size();
                if (n > 0) {
                    List<IOSParameter> iosArgs = iosMethod.getParameters();
                    assert n == iosArgs.size() || iosMethod.isVarArgs();

                    // Pull parameters out of list, so they can be reordered.
                    SingleVariableDeclaration[] params = parameters.toArray(new SingleVariableDeclaration[n]);

                    for (int i = 0; i < n; i++) {
                        SingleVariableDeclaration var = params[i];
                        IVariableBinding varBinding = Types.getVariableBinding(var);
                        IOSParameter iosArg = iosArgs.get(i);
                        SimpleType paramType = ast
                                .newSimpleType(NameTable.unsafeSimpleName(iosArg.getType(), ast));
                        Types.addBinding(paramType, varBinding);
                        Types.addBinding(paramType.getName(), varBinding);
                        var.setType(paramType);
                        Types.addBinding(var.getName(), varBinding);
                        parameters.set(iosArg.getIndex(), var);
                    }
                }

                Types.addMappedIOSMethod(binding, iosMethod);
            }
            return false;
        }
    }
    return false;
}

From source file:com.google.devtools.j2objc.gen.MetadataGenerator.java

License:Apache License

/**
 * Prints enclosing method metadata, returns struct's name.
 *//*from ww w.j  a v a2  s.c o  m*/
private String printEnclosingMethodMetadata() {
    IMethodBinding enclosingMethod = type.getDeclaringMethod();
    if (enclosingMethod == null) {
        return null;
    }

    // Method isn't enclosing if this type is defined in a type also enclosed
    // by this method.
    if (enclosingMethod.isEqualTo(type.getDeclaringClass().getDeclaringMethod())) {
        return null;
    }

    String structName = "enclosing_method";
    printf("  static const J2ObjCEnclosingMethodInfo %s = { ", structName);
    printf("\"%s\", ", nameTable.getFullName(enclosingMethod.getDeclaringClass()));
    printf("\"%s\" };\n", nameTable.getMethodSelector(enclosingMethod));
    return structName;
}