Skip to content

Commit 5d6be16

Browse files
authored
Merge pull request #124 from codellm-devkit/102-create-comprehensive-comment-analysis-capabilities
Feature Request Issue 102: Enrich comment analysis capabilities
2 parents 86235d0 + d7e5c5a commit 5d6be16

File tree

15 files changed

+1105
-334
lines changed

15 files changed

+1105
-334
lines changed

.settings/org.eclipse.buildship.core.prefs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/main/java/com/ibm/cldk/SymbolTable.java

Lines changed: 624 additions & 300 deletions
Large diffs are not rendered by default.

src/main/java/com/ibm/cldk/entities/CallSite.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,81 @@
66
import java.util.List;
77
import java.util.Optional;
88

9+
/**
10+
* Represents a call site within source code, encapsulating information about method invocations
11+
* and their contextual details.
12+
*
13+
* <p>
14+
* A call site contains information about the method being called, its receiver,
15+
* arguments, return type, and various properties that characterize the method call.
16+
* It also tracks the position of the call site within the source file.
17+
* </p>
18+
*
19+
* <p>
20+
* This class leverages Lombok's {@code @Data} annotation to automatically generate
21+
* getters, setters, {@code toString()}, {@code equals()}, and {@code hashCode()} methods.
22+
* </p>
23+
*
24+
* @author Rahul Krishna
25+
* @version 2.3.0
26+
*/
927
@Data
1028
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
1129
public class CallSite {
30+
/** Name of the method being called */
1231
private String methodName;
32+
33+
/** Comment associated with the call site */
34+
private Comment comment;
35+
36+
/** Expression representing the receiver of the method call */
1337
private String receiverExpr;
38+
39+
/** Type of the receiver object */
1440
private String receiverType;
41+
42+
/** List of argument types for the method call */
1543
private List<String> argumentTypes;
44+
45+
/** Return type of the called method */
1646
private String returnType;
47+
48+
/** Full signature of the callee method */
1749
private String calleeSignature;
18-
// Access specifiers
50+
51+
/** Flag indicating if the method has public access */
1952
private boolean isPublic = false;
53+
54+
/** Flag indicating if the method has protected access */
2055
private boolean isProtected = false;
56+
57+
/** Flag indicating if the method has private access */
2158
private boolean isPrivate = false;
59+
60+
/** Flag indicating if the method has unspecified access */
2261
private boolean isUnspecified = false;
62+
63+
/** Flag indicating if this is a static method call */
2364
private boolean isStaticCall;
65+
66+
/** Flag indicating if this is a constructor call */
2467
private boolean isConstructorCall;
68+
69+
/** CRUD operation associated with this call site, if any */
2570
private CRUDOperation crudOperation = null;
71+
72+
/** CRUD query associated with this call site, if any */
2673
private CRUDQuery crudQuery = null;
74+
75+
/** Starting line number of the call site in the source file */
2776
private int startLine;
77+
78+
/** Starting column number of the call site in the source file */
2879
private int startColumn;
80+
81+
/** Ending line number of the call site in the source file */
2982
private int endLine;
83+
84+
/** Ending column number of the call site in the source file */
3085
private int endColumn;
31-
}
86+
}

src/main/java/com/ibm/cldk/entities/Callable.java

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,101 @@
55
import java.util.ArrayList;
66
import java.util.List;
77

