From d93cfdba007418e571989d03327117f9359cbbde Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Sat, 1 Mar 2008 14:39:04 +0300 Subject: [PATCH] do not recreate PyAnnotator instances for every element --- .../validation/PyAnnotatingVisitor.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/python/src/com/jetbrains/python/validation/PyAnnotatingVisitor.java b/python/src/com/jetbrains/python/validation/PyAnnotatingVisitor.java index eb76446b043f..e6c5ac7f99b2 100644 --- a/python/src/com/jetbrains/python/validation/PyAnnotatingVisitor.java +++ b/python/src/com/jetbrains/python/validation/PyAnnotatingVisitor.java @@ -23,7 +23,8 @@ import com.intellij.psi.PsiElement; import com.jetbrains.python.PythonFileType; import com.jetbrains.python.PythonLanguage; -import java.util.Set; +import java.util.List; +import java.util.ArrayList; /** * Created by IntelliJ IDEA. @@ -33,28 +34,31 @@ import java.util.Set; * To change this template use File | Settings | File Templates. */ public class PyAnnotatingVisitor implements Annotator { - private static final Logger LOGGER - = Logger.getInstance(PyAnnotatingVisitor.class.getName()); - private Set> _annotators; + private static final Logger LOGGER = Logger.getInstance(PyAnnotatingVisitor.class.getName()); + private List myAnnotators = new ArrayList(); public PyAnnotatingVisitor() { - _annotators = ((PythonLanguage) PythonFileType.INSTANCE.getLanguage()).getAnnotators(); + for (Class cls : ((PythonLanguage)PythonFileType.INSTANCE.getLanguage()).getAnnotators()) { + PyAnnotator annotator; + try { + annotator = cls.newInstance(); + } + catch (InstantiationException e) { + LOGGER.error(e); + continue; + } + catch (IllegalAccessException e) { + LOGGER.error(e); + continue; + } + myAnnotators.add(annotator); + } } public void annotate(PsiElement psiElement, AnnotationHolder holder) { - for(Class cls: _annotators) { - PyAnnotator annotator; - try { - annotator = cls.newInstance(); - } catch (InstantiationException e) { - LOGGER.error(e); - continue; - } catch (IllegalAccessException e) { - LOGGER.error(e); - continue; - } - annotator.setHolder(holder); - psiElement.accept(annotator); - } + for(PyAnnotator annotator: myAnnotators) { + annotator.setHolder(holder); + psiElement.accept(annotator); } + } }