Skip to content

error: cannot find symbol- subscribeTo(DmlGrammar.TABLE_DECLARATION); #171

@csrvsk

Description

@csrvsk

I am trying to write a custom rule to implement TableName check,

But I am facing compilation errors. Please suggest how to achieve this.

ERROR:
C:\myfiles\zpa-Latest>gradlew build -p plsql-custom-rules
Picked up JAVA_TOOL_OPTIONS: -Djava.vendor="Sun Microsystems Inc."

Task :compileJava
Picked up JAVA_TOOL_OPTIONS: -Djava.vendor="Sun Microsystems Inc."
C:\myfiles\zpa-Latest\plsql-custom-rules\src\main\java\com\company\plsql\TableNamingCheck.java:30: error: cannot find symbol
subscribeTo(DmlGrammar.TABLE_DECLARATION);
^
symbol: variable TABLE_DECLARATION
location: class DmlGrammar
1 error

Task :compileJava FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileJava'.

Compilation failed; see the compiler error output for details.

  • Try:

Run with --info option to get more log output.
Run with --scan to get full insights.

BUILD FAILED in 4s
1 actionable task: 1 executed


Here is my custom rule class

package com.company.plsql;

import java.util.regex.Pattern;
import org.sonar.plugins.plsqlopen.api.annotations.Priority;
import org.sonar.plugins.plsqlopen.api.annotations.Rule;
import org.sonar.plugins.plsqlopen.api.DmlGrammar;
import org.sonar.plugins.plsqlopen.api.annotations.ActivatedByDefault;
import org.sonar.plugins.plsqlopen.api.annotations.ConstantRemediation;
import org.sonar.plugins.plsqlopen.api.checks.PlSqlCheck;
import org.sonar.plugins.plsqlopen.api.sslr.AstNode;
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar;
import org.sonar.plugins.plsqlopen.api.DmlGrammar;

@rule(
name = "Table Naming Conventions",
description = "Ensure tables follow the defined naming conventions.",
key = "TableNamingCheck",
priority = Priority.MAJOR
)
@ConstantRemediation("10min")
@ActivatedByDefault
public class TableNamingCheck extends PlSqlCheck {

private static final Pattern TABLE_PATTERN = Pattern.compile("^([A-Z0-9]{2,3})_([A-Z0-9_]+)(_TN|_TABLE_TN|_TABLE)?$");

@Override
public void init() {
    subscribeTo(DmlGrammar.TABLE_DECLARATION);
}
@Override
public void visitNode(AstNode node) {
    String tableName = node.getTokenOriginalValue().toUpperCase();

    if (!TABLE_PATTERN.matcher(tableName).matches()) {
        addIssue(node, "Table name does not follow the naming conventions.");
        return;
    }
    // Additional checks for exceptions
    if (tableName.endsWith("_GTT") || tableName.endsWith("_MV") || tableName.startsWith("TMP_") || tableName.endsWith("_TEMP") || tableName.endsWith("_TMP")) {
        return;
    }
    if (tableName.startsWith("JSR") || tableName.startsWith("JSD")) {
        addIssue(node, "Table names should not start with JSR or JSD.");
    }
}

}

NOTE: I also tried with PlSqlGrammar.TABLE_DECLARATION; But still got the same error.

Please suggest an alternative way to achieve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions