org.eclipse.jdt.internal.ui.javaeditor.JavaEditor Java Examples

The following examples show how to use org.eclipse.jdt.internal.ui.javaeditor.JavaEditor. 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: WriteReferencesSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 * @param editor the Java editor
 *
 * @noreference This constructor is not intended to be referenced by clients.
 */
public WriteReferencesSearchGroup(JavaEditor editor) {
	fEditor= editor;
	fSite= fEditor.getSite();
	fGroupId= ITextEditorActionConstants.GROUP_FIND;

	fFindWriteReferencesAction= new FindWriteReferencesAction(fEditor);
	fFindWriteReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE);
	fEditor.setAction("SearchWriteAccessInWorkspace", fFindWriteReferencesAction); //$NON-NLS-1$

	fFindWriteReferencesInProjectAction= new FindWriteReferencesInProjectAction(fEditor);
	fFindWriteReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_PROJECT);
	fEditor.setAction("SearchWriteAccessInProject", fFindWriteReferencesInProjectAction); //$NON-NLS-1$

	fFindWriteReferencesInHierarchyAction= new FindWriteReferencesInHierarchyAction(fEditor);
	fFindWriteReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY);
	fEditor.setAction("SearchWriteAccessInHierarchy", fFindWriteReferencesInHierarchyAction); //$NON-NLS-1$

	fFindWriteReferencesInWorkingSetAction= new FindWriteReferencesInWorkingSetAction(fEditor);
	fFindWriteReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET);
	fEditor.setAction("SearchWriteAccessInWorkingSet", fFindWriteReferencesInWorkingSetAction); //$NON-NLS-1$
}
 
Example #2
Source File: FindWriteReferencesInProjectAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
QuerySpecification createQuery(IJavaElement element) throws JavaModelException {
	JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
	JavaEditor editor= getEditor();

	IJavaSearchScope scope;
	String description;
	boolean isInsideJRE= factory.isInsideJRE(element);
	if (editor != null) {
		scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE);
		description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
	} else {
		scope= factory.createJavaProjectSearchScope(element.getJavaProject(), isInsideJRE);
		description=  factory.getProjectScopeDescription(element.getJavaProject(), isInsideJRE);
	}
	return new ElementQuerySpecification(element, getLimitTo(), scope, description);
}
 
Example #3
Source File: NLSStringHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
	if (!(getEditor() instanceof JavaEditor))
		return null;

	ITypeRoot je= getEditorInputJavaElement();
	if (je == null)
		return null;

	// Never wait for an AST in UI thread.
	CompilationUnit ast= SharedASTProvider.getAST(je, SharedASTProvider.WAIT_NO, null);
	if (ast == null)
		return null;

	ASTNode node= NodeFinder.perform(ast, offset, 1);
	if (node instanceof StringLiteral) {
		StringLiteral stringLiteral= (StringLiteral)node;
		return new Region(stringLiteral.getStartPosition(), stringLiteral.getLength());
	} else if (node instanceof SimpleName) {
		SimpleName simpleName= (SimpleName)node;
		return new Region(simpleName.getStartPosition(), simpleName.getLength());
	}

	return null;
}
 
Example #4
Source File: FindReadReferencesInProjectAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
QuerySpecification createQuery(IJavaElement element) throws JavaModelException {
	JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
	JavaEditor editor= getEditor();

	IJavaSearchScope scope;
	String description;
	boolean isInsideJRE= factory.isInsideJRE(element);
	if (editor != null) {
		scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE);
		description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
	} else {
		scope= factory.createJavaProjectSearchScope(element.getJavaProject(), isInsideJRE);
		description=  factory.getProjectScopeDescription(element.getJavaProject(), isInsideJRE);
	}
	return new ElementQuerySpecification(element, getLimitTo(), scope, description);
}
 
Example #5
Source File: DeclarationsSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 *
 * @param editor the Java editor
 *
 * @noreference This constructor is not intended to be referenced by clients.
 */
