From 2dc4ef21292af7de44298f215713008be57730ff Mon Sep 17 00:00:00 2001 From: kindlich Date: Sat, 31 Aug 2024 10:07:39 +0200 Subject: [PATCH] Cleanup: Extract InterfaceResolvedType.of and some reformattings --- .../codemodel/type/builtin/ArrayTypeSymbol.java | 16 ++++++++-------- .../type/member/InterfaceResolvedType.java | 9 ++++++++- .../type/member/InterfaceResolvingType.java | 7 ++++--- .../codemodel/type/member/MemberSet.java | 15 ++++++++------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ArrayTypeSymbol.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ArrayTypeSymbol.java index 046d541d..8678bc46 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ArrayTypeSymbol.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ArrayTypeSymbol.java @@ -20,7 +20,7 @@ import static org.openzen.zenscript.codemodel.type.BasicTypeID.USIZE; public class ArrayTypeSymbol implements TypeSymbol { - private final Modifiers MODIFIERS = Modifiers.PUBLIC; + private static final Modifiers MODIFIERS = Modifiers.PUBLIC; public static final TypeParameter ELEMENT = new TypeParameter(BUILTIN, "E"); public static final GenericTypeID ELEMENT_TYPE = new GenericTypeID(ELEMENT); @@ -114,19 +114,19 @@ public ResolvingType resolve(TypeID[] typeArguments) { if (baseType == BYTE) members.method(new MethodInstance(BuiltinMethodSymbol.BYTE_ARRAY_AS_SBYTE_ARRAY)); - if (baseType == SBYTE) + else if (baseType == SBYTE) members.method(new MethodInstance(BuiltinMethodSymbol.SBYTE_ARRAY_AS_BYTE_ARRAY)); - if (baseType == SHORT) + else if (baseType == SHORT) members.method(new MethodInstance(BuiltinMethodSymbol.SHORT_ARRAY_AS_USHORT_ARRAY)); - if (baseType == USHORT) + else if (baseType == USHORT) members.method(new MethodInstance(BuiltinMethodSymbol.USHORT_ARRAY_AS_SHORT_ARRAY)); - if (baseType == INT) + else if (baseType == INT) members.method(new MethodInstance(BuiltinMethodSymbol.INT_ARRAY_AS_UINT_ARRAY)); - if (baseType == UINT) + else if (baseType == UINT) members.method(new MethodInstance(BuiltinMethodSymbol.UINT_ARRAY_AS_INT_ARRAY)); - if (baseType == LONG) + else if (baseType == LONG) members.method(new MethodInstance(BuiltinMethodSymbol.LONG_ARRAY_AS_ULONG_ARRAY)); - if (baseType == ULONG) + else if (baseType == ULONG) members.method(new MethodInstance(BuiltinMethodSymbol.ULONG_ARRAY_AS_LONG_ARRAY)); } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvedType.java index 2538981d..8e060d57 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvedType.java @@ -20,12 +20,19 @@ public class InterfaceResolvedType implements ResolvedType { private final List implementations; private final Collection implementedInterfaces; - public InterfaceResolvedType(ResolvedType baseType, Collection implementedInterfaces) { + private InterfaceResolvedType(ResolvedType baseType, Collection implementedInterfaces) { this.baseType = baseType; implementations = Stream.concat(Stream.of(baseType), implementedInterfaces.stream()).collect(Collectors.toList()); this.implementedInterfaces = implementedInterfaces.stream().map(ResolvedType::getType).collect(Collectors.toList()); } + public static ResolvedType of(ResolvedType baseType, Collection implementedInterfaces) { + if(implementedInterfaces.isEmpty()) + return baseType; + + return new InterfaceResolvedType(baseType, implementedInterfaces); + } + @Override public TypeID getType() { return baseType.getType(); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvingType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvingType.java index c588d701..33d27334 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvingType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvingType.java @@ -15,7 +15,7 @@ public class InterfaceResolvingType implements ResolvingType { private final Collection implementedInterfaces; public static ResolvingType of(ResolvingType baseType, Collection implementedInterfaces) { - if(implementedInterfaces.isEmpty()){ + if (implementedInterfaces.isEmpty()) { return baseType; } @@ -40,10 +40,11 @@ public ResolvedType withExpansions(List expansions) { .flatMap(iface -> expansions.stream().map(expansion -> expansion.resolve(iface)).filter(Optional::isPresent).map(Optional::get)) .collect(Collectors.toList()); - return new InterfaceResolvedType( + return InterfaceResolvedType.of( ExpandedResolvedType.of( baseType.withExpansions(expansions), interfaceExpansions), - resolvedInterfaces); + resolvedInterfaces + ); } } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java index 627950ff..1a76fb2d 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java @@ -14,10 +14,6 @@ import java.util.stream.Collectors; public class MemberSet implements ResolvedType { - public static Builder create(TypeID type) { - MemberSet members = new MemberSet(type); - return new Builder(members); - } private final TypeID type; private final List constructors = new ArrayList<>(); @@ -30,10 +26,15 @@ public static Builder create(TypeID type) { private final List iterators = new ArrayList<>(); private final List comparators = new ArrayList<>(); - public MemberSet(TypeID type) { + private MemberSet(TypeID type) { this.type = type; } + public static Builder create(TypeID type) { + MemberSet members = new MemberSet(type); + return new Builder(members); + } + @Override public TypeID getType() { return type; @@ -230,7 +231,7 @@ public boolean hasNoConstructor() { return target.constructors.isEmpty(); } - public Resolving build() { + public ResolvingType build() { return new Resolving(target); } @@ -239,7 +240,7 @@ public ResolvedType buildWithoutExpansions() { } } - public static class Resolving implements ResolvingType { + private static class Resolving implements ResolvingType { private final MemberSet target; public Resolving(MemberSet target) { this.target = target;