Skip to content

Feature Request Issue 102: Enrich comment analysis capabilities #124

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

Merged
merged 8 commits into from
Feb 19, 2025
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/release_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
{
"title": "## \uD83D\uDEE0 Other Updates",
"labels": ["other", "kind/dependency-change"]
},
{
"title": "## 🚨 Breaking Changes",
"labels": ["breaking"]
}
],
"ignore_labels": [
Expand Down
13 changes: 0 additions & 13 deletions .settings/org.eclipse.buildship.core.prefs

This file was deleted.

923 changes: 646 additions & 277 deletions src/main/java/com/ibm/cldk/SymbolTable.java

Large diffs are not rendered by default.

59 changes: 57 additions & 2 deletions src/main/java/com/ibm/cldk/entities/CallSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,81 @@
import java.util.List;
import java.util.Optional;

/**
* Represents a call site within source code, encapsulating information about method invocations
* and their contextual details.
*
* <p>
* A call site contains information about the method being called, its receiver,
* arguments, return type, and various properties that characterize the method call.
* It also tracks the position of the call site within the source file.
* </p>
*
* <p>
* This class leverages Lombok's {@code @Data} annotation to automatically generate
* getters, setters, {@code toString()}, {@code equals()}, and {@code hashCode()} methods.
* </p>
*
* @author Rahul Krishna
* @version 2.3.0
*/
@Data
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class CallSite {
/** Name of the method being called */
private String methodName;

/** Comment associated with the call site */
private Comment comment;

/** Expression representing the receiver of the method call */
private String receiverExpr;

/** Type of the receiver object */
private String receiverType;

/** List of argument types for the method call */
private List<String> argumentTypes;

/** Return type of the called method */
private String returnType;

/** Full signature of the callee method */
private String calleeSignature;
// Access specifiers

/** Flag indicating if the method has public access */
private boolean isPublic = false;

/** Flag indicating if the method has protected access */
private boolean isProtected = false;

/** Flag indicating if the method has private access */
private boolean isPrivate = false;

/** Flag indicating if the method has unspecified access */
private boolean isUnspecified = false;

/** Flag indicating if this is a static method call */
private boolean isStaticCall;

/** Flag indicating if this is a constructor call */
private boolean isConstructorCall;

/** CRUD operation associated with this call site, if any */
private CRUDOperation crudOperation = null;

/** CRUD query associated with this call site, if any */
private CRUDQuery crudQuery = null;

/** Starting line number of the call site in the source file */
private int startLine;

/** Starting column number of the call site in the source file */
private int startColumn;

/** Ending line number of the call site in the source file */
private int endLine;

/** Ending column number of the call site in the source file */
private int endColumn;
}
}
77 changes: 75 additions & 2 deletions src/main/java/com/ibm/cldk/entities/Callable.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,101 @@
import java.util.ArrayList;
import java.util.List;

/**
* Represents a callable entity in the source code, such as a method or constructor.
*
* <p>
* This class encapsulates information about the callable's file path, signature, comments,
* annotations, modifiers, thrown exceptions, declaration, parameters, code, position within
* the source file, return type, and various properties that characterize the callable.
* </p>
*
* <p>
* This class leverages Lombok's {@code @Data} annotation to automatically generate
* getters, setters, {@code toString()}, {@code equals()}, and {@code hashCode()} methods.
* </p>
*
* <p>
* Example usage:
* <pre>
* Callable callable = new Callable();
* callable.setFilePath("src/main/java/com/ibm/cldk/entities/Example.java");
* callable.setSignature("public void exampleMethod()");
* callable.setStartLine(10);
* callable.setEndLine(20);
* callable.setReturnType("void");
* callable.setConstructor(false);
* </pre>
* </p>
*
* @author Rahul Krishna
* @version 2.3.0
*/
@Data
public class Callable {
/** The file path where the callable entity is defined. */
private String filePath;

/** The signature of the callable entity. */
private String signature;
private String comment;

/** A list of comments associated with the callable entity. */
private List<Comment> comments;

/** A list of annotations applied to the callable entity. */
private List<String> annotations;

/** A list of modifiers applied to the callable entity (e.g., public, private). */
private List<String> modifiers;

/** A list of exceptions thrown by the callable entity. */
private List<String> thrownExceptions;

/** The declaration of the callable entity. */
private String declaration;

/** A list of parameters for the callable entity. */
private List<ParameterInCallable> parameters;

/** The code of the callable entity. */
private String code;

/** The starting line number of the callable entity in the source file. */
private int startLine;

/** The ending line number of the callable entity in the source file. */
private int endLine;

/** The return type of the callable entity. */
private String returnType = null;

/** Indicates whether the callable entity is implicit. */
private boolean isImplicit = false;

/** Indicates whether the callable entity is a constructor. */
private boolean isConstructor = false;

/** A list of types referenced by the callable entity. */
private List<String> referencedTypes;

/** A list of fields accessed by the callable entity. */
private List<String> accessedFields;

/** A list of call sites within the callable entity. */
private List<CallSite> callSites;

/** A list of variable declarations within the callable entity. */
private List<VariableDeclaration> variableDeclarations;

/** A list of CRUD operations associated with the callable entity. */
private List<CRUDOperation> crudOperations = new ArrayList<>();

/** A list of CRUD queries associated with the callable entity. */
private List<CRUDQuery> crudQueries = new ArrayList<>();

/** The cyclomatic complexity of the callable entity. */
private int cyclomaticComplexity;

/** Indicates whether the callable entity is an entry point. */
private boolean isEntrypoint = false;
}
}
80 changes: 80 additions & 0 deletions src/main/java/com/ibm/cldk/entities/Comment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.ibm.cldk.entities;

