Search in sources :

Example 1 with PolymorphicMethodBinding

use of org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding in project bazel-jdt-java-toolchain by salesforce.

the class CastExpression method resolveType.

@Override
public TypeBinding resolveType(BlockScope scope) {
    // compute a new constant if the cast is effective
    this.constant = Constant.NotAConstant;
    this.implicitConversion = TypeIds.T_undefined;
    boolean exprContainCast = false;
    TypeBinding castType = this.resolvedType = this.type.resolveType(scope);
    if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8) {
        this.expression.setExpressionContext(CASTING_CONTEXT);
        if (this.expression instanceof FunctionalExpression) {
            this.expression.setExpectedType(this.resolvedType);
            this.bits |= ASTNode.DisableUnnecessaryCastCheck;
        }
    }
    if (this.expression instanceof CastExpression) {
        this.expression.bits |= ASTNode.DisableUnnecessaryCastCheck;
        exprContainCast = true;
    }
    TypeBinding expressionType = this.expression.resolveType(scope);
    if (this.expression instanceof MessageSend) {
        MessageSend messageSend = (MessageSend) this.expression;
        MethodBinding methodBinding = messageSend.binding;
        if (methodBinding != null && methodBinding.isPolymorphic()) {
            messageSend.binding = scope.environment().updatePolymorphicMethodReturnType((PolymorphicMethodBinding) methodBinding, castType);
            if (TypeBinding.notEquals(expressionType, castType)) {
                expressionType = castType;
                this.bits |= ASTNode.DisableUnnecessaryCastCheck;
            }
        }
    }
    if (castType != null) {
        if (expressionType != null) {
            boolean nullAnnotationMismatch = scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled && NullAnnotationMatching.analyse(castType, expressionType, -1).isAnyMismatch();
            if (this.instanceofType != null && expressionType.isParameterizedType() && expressionType.isProvablyDistinct(this.instanceofType)) {
                this.bits |= ASTNode.DisableUnnecessaryCastCheck;
            }
            if (this.isVarTypeDeclaration && TypeBinding.notEquals(expressionType, castType)) {
                this.bits |= ASTNode.DisableUnnecessaryCastCheck;
            }
            boolean isLegal = checkCastTypesCompatibility(scope, castType, expressionType, this.expression, true);
            if (isLegal) {
                this.expression.computeConversion(scope, castType, expressionType);
                if ((this.bits & ASTNode.UnsafeCast) != 0) {
                    // unsafe cast
                    if (scope.compilerOptions().reportUnavoidableGenericTypeProblems || !(expressionType.isRawType() && this.expression.forcedToBeRaw(scope.referenceContext()))) {
                        scope.problemReporter().unsafeCast(this, scope);
                    }
                } else if (nullAnnotationMismatch) {
                    // report null annotation issue at medium priority
                    scope.problemReporter().unsafeNullnessCast(this, scope);
                } else {
                    if (castType.isRawType() && scope.compilerOptions().getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) {
                        scope.problemReporter().rawTypeReference(this.type, castType);
                    }
                    if ((this.bits & (ASTNode.UnnecessaryCast | ASTNode.DisableUnnecessaryCastCheck)) == ASTNode.UnnecessaryCast) {
                        // unnecessary cast
                        if (// used for generic type inference or boxing ?
                        !isIndirectlyUsed())
                            scope.problemReporter().unnecessaryCast(this);
                    }
                }
            } else {
                // illegal cast
                if ((castType.tagBits & TagBits.HasMissingType) == 0) {
                    // no complaint if secondary error
                    scope.problemReporter().typeCastError(this, castType, expressionType);
                }
                // disable further secondary diagnosis
                this.bits |= ASTNode.DisableUnnecessaryCastCheck;
            }
        }
        // make it unique, a cast expression shares source end with the expression.
        this.resolvedType = castType.capture(scope, this.type.sourceStart, this.type.sourceEnd);
        if (exprContainCast) {
            checkNeedForCastCast(scope, this);
        }
    }
    return this.resolvedType;
}
Also used : ParameterizedTypeBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) ParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding)

