KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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
21 import org.eclipse.jdt.core.IClassFile;
22 import org.eclipse.jdt.core.IType;
23
24 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
25
26 /**
27  * Operation, which run, creates source code for a list of binary package
28  * fragments with attached source.
29  *
30  * @since 3.2
31  */

32 public class SourceCreationOperation extends AbstractCodeCreationOperation {
33
34     /**
35      * Creates a new source creation operation.
36      *
37      * @param uri
38      * the URI where to output the source
39      * @param packages
40      * the list of packages to create source for
41      */

42     public SourceCreationOperation(final URI JavaDoc uri, final List JavaDoc packages) {
43         super(uri, packages);
44     }
45
46     /**
47      * Returns the operation label.
48      *
49      * @return the operation label
50      */

51     protected String JavaDoc getOperationLabel() {
52         return RefactoringCoreMessages.SourceCreationOperation_creating_source_folder;
53     }
54
55     /**
56      * Runs the stub generation on the specified class file.
57      *
58      * @param file
59      * the class file
60      * @param parent
61      * the parent store
62      * @param monitor
63      * the progress monitor to use
64      * @throws CoreException
65      * if an error occurs
66      */

67     protected void run(final IClassFile file, final IFileStore parent, final IProgressMonitor monitor) throws CoreException {
68         try {
69             monitor.beginTask(getOperationLabel(), 2);
70             final IType type= file.getType();
71             if (type.isAnonymous() || type.isLocal() || type.isMember())
72                 return;
73             final String JavaDoc source= file.getSource();
74             createCompilationUnit(parent, type.getElementName() + ".java", source != null ? source : "", monitor); //$NON-NLS-1$ //$NON-NLS-2$
75
} finally {
76             monitor.done();
77         }
78     }
79 }
Popular Tags