Skip to content
This repository was archived by the owner on Jun 1, 2019. It is now read-only.

Commit 090d2e0

Browse files
committed
Remove dependencies on Java 7 std library.
1 parent fa8d632 commit 090d2e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+146
-140
lines changed

src/com/google/javascript/jscomp/AbstractCommandLineRunner.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.US_ASCII;
20-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.US_ASCII;
20+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2121

2222
import com.google.common.annotations.GwtIncompatible;
2323
import com.google.common.annotations.VisibleForTesting;

src/com/google/javascript/jscomp/AliasStrings.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.annotations.GwtIncompatible;
2222
import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;

src/com/google/javascript/jscomp/CallGraph.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.LinkedHashMap;
3232
import java.util.LinkedList;
3333
import java.util.Map;
34-
import java.util.Objects;
34+
import java7compat.util.Objects;
3535

3636
/**
3737
* A pass the uses a {@link DefinitionProvider} to compute a call graph for an

src/com/google/javascript/jscomp/CommandLineRunner.java

+15-67
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.annotations.GwtIncompatible;
2222
import com.google.common.base.Joiner;
@@ -45,22 +45,9 @@
4545
import org.kohsuke.args4j.spi.Setter;
4646
import org.kohsuke.args4j.spi.StringOptionHandler;
4747

48-
import java.io.BufferedReader;
49-
import java.io.File;
50-
import java.io.FileInputStream;
51-
import java.io.IOException;
52-
import java.io.InputStream;
53-
import java.io.OutputStreamWriter;
54-
import java.io.PrintStream;
48+
import java.io.*;
5549
import java.lang.reflect.AnnotatedElement;
56-
import java.nio.file.FileSystem;
57-
import java.nio.file.FileSystems;
58-
import java.nio.file.FileVisitResult;
59-
import java.nio.file.Path;
60-
import java.nio.file.PathMatcher;
61-
import java.nio.file.Paths;
62-
import java.nio.file.SimpleFileVisitor;
63-
import java.nio.file.attribute.BasicFileAttributes;
50+
import java.net.URI;
6451
import java.util.ArrayList;
6552
import java.util.Collection;
6653
import java.util.Collections;
@@ -1181,10 +1168,12 @@ private void reportError(String message) {
11811168

11821169
private void processFlagFile()
11831170
throws CmdLineException, IOException {
1184-
Path flagFile = Paths.get(flags.flagFile);
1171+
File flagFile = new File(flags.flagFile);
1172+
1173+
InputStream newInputStream = new FileInputStream(flagFile);
1174+
Reader reader = new InputStreamReader(newInputStream, UTF_8.newDecoder());
1175+
BufferedReader buffer = new BufferedReader(reader);
11851176

1186-
BufferedReader buffer =
1187-
java.nio.file.Files.newBufferedReader(flagFile, UTF_8);
11881177
// Builds the tokens.
11891178
StringBuilder builder = new StringBuilder();
11901179
// Stores the built tokens.
@@ -1568,13 +1557,15 @@ protected CompilerOptions createOptions() {
15681557
Instrumentation.Builder builder = Instrumentation.newBuilder();
15691558
BufferedReader br = null;
15701559
try {
1571-
br = new BufferedReader(Files.newReader(new File(flags.instrumentationFile), UTF_8));
1560+
InputStream newInputStream = new FileInputStream(new File(flags.instrumentationFile));
1561+
Reader reader = new InputStreamReader(newInputStream, UTF_8.newDecoder());
1562+
br = new BufferedReader(reader);
15721563
StringBuilder sb = new StringBuilder();
15731564
String line = br.readLine();
15741565

15751566
while (line != null) {
15761567
sb.append(line);
1577-
sb.append(System.lineSeparator());
1568+
sb.append(System.getProperty("line.separator"));
15781569
line = br.readLine();
15791570
}
15801571
instrumentationPb = sb.toString();
@@ -1685,8 +1676,8 @@ private static List<String> findJsFiles(Collection<String> patterns, boolean sor
16851676
if (matchedFile.isDirectory()) {
16861677
matchPaths(new File(matchedFile, "**.js").toString(), allJsInputs, excludes);
16871678
} else {
1688-
Path original = Paths.get(pattern);
1689-
String pathStringAbsolute = original.normalize().toAbsolutePath().toString();
1679+
URI original = new File(pattern).toURI();
1680+
String pathStringAbsolute = new File(original.normalize().toString()).getAbsolutePath();
16901681
if (!excludes.contains(pathStringAbsolute)) {
16911682
allJsInputs.put(pathStringAbsolute, original.toString());
16921683
}
@@ -1701,50 +1692,7 @@ private static List<String> findJsFiles(Collection<String> patterns, boolean sor
17011692

17021693
private static void matchPaths(String pattern, final Map<String, String> allJsInputs,
17031694
final Set<String> excludes) throws IOException {
1704-
FileSystem fs = FileSystems.getDefault();
1705-
final boolean remove = pattern.indexOf('!') == 0;
1706-
if (remove) {
1707-
pattern = pattern.substring(1);
1708-
}
1709-
1710-
String separator = File.separator.equals("\\") ? "\\\\" : File.separator;
1711-
1712-
// Split the pattern into two pieces: the globbing part
1713-
// and the non-globbing prefix.
1714-
List<String> patternParts = Splitter.on(File.separator).splitToList(pattern);
1715-
String prefix = ".";
1716-
for (int i = 0; i < patternParts.size(); i++) {
1717-
if (patternParts.get(i).contains("*")) {
1718-
if (i > 0) {
1719-
prefix = Joiner.on(separator).join(patternParts.subList(0, i));
1720-
pattern = Joiner.on(separator).join(patternParts.subList(i, patternParts.size()));
1721-
}
1722-
break;
1723-
}
1724-
}
1725-
1726-
final PathMatcher matcher = fs.getPathMatcher("glob:" + prefix + separator + pattern);
1727-
java.nio.file.Files.walkFileTree(
1728-
fs.getPath(prefix), new SimpleFileVisitor<Path>() {
1729-
@Override
1730-
public FileVisitResult visitFile(Path p, BasicFileAttributes attrs) {
1731-
if (matcher.matches(p) || matcher.matches(p.normalize())) {
1732-
String pathStringAbsolute = p.normalize().toAbsolutePath().toString();
1733-
if (remove) {
1734-
excludes.add(pathStringAbsolute);
1735-
allJsInputs.remove(pathStringAbsolute);
1736-
} else if (!excludes.contains(pathStringAbsolute)) {
1737-
allJsInputs.put(pathStringAbsolute, p.toString());
1738-
}
1739-
}
1740-
return FileVisitResult.CONTINUE;
1741-
}
1742-
1743-
@Override
1744-
public FileVisitResult visitFileFailed(Path file, IOException e) {
1745-
return FileVisitResult.SKIP_SUBTREE;
1746-
}
1747-
});
1695+
throw new UnsupportedOperationException("");
17481696
}
17491697

17501698
/**

src/com/google/javascript/jscomp/Compiler.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import java.io.File;
5050
import java.io.IOException;
5151
import java.io.PrintStream;
52-
import java.nio.file.FileSystems;
5352
import java.util.ArrayList;
5453
import java.util.Collections;
5554
import java.util.HashMap;
@@ -562,8 +561,9 @@ private static List<CompilerInput> getAllInputsFromModules(
562561
* getRelativeTo("../foo/bar.js", "baz/bam/qux.js") --> "baz/foo/bar.js"
563562
*/
564563
private static String getRelativeTo(String relative, String base) {
565-
return FileSystems.getDefault().getPath(base)
566-
.resolveSibling(relative)
564+
return new File(base)
565+
.toURI()
566+
.resolve(relative)
567567
.normalize()
568568
.toString()
569569
.replace(File.separator, "/");

src/com/google/javascript/jscomp/DataFlowAnalysis.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.Iterator;
3232
import java.util.LinkedHashSet;
3333
import java.util.List;
34-
import java.util.Objects;
34+
import java7compat.util.Objects;
3535
import java.util.Set;
3636
import java.util.TreeSet;
3737

src/com/google/javascript/jscomp/DefaultPassConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.javascript.jscomp;
1818

1919
import static com.google.javascript.jscomp.PassFactory.createEmptyPass;
20-
import static java.nio.charset.StandardCharsets.UTF_8;
20+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2121

2222
import com.google.common.annotations.VisibleForTesting;
2323
import com.google.common.base.Preconditions;

src/com/google/javascript/jscomp/FileInstrumentationData.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ String getInstrumentedLinesAsHexString() {
6161
StringBuilder builder = new StringBuilder();
6262

6363
// Build the hex string.
64-
for (byte byteEntry : instrumentedBits.toByteArray()) {
64+
for (byte byteEntry : toByteArray(instrumentedBits)) {
6565
// Java bytes are signed, but we want the value as if it were unsigned.
6666
int value = UnsignedBytes.toInt(byteEntry);
6767
String hexString = Integer.toHexString(value);
@@ -75,6 +75,15 @@ String getInstrumentedLinesAsHexString() {
7575
return builder.toString();
7676
}
7777

78+
private static byte[] toByteArray(BitSet bits) {
79+
byte[] bytes = new byte[(bits.length() + 7) / 8];
80+
for (int i = 0; i < bits.length(); i++) {
81+
if (bits.get(i)) {
82+
bytes[(bytes.length - i) / (8 - 1)] |= 1 << (i % 8);
83+
}
84+
}
85+
return bytes;
86+
}
7887

7988
/**
8089
* Mark given 1-based line number as instrumented. Zero, Negative numbers

src/com/google/javascript/jscomp/GlobalNamespace.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import java.util.HashMap;
3838
import java.util.List;
3939
import java.util.Map;
40-
import java.util.Objects;
40+
import java7compat.util.Objects;
4141
import java.util.Set;
4242

4343
/**

src/com/google/javascript/jscomp/GoogleJsMessageIdGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.base.CaseFormat;
2222
import com.google.common.base.Preconditions;

src/com/google/javascript/jscomp/JsMessage.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.annotations.GwtIncompatible;
2222
import com.google.common.base.Preconditions;

src/com/google/javascript/jscomp/Linter.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import com.google.javascript.refactoring.SuggestedFix;
2525

2626
import java.io.IOException;
27-
import java.nio.file.Path;
28-
import java.nio.file.Paths;
2927
import java.util.ArrayList;
3028
import java.util.List;
3129

@@ -45,15 +43,15 @@ public static void main(String[] args) throws IOException {
4543

4644

4745
static void lint(String filename) throws IOException {
48-
lint(Paths.get(filename), false);
46+
lint(filename, false);
4947
}
5048

5149
static void fix(String filename) throws IOException {
52-
lint(Paths.get(filename), true);
50+
lint(filename, true);
5351
}
5452

55-
private static void lint(Path path, boolean fix) throws IOException {
56-
SourceFile file = SourceFile.fromFile(path.toString());
53+
private static void lint(String filename, boolean fix) throws IOException {
54+
SourceFile file = SourceFile.fromFile(filename);
5755
Compiler compiler = new Compiler(System.out);
5856
CompilerOptions options = new CompilerOptions();
5957
options.setLanguage(LanguageMode.ECMASCRIPT6_STRICT);

src/com/google/javascript/jscomp/NameAnalyzer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.base.Preconditions;
2222
import com.google.common.base.Predicate;

src/com/google/javascript/jscomp/NewTypeInference.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import java.util.LinkedList;
4949
import java.util.List;
5050
import java.util.Map;
51-
import java.util.Objects;
51+
import java7compat.util.Objects;
5252
import java.util.Set;
5353

5454
/**

src/com/google/javascript/jscomp/NodeTraversal.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ public final boolean shouldTraverse(NodeTraversal t, Node n, Node p) {
547547

548548
/**
549549
* Traverses a node recursively.
550-
* @deprecated Use traverseEs6 whenever possible.
550+
* Use traverseEs6 whenever possible.
551551
*/
552552
@Deprecated
553553
public static void traverse(AbstractCompiler compiler, Node root, Callback cb) {

src/com/google/javascript/jscomp/OutputCharsetEncoder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.US_ASCII;
19+
import static java7compat.nio.charset.StandardCharsets.US_ASCII;
2020

2121
import com.google.common.annotations.GwtIncompatible;
2222

src/com/google/javascript/jscomp/PerformanceTracker.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.annotations.GwtIncompatible;
2222
import com.google.common.annotations.VisibleForTesting;
@@ -283,7 +283,7 @@ public void outputTracerReport(PrintStream pstr) {
283283
new Comparator<Entry<String, Stats>>() {
284284
@Override
285285
public int compare(Entry<String, Stats> e1, Entry<String, Stats> e2) {
286-
return Long.compare(e1.getValue().runtime, e2.getValue().runtime);
286+
return Long.valueOf(e1.getValue().runtime).compareTo(e2.getValue().runtime);
287287
}
288288
});
289289

src/com/google/javascript/jscomp/PureFunctionIdentifier.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.base.Preconditions;
2222
import com.google.common.base.Predicate;

src/com/google/javascript/jscomp/ResourceLoader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.annotations.GwtIncompatible;
2222
import com.google.common.io.CharStreams;

src/com/google/javascript/jscomp/SourceFile.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.google.javascript.jscomp;
1818

1919
import static com.google.common.base.Strings.isNullOrEmpty;
20-
import static java.nio.charset.StandardCharsets.UTF_8;
20+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2121

2222
import com.google.common.annotations.GwtIncompatible;
2323
import com.google.common.annotations.VisibleForTesting;
@@ -36,7 +36,7 @@
3636
import java.io.StringReader;
3737
import java.net.URL;
3838
import java.nio.charset.Charset;
39-
import java.nio.charset.StandardCharsets;
39+
import java7compat.nio.charset.StandardCharsets;
4040
import java.util.ArrayList;
4141
import java.util.Arrays;
4242
import java.util.Enumeration;

src/com/google/javascript/jscomp/TransformAMDToCJSModule.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void handleRequiresAndParamList(NodeTraversal t, Node defineNode,
158158
Iterator<Node> paramList = callback.getSecondChild().children().
159159
iterator();
160160
Iterator<Node> requires = requiresNode != null ?
161-
requiresNode.children().iterator() : Collections.<Node>emptyIterator();
161+
requiresNode.children().iterator() : Collections.<Node>emptyList().iterator();
162162
while (paramList.hasNext() || requires.hasNext()) {
163163
Node aliasNode = paramList.hasNext() ? paramList.next() : null;
164164
Node modNode = requires.hasNext() ? requires.next() : null;

src/com/google/javascript/jscomp/TypeValidator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import java.util.ArrayList;
4747
import java.util.Iterator;
4848
import java.util.List;
49-
import java.util.Objects;
49+
import java7compat.util.Objects;
5050

5151
import javax.annotation.Nullable;
5252

src/com/google/javascript/jscomp/VariableMap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.javascript.jscomp;
1818

19-
import static java.nio.charset.StandardCharsets.UTF_8;
19+
import static java7compat.nio.charset.StandardCharsets.UTF_8;
2020

2121
import com.google.common.annotations.GwtIncompatible;
2222
import com.google.common.annotations.VisibleForTesting;

0 commit comments

Comments
 (0)