Skip to content

Commit

Permalink
Cleanup: Extract InterfaceResolvedType.of and some reformattings
Browse files Browse the repository at this point in the history
  • Loading branch information
kindlich committed Aug 31, 2024
1 parent 1bc4e81 commit 2dc4ef2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ public class InterfaceResolvedType implements ResolvedType {
private final List<ResolvedType> implementations;
private final Collection<TypeID> implementedInterfaces;

public InterfaceResolvedType(ResolvedType baseType, Collection<ResolvedType> implementedInterfaces) {
private InterfaceResolvedType(ResolvedType baseType, Collection<ResolvedType> 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<ResolvedType> implementedInterfaces) {
if(implementedInterfaces.isEmpty())
return baseType;

return new InterfaceResolvedType(baseType, implementedInterfaces);
}

@Override
public TypeID getType() {
return baseType.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class InterfaceResolvingType implements ResolvingType {
private final Collection<TypeID> implementedInterfaces;

public static ResolvingType of(ResolvingType baseType, Collection<TypeID> implementedInterfaces) {
if(implementedInterfaces.isEmpty()){
if (implementedInterfaces.isEmpty()) {
return baseType;
}

Expand All @@ -40,10 +40,11 @@ public ResolvedType withExpansions(List<ExpansionSymbol> 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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<StaticCallableMethod> constructors = new ArrayList<>();
Expand All @@ -30,10 +26,15 @@ public static Builder create(TypeID type) {
private final List<IteratorInstance> iterators = new ArrayList<>();
private final List<Comparator> 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;
Expand Down Expand Up @@ -230,7 +231,7 @@ public boolean hasNoConstructor() {
return target.constructors.isEmpty();
}

public Resolving build() {
public ResolvingType build() {
return new Resolving(target);
}

Expand All @@ -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;
Expand Down

0 comments on commit 2dc4ef2

Please sign in to comment.