11package com .semmle .ts .extractor ;
22
3- import java .util .ArrayList ;
4- import java .util .Collections ;
5- import java .util .List ;
6- import java .util .regex .Matcher ;
7- import java .util .regex .Pattern ;
8-
93import com .google .gson .JsonArray ;
104import com .google .gson .JsonElement ;
115import com .google .gson .JsonNull ;
145139import com .semmle .ts .ast .ParenthesizedTypeExpr ;
146140import com .semmle .ts .ast .PredicateTypeExpr ;
147141import com .semmle .ts .ast .RestTypeExpr ;
142+ import com .semmle .ts .ast .SatisfiesExpr ;
148143import com .semmle .ts .ast .TemplateLiteralTypeExpr ;
149144import com .semmle .ts .ast .TupleTypeExpr ;
150145import com .semmle .ts .ast .TypeAliasDeclaration ;
151146import com .semmle .ts .ast .TypeAssertion ;
152- import com .semmle .ts .ast .SatisfiesExpr ;
153147import com .semmle .ts .ast .TypeParameter ;
154148import com .semmle .ts .ast .TypeofTypeExpr ;
155149import com .semmle .ts .ast .UnaryTypeExpr ;
156150import com .semmle .ts .ast .UnionTypeExpr ;
157151import com .semmle .util .collections .CollectionUtil ;
158152import com .semmle .util .data .IntList ;
153+ import java .util .ArrayList ;
154+ import java .util .Collections ;
155+ import java .util .List ;
156+ import java .util .regex .Matcher ;
157+ import java .util .regex .Pattern ;
159158
160159/**
161160 * Utility class for converting a <a
@@ -877,8 +876,10 @@ private Node convertBinaryExpression(JsonObject node, SourceLocation loc) throws
877876 }
878877 }
879878
880- private Node convertStaticInitializerBlock (JsonObject node , SourceLocation loc ) throws ParseError {
881- BlockStatement body = new BlockStatement (loc , convertChildren (node .get ("body" ).getAsJsonObject (), "statements" ));
879+ private Node convertStaticInitializerBlock (JsonObject node , SourceLocation loc )
880+ throws ParseError {
881+ BlockStatement body =
882+ new BlockStatement (loc , convertChildren (node .get ("body" ).getAsJsonObject (), "statements" ));
882883 return new StaticInitializer (loc , body );
883884 }
884885
@@ -893,7 +894,8 @@ private Node convertBreakStatement(JsonObject node, SourceLocation loc) throws P
893894 private Node convertCallExpression (JsonObject node , SourceLocation loc ) throws ParseError {
894895 List <Expression > arguments = convertChildren (node , "arguments" );
895896 if (arguments .size () >= 1 && hasKind (node .get ("expression" ), "ImportKeyword" )) {
896- return new DynamicImport (loc , arguments .get (0 ), arguments .size () > 1 ? arguments .get (1 ) : null );
897+ return new DynamicImport (
898+ loc , arguments .get (0 ), arguments .size () > 1 ? arguments .get (1 ) : null );
897899 }
898900 Expression callee = convertChild (node , "expression" );
899901 List <ITypeExpression > typeArguments = convertChildrenAsTypes (node , "typeArguments" );
@@ -1238,7 +1240,8 @@ private Node convertExpressionWithTypeArguments(JsonObject node, SourceLocation
12381240
12391241 private Node convertExternalModuleReference (JsonObject node , SourceLocation loc )
12401242 throws ParseError {
1241- ExternalModuleReference moduleRef = new ExternalModuleReference (loc , convertChild (node , "expression" ));
1243+ ExternalModuleReference moduleRef =
1244+ new ExternalModuleReference (loc , convertChild (node , "expression" ));
12421245 attachSymbolInformation (moduleRef , node );
12431246 return moduleRef ;
12441247 }
@@ -1407,7 +1410,8 @@ private Node convertImportDeclaration(JsonObject node, SourceLocation loc) throw
14071410 }
14081411 hasTypeKeyword = importClause .get ("isTypeOnly" ).getAsBoolean ();
14091412 }
1410- ImportDeclaration importDecl = new ImportDeclaration (loc , specifiers , src , assertion , hasTypeKeyword );
1413+ ImportDeclaration importDecl =
1414+ new ImportDeclaration (loc , specifiers , src , assertion , hasTypeKeyword );
14111415 attachSymbolInformation (importDecl , node );
14121416 return importDecl ;
14131417 }
@@ -1558,7 +1562,9 @@ private Node convertJsxAttribute(JsonObject node, SourceLocation loc) throws Par
15581562 nameNode = nameNode .get ("name" ).getAsJsonObject ();
15591563 }
15601564 return new JSXAttribute (
1561- loc , convertJSXName (((Expression )convertNode (nameNode , null ))), convertChild (node , "initializer" )); // 2
1565+ loc ,
1566+ convertJSXName (((Expression ) convertNode (nameNode , null ))),
1567+ convertChild (node , "initializer" )); // 2
15621568 }
15631569
15641570 private Node convertJsxClosingElement (JsonObject node , SourceLocation loc ) throws ParseError {
@@ -1649,8 +1655,10 @@ private Node convertLiteralType(JsonObject node, SourceLocation loc) throws Pars
16491655 }
16501656 }
16511657 if (literal instanceof TemplateLiteral ) {
1652- // A LiteralType containing a NoSubstitutionTemplateLiteral must produce a TemplateLiteralTypeExpr
1653- return new TemplateLiteralTypeExpr (literal .getLoc (), new ArrayList <>(), ((TemplateLiteral )literal ).getQuasis ());
1658+ // A LiteralType containing a NoSubstitutionTemplateLiteral must produce a
1659+ // TemplateLiteralTypeExpr
1660+ return new TemplateLiteralTypeExpr (
1661+ literal .getLoc (), new ArrayList <>(), ((TemplateLiteral ) literal ).getQuasis ());
16541662 }
16551663 return literal ;
16561664 }
@@ -2254,15 +2262,16 @@ private Node convertTupleType(JsonObject node, SourceLocation loc) throws ParseE
22542262 for (JsonElement element : node .get ("elements" ).getAsJsonArray ()) {
22552263 Identifier id = null ;
22562264 if (getKind (element ).equals ("NamedTupleMember" )) {
2257- id = (Identifier )convertNode (element .getAsJsonObject ().get ("name" ).getAsJsonObject ());
2265+ id = (Identifier ) convertNode (element .getAsJsonObject ().get ("name" ).getAsJsonObject ());
22582266 }
22592267 names .add (id );
22602268 }
22612269
22622270 return new TupleTypeExpr (loc , convertChildrenAsTypes (node , "elements" ), names );
22632271 }
22642272
2265- // This method just does a trivial forward to the type. The names have already been extracted in `convertTupleType`.
2273+ // This method just does a trivial forward to the type. The names have already been extracted in
2274+ // `convertTupleType`.
22662275 private Node convertNamedTupleMember (JsonObject node , SourceLocation loc ) throws ParseError {
22672276 return convertChild (node , "type" );
22682277 }
@@ -2291,7 +2300,7 @@ private Node convertTypeAssertionExpression(JsonObject node, SourceLocation loc)
22912300 private Node convertAssertClause (JsonObject node , SourceLocation loc ) throws ParseError {
22922301 List <Property > properties = new ArrayList <>();
22932302 for (INode child : convertChildren (node , "elements" )) {
2294- properties .add ((Property )child );
2303+ properties .add ((Property ) child );
22952304 }
22962305 // Adjust location to skip over the `assert` keyword.
22972306 Matcher m = ASSERT_START .matcher (loc .getSource ());
@@ -2303,12 +2312,7 @@ private Node convertAssertClause(JsonObject node, SourceLocation loc) throws Par
23032312
23042313 private Node convertAssertEntry (JsonObject node , SourceLocation loc ) throws ParseError {
23052314 return new Property (
2306- loc ,
2307- convertChild (node , "key" ),
2308- convertChild (node , "value" ),
2309- "init" ,
2310- false ,
2311- false );
2315+ loc , convertChild (node , "key" ), convertChild (node , "value" ), "init" , false , false );
23122316 }
23132317
23142318 private Node convertSatisfiesExpression (JsonObject node , SourceLocation loc ) throws ParseError {
@@ -2490,7 +2494,8 @@ private Node fixExports(SourceLocation loc, Node decl) {
24902494 advance (loc , skipped );
24912495 // capture group 1 is `default`, if present
24922496 if (m .group (1 ) == null )
2493- return new ExportNamedDeclaration (outerLoc , (Statement ) decl , new ArrayList <>(), null , null );
2497+ return new ExportNamedDeclaration (
2498+ outerLoc , (Statement ) decl , new ArrayList <>(), null , null );
24942499 return new ExportDefaultDeclaration (outerLoc , decl );
24952500 }
24962501 return decl ;
@@ -2586,8 +2591,9 @@ private Iterable<JsonElement> getModifiers(JsonObject node) {
25862591 }
25872592
25882593 /**
2589- * Returns a specific modifier from the given node (or <code>null</code> if absent), as defined by its
2590- * <code>modifiers</code> property and the <code>kind</code> property of the modifier AST node.
2594+ * Returns a specific modifier from the given node (or <code>null</code> if absent), as defined by
2595+ * its <code>modifiers</code> property and the <code>kind</code> property of the modifier AST
2596+ * node.
25912597 */
25922598 private JsonObject getModifier (JsonObject node , String modKind ) {
25932599 for (JsonElement mod : getModifiers (node ))
@@ -2597,8 +2603,8 @@ private JsonObject getModifier(JsonObject node, String modKind) {
25972603 }
25982604
25992605 /**
2600- * Check whether a node has a particular modifier, as defined by its <code>modifiers</code> property
2601- * and the <code>kind</code> property of the modifier AST node.
2606+ * Check whether a node has a particular modifier, as defined by its <code>modifiers</code>
2607+ * property and the <code>kind</code> property of the modifier AST node.
26022608 */
26032609 private boolean hasModifier (JsonObject node , String modKind ) {
26042610 return getModifier (node , modKind ) != null ;
@@ -2639,8 +2645,8 @@ private int getMemberModifierKeywords(JsonObject node) {
26392645 }
26402646
26412647 /**
2642- * Check whether a node has a particular flag, as defined by its <code>flags</code> property and the
2643- * <code>ts.NodeFlags</code> in enum.
2648+ * Check whether a node has a particular flag, as defined by its <code>flags</code> property and
2649+ * the <code>ts.NodeFlags</code> in enum.
26442650 */
26452651 private boolean hasFlag (JsonObject node , String flagName ) {
26462652 int flagId = metadata .getNodeFlagId (flagName );
@@ -2683,7 +2689,7 @@ private boolean hasKind(JsonElement node, String kind) {
26832689 }
26842690
26852691 /**
2686- * Gets the declaration kind of the given node, which is one of {@code "var"}, {@code "let"},
2692+ * Gets the declaration kind of the given node, which is one of {@code "var"}, {@code "let"},
26872693 * {@code "const"}, or {@code "using"}.
26882694 */
26892695 private String getDeclarationKind (JsonObject declarationList ) {
0 commit comments