8+
/**
9+
* Represents a callable entity in the source code, such as a method or constructor.
10+
*
11+
* <p>
12+
* This class encapsulates information about the callable's file path, signature, comments,
13+
* annotations, modifiers, thrown exceptions, declaration, parameters, code, position within
14+
* the source file, return type, and various properties that characterize the callable.
15+
* </p>
16+
*
17+
* <p>
18+
* This class leverages Lombok's {@code @Data} annotation to automatically generate
19+
* getters, setters, {@code toString()}, {@code equals()}, and {@code hashCode()} methods.
20+
* </p>
21+
*
22+
* <p>
23+
* Example usage:
24+
* <pre>
25+
* Callable callable = new Callable();
26+
* callable.setFilePath("src/main/java/com/ibm/cldk/entities/Example.java");
27+
* callable.setSignature("public void exampleMethod()");
28+
* callable.setStartLine(10);
29+
* callable.setEndLine(20);
30+
* callable.setReturnType("void");
31+
* callable.setConstructor(false);
32+
* </pre>
33+
* </p>
34+
*
35+
* @author Rahul Krishna
36+
* @version 2.3.0
37+
*/
838
@Data
939
public class Callable {
40+
/** The file path where the callable entity is defined. */
1041
private String filePath;
42+
43+
/** The signature of the callable entity. */
1144
private String signature;
12-
private String comment;
45+
46+
/** A list of comments associated with the callable entity. */
47+
private List<Comment> comments;
48+
49+
/** A list of annotations applied to the callable entity. */
1350
private List<String> annotations;
51+
52+
/** A list of modifiers applied to the callable entity (e.g., public, private). */
1453
private List<String> modifiers;
54+
55+
/** A list of exceptions thrown by the callable entity. */
1556
private List<String> thrownExceptions;
57+
58+
/** The declaration of the callable entity. */
1659
private String declaration;
60+
61+
/** A list of parameters for the callable entity. */
1762
private List<ParameterInCallable> parameters;
63+
64+
/** The code of the callable entity. */
1865
private String code;
66+
67+
/** The starting line number of the callable entity in the source file. */
1968
private int startLine;
69+
70+
/** The ending line number of the callable entity in the source file. */
2071
private int endLine;
72+
73+
/** The return type of the callable entity. */
2174
private String returnType = null;
75+
76+
/** Indicates whether the callable entity is implicit. */
2277
private boolean isImplicit = false;
78+
79+
/** Indicates whether the callable entity is a constructor. */
2380
private boolean isConstructor = false;
81+
82+
/** A list of types referenced by the callable entity. */
2483
private List<String> referencedTypes;
84+
85+
/** A list of fields accessed by the callable entity. */
2586
private List<String> accessedFields;
87+
88+
/** A list of call sites within the callable entity. */
2689
private List<CallSite> callSites;
90+
91+
/** A list of variable declarations within the callable entity. */
2792
private List<VariableDeclaration> variableDeclarations;
93+
94+
/** A list of CRUD operations associated with the callable entity. */
2895
private List<CRUDOperation> crudOperations = new ArrayList<>();
96+
97+
/** A list of CRUD queries associated with the callable entity. */
2998
private List<CRUDQuery> crudQueries = new ArrayList<>();
99+
100+
/** The cyclomatic complexity of the callable entity. */
30101
private int cyclomaticComplexity;
102+
103+
/** Indicates whether the callable entity is an entry point. */
31104
private boolean isEntrypoint = false;
32-
}
105+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.ibm.cldk.entities;
2+
3+
import lombok.Data;
4+
5+
/**
6+
* Represents a comment entity extracted from source code.
7+
* This class encapsulates information about the content, position,
8+
* and type of a comment within a source file.
9+
*
10+
* <p>
11+
* The comment can be of various types, including Javadoc, block comments, or line comments.
12+
* The class also keeps track of the comment's position within the file (line and column numbers).
13+
* </p>
14+
*
15+
* <p>
16+
* This class leverages Lombok's {@code @Data} annotation to automatically generate
17+
* getters, setters, {@code toString()}, {@code equals()}, and {@code hashCode()} methods.
18+
* </p>
19+
*
20+
* Example usage:
21+
* <pre>
22+
* Comment comment = new Comment();
23+
* comment.setContent("This is a sample comment.");
24+
* comment.setStartLine(10);
25+
* comment.setEndLine(12);
26+
* comment.setJavadoc(true);
27+
* </pre>
28+
*
29+
* @author Rahul Krishna
30+
* @version 2.3.0
31+
*/
32+
@Data
33+
public class Comment {
34+
35+
/**
36+
* The textual content of the comment.
37+
*/
38+
private String content;
39+
40+
/**
41+
* The starting line number of the comment in the source file.
42+
* <p>
43+
* Defaults to {@code -1} if the position is unknown.
44+
* </p>
45+
*/
46+
private int startLine = -1;
47+
48+
/**
49+
* The ending line number of the comment in the source file.
50+
* <p>
51+
* Defaults to {@code -1} if the position is unknown.
52+
* </p>
53+
*/
54+
private int endLine = -1;
55+
56+
/**
57+
* The starting column number of the comment in the source file.
58+
* <p>
59+
* Defaults to {@code -1} if the position is unknown.
60+
* </p>
61+
*/
62+
private int startColumn = -1;
63+
64+
/**
65+
* The ending column number of the comment in the source file.
66+
* <p>
67+
* Defaults to {@code -1} if the position is unknown.
68+
* </p>
69+
*/
70+
private int endColumn = -1;
71+
72+
/**
73+
* Indicates whether the comment is a Javadoc comment.
74+
* <p>
75+
* Javadoc comments are special block comments used for generating documentation
76+
* and typically start with {@code /**}.
77+
* </p>
78+
*/
79+
private boolean isJavadoc = false;
80+
}

