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

  • SEARCH
  • Home
  • 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 8709189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:18:28+00:00 2026-06-13T04:18:28+00:00

Files that define Java classes can be organized into packages by declaring them to

  • 0

Files that define Java classes can be organized into packages by declaring them to belong to particular package, e.g.

package foo.bar;

which declares that the file in question belongs to the subpackage bar of the package foo. The files are then stored in directories with a hierarchy corresponding to the hierarchy of the packages. Also, the root of the package hierarchy is usually some directory src. Is it possible to write a YASnippet that expands into a package declaration such it gets the package name from the path of the current file?

  • 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-06-13T04:18:29+00:00Added an answer on June 13, 2026 at 4:18 am

    You can write a snippet with embedded Emacs Lisp that gets the buffer’s path and converts it to a package name by treating the directory src as the root in the package hierarchy:

    # -*- mode: snippet -*-
    #name : package
    #key : pa
    # --
    package ${1:`(mapconcat 'identity (cdr (member "src" (split-string default-directory "/" t))) ".")`};$0
    

    This will recognize multi-level package hierarchies, i.e. if the path to the buffer of the file you are editing is /home/nn/src/foo/bar/Baz.java the snippet will expand to

    package foo.bar;
    

    Note that this requires you to use src as the root directory storing the package hierarchy. If there is directory named src in the path to the buffer the snippet will expand to

    package ;
    

    To have the snippet recognize some other directory as the root in the package hierarchy simply replace "src" with the desired directory name.

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

Sidebar

Related Questions

I have these two simple files that define a C++ class with a tryME
I'm curious as to whether one can define a Java class purely using a
I have a set of xsd files and I need to generate java classes
in my java Project I have several classes/java files but is in Menu class
I have a file that defines constant variables, like this: define_vars.php <? define(something,value); define(something1,value);
I need to define a Wix file component that may not exist in certain
I'm trying to define a service endpoint in my web.config file so that I
I understand that we need to create MXML file to define a view. Suppose
This the model that I want to create using json file Ext.define('Users', { extend:
I'm facing the problem, that the annotation @Autowired doesn't work anymore (in all Java

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.