blob: e70a7ad12a516f4da3219b0c9e96e2ea79ea65ca [file] [log] [blame]
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jetbrains.python.psi;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiNameIdentifierOwner;
import com.intellij.psi.PsiNamedElement;
import com.intellij.psi.StubBasedPsiElement;
import com.intellij.util.ArrayFactory;
import com.jetbrains.python.codeInsight.controlflow.ScopeOwner;
import com.jetbrains.python.psi.stubs.PyFunctionStub;
import com.jetbrains.python.psi.types.PyType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Function declaration in source (the <code>def</code> and everything within).
*
* @author yole
*/
public interface PyFunction
extends
PsiNamedElement, StubBasedPsiElement<PyFunctionStub>,
PsiNameIdentifierOwner, PyStatement, Callable, NameDefiner, PyDocStringOwner, ScopeOwner, PyDecoratable, PyTypedElement,
PyStatementListContainer{
PyFunction[] EMPTY_ARRAY = new PyFunction[0];
ArrayFactory<PyFunction> ARRAY_FACTORY = new ArrayFactory<PyFunction>() {
@NotNull
@Override
public PyFunction[] create(int count) {
return new PyFunction[count];
}
};
/**
* Returns the AST node for the function name identifier.
*
* @return the node, or null if the function is incomplete (only the "def"
* keyword was typed)
*/
@Nullable
ASTNode getNameNode();
@Nullable
PyClass getContainingClass();
@Nullable
PyType getReturnTypeFromDocString();
/**
* If the function raises a DeprecationWarning or a PendingDeprecationWarning, returns the explanation text provided for the warning..
*
* @return the deprecation message or null if the function is not deprecated.
*/
@Nullable
String getDeprecationMessage();
/**
* Looks for two standard decorators to a function, or a wrapping assignment that closely follows it.
*
* @return a flag describing what was detected.
*/
@Nullable
Modifier getModifier();
/**
* Flags that mark common alterations of a function: decoration by and wrapping in classmethod() and staticmethod().
*/
enum Modifier {
/**
* Function is decorated with @classmethod, its first param is the class.
*/
CLASSMETHOD,
/**
* Function is decorated with {@code @staticmethod}, its first param is as in a regular function.
*/
STATICMETHOD,
}
/**
* Returns a property for which this function is a getter, setter or deleter.
*
* @return the corresponding property, or null if there isn't any.
*/
@Nullable
Property getProperty();
@Nullable
PyAnnotation getAnnotation();
}