Skip to content

Commit

Permalink
Java indexer: emit snippets over entire surrounding statement
Browse files Browse the repository at this point in the history
Summary:
Unlike the default line snippets that the Kythe server synthesizes,
these snippets may span over multiple lines to give a broader context.

Reviewers: shahms, zarko

Reviewed By: zarko

Projects: #java

Differential Revision: https://phabricator-dot-kythe-repo.appspot.com/D576
  • Loading branch information
schroederc committed Oct 26, 2015
1 parent 5f38bfd commit 94b15b4
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 58 deletions.
3 changes: 3 additions & 0 deletions RELEASES.md
Expand Up @@ -6,6 +6,9 @@ Notable changes:
- Use proto3 JSON mapping for web requests: https://developers.google.com/protocol-buffers/docs/proto3#json
- Java indexer: report error when indexing from compilation's source root

Notable additions:
- Java indexer: emit (possibly multi-line) snippets over entire surrounding statement

## v0.0.15

Notable changes:
Expand Down
Expand Up @@ -22,6 +22,7 @@
import com.google.devtools.kythe.proto.Analysis.CompilationUnit.FileInput;
import com.google.devtools.kythe.proto.Storage.VName;
import com.google.devtools.kythe.util.KytheURI;
import com.google.devtools.kythe.util.Span;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -112,18 +113,31 @@ public EntrySet getBuiltin(String name) {
}

/** Returns (and emits) a new anchor node at the given location in the file. */
public EntrySet getAnchor(VName fileVName, int start, int end) {
if (start > end || start < 0) {
public EntrySet getAnchor(VName fileVName, Span loc) {
return getAnchor(fileVName, loc, null);
}

/**
* Returns (and emits) a new anchor node at the given location in the file with an optional
* snippet span.
*/
public EntrySet getAnchor(VName fileVName, Span loc, Span snippet) {
if (loc == null || !loc.valid()) {
// TODO(schroederc): reduce number of invalid anchors
return null;
}
EntrySet anchor =
EntrySet.Builder builder =
newNode(NodeKind.ANCHOR)
.setCorpusPath(CorpusPath.fromVName(fileVName))
.addSignatureSalt(fileVName)
.setProperty("loc/start", "" + start)
.setProperty("loc/end", "" + end)
.build();
.setProperty("loc/start", "" + loc.getStart())
.setProperty("loc/end", "" + loc.getEnd());
if (snippet != null && snippet.valid()) {
builder
.setProperty("snippet/start", "" + snippet.getStart())
.setProperty("snippet/end", "" + snippet.getEnd());
}
EntrySet anchor = builder.build();
emitEdge(anchor.getVName(), EdgeKind.CHILDOF, fileVName);
return emitAndReturn(anchor);
}
Expand Down
Expand Up @@ -131,21 +131,25 @@ public EntrySet getWildcardNode(JCTree.JCWildcard wild) {

/** Returns and emits a Java anchor for the given {@link JCTree}. */
public EntrySet getAnchor(Positions filePositions, JCTree tree) {
return getAnchor(filePositions, filePositions.getStart(tree), filePositions.getEnd(tree));
return getAnchor(filePositions, filePositions.getSpan(tree));
}

/** Returns and emits a Java anchor for the given offset span. */
public EntrySet getAnchor(Positions filePositions, int start, int end) {
return getAnchor(lookupVName(getDigest(filePositions.getSourceFile())), start, end);
public EntrySet getAnchor(Positions filePositions, Span loc) {
return getAnchor(filePositions, loc, null);
}

/** Returns and emits a Java anchor for the given offset span. */
public EntrySet getAnchor(Positions filePositions, Span loc, Span snippet) {
return getAnchor(lookupVName(getDigest(filePositions.getSourceFile())), loc, snippet);
}

/** Returns and emits a Java anchor for the given identifier. */
public EntrySet getAnchor(Positions filePositions, Name name, int startOffset) {
public EntrySet getAnchor(Positions filePositions, Name name, int startOffset, Span snippet) {
Span span = filePositions.findIdentifier(name, startOffset);
return span == null
? null
: getAnchor(
lookupVName(getDigest(filePositions.getSourceFile())), span.getStart(), span.getEnd());
: getAnchor(lookupVName(getDigest(filePositions.getSourceFile())), span, snippet);
}

/** Returns the equivalent {@link NodeKind} for the given {@link ElementKind}. */
Expand Down

0 comments on commit 94b15b4

Please sign in to comment.