Use relative paths by default

Fix filtering interface methods

Get relative path from tag file
This commit is contained in:
2025-03-26 21:46:29 +03:00
parent b386142752
commit 2d3d4b4de4
4 changed files with 18 additions and 17 deletions

View File

@@ -56,9 +56,13 @@ public class Build {
}
static void buildJtags(String mainClass, String[] sourcePaths, String[] classPaths) {
if (classNeedsRebuild(mainClass, sourcePaths)) {
logger.info("Compiling %s...".formatted(program));
compileJava(classPaths, sourcePaths);
if (!classNeedsRebuild(mainClass, sourcePaths)) {
return;
}
logger.info("Compiling %s...".formatted(program));
if (!compileJava(classPaths, sourcePaths)) {
System.exit(1);
}
}

View File

@@ -11,7 +11,7 @@ import java.util.List;
public class Jtags {
static class Options {
List<String> sources = new ArrayList<>();
Path output = Path.of("tags");
Path output = Path.of(".", "tags");
boolean absolutePaths = false;
boolean excludeNonPublic = false;
boolean excludeAnonymous = false;
@@ -91,7 +91,6 @@ public class Jtags {
case "-lib":
logger.config("Third-party library mode");
options.absolutePaths = true;
options.excludeNonPublic = true;
options.excludeAnonymous = true;
break;
@@ -139,7 +138,7 @@ Usage: jtags [options] <sources...>
Options:
-o, -output <file> Write tags to specified <file>
-lib Treat sources as third-party libraries
(alias for -absolute -no-non-public -no-anonymous)
(alias for -no-non-public -no-anonymous)
-no-anonymous Exclude anonymous classes
-no-non-public Exclude non-public elements
-absolute Use absolute paths for tag locations

View File

@@ -9,7 +9,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Path;
import java.util.PriorityQueue;
import xyz.naofal.jtags.Jtags.Options;
@@ -47,7 +46,7 @@ public record TagsWriter(Options options) {
writer.write(
options().absolutePaths
? tag.location().toString()
: Path.of(".").toAbsolutePath().relativize(tag.location()).toString());
: options.output.getParent().toAbsolutePath().relativize(tag.location()).toString());
writer.write("\t/^");
writer.write(tag.line().substring(0, Math.min(tag.line().length(), MAX_PATTERN_LENGTH)));
writer.write("$/;\"\t");

View File

@@ -104,7 +104,11 @@ public class TreeVisitor extends TreePathScanner<Void, TreeVisitorContext> {
@Override
public Void visitMethod(MethodTree node, TreeVisitorContext p) {
if (options.excludeNonPublic && !node.getModifiers().getFlags().contains(Modifier.PUBLIC)) {
ClassTree enclosingType = (ClassTree)getCurrentPath().getParentPath().getLeaf();
if (options.excludeNonPublic
&& !node.getModifiers().getFlags().contains(Modifier.PUBLIC)
&& enclosingType.getKind() != Tree.Kind.INTERFACE) {
return null;
}
@@ -116,14 +120,9 @@ public class TreeVisitor extends TreePathScanner<Void, TreeVisitorContext> {
}
if (options.fields.contains(TagField.EnclosingType.class)) {
for (var path : getCurrentPath().getParentPath()) {
if (path instanceof ClassTree classTree) {
fields.add(
new TagField.EnclosingType(
classTree.getSimpleName().toString(), getTypeKind(classTree)));
break;
}
}
fields.add(
new TagField.EnclosingType(
enclosingType.getSimpleName().toString(), getTypeKind(enclosingType)));
}
Tag tag =