1 package org.codehaus.mojo.jflex;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.FileReader;
6 import java.io.IOException;
7 import java.io.LineNumberReader;
8
9 public class LexSimpleAnalyzer {
10 public static final String DEFAULT_NAME = "Yylex";
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 protected static ClassInfo guessPackageAndClass(File lexFile)
28 throws FileNotFoundException, IOException {
29
30 LineNumberReader reader = new LineNumberReader(new FileReader(lexFile));
31
32 ClassInfo classInfo = new ClassInfo();
33
34 while (classInfo.className == null || classInfo.packageName == null) {
35 String line = reader.readLine();
36 if (line == null)
37 break;
38
39 if (classInfo.packageName == null) {
40 int index = line.indexOf("package");
41 if (index >= 0) {
42 index += 7;
43
44 int end = line.indexOf(';', index);
45 if (end >= index) {
46 classInfo.packageName = line.substring(index, end);
47 classInfo.packageName = classInfo.packageName.trim();
48 }
49 }
50 }
51
52 if (classInfo.className == null) {
53 int index = line.indexOf("%class");
54 if (index >= 0) {
55 index += 6;
56
57 classInfo.className = line.substring(index);
58 classInfo.className = classInfo.className.trim();
59 }
60 }
61 }
62
63
64 if (classInfo.className == null) {
65
66
67
68 classInfo.className = DEFAULT_NAME;
69 }
70 return classInfo;
71 }
72 }