Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6116877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:15:25+00:00 2026-05-23T15:15:25+00:00

I have another StackOverflow question on how to install and run a custom checkstyle.

  • 0

I have another StackOverflow question on how to install and run a custom checkstyle. I’ve learned how to do this, and I will update that answer shortly with detailed instructions. Now I am having trouble customizing my check. Below is my code. The problem is I would like to see the fully qualified package as a string (e.g com.amir.foo) – but instead when I run getText() or just toString(), I get some obscure result ([checkstyle] package set to : ANNOTATIONS). Does anyone know how to work with this to achieve the desired results?

import com.puppycrawl.tools.checkstyle.api.*;

public class MyCheck extends Check
{

    FullIdent packageDeclaration;

    public int[] getDefaultTokens() {
        return new int[]{TokenTypes.PACKAGE_DEF};
    }

    public void visitToken(DetailAST ast)
    {

        switch(ast.getType()) {
            case TokenTypes.PACKAGE_DEF:
                System.out.println("got package!");
                visitPackage(ast);
                break;
            default:
                System.out.println("naughty!");
        }

    }

    private void visitPackage(DetailAST pack) {
        packageDeclaration = FullIdent.createFullIdentBelow(pack);
        System.out.println("package set to : " +packageDeclaration);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:15:25+00:00Added an answer on May 23, 2026 at 3:15 pm

    What your looking for is used by the check for package names, you should use a code similar to the following:

    @Override
    public void visitToken(DetailAST aAST)
    {
        final DetailAST nameAST = aAST.getLastChild().getPreviousSibling();
        final FullIdent full = FullIdent.createFullIdent(nameAST);
        final String package = full.getText();
    
    
        // do some fancy stuff with package name
    }
    

    For more details please refer to the source code of PackageNameCheck:
    http://checkstyle.hg.sourceforge.net/hgweb/checkstyle/checkstyle/file/cd352660c53a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/naming/PackageNameCheck.java

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code (found from another StackOverflow question: $(document).ready(function() { $.ajax({ url: soundfile.mp3,
I have a question from this stackoverflow question about iPhone storage . Like I
There is another question on stackoverflow with this title. This is the link to
I have seen a few variants of this nested UL array question on stackoverflow,
I have a question about .data(). In a stackoverflow answer, jquery saves data in
I have a Java application that launches another java application. The launcher has a
I have a value like this: Foo Bar Another Value something else What regex
I have an application that writes to another application and needs to provide the
Put it another way: what code have you written that cannot fail. I'm interested
Good morning, all. This is my first question on stackoverflow, so hopefully this isn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.