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

java-parser

Package Overview
Dependencies
Maintainers
6
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 2.0.5 to 2.1.0

src/productions/utils/class-body-types.js

4

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

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

},
"gitHead": "fce16b970ecc46e1cc3f134432eac42877801674"
"gitHead": "acdd5e7f28d08c4fb0351cfaf43d4ff9524b90ba"
}

@@ -249,3 +249,8 @@ "use strict";

GATE: () => this.BACKTRACK_LOOKAHEAD($.pattern),
ALT: () => $.SUBRULE($.pattern)
ALT: () => {
$.SUBRULE($.pattern);
$.OPTION(() => {
$.SUBRULE($.guard);
});
}
},

@@ -252,0 +257,0 @@ {

"use strict";
const { isRecognitionException, tokenMatcher } = require("chevrotain");
const { classBodyTypes } = require("./utils/class-body-types");

@@ -113,14 +114,2 @@ function defineRules($, t) {

const classBodyTypes = {
unknown: 0,
fieldDeclaration: 1,
methodDeclaration: 2,
classDeclaration: 3,
interfaceDeclaration: 4,
semiColon: 5,
instanceInitializer: 6,
staticInitializer: 7,
constructorDeclaration: 8
};
// https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-ClassBodyDeclaration

@@ -206,5 +195,9 @@ $.RULE("classBodyDeclaration", () => {

$.SUBRULE($.variableDeclarator);
$.MANY(() => {
$.CONSUME(t.Comma);
$.SUBRULE2($.variableDeclarator);
$.MANY({
// required to distinguish from patternList
GATE: () => !tokenMatcher(this.LA(3).tokenType, t.Identifier),
DEF: () => {
$.CONSUME(t.Comma);
$.SUBRULE2($.variableDeclarator);
}
});

@@ -211,0 +204,0 @@ });

@@ -564,21 +564,11 @@ "use strict";

// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-Pattern
$.RULE("pattern", () => {
$.SUBRULE($.primaryPattern);
$.OPTION(() => {
$.CONSUME(t.AndAnd);
$.SUBRULE($.binaryExpression);
});
});
$.RULE("primaryPattern", () => {
$.OR([
{
ALT: () => {
$.CONSUME(t.LBrace);
$.SUBRULE($.pattern);
$.CONSUME(t.RBrace);
}
GATE: () => this.BACKTRACK_LOOKAHEAD($.typePattern),
ALT: () => $.SUBRULE($.typePattern)
},
{
ALT: () => $.SUBRULE($.typePattern)
ALT: () => $.SUBRULE($.recordPattern)
}

@@ -588,2 +578,3 @@ ]);

// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-TypePattern
$.RULE("typePattern", () => {

@@ -593,2 +584,27 @@ $.SUBRULE($.localVariableDeclaration);

// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-RecordPattern
$.RULE("recordPattern", () => {
$.SUBRULE($.referenceType);
$.CONSUME(t.LBrace);
$.OPTION(() => {
$.SUBRULE($.patternList);
});
$.CONSUME(t.RBrace);
});
// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-PatternList
$.RULE("patternList", () => {
$.SUBRULE($.pattern);
$.MANY(() => {
$.CONSUME(t.Comma);
$.SUBRULE2($.pattern);
});
});
// https://docs.oracle.com/javase/specs/jls/se21/html/jls-14.html#jls-Guard
$.RULE("guard", () => {
$.CONSUME(t.When);
$.SUBRULE($.expression);
});
// backtracking lookahead logic

@@ -595,0 +611,0 @@ $.RULE("identifyNewExpressionType", () => {

"use strict";
const { isRecognitionException, tokenMatcher, EOF } = require("chevrotain");
const { classBodyTypes } = require("./utils/class-body-types");
function defineRules($, t) {
// https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#CompilationUnit
/**
* Spec Deviation: As OrdinaryCompilationUnit and UnnamedClassCompilationUnit
* both can have multiple class or interface declarations, both were combined
* in the ordinaryCompilationUnit rule
*
* https://docs.oracle.com/javase/specs/jls/se21/html/jls-7.html#jls-7.3
* https://docs.oracle.com/javase/specs/jls/se21/preview/specs/unnamed-classes-instance-main-methods-jls.html
*/
$.RULE("compilationUnit", () => {

@@ -98,14 +106,36 @@ // custom optimized backtracking lookahead logic

// https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-TypeDeclaration
/**
* Spec Deviation: As OrdinaryCompilationUnit and UnnamedClassCompilationUnit
* both can have multiple class or interface declarations, both were combined
* in the ordinaryCompilationUnit rule
*
* As a result, the typeDeclaration combine TopLevelClassOrInterfaceDeclaration and includes fields and method declarations as well
* to handle unnamed class compilation unit
*
* https://docs.oracle.com/javase/specs/jls/se21/html/jls-7.html#jls-TopLevelClassOrInterfaceDeclaration
* https://docs.oracle.com/javase/specs/jls/se21/preview/specs/unnamed-classes-instance-main-methods-jls.html
*/
$.RULE("typeDeclaration", () => {
// TODO: consider extracting the prefix modifiers here to avoid backtracking
const isClassDeclaration = this.BACKTRACK_LOOKAHEAD($.isClassDeclaration);
const nextRuleType = $.BACKTRACK_LOOKAHEAD(
$.identifyClassBodyDeclarationType
);
$.OR([
{ ALT: () => $.CONSUME(t.Semicolon) },
{
GATE: () => isClassDeclaration,
GATE: () => nextRuleType === classBodyTypes.classDeclaration,
ALT: () => $.SUBRULE($.classDeclaration)
},
{ ALT: () => $.SUBRULE($.interfaceDeclaration) },
{ ALT: () => $.CONSUME(t.Semicolon) }
{
GATE: () => nextRuleType === classBodyTypes.interfaceDeclaration,
ALT: () => $.SUBRULE($.interfaceDeclaration)
},
{
GATE: () => nextRuleType === classBodyTypes.fieldDeclaration,
ALT: () => $.SUBRULE($.fieldDeclaration)
},
{
ALT: () => $.SUBRULE($.methodDeclaration)
}
]);

@@ -112,0 +142,0 @@ });

@@ -240,3 +240,3 @@ "use strict";

// https://docs.oracle.com/javase/specs/jls/se11/html/jls-3.html#jls-3.9
// https://docs.oracle.com/javase/specs/jls/se21/html/jls-3.html#jls-3.9
// TODO: how to handle the special rule (see spec above) for "requires" and "transitive"

@@ -253,2 +253,3 @@ const restrictedKeywords = [

"provides",
"when",
"with",

@@ -255,0 +256,0 @@ "sealed",

Sorry, the diff of this file is too big to display

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