Compare commits
2 Commits
main
...
multithrea
| Author | SHA1 | Date | |
|---|---|---|---|
| e97a196354 | |||
| e782d88f37 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,6 +9,7 @@
|
||||
|
||||
/third-party/downloads/*
|
||||
/third-party/**/*.jar
|
||||
/src/test/resources/downloads/*
|
||||
|
||||
/*.jar
|
||||
/docs
|
||||
|
||||
@@ -5,8 +5,11 @@ import static xyz.naofal.jtags.JtagsLogger.logger;
|
||||
import com.sun.source.tree.CompilationUnitTree;
|
||||
import com.sun.source.util.JavacTask;
|
||||
import com.sun.source.util.Trees;
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.StandardJavaFileManager;
|
||||
@@ -23,20 +26,25 @@ public class TagCollector {
|
||||
Iterable<? extends JavaFileObject> compilationUnits =
|
||||
fileManager.getJavaFileObjects(options.sources.toArray(String[]::new));
|
||||
|
||||
logger.info("Parsing sources...");
|
||||
JavacTask task =
|
||||
(JavacTask) compiler.getTask(null, fileManager, null, null, null, compilationUnits);
|
||||
Iterable<? extends CompilationUnitTree> trees = task.parse();
|
||||
|
||||
TreeVisitor treeVisitor = new TreeVisitor(options);
|
||||
TreeVisitorContext context = new TreeVisitorContext(Trees.instance(task));
|
||||
logger.info("Collecting tags...");
|
||||
|
||||
Trees treeUtils = Trees.instance(task);
|
||||
AbstractQueue<Tag> tags = new PriorityBlockingQueue<>();
|
||||
|
||||
TreeVisitor treeVisitor = new TreeVisitor(options, tags);
|
||||
for (CompilationUnitTree compilationUnitTree : trees) {
|
||||
treeVisitor.scan(compilationUnitTree, context);
|
||||
TreeVisitorContext context = new TreeVisitorContext(compilationUnitTree, treeUtils);
|
||||
treeVisitor.scan(compilationUnitTree, context);
|
||||
}
|
||||
|
||||
return treeVisitor.tags;
|
||||
return tags;
|
||||
|
||||
} catch (IOException ex) {
|
||||
} catch (Exception ex) {
|
||||
logger.severe(ex.toString());
|
||||
System.exit(1);
|
||||
return null;
|
||||
|
||||
@@ -13,22 +13,20 @@ import java.util.AbstractQueue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import xyz.naofal.jtags.Jtags.Options;
|
||||
|
||||
public class TreeVisitor extends TreePathScanner<Void, TreeVisitorContext> {
|
||||
public final Options options;
|
||||
public final AbstractQueue<Tag> tags = new PriorityBlockingQueue<>();
|
||||
public final AbstractQueue<Tag> tags;
|
||||
|
||||
public TreeVisitor(Options options) {
|
||||
public TreeVisitor(Options options, AbstractQueue<Tag> tagQueue) {
|
||||
this.options = options;
|
||||
this.tags = tagQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitCompilationUnit(CompilationUnitTree node, TreeVisitorContext p) {
|
||||
p.compilationUnitTree = node;
|
||||
|
||||
logger.fine(() -> "Collecting tags in file: " + p.getLocation());
|
||||
|
||||
return scan(node.getTypeDecls(), p);
|
||||
|
||||
@@ -16,11 +16,12 @@ import java.util.Optional;
|
||||
public class TreeVisitorContext {
|
||||
final Trees trees;
|
||||
final SourcePositions sourcePositions;
|
||||
public CompilationUnitTree compilationUnitTree;
|
||||
final CompilationUnitTree compilationUnitTree;
|
||||
|
||||
public TreeVisitorContext(Trees trees) {
|
||||
public TreeVisitorContext(CompilationUnitTree compilationUnitTree, Trees trees) {
|
||||
this.compilationUnitTree = compilationUnitTree;
|
||||
this.trees = trees;
|
||||
sourcePositions = trees.getSourcePositions();
|
||||
this.sourcePositions = trees.getSourcePositions();
|
||||
}
|
||||
|
||||
public Path getLocation() {
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import static notest.Test.Util.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import notest.Test;
|
||||
|
||||
class TestJtags {
|
||||
@@ -18,10 +25,70 @@ class TestJtags {
|
||||
Jtags,
|
||||
"-o",
|
||||
"-",
|
||||
"src/test/java/examples/BasicExample.java");
|
||||
"src/test/resources/BasicExample.java");
|
||||
|
||||
var tags = readAllLines(process.inputReader());
|
||||
|
||||
getSnapshot().assertEquals(tags);
|
||||
}
|
||||
|
||||
static void downloadOpenjdkSources() throws IOException {
|
||||
Path destination = Path.of("src", "test", "resources", "downloads");
|
||||
if (Files.exists(destination.resolve("openjdk-src"))) return;
|
||||
|
||||
URL openjdkSrcZipURL =
|
||||
URI.create("https://github.com/openjdk/jdk24u/archive/refs/tags/jdk-24+36.zip").toURL();
|
||||
Path openjdkSrcZip = destination.resolve("jdk-24+36.zip");
|
||||
|
||||
if (!Files.exists(openjdkSrcZip)) {
|
||||
System.err.println("Downloading openjdk sources jdk-24+36.zip (~118MB)...");
|
||||
openjdkSrcZipURL
|
||||
.openConnection()
|
||||
.getInputStream()
|
||||
.transferTo(Files.newOutputStream(openjdkSrcZip));
|
||||
}
|
||||
|
||||
System.err.println("Extracting openjdk sources...");
|
||||
|
||||
Files.createDirectories(destination.resolve("openjdk-src"));
|
||||
|
||||
try (InputStream in = Files.newInputStream(openjdkSrcZip);
|
||||
ZipInputStream zin = new ZipInputStream(in)) {
|
||||
ZipEntry entry;
|
||||
while ((entry = zin.getNextEntry()) != null) {
|
||||
if (!entry.getName().startsWith("jdk24u-jdk-24-36/src/j")) {
|
||||
zin.closeEntry();
|
||||
entry = zin.getNextEntry();
|
||||
continue;
|
||||
}
|
||||
Path entryPath =
|
||||
destination.resolve(
|
||||
"openjdk-src", entry.getName().substring("jdk24u-jdk-24-36/src/".length()));
|
||||
if (entry.isDirectory()) {
|
||||
Files.createDirectories(entryPath);
|
||||
} else {
|
||||
var bytes = zin.readAllBytes();
|
||||
Files.write(entryPath, bytes);
|
||||
}
|
||||
zin.closeEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
static void openjdkSources() throws IOException {
|
||||
downloadOpenjdkSources();
|
||||
|
||||
// var process =
|
||||
// runJava(
|
||||
// new String[] {"-Dlogger.level=CONFIG"},
|
||||
// Jtags,
|
||||
// Stream.concat(Stream.of("-o", "-"),
|
||||
// Arrays.stream(glob("src/test/resources/downloads/**/.java")))
|
||||
// .toArray(String[]::new));
|
||||
|
||||
// var tags = readAllLines(process.inputReader());
|
||||
|
||||
// getSnapshot().assertEquals(tags);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
ABC
|
||||
!_TAG_FILE_ENCODING utf-8
|
||||
!_TAG_FILE_SORTED 2 /0=unsorted, 1=sorted, 2=foldcase/
|
||||
InnerClass src/test/java/examples/BasicExample.java /^ class InnerClass {$/;" Cls package:examples class:BasicExample
|
||||
method1 src/test/java/examples/BasicExample.java /^ private boolean method1() {$/;" mthd class:BasicExample
|
||||
method2 src/test/java/examples/BasicExample.java /^ void method2() {}$/;" mthd class:(Anonymous)
|
||||
methodX src/test/java/examples/BasicExample.java /^ public static void method2($/;" mthd file: class:BasicExample
|
||||
method3 src/test/java/examples/BasicExample.java /^ void method3() {}$/;" mthd class:InnerClass
|
||||
method4 src/test/java/examples/BasicExample.java /^ private void method4() {}$/;" mthd class:InnerClass
|
||||
BasicExample src/test/resources/BasicExample.java /^public class BasicExample {$/;" Cls package:examples
|
||||
InnerClass src/test/resources/BasicExample.java /^ class InnerClass {$/;" Cls package:examples class:BasicExample
|
||||
method1 src/test/resources/BasicExample.java /^ private boolean method1() {$/;" mthd class:BasicExample
|
||||
method2 src/test/resources/BasicExample.java /^ void method2() {}$/;" mthd class:(Anonymous)
|
||||
method2 src/test/resources/BasicExample.java /^ public static void method2($/;" mthd file: class:BasicExample
|
||||
method3 src/test/resources/BasicExample.java /^ void method3() {}$/;" mthd class:InnerClass
|
||||
method4 src/test/resources/BasicExample.java /^ private void method4() {}$/;" mthd class:InnerClass
|
||||
|
||||
Reference in New Issue
Block a user