org.walkmod.javalang.walkers.JavaSourceUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of walkmod-javalang-plugin Show documentation
Show all versions of walkmod-javalang-plugin Show documentation
Walkmod plugin to support the Java 8 programming language. It contains helper visitors, a walker and a basic code writer.
package org.walkmod.javalang.walkers;
import java.io.File;
import org.walkmod.javalang.ast.CompilationUnit;
import org.walkmod.javalang.ast.PackageDeclaration;
import org.walkmod.javalang.ast.expr.NameExpr;
public class JavaSourceUtils {
public static String getSourceDirs(String rootDir, File file, CompilationUnit cu) throws Exception {
String readerFile = new File(rootDir).getCanonicalPath();
if (!readerFile.endsWith(File.separator)) {
readerFile += File.separator;
}
String path = file.getCanonicalPath();
String cuPath = getRelativePath(file, cu);
int srcIndex = path.indexOf(cuPath);
return path.substring(readerFile.length(), srcIndex);
}
public static String getRelativePath(File file, CompilationUnit cu) throws Exception {
String cuPath = "";
PackageDeclaration pd = cu.getPackage();
if (pd != null) {
NameExpr packageName = pd.getName();
String packPath = packageName.toString().replace('.', File.separatorChar);
cuPath = packPath + File.separator + file.getName();
} else {
cuPath = file.getName();
}
return cuPath;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy