Convert ScriptNameUtil to Kotlin: phase 2 - convert
This commit is contained in:
committed by
Pavel V. Talanov
parent
f96517a54a
commit
590f09ee58
@@ -14,40 +14,35 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.script;
|
package org.jetbrains.kotlin.script
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.psi.KtScript
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
|
||||||
import org.jetbrains.kotlin.psi.KtScript;
|
|
||||||
|
|
||||||
public class ScriptNameUtil {
|
object ScriptNameUtil {
|
||||||
private ScriptNameUtil() {
|
|
||||||
|
fun fileNameWithExtensionStripped(script: KtScript, extension: String): Name {
|
||||||
|
val file = script.getContainingKtFile()
|
||||||
|
return Name.identifier(generateNameByFileName(file.name, extension))
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
fun generateNameByFileName(fileName: String, extension: String): String {
|
||||||
public static Name fileNameWithExtensionStripped(@NotNull KtScript script, @NotNull String extension) {
|
var fileName = fileName
|
||||||
KtFile file = script.getContainingKtFile();
|
var index = fileName.lastIndexOf('/')
|
||||||
return Name.identifier(generateNameByFileName(file.getName(), extension));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static String generateNameByFileName(@NotNull String fileName, @NotNull String extension) {
|
|
||||||
int index = fileName.lastIndexOf('/');
|
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
fileName = fileName.substring(index + 1);
|
fileName = fileName.substring(index + 1)
|
||||||
}
|
}
|
||||||
if (fileName.endsWith(extension)) {
|
if (fileName.endsWith(extension)) {
|
||||||
fileName = fileName.substring(0, fileName.length() - extension.length());
|
fileName = fileName.substring(0, fileName.length - extension.length)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
index = fileName.indexOf('.');
|
index = fileName.indexOf('.')
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
fileName = fileName.substring(0, index);
|
fileName = fileName.substring(0, index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fileName = Character.toUpperCase(fileName.charAt(0)) + (fileName.length() == 0 ? "" : fileName.substring(1));
|
fileName = Character.toUpperCase(fileName[0]) + if (fileName.length == 0) "" else fileName.substring(1)
|
||||||
fileName = fileName.replace('.', '_');
|
fileName = fileName.replace('.', '_')
|
||||||
return fileName;
|
return fileName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user