Skip to content
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

Metric of PsiContext for Java and Python #139

Closed
phodal opened this issue Nov 16, 2024 · 0 comments
Closed

Metric of PsiContext for Java and Python #139

phodal opened this issue Nov 16, 2024 · 0 comments

Comments

@phodal
Copy link
Owner

phodal commented Nov 16, 2024

Is your feature request related to a problem? Please describe.
No

Describe the solution you'd like
Support for metric element metric, add to PsiContextVariable.kt

  • changeCount
  • lineCount
  • complexityCount

Describe alternatives you've considered
Similar project: https://github.com/nikolaikopernik/code-complexity-plugin

Additional context
implementation simple changeCount, lineCount, complexityCount function in PsiContextVariableProvider

  1. changeCount analysis current psiElement.containingFile git change
  2. lineCount count current containingFile length
  3. complexityCount create a new interface like (ComplexityProvider) to analysis complexity, create visitor to visit element, like:
    • every language (java , kotlin) should implementation ComplexityProvider
    • Based on langauge syntax to generate Point

ElementVisitor example

package com.github.nikolaikopernik.codecomplexity.core

import com.intellij.psi.PsiElement
import com.intellij.psi.PsiRecursiveElementVisitor

abstract class ElementVisitor : PsiRecursiveElementVisitor(true) {
    override fun visitElement(element: PsiElement) {
        processElement(element)
        if (shouldVisitElement(element)) {
            super.visitElement(element)
        }
        postProcess(element)
    }

    /**
     * Increases complexity and nesting
     */
    protected abstract fun processElement(element: PsiElement)

    /**
     * Decreases nesting
     */
    protected abstract fun postProcess(element: PsiElement)

    /**
     * @return true if PsiElement is Binary Expression with operations || or &&
     */
    protected abstract fun shouldVisitElement(element: PsiElement): Boolean
}

phodal added a commit that referenced this issue Nov 16, 2024
Related to #139

Add support for metrics in PsiContext.

* **PsiContextVariable.kt**: Add new enum constants `CHANGE_COUNT`, `LINE_COUNT`, and `COMPLEXITY_COUNT` with descriptions.
* **DefaultPsiContextVariableProvider.kt**: Implement logic to resolve `CHANGE_COUNT`, `LINE_COUNT`, and `COMPLEXITY_COUNT` variables with placeholder values.
* **PostProcessorContext.kt**: Add properties `changeCount`, `lineCount`, and `complexityCount` to the `PostProcessorContext` class.
* **PostProcessor.kt**: Initialize `changeCount`, `lineCount`, and `complexityCount` in the `setup` method and add a placeholder for finalizing these metrics in the `finish` method.
* **PostProcessorType.kt**: Add new enum constants `ChangeCountMetric`, `LineCountMetric`, and `ComplexityMetric`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/phodal/shire/issues/139?shareId=XXXX-XXXX-XXXX-XXXX).
phodal added a commit that referenced this issue Nov 16, 2024
Related to #139

Add support for metric elements in `PsiContextVariable`. #139

* Add new enum entries `CHANGE_COUNT`, `LINE_COUNT`, and `COMPLEXITY_COUNT` to `PsiContextVariable`.
* Implement `changeCount`, `lineCount`, and `complexityCount` functions in `PsiContextVariableProviderImpl`.
* Use `Git` API to analyze changes for `changeCount`.
* Use `PsiFile` API to count lines for `lineCount`.
* Create `ComplexityVisitor` class extending `PsiRecursiveElementVisitor` to analyze complexity for `complexityCount`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/phodal/shire/issues/139?shareId=XXXX-XXXX-XXXX-XXXX).
phodal added a commit that referenced this issue Nov 16, 2024
Related to #139

Add support for metric elements `changeCount`, `lineCount`, and `complexityCount` in `PsiContextVariable`.

* Add `changeCount`, `lineCount`, and `complexityCount` as new variables in `PsiContextVariable` enum in `PsiContextVariable.kt`.
* Implement `changeCount`, `lineCount`, and `complexityCount` functions in `DefaultPsiContextVariableProvider.kt`.
* Implement `changeCount`, `lineCount`, and `complexityCount` functions in `MarkdownPsiContextVariableProvider.kt`.
* Implement `changeCount`, `lineCount`, and `complexityCount` functions in `GoPsiContextVariableProvider.kt`.
* Implement `changeCount`, `lineCount`, and `complexityCount` functions in `JavaPsiContextVariableProvider.kt`.
* Implement `changeCount`, `lineCount`, and `complexityCount` functions in `JSPsiContextVariableProvider.kt`.
* Add tests for `changeCount`, `lineCount`, and `complexityCount` functions in `MarkdownPsiContextVariableProviderTest.kt`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/phodal/shire/issues/139?shareId=XXXX-XXXX-XXXX-XXXX).
@phodal phodal closed this as completed in e23687c Nov 17, 2024
@phodal phodal reopened this Nov 17, 2024
phodal added a commit that referenced this issue Nov 18, 2024
Extract the PsiSyntaxCheckingVisitor from VerifyCodeProcessor to a new standalone file in the ast package. This refactoring promotes code reusability and cleans up the VerifyCodeProcessor by removing the visitor code and now importing it from the new location.
phodal added a commit that referenced this issue Nov 18, 2024
Add the ability to process a PsiElement to the ComplexityProvider, allowing for more granular complexity calculations.
phodal added a commit that referenced this issue Nov 18, 2024
…ySink and ComplexityPoint #139

- Modify ComplexityProvider interface to accept a ComplexitySink in the visitor function.
- Introduce ComplexitySink class to track and manage complexity points and nesting levels.
- Add ComplexityPoint data class to represent individual complexity points with their types.
phodal added a commit that referenced this issue Nov 18, 2024
Updated the qualified name of the complexity provider extension point to reflect a more specific naming convention. Implemented a new Java complexity provider and its corresponding visitor to calculate code complexity for Java language files.
phodal added a commit that referenced this issue Nov 18, 2024
…vider #139

The commit updates the `JavaComplexityProvider` to accurately calculate complexity by accepting a visitor and using a `ComplexitySink`. Additionally, it introduces a test case `JavaComplexityProviderTest` to verify the complexity calculation for a given Java code snippet.
phodal added a commit that referenced this issue Nov 18, 2024
…eProvider #139

Previously, the complexity count for PsiVariableProvider was not calculated and returned an empty string. Now, the complexity count is properly calculated for each PsiVariableProvider implementation across different languages.
@phodal phodal changed the title Metric of PsiContext Metric of PsiContext for Java and Python Nov 21, 2024
@phodal phodal closed this as completed in 412a90d Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant