1 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 CU_PROPERTY= "org.eclipse.jdt.ui.refactoring.cu"; 27 private ASTCreator() { 28 } 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 property= node.getRoot().getProperty(CU_PROPERTY); 48 if (property instanceof ICompilationUnit) 49 return (ICompilationUnit)property; 50 return null; 51 } 52 } 53 | Popular Tags |