Commits

Jan Lahoda committed d976bd0

Trying to improve performance by not creating empty JavaSource for each element separately.

Comments (0)

Files changed (2)

transformer/manifest.mf

 OpenIDE-Module: org.netbeans.modules.jackpot30.transformers
 OpenIDE-Module-Layer: org/netbeans/modules/jackpot30/transformers/resources/layer.xml
 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/transformers/resources/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.0
+OpenIDE-Module-Specification-Version: 1.1
 

transformer/src/org/netbeans/modules/jackpot30/transformers/TransformationHintProviderImpl.java

 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
+import java.util.WeakHashMap;
 import java.util.regex.Matcher;
 import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.element.AnnotationValue;
 @ServiceProvider(service=ElementBasedHintProvider.class)
 public class TransformationHintProviderImpl implements ElementBasedHintProvider {
 
-    public Collection<? extends HintDescription> computeHints(final CompilationInfo info, final Element el) {
-        final List<HintDescription> hints = new LinkedList<HintDescription>();
+    private final Map<CompilationInfo, JavaSource> cachedJavaSources = new WeakHashMap<CompilationInfo, JavaSource>();
 
+    private JavaSource prepareJavaSource(CompilationInfo info) {
+        //XXX: the caching is a hack (to improve performance by not creating new and new JavaSources).
+        //expects that the CompilationInfo will be the same for all elements from the one editor, but that is not guaranteed
+        //ideally, should go away eventually:
+        JavaSource js = cachedJavaSources.get(info);
+
+        if (js != null) {
+            return js;
+        }
+        
         ClasspathInfo currentCP = info.getClasspathInfo();
         ClassPath overlayCompileCP = prepareOverlayCompileCP();
         ClassPath extendedCompileCP = ClassPathSupport.createProxyClassPath(overlayCompileCP, currentCP.getClassPath(PathKind.COMPILE));
         ClassPath extendedBootCP = ClassPathSupport.createProxyClassPath(overlayBootCP, currentCP.getClassPath(PathKind.BOOT));
         ClasspathInfo extendedCPInfo = ClasspathInfo.create(extendedBootCP, extendedCompileCP, currentCP.getClassPath(PathKind.SOURCE));
 
+        cachedJavaSources.put(info, js = JavaSource.create(extendedCPInfo));
+
+        return js;
+    }
+    
+    public Collection<? extends HintDescription> computeHints(final CompilationInfo info, final Element el) {
+        final List<HintDescription> hints = new LinkedList<HintDescription>();
+
         try {
-        JavaSource.create(extendedCPInfo).runUserActionTask(new Task<CompilationController>() {
+        prepareJavaSource(info).runUserActionTask(new Task<CompilationController>() {
             public void run(final CompilationController overlayInfo) throws Exception {
                 List<HintDescription> w = doComputeHints(info, overlayInfo, el);