Loading sdg-core/src/main/java/es/upv/mist/slicing/graphs/ClassGraph.java +9 −6 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ import com.github.javaparser.resolution.types.ResolvedType; import es.upv.mist.slicing.arcs.Arc; import es.upv.mist.slicing.nodes.ObjectTree; import es.upv.mist.slicing.utils.ASTUtils; import es.upv.mist.slicing.utils.StaticConfig; import es.upv.mist.slicing.utils.Utils; import org.jgrapht.graph.DirectedPseudograph; import org.jgrapht.nio.dot.DOTExporter; Loading Loading @@ -183,31 +184,33 @@ public class ClassGraph extends DirectedPseudograph<ClassGraph.Vertex<?>, ClassG protected ObjectTree generateObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex) { if (classVertex == null) return new ObjectTree(); return generatePolyObjectTreeFor(classVertex, new ObjectTree(), ObjectTree.ROOT_NAME); return generatePolyObjectTreeFor(classVertex, new ObjectTree(), ObjectTree.ROOT_NAME, 0); } protected ObjectTree generatePolyObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex, ObjectTree tree, String level) { protected ObjectTree generatePolyObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex, ObjectTree tree, String level, int depth) { if (depth >= StaticConfig.K_LIMIT) return tree; Set<ClassOrInterfaceDeclaration> types = subclassesOf(classVertex); if (types.isEmpty()) { generateObjectTreeFor(classVertex, tree, level); generateObjectTreeFor(classVertex, tree, level, depth); } else { for (ClassOrInterfaceDeclaration type : types) { Vertex<ClassOrInterfaceDeclaration> subclassVertex = classDeclarationMap.get(mapKey(type)); if (!findAllFieldsOf(subclassVertex).isEmpty()) { ObjectTree newType = tree.addType(ASTUtils.resolvedTypeDeclarationToResolvedType(type.resolve())); generateObjectTreeFor(subclassVertex, tree, level + '.' + newType.getMemberNode().getLabel()); generateObjectTreeFor(subclassVertex, tree, level + '.' + newType.getMemberNode().getLabel(), depth); } } } return tree; } protected void generateObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex, ObjectTree tree, String level) { protected void generateObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex, ObjectTree tree, String level, int depth) { Map<String, Vertex<ClassOrInterfaceDeclaration>> classFields = findAllFieldsOf(classVertex); for (var entry : classFields.entrySet()) { tree.addField(level + '.' + entry.getKey()); if (entry.getValue() != null) generatePolyObjectTreeFor(entry.getValue(), tree, level + '.' + entry.getKey()); generatePolyObjectTreeFor(entry.getValue(), tree, level + '.' + entry.getKey(), depth); } } Loading sdg-core/src/main/java/es/upv/mist/slicing/utils/StaticConfig.java 0 → 100644 +21 −0 Original line number Diff line number Diff line package es.upv.mist.slicing.utils; import java.io.IOException; import java.util.Properties; public class StaticConfig { public static final int K_LIMIT; static { int kLimit; try { Properties p = new Properties(); p.load(StaticConfig.class.getResourceAsStream("sdg.properties")); kLimit = Integer.parseInt((String) p.get("kLimit")); } catch (IOException e) { e.printStackTrace(); kLimit = 10; } K_LIMIT = kLimit; } } sdg-core/src/main/resources/es/upv/mist/slicing/utils/sdg.properties 0 → 100644 +1 −0 Original line number Diff line number Diff line kLimit=10 No newline at end of file Loading
sdg-core/src/main/java/es/upv/mist/slicing/graphs/ClassGraph.java +9 −6 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ import com.github.javaparser.resolution.types.ResolvedType; import es.upv.mist.slicing.arcs.Arc; import es.upv.mist.slicing.nodes.ObjectTree; import es.upv.mist.slicing.utils.ASTUtils; import es.upv.mist.slicing.utils.StaticConfig; import es.upv.mist.slicing.utils.Utils; import org.jgrapht.graph.DirectedPseudograph; import org.jgrapht.nio.dot.DOTExporter; Loading Loading @@ -183,31 +184,33 @@ public class ClassGraph extends DirectedPseudograph<ClassGraph.Vertex<?>, ClassG protected ObjectTree generateObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex) { if (classVertex == null) return new ObjectTree(); return generatePolyObjectTreeFor(classVertex, new ObjectTree(), ObjectTree.ROOT_NAME); return generatePolyObjectTreeFor(classVertex, new ObjectTree(), ObjectTree.ROOT_NAME, 0); } protected ObjectTree generatePolyObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex, ObjectTree tree, String level) { protected ObjectTree generatePolyObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex, ObjectTree tree, String level, int depth) { if (depth >= StaticConfig.K_LIMIT) return tree; Set<ClassOrInterfaceDeclaration> types = subclassesOf(classVertex); if (types.isEmpty()) { generateObjectTreeFor(classVertex, tree, level); generateObjectTreeFor(classVertex, tree, level, depth); } else { for (ClassOrInterfaceDeclaration type : types) { Vertex<ClassOrInterfaceDeclaration> subclassVertex = classDeclarationMap.get(mapKey(type)); if (!findAllFieldsOf(subclassVertex).isEmpty()) { ObjectTree newType = tree.addType(ASTUtils.resolvedTypeDeclarationToResolvedType(type.resolve())); generateObjectTreeFor(subclassVertex, tree, level + '.' + newType.getMemberNode().getLabel()); generateObjectTreeFor(subclassVertex, tree, level + '.' + newType.getMemberNode().getLabel(), depth); } } } return tree; } protected void generateObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex, ObjectTree tree, String level) { protected void generateObjectTreeFor(Vertex<ClassOrInterfaceDeclaration> classVertex, ObjectTree tree, String level, int depth) { Map<String, Vertex<ClassOrInterfaceDeclaration>> classFields = findAllFieldsOf(classVertex); for (var entry : classFields.entrySet()) { tree.addField(level + '.' + entry.getKey()); if (entry.getValue() != null) generatePolyObjectTreeFor(entry.getValue(), tree, level + '.' + entry.getKey()); generatePolyObjectTreeFor(entry.getValue(), tree, level + '.' + entry.getKey(), depth); } } Loading
sdg-core/src/main/java/es/upv/mist/slicing/utils/StaticConfig.java 0 → 100644 +21 −0 Original line number Diff line number Diff line package es.upv.mist.slicing.utils; import java.io.IOException; import java.util.Properties; public class StaticConfig { public static final int K_LIMIT; static { int kLimit; try { Properties p = new Properties(); p.load(StaticConfig.class.getResourceAsStream("sdg.properties")); kLimit = Integer.parseInt((String) p.get("kLimit")); } catch (IOException e) { e.printStackTrace(); kLimit = 10; } K_LIMIT = kLimit; } }
sdg-core/src/main/resources/es/upv/mist/slicing/utils/sdg.properties 0 → 100644 +1 −0 Original line number Diff line number Diff line kLimit=10 No newline at end of file