-
Notifications
You must be signed in to change notification settings - Fork 10
Refactor #421
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
base: main
Are you sure you want to change the base?
Refactor #421
Changes from 1 commit
f4ad227
924f0ee
7a4adf5
637200c
9d56bff
cd3e6f4
4d5caf0
26f11f7
224e427
706f4a4
702e4e3
e5e905d
c6b6da1
14e0c4c
3518456
78523a7
354dd2b
d4472fa
8ead882
ead3cd4
4c837f6
81648d5
6e928e0
c369d72
14871d9
f26bd72
7a6fc1c
02a8153
093e895
e60e057
07bc8ea
ece78bb
ebd54b3
379da54
af5fa76
7a50937
20ee324
10a36ee
03ee823
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.Iterator; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.List; | ||
|
|
@@ -213,12 +214,17 @@ public void addSuperType(Set<MemberType> superTypes) { | |
| } | ||
| } | ||
|
|
||
| Set<MemberType> sanitizedSuperTypes = new LinkedHashSet<>(); | ||
| for (MemberType superType : superTypes) { | ||
| sanitizedSuperTypes.add(sanitizeMemberTypeForSuperTyping(superType)); | ||
| } | ||
|
|
||
| if (commonType == UnsolvedClassOrInterfaceType.CLASS) { | ||
| superTypeRelationships.put(superTypes, SuperTypeRelationship.EXTENDS); | ||
| superTypeRelationships.put(sanitizedSuperTypes, SuperTypeRelationship.EXTENDS); | ||
| } else if (commonType == UnsolvedClassOrInterfaceType.INTERFACE) { | ||
| superTypeRelationships.put(superTypes, SuperTypeRelationship.IMPLEMENTS); | ||
| superTypeRelationships.put(sanitizedSuperTypes, SuperTypeRelationship.IMPLEMENTS); | ||
| } else if (superTypeRelationships.get(superTypes) == null) { | ||
| superTypeRelationships.put(superTypes, SuperTypeRelationship.UNKNOWN); | ||
| superTypeRelationships.put(sanitizedSuperTypes, SuperTypeRelationship.UNKNOWN); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -242,7 +248,8 @@ public void forceSuperClass(MemberType superClass) { | |
| setType(UnsolvedClassOrInterfaceType.CLASS); | ||
| } | ||
|
|
||
| superTypeRelationships.put(Set.of(superClass), SuperTypeRelationship.EXTENDS); | ||
| superTypeRelationships.put( | ||
| Set.of(sanitizeMemberTypeForSuperTyping(superClass)), SuperTypeRelationship.EXTENDS); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -273,7 +280,37 @@ public void forceSuperInterface(MemberType superInterface) { | |
| return; | ||
| } | ||
|
|
||
| superTypeRelationships.put(Set.of(superInterface), SuperTypeRelationship.IMPLEMENTS); | ||
| superTypeRelationships.put( | ||
| Set.of(sanitizeMemberTypeForSuperTyping(superInterface)), SuperTypeRelationship.IMPLEMENTS); | ||
| } | ||
|
|
||
| /** | ||
| * Sanitizes a member type for supertyping such that it no longer contains any wildcards. | ||
| * | ||
| * @param memberType The member type to sanitize | ||
| * @return The sanitized member type | ||
| */ | ||
| private MemberType sanitizeMemberTypeForSuperTyping(MemberType memberType) { | ||
| if (memberType.getTypeArguments().isEmpty()) { | ||
| return memberType; | ||
| } | ||
|
|
||
| List<MemberType> sanitized = new ArrayList<>(); | ||
|
|
||
| // I'm pretty sure this is not right, but until we find a better way to do this, | ||
| // this is what we'll do | ||
|
||
| Iterator<String> getTypeArgs = getTypeVariables().iterator(); | ||
| for (int i = 0; i < memberType.getTypeArguments().size(); i++) { | ||
| MemberType typeArg = memberType.getTypeArguments().get(i); | ||
| if (typeArg instanceof WildcardMemberType) { | ||
| String typeVar = getTypeArgs.next(); | ||
| typeArg = new SolvedMemberType(typeVar); | ||
| } | ||
| sanitized.add(sanitizeMemberTypeForSuperTyping(typeArg)); | ||
| } | ||
|
|
||
| memberType.setTypeArguments(sanitized); | ||
| return memberType; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| package com.example; | ||
| public interface Set<E> extends com.example.Collection<E> { | ||
| public interface Set<T> extends com.example.Collection<T> { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example; | ||
| public class BadFoo<T> { | ||
|
|
||
| public BadFoo() { | ||
| throw new java.lang.Error(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package com.example; | ||
| public class Bar3 { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package com.example; | ||
| public class Baz3 extends com.example.Bar3 { | ||
| } |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.