1 | /* |
---|---|
2 | * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. |
3 | * Copyright (C) 2011, 2013-2020 The JavaParser Team. |
4 | * |
5 | * This file is part of JavaParser. |
6 | * |
7 | * JavaParser can be used either under the terms of |
8 | * a) the GNU Lesser General Public License as published by |
9 | * the Free Software Foundation, either version 3 of the License, or |
10 | * (at your option) any later version. |
11 | * b) the terms of the Apache License |
12 | * |
13 | * You should have received a copy of both licenses in LICENCE.LGPL and |
14 | * LICENCE.APACHE. Please refer to those files for details. |
15 | * |
16 | * JavaParser is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU Lesser General Public License for more details. |
20 | */ |
21 | |
22 | package com.github.javaparser.printer.concretesyntaxmodel; |
23 | |
24 | import com.github.javaparser.GeneratedJavaParserConstants; |
25 | import com.github.javaparser.ast.Node; |
26 | import com.github.javaparser.ast.observer.ObservableProperty; |
27 | import com.github.javaparser.printer.SourcePrinter; |
28 | import com.github.javaparser.utils.LineSeparator; |
29 | |
30 | import java.util.Arrays; |
31 | import java.util.List; |
32 | |
33 | import static com.github.javaparser.TokenTypes.*; |
34 | |
35 | public interface CsmElement { |
36 | |
37 | void prettyPrint(Node node, SourcePrinter printer); |
38 | |
39 | static CsmElement child(ObservableProperty property) { |
40 | return new CsmSingleReference(property); |
41 | } |
42 | |
43 | static CsmElement attribute(ObservableProperty property) { |
44 | return new CsmAttribute(property); |
45 | } |
46 | |
47 | static CsmElement sequence(CsmElement... elements) { |
48 | return new CsmSequence(Arrays.asList(elements)); |
49 | } |
50 | |
51 | static CsmElement string(int tokenType, String content) { |
52 | return new CsmToken(tokenType, content); |
53 | } |
54 | |
55 | static CsmElement string(int tokenType) { |
56 | return new CsmToken(tokenType); |
57 | } |
58 | |
59 | static CsmElement stringToken(ObservableProperty property) { |
60 | return new CsmString(property); |
61 | } |
62 | |
63 | static CsmElement textBlockToken(ObservableProperty property) { |
64 | return new CsmString(property); |
65 | } |
66 | |
67 | static CsmElement charToken(ObservableProperty property) { |
68 | return new CsmChar(property); |
69 | } |
70 | |
71 | static CsmElement token(int tokenType) { |
72 | return new CsmToken(tokenType); |
73 | } |
74 | |
75 | static CsmElement token(int tokenType, CsmToken.TokenContentCalculator tokenContentCalculator) { |
76 | return new CsmToken(tokenType, tokenContentCalculator); |
77 | } |
78 | |
79 | static CsmElement conditional(ObservableProperty property, CsmConditional.Condition condition, CsmElement thenElement) { |
80 | return new CsmConditional(property, condition, thenElement); |
81 | } |
82 | |
83 | static CsmElement conditional(ObservableProperty property, CsmConditional.Condition condition, CsmElement thenElement, CsmElement elseElement) { |
84 | return new CsmConditional(property, condition, thenElement, elseElement); |
85 | } |
86 | |
87 | static CsmElement conditional(List<ObservableProperty> properties, CsmConditional.Condition condition, CsmElement thenElement, CsmElement elseElement) { |
88 | return new CsmConditional(properties, condition, thenElement, elseElement); |
89 | } |
90 | |
91 | static CsmElement space() { |
92 | return new CsmToken(spaceTokenKind(), " "); |
93 | } |
94 | |
95 | static CsmElement semicolon() { |
96 | return new CsmToken(GeneratedJavaParserConstants.SEMICOLON); |
97 | } |
98 | |
99 | static CsmElement comment() { return new CsmComment(); } |
100 | |
101 | static CsmElement newline() { |
102 | return newline(LineSeparator.SYSTEM); |
103 | } |
104 | |
105 | static CsmElement newline(LineSeparator lineSeparator) { |
106 | return new CsmToken(eolTokenKind(lineSeparator), lineSeparator.asRawString()); |
107 | } |
108 | |
109 | static CsmElement none() { |
110 | return new CsmNone(); |
111 | } |
112 | |
113 | static CsmElement comma() { |
114 | return new CsmToken(GeneratedJavaParserConstants.COMMA); |
115 | } |
116 | |
117 | static CsmElement list(ObservableProperty property) { |
118 | return new CsmList(property); |
119 | } |
120 | |
121 | static CsmElement list(ObservableProperty property, CsmElement separator) { |
122 | return new CsmList(property, CsmElement.none(), separator, new CsmNone(), new CsmNone()); |
123 | } |
124 | |
125 | static CsmElement list(ObservableProperty property, CsmElement separator, CsmElement preceeding, CsmElement following) { |
126 | return new CsmList(property, none(), separator, preceeding, following); |
127 | } |
128 | |
129 | static CsmElement list(ObservableProperty property, CsmElement separatorPre, CsmElement separatorPost, CsmElement preceeding, CsmElement following) { |
130 | return new CsmList(property, separatorPre, separatorPost, preceeding, following); |
131 | } |
132 | |
133 | static CsmElement orphanCommentsEnding() { |
134 | return new CsmOrphanCommentsEnding(); |
135 | } |
136 | |
137 | static CsmElement orphanCommentsBeforeThis() { |
138 | // FIXME |
139 | return new CsmNone(); |
140 | } |
141 | |
142 | static CsmElement indent() { |
143 | return new CsmIndent(); |
144 | } |
145 | |
146 | static CsmElement unindent() { |
147 | return new CsmUnindent(); |
148 | } |
149 | |
150 | static CsmElement block(CsmElement content) { |
151 | return sequence(token(GeneratedJavaParserConstants.LBRACE), indent(), content, unindent(), token(GeneratedJavaParserConstants.RBRACE)); |
152 | } |
153 | } |
154 |
Members