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

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

Introduction

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

Prototype

public boolean isSubsignature(IMethodBinding otherMethod);

Source Link

Document

Returns whether this method's signature is a subsignature of the given method as specified in section 8.4.2 of The Java Language Specification, Third Edition (JLS3).

Usage

From source file:cideplus.ui.astview.TrayContentProvider.java

License:Open Source License

private void addMethodBindingComparions(ArrayList result, Binding trayElement) {
    class OverridesProperty extends DynamicBindingProperty {
        public OverridesProperty(Binding parent) {
            super(parent);
        }// ww  w. j av a2s  .c  om

        protected String getName() {
            return "*.overrides(this): "; //$NON-NLS-1$
        }

        protected String executeQuery(IBinding viewerBinding, IBinding trayBinding) {
            if (viewerBinding instanceof IMethodBinding) {
                IMethodBinding viewerMB = (IMethodBinding) viewerBinding;
                IMethodBinding trayMB = (IMethodBinding) trayBinding;
                return Boolean.toString(viewerMB.overrides(trayMB));
            } else {
                return "* not an IMethodBinding"; //$NON-NLS-1$
            }
        }
    }
    result.add(new OverridesProperty(trayElement));

    class IsSubsignatureProperty extends DynamicBindingProperty {
        public IsSubsignatureProperty(Binding parent) {
            super(parent);
        }

        protected String getName() {
            return "*.isSubsignature(this): "; //$NON-NLS-1$
        }

        protected String executeQuery(IBinding viewerBinding, IBinding trayBinding) {
            if (viewerBinding instanceof IMethodBinding) {
                IMethodBinding viewerMB = (IMethodBinding) viewerBinding;
                IMethodBinding trayMB = (IMethodBinding) trayBinding;
                return Boolean.toString(viewerMB.isSubsignature(trayMB));
            } else {
                return "* not an IMethodBinding"; //$NON-NLS-1$
            }
        }
    }
    result.add(new IsSubsignatureProperty(trayElement));
}

From source file:com.codenvy.ide.ext.java.server.JavadocFinder.java

License:Open Source License

private static IBinding resolveSuperclassConstructor(ITypeBinding superClassDeclaration,
        IMethodBinding constructor) {
    IMethodBinding[] methods = superClassDeclaration.getDeclaredMethods();
    for (int i = 0; i < methods.length; i++) {
        IMethodBinding method = methods[i];
        if (method.isConstructor() && constructor.isSubsignature(method))
            return method;
    }/*  ww  w .  java 2s . com*/
    return null;
}

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

License:Open Source License

/**
 * Determines whether one method is a subsignature of another, as defined by JLS3,
 * section 8.4.2.//  www  .  j  ava2s.  c  om
 */
private boolean isSubsignature(IMethodBinding submethod, IMethodBinding supermethod) {
    if (submethod.isSubsignature(supermethod)) {
        return true;
    }
    // IMethodBinding#isSubsignature doesn't seem to be checking subsignatures
    // correctly when comparing two non-generic methods belonging to different
    // generic classes with the same type arguments, so I'm checking this case
    // manually.
    // http://docs.oracle.com/javase/specs/jls/se5.0/html/classes.html#38649
    if (!submethod.getName().equals(supermethod.getName())
            || submethod.getParameterTypes().length != supermethod.getParameterTypes().length
            || submethod.getTypeParameters().length != supermethod.getTypeParameters().length) {
        return false;
    }
    for (int i = 0; i < submethod.getParameterTypes().length; i++) {
        if (!submethod.getParameterTypes()[i].isEqualTo(supermethod.getParameterTypes()[i])) {
            return false;
        }
    }
    for (int i = 0; i < submethod.getTypeParameters().length; i++) {
        if (!submethod.getTypeParameters()[i].isEqualTo(supermethod.getParameterTypes()[i])) {
            return false;
        }
    }
    return true;
}

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

License:Open Source License

@Override
public boolean visit(MethodInvocation node) {
    // translate any embedded method invocations
    if (node.getExpression() != null) {
        node.getExpression().accept(this);
    }/*  www .ja v  a 2 s .  c o  m*/
    @SuppressWarnings("unchecked")
    List<Expression> args = node.arguments(); // safe by definition
    for (Expression e : args) {
        e.accept(this);
    }

    IMethodBinding binding = Types.getMethodBinding(node);
    JavaMethod md = descriptions.get(binding);
    if (md == null && !binding.getName().equals("clone")) { // never map clone()
        IVariableBinding receiver = node.getExpression() != null
                ? Types.getVariableBinding(node.getExpression())
                : null;
        ITypeBinding clazz = receiver != null ? receiver.getType() : binding.getDeclaringClass();
        if (clazz != null && !clazz.isArray()) {
            for (IMethodBinding method : descriptions.keySet()) {
                if (binding.isSubsignature(method)
                        && clazz.isAssignmentCompatible(method.getDeclaringClass())) {
                    md = descriptions.get(method);
                    break;
                }
            }
        }
    }
    if (md != null) {
        String key = md.getKey();
        String value = methodMappings.get(key);
        if (value == null) {
            J2ObjC.error(node, createMissingMethodMessage(binding));
            return true;
        }
        IOSMethod iosMethod = new IOSMethod(value, binding, ast);
        NameTable.rename(binding, iosMethod.getName());
        if (node.getExpression() instanceof SimpleName) {
            SimpleName expr = (SimpleName) node.getExpression();
            if (expr.getIdentifier().equals(binding.getDeclaringClass().getName())
                    || expr.getIdentifier().equals(binding.getDeclaringClass().getQualifiedName())) {
                NameTable.rename(binding.getDeclaringClass(), iosMethod.getDeclaringClass());
            }
        }
        Types.addMappedIOSMethod(binding, iosMethod);
        Types.addMappedInvocation(node, iosMethod.resolveBinding());
    } else {
        // Not mapped, check if it overrides a mapped method.
        for (IMethodBinding methodBinding : mappedMethods) {
            if (binding.overrides(methodBinding)) {
                JavaMethod desc = getDescription(methodBinding);
                String value = methodMappings.get(desc.getKey());
                if (value != null) {
                    IOSMethod iosMethod = new IOSMethod(value, binding, ast);
                    NameTable.rename(methodBinding, iosMethod.getName());
                    Types.addMappedIOSMethod(binding, iosMethod);
                    Types.addMappedInvocation(node, iosMethod.resolveBinding());
                    break;
                }
            }
        }
    }
    return false;
}

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

