Here you can find the source of getPackageURI(String pkgName, String pkgPath, String currentPkgName)
Parameter | Description |
---|---|
pkgName | Name of the package that need the URI for |
pkgPath | String URI of the current package |
currentPkgName | Name of the current package |
public static String getPackageURI(String pkgName, String pkgPath, String currentPkgName)
//package com.java2s; /*/*ww w .ja va 2s . c om*/ * Copyright (c) 2018, WSO2 Inc. (http://wso2.com) All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.nio.file.Paths; public class Main { /** * Get the package URI to the given package name. * * @param pkgName Name of the package that need the URI for * @param pkgPath String URI of the current package * @param currentPkgName Name of the current package * @return String URI for the given path. */ public static String getPackageURI(String pkgName, String pkgPath, String currentPkgName) { String newPackagePath; // If current package path is not null and current package is not default package continue, // else new package path is same as the current package path. if (pkgPath != null && !currentPkgName.equals(".")) { int indexOfCurrentPkgName = pkgPath.lastIndexOf(currentPkgName); if (indexOfCurrentPkgName >= 0) { newPackagePath = pkgPath.substring(0, indexOfCurrentPkgName); } else { newPackagePath = pkgPath; } if (pkgName.equals(".")) { newPackagePath = Paths.get(newPackagePath).toString(); } else { newPackagePath = Paths.get(newPackagePath, pkgName).toString(); } } else { newPackagePath = pkgPath; } return newPackagePath; } }