mirror of https://github.com/FabricMC/yarn.git
Fix redundant public modifier for inner classes, migrate to modern java
Signed-off-by: liach <liach@users.noreply.github.com>
This commit is contained in:
parent
957c0f5138
commit
defbde19d8
|
@ -146,15 +146,15 @@ public class ClassBuilder {
|
|||
builder = TypeSpec.enumBuilder(name);
|
||||
} else {
|
||||
builder = TypeSpec.classBuilder(name)
|
||||
.superclass(signature.superclass);
|
||||
.superclass(signature.superclass());
|
||||
}
|
||||
|
||||
if (!signature.generics.isEmpty()) {
|
||||
builder.addTypeVariables(signature.generics);
|
||||
if (!signature.generics().isEmpty()) {
|
||||
builder.addTypeVariables(signature.generics());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(classNode.name);
|
||||
sb.append("<");
|
||||
for (TypeVariableName each : signature.generics) {
|
||||
for (TypeVariableName each : signature.generics()) {
|
||||
sb.append("T").append(each.name).append(";");
|
||||
}
|
||||
sb.append(">");
|
||||
|
@ -170,7 +170,7 @@ public class ClassBuilder {
|
|||
return;
|
||||
}
|
||||
if (signature != null) {
|
||||
builder.addSuperinterfaces(signature.superinterfaces);
|
||||
builder.addSuperinterfaces(signature.superinterfaces());
|
||||
return;
|
||||
}
|
||||
if (classNode.interfaces.isEmpty()) return;
|
||||
|
@ -284,6 +284,7 @@ public class ClassBuilder {
|
|||
classBuilder.builder.addModifiers(javax.lang.model.element.Modifier.PUBLIC);
|
||||
classBuilder.builder.addModifiers(javax.lang.model.element.Modifier.STATIC);
|
||||
} else {
|
||||
classBuilder.builder.modifiers.remove(javax.lang.model.element.Modifier.PUBLIC); // this modifier may come from class access
|
||||
classBuilder.builder.addModifiers(new ModifierBuilder(innerClassNode.access).getModifiers(classBuilder.enumClass ? ModifierBuilder.Type.ENUM : ModifierBuilder.Type.CLASS));
|
||||
if (!Modifier.isStatic(innerClassNode.access)) {
|
||||
classBuilder.instanceInner = true;
|
||||
|
@ -295,7 +296,7 @@ public class ClassBuilder {
|
|||
sb.append(this.receiverSignature).append("."); // like O<TT;>. for O<T>
|
||||
sb.append(innerClassNode.innerName); // append simple name
|
||||
|
||||
List<TypeVariableName> innerClassGenerics = classBuilder.signature.generics;
|
||||
List<TypeVariableName> innerClassGenerics = classBuilder.signature.generics();
|
||||
if (!innerClassGenerics.isEmpty()) {
|
||||
sb.append("<");
|
||||
for (TypeVariableName each : innerClassGenerics) {
|
||||
|
|
|
@ -166,7 +166,7 @@ public class Main {
|
|||
|
||||
private static void scanInnerClasses(Map<String, Boolean> instanceInnerClasses, Path librariesDir) {
|
||||
try {
|
||||
Files.walkFileTree(librariesDir, new SimpleFileVisitor<Path>() {
|
||||
Files.walkFileTree(librariesDir, new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
if (!file.getFileName().toString().endsWith(".jar")) {
|
||||
|
|
|
@ -159,7 +159,7 @@ public class MethodBuilder {
|
|||
|
||||
if (methodNode.signature != null) {
|
||||
signature = AnnotationAwareSignatures.parseMethodSignature(methodNode.signature, typeAnnotations, context);
|
||||
builder.addTypeVariables(signature.generics);
|
||||
builder.addTypeVariables(signature.generics());
|
||||
}
|
||||
|
||||
return builder;
|
||||
|
@ -187,7 +187,7 @@ public class MethodBuilder {
|
|||
|
||||
TypeName typeName;
|
||||
if (signature != null) {
|
||||
typeName = signature.result;
|
||||
typeName = signature.result();
|
||||
} else {
|
||||
String returnDesc = methodNode.desc.substring(methodNode.desc.lastIndexOf(")") + 1);
|
||||
typeName = AnnotationAwareDescriptors.parseDesc(returnDesc, typeAnnotations.getBank(TypeReference.newTypeReference(TypeReference.METHOD_RETURN)), context);
|
||||
|
@ -257,7 +257,7 @@ public class MethodBuilder {
|
|||
}
|
||||
index++; // consume '('
|
||||
|
||||
Iterator<TypeName> signatureParamIterator = signature == null ? Collections.emptyIterator() : signature.parameters.iterator();
|
||||
Iterator<TypeName> signatureParamIterator = signature == null ? Collections.emptyIterator() : signature.parameters().iterator();
|
||||
while (desc.charAt(index) != ')') {
|
||||
int oldIndex = index;
|
||||
Map.Entry<Integer, TypeName> parsedParam = FieldBuilder.parseType(desc, index);
|
||||
|
@ -288,8 +288,8 @@ public class MethodBuilder {
|
|||
}
|
||||
|
||||
private void addExceptions() {
|
||||
if (signature != null && !signature.thrown.isEmpty()) {
|
||||
for (TypeName each : signature.thrown) {
|
||||
if (signature != null && !signature.thrown().isEmpty()) {
|
||||
for (TypeName each : signature.thrown()) {
|
||||
builder.addException(each);
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -22,14 +22,7 @@ import com.squareup.javapoet.TypeName;
|
|||
import com.squareup.javapoet.TypeVariableName;
|
||||
|
||||
// no more a class signature but general super info about class
|
||||
public final class ClassSignature {
|
||||
public final List<TypeVariableName> generics;
|
||||
public final TypeName superclass;
|
||||
public final List<TypeName> superinterfaces;
|
||||
public record ClassSignature(List<TypeVariableName> generics, TypeName superclass,
|
||||
List<TypeName> superinterfaces) {
|
||||
|
||||
public ClassSignature(List<TypeVariableName> generics, TypeName superclass, List<TypeName> superinterfaces) {
|
||||
this.generics = generics;
|
||||
this.superclass = superclass;
|
||||
this.superinterfaces = superinterfaces;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public interface ClassStaticContext {
|
|||
/**
|
||||
* Returns if this class is an instance inner class.
|
||||
*
|
||||
* <p>For example, a top-level class is not so. A static inner
|
||||
* <p>For example, a top-level class is not so. A static nested
|
||||
* class, such as {@code Map.Entry}, is not as well.</p>
|
||||
*
|
||||
* @param internalName the JVM name of the class
|
||||
|
|
|
@ -21,16 +21,8 @@ import java.util.List;
|
|||
import com.squareup.javapoet.TypeName;
|
||||
import com.squareup.javapoet.TypeVariableName;
|
||||
|
||||
public final class MethodSignature {
|
||||
public final List<TypeVariableName> generics;
|
||||
public final List<TypeName> parameters;
|
||||
public final TypeName result;
|
||||
public final List<TypeName> thrown;
|
||||
public record MethodSignature(List<TypeVariableName> generics,
|
||||
List<TypeName> parameters, TypeName result,
|
||||
List<TypeName> thrown) {
|
||||
|
||||
public MethodSignature(List<TypeVariableName> generics, List<TypeName> parameters, TypeName result, List<TypeName> thrown) {
|
||||
this.generics = generics;
|
||||
this.parameters = parameters;
|
||||
this.result = result;
|
||||
this.thrown = thrown;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,20 +150,12 @@ public final class PoetTypeSignatureWriter extends SignatureVisitor {
|
|||
private void collectLastTypeArgument() {
|
||||
if (activeTypeArgument != null) {
|
||||
TypeName hold = activeTypeArgument.compute();
|
||||
TypeName used;
|
||||
switch (activeTypeArgumentKind) {
|
||||
case SignatureVisitor.EXTENDS:
|
||||
used = WildcardTypeName.subtypeOf(hold);
|
||||
break;
|
||||
case SignatureVisitor.SUPER:
|
||||
used = WildcardTypeName.supertypeOf(hold);
|
||||
break;
|
||||
case SignatureVisitor.INSTANCEOF:
|
||||
used = hold;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException(String.format("Illegal type argument wildcard %s", activeTypeArgumentKind));
|
||||
}
|
||||
TypeName used = switch (activeTypeArgumentKind) {
|
||||
case SignatureVisitor.EXTENDS -> WildcardTypeName.subtypeOf(hold);
|
||||
case SignatureVisitor.SUPER -> WildcardTypeName.supertypeOf(hold);
|
||||
case SignatureVisitor.INSTANCEOF -> hold;
|
||||
default -> throw new IllegalStateException(String.format("Illegal type argument wildcard %s", activeTypeArgumentKind));
|
||||
};
|
||||
|
||||
used = AnnotationAwareDescriptors.annotate(used, storage.advance(TypePath.TYPE_ARGUMENT, params.size()));
|
||||
params.addLast(used);
|
||||
|
|
Loading…
Reference in New Issue