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

58
LINES

< > BotCompany Repo | #1011232 // Test making all fields, methods & classes public in Java source [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 2039K of libraries. Click here for Pure Java version (4663L/30K).

1  
!759
2  
3  
import com.github.javaparser.ast.body.MethodDeclaration;
4  
import com.github.javaparser.ast.body.EnumDeclaration;
5  
import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt;
6  
import com.github.javaparser.ast.Modifier;
7  
import com.github.javaparser.printer.*;
8  
9  
p-center {
10  
  S src = getServerTranspiled2(/*#1011235*/#1001649);
11  
  CompilationUnit cu = javaParseCompilationUnit(src);
12  
  printJavaParserTree(cu);
13  
  new PrettyPrinterConfiguration ppconf;
14  
  ppconf.setIndent("  ");
15  
  S pp = cu.toString(ppconf);
16  
  new PublicationVisitor().visit(cu, null);
17  
  print();
18  
  swingDiff(pp, cu.toString(ppconf));
19  
}
20  
21  
static class PublicationVisitor extends VoidVisitorAdapter {
22  
  void makePublic(Set<Modifier> modifiers) {
23  
    modifiers.remove(Modifier.PRIVATE);
24  
    modifiers.remove(Modifier.PROTECTED);
25  
    modifiers.add(Modifier.PUBLIC);
26  
  }
27  
28  
  public void visit(ClassOrInterfaceDeclaration n, O arg) {
29  
    Node parent = n.getParentNode().get();
30  
    print("Class " + n.getName() + " parent: " + className(parent));
31  
    if (!parent instanceof LocalClassDeclarationStmt)
32  
      makePublic(n.getModifiers());
33  
    super.visit(n, arg);
34  
  }
35  
  
36  
  public void visit(FieldDeclaration n, O arg) {
37  
    makePublic(n.getModifiers());
38  
    super.visit(n, arg);
39  
  }
40  
  
41  
  public void visit(ConstructorDeclaration n, O arg) {
42  
    Node parent = n.getParentNode().get();
43  
    print("Constructor parent: " + className(parent));
44  
    if (!parent instanceof EnumDeclaration)
45  
      makePublic(n.getModifiers());
46  
    super.visit(n, arg);
47  
  }
48  
  
49  
  public void visit(MethodDeclaration n, O arg) {
50  
    EnumSet<Modifier> m = n.getModifiers();
51  
    //print("Method found: " + n.getName() + " with modifiers: " + m + ", position: " + n.getRange()->begin);
52  
    
53  
    if (m.contains(Modifier.PRIVATE)) m.add(Modifier.FINAL);
54  
    makePublic(m);
55  
    
56  
    super.visit(n, arg);
57  
  }
58  
}

Author comment

Began life as a copy of #1011229

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1011232
Snippet name: Test making all fields, methods & classes public in Java source [OK]
Eternal ID of this version: #1011232/27
Text MD5: 99d0f4feec12e989d0b84606df4db6cd
Transpilation MD5: 54ba4ea517a279c0248e9bcb6569fffa
Author: stefan
Category: javax / parsing
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-19 23:00:02
Source code size: 1890 bytes / 58 lines
Pitched / IR pitched: No / No
Views / Downloads: 611 / 1258
Version history: 26 change(s)
Referenced in: [show references]