diff --git a/src/main/java/org/checkerframework/specimin/SpeciminRunner.java b/src/main/java/org/checkerframework/specimin/SpeciminRunner.java index 2c88073e..c22ce570 100644 --- a/src/main/java/org/checkerframework/specimin/SpeciminRunner.java +++ b/src/main/java/org/checkerframework/specimin/SpeciminRunner.java @@ -166,9 +166,9 @@ public static void performMinimization( // correct the types of all related files before adding them to parsedTargetFiles JavaTypeCorrect typeCorrecter = new JavaTypeCorrect(root, relatedClass); typeCorrecter.correctTypesForAllFiles(); - Map<@ClassGetSimpleName String, @ClassGetSimpleName String> typeToChange = + Map<@ClassGetSimpleName String, @ClassGetSimpleName String> typesToChange = typeCorrecter.getTypeToChange(); - addMissingClass.updateTypes(typeToChange); + addMissingClass.updateTypes(typesToChange); for (String directory : relatedClass) { // directories already in parsedTargetFiles are original files in the root directory, we are @@ -191,17 +191,18 @@ public static void performMinimization( // target key will have this form: "path/of/package/ClassName.java" String classFullyQualfiedName = target.getKey().replace("/", "."); if (!classFullyQualfiedName.endsWith(".java")) { - throw new RuntimeException("A Java file directory does not end with .java: " + classFullyQualfiedName); + throw new RuntimeException( + "A Java file directory does not end with .java: " + classFullyQualfiedName); } classFullyQualfiedName = - classFullyQualfiedName.substring(0, classFullyQualfiedName.length() - 5); + classFullyQualfiedName.substring(0, classFullyQualfiedName.length() - 5); @SuppressWarnings("signature") // since it's the last element of a fully qualified path @ClassGetSimpleName String simpleName = classFullyQualfiedName.substring(classFullyQualfiedName.lastIndexOf(".") + 1); // If this condition is true, this class is a synthetic class initially created to be a // return type of some synthetic methods, but later javac has found the correct return type // for that method. - if (typeToChange.containsKey(simpleName)) { + if (typesToChange.containsKey(simpleName)) { continue; } if (!finder.getUsedClass().contains(classFullyQualfiedName)) { diff --git a/src/main/java/org/checkerframework/specimin/TargetMethodFinderVisitor.java b/src/main/java/org/checkerframework/specimin/TargetMethodFinderVisitor.java index 14f6445b..c2e6d01d 100644 --- a/src/main/java/org/checkerframework/specimin/TargetMethodFinderVisitor.java +++ b/src/main/java/org/checkerframework/specimin/TargetMethodFinderVisitor.java @@ -213,7 +213,8 @@ public Visitable visit(Parameter para, Void p) { if (insideTargetMethod) { ResolvedType paraType = para.resolve().getType(); if (paraType.isReferenceType()) { - String paraTypeFullName = paraType.asReferenceType().getTypeDeclaration().get().getQualifiedName(); + String paraTypeFullName = + paraType.asReferenceType().getTypeDeclaration().get().getQualifiedName(); usedClass.add(paraTypeFullName); for (ResolvedType typeVariable : paraType.asReferenceType().typeParametersValues()) { String typeVariableFullName = typeVariable.describe(); diff --git a/src/main/java/org/checkerframework/specimin/UnsolvedSymbolVisitor.java b/src/main/java/org/checkerframework/specimin/UnsolvedSymbolVisitor.java index 050b5d44..de462e2c 100644 --- a/src/main/java/org/checkerframework/specimin/UnsolvedSymbolVisitor.java +++ b/src/main/java/org/checkerframework/specimin/UnsolvedSymbolVisitor.java @@ -264,31 +264,6 @@ public Visitable visit(PackageDeclaration node, Void arg) { return super.visit(node, arg); } - /* - @Override - public Node visit(ImportDeclaration decl, Void arg) { - @SuppressWarnings( - "signature") // since this is the content of an import statement, it will be a qualified - // class path - @FullyQualifiedName String declAsString = decl.getNameAsString(); - // if there is no jar paths included, every imported class is unsolved, apart from those - // belonging to the Java language. - if (!classesFromJar.isEmpty() || declAsString.startsWith("java.")) { - return super.visit(decl, arg); - } - UnsolvedClass declaredClass = getSimpleSyntheticClassFromFullyQualifiedName(declAsString); - try { - createMissingClass(declaredClass); - missingClass.add(declaredClass); - } catch (RuntimeException e) { - // The class file already exists in the codebase - return super.visit(decl, arg); - } - return super.visit(decl, arg); - } - - */ - @Override public Visitable visit(ClassOrInterfaceDeclaration node, Void arg) { SimpleName nodeName = node.getName(); @@ -542,7 +517,6 @@ public Visitable visit(MethodDeclaration node, Void arg) { // since this method declaration is inside an anonymous class, its parent will be an // ObjectCreationExpr ((ObjectCreationExpr) parentNode).resolve(); - nodeType.resolve(); } catch (UnsolvedSymbolException | UnsupportedOperationException e) { SimpleName classNodeSimpleName = ((ObjectCreationExpr) parentNode).getType().getName(); String nameOfClass = classNodeSimpleName.asString(); @@ -600,9 +574,12 @@ public Visitable visit(MethodCallExpr method, Void p) { @Override public Visitable visit(ClassOrInterfaceType typeExpr, Void p) { - // this line is to work around a bug of JavaParser. When a type is called as a class path, such - // as com.example.Dog dog, JavaParser will also consider com and com.example as type name. This - // bug happens even if the source file of class Dog is present in the codebase. + /** + * Workaround for a JavaParser bug: When a type is referenced as a class path, like + * com.example.Dog dog, JavaParser considers its package components (com and com.example) as + * types, too. This issue happens even when the source file of the Dog class is present in the + * codebase. + */ if (!isCapital(typeExpr.getName().asString())) { return super.visit(typeExpr, p); } @@ -1289,13 +1266,6 @@ public void createMissingClass(UnsolvedClass missedClass) { this.rootDirectory + classDirectory + "/" + missedClass.getClassName() + ".java"; Path filePath = Paths.get(filePathStr); - // When class paths are not provide, this visitor will attempt to create synthetic classes for - // every class imported by the import statements. However, some of those classes might already - // exist in the input codebase. - if (Files.exists(filePath)) { - throw new RuntimeException("File already exists: " + filePath); - } - createdClass.add(filePath); try { Path parentPath = filePath.getParent();