当前位置: 首页>>代码示例>>Java>>正文


Java JavaUI.getEditorInputJavaElement方法代码示例

本文整理汇总了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;
}
 
开发者ID:junit-tools-team,项目名称:junit-tools,代码行数:20,代码来源:JDTUtils.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:PackageExplorerPart.java

示例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;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:20,代码来源:BugInfoView.java

示例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;
}
 
开发者ID:mybatis,项目名称:mybatipse,代码行数:22,代码来源:JavaRefactoringPropertyTester.java

示例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;
}
 
开发者ID:de-jcup,项目名称:egradle,代码行数:35,代码来源:JavaHelper.java

示例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);
}
 
开发者ID:cchabanois,项目名称:mesfavoris,代码行数:32,代码来源:JavaEditorBookmarkPropertiesProvider.java

示例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;
}
 
开发者ID:aroog,项目名称:code,代码行数:29,代码来源:ASTUtils.java

示例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();
}
 
开发者ID:sealuzh,项目名称:Permo,代码行数:18,代码来源:SelectedMethods.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:8,代码来源:OrganizeImportsAction.java

示例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
      }
    }
  }
}
 
开发者ID:UBPL,项目名称:jive,代码行数:34,代码来源:SelectionTokenizer.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:11,代码来源:JavaSearchScopeFactory.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:EditorUtility.java


注:本文中的org.eclipse.jdt.ui.JavaUI.getEditorInputJavaElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。