public DeclarationsSearchGroup(JavaEditor editor) {
	Assert.isNotNull(editor);
	fEditor= editor;
	fSite= fEditor.getSite();
	fGroupId= ITextEditorActionConstants.GROUP_FIND;

	fFindDeclarationsAction= new FindDeclarationsAction(fEditor);
	fFindDeclarationsAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKSPACE);
	fEditor.setAction("SearchDeclarationsInWorkspace", fFindDeclarationsAction); //$NON-NLS-1$

	fFindDeclarationsInProjectAction= new FindDeclarationsInProjectAction(fEditor);
	fFindDeclarationsInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_PROJECTS);
	fEditor.setAction("SearchDeclarationsInProjects", fFindDeclarationsInProjectAction); //$NON-NLS-1$

	fFindDeclarationsInHierarchyAction= new FindDeclarationsInHierarchyAction(fEditor);
	fFindDeclarationsInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_HIERARCHY);
	fEditor.setAction("SearchDeclarationsInHierarchy", fFindDeclarationsInHierarchyAction); //$NON-NLS-1$

	fFindDeclarationsInWorkingSetAction= new FindDeclarationsInWorkingSetAction(fEditor);
	fFindDeclarationsInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKING_SET);
	fEditor.setAction("SearchDeclarationsInWorkingSet", fFindDeclarationsInWorkingSetAction); //$NON-NLS-1$
}
 
Example #6
Source File: FindImplementorsInProjectAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
QuerySpecification createQuery(IJavaElement element) throws JavaModelException {
	JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
	JavaEditor editor= getEditor();

	IJavaSearchScope scope;
	String description;
	boolean isInsideJRE= factory.isInsideJRE(element);
	if (editor != null) {
		scope= factory.createJavaProjectSearchScope(editor.getEditorInput(), isInsideJRE);
		description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
	} else {
		scope= factory.createJavaProjectSearchScope(element.getJavaProject(), isInsideJRE);
		description=  factory.getProjectScopeDescription(element.getJavaProject(), isInsideJRE);
	}
	return new ElementQuerySpecification(element, getLimitTo(), scope, description);
}
 
Example #7
Source File: ImplementorsSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 * @param editor the Java editor
 *
 * @noreference This constructor is not intended to be referenced by clients.
 */
public ImplementorsSearchGroup(JavaEditor editor) {
	fEditor= editor;
	fSite= fEditor.getSite();
	fGroupId= ITextEditorActionConstants.GROUP_FIND;

	fFindImplementorsAction= new FindImplementorsAction(fEditor);
	fFindImplementorsAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_WORKSPACE);
	fEditor.setAction("SearchImplementorsInWorkspace", fFindImplementorsAction); //$NON-NLS-1$

	fFindImplementorsInProjectAction= new FindImplementorsInProjectAction(fEditor);
	fFindImplementorsInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_PROJECT);
	fEditor.setAction("SearchImplementorsInProject", fFindImplementorsInProjectAction); //$NON-NLS-1$

	fFindImplementorsInWorkingSetAction= new FindImplementorsInWorkingSetAction(fEditor);
	fFindImplementorsInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENTORS_IN_WORKING_SET);
	fEditor.setAction("SearchImplementorsInWorkingSet", fFindImplementorsInWorkingSetAction); //$NON-NLS-1$
}
 
Example #8
Source File: ReadReferencesSearchGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 * @param editor the Java editor
 *
 * @noreference This constructor is not intended to be referenced by clients.
 */
public ReadReferencesSearchGroup(JavaEditor editor) {
	fEditor= editor;
	fSite= fEditor.getSite();
	fGroupId= ITextEditorActionConstants.GROUP_FIND;

	fFindReadReferencesAction= new FindReadReferencesAction(fEditor);
	fFindReadReferencesAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE);
	fEditor.setAction("SearchReadAccessInWorkspace", fFindReadReferencesAction); //$NON-NLS-1$

	fFindReadReferencesInProjectAction= new FindReadReferencesInProjectAction(fEditor);
	fFindReadReferencesInProjectAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_READ_ACCESS_IN_PROJECT);
	fEditor.setAction("SearchReadAccessInProject", fFindReadReferencesInProjectAction); //$NON-NLS-1$

	fFindReadReferencesInHierarchyAction= new FindReadReferencesInHierarchyAction(fEditor);
	fFindReadReferencesInHierarchyAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY);
	fEditor.setAction("SearchReadAccessInHierarchy", fFindReadReferencesInHierarchyAction); //$NON-NLS-1$

	fFindReadReferencesInWorkingSetAction= new FindReadReferencesInWorkingSetAction(fEditor);
	fFindReadReferencesInWorkingSetAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET);
	fEditor.setAction("SearchReadAccessInWorkingSet", fFindReadReferencesInWorkingSetAction); //$NON-NLS-1$
}
 
