KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > binary > StubCreationOperation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.binary;
12
13 import java.net.URI JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.filesystem.IFileStore;
17
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.SubProgressMonitor;
21
22 import org.eclipse.jdt.core.IClassFile;
23 import org.eclipse.jdt.core.IType;
24
25 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
26
27 /**
28  * Operation, which run, creates structurally equivalent stub types for a list
29  * of binary package fragments.
30  *
31  * @since 3.2
32  */

33 public class StubCreationOperation extends AbstractCodeCreationOperation {
34
35     /** Should stubs for private member be generated as well? */
36     protected final boolean fStubInvisible;
37
38     /**
39      * Creates a new stub creation operation.
40      *
41      * @param uri
42      * the URI where to output the stubs
43      * @param packages
44      * the list of packages to create stubs for
45      */

46     public StubCreationOperation(final URI JavaDoc uri, final List JavaDoc packages) {
47         this(uri, packages, false);
48     }
49
50     /**
51      * Creates a new stub creation operation.
52      *
53      * @param uri
54      * the URI where to output the stubs
55      * @param packages
56      * the list of packages to create stubs for
57      * @param stub
58      * <code>true</code> to generate stubs for private and package
59      * visible members as well, <code>false</code> otherwise
60      */

61     public StubCreationOperation(final URI JavaDoc uri, final List JavaDoc packages, final boolean stub) {
62         super(uri, packages);
63         fStubInvisible= stub;
64     }
65
66     /**
67      * {@inheritDoc}
68      */

69     protected String JavaDoc getOperationLabel() {
70         return RefactoringCoreMessages.StubCreationOperation_creating_type_stubs;
71     }
72
73     /**
74      * Runs the stub generation on the specified class file.
75      *
76      * @param file
77      * the class file
78      * @param parent
79      * the parent store
80      * @param monitor
81      * the progress monitor to use
82      * @throws CoreException
83      * if an error occurs
84      */

85     protected void run(final IClassFile file, final IFileStore parent, final IProgressMonitor monitor) throws CoreException {
86         try {
87             monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 2);
88             SubProgressMonitor subProgressMonitor= new SubProgressMonitor(monitor, 1);
89             final IType type= file.getType();
90             if (type.isAnonymous() || type.isLocal() || type.isMember())
91                 return;
92             String JavaDoc source= new StubCreator(fStubInvisible).createStub(type, subProgressMonitor);
93             createCompilationUnit(parent, type.getElementName() + ".java", source, monitor); //$NON-NLS-1$
94
} finally {
95             monitor.done();
96         }
97     }
98 }
99
Popular Tags