Search in sources :

Example 6 with Source

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());
}
Also used : DecompilationListener(org.jboss.windup.decompiler.api.DecompilationListener) FunctionUtils.wrapIOConsumer(meghanada.utils.FunctionUtils.wrapIOConsumer) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) Map(java.util.Map) ZipFile(java.util.zip.ZipFile) MethodCall(meghanada.analyze.MethodCall) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) FunctionUtils.wrapIO(meghanada.utils.FunctionUtils.wrapIO) GlobalCache(meghanada.cache.GlobalCache) SimpleName(com.github.javaparser.ast.expr.SimpleName) TypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration) StandardOpenOption(java.nio.file.StandardOpenOption) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MethodScope(meghanada.analyze.MethodScope) ClassNameUtils(meghanada.utils.ClassNameUtils) Optional(java.util.Optional) Project(meghanada.project.Project) Pattern(java.util.regex.Pattern) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) Parameter(com.github.javaparser.ast.body.Parameter) Position(com.github.javaparser.Position) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) Variable(meghanada.analyze.Variable) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ClassScope(meghanada.analyze.ClassScope) OutputStream(java.io.OutputStream) Filter(org.jboss.windup.decompiler.util.Filter) DecompilationResult(org.jboss.windup.decompiler.api.DecompilationResult) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration) FileOutputStream(java.io.FileOutputStream) FileUtils.existsFQCN(meghanada.utils.FileUtils.existsFQCN) IOException(java.io.IOException) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) FileUtils(meghanada.utils.FileUtils) EntryMessage(org.apache.logging.log4j.message.EntryMessage) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Paths(java.nio.file.Paths) Source(meghanada.analyze.Source) FernflowerDecompiler(org.jboss.windup.decompiler.fernflower.FernflowerDecompiler) TypeScope(meghanada.analyze.TypeScope) LogManager(org.apache.logging.log4j.LogManager) JavaParser(com.github.javaparser.JavaParser) InputStream(java.io.InputStream) Optional(java.util.Optional) Source(meghanada.analyze.Source)

Example 7 with Source

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

Example 8 with Source

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);
        }
    }
}
Also used : Config(meghanada.config.Config) RemovalCause(com.google.common.cache.RemovalCause) Source(meghanada.analyze.Source) IOException(java.io.IOException)

Example 9 with Source

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());
}
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 10 with Source

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);
}
Also used : MavenProject(meghanada.project.maven.MavenProject) Matcher(java.util.regex.Matcher) Diagnostic(javax.tools.Diagnostic) Map(java.util.Map) CandidateUnit(meghanada.reflect.CandidateUnit) Objects.isNull(java.util.Objects.isNull) Path(java.nio.file.Path) GlobalCache(meghanada.cache.GlobalCache) TypeInfoSearcher(meghanada.typeinfo.TypeInfoSearcher) Collection(java.util.Collection) CompileResult(meghanada.analyze.CompileResult) StandardOpenOption(java.nio.file.StandardOpenOption) GradleProject(meghanada.project.gradle.GradleProject) Set(java.util.Set) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) JavaFileObject(javax.tools.JavaFileObject) List(java.util.List) Declaration(meghanada.docs.declaration.Declaration) Stream(java.util.stream.Stream) TypeInfo(meghanada.typeinfo.TypeInfo) Logger(org.apache.logging.log4j.Logger) Optional(java.util.Optional) Project(meghanada.project.Project) Pattern(java.util.regex.Pattern) Objects.nonNull(java.util.Objects.nonNull) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) Joiner(com.google.common.base.Joiner) Location(meghanada.location.Location) Stopwatch(com.google.common.base.Stopwatch) HashMap(java.util.HashMap) JavaCompletion(meghanada.completion.JavaCompletion) Deque(java.util.Deque) ArrayList(java.util.ArrayList) JavaVariableCompletion(meghanada.completion.JavaVariableCompletion) HashSet(java.util.HashSet) Reference(meghanada.reference.Reference) ReferenceSearcher(meghanada.reference.ReferenceSearcher) LocationSearcher(meghanada.location.LocationSearcher) LocalVariable(meghanada.completion.LocalVariable) Properties(java.util.Properties) Files(java.nio.file.Files) IOException(java.io.IOException) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) FileUtils(meghanada.utils.FileUtils) EntryMessage(org.apache.logging.log4j.message.EntryMessage) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) Paths(java.nio.file.Paths) ModuleHelper(meghanada.module.ModuleHelper) Source(meghanada.analyze.Source) DeclarationSearcher(meghanada.docs.declaration.DeclarationSearcher) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) File(java.io.File)

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