|
@@ -1,80 +1,80 @@ |
1 |
|
- |
package org.litesoft.javaparser; |
2 |
|
- |
|
3 |
|
- |
import java.io.*; |
4 |
|
- |
import org.litesoft.core.typeutils.Objects; |
5 |
|
- |
import java.util.*; |
6 |
|
- |
|
7 |
|
- |
import org.eclipse.jdt.core.*; |
8 |
|
- |
import org.eclipse.jdt.core.dom.*; |
9 |
|
- |
|
10 |
|
- |
public class MyMain |
11 |
|
- |
{ |
12 |
|
- |
|
13 |
|
- |
public static void main(String[] args) throws Exception |
14 |
|
- |
{ |
15 |
|
- |
System.out.println("Main: " + Arrays.asList(args)); |
16 |
|
- |
if (args.length < 1) |
17 |
|
- |
{ |
18 |
|
- |
System.err.println("At least one file needed..."); |
19 |
|
- |
System.exit( 1 ); |
20 |
|
- |
} |
21 |
|
- |
|
22 |
|
- |
File file = new File(args[0]); |
23 |
|
- |
BufferedReader in = new BufferedReader(new FileReader(file)); |
24 |
|
- |
StringBuffer buffer = new StringBuffer(); |
25 |
|
- |
for (String line; null != (line = in.readLine());) { |
26 |
|
- |
buffer.append(line).append("\n"); |
27 |
|
- |
} |
28 |
|
- |
String text = buffer.toString(); |
29 |
|
- |
|
30 |
|
- |
ASTParser parser = ASTParser.newParser(AST.JLS3); |
31 |
|
- |
Map<String, String> options = new HashMap<String, String>(); |
32 |
|
- |
String zVersion15 = JavaCore.VERSION_1_5; |
33 |
|
- |
options.put(JavaCore.COMPILER_SOURCE, zVersion15); |
34 |
|
- |
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, zVersion15); |
35 |
|
- |
parser.setCompilerOptions(options); |
36 |
|
- |
parser.setResolveBindings(false); |
37 |
|
- |
parser.setKind(ASTParser.K_COMPILATION_UNIT); |
38 |
|
- |
|
39 |
|
- |
parser.setSource(text.toCharArray()); |
40 |
|
- |
CompilationUnit node = (CompilationUnit) parser.createAST(null); |
41 |
|
- |
PackageDeclaration zPackage = node.getPackage(); |
42 |
|
- |
|
43 |
|
- |
System.out.println("Package: " + zPackage.getName()); |
44 |
|
- |
|
45 |
|
- |
List<ImportDeclaration> zImports = (List<ImportDeclaration>) node.imports(); |
46 |
|
- |
if ((zImports != null) && !zImports.isEmpty()) { |
47 |
|
- |
System.out.println("Imports:"); |
48 |
|
- |
for (ImportDeclaration zDeclaration : zImports) { |
49 |
|
- |
System.out.print(" "); |
50 |
|
- |
|
51 |
|
- |
if (zDeclaration.isStatic()) { |
52 |
|
- |
System.out.print("static "); |
53 |
|
- |
} |
54 |
|
- |
System.out.print(zDeclaration.getName()); |
55 |
|
- |
if (zDeclaration.isOnDemand()) { |
56 |
|
- |
System.out.print(".*"); |
57 |
|
- |
} |
58 |
|
- |
System.out.println(); |
59 |
|
- |
} |
60 |
|
- |
} |
61 |
|
- |
|
62 |
|
- |
List<AbstractTypeDeclaration> zTypes = (List<AbstractTypeDeclaration>) node.types(); |
63 |
|
- |
|
64 |
|
- |
if ((zTypes != null) && !zTypes.isEmpty()) { |
65 |
|
- |
System.out.println("Types: " + zTypes.size()); |
66 |
|
- |
for (AbstractTypeDeclaration zDeclaration : zTypes) { |
67 |
|
- |
if (!(zDeclaration instanceof TypeDeclaration)) { |
68 |
|
- |
System.out.println(" Not processing: " + ((zDeclaration == null) ? "null" : zDeclaration.getClass().getSimpleName())); |
69 |
|
- |
} else { |
70 |
|
- |
TypeDeclaration zType = (TypeDeclaration) zDeclaration; |
71 |
|
- |
MarkerAnnotation ma = null; // zType.toString(); |
72 |
|
- |
System.out.println( " extends: " + zType.getSuperclassType() ); |
73 |
|
- |
System.out.println( " impliments: " + zType.superInterfaceTypes() ); |
74 |
|
- |
} |
75 |
|
- |
} |
76 |
|
- |
} |
77 |
|
- |
|
78 |
|
- |
// IPackageDeclaration, IImportContainer, and IType, and appear in the order in which they are declared in the source. If a source file cannot be parsed, its structure remains unknown. Use IJavaElement.isStructureKnown() |
79 |
|
- |
} |
80 |
|
- |
} |
|
1 |
+ |
package org.litesoft.javaparser; |
|
2 |
+ |
|
|
3 |
+ |
import java.io.*; |
|
4 |
+ |
import org.litesoft.core.typeutils.Objects; |
|
5 |
+ |
import java.util.*; |
|
6 |
+ |
|
|
7 |
+ |
import org.eclipse.jdt.core.*; |
|
8 |
+ |
import org.eclipse.jdt.core.dom.*; |
|
9 |
+ |
|
|
10 |
+ |
public class MyMain |
|
11 |
+ |
{ |
|
12 |
+ |
|
|
13 |
+ |
public static void main(String[] args) throws Exception |
|
14 |
+ |
{ |
|
15 |
+ |
System.out.println("Main: " + Arrays.asList(args)); |
|
16 |
+ |
if (args.length < 1) |
|
17 |
+ |
{ |
|
18 |
+ |
System.err.println("At least one file needed..."); |
|
19 |
+ |
System.exit( 1 ); |
|
20 |
+ |
} |
|
21 |
+ |
|
|
22 |
+ |
File file = new File(args[0]); |
|
23 |
+ |
BufferedReader in = new BufferedReader(new FileReader(file)); |
|
24 |
+ |
StringBuffer buffer = new StringBuffer(); |
|
25 |
+ |
for (String line; null != (line = in.readLine());) { |
|
26 |
+ |
buffer.append(line).append("\n"); |
|
27 |
+ |
} |
|
28 |
+ |
String text = buffer.toString(); |
|
29 |
+ |
|
|
30 |
+ |
ASTParser parser = ASTParser.newParser(AST.JLS3); |
|
31 |
+ |
Map<String, String> options = new HashMap<String, String>(); |
|
32 |
+ |
String zVersion15 = JavaCore.VERSION_1_5; |
|
33 |
+ |
options.put(JavaCore.COMPILER_SOURCE, zVersion15); |
|
34 |
+ |
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, zVersion15); |
|
35 |
+ |
parser.setCompilerOptions(options); |
|
36 |
+ |
parser.setResolveBindings(false); |
|
37 |
+ |
parser.setKind(ASTParser.K_COMPILATION_UNIT); |
|
38 |
+ |
|
|
39 |
+ |
parser.setSource(text.toCharArray()); |
|
40 |
+ |
CompilationUnit node = (CompilationUnit) parser.createAST(null); |
|
41 |
+ |
PackageDeclaration zPackage = node.getPackage(); |
|
42 |
+ |
|
|
43 |
+ |
System.out.println("Package: " + zPackage.getName()); |
|
44 |
+ |
|
|
45 |
+ |
List<ImportDeclaration> zImports = (List<ImportDeclaration>) node.imports(); |
|
46 |
+ |
if ((zImports != null) && !zImports.isEmpty()) { |
|
47 |
+ |
System.out.println("Imports:"); |
|
48 |
+ |
for (ImportDeclaration zDeclaration : zImports) { |
|
49 |
+ |
System.out.print(" "); |
|
50 |
+ |
|
|
51 |
+ |
if (zDeclaration.isStatic()) { |
|
52 |
+ |
System.out.print("static "); |
|
53 |
+ |
} |
|
54 |
+ |
System.out.print(zDeclaration.getName()); |
|
55 |
+ |
if (zDeclaration.isOnDemand()) { |
|
56 |
+ |
System.out.print(".*"); |
|
57 |
+ |
} |
|
58 |
+ |
System.out.println(); |
|
59 |
+ |
} |
|
60 |
+ |
} |
|
61 |
+ |
|
|
62 |
+ |
List<AbstractTypeDeclaration> zTypes = (List<AbstractTypeDeclaration>) node.types(); |
|
63 |
+ |
|
|
64 |
+ |
if ((zTypes != null) && !zTypes.isEmpty()) { |
|
65 |
+ |
System.out.println("Types: " + zTypes.size()); |
|
66 |
+ |
for (AbstractTypeDeclaration zDeclaration : zTypes) { |
|
67 |
+ |
if (!(zDeclaration instanceof TypeDeclaration)) { |
|
68 |
+ |
System.out.println(" Not processing: " + ((zDeclaration == null) ? "null" : zDeclaration.getClass().getSimpleName())); |
|
69 |
+ |
} else { |
|
70 |
+ |
TypeDeclaration zType = (TypeDeclaration) zDeclaration; |
|
71 |
+ |
MarkerAnnotation ma = null; // zType.toString(); |
|
72 |
+ |
System.out.println( " extends: " + zType.getSuperclassType() ); |
|
73 |
+ |
System.out.println( " impliments: " + zType.superInterfaceTypes() ); |
|
74 |
+ |
} |
|
75 |
+ |
} |
|
76 |
+ |
} |
|
77 |
+ |
|
|
78 |
+ |
// IPackageDeclaration, IImportContainer, and IType, and appear in the order in which they are declared in the source. If a source file cannot be parsed, its structure remains unknown. Use IJavaElement.isStructureKnown() |
|
79 |
+ |
} |
|
80 |
+ |
} |