KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > typeconstraints > ASTCreator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.refactoring.typeconstraints;
12
13 import org.eclipse.jdt.core.ICompilationUnit;
14 import org.eclipse.jdt.core.WorkingCopyOwner;
15 import org.eclipse.jdt.core.dom.AST;
16 import org.eclipse.jdt.core.dom.ASTNode;
17 import org.eclipse.jdt.core.dom.ASTParser;
18 import org.eclipse.jdt.core.dom.CompilationUnit;
19
20 import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser;
21
22
23 public class ASTCreator {
24
25     public static final String JavaDoc CU_PROPERTY= "org.eclipse.jdt.ui.refactoring.cu"; //$NON-NLS-1$
26

27     private ASTCreator() {
28         //private
29
}
30     
31     public static CompilationUnit createAST(ICompilationUnit cu, WorkingCopyOwner workingCopyOwner) {
32         CompilationUnit cuNode= getCuNode(workingCopyOwner, cu);
33         cuNode.setProperty(CU_PROPERTY, cu);
34         return cuNode;
35     }
36
37     private static CompilationUnit getCuNode(WorkingCopyOwner workingCopyOwner, ICompilationUnit cu) {
38         ASTParser p = ASTParser.newParser(AST.JLS3);
39         p.setSource(cu);
40         p.setResolveBindings(true);
41         p.setWorkingCopyOwner(workingCopyOwner);
42         p.setCompilerOptions(RefactoringASTParser.getCompilerOptions(cu));
43         return (CompilationUnit) p.createAST(null);
44     }
45
46     public static ICompilationUnit getCu(ASTNode node) {
47         Object JavaDoc property= node.getRoot().getProperty(CU_PROPERTY);
48         if (property instanceof ICompilationUnit)
49             return (ICompilationUnit)property;
50         return null;
51     }
52 }
53
Popular Tags