]>
Commit | Line | Data |
---|---|---|
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 | *******************************************************************************/ | |
11 | package org.eclipse.jdt.internal.corext.refactoring.binary; | |
12 | ||
13 | import java.net.URI; | |
14 | import java.util.List; | |
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.IPackageFragment; | |
24 | import org.eclipse.jdt.core.IType; | |
25 | ||
26 | import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; | |
27 | import org.eclipse.jdt.internal.corext.util.JavaModelUtil; | |
28 | ||
29 | /** | |
30 | * Operation, which run, creates structurally equivalent stub types for a list | |
31 | * of binary package fragments. | |
32 | * | |
33 | * @since 3.2 | |
34 | */ | |
35 | public class StubCreationOperation extends AbstractCodeCreationOperation { | |
36 | ||
37 | /** Should stubs for private member be generated as well? */ | |
38 | protected final boolean fStubInvisible; | |
39 | ||
40 | /** | |
41 | * Creates a new stub creation operation. | |
42 | * | |
43 | * @param uri | |
44 | * the URI where to output the stubs | |
45 | * @param packages | |
46 | * the list of packages to create stubs for | |
47 | */ | |
48 | public StubCreationOperation(final URI uri, final List<IPackageFragment> packages) { | |
49 | this(uri, packages, false); | |
50 | } | |
51 | ||
52 | /** | |
53 | * Creates a new stub creation operation. | |
54 | * | |
55 | * @param uri | |
56 | * the URI where to output the stubs | |
57 | * @param packages | |
58 | * the list of packages to create stubs for | |
59 | * @param stub | |
60 | * <code>true</code> to generate stubs for private and package | |
61 | * visible members as well, <code>false</code> otherwise | |
62 | */ | |
63 | public StubCreationOperation(final URI uri, final List<IPackageFragment> packages, final boolean stub) { | |
64 | super(uri, packages); | |
65 | fStubInvisible= stub; | |
66 | } | |
67 | ||
68 | /** | |
69 | * {@inheritDoc} | |
70 | */ | |
71 | @Override | |
72 | protected String getOperationLabel() { | |
73 | return RefactoringCoreMessages.StubCreationOperation_creating_type_stubs; | |
74 | } | |
75 | ||
76 | /** | |
77 | * Runs the stub generation on the specified class file. | |
78 | * | |
79 | * @param file | |
80 | * the class file | |
81 | * @param parent | |
82 | * the parent store | |
83 | * @param monitor | |
84 | * the progress monitor to use | |
85 | * @throws CoreException | |
86 | * if an error occurs | |
87 | */ | |
88 | @Override | |
89 | protected void run(final IClassFile file, final IFileStore parent, final IProgressMonitor monitor) throws CoreException { | |
90 | try { | |
91 | monitor.beginTask(RefactoringCoreMessages.StubCreationOperation_creating_type_stubs, 2); | |
92 | SubProgressMonitor subProgressMonitor= new SubProgressMonitor(monitor, 1); | |
93 | final IType type= file.getType(); | |
94 | if (type.isAnonymous() || type.isLocal() || type.isMember()) | |
95 | return; | |
96 | String source= new StubCreator(fStubInvisible).createStub(type, subProgressMonitor); | |
97 | createCompilationUnit(parent, type.getElementName() + JavaModelUtil.DEFAULT_CU_SUFFIX, source, monitor); | |
98 | } finally { | |
99 | monitor.done(); | |
100 | } | |
101 | } | |
102 | } |