Skip to content

Commit 27e36cf

Browse files
author
Esben Sparre Andreasen
committed
JS: apply google-java-format to extractor source code
1 parent 9eebe00 commit 27e36cf

File tree

12 files changed

+133
-134
lines changed

12 files changed

+133
-134
lines changed

javascript/extractor/src/com/semmle/js/ast/DefaultVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.semmle.ts.ast.InterfaceTypeExpr;
3636
import com.semmle.ts.ast.IntersectionTypeExpr;
3737
import com.semmle.ts.ast.IsTypeExpr;
38-
import com.semmle.ts.ast.UnaryTypeExpr;
3938
import com.semmle.ts.ast.KeywordTypeExpr;
4039
import com.semmle.ts.ast.MappedTypeExpr;
4140
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -49,6 +48,7 @@
4948
import com.semmle.ts.ast.TypeExpression;
5049
import com.semmle.ts.ast.TypeParameter;
5150
import com.semmle.ts.ast.TypeofTypeExpr;
51+
import com.semmle.ts.ast.UnaryTypeExpr;
5252
import com.semmle.ts.ast.UnionTypeExpr;
5353
import com.semmle.util.exception.CatastrophicError;
5454

javascript/extractor/src/com/semmle/js/ast/Visitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.semmle.ts.ast.InterfaceTypeExpr;
3232
import com.semmle.ts.ast.IntersectionTypeExpr;
3333
import com.semmle.ts.ast.IsTypeExpr;
34-
import com.semmle.ts.ast.UnaryTypeExpr;
3534
import com.semmle.ts.ast.KeywordTypeExpr;
3635
import com.semmle.ts.ast.MappedTypeExpr;
3736
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -44,6 +43,7 @@
4443
import com.semmle.ts.ast.TypeAssertion;
4544
import com.semmle.ts.ast.TypeParameter;
4645
import com.semmle.ts.ast.TypeofTypeExpr;
46+
import com.semmle.ts.ast.UnaryTypeExpr;
4747
import com.semmle.ts.ast.UnionTypeExpr;
4848

