use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class Session method parseFile.
public synchronized boolean parseFile(final String path) throws ExecutionException {
// java file only
final File file = normalize(path);
if (!FileUtils.isJavaFile(file)) {
return false;
}
boolean b = this.changeProject(path);
final GlobalCache globalCache = GlobalCache.getInstance();
globalCache.invalidateSource(currentProject, file);
Optional<Source> source = this.parseJavaSource(file);
return source.isPresent();
}
use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class ProjectDatabaseHelper method getAllSources.
public static List<Source> getAllSources() {
ProjectDatabase database = ProjectDatabase.getInstance();
return database.computeInReadonly(txn -> {
EntityIterable iterable = txn.getAll(Source.ENTITY_TYPE);
List<Source> result = new ArrayList<>(8);
for (Entity entity : iterable) {
try (InputStream in = entity.getBlob(ProjectDatabase.SERIALIZE_KEY)) {
Source s = Serializer.readObject(in, Source.class);
if (nonNull(s)) {
result.add(s);
}
} catch (Exception e) {
log.warn(e.getMessage());
}
}
return result;
});
}
use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class JavaSourceLoader method loadSource.
private Optional<Source> loadSource(final File sourceFile) throws Exception {
String filePath = sourceFile.getCanonicalPath();
Source source = ProjectDatabaseHelper.loadSource(filePath);
return Optional.ofNullable(source);
}
use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class JavaSourceLoader method load.
@Override
public Source load(final File file) throws IOException {
final Config config = Config.load();
if (!file.exists()) {
return new Source(file.getPath());
}
if (!config.useSourceCache()) {
final CompileResult compileResult = project.parseFile(file);
return compileResult.getSources().get(file);
}
final String projectRootPath = this.project.getProjectRootPath();
final Map<String, String> checksumMap = ProjectDatabaseHelper.getChecksumMap(projectRootPath);
final String path = file.getCanonicalPath();
final String md5sum = FileUtils.getChecksum(file);
if (checksumMap.containsKey(path)) {
// compare checksum
final String prevSum = checksumMap.get(path);
if (md5sum.equals(prevSum)) {
// load from cache
try {
final Optional<Source> source = loadSource(file);
if (source.isPresent()) {
log.debug("hit source cache {}", file);
return source.get();
}
} catch (Exception e) {
log.catching(e);
}
}
}
log.warn("source cache miss {}", file);
final CompileResult compileResult = project.parseFile(file.getCanonicalFile());
return compileResult.getSources().get(file.getCanonicalFile());
}
use of meghanada.analyze.Source in project meghanada-server by mopemope.
the class DeclarationSearcher method searchLocalVariable.
private static Optional<Declaration> searchLocalVariable(final Source source, final Integer line, final Integer col, final String symbol) {
final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
final Optional<Variable> variable = source.getVariable(line, col);
final Optional<Declaration> result = variable.map(var -> {
final Declaration declaration = new Declaration(symbol, var.fqcn, Declaration.Type.VAR, var.argumentIndex);
return Optional.of(declaration);
}).orElseGet(() -> searchFieldVar(source, line, symbol));
log.traceExit(entryMessage);
return result;
}
Aggregations