]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/core refactoring/org/eclipse/jdt/internal/corext/refactoring/typeconstraints/ASTCreator.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / core refactoring / org / eclipse / jdt / internal / corext / refactoring / typeconstraints / ASTCreator.java
CommitLineData
1b2798f6
EK
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
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.corext.refactoring.typeconstraints;
12
13import org.eclipse.jdt.core.ICompilationUnit;
14import org.eclipse.jdt.core.WorkingCopyOwner;
15import org.eclipse.jdt.core.dom.ASTNode;
16import org.eclipse.jdt.core.dom.ASTParser;
17import org.eclipse.jdt.core.dom.CompilationUnit;
18
19import org.eclipse.jdt.internal.corext.refactoring.util.RefactoringASTParser;
20
21import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;
22
23
24public class ASTCreator {
25
26 public static final String CU_PROPERTY= "org.eclipse.jdt.ui.refactoring.cu"; //$NON-NLS-1$
27
28 private ASTCreator() {
29 //private
30 }
31
32 public static CompilationUnit createAST(ICompilationUnit cu, WorkingCopyOwner workingCopyOwner) {
33 CompilationUnit cuNode= getCuNode(workingCopyOwner, cu);
34 cuNode.setProperty(CU_PROPERTY, cu);
35 return cuNode;
36 }
37
38 private static CompilationUnit getCuNode(WorkingCopyOwner workingCopyOwner, ICompilationUnit cu) {
39 ASTParser p = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
40 p.setSource(cu);
41 p.setResolveBindings(true);
42 p.setWorkingCopyOwner(workingCopyOwner);
43 p.setCompilerOptions(RefactoringASTParser.getCompilerOptions(cu));
44 return (CompilationUnit) p.createAST(null);
45 }
46
47 public static ICompilationUnit getCu(ASTNode node) {
48 Object property= node.getRoot().getProperty(CU_PROPERTY);
49 if (property instanceof ICompilationUnit)
50 return (ICompilationUnit)property;
51 return null;
52 }
53}