Example 2 with PolymorphicMethodBinding

use of org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding in project bazel-jdt-java-toolchain by salesforce.

the class MessageSend method generateCode.

/**
 * MessageSend code generation
 *
 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
 * @param valueRequired boolean
 */
@Override
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
    cleanUpInferenceContexts();
    int pc = codeStream.position;
    // generate receiver/enclosing instance access
    MethodBinding codegenBinding = this.binding instanceof PolymorphicMethodBinding ? this.binding : this.binding.original();
    boolean isStatic = codegenBinding.isStatic();
    if (isStatic) {
        this.receiver.generateCode(currentScope, codeStream, false);
    } else if ((this.bits & ASTNode.DepthMASK) != 0 && this.receiver.isImplicitThis()) {
        // outer access ?
        // outer method can be reached through emulation if implicit access
        ReferenceBinding targetType = currentScope.enclosingSourceType().enclosingTypeAt((this.bits & ASTNode.DepthMASK) >> ASTNode.DepthSHIFT);
        Object[] path = currentScope.getEmulationPath(targetType, true, /*only exact match*/
        false);
        codeStream.generateOuterAccess(path, this, targetType, currentScope);
    } else {
        this.receiver.generateCode(currentScope, codeStream, true);
        if ((this.bits & NeedReceiverGenericCast) != 0) {
            codeStream.checkcast(this.actualReceiverType);
        }
    }
    codeStream.recordPositionsFrom(pc, this.sourceStart);
    // generate arguments
    generateArguments(this.binding, this.arguments, currentScope, codeStream);
    pc = codeStream.position;
    // actual message invocation
    if (this.syntheticAccessor == null) {
        TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, codegenBinding, this.actualReceiverType, this.receiver.isImplicitThis());
        if (isStatic) {
            codeStream.invoke(Opcodes.OPC_invokestatic, codegenBinding, constantPoolDeclaringClass, this.typeArguments);
        } else if ((this.receiver.isSuper()) || (!currentScope.enclosingSourceType().isNestmateOf(this.binding.declaringClass) && codegenBinding.isPrivate())) {
            codeStream.invoke(Opcodes.OPC_invokespecial, codegenBinding, constantPoolDeclaringClass, this.typeArguments);
        } else if (constantPoolDeclaringClass.isInterface()) {
            // interface or annotation type
            codeStream.invoke(Opcodes.OPC_invokeinterface, codegenBinding, constantPoolDeclaringClass, this.typeArguments);
        } else {
            codeStream.invoke(Opcodes.OPC_invokevirtual, codegenBinding, constantPoolDeclaringClass, this.typeArguments);
        }
    } else {
        codeStream.invoke(Opcodes.OPC_invokestatic, this.syntheticAccessor, null, /* default declaringClass */
        this.typeArguments);
    }
    // required cast must occur even if no value is required
    if (this.valueCast != null)
        codeStream.checkcast(this.valueCast);
    if (valueRequired) {
        // implicit conversion if necessary
        codeStream.generateImplicitConversion(this.implicitConversion);
    } else {
        boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0;
        // conversion only generated if unboxing
        if (isUnboxing)
            codeStream.generateImplicitConversion(this.implicitConversion);
        switch(isUnboxing ? postConversionType(currentScope).id : codegenBinding.returnType.id) {
            case T_long:
            case T_double:
                codeStream.pop2();
                break;
            case T_void:
                break;
            default:
                codeStream.pop();
        }
    }
    // highlight selector
    codeStream.recordPositionsFrom(pc, (int) (this.nameSourcePosition >>> 32));
}
Also used : PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) MissingTypeBinding(org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding) PolyTypeBinding(org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding) RawTypeBinding(org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding) PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) ProblemMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) ParameterizedMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding) PolyParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolyParameterizedGenericMethodBinding) ParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) ProblemReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding)

Example 3 with PolymorphicMethodBinding

use of org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding in project bazel-jdt-java-toolchain by salesforce.

the class MessageSend method resolveType.

