Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"projectName": "com.microsoft.java.lsif.core",
"port": 6006
}
]
}
1,667 changes: 590 additions & 1,077 deletions cmd/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions com.microsoft.java.lsif.core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="lib/rxjava-2.2.8.jar"/>
<classpathentry exported="true" kind="lib" path="lib/reactive-streams-1.0.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/maven-scm-api-1.11.2.jar"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
28 changes: 24 additions & 4 deletions com.microsoft.java.lsif.core/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,32 @@ org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false
org.eclipse.jdt.core.formatter.align_with_spaces=false
org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0
org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16
org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_module_statements=16
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16
org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
Expand Down Expand Up @@ -222,11 +226,12 @@ org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_ini
org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
Expand Down Expand Up @@ -257,6 +262,8 @@ org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert
org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
Expand All @@ -281,13 +288,17 @@ org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert
org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
Expand Down Expand Up @@ -335,6 +346,8 @@ org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do no
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert
org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
Expand Down Expand Up @@ -371,9 +384,12 @@ org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not inser
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert
org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
Expand Down Expand Up @@ -423,9 +439,13 @@ org.eclipse.jdt.core.formatter.tabulation.char=tab
org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=true
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true
org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true
org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true
org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true
org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter
1 change: 1 addition & 0 deletions com.microsoft.java.lsif.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.12.0",
Export-Package: com.microsoft.java.lsif.core.internal
Bundle-ClassPath: lib/rxjava-2.2.8.jar,
lib/reactive-streams-1.0.0.jar,
lib/maven-scm-api-1.11.2.jar,
.
Bundle-Vendor: %Bundle-Vendor
Automatic-Module-Name: org.eclipse.jdt.ls.core
5 changes: 5 additions & 0 deletions com.microsoft.java.lsif.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<artifactId>reactive-streams</artifactId>
<version>1.0.0</version>
</artifactItem>
<artifactItem>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-api</artifactId>
<version>1.11.2</version>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static CompilationUnit createAST(final ITypeRoot input, final IProgressMo
if (root[0] == null) {
final ASTParser parser = newASTParser();
parser.setSource(input);
parser.setResolveBindings(true);
root[0] = (CompilationUnit) parser.createAST(progressMonitor);
}
// mark as unmodifiable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ public Edge next(Vertex from, Vertex to) {
return new Edge(generator.next(), Edge.NEXT, from.getId(), to.getId());
}

public Edge moniker(Vertex from, Vertex to) {
return new Edge(generator.next(), Edge.MONIKER, from.getId(), to.getId());
}

public Edge attach(Vertex from, Vertex to) {
return new Edge(generator.next(), Edge.ATTACH, from.getId(), to.getId());
}

public Edge packageInformation(Vertex from, Vertex to) {
return new Edge(generator.next(), Edge.PACKAGEINFORMATION, from.getId(), to.getId());
}

