X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/EditorUtility.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/EditorUtility.java index b874f4f..b951472 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/EditorUtility.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/EditorUtility.java @@ -14,14 +14,17 @@ package net.sourceforge.phpeclipse.phpeditor; import net.sourceforge.phpdt.core.ICompilationUnit; import net.sourceforge.phpdt.core.IJavaElement; +import net.sourceforge.phpdt.core.IJavaProject; import net.sourceforge.phpdt.core.IMember; import net.sourceforge.phpdt.core.IWorkingCopy; +import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil; import net.sourceforge.phpdt.ui.JavaUI; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.jface.action.Action; import org.eclipse.swt.SWT; @@ -67,7 +70,7 @@ public class EditorUtility { IEditorInput input= null; try { - input= getEditorInput(inputElement); + input = getEditorInput(inputElement); } catch (JavaModelException x) { PHPeclipsePlugin.log(x.getStatus()); } @@ -365,4 +368,29 @@ public class EditorUtility { return newModifierString; return PHPEditorMessages.getFormattedString("EditorUtility.concatModifierStrings", new String[] {modifierString, newModifierString}); //$NON-NLS-1$ } + + /** + * Returns the Java project for a given editor input or null if no corresponding + * Java project exists. + * + * @param input the editor input + * @return the corresponding Java project + * + * @since 3.0 + */ + public static IJavaProject getJavaProject(IEditorInput input) { + IJavaProject jProject= null; + if (input instanceof IFileEditorInput) { + IProject project= ((IFileEditorInput)input).getFile().getProject(); + if (project != null) { + jProject= JavaCore.create(project); + if (!jProject.exists()) + jProject= null; + } + } +// else if (input instanceof IClassFileEditorInput) { +// jProject= ((IClassFileEditorInput)input).getClassFile().getJavaProject(); +// } + return jProject; + } }