@Override
public TypeBinding resolveType(BlockScope scope) {
    // Base type promotion
    if (this.constant != Constant.NotAConstant) {
        this.constant = Constant.NotAConstant;
        long sourceLevel = scope.compilerOptions().sourceLevel;
        boolean receiverCast = false;
        if (this.receiver instanceof CastExpression) {
            // will check later on
            this.receiver.bits |= ASTNode.DisableUnnecessaryCastCheck;
            receiverCast = true;
        }
        this.actualReceiverType = this.receiver.resolveType(scope);
        if (this.actualReceiverType instanceof InferenceVariable) {
            // not yet ready for resolving
            return null;
        }
        this.receiverIsType = this.receiver.isType();
        if (receiverCast && this.actualReceiverType != null) {
            // due to change of declaring class with receiver type, only identity cast should be notified
            TypeBinding resolvedType2 = ((CastExpression) this.receiver).expression.resolvedType;
            if (TypeBinding.equalsEquals(resolvedType2, this.actualReceiverType)) {
                if (!scope.environment().usesNullTypeAnnotations() || !NullAnnotationMatching.analyse(this.actualReceiverType, resolvedType2, -1).isAnyMismatch()) {
                    scope.problemReporter().unnecessaryCast((CastExpression) this.receiver);
                }
            }
        }
        // resolve type arguments (for generic constructor call)
        if (this.typeArguments != null) {
            int length = this.typeArguments.length;
            // typeChecks all arguments
            this.argumentsHaveErrors = sourceLevel < ClassFileConstants.JDK1_5;
            this.genericTypeArguments = new TypeBinding[length];
            for (int i = 0; i < length; i++) {
                TypeReference typeReference = this.typeArguments[i];
                if ((this.genericTypeArguments[i] = typeReference.resolveType(scope, true, /* check bounds*/
                Binding.DefaultLocationTypeArgument)) == null) {
                    this.argumentsHaveErrors = true;
                }
                if (this.argumentsHaveErrors && typeReference instanceof Wildcard) {
                    scope.problemReporter().illegalUsageOfWildcard(typeReference);
                }
            }
            if (this.argumentsHaveErrors) {
                if (this.arguments != null) {
                    // still attempt to resolve arguments
                    for (int i = 0, max = this.arguments.length; i < max; i++) {
                        this.arguments[i].resolveType(scope);
                    }
                }
                return null;
            }
        }
        // will check for null after args are resolved
        if (this.arguments != null) {
            // typeChecks all arguments
            this.argumentsHaveErrors = false;
            int length = this.arguments.length;
            this.argumentTypes = new TypeBinding[length];
            for (int i = 0; i < length; i++) {
                Expression argument = this.arguments[i];
                if (this.arguments[i].resolvedType != null)
                    // $NON-NLS-1$
                    scope.problemReporter().genericInferenceError("Argument was unexpectedly found resolved", this);
                if (argument instanceof CastExpression) {
                    // will check later on
                    argument.bits |= ASTNode.DisableUnnecessaryCastCheck;
                    this.argsContainCast = true;
                }
                argument.setExpressionContext(INVOCATION_CONTEXT);
                if ((this.argumentTypes[i] = argument.resolveType(scope)) == null) {
                    this.argumentsHaveErrors = true;
                }
            }
            if (this.argumentsHaveErrors) {
                if (this.actualReceiverType instanceof ReferenceBinding) {
                    // record a best guess, for clients who need hint about possible method match
                    TypeBinding[] pseudoArgs = new TypeBinding[length];
                    for (int i = length; --i >= 0; ) // replace args with errors with null type
                    pseudoArgs[i] = this.argumentTypes[i] == null ? TypeBinding.NULL : this.argumentTypes[i];
                    this.binding = this.receiver.isImplicitThis() ? scope.getImplicitMethod(this.selector, pseudoArgs, this) : scope.findMethod((ReferenceBinding) this.actualReceiverType, this.selector, pseudoArgs, this, false);
                    if (this.binding != null && !this.binding.isValidBinding()) {
                        MethodBinding closestMatch = ((ProblemMethodBinding) this.binding).closestMatch;
                        // record the closest match, for clients who may still need hint about possible method match
                        if (closestMatch != null) {
                            if (closestMatch.original().typeVariables != Binding.NO_TYPE_VARIABLES) {
                                // generic method
                                // shouldn't return generic method outside its context, rather convert it to raw method (175409)
                                closestMatch = scope.environment().createParameterizedGenericMethod(closestMatch.original(), (RawTypeBinding) null);
                            }
                            this.binding = closestMatch;
                            MethodBinding closestMatchOriginal = closestMatch.original();
                            if (closestMatchOriginal.isOrEnclosedByPrivateType() && !scope.isDefinedInMethod(closestMatchOriginal)) {
                                // ignore cases where method is used from within inside itself (e.g. direct recursions)
                                closestMatchOriginal.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
                            }
                        }
                    }
                }
                return null;
            }
        }
        if (this.actualReceiverType == null) {
            return null;
        }
        // base type cannot receive any message
        if (this.actualReceiverType.isBaseType()) {
            scope.problemReporter().errorNoMethodFor(this, this.actualReceiverType, this.argumentTypes);
            return null;
        }
    }
    TypeBinding methodType = findMethodBinding(scope);
    if (methodType != null && methodType.isPolyType()) {
        this.resolvedType = this.binding.returnType.capture(scope, this.sourceStart, this.sourceEnd);
        return methodType;
    }
    if (!this.binding.isValidBinding()) {
        if (this.binding.declaringClass == null) {
            if (this.actualReceiverType instanceof ReferenceBinding) {
                this.binding.declaringClass = (ReferenceBinding) this.actualReceiverType;
            } else {
                scope.problemReporter().errorNoMethodFor(this, this.actualReceiverType, this.argumentTypes);
                return null;
            }
        }
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=245007 avoid secondary errors in case of
        // missing super type for anonymous classes ...
        ReferenceBinding declaringClass = this.binding.declaringClass;
        boolean avoidSecondary = declaringClass != null && declaringClass.isAnonymousType() && declaringClass.superclass() instanceof MissingTypeBinding;
        if (!avoidSecondary)
            scope.problemReporter().invalidMethod(this, this.binding, scope);
        MethodBinding closestMatch = ((ProblemMethodBinding) this.binding).closestMatch;
        switch(this.binding.problemId()) {
            case ProblemReasons.Ambiguous:
                // no resilience on ambiguous
                break;
            case ProblemReasons.InferredApplicableMethodInapplicable:
            case ProblemReasons.InvocationTypeInferenceFailure:
                // Grabbing the closest match improves error reporting in nested invocation contexts
                if (this.expressionContext != INVOCATION_CONTEXT)
                    break;
            // $FALL-THROUGH$
            case ProblemReasons.NotVisible:
            case ProblemReasons.NonStaticReferenceInConstructorInvocation:
            case ProblemReasons.NonStaticReferenceInStaticContext:
            case ProblemReasons.ReceiverTypeNotVisible:
            case ProblemReasons.ParameterBoundMismatch:
                // only steal returnType in cases listed above
                if (closestMatch != null)
                    this.resolvedType = closestMatch.returnType;
                break;
            case ProblemReasons.ContradictoryNullAnnotations:
                if (closestMatch != null && closestMatch.returnType != null)
                    this.resolvedType = closestMatch.returnType.withoutToplevelNullAnnotation();
                break;
        }
        // record the closest match, for clients who may still need hint about possible method match
        if (closestMatch != null) {
            this.binding = closestMatch;
            MethodBinding closestMatchOriginal = closestMatch.original();
            if (closestMatchOriginal.isOrEnclosedByPrivateType() && !scope.isDefinedInMethod(closestMatchOriginal)) {
                // ignore cases where method is used from within inside itself (e.g. direct recursions)
                closestMatchOriginal.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
            }
        }
        return (this.resolvedType != null && (this.resolvedType.tagBits & TagBits.HasMissingType) == 0) ? this.resolvedType : null;
    }
    final CompilerOptions compilerOptions = scope.compilerOptions();
    if (compilerOptions.complianceLevel <= ClassFileConstants.JDK1_6 && this.binding.isPolymorphic()) {
        scope.problemReporter().polymorphicMethodNotBelow17(this);
        return null;
    }
    if (compilerOptions.isAnnotationBasedNullAnalysisEnabled) {
        ImplicitNullAnnotationVerifier.ensureNullnessIsKnown(this.binding, scope);
        if (compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8) {
            if (this.binding instanceof ParameterizedGenericMethodBinding && this.typeArguments != null) {
                TypeVariableBinding[] typeVariables = this.binding.original().typeVariables();
                for (int i = 0; i < this.typeArguments.length; i++) this.typeArguments[i].checkNullConstraints(scope, (ParameterizedGenericMethodBinding) this.binding, typeVariables, i);
            }
        }
    }
    if (this.binding.isPolymorphic()) {
        boolean resultDetermined = compilerOptions.sourceLevel >= ClassFileConstants.JDK9 && (this.binding.returnType == TypeBinding.VOID || this.binding.returnType.id != TypeIds.T_JavaLangObject);
        if (!resultDetermined && ((this.bits & ASTNode.InsideExpressionStatement) != 0)) {
            // we only set the return type to be void if this method invocation is used inside an expression statement
            this.binding = scope.environment().updatePolymorphicMethodReturnType((PolymorphicMethodBinding) this.binding, TypeBinding.VOID);
        }
    }
    if ((this.binding.tagBits & TagBits.HasMissingType) != 0) {
        scope.problemReporter().missingTypeInMethod(this, this.binding);
    }
    if (!this.binding.isStatic()) {
        // the "receiver" must not be a type
        if (this.receiverIsType) {
            scope.problemReporter().mustUseAStaticMethod(this, this.binding);
            if (this.actualReceiverType.isRawType() && (this.receiver.bits & ASTNode.IgnoreRawTypeCheck) == 0 && compilerOptions.getSeverity(CompilerOptions.RawTypeReference) != ProblemSeverities.Ignore) {
                scope.problemReporter().rawTypeReference(this.receiver, this.actualReceiverType);
            }
        } else {
            // handle indirect inheritance thru variable secondary bound
            // receiver may receive generic cast, as part of implicit conversion
            TypeBinding oldReceiverType = this.actualReceiverType;
            this.actualReceiverType = this.actualReceiverType.getErasureCompatibleType(this.binding.declaringClass);
            this.receiver.computeConversion(scope, this.actualReceiverType, this.actualReceiverType);
            if (TypeBinding.notEquals(this.actualReceiverType, oldReceiverType) && TypeBinding.notEquals(this.receiver.postConversionType(scope), this.actualReceiverType)) {
                // record need for explicit cast at codegen since receiver could not handle it
                this.bits |= NeedReceiverGenericCast;
            }
        }
    } else {
        // static message invoked through receiver? legal but unoptimal (optional warning).
        if (this.binding.declaringClass.isInterface() && !((isTypeAccess() || this.receiver.isImplicitThis()) && TypeBinding.equalsEquals(this.binding.declaringClass, this.actualReceiverType))) {
            scope.problemReporter().nonStaticOrAlienTypeReceiver(this, this.binding);
        } else if (!(this.receiver.isImplicitThis() || this.receiver.isSuper() || this.receiverIsType)) {
            scope.problemReporter().nonStaticAccessToStaticMethod(this, this.binding);
        }
        if (!this.receiver.isImplicitThis() && TypeBinding.notEquals(this.binding.declaringClass, this.actualReceiverType)) {
            scope.problemReporter().indirectAccessToStaticMethod(this, this.binding);
        }
    }
    if (checkInvocationArguments(scope, this.receiver, this.actualReceiverType, this.binding, this.arguments, this.argumentTypes, this.argsContainCast, this)) {
        this.bits |= ASTNode.Unchecked;
    }
    // -------message send that are known to fail at compile time-----------
    if (this.binding.isAbstract()) {
        if (this.receiver.isSuper()) {
            scope.problemReporter().cannotDireclyInvokeAbstractMethod(this, this.binding);
        }
    // abstract private methods cannot occur nor abstract static............
    }
    if (isMethodUseDeprecated(this.binding, scope, true, this))
        scope.problemReporter().deprecatedMethod(this.binding, this);
    TypeBinding returnType;
    if ((this.bits & ASTNode.Unchecked) != 0 && this.genericTypeArguments == null) {
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=277643, align with javac on JLS 15.12.2.6
        returnType = this.binding.returnType;
        if (returnType != null) {
            returnType = scope.environment().convertToRawType(returnType.erasure(), true);
        }
    } else {
        returnType = this.binding.returnType;
        if (returnType != null) {
            returnType = returnType.capture(scope, this.sourceStart, this.sourceEnd);
        }
    }
    this.resolvedType = returnType;
    if (this.receiver.isSuper() && compilerOptions.getSeverity(CompilerOptions.OverridingMethodWithoutSuperInvocation) != ProblemSeverities.Ignore) {
        final ReferenceContext referenceContext = scope.methodScope().referenceContext;
        if (referenceContext instanceof AbstractMethodDeclaration) {
            final AbstractMethodDeclaration abstractMethodDeclaration = (AbstractMethodDeclaration) referenceContext;
            MethodBinding enclosingMethodBinding = abstractMethodDeclaration.binding;
            if (enclosingMethodBinding.isOverriding() && CharOperation.equals(this.binding.selector, enclosingMethodBinding.selector) && this.binding.areParametersEqual(enclosingMethodBinding)) {
                abstractMethodDeclaration.bits |= ASTNode.OverridingMethodWithSupercall;
            }
        }
    }
    if (this.receiver.isSuper() && this.actualReceiverType.isInterface()) {
        // 15.12.3 (Java 8)
        scope.checkAppropriateMethodAgainstSupers(this.selector, this.binding, this.argumentTypes, this);
    }
    if (this.typeArguments != null && this.binding.original().typeVariables == Binding.NO_TYPE_VARIABLES) {
        scope.problemReporter().unnecessaryTypeArgumentsForMethodInvocation(this.binding, this.genericTypeArguments, this.typeArguments);
    }
    return (this.resolvedType.tagBits & TagBits.HasMissingType) == 0 ? this.resolvedType : null;
}
Also used : TypeVariableBinding(org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding) ProblemMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) MissingTypeBinding(org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding) PolyTypeBinding(org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding) RawTypeBinding(org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding) PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) PolyParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolyParameterizedGenericMethodBinding) ParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) ProblemReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding) InferenceVariable(org.eclipse.jdt.internal.compiler.lookup.InferenceVariable) RawTypeBinding(org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding) MissingTypeBinding(org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding) CompilerOptions(org.eclipse.jdt.internal.compiler.impl.CompilerOptions) ReferenceContext(org.eclipse.jdt.internal.compiler.impl.ReferenceContext) PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) ProblemMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) ParameterizedMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding) PolyParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolyParameterizedGenericMethodBinding) ParameterizedGenericMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding)

