Extracted method.

This commit is contained in:
Evgeny Gerashchenko
2013-03-21 22:52:35 +04:00
parent 0422253943
commit 7a136eae5b
@@ -313,6 +313,27 @@ public final class JavaFunctionResolver {
return functions; return functions;
} }
@Nullable
private SimpleFunctionDescriptor resolveSamConstructor(
@NotNull NamespaceDescriptor ownerDescriptor,
@NotNull NamedMembers namedMembers
) {
PsiClass functionalInterface = namedMembers.getFunctionalInterface();
if (functionalInterface != null) {
ClassifierDescriptor classifier = ownerDescriptor.getMemberScope().getClassifier(namedMembers.getName());
if (classifier instanceof ClassDescriptor) {
ClassDescriptor klass = (ClassDescriptor) classifier;
if (SingleAbstractMethodUtils.isFunctionalInterface(klass)) {
SimpleFunctionDescriptor constructorFunction = SingleAbstractMethodUtils.createConstructorFunction(klass);
trace.record(BindingContext.SAM_CONSTRUCTOR_TO_TRAIT, constructorFunction, klass);
return constructorFunction;
}
}
}
return null;
}
@NotNull @NotNull
public Set<FunctionDescriptor> resolveFunctionGroup( public Set<FunctionDescriptor> resolveFunctionGroup(
@NotNull Name methodName, @NotNull Name methodName,
@@ -340,21 +361,11 @@ public final class JavaFunctionResolver {
return Collections.emptySet(); return Collections.emptySet();
} }
PsiClass functionalInterface = namedMembers.getFunctionalInterface(); SimpleFunctionDescriptor samConstructor = resolveSamConstructor(ownerDescriptor, namedMembers);
if (functionalInterface != null) {
ClassifierDescriptor classifier = ownerDescriptor.getMemberScope().getClassifier(functionName);
if (classifier instanceof ClassDescriptor) {
ClassDescriptor klass = (ClassDescriptor) classifier;
if (SingleAbstractMethodUtils.isFunctionalInterface(klass)) { return samConstructor == null
SimpleFunctionDescriptor constructorFunction = SingleAbstractMethodUtils.createConstructorFunction(klass); ? Collections.<FunctionDescriptor>emptySet()
trace.record(BindingContext.SAM_CONSTRUCTOR_TO_TRAIT, constructorFunction, klass); : Collections.<FunctionDescriptor>singleton(samConstructor);
return Collections.<FunctionDescriptor>singleton(constructorFunction);
}
}
}
return Collections.emptySet();
} }
@NotNull @NotNull