1 19 package org.netbeans.modules.java.editor.semantic; 20 21 import java.lang.ref.Reference ; 22 import java.lang.ref.WeakReference ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.List ; 27 import java.util.Map ; 28 import java.util.WeakHashMap ; 29 import javax.swing.text.Document ; 30 import org.netbeans.modules.editor.errorstripe.privatespi.Mark; 31 import org.netbeans.modules.editor.errorstripe.privatespi.MarkProvider; 32 import org.netbeans.modules.editor.highlights.spi.Highlight; 33 34 38 public class OccurrencesMarkProvider extends MarkProvider { 39 40 private static Map <Document , Reference <OccurrencesMarkProvider>> providers = new WeakHashMap <Document , Reference <OccurrencesMarkProvider>>(); 41 42 public static synchronized OccurrencesMarkProvider get(Document doc) { 43 Reference <OccurrencesMarkProvider> ref = providers.get(doc); 44 OccurrencesMarkProvider p = ref != null ? ref.get() : null; 45 46 if (p == null) { 47 providers.put(doc, new WeakReference (p = new OccurrencesMarkProvider())); 48 } 49 50 return p; 51 } 52 53 private List <Mark> semantic; 54 private List <Mark> occurrences; 55 private List <Mark> joint; 56 57 58 private OccurrencesMarkProvider() { 59 semantic = Collections.emptyList(); 60 occurrences = Collections.emptyList(); 61 joint = Collections.emptyList(); 62 } 63 64 public synchronized List getMarks() { 65 return joint; 66 } 67 68 public void setSematic(Collection <Highlight> s) { 69 List <Mark> old; 70 List <Mark> nue; 71 72 synchronized (this) { 73 semantic = new ArrayList <Mark>(); 74 75 for (Highlight h : s) { 76 if (h != null && h instanceof Mark && ((Mark) h).getEnhancedColor() != null) 77 semantic.add((Mark) h); 78 } 79 80 old = joint; 81 82 nue = joint = new ArrayList <Mark>(); 83 84 joint.addAll(semantic); 85 joint.addAll(occurrences); 86 } 87 88 firePropertyChange(PROP_MARKS, old, nue); 90 } 91 92 public void setOccurrences(Collection <Highlight> s) { 93 List <Mark> old; 94 List <Mark> nue; 95 96 synchronized (this) { 97 occurrences = new ArrayList <Mark>(); 98 99 for (Highlight h : s) { 100 if (h != null && h instanceof Mark && ((Mark) h).getEnhancedColor() != null) 101 occurrences.add((Mark) h); 102 } 103 104 old = joint; 105 106 nue = joint = new ArrayList <Mark>(); 107 108 joint.addAll(semantic); 109 joint.addAll(occurrences); 110 } 111 112 firePropertyChange(PROP_MARKS, old, nue); 114 } 115 116 } 117 | Popular Tags |