Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up support for Multi-Release jars in Error Prone #4538

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-fixupmessages: "Classes found in the wrong directory"; restrict:=error; is:=warning
24 changes: 24 additions & 0 deletions check_api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,30 @@
</path>
</annotationProcessorPaths>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<jdkToolchain>
<version>11</version>
</jdkToolchain>
</configuration>
</execution>
<execution>
<id>java24</id>
<configuration>
<jdkToolchain>
<version>24</version>
</jdkToolchain>
<compileSourceRoots>
<compileSourceRoot>${basedir}/src/main/java24</compileSourceRoot>
</compileSourceRoots>
<!-- multiReleaseOutput requires setting release -->
<outputDirectory>${project.build.outputDirectory}/META-INF/versions/24</outputDirectory>
</configuration>
</execution>
</executions>

</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2024 The Error Prone 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.errorprone.util;

import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;

class ErrorProneSignatureGenerator extends Types.SignatureGenerator {

private final com.sun.tools.javac.util.ByteBuffer buffer =
new com.sun.tools.javac.util.ByteBuffer();

private final Names names;

protected ErrorProneSignatureGenerator(Types types, Names names) {
super(types);
this.names = names;
}

@Override
protected void append(char ch) {
buffer.appendByte(ch);
}

@Override
protected void append(byte[] ba) {
buffer.appendBytes(ba);
}

@Override
protected void append(Name name) {
buffer.appendName(name);
}

@SuppressWarnings("CatchingUnchecked") // handles InvalidUtfException on JDK 21+
@Override
public String toString() {
try {
return buffer.toName(names).toString();
} catch (Exception e) {
throw new AssertionError(e);
}
}
}
60 changes: 6 additions & 54 deletions check_api/src/main/java/com/google/errorprone/util/Signatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,76 +26,26 @@
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.code.Types.DefaultTypeVisitor;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;

/** Signature generation. */
public final class Signatures {

/** Returns the binary names of the class. */
public static String classDescriptor(Type type, VisitorState state) {
return new Signatures(state).classDescriptor(type);
}

private String classDescriptor(Type type) {
SigGen sig = new SigGen();
Types types = state.getTypes();
ErrorProneSignatureGenerator sig = new ErrorProneSignatureGenerator(types, state.getNames());
sig.assembleClassSig(types.erasure(type));
return sig.toString();
}

/** Returns a JVMS 4.3.3 method descriptor. */
public static String descriptor(Type type, VisitorState state) {
return new Signatures(state).descriptor(type);
}

private String descriptor(Type type) {
SigGen sig = new SigGen();
Types types = state.getTypes();
ErrorProneSignatureGenerator sig = new ErrorProneSignatureGenerator(types, state.getNames());
sig.assembleSig(types.erasure(type));
return sig.toString();
}

final Types types;
final Names names;

private Signatures(VisitorState state) {
this.types = state.getTypes();
this.names = state.getNames();
}

private class SigGen extends Types.SignatureGenerator {

private final com.sun.tools.javac.util.ByteBuffer buffer =
new com.sun.tools.javac.util.ByteBuffer();

protected SigGen() {
super(types);
}

@Override
protected void append(char ch) {
buffer.appendByte(ch);
}

@Override
protected void append(byte[] ba) {
buffer.appendBytes(ba);
}

@Override
protected void append(Name name) {
buffer.appendName(name);
}

@SuppressWarnings("CatchingUnchecked") // handles InvalidUtfException on JDK 21+
@Override
public String toString() {
try {
return buffer.toName(names).toString();
} catch (Exception e) {
throw new AssertionError(e);
}
}
}

/**
* Pretty-prints a method signature for use in diagnostics.
*
Expand Down Expand Up @@ -171,4 +121,6 @@ public String visitType(Type t, Void s) {
return t.toString();
}
};

private Signatures() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2024 The Error Prone 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.errorprone.util;

import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;

class ErrorProneSignatureGenerator extends Types.SignatureGenerator {

private final com.sun.tools.javac.util.ByteBuffer buffer =
new com.sun.tools.javac.util.ByteBuffer();

private final Names names;

protected ErrorProneSignatureGenerator(Types types, Names names) {
types.super();
this.names = names;
}

@Override
protected void append(char ch) {
buffer.appendByte(ch);
}

@Override
protected void append(byte[] ba) {
buffer.appendBytes(ba);
}

@Override
protected void append(Name name) {
buffer.appendName(name);
}

@SuppressWarnings("CatchingUnchecked") // handles InvalidUtfException on JDK 21+
@Override
public String toString() {
try {
return buffer.toName(names).toString();
} catch (Exception e) {
throw new AssertionError(e);
}
}
}
22 changes: 21 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.13.0</version>
<configuration>
<source>11</source>
<target>11</target>
Expand Down Expand Up @@ -264,6 +264,26 @@
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<toolchains>
<jdk>
<version>11</version>
<version>24</version>
</jdk>
</toolchains>
</configuration>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Loading