Example 4 with PolymorphicMethodBinding

use of org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding in project bazel-jdt-java-toolchain by salesforce.

the class ClassFile method addBootStrapLambdaEntry.

private int addBootStrapLambdaEntry(int localContentsOffset, FunctionalExpression functional, Map<String, Integer> fPtr) {
    MethodBinding[] bridges = functional.getRequiredBridges();
    TypeBinding[] markerInterfaces = null;
    final int contentsEntries = 10;
    int indexForAltMetaFactory = fPtr.get(ClassFile.ALTMETAFACTORY_STRING);
    int indexForMetaFactory = fPtr.get(ClassFile.METAFACTORY_STRING);
    if ((functional instanceof LambdaExpression && (((markerInterfaces = ((LambdaExpression) functional).getMarkerInterfaces()) != null)) || bridges != null) || functional.isSerializable) {
        // may need even more space
        // at least 2 more than when the normal metafactory is used, for the bitflags entry
        int extraSpace = 2;
        if (markerInterfaces != null) {
            // 2 for the marker interface list size then 2 per marker interface index
            extraSpace += (2 + 2 * markerInterfaces.length);
        }
        if (bridges != null) {
            // 2 for bridge count then 2 per bridge method type.
            extraSpace += (2 + 2 * bridges.length);
        }
        if (extraSpace + contentsEntries + localContentsOffset >= this.contents.length) {
            resizeContents(extraSpace + contentsEntries);
        }
        if (indexForAltMetaFactory == 0) {
            ReferenceBinding javaLangInvokeLambdaMetafactory = this.referenceBinding.scope.getJavaLangInvokeLambdaMetafactory();
            indexForAltMetaFactory = this.constantPool.literalIndexForMethodHandle(ClassFileConstants.MethodHandleRefKindInvokeStatic, javaLangInvokeLambdaMetafactory, ConstantPool.ALTMETAFACTORY, ConstantPool.JAVA_LANG_INVOKE_LAMBDAMETAFACTORY_ALTMETAFACTORY_SIGNATURE, false);
            fPtr.put(ClassFile.ALTMETAFACTORY_STRING, indexForAltMetaFactory);
        }
        this.contents[localContentsOffset++] = (byte) (indexForAltMetaFactory >> 8);
        this.contents[localContentsOffset++] = (byte) indexForAltMetaFactory;
        // u2 num_bootstrap_arguments
        this.contents[localContentsOffset++] = 0;
        this.contents[localContentsOffset++] = (byte) (4 + (markerInterfaces == null ? 0 : 1 + markerInterfaces.length) + (bridges == null ? 0 : 1 + bridges.length));
        int functionalDescriptorIndex = this.constantPool.literalIndexForMethodType(functional.descriptor.original().signature());
        this.contents[localContentsOffset++] = (byte) (functionalDescriptorIndex >> 8);
        this.contents[localContentsOffset++] = (byte) functionalDescriptorIndex;
        // Speak of " implementation" (erased) version here, adaptations described below.
        int methodHandleIndex = this.constantPool.literalIndexForMethodHandle(functional.binding.original());
        this.contents[localContentsOffset++] = (byte) (methodHandleIndex >> 8);
        this.contents[localContentsOffset++] = (byte) methodHandleIndex;
        char[] instantiatedSignature = functional.descriptor.signature();
        int methodTypeIndex = this.constantPool.literalIndexForMethodType(instantiatedSignature);
        this.contents[localContentsOffset++] = (byte) (methodTypeIndex >> 8);
        this.contents[localContentsOffset++] = (byte) methodTypeIndex;
        int bitflags = 0;
        if (functional.isSerializable) {
            bitflags |= ClassFileConstants.FLAG_SERIALIZABLE;
        }
        if (markerInterfaces != null) {
            bitflags |= ClassFileConstants.FLAG_MARKERS;
        }
        if (bridges != null) {
            bitflags |= ClassFileConstants.FLAG_BRIDGES;
        }
        int indexForBitflags = this.constantPool.literalIndex(bitflags);
        this.contents[localContentsOffset++] = (byte) (indexForBitflags >> 8);
        this.contents[localContentsOffset++] = (byte) (indexForBitflags);
        if (markerInterfaces != null) {
            int markerInterfaceCountIndex = this.constantPool.literalIndex(markerInterfaces.length);
            this.contents[localContentsOffset++] = (byte) (markerInterfaceCountIndex >> 8);
            this.contents[localContentsOffset++] = (byte) (markerInterfaceCountIndex);
            for (int m = 0, maxm = markerInterfaces.length; m < maxm; m++) {
                int classTypeIndex = this.constantPool.literalIndexForType(markerInterfaces[m]);
                this.contents[localContentsOffset++] = (byte) (classTypeIndex >> 8);
                this.contents[localContentsOffset++] = (byte) (classTypeIndex);
            }
        }
        if (bridges != null) {
            int bridgeCountIndex = this.constantPool.literalIndex(bridges.length);
            this.contents[localContentsOffset++] = (byte) (bridgeCountIndex >> 8);
            this.contents[localContentsOffset++] = (byte) (bridgeCountIndex);
            for (int m = 0, maxm = bridges.length; m < maxm; m++) {
                char[] bridgeSignature = bridges[m].signature();
                int bridgeMethodTypeIndex = this.constantPool.literalIndexForMethodType(bridgeSignature);
                this.contents[localContentsOffset++] = (byte) (bridgeMethodTypeIndex >> 8);
                this.contents[localContentsOffset++] = (byte) bridgeMethodTypeIndex;
            }
        }
    } else {
        if (contentsEntries + localContentsOffset >= this.contents.length) {
            resizeContents(contentsEntries);
        }
        if (indexForMetaFactory == 0) {
            ReferenceBinding javaLangInvokeLambdaMetafactory = this.referenceBinding.scope.getJavaLangInvokeLambdaMetafactory();
            indexForMetaFactory = this.constantPool.literalIndexForMethodHandle(ClassFileConstants.MethodHandleRefKindInvokeStatic, javaLangInvokeLambdaMetafactory, ConstantPool.METAFACTORY, ConstantPool.JAVA_LANG_INVOKE_LAMBDAMETAFACTORY_METAFACTORY_SIGNATURE, false);
            fPtr.put(ClassFile.METAFACTORY_STRING, indexForMetaFactory);
        }
        this.contents[localContentsOffset++] = (byte) (indexForMetaFactory >> 8);
        this.contents[localContentsOffset++] = (byte) indexForMetaFactory;
        // u2 num_bootstrap_arguments
        this.contents[localContentsOffset++] = 0;
        this.contents[localContentsOffset++] = (byte) 3;
        int functionalDescriptorIndex = this.constantPool.literalIndexForMethodType(functional.descriptor.original().signature());
        this.contents[localContentsOffset++] = (byte) (functionalDescriptorIndex >> 8);
        this.contents[localContentsOffset++] = (byte) functionalDescriptorIndex;
        // Speak of " implementation" (erased) version here, adaptations described below.
        int methodHandleIndex = this.constantPool.literalIndexForMethodHandle(functional.binding instanceof PolymorphicMethodBinding ? functional.binding : functional.binding.original());
        this.contents[localContentsOffset++] = (byte) (methodHandleIndex >> 8);
        this.contents[localContentsOffset++] = (byte) methodHandleIndex;
        char[] instantiatedSignature = functional.descriptor.signature();
        int methodTypeIndex = this.constantPool.literalIndexForMethodType(instantiatedSignature);
        this.contents[localContentsOffset++] = (byte) (methodTypeIndex >> 8);
        this.contents[localContentsOffset++] = (byte) methodTypeIndex;
    }
    return localContentsOffset;
}
Also used : TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) LocalTypeBinding(org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding) PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) SyntheticMethodBinding(org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding) ReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) ProblemReferenceBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding) LambdaExpression(org.eclipse.jdt.internal.compiler.ast.LambdaExpression)