License:Open Source License

private boolean isMethodImplemented(ITypeBinding type, IMethodBinding method) {
    if (type == null || type.getQualifiedName().equals("java.lang.Object")) {
        return false;
    }//from  w  w  w.j a  v  a  2 s.  co m

    for (IMethodBinding m : type.getDeclaredMethods()) {
        if (method.isSubsignature(m) || (method.getName().equals(m.getName())
                && method.getReturnType().getErasure().isEqualTo(m.getReturnType().getErasure())
                && Arrays.equals(method.getParameterTypes(), m.getParameterTypes()))) {
            return true;
        }
    }

    return isMethodImplemented(type.getSuperclass(), method);
}

From source file:com.google.devtools.j2objc.jdt.JdtTypes.java

License:Apache License

static TypeMirror asMemberOfInternal(DeclaredType containing, Element element) {
    ITypeBinding c = BindingConverter.unwrapTypeMirrorIntoTypeBinding(containing);
    if (ElementUtil.isExecutableElement(element)) {
        IMethodBinding e = BindingConverter.unwrapExecutableElement((ExecutableElement) element);
        for (IMethodBinding m : c.getDeclaredMethods()) {
            if (m.isSubsignature(e)) {
                return BindingConverter.getType(m);
            }/*from  www  .java 2  s  .co  m*/
        }
    } else if (ElementUtil.isVariable(element)) {
        IVariableBinding declaredVar = BindingConverter.unwrapVariableElement((VariableElement) element);
        for (IVariableBinding var : c.getDeclaredFields()) {
            if (var.getVariableDeclaration().isEqualTo(declaredVar)) {
                return BindingConverter.getType(var.getType());
            }
        }
    }
    throw new IllegalArgumentException("Element: " + element + " is not a member of " + containing);
}

From source file:com.google.devtools.j2objc.jdt.TreeConverter.java

License:Apache License

private static IMethodBinding findSuperConstructor(IMethodBinding constructor) {
    ITypeBinding superClass = constructor.getDeclaringClass().getSuperclass();
    for (IMethodBinding m : superClass.getDeclaredMethods()) {
        if (m.isConstructor() && constructor.isSubsignature(m)) {
            return m;
        }//from  ww  w. j  a va2  s  .c  o m
    }
    throw new AssertionError("could not find constructor");
}

From source file:com.google.devtools.j2objc.translate.AbstractMethodRewriter.java

License:Apache License

private boolean isMethodImplemented(ITypeBinding type, IMethodBinding method) {
    if (type == null) {
        return false;
    }/* w ww  .j a  v a 2  s .  c  o  m*/

    for (IMethodBinding m : type.getDeclaredMethods()) {
        if (method.isSubsignature(m) || (method.getName().equals(m.getName())
                && method.getReturnType().getErasure().isEqualTo(m.getReturnType().getErasure())
                && Arrays.equals(method.getParameterTypes(), m.getParameterTypes()))) {
            return true;
        }
    }

    return isMethodImplemented(type.getSuperclass(), method);
}

From source file:com.google.devtools.j2objc.translate.AnonymousClassConverter.java

License:Open Source License

private IMethodBinding findSuperConstructorBinding(IMethodBinding constructorBinding) {
    ITypeBinding superClass = constructorBinding.getDeclaringClass().getSuperclass();
    for (IMethodBinding m : superClass.getDeclaredMethods()) {
        if (m.isConstructor() && constructorBinding.isSubsignature(m)) {
            return m;
        }/*ww  w.j  av  a 2  s.  c  om*/
    }
    throw new AssertionError("could not find constructor");
}

From source file:de.ovgu.cide.typing.jdt.checks.util.CheckUtils.java

License:Open Source License

public static void collectSimilarMethodKeysInSuperClasses(IMethodBinding implMethodBinding,
        ITypeBinding superClassBinding, List<MethodPathItem> methods, Set<String> checkedInterfaces) {

    if (implMethodBinding == null || superClassBinding == null || methods == null)
        return;/*from   ww  w  .  j  ava2 s  .  c o  m*/

    IMethodBinding[] methodBindings = superClassBinding.getDeclaredMethods();

    // check all methods of current class
    for (int j = 0; j < methodBindings.length; j++) {
        IMethodBinding tmpMethodBinding = methodBindings[j];

        // add method if current method is a sub signature of the implemented
        // method
        if (!tmpMethodBinding.isSubsignature(implMethodBinding))
            continue;

        // add the method binding
        methods.add(
                new MethodPathItem(tmpMethodBinding, Modifier.isAbstract(superClassBinding.getModifiers())));

    }

    // in addition to this (recursively) check the super class of the
    // current class
    collectSimilarMethodKeysInSuperClasses(implMethodBinding, superClassBinding.getSuperclass(), methods,
            checkedInterfaces);

    // in addition to this (recursively) check all interfaces of the current
    // class
    collectSimilarMethodKeysInInterfaces(implMethodBinding, superClassBinding.getInterfaces(), methods,
            checkedInterfaces);

}