Source Code Cross Referenced for ClassExplorer.java in  » IDE-Netbeans » mobility » org » netbeans » modules » e2e » wsdl » wsdl2java » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » mobility » org.netbeans.modules.e2e.wsdl.wsdl2java 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Main.java
003:         *
004:         * Created on 28-Aug-2007, 12:11:26
005:         *
006:         * To change this template, choose Tools | Templates
007:         * and open the template in the editor.
008:         */
009:
010:        package org.netbeans.modules.e2e.wsdl.wsdl2java;
011:
012:        import com.sun.source.tree.CompilationUnitTree;
013:        import com.sun.source.tree.Tree;
014:        import com.sun.source.util.TreePath;
015:        import com.sun.source.util.Trees;
016:        import java.io.File;
017:        import java.util.ArrayList;
018:        import java.util.Collections;
019:        import java.util.HashMap;
020:        import java.util.HashSet;
021:        import java.util.List;
022:        import java.util.Set;
023:        import java.util.concurrent.Future;
024:        import java.util.logging.Level;
025:        import java.util.logging.Logger;
026:        import javax.lang.model.element.Element;
027:        import javax.lang.model.element.ElementKind;
028:        import javax.lang.model.element.ExecutableElement;
029:        import javax.lang.model.element.TypeElement;
030:        import javax.lang.model.element.VariableElement;
031:        import javax.lang.model.type.TypeMirror;
032:        import org.netbeans.api.java.source.CancellableTask;
033:        import org.netbeans.api.java.source.CompilationController;
034:        import org.netbeans.api.java.source.ElementHandle;
035:        import org.netbeans.api.java.source.JavaSource;
036:        import org.netbeans.api.java.source.JavaSource.Phase;
037:        import org.openide.filesystems.FileObject;
038:        import org.openide.filesystems.FileUtil;
039:
040:        /**
041:         *
042:         * @author luky
043:         */
044:        public class ClassExplorer {
045:            static {
046:                System.setProperty("netbeans.user",
047:                        "C:\\Documents and Settings\\luky\\.netbeans\\dev");
048:            }
049:
050:            private CompilationUnitTree compilationUnit;
051:            private Trees trees;
052:            private boolean initialized = false;
053:
054:            private class ClassFinderTask implements 
055:                    CancellableTask<CompilationController> {
056:
057:                private volatile boolean cancelled;
058:                private HashMap<ElementHandle<TypeElement>, List<ExecutableElement>> topClassMap = new HashMap<ElementHandle<TypeElement>, List<ExecutableElement>>();
059:
060:                public void cancel() {
061:                    this .cancelled = true;
062:                }
063:
064:                public void run(CompilationController parameter)
065:                        throws Exception {
066:                    if (!initialized) {
067:                        parameter.toPhase(Phase.ELEMENTS_RESOLVED);
068:                        if (cancelled) {
069:                            return;
070:                        }
071:                        ClassExplorer.this .compilationUnit = parameter
072:                                .getCompilationUnit();
073:                        ClassExplorer.this .trees = parameter.getTrees();
074:                        initialized = true;
075:                    }
076:                }
077:            }
078:
079:            public ClassExplorer(FileObject fobj) {
080:                try {
081:                    JavaSource javaSource = JavaSource.forFileObject(fobj);
082:                    ClassFinderTask task = new ClassFinderTask();
083:                    Future fin = javaSource.runWhenScanFinished(task, true);
084:                    //Wait till task is finished
085:                    fin.get();
086:                } catch (Exception ex) {
087:                    Logger.getLogger(ClassExplorer.class.getName()).log(
088:                            Level.SEVERE, null, ex);
089:                }
090:            }
091:
092:            public List<TypeElement> getClasses() {
093:                List<TypeElement> result = new ArrayList<TypeElement>();
094:                if (initialized) {
095:                    List<? extends Tree> typeDecls = compilationUnit
096:                            .getTypeDecls();
097:                    if ((typeDecls == null) || typeDecls.isEmpty()) {
098:                        return Collections.<TypeElement> emptyList();
099:                    }
100:
101:                    TreePath tPath = new TreePath(compilationUnit);
102:                    for (Tree typeDecl : typeDecls) {
103:                        if (typeDecl.getKind() == Tree.Kind.CLASS) {
104:                            TypeElement elem = (TypeElement) trees
105:                                    .getElement(new TreePath(tPath, typeDecl));
106:                            result.add(elem);
107:                        }
108:                    }
109:                }
110:                return result;
111:            }
112:
113:            public List<ExecutableElement> getMethods(TypeElement elem) {
114:                List<? extends Element> elems = elem.getEnclosedElements();
115:                List<ExecutableElement> exElems = new ArrayList<ExecutableElement>(
116:                        elems.size());
117:                for (Element el : elems) {
118:                    if (el.getKind().equals(ElementKind.METHOD)
119:                            || el.getKind().equals(ElementKind.CONSTRUCTOR)) {
120:                        exElems.add((ExecutableElement) el);
121:                    }
122:                }
123:                return exElems;
124:            }
125:
126:            public TypeMirror getReturnType(ExecutableElement elem) {
127:                return elem.getReturnType();
128:            }
129:
130:            public List<TypeMirror> getParameters(ExecutableElement elem) {
131:                List<? extends VariableElement> varElems = elem.getParameters();
132:                List<TypeMirror> paramList = new ArrayList<TypeMirror>(varElems
133:                        .size());
134:                for (VariableElement vElem : varElems) {
135:                    paramList.add(vElem.asType());
136:                }
137:                return paramList;
138:            }
139:
140:            public boolean compareClasses(Set<String> classes,
141:                    List<TypeElement> classElems) {
142:                if (classes.size() == classElems.size()) {
143:                    HashSet<String> set = new HashSet<String>();
144:                    for (TypeElement elem : classElems) {
145:                        set.add(elem.getQualifiedName().toString());
146:                    }
147:                    for (String className : classes) {
148:                        if (!set.contains(className)) {
149:                            System.err.println("Class: " + className
150:                                    + " not found in generated file");
151:                            break;
152:                        }
153:                    }
154:                    return true;
155:                }
156:                return false;
157:            }
158:
159:            public boolean compareMethods(Set<String> methods,
160:                    List<ExecutableElement> methodElems) {
161:                if (methods.size() == methodElems.size()) {
162:                    HashSet<String> set = new HashSet<String>();
163:                    for (ExecutableElement elem : methodElems) {
164:                        set.add(elem.getSimpleName().toString());
165:                    }
166:                    for (String methodName : methods) {
167:                        if (!set.contains(methodName)) {
168:                            System.err.println("Method: " + methodName
169:                                    + " not found in generated file");
170:                            break;
171:                        }
172:                    }
173:                    return true;
174:                }
175:                return false;
176:            }
177:
178:            public boolean compareParameters(Set<String> params,
179:                    List<TypeMirror> variableElems) {
180:                if (params.size() == variableElems.size()) {
181:                    HashSet<String> set = new HashSet<String>();
182:                    for (TypeMirror elem : variableElems) {
183:                        set.add(elem.toString());
184:                    }
185:                    for (String variableType : params) {
186:                        if (!set.contains(variableType.toString())) {
187:                            System.err.println("Parameter: " + variableType
188:                                    + " not found in generated file");
189:                            break;
190:                        }
191:                    }
192:                    return true;
193:                }
194:                return false;
195:            }
196:
197:            /**
198:             * @param args the command line arguments
199:             */
200:            public static void main(String[] args) {
201:                // TODO code application logic here
202:                ClassExplorer expl = new ClassExplorer(FileUtil
203:                        .toFileObject(new File("C:\\test.java")));
204:                List<TypeElement> tel = expl.getClasses();
205:                for (TypeElement te : tel) {
206:                    System.out.println(te.toString());
207:                    List<ExecutableElement> mel = expl.getMethods(te);
208:                    for (ExecutableElement me : mel) {
209:                        System.out
210:                                .println("\t" + me.getSimpleName().toString());
211:                        List<TypeMirror> vel = expl.getParameters(me);
212:                        for (TypeMirror var : vel) {
213:                            System.out.println("\t\t" + var.toString());
214:                        }
215:                        System.out.println("\t\treturns:"
216:                                + me.getReturnType().toString());
217:                    }
218:                }
219:                System.exit(-1);
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.