1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar.cpptasks.trolltech;
21
22 import java.io.IOException;
23 import java.io.Reader;
24
25 import com.github.maven_nar.cpptasks.parser.AbstractParser;
26 import com.github.maven_nar.cpptasks.parser.AbstractParserState;
27 import com.github.maven_nar.cpptasks.parser.LetterState;
28 import com.github.maven_nar.cpptasks.parser.WhitespaceOrLetterState;
29
30
31
32
33
34
35 public final class MetaObjectParser extends AbstractParser {
36
37
38
39 private static final class FinalTState extends AbstractParserState {
40
41
42
43 private final MetaObjectParser mocParser;
44
45
46
47
48
49
50
51 public FinalTState(final MetaObjectParser parser) {
52 super(parser);
53 this.mocParser = parser;
54 }
55
56
57
58
59
60
61
62
63
64 @Override
65 public AbstractParserState consume(final char ch) {
66 if (ch == 'T') {
67 this.mocParser.setQObject(true);
68 return null;
69 }
70 if (ch == '\n') {
71 getParser().getNewLineState();
72 }
73 return null;
74 }
75 }
76
77
78
79
80
81
82
83
84
85
86 public static boolean hasQObject(final Reader reader) throws IOException {
87 final MetaObjectParser parser = new MetaObjectParser();
88 parser.parse(reader);
89 return parser.hasQObject;
90
91 }
92
93
94
95
96 private boolean hasQObject = false;
97
98
99
100
101 private final AbstractParserState newLineState;
102
103
104
105
106
107 private MetaObjectParser() {
108
109
110
111 final AbstractParserState t = new FinalTState(this);
112 final AbstractParserState c = new LetterState(this, 'C', t, null);
113 final AbstractParserState e = new LetterState(this, 'E', c, null);
114 final AbstractParserState j = new LetterState(this, 'J', e, null);
115 final AbstractParserState b = new LetterState(this, 'B', j, null);
116 final AbstractParserState o = new LetterState(this, 'O', b, null);
117 final AbstractParserState underline = new LetterState(this, '_', o, null);
118 this.newLineState = new WhitespaceOrLetterState(this, 'Q', underline);
119 }
120
121
122
123
124
125
126
127 @Override
128 protected void addFilename(final String filename) {
129
130 }
131
132
133
134
135
136
137 @Override
138 public AbstractParserState getNewLineState() {
139 return this.newLineState;
140 }
141
142
143
144
145
146
147
148
149
150 @Override
151 public void parse(final Reader reader) throws IOException {
152 this.hasQObject = false;
153 super.parse(reader);
154 }
155
156
157
158
159
160
161
162 public void setQObject(final boolean value) {
163 this.hasQObject = value;
164 }
165 }