< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/parser/FindSymbol.java

Print this page




  29 import java.util.ArrayList;
  30 import java.util.List;
  31 import java.util.Collection;
  32 import java.util.function.Predicate;
  33 import com.sun.tools.jextract.tree.Tree;
  34 import com.sun.tools.jextract.tree.HeaderTree;
  35 import com.sun.tools.jextract.tree.Printer;
  36 
  37 public class FindSymbol {
  38     public static void main(String[] args) {
  39         if (args.length == 0) {
  40             System.err.println("Expected a header file");
  41             return;
  42         }
  43 
  44         final List<Path> paths = List.of(Paths.get(args[0]));
  45         final Path builtinInc = Paths.get(System.getProperty("java.home"), "conf", "jextract");
  46         final List<String> clangArgs = List.of("-I" + builtinInc);
  47 
  48         final Parser parser = new Parser(true);
  49         final List<HeaderTree> headers = parser.parse(paths, clangArgs, c->true);
  50         final Printer p = new Printer();
  51         final HeaderTree tu = headers.get(0);
  52 
  53         if (args.length == 1) {
  54             p.printRecursive(tu, Integer.MAX_VALUE);
  55             return;
  56         }
  57 
  58         final Collection<String> set = Arrays.asList(Arrays.copyOfRange(args, 1, args.length));
  59         final Predicate<Tree> matchName = tree -> tree.isDeclaration() && set.contains(tree.name());
  60         tu.declarations().stream()
  61                 .filter(matchName)
  62                 .forEach(declTree -> p.printRecursive(declTree, Integer.MAX_VALUE));
  63     }
  64 }


  29 import java.util.ArrayList;
  30 import java.util.List;
  31 import java.util.Collection;
  32 import java.util.function.Predicate;
  33 import com.sun.tools.jextract.tree.Tree;
  34 import com.sun.tools.jextract.tree.HeaderTree;
  35 import com.sun.tools.jextract.tree.Printer;
  36 
  37 public class FindSymbol {
  38     public static void main(String[] args) {
  39         if (args.length == 0) {
  40             System.err.println("Expected a header file");
  41             return;
  42         }
  43 
  44         final List<Path> paths = List.of(Paths.get(args[0]));
  45         final Path builtinInc = Paths.get(System.getProperty("java.home"), "conf", "jextract");
  46         final List<String> clangArgs = List.of("-I" + builtinInc);
  47 
  48         final Parser parser = new Parser(true);
  49         final List<HeaderTree> headers = parser.parse(paths, clangArgs);
  50         final Printer p = new Printer();
  51         final HeaderTree tu = headers.get(0);
  52 
  53         if (args.length == 1) {
  54             p.printRecursive(tu, Integer.MAX_VALUE);
  55             return;
  56         }
  57 
  58         final Collection<String> set = Arrays.asList(Arrays.copyOfRange(args, 1, args.length));
  59         final Predicate<Tree> matchName = tree -> tree.isDeclaration() && set.contains(tree.name());
  60         tu.declarations().stream()
  61                 .filter(matchName)
  62                 .forEach(declTree -> p.printRecursive(declTree, Integer.MAX_VALUE));
  63     }
  64 }
< prev index next >