Skip to content

Commit

Permalink
Move gwt/client/JsfileParser.java into deps/JsFileFullParser.java.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=260560304
  • Loading branch information
tjgq authored and rishipal committed Jul 29, 2019
1 parent 1d61d33 commit c401fcf
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 22 deletions.
9 changes: 9 additions & 0 deletions pom-gwt.xml
Expand Up @@ -167,6 +167,15 @@
<version>1.0.0-beta-1</version>
</dependency>

<!-- We need both the binary and the sources jar for RE2/J, since the source code and the GWT
configuration file are in the sources jar, but maven-compiler-plugin will also perform a
regular build depending on the binary jar. -->
<dependency>
<groupId>com.google.re2j</groupId>
<artifactId>re2j</artifactId>
<version>1.3</version>
</dependency>

<dependency>
<groupId>com.google.re2j</groupId>
<artifactId>re2j</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions pom-main.xml
Expand Up @@ -150,6 +150,12 @@
<!-- See <dependencyManagement> in pom.xml for <version> -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.re2j</groupId>
<artifactId>re2j</artifactId>
<version>1.3</version>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> hasSoyDelcalls = new TreeSet<>();
final Set<String> hasSoyDeltemplates = new TreeSet<>();
public final Set<String> hasSoyDelcalls = new TreeSet<>();
public final Set<String> hasSoyDeltemplates = new TreeSet<>();
// Use a LinkedHashSet as import order matters!
final Set<String> importedModules = new LinkedHashSet<>();
final List<String> modName = new ArrayList<>();
final List<String> mods = new ArrayList<>();
public final Set<String> importedModules = new LinkedHashSet<>();
public final List<String> modName = new ArrayList<>();
public final List<String> 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<String> provides = TreeMultiset.create();
final Multiset<String> requires = TreeMultiset.create();
final Multiset<String> typeRequires = TreeMultiset.create();
final Multiset<String> requiresCss = TreeMultiset.create();
final Multiset<String> visibility = TreeMultiset.create();
public final Multiset<String> provides = TreeMultiset.create();
public final Multiset<String> requires = TreeMultiset.create();
public final Multiset<String> typeRequires = TreeMultiset.create();
public final Multiset<String> requiresCss = TreeMultiset.create();
public final Multiset<String> visibility = TreeMultiset.create();

final Multimap<String, String> customAnnotations = TreeMultimap.create();
final Multimap<String, String> loadFlags = TreeMultimap.create();
public final Multimap<String, String> customAnnotations = TreeMultimap.create();
public final Multimap<String, String> loadFlags = TreeMultimap.create();
}

/** Represents a single JSDoc annotation, with an optional argument. */
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -70,7 +71,8 @@ public native void exportGjd() /*-{
*/
@JsMethod(namespace = "jscomp")
public static JsObject<Object> 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) {
Expand Down Expand Up @@ -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;
}
Expand Down
52 changes: 52 additions & 0 deletions 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}.
*
* <p>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);
}
}

0 comments on commit c401fcf

Please sign in to comment.