예제 #1
0
 /**
  * Returns true if {@code method}, is a method in {@code jsniClassQualifier} (to support current
  * private method access} or is a visible method in the super class per Java import rules.
  */
 private boolean isMethodVisibleToJsniRef(
     ReferenceBinding jsniClassQualifier, MethodBinding targetMethod) {
   return
   // All methods are visible (regardless of access) as long as the JSNI class reference is
   // explicit.
   jsniClassQualifier == targetMethod.declaringClass
       ||
       // All public superclass methods are visible.
       targetMethod.isPublic()
       // Protected and package private are visible from the same package.
       || !targetMethod.isPrivate()
           && method.binding.declaringClass.getPackage()
               == targetMethod.declaringClass.getPackage()
       // Protected super class methods are visible from any subclass.
       || targetMethod.isProtected()
           && targetMethod.declaringClass.isSuperclassOf(method.binding.declaringClass);
 }
예제 #2
0
  private static List<MethodBinding> getApplicableExtensionMethodsDefinedInProvider(
      EclipseNode typeNode,
      ReferenceBinding extensionMethodProviderBinding,
      TypeBinding receiverType) {

    List<MethodBinding> extensionMethods = new ArrayList<MethodBinding>();
    CompilationUnitScope cuScope = ((CompilationUnitDeclaration) typeNode.top().get()).scope;
    for (MethodBinding method : extensionMethodProviderBinding.methods()) {
      if (!method.isStatic()) continue;
      if (!method.isPublic()) continue;
      if (method.parameters == null || method.parameters.length == 0) continue;
      TypeBinding firstArgType = method.parameters[0];
      if (receiverType.isProvablyDistinct(firstArgType)
          && !receiverType.isCompatibleWith(firstArgType.erasure())) continue;
      TypeBinding[] argumentTypes =
          Arrays.copyOfRange(method.parameters, 1, method.parameters.length);
      if ((receiverType instanceof ReferenceBinding)
          && ((ReferenceBinding) receiverType)
                  .getExactMethod(method.selector, argumentTypes, cuScope)
              != null) continue;
      extensionMethods.add(method);
    }
    return extensionMethods;
  }