Transpiled version (8117L) is out of date.
1 | import com.github.javaparser.ast.body.MethodDeclaration; |
2 | import com.github.javaparser.ast.body.EnumDeclaration; |
3 | import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt; |
4 | import com.github.javaparser.printer.*; |
5 | |
6 | static S javaParser_makeAllPublic(S src, O... _) { |
7 | CompilationUnit cu = javaParseCompilationUnit(src); |
8 | new PrettyPrinterConfiguration ppconf; |
9 | ppconf.setIndent(" "); |
10 | ppconf.setPrintComments(false); |
11 | new javaParser_makeAllPublic_Visitor visitor; |
12 | visitor.notTopLevelClassDecl = boolOptPar notTopLevelClassDecl(_); |
13 | visitor.visit(cu, null); |
14 | ret cu.toString(ppconf); |
15 | } |
16 | |
17 | sclass javaParser_makeAllPublic_Visitor extends VoidVisitorAdapter { |
18 | bool notTopLevelClassDecl; // don't make top-level class declaration public |
19 | |
20 | void makePublic(Set<com.github.javaparser.ast.Modifier> modifiers) { |
21 | modifiers.remove(com.github.javaparser.ast.Modifier.PRIVATE); |
22 | modifiers.remove(com.github.javaparser.ast.Modifier.PROTECTED); |
23 | modifiers.add(com.github.javaparser.ast.Modifier.PUBLIC); |
24 | } |
25 | |
26 | public void visit(ClassOrInterfaceDeclaration n, O arg) { |
27 | Node parent = n.getParentNode().get(); |
28 | if (!(parent instanceof LocalClassDeclarationStmt |
29 | || parent instanceof CompilationUnit && neq(n.getName().asString(), "main"))) |
30 | if (notTopLevelClassDecl) |
31 | notTopLevelClassDecl = false; |
32 | else |
33 | makePublic(n.getModifiers()); |
34 | super.visit(n, arg); |
35 | } |
36 | |
37 | @Override |
38 | public void visit(EnumDeclaration n, O arg) { |
39 | makePublic(n.getModifiers()); |
40 | super.visit(n, arg); |
41 | } |
42 | |
43 | public void visit(FieldDeclaration n, O arg) { |
44 | makePublic(n.getModifiers()); |
45 | super.visit(n, arg); |
46 | } |
47 | |
48 | public void visit(ConstructorDeclaration n, O arg) { |
49 | Node parent = n.getParentNode().get(); |
50 | if (!parent instanceof EnumDeclaration) |
51 | makePublic(n.getModifiers()); |
52 | super.visit(n, arg); |
53 | } |
54 | |
55 | public void visit(MethodDeclaration n, O arg) { |
56 | EnumSet<com.github.javaparser.ast.Modifier> m = n.getModifiers(); |
57 | //print("Method found: " + n.getName() + " with modifiers: " + m + ", position: " + n.getRange()->begin); |
58 | if (m.contains(com.github.javaparser.ast.Modifier.PRIVATE) && !m.contains(com.github.javaparser.ast.Modifier.STATIC)) m.add(com.github.javaparser.ast.Modifier.FINAL); |
59 | makePublic(m); |
60 | super.visit(n, arg); |
61 | } |
62 | } |
Began life as a copy of #1011232
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1011234 |
Snippet name: | javaParser_makeAllPublic (OLD) - also pretty-prints whole source |
Eternal ID of this version: | #1011234/14 |
Text MD5: | b7d4b73bc0048ee9721e38076e05696f |
Author: | stefan |
Category: | javax / parsing |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-06-16 21:25:09 |
Source code size: | 2376 bytes / 62 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 574 / 626 |
Version history: | 13 change(s) |
Referenced in: | [show references] |