Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 807cc1001acf1915f45f3a65713a0c024a3cc923 (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2005, 2018 BEA Systems, Inc. and others 
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *    mkaufman@bea.com - initial API and implementation
 *    
 *******************************************************************************/

package org.eclipse.jdt.apt.core.env;

import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.apt.core.internal.env.BaseProcessorEnv;
import org.eclipse.jdt.apt.core.internal.util.TestCodeUtil;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.dom.CompilationUnit;

import com.sun.mirror.apt.AnnotationProcessorEnvironment;

public class EnvironmentFactory {

	/**
	 * Return a processor environment for use outside of building or reconciling.
	 * Note that this environment does <b>NOT</b> support the Filer or Messager API,
	 * as it is to be used to perform type system navigation, not building.<p>
	 * 
	 * If either getFiler() or getMessager() are called, this environment
	 * will throw an UnsupportedOperationException.
	 * 
	 * @param compilationUnit the working copy for which the Environment object is to be created
	 * @param javaProject the java project that the working copy is in. 
	 * @return the created environment.
	 */
	public static AnnotationProcessorEnvironment getEnvironment(ICompilationUnit compilationUnit, IJavaProject javaProject )
	{	
		CompilationUnit node = BaseProcessorEnv.createAST( javaProject, compilationUnit);
       	BaseProcessorEnv env = new BaseProcessorEnv(
       			node,
       			(IFile)compilationUnit.getResource(),
       			javaProject,
       			Phase.OTHER,
       			TestCodeUtil.isTestCode(compilationUnit)
       			);
       	return env;
	}
}

Back to the top