4949
/**

javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package com.semmle.js.extractor;
22

3-
import java.util.ArrayList;
4-
import java.util.Collections;
5-
import java.util.List;
6-
import java.util.Set;
7-
import java.util.Stack;
8-
93
import com.semmle.js.ast.AClass;
104
import com.semmle.js.ast.AFunction;
115
import com.semmle.js.ast.AFunctionExpression;
@@ -149,6 +143,11 @@
149143
import com.semmle.util.collections.CollectionUtil;
150144
import com.semmle.util.trap.TrapWriter;
151145
import com.semmle.util.trap.TrapWriter.Label;
146+
import java.util.ArrayList;
147+
import java.util.Collections;
148+
import java.util.List;
149+
import java.util.Set;
150+
import java.util.Stack;
152151

153152
/** Extractor for AST-based information; invoked by the {@link JSExtractor}. */
154153
public class ASTExtractor {

javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
package com.semmle.js.extractor;
22

3+
import com.semmle.js.extractor.ExtractorConfig.SourceType;
4+
import com.semmle.js.extractor.FileExtractor.FileType;
5+
import com.semmle.js.extractor.trapcache.DefaultTrapCache;
6+
import com.semmle.js.extractor.trapcache.DummyTrapCache;
7+
import com.semmle.js.extractor.trapcache.ITrapCache;
8+
import com.semmle.js.parser.ParsedProject;
9+
import com.semmle.js.parser.TypeScriptParser;
10+
import com.semmle.ts.extractor.TypeExtractor;
11+
import com.semmle.ts.extractor.TypeTable;
12+
import com.semmle.util.data.StringUtil;
13+
import com.semmle.util.exception.CatastrophicError;
14+
import com.semmle.util.exception.Exceptions;
15+
import com.semmle.util.exception.ResourceError;
16+
import com.semmle.util.exception.UserError;
17+
import com.semmle.util.extraction.ExtractorOutputConfig;
18+
import com.semmle.util.files.FileUtil;
19+
import com.semmle.util.io.csv.CSVReader;
20+
import com.semmle.util.language.LegacyLanguage;
21+
import com.semmle.util.process.Env;
22+
import com.semmle.util.projectstructure.ProjectLayout;
23+
import com.semmle.util.trap.TrapWriter;
324
import java.io.File;
425
import java.io.IOException;
526
import java.io.Reader;
@@ -27,28 +48,6 @@
2748
import java.util.concurrent.TimeUnit;
2849
import java.util.stream.Stream;
2950

30-
import com.semmle.js.extractor.ExtractorConfig.SourceType;
31-
import com.semmle.js.extractor.FileExtractor.FileType;
32-
import com.semmle.js.extractor.trapcache.DefaultTrapCache;
33-
import com.semmle.js.extractor.trapcache.DummyTrapCache;
34-
import com.semmle.js.extractor.trapcache.ITrapCache;
35-
import com.semmle.js.parser.ParsedProject;
36-
import com.semmle.js.parser.TypeScriptParser;
37-
import com.semmle.ts.extractor.TypeExtractor;
38-
import com.semmle.ts.extractor.TypeTable;
39-
import com.semmle.util.data.StringUtil;
40-
import com.semmle.util.exception.CatastrophicError;
41-
import com.semmle.util.exception.Exceptions;
42-
import com.semmle.util.exception.ResourceError;
43-
import com.semmle.util.exception.UserError;
44-
import com.semmle.util.extraction.ExtractorOutputConfig;
45-
import com.semmle.util.files.FileUtil;
46-
import com.semmle.util.io.csv.CSVReader;
47-
import com.semmle.util.language.LegacyLanguage;
48-
import com.semmle.util.process.Env;
49-
import com.semmle.util.projectstructure.ProjectLayout;
50-
import com.semmle.util.trap.TrapWriter;
51-
5251
/**
5352
* An alternative entry point to the JavaScript extractor.
5453
*
@@ -71,8 +70,8 @@
7170
* patterns that can be used to refine the list of files to include and exclude
7271
* <li><code>LGTM_INDEX_TYPESCRIPT</code>: whether to extract TypeScript
7372
* <li><code>LGTM_INDEX_FILETYPES</code>: a newline-separated list of ".extension:filetype" pairs
74-
* specifying which {@link FileType} to use for the given extension; the additional file
75-
* type <code>XML</code> is also supported
73+
* specifying which {@link FileType} to use for the given extension; the additional file type
74+
* <code>XML</code> is also supported
7675
* <li><code>LGTM_INDEX_XML_MODE</code>: whether to extract XML files
7776
* <li><code>LGTM_THREADS</code>: the maximum number of files to extract in parallel
7877
* <li><code>LGTM_TRAP_CACHE</code>: the path of a directory to use for trap caching
@@ -166,8 +165,8 @@
166165
* <p>If <code>LGTM_INDEX_XML_MODE</code> is set to <code>ALL</code>, then all files with extension
167166
* <code>.xml</code> under <code>LGTM_SRC</code> are extracted as XML (in addition to any files
168167
* whose file type is specified to be <code>XML</code> via <code>LGTM_INDEX_SOURCE_TYPE</code>).
169-
* Currently XML extraction does not respect inclusion and exclusion filters, but this is a bug,
170-
* not a feature, and hence will change eventually.
168+
* Currently XML extraction does not respect inclusion and exclusion filters, but this is a bug, not
169+
* a feature, and hence will change eventually.
171170
*
172171
* <p>Note that all these customisations only apply to <code>LGTM_SRC</code>. Extraction of externs
173172
* is not customisable.
@@ -288,8 +287,7 @@ private void setupFileTypes() {
288287
try {
289288
fileType = StringUtil.uc(fileType);
290289
if ("XML".equals(fileType)) {
291-
if (extension.length() < 2)
292-
throw new UserError("Invalid extension '" + extension + "'.");
290+
if (extension.length() < 2) throw new UserError("Invalid extension '" + extension + "'.");
293291
xmlExtensions.add(extension.substring(1));
294292
} else {
295293
fileTypes.put(extension, FileType.valueOf(fileType));
@@ -304,8 +302,7 @@ private void setupFileTypes() {
304302
private void setupXmlMode() {
305303
String xmlMode = getEnvVar("LGTM_INDEX_XML_MODE", "DISABLED");
306304
xmlMode = StringUtil.uc(xmlMode.trim());
307-
if ("ALL".equals(xmlMode))
308-
xmlExtensions.add("xml");
305+
if ("ALL".equals(xmlMode)) xmlExtensions.add("xml");
309306
else if (!"DISABLED".equals(xmlMode))
310307
throw new UserError("Invalid XML mode '" + xmlMode + "' (should be either ALL or DISABLED).");
311308
}
@@ -744,8 +741,7 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state)
744741
try {
745742
long start = logBeginProcess("Extracting " + file);
746743
Integer loc = extractor.extract(f, state);
747-
if (!extractor.getConfig().isExterns() && (loc == null || loc != 0))
748-
seenCode = true;
744+
if (!extractor.getConfig().isExterns() && (loc == null || loc != 0)) seenCode = true;
749745
logEndProcess(start, "Done extracting " + file);
750746
} catch (Throwable t) {
751747
System.err.println("Exception while extracting " + file + ".");
@@ -776,8 +772,7 @@ public Set<String> getXmlExtensions() {
776772
}
777773

778774
protected void extractXml() throws IOException {
779-
if (xmlExtensions.isEmpty())
780-
return;
775+
if (xmlExtensions.isEmpty()) return;
781776
List<String> cmd = new ArrayList<>();
782777
cmd.add("odasa");
783778
cmd.add("index");

javascript/extractor/src/com/semmle/js/extractor/FileExtractor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,7 @@ public boolean supports(File f) {
384384
return config.hasFileType() || FileType.forFile(f, config) != null;
385385
}
386386

387-
/**
388-
* @return the number of lines of code extracted, or {@code null} if the file was cached
389-
*/
387+
/** @return the number of lines of code extracted, or {@code null} if the file was cached */
390388
public Integer extract(File f, ExtractorState state) throws IOException {
391389
// populate source archive
392390
String source = new WholeIO(config.getDefaultEncoding()).strictread(f);

javascript/extractor/src/com/semmle/js/extractor/TypeExprKinds.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.semmle.ts.ast.InterfaceTypeExpr;
1818
import com.semmle.ts.ast.IntersectionTypeExpr;
1919
import com.semmle.ts.ast.IsTypeExpr;
20-
import com.semmle.ts.ast.UnaryTypeExpr;
2120
import com.semmle.ts.ast.KeywordTypeExpr;
2221
import com.semmle.ts.ast.MappedTypeExpr;
2322
import com.semmle.ts.ast.OptionalTypeExpr;
@@ -26,6 +25,7 @@
2625
import com.semmle.ts.ast.TupleTypeExpr;
2726
import com.semmle.ts.ast.TypeParameter;
2827
import com.semmle.ts.ast.TypeofTypeExpr;
28+
import com.semmle.ts.ast.UnaryTypeExpr;
2929
import com.semmle.ts.ast.UnionTypeExpr;
3030
import com.semmle.util.exception.CatastrophicError;
3131

@@ -129,8 +129,10 @@ public Integer visit(TupleTypeExpr nd, Void c) {
129129
@Override
130130
public Integer visit(UnaryTypeExpr nd, Void c) {
131131
switch (nd.getKind()) {
132-
case Keyof: return keyofTypeExpr;
133-
case Readonly: return readonlyTypeExpr;
132+
case Keyof:
133+
return keyofTypeExpr;
134+
case Readonly:
135+
return readonlyTypeExpr;
134136
}
135137
throw new CatastrophicError("Unhandled UnaryTypeExpr kind: " + nd.getKind());
136138
}

javascript/extractor/src/com/semmle/js/extractor/test/AutoBuildTests.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package com.semmle.js.extractor.test;
22

3+
import com.semmle.js.extractor.AutoBuild;
4+
import com.semmle.js.extractor.ExtractorState;
5+
import com.semmle.js.extractor.FileExtractor;
6+
import com.semmle.js.extractor.FileExtractor.FileType;
7+
import com.semmle.util.data.StringUtil;
8+
import com.semmle.util.exception.UserError;
9+
import com.semmle.util.files.FileUtil;
10+
import com.semmle.util.files.FileUtil8;
11+
import com.semmle.util.process.Env;
312
import java.io.File;
413
import java.io.IOException;
514
import java.nio.charset.StandardCharsets;
@@ -16,23 +25,12 @@
1625
import java.util.List;
1726
import java.util.Map;
1827
import java.util.Set;
19-
2028
import org.junit.After;
2129
import org.junit.Assert;
2230
import org.junit.Assume;
2331
import org.junit.Before;
2432
import org.junit.Test;
2533

26-
import com.semmle.js.extractor.AutoBuild;
27-
import com.semmle.js.extractor.ExtractorState;
28-
import com.semmle.js.extractor.FileExtractor;
29-
import com.semmle.js.extractor.FileExtractor.FileType;
30-
import com.semmle.util.data.StringUtil;
31-
import com.semmle.util.exception.UserError;
32-
import com.semmle.util.files.FileUtil;
33-
import com.semmle.util.files.FileUtil8;
34-
import com.semmle.util.process.Env;
35-
3634
public class AutoBuildTests {
3735
private Path SEMMLE_DIST, LGTM_SRC;
3836
private Set<String> expected;
@@ -132,16 +130,18 @@ public void extractTypeScriptFiles(
132130

133131
@Override
134132
protected void extractXml() throws IOException {
135-
Files.walkFileTree(LGTM_SRC, new SimpleFileVisitor<Path>(){
136-
@Override
137-
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
138-
throws IOException {
139-
String ext = FileUtil.extension(file);
140-
if (!ext.isEmpty() && getXmlExtensions().contains(ext.substring(1)))
141-
actual.add(file.toString());
142-
return FileVisitResult.CONTINUE;
143-
}
144-
});
133+
Files.walkFileTree(
134+
LGTM_SRC,
135+
new SimpleFileVisitor<Path>() {
136+
@Override
137+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
138+
throws IOException {
139+
String ext = FileUtil.extension(file);
140+
if (!ext.isEmpty() && getXmlExtensions().contains(ext.substring(1)))
141+
actual.add(file.toString());
142+
return FileVisitResult.CONTINUE;
143+
}
144+
});
145145
}
146146
}.run();
147147
String expectedString = StringUtil.glue("\n", expected.stream().sorted().toArray());

javascript/extractor/src/com/semmle/js/parser/JSDocParser.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ public JSDocComment parse(Comment comment) {
4747
// This occurs before the start of 'source', so the lineStart is negative.
4848
int firstLineStart = -(startPos.getColumn() + "/**".length() - 1);
4949
this.absoluteOffset = startPos.getOffset();
50-
Pair<String, List<JSDocTagParser.Tag>> r = p.new TagParser(null).parseComment(
51-
startPos.getLine() - 1,
52-
firstLineStart);
50+
Pair<String, List<JSDocTagParser.Tag>> r =
51+
p.new TagParser(null).parseComment(startPos.getLine() - 1, firstLineStart);
5352
List<JSDocTag> tags = new ArrayList<>();
5453
for (JSDocTagParser.Tag tag : r.snd()) {
5554
String title = tag.title;
@@ -269,21 +268,21 @@ private SourceLocation loc() {
269268
return new SourceLocation(pos());
270269
}
271270

272-
/**
273-
* Returns the absolute position of the start of the current token.
274-
*/
271+
/** Returns the absolute position of the start of the current token. */
275272
private Position pos() {
276-
return new Position(this.lineNumber + 1, startOfCurToken - lineStart, startOfCurToken + absoluteOffset);
273+
return new Position(
274+
this.lineNumber + 1, startOfCurToken - lineStart, startOfCurToken + absoluteOffset);
277275
}
278276

279277
/**
280278
* Returns the absolute position of the end of the previous token.
281279
*
282-
* This can differ from the start of the current token in case the two tokens
283-
* are separated by whitespace.
280+
* <p>This can differ from the start of the current token in case the two tokens are separated
281+
* by whitespace.
284282
*/
285283
private Position endPos() {
286-
return new Position(this.lineNumber + 1, endOfPrevToken - lineStart, endOfPrevToken + absoluteOffset);
284+
return new Position(
285+
this.lineNumber + 1, endOfPrevToken - lineStart, endOfPrevToken + absoluteOffset);
287286
}
288287

289288
private <T extends JSDocTypeExpression> T finishNode(T node) {
@@ -306,7 +305,8 @@ private int advance() {
306305
if (index >= source.length()) return -1;
307306
int ch = source.charAt(index);
308307
++index;
309-
if (isLineTerminator(ch) && !(ch == '\r' && index < endIndex && source.charAt(index) == '\n')) {
308+
if (isLineTerminator(ch)
309+
&& !(ch == '\r' && index < endIndex && source.charAt(index) == '\n')) {
310310
lineNumber += 1;
311311
lineStart = index;
312312
index = skipStars(index, endIndex);
@@ -950,7 +950,10 @@ private List<JSDocTypeExpression> parseParametersType() throws ParseError {
950950
consume(Token.COLON);
951951
expr =
952952
finishNode(
953-
new ParameterType(new SourceLocation(loc), ((NameExpression) expr).getName(), parseTypeExpression()));
953+
new ParameterType(
954+
new SourceLocation(loc),
955+
((NameExpression) expr).getName(),
956+
parseTypeExpression()));
954957
}
955958
if (token == Token.EQUAL) {
956959
consume(Token.EQUAL);
@@ -1125,8 +1128,7 @@ private JSDocTypeExpression parseTypeExpression() throws ParseError {
11251128
consume(Token.RBRACK, "expected an array-style type declaration (' + value + '[])");
11261129
List<JSDocTypeExpression> expressions = new ArrayList<>();
11271130
expressions.add(expr);
1128-
NameExpression nameExpr =
1129-
finishNode(new NameExpression(new SourceLocation(loc), "Array"));
1131+
NameExpression nameExpr = finishNode(new NameExpression(new SourceLocation(loc), "Array"));
11301132
return finishNode(new TypeApplication(loc, nameExpr, expressions));
11311133
}
11321134

@@ -1183,7 +1185,8 @@ private JSDocTypeExpression parseTopParamType() throws ParseError {
11831185
return expr;
11841186
}
11851187

1186-
private JSDocTypeExpression parseType(int startIndex, int endIndex, int lineStart, int lineNumber) throws ParseError {
1188+
private JSDocTypeExpression parseType(
1189+
int startIndex, int endIndex, int lineStart, int lineNumber) throws ParseError {
11871190
JSDocTypeExpression expr;
11881191

11891192
this.lineNumber = lineNumber;
@@ -1202,7 +1205,8 @@ private JSDocTypeExpression parseType(int startIndex, int endIndex, int lineStar
12021205
return expr;
12031206
}
12041207

1205-
private JSDocTypeExpression parseParamType(int startIndex, int endIndex, int lineStart, int lineNumber) throws ParseError {
1208+
private JSDocTypeExpression parseParamType(
1209+
int startIndex, int endIndex, int lineStart, int lineNumber) throws ParseError {
12061210
JSDocTypeExpression expr;
12071211

12081212
this.lineNumber = lineNumber;

0 commit comments

Comments
 (0)