src/main/java/com/ibm/cldk/entities/Field.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
@Data
77
public class Field {
8-
private String comment;
8+
private Comment comment;
99
private String name;
1010
private String type;
1111
private Integer startLine;

src/main/java/com/ibm/cldk/entities/InitializationBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@Data
99
public class InitializationBlock {
1010
private String filePath;
11-
private String comment;
11+
private List<Comment> comments;
1212
private List<String> annotations;
1313
private List<String> thrownExceptions;
1414
private String code;

src/main/java/com/ibm/cldk/entities/JavaCompilationUnit.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.ibm.cldk.entities;
22

33
import lombok.Data;
4+
5+
import java.util.ArrayList;
46
import java.util.List;
57
import java.util.Map;
68

79
@Data
810
public class JavaCompilationUnit {
911
private String filePath;
10-
private String comment;
12+
private String packageName;
13+
private List<Comment> comments = new ArrayList<>();
1114
private List<String> imports;
1215
private Map<String, Type> typeDeclarations;
1316
private boolean isModified;

src/main/java/com/ibm/cldk/entities/ParameterInCallable.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,60 @@
44

55
import java.util.List;
66

7+
/**
8+
* Represents a parameter in a callable entity (e.g., method or constructor).
9+
*
10+
* <p>
11+
* This class encapsulates information about the parameter's type, name, annotations,
12+
* modifiers, and its position within the source file.
13+
* </p>
14+
*
15+
* <p>
16+
* This class leverages Lombok's {@code @Data} annotation to automatically generate
17+
* getters, setters, {@code toString()}, {@code equals()}, and {@code hashCode()} methods.
18+
* </p>
19+
*
20+
* <p>
21+
* Example usage:
22+
* <pre>
23+
* ParameterInCallable param = new ParameterInCallable();
24+
* param.setType("String");
25+
* param.setName("exampleParam");
26+
* param.setAnnotations(Arrays.asList("NotNull"));
27+
* param.setModifiers(Arrays.asList("final"));
28+
* param.setStartLine(10);
29+
* param.setEndLine(10);
30+
* param.setStartColumn(5);
31+
* param.setEndColumn(20);
32+
* </pre>
33+
* </p>
34+
*
35+
* @author Rahul Krishna
36+
* @version 2.3.0
37+
*/
738
@Data
839
public class ParameterInCallable {
40+
/** The type of the parameter (e.g., int, String). */
941
private String type;
42+
43+
/** The name of the parameter. */
1044
private String name;
45+
46+
/** A list of annotations applied to the parameter. */
1147
private List<String> annotations;
48+
49+
/** A list of modifiers applied to the parameter (e.g., final, static). */
1250
private List<String> modifiers;
51+
52+
/** The starting line number of the parameter in the source file. */
1353
private int startLine;
54+
55+
/** The ending line number of the parameter in the source file. */
1456
private int endLine;
57+
58+
/** The starting column number of the parameter in the source file. */
1559
private int startColumn;
60+
61+
/** The ending column number of the parameter in the source file. */
1662
private int endColumn;
17-
}
63+
}

0 commit comments

Comments
 (0)