Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

java-parser

Package Overview
Dependencies
Maintainers
4
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

java-parser - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

4

package.json
{
"name": "java-parser",
"version": "0.1.3",
"version": "0.2.0",
"description": "Java Parser in JavaScript",

@@ -16,3 +16,3 @@ "main": "src/index.js",

},
"gitHead": "79948b55a1c62a4eca415ac4ac98c8d254468405"
"gitHead": "e4359b29b74611cbd8553a3d806b1209bd54c4c8"
}

@@ -29,2 +29,4 @@ [![npm](https://img.shields.io/npm/v/java-parser.svg)](https://www.npmjs.com/package/java-parser)

### Parsing
```javascript

@@ -43,1 +45,38 @@ const { parse } = require("java-parser");

```
### Traversing the CST
See relevant [Chevrotain documentation on CST Traversal](http://sap.github.io/chevrotain/docs/guide/concrete_syntax_tree.html#traversing).
```javascript
const {
BaseJavaCstVisitor,
BaseJavaCstVisitorWithDefaults
} = require("java-parser");
// Use "BaseJavaCstVisitor" if you need to implement all the visitor methods yourself.
class LambdaArrowsPositionCollector extends BaseJavaCstVisitorWithDefaults {
constructor() {
super();
this.result = [];
this.validateVisitor();
}
lambdaExpression(ctx) {
// Collects all the starting offsets of lambda arrows in lambdas with short (no parenthesis)
// single argument lists: e.g:
// - n -> n*n (will be collected)
// - (n) -> n*n (not collected)
if (ctx.lambdaParameters.children.Identifier.length > 0) {
this.result.push(ctx.Arrow[0].startOffset);
}
}
}
const lambdaArrowsCollector = new LambdaArrowsPositionCollector();
// The CST result from the previous code snippet
lambdaArrowsCollector.visit(cst);
lambdaArrowsCollector.result.forEach(arrowOffset => {
console.log(arrowOffset);
});
```

@@ -0,1 +1,2 @@

/* eslint no-console: 0 */
"use strict";

@@ -2,0 +3,0 @@ const cp = require("child_process");

@@ -7,2 +7,5 @@ "use strict";

const parser = new JavaParser();
const BaseJavaCstVisitor = parser.getBaseCstVisitorConstructor();
const BaseJavaCstVisitorWithDefaults = parser.getBaseCstVisitorConstructorWithDefaults();
// const endTime = new Date().getTime();

@@ -48,2 +51,6 @@ // const totalTime = endTime - startTime;

module.exports = { parse };
module.exports = {
parse,
BaseJavaCstVisitor,
BaseJavaCstVisitorWithDefaults
};

@@ -0,1 +1,3 @@

"use strict";
const _ = require("lodash");

@@ -8,8 +10,10 @@ const path = require("path");

describe("The Java Parser", function() {
context("java-design-patterns samples", () => {
const samplesDir = path.resolve(
__dirname,
"../samples/java-design-patterns"
);
describe("The Java Parser", () => {
createSampleSpecs("java-design-patterns");
createSampleSpecs("spring-boot");
});
function createSampleSpecs(sampleName) {
context(sampleName + " samples", () => {
const samplesDir = path.resolve(__dirname, "../samples/" + sampleName);
const sampleFiles = klawSync(samplesDir, { nodir: true });

@@ -31,2 +35,2 @@ const javaSampleFiles = sampleFiles.filter(fileDesc =>

});
});
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc