Search in sources :

Example 11 with Source

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();
}
Also used : GlobalCache(meghanada.cache.GlobalCache) File(java.io.File) Source(meghanada.analyze.Source)

Example 12 with Source

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;
    });
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Source(meghanada.analyze.Source) IOException(java.io.IOException)

Example 13 with Source

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);
}
Also used : Source(meghanada.analyze.Source)

Example 14 with 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());
}
Also used : Config(meghanada.config.Config) CompileResult(meghanada.analyze.CompileResult) Source(meghanada.analyze.Source) IOException(java.io.IOException)

Example 15 with Source

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;
}
Also used : FileUtils.getSource(meghanada.utils.FileUtils.getSource) ClassIndex(meghanada.reflect.ClassIndex) Set(java.util.Set) IOException(java.io.IOException) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) EntryMessage(org.apache.logging.log4j.message.EntryMessage) File(java.io.File) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExecutionException(java.util.concurrent.ExecutionException) Variable(meghanada.analyze.Variable) MemberDescriptor(meghanada.reflect.MemberDescriptor) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ClassNameUtils(meghanada.utils.ClassNameUtils) Optional(java.util.Optional) Project(meghanada.project.Project) MethodCall(meghanada.analyze.MethodCall) ClassScope(meghanada.analyze.ClassScope) Source(meghanada.analyze.Source) LogManager(org.apache.logging.log4j.LogManager) Joiner(com.google.common.base.Joiner) Variable(meghanada.analyze.Variable) EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Aggregations

Source (meghanada.analyze.Source)16 IOException (java.io.IOException)13 File (java.io.File)12 ArrayList (java.util.ArrayList)11 Config (meghanada.config.Config)11 List (java.util.List)10 Optional (java.util.Optional)10 GlobalCache (meghanada.cache.GlobalCache)10 LogManager (org.apache.logging.log4j.LogManager)10 Logger (org.apache.logging.log4j.Logger)10 InputStream (java.io.InputStream)9 Map (java.util.Map)9 ExecutionException (java.util.concurrent.ExecutionException)9 Project (meghanada.project.Project)9 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)9 UncheckedIOException (java.io.UncheckedIOException)8 HashMap (java.util.HashMap)8 Pattern (java.util.regex.Pattern)8 Stream (java.util.stream.Stream)8 ClassScope (meghanada.analyze.ClassScope)8