diff --git a/python/src/com/jetbrains/python/psi/PyElementType.java b/python/src/com/jetbrains/python/psi/PyElementType.java index 1ae9a3347348..0caf5ea33b73 100644 --- a/python/src/com/jetbrains/python/psi/PyElementType.java +++ b/python/src/com/jetbrains/python/psi/PyElementType.java @@ -11,9 +11,12 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.Constructor; + public class PyElementType extends IElementType { protected Class _psiElementClass; private static final Class[] PARAMETER_TYPES = new Class[]{ASTNode.class}; + private Constructor myConstructor; public PyElementType(@NotNull @NonNls String debugName) { super(debugName, PythonFileType.INSTANCE.getLanguage()); @@ -31,7 +34,11 @@ public class PyElementType extends IElementType { } try { - return _psiElementClass.getConstructor(PARAMETER_TYPES).newInstance(node); + if (myConstructor == null) { + myConstructor = _psiElementClass.getConstructor(PARAMETER_TYPES); + } + + return myConstructor.newInstance(node); } catch (Exception e) { throw new IllegalStateException("No necessary constructor for " + node.getElementType(), e);