From c401fcf037b346246eb5a454f95f4ab90c60460c Mon Sep 17 00:00:00 2001 From: tjgq Date: Mon, 29 Jul 2019 12:54:26 -0700 Subject: [PATCH] Move gwt/client/JsfileParser.java into deps/JsFileFullParser.java. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=260560304 --- pom-gwt.xml | 9 ++++ pom-main.xml | 6 +++ .../JsFileFullParser.java} | 41 ++++++++------- .../jscomp/gwt/client/JsfileParserGwt.java | 6 ++- .../jscomp/deps/JsFileFullParserTest.java | 52 +++++++++++++++++++ 5 files changed, 92 insertions(+), 22 deletions(-) rename src/com/google/javascript/jscomp/{gwt/client/JsfileParser.java => deps/JsFileFullParser.java} (90%) create mode 100644 test/com/google/javascript/jscomp/deps/JsFileFullParserTest.java diff --git a/pom-gwt.xml b/pom-gwt.xml index 46103f3d853..06ff7d54a13 100644 --- a/pom-gwt.xml +++ b/pom-gwt.xml @@ -167,6 +167,15 @@ 1.0.0-beta-1 + + + com.google.re2j + re2j + 1.3 + + com.google.re2j re2j diff --git a/pom-main.xml b/pom-main.xml index 16cee3cdeb4..81343aa1e1c 100644 --- a/pom-main.xml +++ b/pom-main.xml @@ -150,6 +150,12 @@ test + + + com.google.re2j + re2j + 1.3 + diff --git a/src/com/google/javascript/jscomp/gwt/client/JsfileParser.java b/src/com/google/javascript/jscomp/deps/JsFileFullParser.java similarity index 90% rename from src/com/google/javascript/jscomp/gwt/client/JsfileParser.java rename to src/com/google/javascript/jscomp/deps/JsFileFullParser.java index 6305e2e931b..264851ad726 100644 --- a/src/com/google/javascript/jscomp/gwt/client/JsfileParser.java +++ b/src/com/google/javascript/jscomp/deps/JsFileFullParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.google.javascript.jscomp.gwt.client; +package com.google.javascript.jscomp.deps; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; @@ -54,31 +54,32 @@ * goog.provide, goog.module, import/export statements, and JSDoc annotations related to dependency * management. */ -public class JsfileParser { - static final class FileInfo { - boolean goog = false; - boolean isConfig = false; - boolean isExterns = false; - boolean provideGoog = false; - boolean testonly = false; +public class JsFileFullParser { + /** The dependency information contained in a .js source file. */ + public static final class FileInfo { + public boolean goog = false; + public boolean isConfig = false; + public boolean isExterns = false; + public boolean provideGoog = false; + public boolean testonly = false; - final Set hasSoyDelcalls = new TreeSet<>(); - final Set hasSoyDeltemplates = new TreeSet<>(); + public final Set hasSoyDelcalls = new TreeSet<>(); + public final Set hasSoyDeltemplates = new TreeSet<>(); // Use a LinkedHashSet as import order matters! - final Set importedModules = new LinkedHashSet<>(); - final List modName = new ArrayList<>(); - final List mods = new ArrayList<>(); + public final Set importedModules = new LinkedHashSet<>(); + public final List modName = new ArrayList<>(); + public final List mods = new ArrayList<>(); // Note: multiple copies doesn't make much sense, but we report // each copy so that calling code can choose how to handle it - final Multiset provides = TreeMultiset.create(); - final Multiset requires = TreeMultiset.create(); - final Multiset typeRequires = TreeMultiset.create(); - final Multiset requiresCss = TreeMultiset.create(); - final Multiset visibility = TreeMultiset.create(); + public final Multiset provides = TreeMultiset.create(); + public final Multiset requires = TreeMultiset.create(); + public final Multiset typeRequires = TreeMultiset.create(); + public final Multiset requiresCss = TreeMultiset.create(); + public final Multiset visibility = TreeMultiset.create(); - final Multimap customAnnotations = TreeMultimap.create(); - final Multimap loadFlags = TreeMultimap.create(); + public final Multimap customAnnotations = TreeMultimap.create(); + public final Multimap loadFlags = TreeMultimap.create(); } /** Represents a single JSDoc annotation, with an optional argument. */ diff --git a/src/com/google/javascript/jscomp/gwt/client/JsfileParserGwt.java b/src/com/google/javascript/jscomp/gwt/client/JsfileParserGwt.java index 122aa1352d4..3eb14c36c63 100644 --- a/src/com/google/javascript/jscomp/gwt/client/JsfileParserGwt.java +++ b/src/com/google/javascript/jscomp/gwt/client/JsfileParserGwt.java @@ -17,6 +17,7 @@ package com.google.javascript.jscomp.gwt.client; import com.google.common.collect.Multimap; +import com.google.javascript.jscomp.deps.JsFileFullParser; import com.google.javascript.jscomp.gwt.client.Util.JsArray; import com.google.javascript.jscomp.gwt.client.Util.JsObject; import java.util.Map; @@ -70,7 +71,8 @@ public native void exportGjd() /*-{ */ @JsMethod(namespace = "jscomp") public static JsObject gjd(String code, String filename, @Nullable Reporter reporter) { - JsfileParser.FileInfo info = JsfileParser.parse(code, filename, adaptReporter(reporter)); + JsFileFullParser.FileInfo info = + JsFileFullParser.parse(code, filename, adaptReporter(reporter)); if (info.provideGoog) { info.provides.add("goog"); } else if (info.goog) { @@ -103,7 +105,7 @@ public interface Reporter { void report(boolean fatal, String message, String sourceName, int line, int lineOffset); } - private static JsfileParser.Reporter adaptReporter(@Nullable Reporter r) { + private static JsFileFullParser.Reporter adaptReporter(@Nullable Reporter r) { if (r == null) { return null; } diff --git a/test/com/google/javascript/jscomp/deps/JsFileFullParserTest.java b/test/com/google/javascript/jscomp/deps/JsFileFullParserTest.java new file mode 100644 index 00000000000..711909d8477 --- /dev/null +++ b/test/com/google/javascript/jscomp/deps/JsFileFullParserTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2019 The Closure Compiler Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.javascript.jscomp.deps; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.base.Joiner; +import com.google.javascript.jscomp.deps.JsFileFullParser.FileInfo; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** + * Unit tests for {@link JsFileFullParser}. + * + *

TODO(tjgq): Add more tests. + */ +@RunWith(JUnit4.class) +public final class JsFileFullParserTest { + @Test + public void testProvidesRequires() { + String contents = + lines( + "goog.provide('providedSymbol');", + "goog.require('stronglyRequiredSymbol');", + "goog.requireType('weaklyRequiredSymbol');"); + + FileInfo info = JsFileFullParser.parse(contents, "file.js", null); + + assertThat(info.provides).containsExactly("providedSymbol"); + assertThat(info.requires).containsExactly("stronglyRequiredSymbol"); + assertThat(info.typeRequires).containsExactly("weaklyRequiredSymbol"); + } + + private static String lines(String... lines) { + return Joiner.on('\n').join(lines); + } +}