Use relative paths by default
Fix filtering interface methods Get relative path from tag file
This commit is contained in:
10
Build.java
10
Build.java
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user