use of meghanada.project.Project in project meghanada-server by mopemope.
the class CacheEventSubscriber method analyze.
private void analyze() {
final Stopwatch stopwatch = Stopwatch.createStarted();
final Session session = super.sessionEventBus.getSession();
final Project project = session.getCurrentProject();
final CachedASMReflector reflector = CachedASMReflector.getInstance();
reflector.addClasspath(project.getOutput());
reflector.addClasspath(project.getTestOutput());
project.getDependencies().stream().filter(pd -> pd.getType().equals(ProjectDependency.Type.PROJECT)).forEach(pd -> {
final File df = new File(pd.getDependencyFilePath());
if (df.exists() && df.isDirectory()) {
reflector.addClasspath(df);
}
});
final Collection<File> dependentJars = session.getDependentJars();
final int size = dependentJars.size();
timeItF("create class index ... read " + size + " jars. elapsed:{}", () -> {
reflector.addClasspath(dependentJars);
reflector.createClassIndexes();
});
if (cleanUnusedSource(project)) {
project.resetCallerMap();
}
log.info("start analyze sources ...");
timeItF("analyzed and compiled. elapsed:{}", () -> {
try {
final CompileResult compileResult = project.compileJava();
if (compileResult.isSuccess()) {
if (compileResult.hasDiagnostics()) {
log.warn("compile message: {}", compileResult.getDiagnosticsSummary());
}
final CompileResult testCompileResult = project.compileTestJava();
if (testCompileResult.isSuccess()) {
if (testCompileResult.hasDiagnostics()) {
log.warn("compile(test) message: {}", testCompileResult.getDiagnosticsSummary());
}
} else {
log.warn("compile(test) error: {}", testCompileResult.getDiagnosticsSummary());
}
} else {
log.warn("compile message {}", compileResult.getDiagnosticsSummary());
}
} catch (Exception e) {
log.catching(e);
}
});
final Runtime runtime = Runtime.getRuntime();
final float maxMemory = runtime.maxMemory() / 1024 / 1024;
final float totalMemory = runtime.totalMemory() / 1024 / 1024;
final float usedMemory = (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024;
log.info("class index size:{} total elapsed:{}", reflector.getGlobalClassIndex().size(), stopwatch.stop());
Config.showMemory();
log.info("Ready");
}
use of meghanada.project.Project in project meghanada-server by mopemope.
the class GradleProject method parseProject.
@Override
public Project parseProject() throws ProjectParseException {
final ProjectConnection connection = getProjectConnection();
log.info("loading gradle project:{}", new File(this.projectRoot, Project.GRADLE_PROJECT_FILE));
try {
BuildEnvironment env = connection.getModel(BuildEnvironment.class);
String version = env.getGradle().getGradleVersion();
if (isNull(version)) {
version = GradleVersion.current().getVersion();
}
if (nonNull(version)) {
this.gradleVersion = new ComparableVersion(version);
}
final IdeaProject ideaProject = debugTimeItF("get idea project model elapsed={}", () -> connection.getModel(IdeaProject.class));
this.setCompileTarget(ideaProject);
log.trace("load root project path:{}", this.rootProject);
final DomainObjectSet<? extends IdeaModule> modules = ideaProject.getModules();
final List<? extends IdeaModule> mainModules = modules.parallelStream().filter(ideaModule -> {
final org.gradle.tooling.model.GradleProject gradleProject = ideaModule.getGradleProject();
final File moduleProjectRoot = gradleProject.getProjectDirectory();
final String name = ideaModule.getName();
log.trace("find sub-module name {} path {} ", name, moduleProjectRoot);
this.allModules.putIfAbsent(name, moduleProjectRoot);
return moduleProjectRoot.equals(this.getProjectRoot());
}).collect(Collectors.toList());
mainModules.forEach(wrapIOConsumer(this::parseIdeaModule));
// set default output
if (isNull(super.output)) {
String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "main");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "main");
}
super.output = this.normalize(build);
}
if (isNull(super.testOutput)) {
String build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "test");
if (nonNull(gradleVersion) && gradleVersion.compareTo(new ComparableVersion("4.0")) >= 0) {
build = Joiner.on(File.separator).join(this.projectRoot, "build", "classes", "java", "test");
}
super.testOutput = this.normalize(build);
}
return this;
} catch (Exception e) {
throw new ProjectParseException(e);
} finally {
connection.close();
}
}
use of meghanada.project.Project in project meghanada-server by mopemope.
the class LocationSearcher method getMethodLocationFromProject.
private Optional<Location> getMethodLocationFromProject(final String methodName, final List<String> arguments, final File file) {
try {
final Source declaringClassSrc = getSource(project, file);
final String path = declaringClassSrc.getFile().getPath();
return declaringClassSrc.getClassScopes().stream().flatMap(ts -> ts.getScopes().stream()).filter(bs -> {
if (!methodName.equals(bs.getName())) {
return false;
}
if (!(bs instanceof MethodScope)) {
return false;
}
final MethodScope methodScope = (MethodScope) bs;
final List<String> parameters = methodScope.getParameters();
return ClassNameUtils.compareArgumentType(arguments, parameters);
}).map(MethodScope.class::cast).map(ms -> new Location(path, ms.getBeginLine(), ms.getNameRange().begin.column)).findFirst();
} catch (ExecutionException e) {
throw new UncheckedExecutionException(e);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of meghanada.project.Project 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());
}
use of meghanada.project.Project 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());
}
Aggregations