From 35a9df144a6d5a35040de2fc72c086da2ad65456 Mon Sep 17 00:00:00 2001 From: tsantalis Date: Tue, 22 Oct 2024 21:11:45 -0400 Subject: [PATCH] Modify statement signature in case of anonymous class declaration within the statement --- .../uom/java/xmi/decomposition/StatementObject.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/gr/uom/java/xmi/decomposition/StatementObject.java b/src/main/java/gr/uom/java/xmi/decomposition/StatementObject.java index d4a7408e7..4386d8e62 100644 --- a/src/main/java/gr/uom/java/xmi/decomposition/StatementObject.java +++ b/src/main/java/gr/uom/java/xmi/decomposition/StatementObject.java @@ -56,9 +56,6 @@ public StatementObject(CompilationUnit cu, String filePath, Statement statement, this.locationInfo = new LocationInfo(cu, filePath, statement, codeElementType); Visitor visitor = new Visitor(cu, filePath, container, javaFileContent); statement.accept(visitor); - int start = statement.getStartPosition(); - int end = start + statement.getLength(); - this.actualSignature = javaFileContent.substring(start, end); this.variables = visitor.getVariables(); this.types = visitor.getTypes(); this.variableDeclarations = visitor.getVariableDeclarations(); @@ -84,6 +81,15 @@ public StatementObject(CompilationUnit cu, String filePath, Statement statement, this.castExpressions = visitor.getCastExpressions(); this.ternaryOperatorExpressions = visitor.getTernaryOperatorExpressions(); this.lambdas = visitor.getLambdas(); + int start = statement.getStartPosition(); + int end = start + statement.getLength(); + if(this.anonymousClassDeclarations.isEmpty()) { + this.actualSignature = javaFileContent.substring(start, end); + } + else { + int endOffset = this.anonymousClassDeclarations.get(0).getLocationInfo().getStartOffset() + 1; + this.actualSignature = javaFileContent.substring(start, endOffset); + } setDepth(depth); String statementAsString = stringify(statement); if(Visitor.METHOD_INVOCATION_PATTERN.matcher(statementAsString).matches()) {