-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Java #1
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d0432be
Refactor, initial java support
jssblck e95f54d
Add changelog
jssblck d270678
Remove duplicate code
jssblck 31eee14
Minor tweaks
jssblck e4ddde4
Don't publish to crates.io
jssblck 98be31e
Docs
jssblck 2b48ace
Java basics
jssblck e04e557
Fix tests
jssblck f3f7373
More refactors, make method explicit
jssblck 316ffdd
Java method extraction
jssblck fdb303e
Remove function part parser
jssblck 55fd092
Fix doc examples
jssblck af7423c
Java callgraph (#2)
jssblck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# v0.2.0 | ||
|
||
Adds support for Java. | ||
|
||
Breaking: | ||
- Normalizations have been centralized to `snippets::parser::normalize`. | ||
- `snippets::text::buffer` has been merged into `snippets::text`. | ||
- Some vestigal traits (such as `snippets::text::ConvertCRLFToLF`) have been removed. | ||
- Implementation-specific constants such as `NODE_KIND_COMMENT` have been made private. | ||
- Removed `tree-sitter` types from the API. | ||
|
||
# v0.1.3 | ||
|
||
Adds support for C++. | ||
Adds support for C. | ||
|
||
This repository initially existed in FOSSA's [foundation-libs](https://github.com/fossas/foundation-libs/tree/master/snippets) monorepo. | ||
History for this library earlier than v0.1.3 can be viewed there. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
[package] | ||
name = "snippets" | ||
version = "0.1.3" | ||
version = "0.2.0" | ||
edition = "2021" | ||
description = "Extracts snippets of programming languages from files" | ||
|
||
# This is very FOSSA specific, so don't publish to crates.io. | ||
# Instead, just add this as a dependency using git path: `cargo add [email protected]:fossas/lib-snippets.git`. | ||
publish = false | ||
|
||
[features] | ||
default = [] | ||
|
||
|
@@ -12,9 +16,10 @@ sha2-asm = ["sha2/asm"] | |
|
||
# Enables support for each named language. | ||
# For more info, see the module documentation for the language. | ||
lang-all = ["lang-c99-tc3", "lang-cpp-98"] | ||
lang-c99-tc3 = [] | ||
lang-cpp-98 = [] | ||
lang-all = ["lang-c99-tc3", "lang-cpp-98", "lang-java-11"] | ||
lang-c99-tc3 = ["tree-sitter-c"] | ||
lang-cpp-98 = ["tree-sitter-cpp"] | ||
lang-java-11 = ["tree-sitter-java"] | ||
|
||
[dependencies] | ||
base64 = "0.21.2" | ||
|
@@ -24,16 +29,17 @@ fallible-iterator = { version = "0.3.0", features = ["std"] } | |
flagset = "0.4.3" | ||
getset = "0.1.2" | ||
itertools = "0.11.0" | ||
lazy-regex = { version = "3.0.2", features = ["std"] } | ||
once_cell = "1.18.0" | ||
regex = "1.9.4" | ||
sha2 = "0.10.7" | ||
strum = { version = "0.25.0", features = ["derive"] } | ||
tap = "1.0.1" | ||
thiserror = "1.0.47" | ||
tracing = "0.1.37" | ||
tree-sitter = "0.20.10" | ||
tree-sitter-c = "0.20.6" | ||
tree-sitter-cpp = "0.20.3" | ||
tree-sitter-c = { version = "0.20.6", optional = true } | ||
tree-sitter-cpp = { version = "0.20.3", optional = true } | ||
tree-sitter-java = { version = "0.20.2", optional = true } | ||
tree-sitter-traversal = "0.1.2" | ||
typed-builder = "0.15.2" | ||
|
||
|
@@ -42,6 +48,7 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } | |
snippets = { path = ".", features = ["lang-all"] } | ||
criterion = "0.5.1" | ||
pretty_assertions = "1.4.0" | ||
indoc = "2.0.4" | ||
|
||
[[bench]] | ||
name = "hashes" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! Specialized types for dealing with content provided to this library, | ||
//! or reading content into this library. | ||
|
||
use std::{borrow::Cow, path::Path}; | ||
|
||
use derivative::Derivative; | ||
use derive_more::Index; | ||
use tap::Pipe; | ||
|
||
/// Specialized type to indicate the original content provided to the extractor, | ||
/// distinct from a sliced section of that content. | ||
#[derive(Clone, PartialEq, Eq, Derivative, Index)] | ||
#[derivative(Debug = "transparent")] | ||
pub struct Content(Vec<u8>); | ||
|
||
impl Content { | ||
/// Create a new instance with the provided content. | ||
pub fn new(content: Vec<u8>) -> Self { | ||
Self(content) | ||
} | ||
|
||
/// Read a file on disk as content. | ||
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, std::io::Error> { | ||
std::fs::read(path).map(Self::new) | ||
} | ||
|
||
/// View the content as a plain byte slice. | ||
pub fn as_bytes(&self) -> &[u8] { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl<U: AsRef<[u8]>> From<U> for Content { | ||
fn from(value: U) -> Self { | ||
value.as_ref().pipe(|v| v.to_vec()).pipe(Self) | ||
} | ||
} | ||
|
||
/// Common functionality for any type indicating a section of bytes to extract from [`Content`]. | ||
pub trait ByteCoordinate { | ||
/// The byte offset at which the function starts. | ||
fn byte_start(&self) -> usize; | ||
|
||
/// The byte offset at which the function ends. | ||
fn byte_end(&self) -> usize; | ||
|
||
/// Extract the text representing this part from the specified content. | ||
fn extract_from<'a>(&self, content: &'a Content) -> &'a [u8] { | ||
&content[self.byte_start()..self.byte_end()] | ||
} | ||
|
||
/// Extract the text representing this part from the specified content as a lossy string. | ||
fn extract_from_lossy<'a>(&self, content: &'a Content) -> Cow<'a, str> { | ||
let content = self.extract_from(content); | ||
String::from_utf8_lossy(content) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Optional] use https://doc.rust-lang.org/std/ops/struct.Range.html instead, to get
start <= x
andstart <= end
guarantee