KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > structure > ImportRewriteManager


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.structure;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17
18 import org.eclipse.jdt.core.ICompilationUnit;
19 import org.eclipse.jdt.core.IType;
20 import org.eclipse.jdt.core.JavaModelException;
21
22 import org.eclipse.jdt.internal.corext.codemanipulation.ImportRewrite;
23 import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
24
25 class ImportRewriteManager {
26
27     private final Map JavaDoc fImportRewrites; //ICompilationUnit -> ImportEdit
28

29     public ImportRewriteManager() {
30         fImportRewrites= new HashMap JavaDoc();
31     }
32
33     public boolean hasImportEditFor(ICompilationUnit cu) throws JavaModelException {
34         return fImportRewrites.containsKey(cu);
35     }
36
37     public ImportRewrite getImportRewrite(ICompilationUnit cu) throws CoreException {
38         if (hasImportEditFor(cu))
39             return (ImportRewrite)fImportRewrites.get(cu);
40
41         ImportRewrite edit= new ImportRewrite(cu);
42         fImportRewrites.put(cu, edit);
43         return edit;
44     }
45
46     public void addImportTo(String JavaDoc fullyQualifiedName, ICompilationUnit cu) throws CoreException {
47         getImportRewrite(cu).addImport(fullyQualifiedName);
48     }
49
50     public void addImportTo(IType type, ICompilationUnit cu) throws CoreException {
51         addImportTo(JavaModelUtil.getFullyQualifiedName(type), cu);
52     }
53
54     public void removeImportTo(IType type, ICompilationUnit cu) throws CoreException {
55         removeImportTo(JavaModelUtil.getFullyQualifiedName(type), cu);
56     }
57
58     public void removeImportTo(String JavaDoc fullyQualifiedName, ICompilationUnit cu) throws CoreException {
59         getImportRewrite(cu).removeImport(fullyQualifiedName);
60     }
61
62     public void clear() {
63         fImportRewrites.clear();
64     }
65 }
66
Popular Tags