Example #9
Source File: OccurrencesSearchMenuAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void updateActions() {
	IWorkbenchPart activePart= JavaPlugin.getActivePage().getActivePart();
	if (!(activePart instanceof JavaEditor))
		return;

	ISelection javaSelection= getEditorSelection((JavaEditor) activePart);
	if (javaSelection == null)
		return;

	for (int i= 0; i < fRetargetActions.length; i++) {
		RetargetAction action= fRetargetActions[i];
		IAction actionHandler= action.getActionHandler();
		if (actionHandler instanceof SelectionDispatchAction) {
			((SelectionDispatchAction) actionHandler).update(javaSelection);
		}
	}
}
 
Example #10
Source File: JavaAddElementFromHistoryImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean isEnabled(ISelection selection) {

	if (selection.isEmpty()) {
		JavaEditor editor= getEditor();
		if (editor != null) {
			// we check whether editor shows CompilationUnit
			IEditorInput editorInput= editor.getEditorInput();
			IWorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager();
			return manager.getWorkingCopy(editorInput) != null;
		}
		return false;
	}

	if (selection instanceof IStructuredSelection) {
		Object o= ((IStructuredSelection)selection).getFirstElement();
		if (o instanceof ICompilationUnit)
			return true;
	}

	return super.isEnabled(selection);
}
 
Example #11
Source File: GWTJavaEditor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This adds the Open Declaration (F3) behavior to Java references inside JSNI
 * blocks.
 */
@Override
protected void createActions() {
  super.createActions();

  GWTOpenEditorActionGroup gwtOpenEditorActionGroup = new GWTOpenEditorActionGroup(
      this);

  try {
    // Replace the OpenEditorActionGroup from JavaEditor that contributes the
    // main menu items and keyboard binding
    replaceOpenEditorAction(fActionGroups, gwtOpenEditorActionGroup);

    // Also need to replace the OpenEditorActionGroup that contributes the
    // context menu items. This field is private, so we use reflection here.
    Field contextMenuField = JavaEditor.class.getDeclaredField("fContextMenuGroup");
    contextMenuField.setAccessible(true);
    CompositeActionGroup contextMenuGroup = (CompositeActionGroup) contextMenuField.get(this);
    replaceOpenEditorAction(contextMenuGroup, gwtOpenEditorActionGroup);

  } catch (Exception e) {
    GWTPluginLog.logError(e);
  }
}
 
Example #12
Source File: JavaHistoryActionImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
final JavaEditor getEditor(IFile file) {
	FileEditorInput fei= new FileEditorInput(file);
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
	for (int i= 0; i < windows.length; i++) {
		IWorkbenchPage[] pages= windows[i].getPages();
		for (int x= 0; x < pages.length; x++) {
			IEditorPart[] editors= pages[x].getDirtyEditors();
			for (int z= 0; z < editors.length; z++) {
				IEditorPart ep= editors[z];
				if (ep instanceof JavaEditor) {
					JavaEditor je= (JavaEditor) ep;
					if (fei.equals(je.getEditorInput()))
						return (JavaEditor) ep;
				}
			}
		}
	}
	return null;
}
 
Example #13
Source File: IntroduceParameterAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 * @param editor the java editor
 *
 * @noreference This constructor is not intended to be referenced by clients.
 */
public IntroduceParameterAction(JavaEditor editor) {
	super(editor.getEditorSite());
	setText(RefactoringMessages.IntroduceParameterAction_label);
	fEditor= editor;
	setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null);
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.INTRODUCE_PARAMETER_ACTION);
}
 
Example #14
Source File: MultiOrganizeImportAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public MultiOrganizeImportAction(JavaEditor editor) {
	super(editor);

	setText(ActionMessages.OrganizeImportsAction_label);
	setToolTipText(ActionMessages.OrganizeImportsAction_tooltip);
	setDescription(ActionMessages.OrganizeImportsAction_description);

	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.ORGANIZE_IMPORTS_ACTION);
}
 
Example #15
Source File: AbstractInfoView.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Finds and returns the Java element selected in the given part.
 *
 * @param part the workbench part for which to find the selected Java element
 * @param selection the selection
 * @return the selected Java element
 */
protected IJavaElement findSelectedJavaElement(IWorkbenchPart part, ISelection selection) {
	Object element;
	try {
		if (part instanceof JavaEditor && selection instanceof ITextSelection) {
			JavaEditor editor = (JavaEditor)part;
			IJavaElement[] elements= TextSelectionConverter.codeResolve(editor, (ITextSelection)selection);
			if (elements != null && elements.length > 0) {
				return elements[0];
			} else {
				// if we haven't selected anything useful, try the enclosing method call
				IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
				ISelection methodSelection = guessMethodNamePosition(document, (ITextSelection)selection);
				// if an enclosing method call could not be found
				if (methodSelection == null)
					return null;
				// call this method recursively with the new selection
				return findSelectedJavaElement(part, methodSelection);
			}
		} else if (selection instanceof IStructuredSelection) {
			element= SelectionUtil.getSingleElement(selection);
		} else {
			return null;
		}
	} catch (JavaModelException e) {
		return null;
	}

	return findJavaElement(element);
}
 
