Java Path Extract nio extractLuaStacktrace(Path path, StackTraceElement[] stackTrace)

Here you can find the source of extractLuaStacktrace(Path path, StackTraceElement[] stackTrace)

Description

extract Lua Stacktrace

License

Open Source License

Declaration

public static final StackTraceElement[] extractLuaStacktrace(Path path, StackTraceElement[] stackTrace) 

Method Source Code


//package com.java2s;
/*//from  w w w . j  ava2s. com
 * Copyright 2016, Robert 'Bobby' Zenz
 * 
 * This file is part of Quadracoatl.
 * 
 * Quadracoatl is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Quadracoatl is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with Quadracoatl.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static final StackTraceElement[] extractLuaStacktrace(Path path, StackTraceElement[] stackTrace) {
        if (stackTrace == null || stackTrace.length == 0) {
            return new StackTraceElement[0];
        }

        List<StackTraceElement> luaStackTrace = new ArrayList<>();

        String pathAsString = path.toString().replace('.', '/');

        for (StackTraceElement stackTraceElement : stackTrace) {
            String fileName = stackTraceElement.getFileName();

            if (fileName != null && fileName.startsWith(pathAsString)) {
                fileName = fileName.substring(pathAsString.length());
                fileName = fileName.replaceAll("/+", "/");

                String methodName = stackTraceElement.getMethodName();

                int dollarIndex = stackTraceElement.getClassName().indexOf('$');

                if (dollarIndex >= 0) {
                    methodName = stackTraceElement.getClassName().substring(dollarIndex + 1);
                }

                StackTraceElement luaStackTraceElement = new StackTraceElement("", fileName, methodName,
                        stackTraceElement.getLineNumber());

                luaStackTrace.add(luaStackTraceElement);
            }
        }

        return luaStackTrace.toArray(new StackTraceElement[luaStackTrace.size()]);
    }
}

Related

  1. extract(Path archive, Path targetDirectory)
  2. extractClassName(Path path)
  3. extractCurrentPath()
  4. extractFile(ZipInputStream zipIn, Path filePath)
  5. extractLanguageRelativePath(final Path absolutePath)
  6. extractVersion(Path pathToBinaries)
  7. extractZipArchive(final File zipFile, Path destDir)
  8. unzipFileInArchive(FileChannel channel, String relpathInZip, File extractTo)