Skip to content

Commit

Permalink
Fixed bug in duplicate vertex checker in Analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
pollyvolk committed Oct 24, 2022
1 parent 0f5397c commit 4b2d7ed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/cqfn/astranaut/analyzer/VertexStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ private static void checkDuplicateVertices(
* contain duplications
*/
private static void checkDuplicateInheritance(
final List<Vertex> common,
final List<Vertex> local) throws DuplicateRule {
final List<Vertex> common,
final List<Vertex> local) throws DuplicateRule {
final List<Vertex> related = new LinkedList<>(common);
related.addAll(local);
final Set<String> types = new HashSet<>();
Expand All @@ -274,15 +274,16 @@ private static void checkDuplicateInheritance(
final List<Descriptor> descriptors =
((Disjunction) (((Node) vertex).getComposition().get(0))).getDescriptors();
for (final Descriptor descriptor : descriptors) {
if (types.contains(descriptor.getType())) {
final String type = descriptor.getType();
if (types.contains(type) && !type.isEmpty()) {
throw new DuplicateRule(
new StringBuilder()
.append(descriptor)
.append(" inherits an abstract node several times (should once)")
.toString()
);
}
types.add(descriptor.getType());
types.add(type);
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/org/cqfn/astranaut/analyzer/AnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,40 @@ void testExtendedNodeNotFoundException() {
Assertions.assertTrue(thrown instanceof ExtendedNodeNotFound);
}

/**
* Test case when there are several nodes in a specific language
* that extend green abstract nodes.
*/
@Test
void testSeveralNodesExtendingGreenAbstract() {
boolean oops = false;
Program program = null;
try {
final String source = this.readTest("java_set_several_extensions.txt");
final ProgramParser parser = new ProgramParser(source);
program = parser.parse();
} catch (final BaseException exception) {
oops = true;
}
Assertions.assertFalse(oops);
Analyzer analyzer = null;
try {
final List<Instruction<Vertex>> vertices = program.getVertices();
final VertexStorage storage = new VertexStorage(
vertices, program.getNamesOfAllLanguages()
);
storage.collectAndCheck();
analyzer = new Analyzer(storage);
analyzer.analyzeGreen();
for (final String language : program.getNamesOfAllLanguages()) {
analyzer.analyze(language);
}
} catch (final GeneratorException exception) {
oops = true;
}
Assertions.assertFalse(oops);
}

/**
* Test depth four hierarchy of nodes.
* @param analyzer The analyzer
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/analyzer/java_set_several_extensions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
A <- left@E, right@E;
E <- B | C;
F <- left@E, right@E;
B <- A | F;
C <- E, E;

java:
B <- & | D;
E <- & | G;
D <- E, E;
G <- 0;

0 comments on commit 4b2d7ed

Please sign in to comment.