Lines 46-55
Link Here
|
46 |
import org.netbeans.api.java.classpath.GlobalPathRegistryEvent; |
46 |
import org.netbeans.api.java.classpath.GlobalPathRegistryEvent; |
47 |
import org.netbeans.api.java.source.ClasspathInfo; |
47 |
import org.netbeans.api.java.source.ClasspathInfo; |
48 |
import org.netbeans.spi.java.classpath.support.ClassPathSupport; |
48 |
import org.netbeans.spi.java.classpath.support.ClassPathSupport; |
49 |
import java.util.ArrayList; |
|
|
50 |
import java.util.EnumSet; |
49 |
import java.util.EnumSet; |
51 |
import java.util.HashSet; |
50 |
import java.util.HashSet; |
52 |
import java.util.List; |
|
|
53 |
import java.util.Set; |
51 |
import java.util.Set; |
54 |
import java.util.logging.Logger; |
52 |
import java.util.logging.Logger; |
55 |
import javax.lang.model.element.TypeElement; |
53 |
import javax.lang.model.element.TypeElement; |
Lines 63-68
Link Here
|
63 |
import org.netbeans.api.java.source.CompilationController; |
61 |
import org.netbeans.api.java.source.CompilationController; |
64 |
import org.netbeans.api.java.source.ElementHandle; |
62 |
import org.netbeans.api.java.source.ElementHandle; |
65 |
import org.netbeans.api.java.source.JavaSource; |
63 |
import org.netbeans.api.java.source.JavaSource; |
|
|
64 |
import org.netbeans.api.java.source.SourceUtils; |
66 |
import org.netbeans.api.java.source.Task; |
65 |
import org.netbeans.api.java.source.Task; |
67 |
import org.netbeans.api.java.source.ui.TypeElementFinder; |
66 |
import org.netbeans.api.java.source.ui.TypeElementFinder; |
68 |
import org.netbeans.api.project.FileOwnerQuery; |
67 |
import org.netbeans.api.project.FileOwnerQuery; |
Lines 73-79
Link Here
|
73 |
import org.netbeans.modules.java.source.usages.RepositoryUpdater; |
72 |
import org.netbeans.modules.java.source.usages.RepositoryUpdater; |
74 |
import org.netbeans.spi.java.classpath.support.ClassPathSupport; |
73 |
import org.netbeans.spi.java.classpath.support.ClassPathSupport; |
75 |
import org.netbeans.spi.jumpto.type.SearchType; |
74 |
import org.netbeans.spi.jumpto.type.SearchType; |
76 |
import org.netbeans.spi.jumpto.type.TypeDescriptor; |
|
|
77 |
import org.netbeans.spi.jumpto.type.TypeProvider; |
75 |
import org.netbeans.spi.jumpto.type.TypeProvider; |
78 |
import org.openide.filesystems.FileObject; |
76 |
import org.openide.filesystems.FileObject; |
79 |
import org.openide.filesystems.FileStateInvalidException; |
77 |
import org.openide.filesystems.FileStateInvalidException; |
Lines 91-96
Link Here
|
91 |
private final TypeElementFinder.Customizer customizer; |
89 |
private final TypeElementFinder.Customizer customizer; |
92 |
private ClasspathInfo cpInfo; |
90 |
private ClasspathInfo cpInfo; |
93 |
private GlobalPathRegistryListener pathListener; |
91 |
private GlobalPathRegistryListener pathListener; |
|
|
92 |
private boolean cpChanged = false; |
94 |
|
93 |
|
95 |
public String name() { |
94 |
public String name() { |
96 |
return "java"; // NOI18N |
95 |
return "java"; // NOI18N |
Lines 116-126
Link Here
|
116 |
pathListener = new GlobalPathRegistryListener() { |
115 |
pathListener = new GlobalPathRegistryListener() { |
117 |
|
116 |
|
118 |
public void pathsAdded(GlobalPathRegistryEvent event) { |
117 |
public void pathsAdded(GlobalPathRegistryEvent event) { |
119 |
cache = null; cpInfo = null; |
118 |
if (cache != null) { |
|
|
119 |
cache = null; |
120 |
cpChanged = true; |
121 |
} |
122 |
cpInfo = null; |
120 |
} |
123 |
} |
121 |
|
124 |
|
122 |
public void pathsRemoved(GlobalPathRegistryEvent event) { |
125 |
public void pathsRemoved(GlobalPathRegistryEvent event) { |
123 |
cache = null; cpInfo = null; |
126 |
if (cache != null) { |
|
|
127 |
cache = null; |
128 |
cpChanged = true; |
129 |
} |
130 |
cpInfo = null; |
124 |
} |
131 |
} |
125 |
}; |
132 |
}; |
126 |
GlobalPathRegistry.getDefault().addGlobalPathRegistryListener(pathListener); |
133 |
GlobalPathRegistry.getDefault().addGlobalPathRegistryListener(pathListener); |
Lines 148-156
Link Here
|
148 |
// } |
155 |
// } |
149 |
// } |
156 |
// } |
150 |
|
157 |
|
151 |
public List<? extends TypeDescriptor> getTypeNames(Project project, String text, SearchType searchType) { |
158 |
public void computeTypeNames(Context context, Result res) { |
|
|
159 |
String text = context.getText(); |
160 |
SearchType searchType = context.getSearchType(); |
161 |
|
152 |
boolean hasBinaryOpen = Lookup.getDefault().lookup(BinaryElementOpen.class) != null; |
162 |
boolean hasBinaryOpen = Lookup.getDefault().lookup(BinaryElementOpen.class) != null; |
153 |
final ClassIndex.NameKind nameKind; |
163 |
final ClassIndex.NameKind nameKind; |
|
|
164 |
|
154 |
switch (searchType) { |
165 |
switch (searchType) { |
155 |
case EXACT_NAME: nameKind = ClassIndex.NameKind.SIMPLE_NAME; break; |
166 |
case EXACT_NAME: nameKind = ClassIndex.NameKind.SIMPLE_NAME; break; |
156 |
case CASE_INSENSITIVE_EXACT_NAME: nameKind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP; break; |
167 |
case CASE_INSENSITIVE_EXACT_NAME: nameKind = ClassIndex.NameKind.CASE_INSENSITIVE_REGEXP; break; |
Lines 167-172
Link Here
|
167 |
long cp, gss, gsb, sfb, gtn, add, sort; |
178 |
long cp, gss, gsb, sfb, gtn, add, sort; |
168 |
cp = gss = gsb = sfb = gtn = add = sort = 0; |
179 |
cp = gss = gsb = sfb = gtn = add = sort = 0; |
169 |
|
180 |
|
|
|
181 |
// if scan is running set the message |
182 |
if (cpChanged || SourceUtils.isScanInProgress()) { |
183 |
res.setMessage("Result could be incomplete!"); |
184 |
} else { |
185 |
res.setMessage(null); |
186 |
} |
187 |
cpChanged = false; |
188 |
|
170 |
if (cache == null) { |
189 |
if (cache == null) { |
171 |
Set<CacheItem> sources = null; |
190 |
Set<CacheItem> sources = null; |
172 |
|
191 |
|
Lines 183-189
Link Here
|
183 |
time = System.currentTimeMillis(); |
202 |
time = System.currentTimeMillis(); |
184 |
ClasspathInfo ci = ClasspathInfo.create( EMPTY_CLASSPATH, EMPTY_CLASSPATH, ClassPathSupport.createClassPath(root)); //create(roots[i]); |
203 |
ClasspathInfo ci = ClasspathInfo.create( EMPTY_CLASSPATH, EMPTY_CLASSPATH, ClassPathSupport.createClassPath(root)); //create(roots[i]); |
185 |
if ( isCanceled ) { |
204 |
if ( isCanceled ) { |
186 |
return null; |
205 |
return; |
187 |
} |
206 |
} |
188 |
else { |
207 |
else { |
189 |
sources.add( new CacheItem( roots[i], ci, false ) ); |
208 |
sources.add( new CacheItem( roots[i], ci, false ) ); |
Lines 202-208
Link Here
|
202 |
for (int i = 0; i < roots.length; i++ ) { |
221 |
for (int i = 0; i < roots.length; i++ ) { |
203 |
try { |
222 |
try { |
204 |
if ( isCanceled ) { |
223 |
if ( isCanceled ) { |
205 |
return null; |
224 |
return; |
206 |
} |
225 |
} |
207 |
time = System.currentTimeMillis(); |
226 |
time = System.currentTimeMillis(); |
208 |
if (!hasBinaryOpen) { |
227 |
if (!hasBinaryOpen) { |
Lines 223-229
Link Here
|
223 |
} |
242 |
} |
224 |
finally { |
243 |
finally { |
225 |
if ( isCanceled ) { |
244 |
if ( isCanceled ) { |
226 |
return null; |
245 |
return; |
227 |
} |
246 |
} |
228 |
} |
247 |
} |
229 |
} |
248 |
} |
Lines 239-245
Link Here
|
239 |
time = System.currentTimeMillis(); |
258 |
time = System.currentTimeMillis(); |
240 |
ClasspathInfo ci = ClasspathInfo.create(ClassPathSupport.createClassPath(bootRoots[i]), EMPTY_CLASSPATH, EMPTY_CLASSPATH); |
259 |
ClasspathInfo ci = ClasspathInfo.create(ClassPathSupport.createClassPath(bootRoots[i]), EMPTY_CLASSPATH, EMPTY_CLASSPATH); |
241 |
if ( isCanceled ) { |
260 |
if ( isCanceled ) { |
242 |
return null; |
261 |
return; |
243 |
} |
262 |
} |
244 |
else { |
263 |
else { |
245 |
sources.add( new CacheItem( bootRoots[i], ci, true ) ); |
264 |
sources.add( new CacheItem( bootRoots[i], ci, true ) ); |
Lines 252-258
Link Here
|
252 |
time = System.currentTimeMillis(); |
271 |
time = System.currentTimeMillis(); |
253 |
ClasspathInfo ci = ClasspathInfo.create(EMPTY_CLASSPATH, ClassPathSupport.createClassPath(compileRoots[i]), EMPTY_CLASSPATH); |
272 |
ClasspathInfo ci = ClasspathInfo.create(EMPTY_CLASSPATH, ClassPathSupport.createClassPath(compileRoots[i]), EMPTY_CLASSPATH); |
254 |
if ( isCanceled ) { |
273 |
if ( isCanceled ) { |
255 |
return null; |
274 |
return; |
256 |
} |
275 |
} |
257 |
else { |
276 |
else { |
258 |
sources.add( new CacheItem( compileRoots[i], ci, true ) ); |
277 |
sources.add( new CacheItem( compileRoots[i], ci, true ) ); |
Lines 265-271
Link Here
|
265 |
time = System.currentTimeMillis(); |
284 |
time = System.currentTimeMillis(); |
266 |
ClasspathInfo ci = ClasspathInfo.create(EMPTY_CLASSPATH, EMPTY_CLASSPATH, ClassPathSupport.createClassPath(sourceRoots[i])); |
285 |
ClasspathInfo ci = ClasspathInfo.create(EMPTY_CLASSPATH, EMPTY_CLASSPATH, ClassPathSupport.createClassPath(sourceRoots[i])); |
267 |
if ( isCanceled ) { |
286 |
if ( isCanceled ) { |
268 |
return null; |
287 |
return; |
269 |
} |
288 |
} |
270 |
else { |
289 |
else { |
271 |
sources.add( new CacheItem( sourceRoots[i], ci, false ) ); |
290 |
sources.add( new CacheItem( sourceRoots[i], ci, false ) ); |
Lines 279-291
Link Here
|
279 |
cache = sources; |
298 |
cache = sources; |
280 |
} |
299 |
} |
281 |
else { |
300 |
else { |
282 |
return null; |
301 |
return; |
283 |
} |
302 |
} |
284 |
|
303 |
|
285 |
} |
304 |
} |
286 |
|
305 |
|
287 |
ArrayList<JavaTypeDescription> types = new ArrayList<JavaTypeDescription>(cache.size() * 20); |
|
|
288 |
|
289 |
for(final CacheItem ci : cache) { |
306 |
for(final CacheItem ci : cache) { |
290 |
time = System.currentTimeMillis(); |
307 |
time = System.currentTimeMillis(); |
291 |
|
308 |
|
Lines 306-311
Link Here
|
306 |
if (customizer != null) { |
323 |
if (customizer != null) { |
307 |
names = customizer.query(ci.classpathInfo, textForQuery, nameKind, EnumSet.of(ci.isBinary ? ClassIndex.SearchScope.DEPENDENCIES : ClassIndex.SearchScope.SOURCE)); |
324 |
names = customizer.query(ci.classpathInfo, textForQuery, nameKind, EnumSet.of(ci.isBinary ? ClassIndex.SearchScope.DEPENDENCIES : ClassIndex.SearchScope.SOURCE)); |
308 |
} else { |
325 |
} else { |
|
|
326 |
@SuppressWarnings("unchecked") |
309 |
final Set<ElementHandle<TypeElement>>[] n = new Set[1]; |
327 |
final Set<ElementHandle<TypeElement>>[] n = new Set[1]; |
310 |
JavaSource source = JavaSource.create(ci.classpathInfo, new FileObject[0]); |
328 |
JavaSource source = JavaSource.create(ci.classpathInfo, new FileObject[0]); |
311 |
try { |
329 |
try { |
Lines 322-328
Link Here
|
322 |
} |
340 |
} |
323 |
|
341 |
|
324 |
if ( isCanceled ) { |
342 |
if ( isCanceled ) { |
325 |
return null; |
343 |
return; |
326 |
} |
344 |
} |
327 |
|
345 |
|
328 |
gtn += System.currentTimeMillis() - time; |
346 |
gtn += System.currentTimeMillis() - time; |
Lines 334-343
Link Here
|
334 |
// Removed because of bad performance To reenable see diff between 1.15 and 1.16 |
352 |
// Removed because of bad performance To reenable see diff between 1.15 and 1.16 |
335 |
// if (defEntry.includes(convertToSourceName(name.getBinaryName()))) { |
353 |
// if (defEntry.includes(convertToSourceName(name.getBinaryName()))) { |
336 |
JavaTypeDescription td = new JavaTypeDescription(ci, name ); |
354 |
JavaTypeDescription td = new JavaTypeDescription(ci, name ); |
337 |
types.add(td); |
355 |
res.addResult(td); |
338 |
// } |
356 |
// } |
339 |
if ( isCanceled ) { |
357 |
if ( isCanceled ) { |
340 |
return null; |
358 |
return; |
341 |
} |
359 |
} |
342 |
} |
360 |
} |
343 |
add += System.currentTimeMillis() - time; |
361 |
add += System.currentTimeMillis() - time; |
Lines 349-358
Link Here
|
349 |
// Collections.sort(types); |
367 |
// Collections.sort(types); |
350 |
sort += System.currentTimeMillis() - time; |
368 |
sort += System.currentTimeMillis() - time; |
351 |
LOGGER.fine("PERF - " + " GSS: " + gss + " GSB " + gsb + " CP: " + cp + " SFB: " + sfb + " GTN: " + gtn + " ADD: " + add + " SORT: " + sort ); |
369 |
LOGGER.fine("PERF - " + " GSS: " + gss + " GSB " + gsb + " CP: " + cp + " SFB: " + sfb + " GTN: " + gtn + " ADD: " + add + " SORT: " + sort ); |
352 |
return types; |
370 |
return; |
353 |
} |
371 |
} |
354 |
else { |
372 |
else { |
355 |
return null; |
373 |
return; |
356 |
} |
374 |
} |
357 |
} |
375 |
} |
358 |
|
376 |
|