-
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
Draft
theron-wang
wants to merge
39
commits into
njit-jerse:main
Choose a base branch
from
theron-wang:refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Refactor #421
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
f4ad227
upgrade to latest versions
theron-wang 924f0ee
Refactor without unsolved symbol generation
theron-wang 7a4adf5
make SpeciminRunner runnable
theron-wang 637200c
unsolved symbol generation part 1
theron-wang 9d56bff
forgot to include changes to `Slicer`
theron-wang cd3e6f4
add type parameter support
theron-wang 4d5caf0
add handling for conditionals + operator in type guessing
theron-wang 26f11f7
some fixes + best effort output
theron-wang 224e427
add deleted files
theron-wang 706f4a4
make it build
theron-wang 702e4e3
fix some bugs
theron-wang e5e905d
more bug fixes + test case updates
theron-wang c6b6da1
make requested changes + add docs
theron-wang 14e0c4c
handle array types
theron-wang 3518456
some more bug fixes
theron-wang 78523a7
add ambiguity case for unsolved method calls in solvable method/const…
theron-wang 354dd2b
make some changes
theron-wang d4472fa
make some more changes
theron-wang 8ead882
make comment changes from yesterday's review
theron-wang ead3cd4
make some fixes
theron-wang 4c837f6
make fixes
theron-wang 81648d5
bug fixes + short review changes
theron-wang 6e928e0
add support for type arguments
theron-wang c369d72
must implement methods and other fixes
theron-wang 14871d9
pr review changes
theron-wang f26bd72
fix some bugs
theron-wang 7a6fc1c
fix anonymous classes, override in synthetic types, pr changes, lambd…
theron-wang 02a8153
stop crashing for cases with solvable lambda constraint types
theron-wang 093e895
small fixes and add additional test cases based on #423
theron-wang e60e057
super type relationships + bug fixes
theron-wang 07bc8ea
allow inheritance for bounded wildcards and other type arguments + ja…
theron-wang ece78bb
fix a few bugs
theron-wang ebd54b3
address pr comments and start adding method reference support
theron-wang 379da54
method references
theron-wang af5fa76
bug fixes + javadoc
theron-wang 7a50937
fix must implement methods
theron-wang 20ee324
must implement methods should generate in unsolved class + private ou…
theron-wang 10a36ee
Merge branch 'main' of https://github.com/njit-jerse/specimin into re…
theron-wang 03ee823
include methods that are implemented but referenced by an abstract su…
theron-wang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/checkerframework/specimin/AmbiguityResolutionPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.checkerframework.specimin; | ||
|
|
||
| import com.google.common.base.Ascii; | ||
|
|
||
| public enum AmbiguityResolutionPolicy { | ||
| All, | ||
| BestEffort, | ||
| InputCondition; | ||
|
|
||
| public static AmbiguityResolutionPolicy parse(String input) { | ||
| return switch (Ascii.toLowerCase(input)) { | ||
| case "all" -> AmbiguityResolutionPolicy.All; | ||
| case "best-effort" -> AmbiguityResolutionPolicy.BestEffort; | ||
| case "input-condition" -> AmbiguityResolutionPolicy.InputCondition; | ||
| default -> throw new IllegalArgumentException(); | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
src/main/java/org/checkerframework/specimin/Slicer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| package org.checkerframework.specimin; | ||
|
|
||
| import com.github.javaparser.StaticJavaParser; | ||
| import com.github.javaparser.ast.CompilationUnit; | ||
| import com.github.javaparser.ast.ImportDeclaration; | ||
| import com.github.javaparser.ast.Node; | ||
| import com.github.javaparser.ast.PackageDeclaration; | ||
| import com.github.javaparser.resolution.Resolvable; | ||
| import com.github.javaparser.resolution.UnsolvedSymbolException; | ||
| import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration; | ||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.ArrayDeque; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
| import java.util.Queue; | ||
| import java.util.Set; | ||
| import org.checkerframework.specimin.unsolved.UnsolvedSymbolAlternates; | ||
| import org.checkerframework.specimin.unsolved.UnsolvedSymbolGenerator; | ||
|
|
||
| public class Slicer { | ||
theron-wang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** The slice of nodes. */ | ||
| private final Set<Node> slice = new HashSet<>(); | ||
|
|
||
| /** | ||
| * The slice of unsolved symbol definitions. These values need not be unique; the map is provided | ||
| * for simple lookups when adding new symbols. | ||
theron-wang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| private final Map<String, UnsolvedSymbolAlternates<?>> unsolvedSlice = new HashMap<>(); | ||
|
|
||
| /** The Nodes that need to be processed in the main algorithm. */ | ||
| private final Queue<Node> worklist = new ArrayDeque<>(); | ||
|
|
||
| private final Map<String, Path> existingClassesToFilePath; | ||
| private final String rootDirectory; | ||
| private final Map<String, CompilationUnit> toSlice; | ||
|
|
||
| public Slicer( | ||
theron-wang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Map<String, Path> existingClassesToFilePath, | ||
| String rootDirectory, | ||
| Map<String, CompilationUnit> toSlice) { | ||
| this.existingClassesToFilePath = existingClassesToFilePath; | ||
| this.rootDirectory = rootDirectory; | ||
| this.toSlice = toSlice; | ||
| } | ||
|
|
||
| public void slice() throws IOException { | ||
theron-wang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Set<String> usedTypes = new HashSet<>(); | ||
|
|
||
| // Step 1: build the slice; see which nodes to keep | ||
| while (!worklist.isEmpty()) { | ||
| Node element = worklist.remove(); | ||
| handleElement(element, usedTypes); | ||
| } | ||
|
|
||
| // Step 2: add all used types | ||
| for (String used : usedTypes) { | ||
| toSlice.put( | ||
| used, StaticJavaParser.parse(Path.of(rootDirectory, qualifiedNameToFilePath(used)))); | ||
theron-wang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Step 3: remove all nodes except the ones marked for keeping OR package/import declarations | ||
| for (CompilationUnit cu : toSlice.values()) { | ||
| sliceNode(cu); | ||
| } | ||
| } | ||
|
|
||
| public void addToWorklist(Node node) { | ||
| worklist.add(node); | ||
| } | ||
theron-wang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private void handleElement(Node node, Set<String> usedTypes) { | ||
| if (slice.contains(node)) { | ||
| return; | ||
| } | ||
|
|
||
| if (node instanceof Resolvable<?>) { | ||
| Resolvable<?> asResolvable = (Resolvable<?>) node; | ||
|
|
||
| try { | ||
| Object resolved = asResolvable.resolve(); | ||
|
|
||
| worklist.addAll(TypeRuleDependencyMap.getRelevantElements(resolved)); | ||
| if (resolved instanceof ResolvedReferenceTypeDeclaration) { | ||
| String qualifiedName = ((ResolvedReferenceTypeDeclaration) resolved).getQualifiedName(); | ||
| usedTypes.add(qualifiedName); | ||
| } | ||
|
|
||
| slice.add(node); | ||
| } catch (UnsolvedSymbolException ex) { | ||
| // Generate a synthetic type | ||
| } | ||
| } else { | ||
| // If it's not a resolvable node, it's going to be: | ||
| // 1) a non-resolvable expression (like a try {} block) | ||
| // 2) a type parameter | ||
|
|
||
| // It's guaranteed that these are relevant to the slice due to the algorithm. | ||
|
|
||
| // We need to add this to the slice (or we potentially face missing | ||
| // declarations or broken code). We also need to ask the type rule | ||
| // dependency map if we can break this node down further. | ||
|
|
||
| slice.add(node); | ||
| } | ||
|
|
||
| worklist.addAll(TypeRuleDependencyMap.getRelevantElements(node)); | ||
theron-wang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * Recursively removes all nodes not in the slice. | ||
| * | ||
| * @param node The node to slice | ||
| */ | ||
| private void sliceNode(Node node) { | ||
theron-wang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (slice.contains(node)) { | ||
| for (Node child : node.getChildNodes()) { | ||
| sliceNode(child); | ||
| } | ||
| } else if (!(node instanceof PackageDeclaration || node instanceof ImportDeclaration)) { | ||
| node.remove(); | ||
| } | ||
| } | ||
|
|
||
| private String qualifiedNameToFilePath(String qualifiedName) { | ||
| if (!existingClassesToFilePath.containsKey(qualifiedName)) { | ||
| throw new RuntimeException( | ||
| "qualifiedNameToFilePath only works for classes in the original directory"); | ||
| } | ||
| Path absoluteFilePath = existingClassesToFilePath.get(qualifiedName); | ||
| // theoretically rootDirectory should already be absolute as stated in README. | ||
| Path absoluteRootDirectory = Paths.get(rootDirectory).toAbsolutePath(); | ||
| return absoluteRootDirectory.relativize(absoluteFilePath).toString(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.