@Override public void applyToComputationState() { Candidate candidate = getPrimaryCandidate(); candidate.getState().getResolvedTypes().reassignLinkingInformation(candidate.getExpression(), this); candidate.applyToComputationState(); }
@Override public void applyToModel(IResolvedTypes resolvedTypes) { getPrimaryCandidate().applyToModel(resolvedTypes); }
@SuppressWarnings("incomplete-switch") protected CandidateCompareResult compareByArgumentTypes(AbstractPendingLinkingCandidate<?> right) { initializeArgumentTypeComputation(); right.initializeArgumentTypeComputation(); boolean hadIssues = false; CandidateCompareResult argumentTypeResult = compareByArgumentTypes(right, false); switch(argumentTypeResult) { case SUSPICIOUS_OTHER: CandidateCompareResult parameterTypeResult = compareExpectedArgumentTypes(right); switch(parameterTypeResult) { case EQUALLY_INVALID: CandidateCompareResult secondPassArgumentTypes = compareByArgumentTypes(right, true); if (secondPassArgumentTypes == CandidateCompareResult.SUSPICIOUS_OTHER) throw new IllegalStateException();
protected CandidateCompareResult compareByArityWith(AbstractPendingLinkingCandidate<?> right) { CandidateCompareResult arityCompareResult = compareByArity(getArityMismatch(), right.getArityMismatch()); return arityCompareResult; }
@Override protected CandidateCompareResult compareByArgumentTypes(AbstractPendingLinkingCandidate<?> right) { CandidateCompareResult result = super.compareByArgumentTypes(right); if (result == CandidateCompareResult.AMBIGUOUS && !right.isTypeLiteral()) { result = compareByNameAndStaticFlag(right); } return result; }
CandidateCompareResult arityCompareResult = compareByArityWith(right); switch(arityCompareResult) { case SUSPICIOUS_OTHER: boolean visible = isVisible(); if (visible != right.isVisible()) { if (visible) return CandidateCompareResult.THIS; CandidateCompareResult typeArityCompareResult = compareByArity(getTypeArityMismatch(), right.getTypeArityMismatch()); switch(typeArityCompareResult) { case SUSPICIOUS_OTHER: CandidateCompareResult nameCompareResult = compareByName(right); switch(nameCompareResult) { case SUSPICIOUS_OTHER: CandidateCompareResult argumentTypeCompareResult = compareByArgumentTypes(right); switch(argumentTypeCompareResult) { case EQUALLY_INVALID: CandidateCompareResult typeArgumentCompareResult = compareByTypeArguments(right); switch(typeArgumentCompareResult) { case SUSPICIOUS_OTHER: if (isVarArgs() != right.isVarArgs()) { if (isVarArgs()) return CandidateCompareResult.OTHER; return CandidateCompareResult.THIS;
boolean invalid = false; int upTo = Math.max(arguments.getArgumentCount(), right.arguments.getArgumentCount()); for(int leftIdx = hasReceiver() ? 0 : -1, rightIdx = right.hasReceiver() ? 0 : -1; leftIdx < upTo || rightIdx < upTo; leftIdx++, rightIdx++) { boolean leftIsPossibleFunctionType = isPossibleFunctionType(leftIdx); if (leftIsPossibleFunctionType != right.isPossibleFunctionType(rightIdx)) { if (leftIsPossibleFunctionType) { return CandidateCompareResult.THIS; int leftConformance = getConformanceFlags(leftIdx, recompute); int rightConformance = right.getConformanceFlags(rightIdx, recompute); CandidateCompareResult argumentCompareResult = compareByArgumentTypesFlags(right, leftIdx, rightIdx, leftConformance, rightConformance); switch(argumentCompareResult) { case SUSPICIOUS_OTHER: if (isExtension() == right.isExtension()) { if (arguments.hasEmptyTrailingVarArg()) { leftVarArgs++; CandidateCompareResult result = compareByArgumentTypes(right, leftBoxing, rightBoxing, leftDemand, rightDemand); switch(result) { case AMBIGUOUS: {
@Override protected CandidateCompareResult compareByArityWith(AbstractPendingLinkingCandidate<?> right) { CandidateCompareResult result = super.compareByArityWith(right); if (result == CandidateCompareResult.AMBIGUOUS) { boolean isExecutable = getFeature() instanceof JvmExecutable; if (isExecutable != right.getFeature() instanceof JvmExecutable && isVisible() == right.isVisible() && isTypeLiteral() == right.isTypeLiteral()) { return CandidateCompareResult.OTHER; } else if (getFeature() == right.getFeature() && right instanceof FeatureLinkingCandidate) { FeatureLinkingCandidate casted = (FeatureLinkingCandidate) right; if (isStatic() && casted.isStatic()) {
@Override protected CandidateCompareResult compareByArgumentTypes(AbstractPendingLinkingCandidate<?> right, boolean recompute) { CandidateCompareResult result = super.compareByArgumentTypes(right, recompute); if (result == CandidateCompareResult.AMBIGUOUS && getExpression() instanceof XAssignment) { if (description.isValidStaticState() == right.description.isValidStaticState()) { if (getFeature() instanceof JvmExecutable != right.getFeature() instanceof JvmExecutable) { if (getFeature() instanceof JvmExecutable) { return CandidateCompareResult.OTHER; } return CandidateCompareResult.THIS; } } } return result; }
@Override protected CandidateCompareResult compareByBucket(AbstractPendingLinkingCandidate<?> right) { if (isExtension() && right.isExtension()) { if (description.getShadowingKey().equals(right.description.getShadowingKey())) { if (description.getBucketId() == right.description.getBucketId()) { return CandidateCompareResult.AMBIGUOUS; } if (isAmbiguousExtensionProvider(right)) { return CandidateCompareResult.AMBIGUOUS; } return CandidateCompareResult.THIS; } return CandidateCompareResult.AMBIGUOUS; } return super.compareByBucket(right); }
/** * Compare this linking candidate with the given {@code other} candidate at {@code argumentIndex} * * Returns {@code CandidateCompareResult#THIS} if this candidate is better, {@code CandidateCompareResult#OTHER} if the * right candidate was better, {@code CandidateCompareResult#AMBIGUOUS} if both candidates are valid * but ambiguous or {@code CandidateCompareResult#EQUALLY_INVALID} if both candidates are * ambiguous but erroneous. * * @param other the other candidate (the rhs of the comparison) * @param leftBoxing the number of required boxing conversions if this candidate was chosen * @param rightBoxing the number of required boxing conversions if the other candidate was chosen * @param leftDemand the number of required demand conversions if this candidate was chosen * @param rightDemand the number of required demand conversions if the other candidate was chosen */ protected CandidateCompareResult compareByArgumentTypes(AbstractPendingLinkingCandidate<?> other, int leftBoxing, int rightBoxing, int leftDemand, int rightDemand) { if (leftDemand != rightDemand) { if (leftDemand < rightDemand) return CandidateCompareResult.THIS; return CandidateCompareResult.OTHER; } return compareByBoxing(leftBoxing, rightBoxing); }
@Override protected CandidateCompareResult compareByName(AbstractPendingLinkingCandidate<?> right) { if (!(right instanceof FeatureLinkingCandidate)) { return super.compareByName(right); } FeatureLinkingCandidate other = (FeatureLinkingCandidate) right; boolean thisCompoundOperator = isCompoundOperator(); boolean otherCompoundOperator = other.isCompoundOperator(); if (thisCompoundOperator == otherCompoundOperator) { return CandidateCompareResult.AMBIGUOUS; } if (thisCompoundOperator) { return CandidateCompareResult.THIS; } return CandidateCompareResult.OTHER; }
@Override protected CandidateCompareResult compareByArgumentTypesFlags( AbstractPendingLinkingCandidate<?> right, int leftIdx, int rightIdx, int leftConformance, int rightConformance) { CandidateCompareResult result = super.compareByArgumentTypesFlags(right, leftIdx, rightIdx, leftConformance, rightConformance); if ((result != CandidateCompareResult.EQUALLY_INVALID && result != CandidateCompareResult.AMBIGUOUS) || ((leftConformance & ConformanceFlags.SUCCESS) != 0) || !(right instanceof FeatureLinkingCandidate)) return result; // both types do not match - pick the one which is not an extension boolean firstArgumentMismatch = isFirstArgument(leftIdx); boolean rightFirstArgumentMismatch = ((FeatureLinkingCandidate) right).isFirstArgument(rightIdx); if (firstArgumentMismatch != rightFirstArgumentMismatch) { if (firstArgumentMismatch) return CandidateCompareResult.OTHER; return CandidateCompareResult.THIS; } return result; }