Java Code Examples for org.eclipse.jdt.ui.JavaUI#getEditorInputJavaElement()

The following examples show how to use org.eclipse.jdt.ui.JavaUI#getEditorInputJavaElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BugInfoView.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean matchInput(IEditorInput input) {
    if (file != null && (input instanceof IFileEditorInput)) {
        return file.equals(((IFileEditorInput) input).getFile());
    }
    if (javaElt != null && input != null) {
        IJavaElement javaElement = JavaUI.getEditorInputJavaElement(input);
        if (javaElt.equals(javaElement)) {
            return true;
        }
        IJavaElement parent = javaElt.getParent();
        while (parent != null && !parent.equals(javaElement)) {
            parent = parent.getParent();
        }
        if (parent != null && parent.equals(javaElement)) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: JavaSourceViewerConfiguration.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the hierarchy presenter which will determine and shown type hierarchy
 * information requested for the current cursor position.
 *
 * @param sourceViewer the source viewer to be configured by this configuration
 * @param doCodeResolve a boolean which specifies whether code resolve should be used to compute the Java element
 * @return an information presenter
 * @since 3.0
 */
public IInformationPresenter getHierarchyPresenter(ISourceViewer sourceViewer, boolean doCodeResolve) {

	// Do not create hierarchy presenter if there's no CU.
	if (getEditor() != null && getEditor().getEditorInput() != null && JavaUI.getEditorInputJavaElement(getEditor().getEditorInput()) == null)
		return null;

	InformationPresenter presenter= new InformationPresenter(getHierarchyPresenterControlCreator());
	presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
	presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL);
	IInformationProvider provider= new JavaElementProvider(getEditor(), doCodeResolve);
	presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_STRING);
	presenter.setInformationProvider(provider, IJavaPartitions.JAVA_CHARACTER);
	presenter.setSizeConstraints(50, 20, true, false);
	return presenter;
}
 
Example 3
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Object getInputFromEditor(IEditorInput editorInput) {
	Object input= JavaUI.getEditorInputJavaElement(editorInput);
	if (input instanceof ICompilationUnit) {
		ICompilationUnit cu= (ICompilationUnit) input;
		if (!cu.getJavaProject().isOnClasspath(cu)) { // test needed for Java files in non-source folders (bug 207839)
			input= cu.getResource();
		}
	}
	if (input == null) {
		input= editorInput.getAdapter(IFile.class);
	}
	if (input == null && editorInput instanceof IStorageEditorInput) {
		try {
			input= ((IStorageEditorInput) editorInput).getStorage();
		} catch (CoreException e) {
			// ignore
		}
	}
	return input;
}
 
Example 4
Source File: EditorInputAdapterFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public Object getAdapter(Object element, Class key) {
	updateLazyLoadedAdapters();
	if (fSearchPageScoreComputer != null && ISearchPageScoreComputer.class.equals(key) && element instanceof IEditorInput && JavaUI.getEditorInputJavaElement((IEditorInput)element) != null)
		return fSearchPageScoreComputer;

	if (IJavaElement.class.equals(key) && element instanceof IEditorInput) {
		IJavaElement je= JavaUI.getWorkingCopyManager().getWorkingCopy((IEditorInput)element);
		if (je != null)
			return je;
		if (element instanceof IStorageEditorInput) {
			try {
				return ((IStorageEditorInput)element).getStorage().getAdapter(key);
			} catch (CoreException ex) {
				// Fall through
			}
		}
	}
	return null;
}
 
Example 5
Source File: OrganizeImportsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ICompilationUnit getCompilationUnit(JavaEditor editor) {
	IJavaElement element= JavaUI.getEditorInputJavaElement(editor.getEditorInput());
	if (!(element instanceof ICompilationUnit))
		return null;

	return (ICompilationUnit)element;
}
 
Example 6
Source File: JavaSearchPageScoreComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public int computeScore(String id, Object element) {
	if (!JavaSearchPage.EXTENSION_POINT_ID.equals(id))
		// Can't decide
		return ISearchPageScoreComputer.UNKNOWN;

	if (element instanceof IJavaElement || element instanceof IClassFileEditorInput || element instanceof LogicalPackage
			|| (element instanceof IEditorInput && JavaUI.getEditorInputJavaElement((IEditorInput)element) != null))
		return 90;

	return ISearchPageScoreComputer.LOWEST;
}
 
Example 7
Source File: JavaSearchScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IJavaSearchScope createJavaProjectSearchScope(IEditorInput editorInput, int includeMask) {
	IJavaElement elem= JavaUI.getEditorInputJavaElement(editorInput);
	if (elem != null) {
		IJavaProject project= elem.getJavaProject();
		if (project != null) {
			return createJavaProjectSearchScope(project, includeMask);
		}
	}
	return EMPTY_SCOPE;
}
 
Example 8
Source File: JavaSearchScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getProjectScopeDescription(IEditorInput editorInput, boolean includeJRE) {
	IJavaElement elem= JavaUI.getEditorInputJavaElement(editorInput);
	if (elem != null) {
		IJavaProject project= elem.getJavaProject();
		if (project != null) {
			return getProjectScopeDescription(project, includeJRE);
		}
	}
	return Messages.format(SearchMessages.ProjectScope, "");  //$NON-NLS-1$
}
 
Example 9
Source File: EditorUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the Java element edited in the current active editor.
 *
 * @return the Java element or <code>null</code> if the active editor doesn't edit a Java element
 */
public static IJavaElement getActiveEditorJavaInput() {
	IWorkbenchPage page= JavaPlugin.getActivePage();
	if (page != null) {
		IEditorPart part= page.getActiveEditor();
		if (part != null) {
			IEditorInput editorInput= part.getEditorInput();
			if (editorInput != null) {
				return JavaUI.getEditorInputJavaElement(editorInput);
			}
		}
	}
	return null;
}
 
Example 10
Source File: CleanUpAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ICompilationUnit getCompilationUnit(JavaEditor editor) {
	IJavaElement element= JavaUI.getEditorInputJavaElement(editor.getEditorInput());
	if (!(element instanceof ICompilationUnit))
		return null;

	return (ICompilationUnit)element;
}
 
Example 11
Source File: QuickAssistLightBulbUpdater.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ICompilationUnit getCompilationUnit() {
	IJavaElement elem= JavaUI.getEditorInputJavaElement(fEditor.getEditorInput());
	if (elem instanceof ICompilationUnit) {
		return (ICompilationUnit) elem;
	}
	return null;
}
 
Example 12
Source File: JavaFileLinkHelper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public IStructuredSelection findSelection(IEditorInput input) {
	IJavaElement element= JavaUI.getEditorInputJavaElement(input);
	if (element == null) {
		IFile file = ResourceUtil.getFile(input);
		if (file != null) {
			element= JavaCore.create(file);
		}
	}
	return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY;
}
 
Example 13
Source File: JavaBrowsingPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the element contained in the EditorInput
 * @param input the editor input
 * @return the input element
 */
Object getElementOfInput(IEditorInput input) {
	if (input instanceof IFileEditorInput)
		return ((IFileEditorInput)input).getFile();
	if (input != null)
		return JavaUI.getEditorInputJavaElement(input);
	return null;
}