use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class LocationSearcher method searchDeclarationLocation.
public Optional<Location> searchDeclarationLocation(final File file, final int line, final int column, final String symbol) throws ExecutionException, IOException {
final Source source = getSource(project, file);
log.trace("search symbol {}", symbol);
return this.functions.stream().map(f -> f.apply(source, line, column, symbol)).filter(Optional::isPresent).findFirst().orElse(Optional.empty());
}
use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class GlobalCache method getSourceCache.
public LoadingCache<File, Source> getSourceCache(final Project project) {
final File projectRoot = project.getProjectRoot();
if (this.sourceCaches.containsKey(projectRoot)) {
return this.sourceCaches.get(projectRoot);
} else {
final JavaSourceLoader javaSourceLoader = new JavaSourceLoader(project);
int size = Config.load().getSourceCacheSize();
final LoadingCache<File, Source> loadingCache = CacheBuilder.newBuilder().maximumSize(size).expireAfterAccess(10, TimeUnit.MINUTES).removalListener(javaSourceLoader).build(javaSourceLoader);
this.sourceCaches.put(projectRoot, loadingCache);
return loadingCache;
}
}
use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class JavaSourceLoader method onRemoval.
@Override
public void onRemoval(final RemovalNotification<File, Source> notification) {
final RemovalCause cause = notification.getCause();
final Config config = Config.load();
if (config.useSourceCache() && cause.equals(RemovalCause.EXPLICIT)) {
final Source source = notification.getValue();
try {
deleteSource(source);
} catch (Exception e) {
log.catching(e);
}
}
}
use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class JavaCompletion method completionPackage.
private Collection<? extends CandidateUnit> completionPackage() {
final GlobalCache globalCache = GlobalCache.getInstance();
final LoadingCache<File, Source> sourceCache = globalCache.getSourceCache(project);
return sourceCache.asMap().values().stream().map(source -> ClassIndex.createPackage(source.getPackageName())).collect(Collectors.toSet());
}
use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class Session method addImport.
public synchronized boolean addImport(final String path, final String fqcn) throws ExecutionException {
// java file only
final File file = normalize(path);
if (!FileUtils.isJavaFile(file)) {
return false;
}
boolean b = this.changeProject(path);
log.debug("addImport path={} fqcn={}", path, fqcn);
return parseJavaSource(file).map(source -> source.addImportIfAbsent(fqcn)).orElse(false);
}
Aggregations