Aggregations

MethodBinding (org.eclipse.jdt.internal.compiler.lookup.MethodBinding)4 PolymorphicMethodBinding (org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding)4 TypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeBinding)4 ParameterizedGenericMethodBinding (org.eclipse.jdt.internal.compiler.lookup.ParameterizedGenericMethodBinding)3 ProblemReferenceBinding (org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding)3 ReferenceBinding (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding)3 SourceTypeBinding (org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)3 MissingTypeBinding (org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding)2 ParameterizedMethodBinding (org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding)2 PolyParameterizedGenericMethodBinding (org.eclipse.jdt.internal.compiler.lookup.PolyParameterizedGenericMethodBinding)2 PolyTypeBinding (org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding)2 ProblemMethodBinding (org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding)2 RawTypeBinding (org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding)2 LambdaExpression (org.eclipse.jdt.internal.compiler.ast.LambdaExpression)1 CompilerOptions (org.eclipse.jdt.internal.compiler.impl.CompilerOptions)1 ReferenceContext (org.eclipse.jdt.internal.compiler.impl.ReferenceContext)1 InferenceVariable (org.eclipse.jdt.internal.compiler.lookup.InferenceVariable)1 LocalTypeBinding (org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding)1 ParameterizedTypeBinding (org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding)1 SyntheticMethodBinding (org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding)1