Package de.loskutov.anyedit.util
Class EclipseUtils
- java.lang.Object
-
- de.loskutov.anyedit.util.EclipseUtils
-
public final class EclipseUtils extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
EclipseUtils.DummyContainer
(package private) static class
EclipseUtils.MyOpenResourceDialog
-
Constructor Summary
Constructors Modifier Constructor Description private
EclipseUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
disconnectBuffer(org.eclipse.core.filebuffers.ITextFileBuffer buffer)
private static java.util.List<org.eclipse.core.resources.IFile>
filterNonExistentFiles(org.eclipse.core.resources.IFile[] files)
private static org.eclipse.core.resources.IFile
findAbsoluteFile(java.lang.String selectedText)
private static org.eclipse.core.resources.IFile
findInProject(java.lang.String currentPath, org.eclipse.core.resources.IContainer project, java.lang.String selectedText, java.util.List<org.eclipse.core.resources.IResource> resultList)
private static org.eclipse.core.resources.IFile
findInProjects(org.eclipse.core.resources.IProject[] projects, java.lang.String currentPath, java.lang.String selectedText, java.util.List<org.eclipse.core.resources.IProject> checkedProjects, java.util.List<org.eclipse.core.resources.IResource> resultList)
static org.eclipse.ui.IEditorPart
getActiveEditor()
static <V> @Nullable V
getAdapter(java.lang.Object object, java.lang.Class<V> target)
Adapt object to given target class typestatic <V> @Nullable V
getAdapter(java.lang.Object o, java.lang.Class<V> target, boolean askPlatform)
Adapt object to given target class typestatic <T> @Nullable T
getAdapter(org.eclipse.core.runtime.IAdaptable adaptable, java.lang.Class<T> adapterClass)
Returns the adapter corresponding to the given adapter class.static org.eclipse.core.filebuffers.ITextFileBuffer
getBuffer(org.eclipse.core.resources.IFile file)
The caller has to disconnect the buffer after buffer is usedstatic int
getCaretPosition(org.eclipse.jface.viewers.ISelectionProvider selectionProvider)
static java.lang.String
getClipboardContent()
static org.eclipse.ui.IEditorReference[]
getEditors()
static @Nullable java.io.File
getFile(@Nullable org.eclipse.ui.IEditorInput input)
static @Nullable java.io.File
getFile(java.lang.Object o, boolean askPlatform)
static @Nullable org.eclipse.core.resources.IFile
getIFile(java.lang.Object o, boolean askPlatform)
static @Nullable org.eclipse.core.resources.IFile
getIFile(org.eclipse.core.runtime.IPath iPath)
static @Nullable java.io.File
getLocalFile(@Nullable java.net.URI uri)
static java.lang.String
getNewLineFromDocument(org.eclipse.jface.text.IDocument document)
static java.lang.String
getNewLineFromFile(org.eclipse.core.resources.IFile file)
Looks into the file returns the newline characters used in the filestatic org.eclipse.core.resources.IProject
getProject(org.eclipse.ui.IEditorInput currentInput)
static org.eclipse.core.resources.IProject
getProject(org.eclipse.ui.IWorkbenchPart viewPart)
private static java.lang.String
getRelativePath(org.eclipse.ui.IFileEditorInput currentInput)
static org.eclipse.core.resources.IResource
getResource(java.lang.Object o)
static @Nullable org.eclipse.core.resources.IResource
getResource(java.lang.Object o, boolean askPlatform)
static org.eclipse.core.resources.IFile
getResource(org.eclipse.core.resources.IProject project, org.eclipse.ui.IEditorInput currentInput, java.lang.String selectedText)
static java.lang.String
getSelectedText(org.eclipse.jface.viewers.ISelectionProvider selectionProvider)
static @Nullable java.net.URI
getURI(@Nullable org.eclipse.ui.IEditorInput input)
static org.osgi.framework.Version
getWorkbenchVersion()
static @Nullable org.eclipse.core.resources.IFile
getWorkspaceFile()
private static org.eclipse.core.resources.IFile
getWorkspaceFile(java.io.File file)
static boolean
hasJDT()
private static boolean
isJavaFile(java.lang.String fileName)
static boolean
isJavaInput(org.eclipse.core.resources.IFile file)
private static boolean
isJavaInput(org.eclipse.ui.IEditorInput editorInput)
static boolean
isWindows()
static boolean
matchFilter(java.lang.String fileName, java.lang.String[] filters)
static boolean
matchFilter(org.eclipse.ui.IEditorPart part, CombinedPreferences prefs)
static java.lang.String[]
parseList(java.lang.String listString)
Parses the comma separated string into an array of stringsstatic org.eclipse.core.resources.IFile
queryFile(java.lang.String path, org.eclipse.core.resources.IContainer input)
static java.util.List<org.eclipse.core.resources.IFile>
queryFiles(java.lang.String path, org.eclipse.core.resources.IContainer input)
static void
searchForPathFragment(org.eclipse.core.resources.IContainer container, java.lang.String pathFragment, java.util.List<org.eclipse.core.resources.IResource> resultList, boolean searchInRoot)
Try to find given PathFragment somewhere in project resources tree.static java.lang.String[]
splitFileName(java.lang.String name)
-
-
-
Method Detail
-
getWorkbenchVersion
public static org.osgi.framework.Version getWorkbenchVersion()
-
getProject
public static org.eclipse.core.resources.IProject getProject(org.eclipse.ui.IEditorInput currentInput)
- Parameters:
currentInput
- may be null- Returns:
- project, may be null
-
getProject
public static org.eclipse.core.resources.IProject getProject(org.eclipse.ui.IWorkbenchPart viewPart)
-
getFile
public static @Nullable java.io.File getFile(java.lang.Object o, boolean askPlatform)
- Parameters:
o
- selection or some object which is or can be adapted to fileaskPlatform
-- Returns:
- adapter from given object to file, may return null
-
getIFile
public static @Nullable org.eclipse.core.resources.IFile getIFile(java.lang.Object o, boolean askPlatform)
- Parameters:
o
- selection or some object which is or can be adapted toIFile
b
-- Returns:
- adapter from given object to
IFile
, may return null
-
getAdapter
public static <V> @Nullable V getAdapter(java.lang.Object object, java.lang.Class<V> target)
Adapt object to given target class type- Type Parameters:
V
- type of target- Parameters:
object
-target
-- Returns:
- adapter from given object to given type, may return null
-
getResource
public static org.eclipse.core.resources.IResource getResource(java.lang.Object o)
- Parameters:
o
- selection or some object which is or can be adapted to resource- Returns:
- given object as resource, may return null
-
getResource
public static @Nullable org.eclipse.core.resources.IResource getResource(java.lang.Object o, boolean askPlatform)
- Parameters:
o
- selection or some object which is or can be adapted to resourceaskPlatform
-- Returns:
- adapter from given object to resource, may return null
-
getAdapter
public static <V> @Nullable V getAdapter(java.lang.Object o, java.lang.Class<V> target, boolean askPlatform)
Adapt object to given target class type- Type Parameters:
V
- type of target- Parameters:
o
- selection or some object which is or can be adapted to given typetarget
-- Returns:
- adapter from given object to given type, may return null
-
getAdapter
public static <T> @Nullable T getAdapter(org.eclipse.core.runtime.IAdaptable adaptable, java.lang.Class<T> adapterClass)
Returns the adapter corresponding to the given adapter class.Workaround for "Unnecessary cast" errors, see bug 460685. Can be removed when plugin depends on Eclipse 4.5 or higher.
- Parameters:
adaptable
- the adaptableadapterClass
- the adapter class to look up- Returns:
- a object of the given class, or
null
if this object does not have an adapter for the given class
-
getResource
public static org.eclipse.core.resources.IFile getResource(org.eclipse.core.resources.IProject project, org.eclipse.ui.IEditorInput currentInput, java.lang.String selectedText) throws org.eclipse.core.runtime.OperationCanceledException
- Throws:
org.eclipse.core.runtime.OperationCanceledException
-
findAbsoluteFile
private static org.eclipse.core.resources.IFile findAbsoluteFile(java.lang.String selectedText) throws org.eclipse.core.runtime.OperationCanceledException
- Throws:
org.eclipse.core.runtime.OperationCanceledException
-
getIFile
public static @Nullable org.eclipse.core.resources.IFile getIFile(org.eclipse.core.runtime.IPath iPath) throws org.eclipse.core.runtime.OperationCanceledException
- Parameters:
iPath
- non null- Returns:
- may return null or external file, which location in workspace is null. For files located inside the root of the file system, always returns null.
- Throws:
org.eclipse.core.runtime.OperationCanceledException
-
findInProjects
private static org.eclipse.core.resources.IFile findInProjects(org.eclipse.core.resources.IProject[] projects, java.lang.String currentPath, java.lang.String selectedText, java.util.List<org.eclipse.core.resources.IProject> checkedProjects, java.util.List<org.eclipse.core.resources.IResource> resultList) throws org.eclipse.core.runtime.OperationCanceledException
- Throws:
org.eclipse.core.runtime.OperationCanceledException
-
findInProject
private static org.eclipse.core.resources.IFile findInProject(java.lang.String currentPath, org.eclipse.core.resources.IContainer project, java.lang.String selectedText, java.util.List<org.eclipse.core.resources.IResource> resultList) throws org.eclipse.core.runtime.OperationCanceledException
- Throws:
org.eclipse.core.runtime.OperationCanceledException
-
getRelativePath
private static java.lang.String getRelativePath(org.eclipse.ui.IFileEditorInput currentInput)
- Returns:
- relative path to input file
-
getWorkspaceFile
public static final @Nullable org.eclipse.core.resources.IFile getWorkspaceFile()
-
getWorkspaceFile
private static org.eclipse.core.resources.IFile getWorkspaceFile(java.io.File file) throws org.eclipse.core.runtime.OperationCanceledException
- Throws:
org.eclipse.core.runtime.OperationCanceledException
-
getBuffer
public static org.eclipse.core.filebuffers.ITextFileBuffer getBuffer(org.eclipse.core.resources.IFile file)
The caller has to disconnect the buffer after buffer is used- Returns:
- file buffer for given file, or null, if file is external
-
getURI
public static @Nullable java.net.URI getURI(@Nullable org.eclipse.ui.IEditorInput input)
-
getFile
public static @Nullable java.io.File getFile(@Nullable org.eclipse.ui.IEditorInput input)
-
getLocalFile
public static @Nullable java.io.File getLocalFile(@Nullable java.net.URI uri)
- Returns:
- may return null
-
getNewLineFromFile
public static java.lang.String getNewLineFromFile(org.eclipse.core.resources.IFile file)
Looks into the file returns the newline characters used in the file- Returns:
- given string with converted newlines, or unchanged string if something goes wrong
-
getNewLineFromDocument
public static java.lang.String getNewLineFromDocument(org.eclipse.jface.text.IDocument document)
-
disconnectBuffer
public static void disconnectBuffer(org.eclipse.core.filebuffers.ITextFileBuffer buffer)
-
filterNonExistentFiles
private static java.util.List<org.eclipse.core.resources.IFile> filterNonExistentFiles(org.eclipse.core.resources.IFile[] files)
-
getCaretPosition
public static int getCaretPosition(org.eclipse.jface.viewers.ISelectionProvider selectionProvider)
-
getSelectedText
public static java.lang.String getSelectedText(org.eclipse.jface.viewers.ISelectionProvider selectionProvider)
-
getClipboardContent
public static java.lang.String getClipboardContent()
-
isJavaInput
private static boolean isJavaInput(org.eclipse.ui.IEditorInput editorInput)
-
isJavaFile
private static boolean isJavaFile(java.lang.String fileName)
-
isJavaInput
public static boolean isJavaInput(org.eclipse.core.resources.IFile file)
-
matchFilter
public static boolean matchFilter(org.eclipse.ui.IEditorPart part, CombinedPreferences prefs)
- Returns:
- false, if file filters are not applicable to the editor input. Return true, if at least one of filters matches the file name.
-
matchFilter
public static boolean matchFilter(java.lang.String fileName, java.lang.String[] filters)
-
splitFileName
public static java.lang.String[] splitFileName(java.lang.String name)
-
parseList
public static java.lang.String[] parseList(java.lang.String listString)
Parses the comma separated string into an array of strings
-
searchForPathFragment
public static void searchForPathFragment(org.eclipse.core.resources.IContainer container, java.lang.String pathFragment, java.util.List<org.eclipse.core.resources.IResource> resultList, boolean searchInRoot)
Try to find given PathFragment somewhere in project resources tree. The matches will be added to resultList
-
queryFile
public static org.eclipse.core.resources.IFile queryFile(java.lang.String path, org.eclipse.core.resources.IContainer input) throws org.eclipse.core.runtime.OperationCanceledException
- Parameters:
path
- may be null, see org.eclipse.ui.internal.ide.actions.OpenWorkspaceFileAction#queryFileResource()- Throws:
org.eclipse.core.runtime.OperationCanceledException
- if user cancels the dialog
-
queryFiles
public static java.util.List<org.eclipse.core.resources.IFile> queryFiles(java.lang.String path, org.eclipse.core.resources.IContainer input) throws org.eclipse.core.runtime.OperationCanceledException
- Parameters:
path
- may be null, see org.eclipse.ui.internal.ide.actions.OpenWorkspaceFileAction#queryFileResource()- Throws:
org.eclipse.core.runtime.OperationCanceledException
- if user cancels the dialog
-
hasJDT
public static boolean hasJDT()
-
isWindows
public static boolean isWindows()
-
getActiveEditor
public static org.eclipse.ui.IEditorPart getActiveEditor()
-
getEditors
public static org.eclipse.ui.IEditorReference[] getEditors()
-
-