Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

36
LINES

< > TinyBrain | #1004951 - Test JavaParser

JavaX source code [tags: use-pretranspiled] - run with: x30.jar - homepage

Uses 363K of libraries. Click here for Pure Java version (1732L/12K/42K).

!7

lib 1004950 // JavaParser

import com.github.javaparser.*;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.*;
import com.github.javaparser.ast.visitor.*;

p {
  File file = getProgramFile("it.java");
  S java = loadTextFile(file);
  if (java == null) {
    java = getServerTranspilation("#1004930");
    saveTextFile(file, java);
  }

  CompilationUnit cu = JavaParser.parse(java);

  // prints the resulting compilation unit to default system output
  print(cu.toString());
  
  // Visit methods
  new MethodVisitor().visit(cu, null);
}

static class MethodVisitor extends VoidVisitorAdapter {
  public void visit(MethodDeclaration n, Object arg) {
    // here you can access the attributes of the method.
    // this method will be called for all methods in this 
    // CompilationUnit, including inner class methods
    print("Method found: " + n.getName());
    super.visit(n, arg);
  }
}

download  show line numbers  debug dex   

Travelled to 3 computer(s): cfunsshuasjs, ddnzoavkxhuk, tvejysmllsmz

No comments. add comment

Snippet ID: #1004951
Snippet name: Test JavaParser
Eternal ID of this version: #1004951/2
Text MD5: 62e8c57b67bea88cf187d0bc676ed1e3
Transpilation MD5: 252925d7ecf67c83317725004520fb00
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-09-13 17:48:05
Source code size: 973 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 105 / 79
Version history: 1 change(s)
Referenced in: [show]