Skip to content

Melhorar estratégia da expertise. #5

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions outputs/analysis-javaparser.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

CLASS: /src/song/Song.java

METHODS: --------------- public boolean isMainstream()
--------------- public String getName()
--------------- public void setName(String name)
--------------- public int getLength()
--------------- public void setLength(int length)

CLASS: /src/song/Pop.java

METHODS:
CLASS: /src/exception/ArtistaException.java

METHODS:
CLASS: /src/person/Person.java

METHODS:
CLASS: /src/genre/Genre.java

METHODS:
CLASS: /src/main/Main.java

METHODS: --------------- public static void main(String[] args)

CLASS: /src/person/Producer.java

METHODS:
CLASS: /src/album/Album.java

METHODS:
CLASS: /src/genre/Rock.java

METHODS:
CLASS: /tests/song/SongTest.java

METHODS: --------------- public void setUp()
--------------- public void isMainstreamTest()

CLASS: /src/person/Artist.java

METHODS:
17 changes: 17 additions & 0 deletions outputs/analysis-result.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
STUDENT NAME CLASS PATH OWNERSHIP PERCENTAGE EXPERTISE LIST
<<<<<<< HEAD
Robson src/exception/ArtistaException.java 100 [EXCEPTIONS, INHERITANCE, EXCEPTION_HIERARCHY]
Mariana src/song/Pop.java 100 [INTERFACE]
Mariana src/genre/Rock.java 100 [INTERFACE]
Robson src/album/Album.java 100 []
Robson src/exception/ArtistaException.java 100 [EXCEPTIONS, INHERITANCE, EXCEPTION_HIERARCHY]
Robson src/genre/Genre.java 100 []
Robson src/genre/Rock.java 100 [INTERFACE]
Robson src/main/Main.java 100 []
Robson src/person/Artist.java 100 [INHERITANCE]
Robson src/person/Person.java 100 [ABSTRACT_CLASSES]
Robson src/person/Producer.java 100 [INHERITANCE]
Robson src/song/Pop.java 100 [INTERFACE]
Robson src/song/Song.java 100 []
Robson tests/song/SongTest.java 100 [TESTS]
=======
Mikael QuemMeAjuda/easyAccept/Main.java 38,1 []
Diego QuemMeAjuda/easyAccept/Main.java 33,3 []
Jesse QuemMeAjuda/easyAccept/Main.java 23,8 []
Expand Down Expand Up @@ -75,3 +91,4 @@ Jesse QuemMeAjuda/testes/tutor/TutorControllerTest.java 70,2 [TESTS, EXCEPTIONS]
Mikael QuemMeAjuda/testes/tutor/TutorTest.java 98,8 [TESTS, EXCEPTIONS]
Diego QuemMeAjuda/testes/tutor/TutorTest.java 0,6 [TESTS, EXCEPTIONS]
Jesse QuemMeAjuda/testes/tutor/TutorTest.java 0,6 [TESTS, EXCEPTIONS]
>>>>>>> origin/master
1 change: 1 addition & 0 deletions src/main/java/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import artifact.Artifact;
import codeOwnership.CodeOwnership;
import exception.StudentNotFoundException;
import extractor.Extractor;
import expertise.Expertise;
import git.GitRepository;
import pair.PairStudentArtifact;
Expand Down
73 changes: 73 additions & 0 deletions src/main/java/extractor/ComponentClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package extractor;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.github.javaparser.JavaParser;
import com.github.javaparser.ParseException;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;

public class ComponentClass<Object> extends VoidVisitorAdapter<Object>{

private Map<Object,List<MethodDeclaration>> methods;
private Map<Object,NodeList<ClassOrInterfaceType>> inheritance;
private Set<ClassOrInterfaceDeclaration> classes;

public ComponentClass() {
this.methods = new HashMap<Object,List<MethodDeclaration>>();
this.inheritance = (new HashMap<Object, NodeList<ClassOrInterfaceType>>());
this.classes = new HashSet<>();
}

public void visit(ClassOrInterfaceDeclaration n, Object arg) {
super.visit(n, arg);
this.getInheritance().put((Object) n.getNameAsString(), n.getExtendedTypes());
this.methods.put((Object) n.getNameAsString(), n.getMethods());
this.classes.add(n);
}

public Set<ClassOrInterfaceDeclaration> getClasses() {
return classes;
}

public void setClasses(Set<ClassOrInterfaceDeclaration> classes) {
this.classes = classes;
}

public void getAllMethods(File projectDir) throws ParseException, IOException {
new DirExplorer((level, path, file) -> path.endsWith(".java"), (level, path, file) -> {
Object a = (Object) path;
try {
this.visit(JavaParser.parse(file), a);
} catch (IOException e) {
new RuntimeException(e);
}
}).explore(projectDir);
}

public Map<Object,List<MethodDeclaration>> getMethods() {
return methods;
}

public void setMethods(Map<Object,List<MethodDeclaration>> methods) {
this.methods = methods;
}

public Map<Object,NodeList<ClassOrInterfaceType>> getInheritance() {
return inheritance;
}

public void setInheritance(Map<Object,NodeList<ClassOrInterfaceType>> inheritance) {
this.inheritance = inheritance;
}

}
38 changes: 38 additions & 0 deletions src/main/java/extractor/DirExplorer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package extractor;