Example #16
Source File: ExtractConstantAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 * @param editor the java editor
 *
 * @noreference This constructor is not intended to be referenced by clients.
 */
public ExtractConstantAction(JavaEditor editor) {
	super(editor.getEditorSite());
	setText(RefactoringMessages.ExtractConstantAction_label);
	fEditor= editor;
	setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null);
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EXTRACT_CONSTANT_ACTION);
}
 
Example #17
Source File: OpenViewActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 * @param part the editor part
 *
 * @noreference This constructor is not intended to be referenced by clients.
 */
public OpenViewActionGroup(JavaEditor part) {
	fEditorIsOwner= true;
	fShowShowInMenu= false;
	
	fOpenImplementation= new OpenImplementationAction(part);
	fOpenImplementation.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_IMPLEMENTATION);
	part.setAction("OpenImplementation", fOpenImplementation); //$NON-NLS-1$

	fOpenSuperImplementation= new OpenSuperImplementationAction(part);
	fOpenSuperImplementation.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_SUPER_IMPLEMENTATION);
	part.setAction("OpenSuperImplementation", fOpenSuperImplementation); //$NON-NLS-1$

	fOpenAttachedJavadoc= new OpenAttachedJavadocAction(part);
	fOpenAttachedJavadoc.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_ATTACHED_JAVADOC);
	part.setAction("OpenAttachedJavadoc", fOpenAttachedJavadoc); //$NON-NLS-1$

	fOpenTypeHierarchy= new OpenTypeHierarchyAction(part);
	fOpenTypeHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);
	part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); //$NON-NLS-1$

	fOpenCallHierarchy= new OpenCallHierarchyAction(part);
	fOpenCallHierarchy.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
	part.setAction("OpenCallHierarchy", fOpenCallHierarchy); //$NON-NLS-1$

	initialize(part.getEditorSite().getSelectionProvider());
}
 
Example #18
Source File: JavaHistoryAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
final void init(JavaEditor editor, String text, String title, String message) {
	Assert.isNotNull(editor);
	Assert.isNotNull(title);
	Assert.isNotNull(message);
	fEditor= editor;
	fTitle= title;
	fMessage= message;
	//getDelegate().init(editor, text, title, message);
	setText(text);
	//setEnabled(getDelegate().checkEnabled());
}
 
Example #19
Source File: GWTOpenEditorActionGroup.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call
 * this constructor.
 * 
 * @param editor the Java editor
 */
public GWTOpenEditorActionGroup(JavaEditor editor) {
  isEditorOwner = true;
  openAction = new GWTOpenAction(editor);
  openAction.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR);
  editor.setAction("OpenEditor", openAction); //$NON-NLS-1$
  site = editor.getEditorSite();
  initialize(site.getSelectionProvider());
}
 
Example #20
Source File: DefaultJavaFoldingStructureProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * Subclasses may extend.
 * </p>
 *
 * @param editor {@inheritDoc}
 * @param viewer {@inheritDoc}
 */
public void install(ITextEditor editor, ProjectionViewer viewer) {
	Assert.isLegal(editor != null);
	Assert.isLegal(viewer != null);

	internalUninstall();

	if (editor instanceof JavaEditor) {
		fProjectionListener= new ProjectionListener(viewer);
		fEditor= (JavaEditor)editor;
	}
}
 
Example #21
Source File: ActiveJavaEditorOffsetProvider.java    From SparkBuilderGenerator with MIT License 5 votes vote down vote up
public int provideOffsetOfCurrentCursorPosition() {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart activeEditor = page.getActiveEditor();
    if (activeEditor instanceof JavaEditor) {
        JavaEditor javaEditor = (JavaEditor) activeEditor;
        ISelection selection = javaEditor.getSelectionProvider().getSelection();
        if (selection instanceof ITextSelection) {
            ITextSelection iTextSelection = (ITextSelection) selection;
            return iTextSelection.getOffset();
        }
    }
    return 0;
}
 
