本文整理匯總了Java中org.eclipse.jdt.ui.JavaUI.getEditorInputJavaElement方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaUI.getEditorInputJavaElement方法的具體用法?Java JavaUI.getEditorInputJavaElement怎麽用?Java JavaUI.getEditorInputJavaElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jdt.ui.JavaUI
的用法示例。
在下文中一共展示了JavaUI.getEditorInputJavaElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSelectedMethod
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
public static IMethod getSelectedMethod() throws JavaModelException {
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
ITextEditor editor = (ITextEditor) page.getActiveEditor();
IJavaElement elem = JavaUI.getEditorInputJavaElement(editor
.getEditorInput());
if (elem instanceof ICompilationUnit) {
ITextSelection sel = (ITextSelection) editor.getSelectionProvider()
.getSelection();
IJavaElement selected = ((ICompilationUnit) elem).getElementAt(sel
.getOffset());
if (selected != null
&& selected.getElementType() == IJavaElement.METHOD) {
return (IMethod) selected;
}
}
return null;
}
示例2: getInputFromEditor
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
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;
}
示例3: getAdapter
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
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;
}
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion-Juno38,代碼行數:20,代碼來源:EditorInputAdapterFactory.java
示例4: matchInput
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
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;
}
示例5: test
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
{
ITextEditor editor = (ITextEditor)receiver;
IJavaElement element = JavaUI.getEditorInputJavaElement(editor.getEditorInput());
if (element != null)
{
if ("isMyBatisProject".equals(property))
{
try
{
return element.getJavaProject().getProject().hasNature(MyBatisNature.NATURE_ID);
}
catch (CoreException e)
{
Activator.log(Status.ERROR, e.getMessage(), e);
}
}
}
return false;
}
示例6: getHierarchyPresenter
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
/**
* 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;
}
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion-Juno38,代碼行數:29,代碼來源:JavaSourceViewerConfiguration.java
示例7: getCurrentSelectedJavaMethod
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
/**
* Returns currently selected method or <code>null</code>
* @param editor
* @return method or <code>null</code>
*
*/
public IMethod getCurrentSelectedJavaMethod(ITextEditor editor) {
if (editor==null){
return null;
}
IEditorInput editorInput = editor.getEditorInput();
if (editorInput==null){
return null;
}
IJavaElement elem = JavaUI.getEditorInputJavaElement(editorInput);
if (elem instanceof ICompilationUnit) {
ITextSelection sel = (ITextSelection) editor.getSelectionProvider().getSelection();
IJavaElement selected;
try {
selected = ((ICompilationUnit) elem).getElementAt(sel.getOffset());
} catch (JavaModelException e) {
JunitUtil.logError("Was not able to get element at selection",e);
return null;
}
if (selected==null){
return null;
}
if (selected.getElementType() == IJavaElement.METHOD) {
return (IMethod) selected;
}
}
return null;
}
示例8: addBookmarkProperties
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
@Override
public void addBookmarkProperties(Map<String, String> bookmarkProperties, IWorkbenchPart part, ISelection selection,
IProgressMonitor monitor) {
ITextEditor editor = getTextEditor(part);
if (editor == null) {
return;
}
if (editor != part) {
selection = getSelection(editor);
}
if (!(selection instanceof ITextSelection)) {
return;
}
ITextSelection textSelection = (ITextSelection) selection;
int lineNumber = textSelection.getStartLine();
int offset = getOffset(editor, textSelection);
IJavaElement editorJavaElement = JavaUI.getEditorInputJavaElement(editor.getEditorInput());
if (editorJavaElement == null) {
return;
}
IJavaElement containingJavaElement = getContainingJavaElement(editorJavaElement, offset);
if (!(containingJavaElement instanceof IMember)) {
return;
}
IMember member = (IMember) containingJavaElement;
super.addMemberBookmarkProperties(bookmarkProperties, member);
addLineNumberInsideMemberProperty(bookmarkProperties, member, lineNumber);
addJavadocComment(bookmarkProperties, member, lineNumber);
addLineContent(bookmarkProperties, editor, lineNumber);
}
示例9: getASTNode
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
public static ASTNode getASTNode(int offset, int length, IEditorPart part) {
IJavaElement activeEditorJavaInput = null;
if (part != null) {
IEditorInput editorInput = part.getEditorInput();
if (editorInput != null) {
activeEditorJavaInput = JavaUI
.getEditorInputJavaElement(editorInput);
}
} else {
activeEditorJavaInput = EditorUtility.getActiveEditorJavaInput();
part = getActivePart();
}
if (activeEditorJavaInput != null
&& activeEditorJavaInput.getElementType() == IJavaElement.COMPILATION_UNIT) {
ICompilationUnit compilationUnit = (ICompilationUnit) activeEditorJavaInput;
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(compilationUnit);
parser.setResolveBindings(true);
ASTNode root = parser.createAST(null);
ASTNode node = NodeFinder.perform(root, offset, length);
return node;
}
return null;
}
示例10: getJavaRootElementOfActiveEditor
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
/**
* Determines the root Java element of the active editor.
*
* @return the {@link ITypeRoot} of the active editor or {@link Optional#empty()}, if there is no active editor or the
* active editor is not a Java editor.
*/
private static Optional<ITypeRoot> getJavaRootElementOfActiveEditor() {
final IEditorPart editor = WorkbenchUtil.activePage().getActiveEditor();
if (editor != null) {
final IJavaElement javaElement = JavaUI.getEditorInputJavaElement(editor.getEditorInput());
if (javaElement != null && javaElement instanceof ITypeRoot) {
return Optional.of((ITypeRoot) javaElement);
}
}
return Optional.empty();
}
示例11: getCompilationUnit
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
private static ICompilationUnit getCompilationUnit(JavaEditor editor) {
IJavaElement element= JavaUI.getEditorInputJavaElement(editor.getEditorInput());
if (!(element instanceof ICompilationUnit))
return null;
return (ICompilationUnit)element;
}
示例12: getProjectScopeDescription
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
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$
}
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion-Juno38,代碼行數:11,代碼來源:JavaSearchScopeFactory.java
示例13: tokenize
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
/**
* Tokenizes the supplied {@code ITextSelection} if the selected text corresponds to an
* {@code IJavaElement}.
*/
private void tokenize(final ITextSelection selection)
{
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
if (activePage != null)
{
final IEditorPart editor = activePage.getActiveEditor();
final IEditorInput editorInput = editor.getEditorInput();
final IJavaElement element = JavaUI.getEditorInputJavaElement(editorInput);
if (element instanceof ICodeAssist)
{
final ICodeAssist root = (ICodeAssist) element;
try
{
final int offset = selection.getOffset();
final int length = selection.getLength();
final IJavaElement[] elements = root.codeSelect(offset, length);
if (elements.length > 0)
{
tokenize(elements[0]);
}
}
catch (final JavaModelException e)
{
// do nothing
}
}
}
}
示例14: createJavaProjectSearchScope
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
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;
}
示例15: getActiveEditorJavaInput
import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
/**
* 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;
}