Bug 47838 Make refactoring menu selection sensitive in editor [refactoring]
M5 Currently all refactoring actions are enabled in the editor's context menu. Make them selection dependent. Check if code resolve might be enough (no need to create an AST).
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/IntroduceFactoryAction.java
public void selectionChanged(ITextSelection selection) {
		setEnabled(checkEnabled(selection));
	}
	
	/*
	 * @see SelectionDispatchAction#selectionChanged(IStructuredSelection)
	 */
	public void selectionChanged(IStructuredSelection selection) {
		try {
			setEnabled(canEnable(selection));
		} catch (JavaModelException e) {
			if (JavaModelUtil.filterNotPresentException(e))
				JavaPlugin.log(e);
			setEnabled(false);
		}
	}
	private static IntroduceFactoryRefactoring createRefactoring(ICompilationUnit cunit, ITextSelection selection) throws CoreException {
		return IntroduceFactoryRefactoring.create(cunit, 
				selection.getOffset(), selection.getLength(),
				JavaPreferencesSettings.getCodeGenerationSettings());
	}
	private RefactoringWizard createWizard(IntroduceFactoryRefactoring refactoring) {
		String pageTitle= RefactoringMessages.getString("IntroduceFactoryAction.use_factory"); 
		return new IntroduceFactoryWizard(refactoring, pageTitle);
	}
	private boolean checkEnabled(ITextSelection selection) {
		return fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null;
	}
}