1
1
package com .semmle .ts .extractor ;
2
2
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
-
9
3
import com .google .gson .JsonArray ;
10
4
import com .google .gson .JsonElement ;
11
5
import com .google .gson .JsonNull ;
145
139
import com .semmle .ts .ast .ParenthesizedTypeExpr ;
146
140
import com .semmle .ts .ast .PredicateTypeExpr ;
147
141
import com .semmle .ts .ast .RestTypeExpr ;
142
+ import com .semmle .ts .ast .SatisfiesExpr ;
148
143
import com .semmle .ts .ast .TemplateLiteralTypeExpr ;
149
144
import com .semmle .ts .ast .TupleTypeExpr ;
150
145
import com .semmle .ts .ast .TypeAliasDeclaration ;
151
146
import com .semmle .ts .ast .TypeAssertion ;
152
- import com .semmle .ts .ast .SatisfiesExpr ;
153
147
import com .semmle .ts .ast .TypeParameter ;
154
148
import com .semmle .ts .ast .TypeofTypeExpr ;
155
149
import com .semmle .ts .ast .UnaryTypeExpr ;
156
150
import com .semmle .ts .ast .UnionTypeExpr ;
157
151
import com .semmle .util .collections .CollectionUtil ;
158
152
import 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 ;
159
158
160
159
/**
161
160
* Utility class for converting a <a
@@ -877,8 +876,10 @@ private Node convertBinaryExpression(JsonObject node, SourceLocation loc) throws
877
876
}
878
877
}
879
878
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" ));
882
883
return new StaticInitializer (loc , body );
883
884
}
884
885
@@ -893,7 +894,8 @@ private Node convertBreakStatement(JsonObject node, SourceLocation loc) throws P
893
894
private Node convertCallExpression (JsonObject node , SourceLocation loc ) throws ParseError {
894
895
List <Expression > arguments = convertChildren (node , "arguments" );
895
896
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 );
897
899
}
898
900
Expression callee = convertChild (node , "expression" );
899
901
List <ITypeExpression > typeArguments = convertChildrenAsTypes (node , "typeArguments" );
@@ -1238,7 +1240,8 @@ private Node convertExpressionWithTypeArguments(JsonObject node, SourceLocation
1238
1240
1239
1241
private Node convertExternalModuleReference (JsonObject node , SourceLocation loc )
1240
1242
throws ParseError {
1241
- ExternalModuleReference moduleRef = new ExternalModuleReference (loc , convertChild (node , "expression" ));
1243
+ ExternalModuleReference moduleRef =
1244
+ new ExternalModuleReference (loc , convertChild (node , "expression" ));
1242
1245
attachSymbolInformation (moduleRef , node );
1243
1246
return moduleRef ;
1244
1247
}
@@ -1407,7 +1410,8 @@ private Node convertImportDeclaration(JsonObject node, SourceLocation loc) throw
1407
1410
}
1408
1411
hasTypeKeyword = importClause .get ("isTypeOnly" ).getAsBoolean ();
1409
1412
}
1410
- ImportDeclaration importDecl = new ImportDeclaration (loc , specifiers , src , assertion , hasTypeKeyword );
1413
+ ImportDeclaration importDecl =
1414
+ new ImportDeclaration (loc , specifiers , src , assertion , hasTypeKeyword );
1411
1415
attachSymbolInformation (importDecl , node );
1412
1416
return importDecl ;
1413
1417
}
@@ -1558,7 +1562,9 @@ private Node convertJsxAttribute(JsonObject node, SourceLocation loc) throws Par
1558
1562
nameNode = nameNode .get ("name" ).getAsJsonObject ();
1559
1563
}
1560
1564
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
1562
1568
}
1563
1569
1564
1570
private Node convertJsxClosingElement (JsonObject node , SourceLocation loc ) throws ParseError {
@@ -1649,8 +1655,10 @@ private Node convertLiteralType(JsonObject node, SourceLocation loc) throws Pars
1649
1655
}
1650
1656
}
1651
1657
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 ());
1654
1662
}
1655
1663
return literal ;
1656
1664
}
@@ -2254,15 +2262,16 @@ private Node convertTupleType(JsonObject node, SourceLocation loc) throws ParseE
2254
2262
for (JsonElement element : node .get ("elements" ).getAsJsonArray ()) {
2255
2263
Identifier id = null ;
2256
2264
if (getKind (element ).equals ("NamedTupleMember" )) {
2257
- id = (Identifier )convertNode (element .getAsJsonObject ().get ("name" ).getAsJsonObject ());
2265
+ id = (Identifier ) convertNode (element .getAsJsonObject ().get ("name" ).getAsJsonObject ());
2258
2266
}
2259
2267
names .add (id );
2260
2268
}
2261
2269
2262
2270
return new TupleTypeExpr (loc , convertChildrenAsTypes (node , "elements" ), names );
2263
2271
}
2264
2272
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`.
2266
2275
private Node convertNamedTupleMember (JsonObject node , SourceLocation loc ) throws ParseError {
2267
2276
return convertChild (node , "type" );
2268
2277
}
@@ -2291,7 +2300,7 @@ private Node convertTypeAssertionExpression(JsonObject node, SourceLocation loc)
2291
2300
private Node convertAssertClause (JsonObject node , SourceLocation loc ) throws ParseError {
2292
2301
List <Property > properties = new ArrayList <>();
2293
2302
for (INode child : convertChildren (node , "elements" )) {
2294
- properties .add ((Property )child );
2303
+ properties .add ((Property ) child );
2295
2304
}
2296
2305
// Adjust location to skip over the `assert` keyword.
2297
2306
Matcher m = ASSERT_START .matcher (loc .getSource ());
@@ -2303,12 +2312,7 @@ private Node convertAssertClause(JsonObject node, SourceLocation loc) throws Par
2303
2312
2304
2313
private Node convertAssertEntry (JsonObject node , SourceLocation loc ) throws ParseError {
2305
2314
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 );
2312
2316
}
2313
2317
2314
2318
private Node convertSatisfiesExpression (JsonObject node , SourceLocation loc ) throws ParseError {
@@ -2490,7 +2494,8 @@ private Node fixExports(SourceLocation loc, Node decl) {
2490
2494
advance (loc , skipped );
2491
2495
// capture group 1 is `default`, if present
2492
2496
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 );
2494
2499
return new ExportDefaultDeclaration (outerLoc , decl );
2495
2500
}
2496
2501
return decl ;
@@ -2586,8 +2591,9 @@ private Iterable<JsonElement> getModifiers(JsonObject node) {
2586
2591
}
2587
2592
2588
2593
/**
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.
2591
2597
*/
2592
2598
private JsonObject getModifier (JsonObject node , String modKind ) {
2593
2599
for (JsonElement mod : getModifiers (node ))
@@ -2597,8 +2603,8 @@ private JsonObject getModifier(JsonObject node, String modKind) {
2597
2603
}
2598
2604
2599
2605
/**
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.
2602
2608
*/
2603
2609
private boolean hasModifier (JsonObject node , String modKind ) {
2604
2610
return getModifier (node , modKind ) != null ;
@@ -2639,8 +2645,8 @@ private int getMemberModifierKeywords(JsonObject node) {
2639
2645
}
2640
2646
2641
2647
/**
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.
2644
2650
*/
2645
2651
private boolean hasFlag (JsonObject node , String flagName ) {
2646
2652
int flagId = metadata .getNodeFlagId (flagName );
@@ -2683,7 +2689,7 @@ private boolean hasKind(JsonElement node, String kind) {
2683
2689
}
2684
2690
2685
2691
/**
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"},
2687
2693
* {@code "const"}, or {@code "using"}.
2688
2694
*/
2689
2695
private String getDeclarationKind (JsonObject declarationList ) {
0 commit comments