Added diagnostic error when in function declaration name was omitted

This commit is contained in:
Stanislav Erokhin
2015-02-05 19:45:24 +03:00
parent a8536fef9b
commit 560c32c0f1
19 changed files with 128 additions and 14 deletions
@@ -333,6 +333,8 @@ public interface Errors {
DiagnosticFactory1<JetFunction, SimpleFunctionDescriptor> NON_MEMBER_FUNCTION_NO_BODY =
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetFunction> FUNCTION_DECLARATION_WITH_NO_NAME = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetParameter> VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetNamedFunction> NO_TAIL_CALLS_FOUND = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
@@ -32,7 +32,9 @@ public object PositioningStrategies {
private open class DeclarationHeader<T : JetDeclaration> : PositioningStrategy<T>() {
override fun isValid(element: T): Boolean {
if (element is JetNamedDeclaration &&
(element !is JetObjectDeclaration && element !is JetSecondaryConstructor)
element !is JetObjectDeclaration &&
element !is JetSecondaryConstructor &&
element !is JetNamedFunction
) {
if (element.getNameIdentifier() == null) {
return false
@@ -103,6 +105,9 @@ public object PositioningStrategies {
}
return markElement(nameIdentifier)
}
if (element is JetNamedFunction) {
return DECLARATION_SIGNATURE.mark(element)
}
return DEFAULT.mark(element)
}
}
@@ -224,6 +224,7 @@ public class DefaultErrorMessages {
MAP.put(FINAL_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without body cannot be final", NAME);
MAP.put(NON_MEMBER_FUNCTION_NO_BODY, "Function ''{0}'' must have a body", NAME);
MAP.put(FUNCTION_DECLARATION_WITH_NO_NAME, "Function declaration must have a name");
MAP.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, "\"open\" has no effect in a final class");
MAP.put(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, "Public or protected member should have specified type");
@@ -237,7 +237,19 @@ public class DescriptorResolver {
@NotNull DataFlowInfo dataFlowInfo
) {
return resolveFunctionDescriptor(containingDescriptor, scope, function, trace, dataFlowInfo,
annotationResolver.resolveAnnotationsWithArguments(scope, function.getModifierList(), trace));
annotationResolver.resolveAnnotationsWithArguments(scope, function.getModifierList(), trace), false);
}
@NotNull
public SimpleFunctionDescriptor resolveAnonymousFunctionDescriptor(
@NotNull DeclarationDescriptor containingDescriptor,
@NotNull JetScope scope,
@NotNull JetNamedFunction function,
@NotNull BindingTrace trace,
@NotNull DataFlowInfo dataFlowInfo
) {
return resolveFunctionDescriptor(containingDescriptor, scope, function, trace, dataFlowInfo,
annotationResolver.resolveAnnotationsWithArguments(scope, function.getModifierList(), trace), true);
}
@NotNull
@@ -249,7 +261,7 @@ public class DescriptorResolver {
@NotNull DataFlowInfo dataFlowInfo
) {
return resolveFunctionDescriptor(containingDescriptor, scope, function, trace, dataFlowInfo,
annotationResolver.resolveAnnotationsWithoutArguments(scope, function.getModifierList(), trace));
annotationResolver.resolveAnnotationsWithoutArguments(scope, function.getModifierList(), trace), false);
}
@NotNull
@@ -259,12 +271,17 @@ public class DescriptorResolver {
@NotNull final JetNamedFunction function,
@NotNull final BindingTrace trace,
@NotNull final DataFlowInfo dataFlowInfo,
@NotNull Annotations annotations
@NotNull Annotations annotations,
boolean nameCanBeOmitted
) {
if (!nameCanBeOmitted && function.getName() == null) {
trace.report(FUNCTION_DECLARATION_WITH_NO_NAME.on(function));
}
final SimpleFunctionDescriptorImpl functionDescriptor = SimpleFunctionDescriptorImpl.create(
containingDescriptor,
annotations,
JetPsiUtil.safeName(function.getName()),
function.getNameAsSafeName(),
CallableMemberDescriptor.Kind.DECLARATION,
toSourceElement(function)
);