-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from LoiNguyenCS/main
update newest update from main
- Loading branch information
Showing
17 changed files
with
201 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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 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
64 changes: 64 additions & 0 deletions
64
src/main/java/org/checkerframework/specimin/GetTypesFullNameVisitor.java
This file contains 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,64 @@ | ||
package org.checkerframework.specimin; | ||
|
||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; | ||
import com.github.javaparser.ast.type.ClassOrInterfaceType; | ||
import com.github.javaparser.ast.visitor.ModifierVisitor; | ||
import com.github.javaparser.ast.visitor.Visitable; | ||
import com.github.javaparser.resolution.UnsolvedSymbolException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* A visitor that traverses a Java file's AST and creates a map, associating the file name with the | ||
* set of types used inside it. | ||
*/ | ||
public class GetTypesFullNameVisitor extends ModifierVisitor<Void> { | ||
|
||
/** The directory path of the Java file. */ | ||
private String fileDirectory = ""; | ||
|
||
/** | ||
* A map that associates the file directory with the set of fully qualified names of types used | ||
* within that file. | ||
*/ | ||
private Map<String, Set<String>> fileAndAssociatedTypes = new HashMap<>(); | ||
|
||
/** | ||
* Get the map of files' directories and types used within those files. | ||
* | ||
* @return the value of fileAndAssociatedTypes | ||
*/ | ||
public Map<String, Set<String>> getFileAndAssociatedTypes() { | ||
return Collections.unmodifiableMap(fileAndAssociatedTypes); | ||
} | ||
|
||
@Override | ||
public Visitable visit(ClassOrInterfaceDeclaration decl, Void p) { | ||
// Nested type classes don't have a separate class file. | ||
if (!decl.isNestedType()) { | ||
fileDirectory = decl.getFullyQualifiedName().get().replace(".", "/") + ".java"; | ||
fileAndAssociatedTypes.put(fileDirectory, new HashSet<>()); | ||
} | ||
return super.visit(decl, p); | ||
} | ||
|
||
@Override | ||
public Visitable visit(ClassOrInterfaceType type, Void p) { | ||
String typeFullName; | ||
try { | ||
typeFullName = type.resolve().getQualifiedName(); | ||
} catch (UnsolvedSymbolException e) { | ||
return super.visit(type, p); | ||
} | ||
if (fileAndAssociatedTypes.containsKey(fileDirectory)) { | ||
fileAndAssociatedTypes.get(fileDirectory).add(typeFullName); | ||
return super.visit(type, p); | ||
} else { | ||
throw new RuntimeException( | ||
"Unexpected files and types: " + fileDirectory + ", " + typeFullName); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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
Oops, something went wrong.