Search in sources :

Example 16 with Project

use of meghanada.project.Project in project meghanada-server by mopemope.

the class GradleTestBase method setupProject.

@SuppressWarnings("CheckReturnValue")
public static void setupProject(boolean useCache) throws Exception {
    if (useCache) {
        System.setProperty("meghanada.source.cache", "true");
    } else {
        System.setProperty("meghanada.source.cache", "false");
    }
    if (project == null) {
        // replace tmp
        Project newProject = new GradleProject(new File("./").getCanonicalFile());
        final File tempDir = Files.createTempDir();
        tempDir.deleteOnExit();
        final String path = tempDir.getCanonicalPath();
        System.setProperty(TEMP_PROJECT_SETTING_DIR, path);
        log.info("create database {}", path);
        project = newProject.parseProject().mergeFromProjectConfig();
    }
    Config config = Config.load();
    if (useCache) {
        config.update("source-cache", true);
    } else {
        config.update("source-cache", false);
    }
    log.info("finish setupProject");
}
Also used : GradleProject(meghanada.project.gradle.GradleProject) Project(meghanada.project.Project) Config(meghanada.config.Config) GradleProject(meghanada.project.gradle.GradleProject) File(java.io.File)

Example 17 with Project

use of meghanada.project.Project in project meghanada-server by mopemope.

the class AnnoTest2 method init.

@BeforeSuite
public static void init() throws Exception {
    final Project project = new GradleProject(new File("./").getCanonicalFile());
    project.parseProject();
    project.compileJava(false);
    project.compileTestJava(false);
    List<String> list = new ArrayList<>();
    final JCDiagnostic.DiagnosticPosition pos = null;
}
Also used : GradleProject(meghanada.project.gradle.GradleProject) Project(meghanada.project.Project) GradleProject(meghanada.project.gradle.GradleProject) File(java.io.File)

Example 18 with Project

use of meghanada.project.Project in project meghanada-server by mopemope.

the class LocationSearcher method getFieldLocationFromProject.

private Optional<Location> getFieldLocationFromProject(final String fqcn, final String fieldName, final File file) {
    try {
        final Source declaringClassSrc = getSource(project, file);
        final String path = declaringClassSrc.getFile().getPath();
        return declaringClassSrc.getClassScopes().stream().map(cs -> getMatchField(cs, fqcn, fieldName)).filter(Optional::isPresent).map(optional -> {
            final Variable variable = optional.get();
            return new Location(path, variable.range.begin.line, variable.range.begin.column);
        }).findFirst();
    } catch (Exception e) {
        throw new UncheckedExecutionException(e);
    }
}
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) Variable(meghanada.analyze.Variable) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Optional(java.util.Optional) Source(meghanada.analyze.Source) UncheckedIOException(java.io.UncheckedIOException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Project (meghanada.project.Project)18 File (java.io.File)13 Config (meghanada.config.Config)10 IOException (java.io.IOException)8 GradleProject (meghanada.project.gradle.GradleProject)8 LogManager (org.apache.logging.log4j.LogManager)8 Logger (org.apache.logging.log4j.Logger)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Map (java.util.Map)7 ExecutionException (java.util.concurrent.ExecutionException)7 GlobalCache (meghanada.cache.GlobalCache)7 ProjectDependency (meghanada.project.ProjectDependency)7 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)7 InputStream (java.io.InputStream)6 UncheckedIOException (java.io.UncheckedIOException)6 HashMap (java.util.HashMap)6 Optional (java.util.Optional)6 Stream (java.util.stream.Stream)6 Source (meghanada.analyze.Source)6