當前位置: 首頁>>代碼示例>>Java>>正文


Java JavaUI.getEditorInputTypeRoot方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.ui.JavaUI.getEditorInputTypeRoot方法的典型用法代碼示例。如果您正苦於以下問題:Java JavaUI.getEditorInputTypeRoot方法的具體用法?Java JavaUI.getEditorInputTypeRoot怎麽用?Java JavaUI.getEditorInputTypeRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.ui.JavaUI的用法示例。


在下文中一共展示了JavaUI.getEditorInputTypeRoot方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: launch

import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
@Override
public void launch(IEditorPart editor, String mode) {
	ITypeRoot element= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
	if (element != null) {
		launch(new Object[] { element }, mode);
	}  
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:8,代碼來源:GW4ELaunchShortcut.java

示例2: computeFieldConstant

import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
/**
 * Compute the textual representation of a 'static' 'final' field's constant initializer value.
 *
 * @param activePart the part that triggered the computation, or <code>null</code>
 * @param selection the selection that references the field, or <code>null</code>
 * @param resolvedField the filed whose constant value will be computed
 * @param monitor the progress monitor
 *
 * @return the textual representation of the constant, or <code>null</code> if the
 *   field is not a constant field, the initializer value could not be computed, or
 *   the progress monitor was cancelled
 * @since 3.4
 */
private String computeFieldConstant(IWorkbenchPart activePart, ISelection selection, IField resolvedField, IProgressMonitor monitor) {

	if (!JavadocHover.isStaticFinal(resolvedField))
		return null;

	Object constantValue;
	IJavaProject preferenceProject;

	if (selection instanceof ITextSelection && activePart instanceof JavaEditor) {
		IEditorPart editor= (IEditorPart) activePart;
		ITypeRoot activeType= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
		preferenceProject= activeType.getJavaProject();
		constantValue= getConstantValueFromActiveEditor(activeType, resolvedField, (ITextSelection) selection, monitor);
		if (constantValue == null) // fall back - e.g. when selection is inside Javadoc of the element
			constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor);
	} else {
		constantValue= computeFieldConstantFromTypeAST(resolvedField, monitor);
		preferenceProject= resolvedField.getJavaProject();
	}

	if (constantValue != null)
		return JavadocHover.getFormattedAssignmentOperator(preferenceProject) + formatCompilerConstantValue(constantValue);

	return null;
}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion,代碼行數:39,代碼來源:JavadocView.java

示例3: getSelectedMethod

import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
public static IMethod getSelectedMethod(IFileEditorInput fileEditorInput)
		throws JavaModelException {
	ITextEditor editor = (ITextEditor) EclipseUIUtils.getActiveEditor();
	ITextSelection sel = (ITextSelection) editor.getSelectionProvider()
			.getSelection();
	ITypeRoot typeRoot = JavaUI.getEditorInputTypeRoot(editor
			.getEditorInput());
	ICompilationUnit icu = (ICompilationUnit) typeRoot
			.getAdapter(ICompilationUnit.class);
	CompilationUnit cu = createASTRoot(icu);
	NodeFinder finder = new NodeFinder(cu, sel.getOffset(), sel.getLength());

	ASTNode node = finder.getCoveringNode();

	MethodDeclaration methodDeclaration = getASTMethod(node);
	if (methodDeclaration == null) {
		return null;
	}

	IMethodBinding methodBinding = methodDeclaration.resolveBinding();

	IMethod selectedMethod = null;
	if (methodBinding != null) {
		selectedMethod = (IMethod) methodBinding.getJavaElement();
	}

	return selectedMethod;
}
 
開發者ID:junit-tools-team,項目名稱:junit-tools,代碼行數:29,代碼來源:JDTUtils.java

示例4: installOnActiveEditor