import java.io.File;

public class DirExplorer {
public interface FileHandler {
void handle(int level, String path, File file);
}

public interface Filter {
boolean interested(int level, String path, File file);
}

private FileHandler fileHandler;
private Filter filter;

public DirExplorer(Filter filter, FileHandler fileHandler) {
this.filter = filter;
this.fileHandler = fileHandler;
}

public void explore(File root) {
explore(0, "", root);
}

private void explore(int level, String path, File file) {
if (file.isDirectory()) {
for (File child : file.listFiles()) {
explore(level + 1, path + "/" + child.getName(), child);
}
} else {
if (filter.interested(level, path, file)) {
fileHandler.handle(level, path, file);
}
}
}

}
97 changes: 97 additions & 0 deletions src/main/java/extractor/Extractor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package extractor;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.github.javaparser.ParseException;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.CallableDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.type.ClassOrInterfaceType;

public class Extractor {

public static final String LS = System.lineSeparator();
private ComponentClass<Object> componentClass;
private Map<String, String> extendedType;
private Map<String, List<String>> methodsFromClass;

public Extractor() {
this.componentClass = new ComponentClass<>();
this.extendedType = new HashMap<>();
this.methodsFromClass = new HashMap<>();
}

public void getMethodsFromProject() throws ParseException, IOException {
this.componentClass.getAllMethods(new File("/home/marianams/HotelGotemburgo/src"));
this.linkClassToMethods();
this.linkExtendTypes();
this.printCommonMethods();
this.printClasses();

}

private void linkClassToMethods() {
Set<Object> methods = this.componentClass.getMethods().keySet();
for (Object key : methods) {
this.methodsFromClass.put((String) key.toString(), new ArrayList<>());
for (MethodDeclaration method : this.componentClass.getMethods().get(key)) {
this.methodsFromClass.get(key).add(method.getDeclarationAsString(false, false, false));

}
}
}

private void linkExtendTypes() {
Map<Object, NodeList<ClassOrInterfaceType>> classes = this.componentClass.getInheritance();
Set<Object> c = classes.keySet();
for (Object object : c) {
if (classes.get(object).size() > 0) {
this.extendedType.put((String) object,
classes.get(object).toString().substring(1, classes.get(object).toString().length() - 1));
}
}
}

private void printCommonMethods() {
Set<String> classes = this.extendedType.keySet();

for (String classe : classes) {
int total = 0;
int inheritance = 0;
System.out.print(LS + "CLASS >>>" + classe);
System.out.println(" EXTENDED >>>" + this.extendedType.get(classe));

List<String> superMethods = this.methodsFromClass.get(this.extendedType.get(classe));

List<String> methods = this.methodsFromClass.get(classe);
total = methods.size();

if (superMethods != null && methods != null) {
for (String superMethod : superMethods) {
for (String method : methods) {
if (superMethod.equals(method)) {
inheritance += 1;
}
}
}
System.out.println("Proporção métodos herdados/total de métodos da classe: " + inheritance + "/" + total);
}
}
}


public void printClasses() {
Set<ClassOrInterfaceDeclaration> classes = this.componentClass.getClasses();
for (ClassOrInterfaceDeclaration c : classes) {
System.out.println(LS + c);
System.out.println("FIELDS: >>>");
}
}
}
29 changes: 29 additions & 0 deletions students.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"students": [
{
"name": "Mariana",
"aliases": [
"Mariana Mendes e Silva",
"Mariana Mendes",
"mariana-mendes",
"MARIANA MENDES E SILVA 115211452"
]
},
{
"name": "Robson",
"aliases": [
"JRobsonJr",
"Robson Junior",
" JOSE ROBSON DA SILVA ARAUJO JUNIOR 116110648"
]
},
{
"name": "David",
"aliases": [
"davidedup",
"DAVID EDUARDO PEREIRA 116110322",

]
}
]
}