KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > util > WorkingCopyUtil


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.util;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14
15 import org.eclipse.jdt.core.ICompilationUnit;
16 import org.eclipse.jdt.core.IJavaElement;
17 import org.eclipse.jdt.core.IMember;
18 import org.eclipse.jdt.core.IPackageFragment;
19 import org.eclipse.jdt.core.JavaModelException;
20 import org.eclipse.jdt.core.WorkingCopyOwner;
21
22
23 public class WorkingCopyUtil {
24
25     //no instances
26
private WorkingCopyUtil(){
27     }
28     
29     /**
30      * @deprecated Inline this method.
31      */

32     public static IJavaElement getWorkingCopyIfExists(IJavaElement element) {
33         return element;
34     }
35     
36     /**
37      * @deprecated Inline this method.
38      */

39     public static ICompilationUnit getWorkingCopyIfExists(ICompilationUnit element) {
40         return element;
41     }
42     
43     /**
44      * @deprecated Inline this method.
45      */

46     public static IMember getWorkingCopyIfExists(IMember member) {
47         return member;
48     }
49     
50     public static IJavaElement getOriginal(IMember member){
51         return JavaModelUtil.toOriginal(member);
52     }
53
54     public static ICompilationUnit getOriginal(ICompilationUnit cu){
55         return JavaModelUtil.toOriginal(cu);
56     }
57     
58     public static IMember[] getOriginals(IMember[] members){
59         IMember[] result= new IMember[members.length];
60         for (int i= 0; i < members.length; i++) {
61             result[i]= (IMember)WorkingCopyUtil.getOriginal(members[i]);
62         }
63         return result;
64     }
65
66     /**
67      * Creates a <em>new</em> working copy and the caller is responsible for destroying it.
68      * @see org.eclipse.jdt.core.ICompilationUnit#discardWorkingCopy()
69      */

70     public static ICompilationUnit getNewWorkingCopy(ICompilationUnit cu) throws JavaModelException{
71         /*
72          * Explicitly create a new working copy.
73          */

74         return getOriginal(cu).getWorkingCopy(null);
75     }
76
77     /**
78      * Creates a <em>new</em> working copy and the caller is responsible for destroying it.
79      * @see org.eclipse.jdt.core.ICompilationUnit#discardWorkingCopy()
80      */

81     public static ICompilationUnit getNewWorkingCopy(ICompilationUnit cu, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException{
82         /*
83          * Explicitly create a new working copy.
84          */

85         return getOriginal(cu).getWorkingCopy(owner, null, pm);
86     }
87
88     /**
89      * Creates a <em>new</em> working copy and the caller is responsible for destroying it.
90      * A cu with the specified name may or may not exist in the package.
91      * @see org.eclipse.jdt.core.ICompilationUnit#discardWorkingCopy()
92      */

93     public static ICompilationUnit getNewWorkingCopy(IPackageFragment pack, String JavaDoc cuName) throws JavaModelException{
94         return pack.getCompilationUnit(cuName).getWorkingCopy(null);
95     }
96
97     /**
98      * Creates a <em>new</em> working copy and the caller is responsible for destroying it.
99      * A cu with the specified name may or may not exist in the package.
100      * @see org.eclipse.jdt.core.ICompilationUnit#discardWorkingCopy()
101      */

102     public static ICompilationUnit getNewWorkingCopy(IPackageFragment pack, String JavaDoc cuName, WorkingCopyOwner owner, IProgressMonitor pm) throws JavaModelException{
103         return pack.getCompilationUnit(cuName).getWorkingCopy(owner, null, pm);
104     }
105 }
106
107
Popular Tags