KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > env > EnvironmentFactory


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * mkaufman@bea.com - initial API and implementation
10  *
11  *******************************************************************************/

12
13 package org.eclipse.jdt.apt.core.env;
14
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv;
17 import org.eclipse.jdt.core.ICompilationUnit;
18 import org.eclipse.jdt.core.IJavaProject;
19 import org.eclipse.jdt.core.dom.CompilationUnit;
20
21 import com.sun.mirror.apt.AnnotationProcessorEnvironment;
22
23 public class EnvironmentFactory {
24
25     /**
26      * Return a processor environment for use outside of building or reconciling.
27      * Note that this environment does <b>NOT</b> support the Filer or Messager API,
28      * as it is to be used to perform type system navigation, not building.<p>
29      *
30      * If either getFiler() or getMessager() are called, this environment
31      * will throw an UnsupportedOperationException.
32      *
33      * @param compilationUnit the working copy for which the Environment object is to be created
34      * @param javaProject the java project that the working copy is in.
35      * @return the created environment.
36      */

37     public static AnnotationProcessorEnvironment getEnvironment(ICompilationUnit compilationUnit, IJavaProject javaProject )
38     {
39         CompilationUnit node = BaseProcessorEnv.createAST( javaProject, compilationUnit);
40         BaseProcessorEnv env = new BaseProcessorEnv(
41                 node,
42                 (IFile)compilationUnit.getResource(),
43                 javaProject,
44                 Phase.OTHER
45                 );
46         return env;
47     }
48 }
49
Popular Tags