1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints;
13 import org.eclipse.jdt.core.ICompilationUnit;
14 import org.eclipse.jdt.core.WorkingCopyOwner;
15 import org.eclipse.jdt.core.dom.ASTNode;
16 import org.eclipse.jdt.core.dom.ASTParser;
17 import org.eclipse.jdt.core.dom.CompilationUnit;
19 import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser;
21 import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;
24 public class ASTCreator {
26 public static final String CU_PROPERTY= "org.eclipse.jdt.ui.refactoring.cu"; //$NON-NLS-1$
28 private ASTCreator() {
32 public static CompilationUnit createAST(ICompilationUnit cu, WorkingCopyOwner workingCopyOwner) {
33 CompilationUnit cuNode= getCuNode(workingCopyOwner, cu);
34 cuNode.setProperty(CU_PROPERTY, cu);
38 private static CompilationUnit getCuNode(WorkingCopyOwner workingCopyOwner, ICompilationUnit cu) {
39 ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
41 p.setResolveBindings(true);
42 p.setWorkingCopyOwner(workingCopyOwner);
43 p.setCompilerOptions(RefactoringASTParser.getCompilerOptions(cu));
44 return (CompilationUnit) p.createAST(null);
47 public static ICompilationUnit getCu(ASTNode node) {
48 Object property= node.getRoot().getProperty(CU_PROPERTY);
49 if (property instanceof ICompilationUnit)
50 return (ICompilationUnit)property;