com.sun.source.tree.TreeVisitor Java Examples

The following examples show how to use com.sun.source.tree.TreeVisitor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavacModuleParser.java    From pro with GNU General Public License v3.0 6 votes vote down vote up
public static void parse(Path moduleInfoPath, ModuleClassVisitor moduleClassVisitor) throws IOException {
  var compiler = ToolProvider.getSystemJavaCompiler();
  try(var fileManager = compiler.getStandardFileManager(null, null, null)) {
    var compilationUnits = fileManager.getJavaFileObjects(moduleInfoPath);
    var task = compiler.getTask(null, fileManager, null, null, null, compilationUnits);
    var javacTask = (JavacTask)task;
    var units = javacTask.parse();
    var unit = units.iterator().next();

    var moduleHandler = new ModuleHandler(moduleClassVisitor);
    var visitor = (TreeVisitor<?,?>)Proxy.newProxyInstance(TreeVisitor.class.getClassLoader(), new Class<?>[]{ TreeVisitor.class},
        (proxy, method, args) -> {
          ModuleHandler.METHOD_MAP
          .getOrDefault(method.getName(), (handler, node, v) -> { 
            throw new AssertionError("invalid node " + node.getClass());
          })
          .visit(moduleHandler, (Tree)args[0], (TreeVisitor<?,?>)proxy);
          return null;
        });

    unit.accept(visitor, null);
  }
}
 
Example #2
Source File: FieldGroupTree.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public <R, D> R accept(TreeVisitor<R, D> arg0, D arg1) {
    R ret = null;
    for (JCVariableDecl v : vars) {
        ret = v.accept(arg0, arg1);
    }
    return ret;
}
 
Example #3
Source File: JavacModuleParser.java    From pro with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("static-method")
public void visitCompilationUnit(CompilationUnitTree node, TreeVisitor<?, ?> visitor) {
  for(var directive: node.getTypeDecls()) {
    if (!(directive instanceof ModuleTree)) {  // skip unnecessary nodes: imports, etc
      continue;
    }
    accept(visitor, directive);
  }
}
 
Example #4
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitSynchronized(this, d);
}
 
Example #5
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitUnary(this, d);
}
 
Example #6
Source File: UPrimitiveTypeTree.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return visitor.visitPrimitiveType(this, data);
}
 
Example #7
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitAssert(this, d);
}
 
Example #8
Source File: UMethodDecl.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return visitor.visitMethod(this, data);
}
 
Example #9
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitUnionType(this, d);
}
 
Example #10
Source File: UOfKind.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return expression().accept(visitor, data);
}
 
Example #11
Source File: UTypeCast.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return visitor.visitTypeCast(this, data);
}
 
Example #12
Source File: UMemberSelect.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return visitor.visitMemberSelect(this, data);
}
 
Example #13
Source File: UConditional.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return visitor.visitConditionalExpression(this, data);
}
 
Example #14
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitBreak(this, d);
}
 
Example #15
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitCompoundAssignment(this, d);
}
 
Example #16
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitContinue(this, d);
}
 
Example #17
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitCase(this, d);
}
 
Example #18
Source File: ULiteral.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return visitor.visitLiteral(this, data);
}
 
Example #19
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitTypeCast(this, d);
}
 
Example #20
Source File: UArrayAccess.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return visitor.visitArrayAccess(this, data);
}
 
Example #21
Source File: UInstanceOf.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return visitor.visitInstanceOf(this, data);
}
 
Example #22
Source File: UAssign.java    From Refaster with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> visitor, D data) {
  return visitor.visitAssignment(this, data);
}
 
Example #23
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitModifiers(this, d);
}
 
Example #24
Source File: JCTree.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitArrayAccess(this, d);
}
 
Example #25
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    throw new AssertionError("TypeBoundKind is not part of a public API");
}
 
Example #26
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitWildcard(this, d);
}
 
Example #27
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitTypeParameter(this, d);
}
 
Example #28
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitUnionType(this, d);
}
 
Example #29
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitParameterizedType(this, d);
}
 
Example #30
Source File: JCTree.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
@Override
public <R, D> R accept(TreeVisitor<R, D> v, D d) {
    return v.visitArrayType(this, d);
}