Source Code Cross Referenced for JDTCompiler.java in  » Code-Analyzer » Spoon » spoon » support » builder » 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 » Code Analyzer » Spoon » spoon.support.builder 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Spoon - http://spoon.gforge.inria.fr/
003:         * Copyright (C) 2006 INRIA Futurs <renaud.pawlak@inria.fr>
004:         * 
005:         * This software is governed by the CeCILL-C License under French law and
006:         * abiding by the rules of distribution of free software. You can use, modify 
007:         * and/or redistribute the software under the terms of the CeCILL-C license as 
008:         * circulated by CEA, CNRS and INRIA at http://www.cecill.info. 
009:         * 
010:         * This program is distributed in the hope that it will be useful, but WITHOUT 
011:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012:         * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
013:         *  
014:         * The fact that you are presently reading this means that you have had
015:         * knowledge of the CeCILL-C license and that you accept its terms.
016:         */
017:
018:        package spoon.support.builder;
019:
020:        import java.io.InputStream;
021:        import java.io.PrintWriter;
022:        import java.util.ArrayList;
023:        import java.util.List;
024:        import java.util.Map;
025:
026:        import org.eclipse.jdt.core.compiler.CategorizedProblem;
027:        import org.eclipse.jdt.internal.compiler.CompilationResult;
028:        import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
029:        import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
030:        import org.eclipse.jdt.internal.compiler.IProblemFactory;
031:        import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
032:        import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
033:        import org.eclipse.jdt.internal.compiler.batch.Main;
034:        import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
035:        import org.eclipse.jdt.internal.compiler.util.Util;
036:
037:        import spoon.reflect.Factory;
038:
039:        public class JDTCompiler extends Main implements  ICompilerRequestor {
040:
041:            class Compiler extends org.eclipse.jdt.internal.compiler.Compiler {
042:
043:                @SuppressWarnings("deprecation")
044:                public Compiler(INameEnvironment environment,
045:                        IErrorHandlingPolicy policy, Map<?, ?> settings,
046:                        ICompilerRequestor requestor,
047:                        IProblemFactory problemFactory, PrintWriter out,
048:                        boolean statementsRecovery) {
049:                    super (environment, policy, settings, requestor,
050:                            problemFactory, statementsRecovery);
051:                }
052:
053:                public CompilationUnitDeclaration[] compileUnits(
054:                        CompilationUnit[] sourceUnits) {
055:                    CompilationUnitDeclaration unit = null;
056:                    int i = 0;
057:                    // build and record parsed units
058:                    beginToCompile(sourceUnits);
059:                    // process all units (some more could be injected in the loop by
060:                    // the lookup environment)
061:                    for (; i < this .totalUnits; i++) {
062:                        unit = unitsToProcess[i];
063:                        this .parser.getMethodBodies(unit);
064:
065:                        // fault in fields & methods
066:                        if (unit.scope != null)
067:                            unit.scope.faultInTypes();
068:                        // verify inherited methods
069:                        if (unit.scope != null)
070:                            unit.scope.verifyMethods(lookupEnvironment
071:                                    .methodVerifier());
072:                        // type checking
073:                        unit.resolve();
074:                        // flow analysis
075:                        unit.analyseCode();
076:
077:                        requestor.acceptResult(unit.compilationResult
078:                                .tagAsAccepted());
079:                    }
080:                    return this .unitsToProcess;
081:                }
082:            }
083:
084:            public static int JAVA_COMPLIANCE = 5;
085:
086:            boolean success = true;
087:
088:            public boolean compileSrc(Factory f, List<CtFile> files)
089:                    throws Exception {
090:                if (files.isEmpty())
091:                    return true;
092:                //		long t=System.currentTimeMillis();
093:                // Build input
094:                List<String> args = new ArrayList<String>();
095:                args.add("-1." + JAVA_COMPLIANCE);
096:                args.add("-preserveAllLocals");
097:                args.add("-enableJavadoc");
098:                args.add("-noExit");
099:                // args.add("-nowarn");
100:                args.add(f.getEnvironment().getSourcePath());
101:
102:                //		JDTCompiler compiler = new JDTCompiler(new PrintWriter(System.out),
103:                //				new PrintWriter(System.err));
104:                configure(args.toArray(new String[0]));
105:                //		f.getEnvironment().debugMessage("compiling src: "+files);
106:                CompilationUnitDeclaration[] units = getUnits(files, f);
107:                //		f.getEnvironment().debugMessage("got units in "+(System.currentTimeMillis()-t)+" ms");
108:
109:                JDTTreeBuilder builder = new JDTTreeBuilder(f);
110:
111:                for (CompilationUnitDeclaration unit : units) {
112:                    try {
113:                        //				t=System.currentTimeMillis();
114:                        unit.traverse(builder, unit.scope);
115:                        //				f.getEnvironment().debugMessage("built unit "+new String(unit.getMainTypeName())+" in "+(System.currentTimeMillis()-t)+" ms");
116:                    } catch (Exception e) {
117:                        e.printStackTrace();
118:                    }
119:                }
120:                return success;
121:            }
122:
123:            public boolean compileTemplate(Factory f, List<CtFile> streams)
124:                    throws Exception {
125:                if (streams.isEmpty())
126:                    return true;
127:                // Build input
128:                List<String> args = new ArrayList<String>();
129:                args.add("-1." + JAVA_COMPLIANCE);
130:                args.add("-preserveAllLocals");
131:                args.add("-enableJavadoc");
132:                args.add("-noExit");
133:                args.add("-nowarn");
134:                args.add(".");
135:
136:                //		JDTCompiler compiler = new JDTCompiler(new PrintWriter(System.out),
137:                //				new PrintWriter(System.err));
138:                configure(args.toArray(new String[0]));
139:
140:                CompilationUnitDeclaration[] units = getUnits(streams, f);
141:
142:                JDTTreeBuilder builder = new JDTTreeBuilder(f);
143:                builder.template = true;
144:                for (CompilationUnitDeclaration unit : units) {
145:                    unit.traverse(builder, unit.scope);
146:                }
147:                return success;
148:            }
149:
150:            Compiler batchCompiler;
151:
152:            PrintWriter out;
153:
154:            public JDTCompiler(PrintWriter outWriter, PrintWriter errWriter) {
155:                super (outWriter, errWriter, false);
156:            }
157:
158:            public JDTCompiler() {
159:                super (new PrintWriter(System.out), new PrintWriter(System.err),
160:                        false);
161:            }
162:
163:            /*
164:             * Build the set of compilation source units
165:             */
166:            public CompilationUnit[] getCompilationUnits(List<CtFile> streams)
167:                    throws Exception {
168:                CompilationUnit[] units = new CompilationUnit[streams.size()];
169:                int i = 0;
170:                for (CtFile stream : streams) {
171:                    InputStream in = stream.getContent();
172:                    units[i] = new CompilationUnit(Util
173:                            .getInputStreamAsCharArray(in, -1, null), stream
174:                            .getPath(), null);
175:                    in.close();
176:                    i++;
177:                }
178:                return units;
179:            }
180:
181:            INameEnvironment environment = null;
182:
183:            public void setEnvironment(INameEnvironment environment) {
184:                this .environment = environment;
185:            }
186:
187:            public CompilationUnitDeclaration[] getUnits(List<CtFile> streams,
188:                    Factory f) throws Exception {
189:                this .startTime = System.currentTimeMillis();
190:                INameEnvironment environment = this .environment;
191:                if (environment == null)
192:                    environment = getLibraryAccess();
193:                this .batchCompiler = new Compiler(environment,
194:                        getHandlingPolicy(), this .options, this ,
195:                        getProblemFactory(), this .out, false);
196:                return batchCompiler.compileUnits(getCompilationUnits(streams));
197:            }
198:
199:            List<CategorizedProblem[]> probs;
200:
201:            public List<CategorizedProblem[]> getProbs() {
202:                if (probs == null) {
203:                    probs = new ArrayList<CategorizedProblem[]>();
204:
205:                }
206:                return probs;
207:            }
208:
209:            public void acceptResult(CompilationResult result) {
210:                if (result.hasErrors()) {
211:                    System.err.println(result);
212:                    getProbs().add(result.problems);
213:                    success = false;
214:                }
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.