Skip to content

Commit

Permalink
Merge branch 'master' of github.com:google/mug
Browse files Browse the repository at this point in the history
  • Loading branch information
fluentfuture committed Nov 29, 2023
2 parents 1a6cb38 + a525eaf commit de74060
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 458 deletions.
14 changes: 3 additions & 11 deletions mug-errorprone/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ java_library(
name = "errorprone",
srcs = glob(["src/main/java/**/*.java"]),
deps = [
":auto_service",
":error_prone_docgen",
"@maven//:com_google_auto_service_auto_service_annotations",
"@maven//:com_google_errorprone_error_prone_annotation",
"@maven//:com_google_errorprone_error_prone_annotations",
Expand All @@ -14,19 +16,9 @@ java_library(

java_plugin(
name = "plugin",
srcs = glob(["src/main/java/**/*.java"]),
visibility = ["//visibility:public"],
deps = [
":auto_service",
":error_prone_docgen",
"@maven//:com_google_auto_service_auto_service_annotations",
"@maven//:com_google_errorprone_error_prone_core",
"@maven//:com_google_errorprone_error_prone_annotation",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_errorprone_error_prone_check_api",
"@maven//:com_google_guava_guava",
"//mug:base",
"//mug-guava",
":errorprone",
],
)

Expand Down
71 changes: 14 additions & 57 deletions mug-errorprone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,33 @@
<version>6.6-SNAPSHOT</version>
</parent>
<artifactId>mug-errorprone</artifactId>
<name>Java Plugins</name>
<name>Compile-time Plugins</name>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.binarypb</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**/testdata/**</include>
</includes>
</testResource>
</testResources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
<annotationProcessorPaths>
<path>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>1.1.1</version>
</path>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.23.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.10.0</version>
<executions>
<execution>
<id>attach-descriptor</id>
<goals>
<goal>attach-descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<argLine>
-Xmx1g
Expand All @@ -88,13 +52,6 @@
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
40 changes: 1 addition & 39 deletions mug-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,14 @@
</parent>
<artifactId>mug-examples</artifactId>
<packaging>jar</packaging>

<name>examples</name>

<name>Examples</name>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<fork>true</fork>
<source>8</source>
<target>8</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
Expand All @@ -54,18 +33,6 @@
together with other annotation processors' below. -->
</annotationProcessorPaths>
</configuration>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mug-guava</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mug</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
Expand All @@ -86,27 +53,22 @@
<artifactId>mug-errorprone</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>

<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
</dependency>

<dependency>
<groupId>com.google.truth.extensions</groupId>
<artifactId>truth-java8-extension</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
56 changes: 5 additions & 51 deletions mug/src/main/java/com/google/mu/util/StringFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,6 @@ public final class StringFormat {
private final List<String> fragments; // The string literals between placeholders
private final List<Boolean> toCapture;
private final int numCapturingPlaceholders;
private final CharPredicate requiredChars; // null for unconstrained matches

/**
* Returns a strict StringFormat according to the {@code format} string. All placeholder values
* must be <em>non-empty</em> and all placeholder value characters must match {@code
* requiredChars}.
*
* <p>For example:
*
* <pre>{@code
* StringFormat userFormat =
* StringFormat.strict("user: {user_id}", CharMatcher.inRange('0', '9'));
* userFormat.parse("user: 123", id -> Integer.parseInt(id)) => Optional.of(123)
* userFormat.parse("user: xyz", ...) => empty()
* userFormat.parse("user: ", ...) => empty()
* }</pre>
*
* <p>Note that {@code requiredChars} applies to all placeholders. If you need to apply
* constraints on an individual placeholder, consider filtering in the lambda by returning null if
* the placeholder value isn't valid.
*
* <p>Parameters passed to {@link #format} are not checked so it's possible that {@code format()}
* returns a string not parseable by the same {@code StringFormat} strict instance.
*
* @since 6.7
* @deprecated Consider manually checking the placeholder values in the lambda
*/
@Deprecated
public static StringFormat strict(String format, CharPredicate requiredChars) {
return new StringFormat(format, requireNonNull(requiredChars));
}

/**
* Returns a {@link Substring.Pattern} spanning the substring matching {@code format}. For
Expand Down Expand Up @@ -258,10 +227,6 @@ public String toString() {
* (e.g. a placeholder immediately followed by another placeholder)
*/
public StringFormat(String format) {
this(format, null);
}

private StringFormat(String format, CharPredicate requiredChars) {
Stream.Builder<String> delimiters = Stream.builder();
Stream.Builder<Boolean> toCapture = Stream.builder();
PLACEHOLDERS.split(format).forEachOrdered(
Expand All @@ -274,7 +239,6 @@ private StringFormat(String format, CharPredicate requiredChars) {
this.toCapture = chop(toCapture.build().collect(toImmutableList()));
this.numCapturingPlaceholders =
this.fragments.size() - 1 - (int) this.toCapture.stream().filter(c -> !c).count();
this.requiredChars = requiredChars;
}

/**
Expand Down Expand Up @@ -394,9 +358,6 @@ private Optional<List<Substring.Match>> internalParse(
if (placeholder == null) {
return Optional.empty();
}
if (requiredChars != null && !isValidPlaceholderValue(placeholder)) {
return Optional.empty();
}
if (toCapture.get(i - 1)) {
builder.add(placeholder);
}
Expand Down Expand Up @@ -671,17 +632,17 @@ public boolean matches(String input) {
public Stream<List<Substring.Match>> scan(String input) {
requireNonNull(input);
if (format.isEmpty()) {
return requiredChars == null
? Stream.generate(() -> Collections.<Substring.Match>emptyList()).limit(input.length() + 1)
: Stream.empty();
return Stream.generate(() -> Collections.<Substring.Match>emptyList())
.limit(input.length() + 1);
}
int numPlaceholders = numPlaceholders();
Stream<List<Substring.Match>> groups = MoreStreams.whileNotNull(
return MoreStreams.whileNotNull(
new Supplier<List<Substring.Match>>() {
private int inputIndex = 0;
private boolean done = false;

@Override public List<Substring.Match> get() {
@Override
public List<Substring.Match> get() {
if (done) {
return null;
}
Expand Down Expand Up @@ -713,10 +674,6 @@ public Stream<List<Substring.Match>> scan(String input) {
return unmodifiableList(builder);
}
});
if (requiredChars == null) {
return groups;
}
return groups.filter(matches -> matches.stream().allMatch(this::isValidPlaceholderValue));
}

/**
Expand Down Expand Up @@ -996,9 +953,6 @@ private void checkPlaceholderCount(int expected) {
}
}

private boolean isValidPlaceholderValue(CharSequence chars) {
return requiredChars == null || (chars.length() > 0 && requiredChars.matchesAllOf(chars));
}

private void checkFormatArgs(Object[] args) {
if (args.length != numPlaceholders()) {
Expand Down
Loading

0 comments on commit de74060

Please sign in to comment.