import lombok.Data;

/**
* Represents a comment entity extracted from source code.
* This class encapsulates information about the content, position,
* and type of a comment within a source file.
*
* <p>
* The comment can be of various types, including Javadoc, block comments, or line comments.
* The class also keeps track of the comment's position within the file (line and column numbers).
* </p>
*
* <p>
* This class leverages Lombok's {@code @Data} annotation to automatically generate
* getters, setters, {@code toString()}, {@code equals()}, and {@code hashCode()} methods.
* </p>
*
* Example usage:
* <pre>
* Comment comment = new Comment();
* comment.setContent("This is a sample comment.");
* comment.setStartLine(10);
* comment.setEndLine(12);
* comment.setJavadoc(true);
* </pre>
*
* @author Rahul Krishna
* @version 2.3.0
*/
@Data
public class Comment {

/**
* The textual content of the comment.
*/
private String content;

/**
* The starting line number of the comment in the source file.
* <p>
* Defaults to {@code -1} if the position is unknown.
* </p>
*/
private int startLine = -1;

/**
* The ending line number of the comment in the source file.
* <p>
* Defaults to {@code -1} if the position is unknown.
* </p>
*/
private int endLine = -1;

/**
* The starting column number of the comment in the source file.
* <p>
* Defaults to {@code -1} if the position is unknown.
* </p>
*/
private int startColumn = -1;

/**
* The ending column number of the comment in the source file.
* <p>
* Defaults to {@code -1} if the position is unknown.
* </p>
*/
private int endColumn = -1;

/**
* Indicates whether the comment is a Javadoc comment.
* <p>
* Javadoc comments are special block comments used for generating documentation
* and typically start with {@code /**}.
* </p>
*/
private boolean isJavadoc = false;
}
2 changes: 1 addition & 1 deletion src/main/java/com/ibm/cldk/entities/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@Data
public class Field {
private String comment;
private Comment comment;
private String name;
private String type;
private Integer startLine;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/ibm/cldk/entities/InitializationBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.ibm.cldk.entities;

import lombok.Data;

import java.util.List;
import java.util.stream.Collector;

@Data
public class InitializationBlock {
private String filePath;
private List<Comment> comments;
private List<String> annotations;
private List<String> thrownExceptions;
private String code;
private int startLine;
private int endLine;
private boolean isStatic;
private List<String> referencedTypes;
private List<String> accessedFields;
private List<CallSite> callSites;
private List<VariableDeclaration> variableDeclarations;
private int cyclomaticComplexity;

}
5 changes: 4 additions & 1 deletion src/main/java/com/ibm/cldk/entities/JavaCompilationUnit.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.ibm.cldk.entities;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
public class JavaCompilationUnit {
private String filePath;
private String comment;
private String packageName;
private List<Comment> comments = new ArrayList<>();
private List<String> imports;
private Map<String, Type> typeDeclarations;
private boolean isModified;
Expand Down
Loading