import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
private void installOnActiveEditor(IWorkbenchPage page) {
	IEditorPart activeEditor= page.getActiveEditor();
	if (activeEditor instanceof ITextEditor) {
		editorActive(activeEditor);
		ISelection selection= activeEditor.getSite().getSelectionProvider().getSelection();
		ITypeRoot typeRoot= JavaUI.getEditorInputTypeRoot(activeEditor.getEditorInput());
		if (typeRoot != null && selection instanceof ITextSelection) {
			CompilationUnit astRoot= SharedASTProvider.getAST(typeRoot, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
			if (astRoot != null) {
				preformEditorSelectionChanged((ITextSelection) selection, astRoot);
			}
		}
	}
}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion,代碼行數:15,代碼來源:OccurrencesSearchResultPage.java

示例5: getEditorInput

import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
private static ITypeRoot getEditorInput(JavaEditor editor) {
	return JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion,代碼行數:4,代碼來源:FindImplementOccurrencesAction.java

示例6: getEditorInput

import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
private ITypeRoot getEditorInput() {
	return JavaUI.getEditorInputTypeRoot(fEditor.getEditorInput());
}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion,代碼行數:4,代碼來源:RefactorActionGroup.java

示例7: getInputJavaElement

import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
private ITypeRoot getInputJavaElement(ITextEditor editor) {
	return JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion,代碼行數:4,代碼來源:NLSKeyHyperlinkDetector.java

示例8: doCutCopyWithImportsOperation

import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
private void doCutCopyWithImportsOperation() {
	ITextEditor editor= getTextEditor();
	ITypeRoot inputElement= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
	ISelection selection= editor.getSelectionProvider().getSelection();

	Object clipboardData= null;
	if (inputElement != null && selection instanceof ITextSelection && !selection.isEmpty()) {
		ITextSelection textSelection= (ITextSelection) selection;
		if (isNonTrivialSelection(textSelection)) {
			clipboardData= getClipboardData(inputElement, textSelection.getOffset(), textSelection.getLength());
		}
	}

	fOperationTarget.doOperation(fOperationCode);

	if (clipboardData != null) {
		/*
		 * We currently make assumptions about what the styled text widget sets,
		 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=61876
		 */
		Clipboard clipboard= new Clipboard(getDisplay());
		try {
			Object textData= clipboard.getContents(TextTransfer.getInstance());
			/*
			 * Don't add if we didn't get any text data from the clipboard, see:
			 * - https://bugs.eclipse.org/bugs/show_bug.cgi?id=70077
			 * - https://bugs.eclipse.org/bugs/show_bug.cgi?id=200743
			 */
			if (textData == null)
				return;

			ArrayList<Object> datas= new ArrayList<Object>(3);
			ArrayList<ByteArrayTransfer> transfers= new ArrayList<ByteArrayTransfer>(3);
			datas.add(textData);
			transfers.add(TextTransfer.getInstance());

			Object rtfData= clipboard.getContents(RTFTransfer.getInstance());
			if (rtfData != null) {
				datas.add(rtfData);
				transfers.add(RTFTransfer.getInstance());
			}

			datas.add(clipboardData);
			transfers.add(fgTransferInstance);

			Transfer[] dataTypes= transfers.toArray(new Transfer[transfers.size()]);
			Object[] data= datas.toArray();
			setClipboardContents(clipboard, data, dataTypes);
		} finally {
			clipboard.dispose();
		}
	}
}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion,代碼行數:54,代碼來源:ClipboardOperationAction.java

示例9: getSelectedElement

import org.eclipse.jdt.ui.JavaUI; //導入方法依賴的package包/類
private Object getSelectedElement(JavaEditor editor) {
	ISourceViewer viewer= editor.getViewer();
	if (viewer == null)
		return null;

	Point selectedRange= viewer.getSelectedRange();
	int length= selectedRange.y;
	int offset= selectedRange.x;

	ITypeRoot element= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
	if (element == null)
		return null;

	CompilationUnit ast= SharedASTProvider.getAST(element, SharedASTProvider.WAIT_YES, null);
	if (ast == null)
		return null;

	NodeFinder finder= new NodeFinder(ast, offset, length);
	ASTNode node= finder.getCoveringNode();

	IBinding binding= null;
	if (node instanceof Name) {
		binding= getConstructorBindingIfAvailable((Name)node);
		if (binding != null)
			return binding;
		binding= ((Name)node).resolveBinding();
	} else if (node instanceof MethodInvocation) {
		binding= ((MethodInvocation)node).resolveMethodBinding();
	} else if (node instanceof MethodDeclaration) {
		binding= ((MethodDeclaration)node).resolveBinding();
	} else if (node instanceof Type) {
		binding= ((Type)node).resolveBinding();
	} else if (node instanceof AnonymousClassDeclaration) {
		binding= ((AnonymousClassDeclaration)node).resolveBinding();
	} else if (node instanceof TypeDeclaration) {
		binding= ((TypeDeclaration)node).resolveBinding();
	} else if (node instanceof CompilationUnit) {
		return ((CompilationUnit)node).getJavaElement();
	} else if (node instanceof Expression) {
		binding= ((Expression)node).resolveTypeBinding();
	} else if (node instanceof ImportDeclaration) {
		binding= ((ImportDeclaration)node).resolveBinding();
	} else if (node instanceof MemberRef) {
		binding= ((MemberRef)node).resolveBinding();
	} else if (node instanceof MemberValuePair) {
		binding= ((MemberValuePair)node).resolveMemberValuePairBinding();
	} else if (node instanceof PackageDeclaration) {
		binding= ((PackageDeclaration)node).resolveBinding();
	} else if (node instanceof TypeParameter) {
		binding= ((TypeParameter)node).resolveBinding();
	} else if (node instanceof VariableDeclaration) {
		binding= ((VariableDeclaration)node).resolveBinding();
	}

	if (binding != null)
		return binding.getJavaElement();

	return null;
}
 
開發者ID:trylimits,項目名稱:Eclipse-Postfix-Code-Completion,代碼行數:60,代碼來源:CopyQualifiedNameAction.java


注:本文中的org.eclipse.jdt.ui.JavaUI.getEditorInputTypeRoot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。