Example #22
Source File: TextSelectionConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static IJavaElement getInput(JavaEditor editor) {
	if (editor == null)
		return null;
	IEditorInput input= editor.getEditorInput();
	if (input instanceof IClassFileEditorInput)
		return ((IClassFileEditorInput)input).getClassFile();
	IWorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager();
	return manager.getWorkingCopy(input);
}
 
Example #23
Source File: ExtractTempAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 * @param editor the java editor
 *
 * @noreference This method is not intended to be referenced by clients.
 */
public ExtractTempAction(JavaEditor editor) {
	super(editor.getEditorSite());
	setText(RefactoringMessages.ExtractTempAction_label);
	fEditor= editor;
	setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null);
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EXTRACT_TEMP_ACTION);
}
 
Example #24
Source File: OpenEditorActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 * @param editor the Java editor
 *
 * @noreference This constructor is not intended to be referenced by clients.
 */
public OpenEditorActionGroup(JavaEditor editor) {
	fIsEditorOwner= true;
	fOpen= new OpenAction(editor);
	fOpen.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR);
	editor.setAction("OpenEditor", fOpen); //$NON-NLS-1$
	fSite= editor.getEditorSite();
	fSelectionProvider= fSite.getSelectionProvider();
	initialize();
}
 
Example #25
Source File: StructureSelectHistoryAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public StructureSelectHistoryAction(JavaEditor editor, SelectionHistory history) {
	super(SelectionActionMessages.StructureSelectHistory_label);
	setToolTipText(SelectionActionMessages.StructureSelectHistory_tooltip);
	setDescription(SelectionActionMessages.StructureSelectHistory_description);
	Assert.isNotNull(history);
	Assert.isNotNull(editor);
	fHistory= history;
	fEditor= editor;
	update();
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.STRUCTURED_SELECTION_HISTORY_ACTION);
}
 
Example #26
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 #27
Source File: QuickAssistProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean getRenameRefactoringProposal(IInvocationContext context, ASTNode node, IProblemLocation[] locations, Collection<ICommandAccess> resultingCollections)
		throws CoreException {
	if (!(context instanceof AssistContext)) {
		return false;
	}
	IEditorPart editor= ((AssistContext)context).getEditor();
	if (!(editor instanceof JavaEditor))
		return false;
	
	if (!(node instanceof SimpleName)) {
		return false;
	}
	SimpleName name= (SimpleName) node;
	IBinding binding= name.resolveBinding();
	if (binding == null) {
		return false;
	}
	
	IJavaElement javaElement= binding.getJavaElement();
	if (javaElement == null || !RefactoringAvailabilityTester.isRenameElementAvailable(javaElement)) {
		return false;
	}
	
	if (resultingCollections == null) {
		return true;
	}
	
	RenameRefactoringProposal proposal= new RenameRefactoringProposal((JavaEditor) editor);
	if (locations.length != 0) {
		proposal.setRelevance(IProposalRelevance.RENAME_REFACTORING_ERROR);
	} else if (containsQuickFixableRenameLocal(locations)) {
		proposal.setRelevance(IProposalRelevance.RENAME_REFACTORING_QUICK_FIX);
	}
	

	resultingCollections.add(proposal);
	return true;
}
 
Example #28
Source File: JavaContentAssistHandler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ITextEditor getActiveEditor() {
	IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window != null) {
		IWorkbenchPage page= window.getActivePage();
		if (page != null) {
			IEditorPart editor= page.getActiveEditor();
			if (editor instanceof ITextEditor)
				return (JavaEditor) editor;
		}
	}
	return null;
}
 
Example #29
Source File: ConvertAnonymousToNestedAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Note: This constructor is for internal use only. Clients should not call this constructor.
 * @param editor the java editor
 *
 * @noreference This constructor is not intended to be referenced by clients.
 */
public ConvertAnonymousToNestedAction(JavaEditor editor) {
	super(editor.getEditorSite());
	setText(RefactoringMessages.ConvertAnonymousToNestedAction_Convert_Anonymous);
	fEditor= editor;
	setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null);
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.CONVERT_ANONYMOUS_TO_NESTED_ACTION);
}
 
Example #30
Source File: SelectionConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static IType getTypeAtOffset(JavaEditor editor) throws JavaModelException {
	IJavaElement element= SelectionConverter.getElementAtOffset(editor);
	IType type= (IType)element.getAncestor(IJavaElement.TYPE);
	if (type == null) {
		ICompilationUnit unit= SelectionConverter.getInputAsCompilationUnit(editor);
		if (unit != null)
			type= unit.findPrimaryType();
	}
	return type;
}