mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
static factory detection for top level method call (IDEA-172566)
This commit is contained in:
+1
-1
@@ -866,7 +866,7 @@ public class InferenceSession {
|
||||
return getTypeByMethod(context, argumentList, properties.getMethod(), properties.isVarargs(), properties.getSubstitutor(), inferParent);
|
||||
}
|
||||
|
||||
final JavaResolveResult result = ((PsiCall)gParent).resolveMethodGenerics();
|
||||
final JavaResolveResult result = PsiDiamondType.getDiamondsAwareResolveResult((PsiCall)gParent);
|
||||
final PsiElement element = result.getElement();
|
||||
if (element == null) {
|
||||
errorMessage.set("Overload resolution failed");
|
||||
|
||||
+2
-2
@@ -172,7 +172,7 @@ public class InferenceSessionContainer {
|
||||
if (initialInferenceState != null) {
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
final int idx = LambdaUtil.getLambdaIdx(argumentList, gParent);
|
||||
final JavaResolveResult result = call.resolveMethodGenerics();
|
||||
final JavaResolveResult result = PsiDiamondType.getDiamondsAwareResolveResult(call);
|
||||
final PsiElement method = result.getElement();
|
||||
if (method instanceof PsiMethod && idx > -1) {
|
||||
LOG.assertTrue(argumentList != null);
|
||||
@@ -244,7 +244,7 @@ public class InferenceSessionContainer {
|
||||
|
||||
@Nullable
|
||||
private static InferenceSession startTopLevelInference(final PsiCall topLevelCall, final ParameterTypeInferencePolicy policy) {
|
||||
final JavaResolveResult result = topLevelCall.resolveMethodGenerics();
|
||||
final JavaResolveResult result = PsiDiamondType.getDiamondsAwareResolveResult(topLevelCall);
|
||||
if (result instanceof MethodCandidateInfo) {
|
||||
final PsiMethod method = ((MethodCandidateInfo)result).getElement();
|
||||
final PsiParameter[] topLevelParameters = method.getParameterList().getParameters();
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class Collectinator<T, A, R> {
|
||||
|
||||
private Collectinator(Collector<T, A, R> collector) { }
|
||||
|
||||
{
|
||||
|
||||
Collectinator<Foo, ?, Optional<Foo>> lastDate =
|
||||
new Collectinator<>(Collectors.maxBy(Foo::compareTo));
|
||||
|
||||
}
|
||||
|
||||
static class Bar {}
|
||||
static class Foo extends Bar{
|
||||
public int compareTo(Bar other) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -9,15 +9,14 @@ inference variable K has incompatible bounds:
|
||||
lower bounds: Holder">Result.create(h);</error>
|
||||
|
||||
Holder dataHolder = null;
|
||||
Result<String> r3 = new Result<error descr="Cannot infer arguments"><></error>(new Holder<error descr="Cannot infer arguments"><></error>(dataHolder));
|
||||
Result<String> r3 = new Result<error descr="Cannot infer arguments"><></error>(new Holder<>(dataHolder));
|
||||
Result<String> r4 = <error descr="Incompatible types. Required Result<String> but 'create' was inferred to Result<K>:
|
||||
no instance(s) of type variable(s) exist so that Holder conforms to String
|
||||
inference variable K has incompatible bounds:
|
||||
equality constraints: String
|
||||
lower bounds: Holder">Result.create(new Holder<>(dataHolder));</error>
|
||||
|
||||
Result<String> r5 = new Result<error descr="Cannot infer arguments"><></error>(<error descr="Incompatible types. Required D but 'create' was inferred to Holder<M>:
|
||||
Incompatible types: Holder is not convertible to D">Holder.create(dataHolder)</error>);
|
||||
Result<String> r5 = new Result<error descr="Cannot infer arguments"><></error>(Holder.create(dataHolder));
|
||||
Result<String> r6 = <error descr="Incompatible types. Required Result<String> but 'create' was inferred to Result<K>:
|
||||
no instance(s) of type variable(s) exist so that Holder conforms to String
|
||||
inference variable K has incompatible bounds:
|
||||
|
||||
+1
-2
@@ -29,8 +29,7 @@ public class ConcurrentCollectors {
|
||||
static <T, K, D, M1 extends Map<K, D>> C<T, M1> groupingBy(F<M1> f,
|
||||
C<T, D> c,
|
||||
BiConsumer<M1, T> consumer) {
|
||||
return new CImpl<error descr="Cannot infer arguments"><></error>(f, consumer, <error descr="Incompatible types. Required BiOp<R> but 'arg' was inferred to BiOp<M2>:
|
||||
no instance(s) of type variable(s) K, V exist so that R conforms to ConcurrentMap<K, V>">arg(c.getOp())</error>);
|
||||
return new CImpl<error descr="Cannot infer arguments"><></error>(f, consumer, arg(c.getOp()));
|
||||
}
|
||||
|
||||
static <K, V, M2 extends ConcurrentMap<K, V>> BiOp<M2> arg(BiOp<V> op) {
|
||||
|
||||
+4
@@ -97,6 +97,10 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testDetectStaticFactoryForTopLevelCall() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws Exception {
|
||||
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user