Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package org.litesoft.javaparser;

import java.io.*;
import org.litesoft.core.typeutils.Objects;
import java.util.*;

import org.eclipse.jdt.core.*;
import org.eclipse.jdt.core.dom.*;

public class MyMain
{

    public static void main(String[] args) throws Exception
    {
        System.out.println("Main: " + Arrays.asList(args));
        if (args.length < 1)
        {
            System.err.println("At least one file needed...");
            System.exit( 1 );
        }

        File file = new File(args[0]);
        BufferedReader in = new BufferedReader(new FileReader(file));
        StringBuffer buffer = new StringBuffer();
        for (String line; null != (line = in.readLine());) {
            buffer.append(line).append("\n");
        }
        String text = buffer.toString();

        ASTParser parser = ASTParser.newParser(AST.JLS3);
        Map<String, String> options = new HashMap<String, String>();
        String zVersion15 = JavaCore.VERSION_1_5;
        options.put(JavaCore.COMPILER_SOURCE, zVersion15);
        options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, zVersion15);
        parser.setCompilerOptions(options);
        parser.setResolveBindings(false);
        parser.setKind(ASTParser.K_COMPILATION_UNIT);

        parser.setSource(text.toCharArray());
        CompilationUnit node = (CompilationUnit) parser.createAST(null);
        PackageDeclaration zPackage = node.getPackage();

        System.out.println("Package: " + zPackage.getName());

        List<ImportDeclaration> zImports = (List<ImportDeclaration>) node.imports();
        if ((zImports != null) && !zImports.isEmpty()) {
            System.out.println("Imports:");
            for (ImportDeclaration zDeclaration : zImports) {
                System.out.print("    ");

                if (zDeclaration.isStatic()) {
                    System.out.print("static ");
                }
                System.out.print(zDeclaration.getName());
                if (zDeclaration.isOnDemand()) {
                    System.out.print(".*");
                }
                System.out.println();
            }
        }

        List<AbstractTypeDeclaration> zTypes = (List<AbstractTypeDeclaration>) node.types();

        if ((zTypes != null) && !zTypes.isEmpty()) {
            System.out.println("Types: " + zTypes.size());
            for (AbstractTypeDeclaration zDeclaration : zTypes) {
                if (!(zDeclaration instanceof TypeDeclaration)) {
                    System.out.println("    Not processing: " + ((zDeclaration == null) ? "null" : zDeclaration.getClass().getSimpleName()));
                } else {
                    TypeDeclaration zType = (TypeDeclaration) zDeclaration;
                    MarkerAnnotation ma = null; // zType.toString();
                    System.out.println( " extends: " + zType.getSuperclassType() );
                    System.out.println( " impliments: " + zType.superInterfaceTypes() );
                }
            }
        }

        // 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()
    }
}

Commits for litesoft/trunk/Java/JavaAST/src/org/litesoft/javaparser/MyMain.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

86 GeorgeS picture GeorgeS Wed 09 Feb, 2011 20:50:03 +0000