public Edge diagnostic(Vertex from, Vertex to) {
return new Edge(generator.next(), Edge.T_DIAGNOSTIC, from.getId(), to.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@

package com.microsoft.java.lsif.core.internal.indexer;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.maven.model.Model;
import org.apache.maven.model.Scm;
import org.apache.maven.project.MavenProject;
import org.apache.maven.scm.provider.ScmUrlUtils;
import org.apache.maven.shared.utils.StringUtils;
import org.eclipse.buildship.core.GradleBuild;
import org.eclipse.buildship.core.GradleCore;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
Expand All @@ -27,13 +35,20 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.ls.core.internal.BuildWorkspaceStatus;
import org.eclipse.jdt.ls.core.internal.IProjectImporter;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
import org.eclipse.jdt.ls.core.internal.managers.GradleProjectImporter;
import org.eclipse.jdt.ls.core.internal.managers.MavenProjectImporter;
import org.eclipse.lsp4j.ClientCapabilities;
import org.gradle.tooling.model.GradleModuleVersion;
import org.gradle.tooling.model.gradle.GradlePublication;
import org.gradle.tooling.model.gradle.ProjectPublications;

import com.microsoft.java.lsif.core.internal.emitter.LsifEmitter;
import com.microsoft.java.lsif.core.internal.protocol.Document;
import com.microsoft.java.lsif.core.internal.protocol.Event;
import com.microsoft.java.lsif.core.internal.protocol.PackageInformation.PackageManager;
import com.microsoft.java.lsif.core.internal.protocol.Project;
import com.microsoft.java.lsif.core.internal.visitors.DiagnosticVisitor;
import com.microsoft.java.lsif.core.internal.visitors.DocumentVisitor;
Expand Down Expand Up @@ -90,16 +105,24 @@ private void buildIndex(IPath path, IProgressMonitor monitor, LsifService lsif)
if (!javaProject.exists()) {
continue;
}
boolean hasPackageInformation = false;
try {
hasPackageInformation = generateExportPackageInformation(proj, monitor, lsif, javaProject);
} catch (Exception e) {
// OperationCanceledException, CoreException from WorkspaceHandler.getImporter
// GradleConnectionException, IllegalStateException from
// ProjectConnection.getModel
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}

Project projVertex = lsif.getVertexBuilder().project();
LsifEmitter.getInstance().emit(projVertex);
LsifEmitter.getInstance()
.emit(lsif.getVertexBuilder().event(Event.EventScope.Project, Event.EventKind.BEGIN,
projVertex.getId()));
LsifEmitter.getInstance().emit(
lsif.getVertexBuilder().event(Event.EventScope.Project, Event.EventKind.BEGIN, projVertex.getId()));

List<ICompilationUnit> sourceList = getAllSourceFiles(javaProject);

dumpParallely(sourceList, threadPool, projVertex, lsif, monitor);
dumpParallelly(sourceList, threadPool, projVertex, lsif, hasPackageInformation, monitor);

VisitorUtils.endAllDocument(lsif);
LsifEmitter.getInstance().emit(
Expand Down Expand Up @@ -139,8 +162,89 @@ private List<ICompilationUnit> getAllSourceFiles(IJavaProject javaProject) throw
return res;
}

private void dumpParallely(List<ICompilationUnit> sourceList, ExecutorService threadPool, Project projVertex,
LsifService lsif, IProgressMonitor monitor) {
/**
* Generate and emit the package information of the given project and return if
* the project is published.
*
* @param proj the project
* @param monitor the IProgressMonitor
* @param lsif the lsif instance
* @param javaProject the javaProject of proj
* @return <code>true</code> if the given project is published
*/
private boolean generateExportPackageInformation(IProject proj, IProgressMonitor monitor, LsifService lsif,
IJavaProject javaProject) throws Exception {
IPath folderPath = proj.getLocation();
if (folderPath == null) {
return false;
}
IProjectImporter importer = this.handler.getImporter(folderPath.toFile(), monitor);
if (importer instanceof MavenProjectImporter) {
File pomfile = VisitorUtils.findPom(proj.getLocation(), 0);
if (pomfile == null) {
return false;
}
MavenProject mavenProject = Repository.getInstance().enlistMavenProject(lsif, pomfile);
if (mavenProject == null) {
return false;
}
Model model = mavenProject.getModel();
String groupId = model.getGroupId();
if (groupId == null) {
return false;
}
String artifactId = model.getArtifactId();
if (artifactId == null) {
return false;
}
String version = model.getVersion();
if (version == null) {
return false;
}
Scm scm = model.getScm();
String url = null;
String type = null;
// scm is optional
if (scm != null) {
url = scm.getUrl();
String connect = scm.getConnection();
if (connect != null) {
type = ScmUrlUtils.getProvider(connect);
}
}
Repository.getInstance().enlistPackageInformation(lsif, javaProject.getPath().toString(),
groupId + "/" + artifactId, PackageManager.MAVEN, version, type, url);
return true;
} else if (importer instanceof GradleProjectImporter) {
GradleBuild build = GradleCore.getWorkspace().getBuild(proj).get();
ProjectPublications model = build
.withConnection(connection -> connection.getModel(ProjectPublications.class), monitor);
List<? extends GradlePublication> publications = model.getPublications().getAll();
if (publications.size() == 0) {
return false;
}
GradleModuleVersion gradleModuleVersion = publications.get(0).getId();
String groupId = gradleModuleVersion.getGroup();
if (StringUtils.isEmpty(groupId)) {
return false;
}
String artifactId = gradleModuleVersion.getName();
if (StringUtils.isEmpty(artifactId)) {
return false;
}
String version = gradleModuleVersion.getVersion();
if (StringUtils.isEmpty(version)) {
return false;
}
Repository.getInstance().enlistPackageInformation(lsif, javaProject.getPath().toString(),
groupId + "/" + artifactId, PackageManager.MAVEN, version, null, null);
return true;
}
return false;
}

private void dumpParallelly(List<ICompilationUnit> sourceList, ExecutorService threadPool, Project projVertex,
LsifService lsif, boolean hasPackageInformation, IProgressMonitor monitor) {
Observable.fromIterable(sourceList)
.flatMap(item -> Observable.just(item).observeOn(Schedulers.from(threadPool)).map(sourceFile -> {
CompilationUnit cu = ASTUtil.createAST(sourceFile, monitor);
Expand All @@ -150,7 +254,7 @@ private void dumpParallely(List<ICompilationUnit> sourceList, ExecutorService th
}
IndexerContext context = new IndexerContext(docVertex, cu, projVertex);

LsifVisitor lsifVisitor = new LsifVisitor(lsif, context);
LsifVisitor lsifVisitor = new LsifVisitor(lsif, context, hasPackageInformation);
cu.accept(lsifVisitor);

DiagnosticVisitor diagnosticVisitor = new DiagnosticVisitor(lsif, context);
Expand All @@ -161,4 +265,5 @@ private void dumpParallely(List<ICompilationUnit> sourceList, ExecutorService th
return 0;
})).blockingSubscribe();
}
}

}
Loading