Lines 45-56
Link Here
|
45 |
import java.io.FileWriter; |
45 |
import java.io.FileWriter; |
46 |
import java.io.IOException; |
46 |
import java.io.IOException; |
47 |
import java.io.PrintWriter; |
47 |
import java.io.PrintWriter; |
|
|
48 |
import java.lang.ref.Reference; |
49 |
import java.lang.ref.WeakReference; |
48 |
import java.text.MessageFormat; |
50 |
import java.text.MessageFormat; |
49 |
import javax.lang.model.SourceVersion; |
51 |
import javax.lang.model.SourceVersion; |
|
|
52 |
import javax.swing.text.Document; |
50 |
import org.junit.Test; |
53 |
import org.junit.Test; |
|
|
54 |
import org.netbeans.api.java.lexer.JavaTokenId; |
55 |
import org.netbeans.api.java.source.CompilationInfo.CacheClearPolicy; |
56 |
import org.netbeans.api.java.source.JavaSource.Phase; |
57 |
import org.netbeans.api.lexer.Language; |
58 |
import org.netbeans.api.lexer.TokenHierarchy; |
51 |
import org.netbeans.junit.NbTestCase; |
59 |
import org.netbeans.junit.NbTestCase; |
|
|
60 |
import org.openide.cookies.EditorCookie; |
52 |
import org.openide.filesystems.FileObject; |
61 |
import org.openide.filesystems.FileObject; |
53 |
import org.openide.filesystems.FileUtil; |
62 |
import org.openide.filesystems.FileUtil; |
|
|
63 |
import org.openide.loaders.DataObject; |
54 |
|
64 |
|
55 |
/** |
65 |
/** |
56 |
* |
66 |
* |
Lines 67-73
Link Here
|
67 |
|
77 |
|
68 |
@Override |
78 |
@Override |
69 |
public void setUp() throws Exception { |
79 |
public void setUp() throws Exception { |
70 |
SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]); |
80 |
SourceUtilsTestUtil.prepareTest(new String[] {"META-INF/generated-layer.xml"}, new Object[0]); |
71 |
} |
81 |
} |
72 |
|
82 |
|
73 |
/** |
83 |
/** |
Lines 105-108
Link Here
|
105 |
return null; |
115 |
return null; |
106 |
} |
116 |
} |
107 |
} |
117 |
} |
|
|
118 |
|
119 |
public void testCacheEviction() throws Exception { |
120 |
clearWorkDir(); |
121 |
|
122 |
FileObject source = FileUtil.createData(new File(getWorkDir(), "Test.java")); |
123 |
DataObject sourceDO = DataObject.find(source); |
124 |
EditorCookie ec = sourceDO.getLookup().lookup(EditorCookie.class); |
125 |
|
126 |
assertNotNull(ec); |
127 |
|
128 |
Document doc = ec.openDocument(); |
129 |
|
130 |
doc.putProperty(Language.class, JavaTokenId.language()); |
131 |
|
132 |
TokenHierarchy.get(doc).tokenSequence().tokenCount(); |
133 |
|
134 |
TestUtilities.copyStringToFile(source, "public class Test {\n void test() {\n //whatever\n }\n}\n"); |
135 |
|
136 |
JavaSource js = JavaSource.forDocument(doc); |
137 |
|
138 |
js.runUserActionTask(new Task<CompilationController>() { |
139 |
public void run(CompilationController parameter) throws Exception { |
140 |
parameter.toPhase(Phase.RESOLVED); |
141 |
parameter.putCachedValue("1", 1, CacheClearPolicy.ON_TASK_END); |
142 |
parameter.putCachedValue("2", 2, CacheClearPolicy.ON_CHANGE); |
143 |
parameter.putCachedValue("3", 3, CacheClearPolicy.ON_SIGNATURE_CHANGE); |
144 |
} |
145 |
}, true); |
146 |
|
147 |
js.runUserActionTask(new Task<CompilationController>() { |
148 |
public void run(CompilationController parameter) throws Exception { |
149 |
parameter.toPhase(Phase.RESOLVED); |
150 |
assertNull(parameter.getCachedValue("1")); |
151 |
assertEquals(2, parameter.getCachedValue("2")); |
152 |
assertEquals(3, parameter.getCachedValue("3")); |
153 |
} |
154 |
}, true); |
155 |
|
156 |
doc.insertString(41, "a", null); |
157 |
|
158 |
js.runUserActionTask(new Task<CompilationController>() { |
159 |
public void run(CompilationController parameter) throws Exception { |
160 |
parameter.toPhase(Phase.RESOLVED); |
161 |
assertNull(parameter.getCachedValue("1")); |
162 |
assertNull(parameter.getCachedValue("2")); |
163 |
assertEquals(3, parameter.getCachedValue("3")); |
164 |
} |
165 |
}, true); |
166 |
|
167 |
doc.insertString(20, "void t2() {}", null); |
168 |
|
169 |
js.runUserActionTask(new Task<CompilationController>() { |
170 |
public void run(CompilationController parameter) throws Exception { |
171 |
parameter.toPhase(Phase.RESOLVED); |
172 |
assertNull(parameter.getCachedValue("1")); |
173 |
assertNull(parameter.getCachedValue("2")); |
174 |
assertNull(parameter.getCachedValue("3")); |
175 |
} |
176 |
}, true); |
177 |
} |
108 |
} |
178 |
} |