Search in sources :

Example 1 with GlobalCache

use of meghanada.cache.GlobalCache in project meghanada-server by mopemope.

the class FileWatchEventSubscriber method on.

@Subscribe
public void on(final FileSystemWatcher.DeleteEvent event) {
    final File file = event.getFile();
    try {
        String filePath = file.getCanonicalPath();
        GlobalCache globalCache = GlobalCache.getInstance();
        Project project = sessionEventBus.getSession().getCurrentProject();
        globalCache.invalidateSource(project, file);
        ProjectDatabaseHelper.deleteSource(filePath);
        FileUtils.getClassFile(filePath, project.getSources(), project.getOutput()).ifPresent(File::delete);
        FileUtils.getClassFile(filePath, project.getTestSources(), project.getTestOutput()).ifPresent(File::delete);
    } catch (Throwable e) {
        log.catching(e);
    }
}
Also used : GlobalCache(meghanada.cache.GlobalCache) Project(meghanada.project.Project) File(java.io.File) Subscribe(com.google.common.eventbus.Subscribe)

Example 2 with GlobalCache

use of meghanada.cache.GlobalCache 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());
}
Also used : FieldDescriptor(meghanada.reflect.FieldDescriptor) LoadingCache(com.google.common.cache.LoadingCache) AccessSymbol(meghanada.analyze.AccessSymbol) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Variable(meghanada.analyze.Variable) Map(java.util.Map) CandidateUnit(meghanada.reflect.CandidateUnit) MethodCall(meghanada.analyze.MethodCall) ClassScope(meghanada.analyze.ClassScope) GlobalCache(meghanada.cache.GlobalCache) ClassIndex(meghanada.reflect.ClassIndex) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) Collectors(java.util.stream.Collectors) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) MemberDescriptor(meghanada.reflect.MemberDescriptor) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) ClassNameUtils(meghanada.utils.ClassNameUtils) Optional(java.util.Optional) Project(meghanada.project.Project) Source(meghanada.analyze.Source) Objects.nonNull(java.util.Objects.nonNull) Comparator(java.util.Comparator) Collections(java.util.Collections) TypeScope(meghanada.analyze.TypeScope) Config(meghanada.config.Config) LogManager(org.apache.logging.log4j.LogManager) GlobalCache(meghanada.cache.GlobalCache) File(java.io.File) Source(meghanada.analyze.Source)

Example 3 with GlobalCache

use of meghanada.cache.GlobalCache 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 4 with GlobalCache

use of meghanada.cache.GlobalCache in project meghanada-server by mopemope.

the class CachedASMReflector method reflect.

public List<MemberDescriptor> reflect(final String className) {
    final ClassName cn = new ClassName(className);
    // check type parameter
    final String classWithoutTP = cn.getName();
    final GlobalCache globalCache = GlobalCache.getInstance();
    try {
        final List<MemberDescriptor> members = new ArrayList<>(16);
        List<MemberDescriptor> list = globalCache.getMemberDescriptors(classWithoutTP);
        for (final MemberDescriptor md : list) {
            members.add(md.clone());
        }
        if (cn.hasTypeParameter()) {
            return this.replaceMembers(classWithoutTP, className, members);
        }
        return members;
    } catch (ExecutionException e) {
        throw new UncheckedExecutionException(e);
    }
}
Also used : GlobalCache(meghanada.cache.GlobalCache) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) MemberDescriptor(meghanada.reflect.MemberDescriptor) ClassName(meghanada.utils.ClassName) ArrayList(java.util.ArrayList) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with GlobalCache

use of meghanada.cache.GlobalCache in project meghanada-server by mopemope.

the class Source method invalidateCache.

private void invalidateCache(final List<ClassScope> classScopes) {
    final GlobalCache globalCache = GlobalCache.getInstance();
    for (final ClassScope classScope : classScopes) {
        globalCache.invalidateMemberDescriptors(classScope.getFQCN());
        this.invalidateCache(classScope.classScopes);
    }
}
Also used : GlobalCache(meghanada.cache.GlobalCache)

Aggregations

GlobalCache (meghanada.cache.GlobalCache)5 File (java.io.File)3 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 Source (meghanada.analyze.Source)2 Project (meghanada.project.Project)2 MemberDescriptor (meghanada.reflect.MemberDescriptor)2 LoadingCache (com.google.common.cache.LoadingCache)1 Subscribe (com.google.common.eventbus.Subscribe)1 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects.nonNull (java.util.Objects.nonNull)1 Optional (java.util.Optional)1 Set (java.util.Set)1