public static Path getRootFolderForSource ( Path sourceFilePath , String packageName ) { if ( packageName == null || packageName . trim ( ) . isEmpty ( ) ) { return sourceFilePath . getParent ( ) ; } String [ ] packageNameComponents = packageName . split ( "\\." ) ; Path currentPath = sourceFilePath . getParent ( ) ; for ( int i = packageNameComponents . length ; i > 0 ; i -- ) { String packageComponent = packageNameComponents [ i - 1 ] ; if ( ! StringUtils . equals ( packageComponent , currentPath . getFileName ( ) . toString ( ) ) ) { return null ; } currentPath = currentPath . getParent ( ) ; } return currentPath ; }
Returns the root path for this source file based upon the package name .