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


Java QuestionAction类代码示例

本文整理汇总了Java中com.intellij.codeInsight.hint.QuestionAction的典型用法代码示例。如果您正苦于以下问题:Java QuestionAction类的具体用法?Java QuestionAction怎么用?Java QuestionAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


QuestionAction类属于com.intellij.codeInsight.hint包,在下文中一共展示了QuestionAction类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: moveClass

import com.intellij.codeInsight.hint.QuestionAction; //导入依赖的package包/类
private void moveClass(Project project, Editor editor, PsiFile file, PsiClass aClass) {
  RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler();
  DataManager dataManager = DataManager.getInstance();
  DataContext dataContext = dataManager.getDataContext();
  final String fqName = aClass.getQualifiedName();
  LOG.assertTrue(fqName != null);
  PsiDirectory directory = PackageUtil
    .findOrCreateDirectoryForPackage(myCurrentModule, StringUtil.getPackageName(fqName), mySourceRoot, true);
  DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory, dataContext);

  moveHandler.invoke(project, new PsiElement[]{aClass}, context);
  PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
  PsiClass newClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.moduleScope(myCurrentModule));
  if (reference != null && newClass != null) {
    final QuestionAction action = new AddImportAction(project, reference, editor, newClass);
    action.execute();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:MoveClassToModuleFix.java

示例2: moveClass

import com.intellij.codeInsight.hint.QuestionAction; //导入依赖的package包/类
private void moveClass(Project project, Editor editor, PsiFile file, PsiClass aClass) {
  RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler();
  DataManager dataManager = DataManager.getInstance();
  DataContext dataContext = dataManager.getDataContext();
  final String fqName = aClass.getQualifiedName();
  LOG.assertTrue(fqName != null);
  PsiDirectory directory = PackageUtil
    .findOrCreateDirectoryForPackage(myCurrentModule, StringUtil.getPackageName(fqName), mySourceRoot, true);
  DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT, directory, dataContext);

  moveHandler.invoke(project, new PsiElement[]{aClass}, context);
  PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
  PsiClass newClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.moduleScope(myCurrentModule));
  if (reference != null && newClass != null) {
    final QuestionAction action = new AddImportAction(project, reference, editor, newClass);
    action.execute();
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:MoveClassToModuleFix.java

示例3: doFix

import com.intellij.codeInsight.hint.QuestionAction; //导入依赖的package包/类
private ImportClassFixBase.Result doFix(Editor editor)
	{
		if(!CodeInsightSettings.getInstance().ADD_MEMBER_IMPORTS_ON_THE_FLY)
		{
			return ImportClassFixBase.Result.POPUP_NOT_SHOWN;
		}
		final List<T> candidates = getMembersToImport(true);
		if(candidates.isEmpty())
		{
			return ImportClassFixBase.Result.POPUP_NOT_SHOWN;
		}

		final PsiElement element = getElement();
		if(element == null)
		{
			return ImportClassFixBase.Result.POPUP_NOT_SHOWN;
		}

		final QuestionAction action = createQuestionAction(candidates, element.getProject(), editor);
	/* PsiFile psiFile = element.getContainingFile();
   if (candidates.size() == 1 &&
        ImportClassFixBase.isAddUnambiguousImportsOnTheFlyEnabled(psiFile) &&
        (ApplicationManager.getApplication().isUnitTestMode() || DaemonListeners.canChangeFileSilently(psiFile)) &&
        !LaterInvocator.isInModalContext()) {
      CommandProcessor.getInstance().runUndoTransparentAction(() -> action.execute());
      return ImportClassFixBase.Result.CLASS_AUTO_IMPORTED;
    }
*/
		String hintText = ShowAutoImportPass.getMessage(candidates.size() > 1, getMemberPresentableText(candidates.get(0)));
		if(!ApplicationManager.getApplication().isUnitTestMode() && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true))
		{
			final TextRange textRange = element.getTextRange();
			HintManager.getInstance().showQuestionHint(editor, hintText, textRange.getStartOffset(), textRange.getEndOffset(), action);
		}
		return ImportClassFixBase.Result.POPUP_SHOWN;
	}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:37,代码来源:StaticImportMemberFix.java

示例4: doFix

import com.intellij.codeInsight.hint.QuestionAction; //导入依赖的package包/类
public Result doFix(@NotNull final Editor editor, boolean allowPopup, final boolean allowCaretNearRef) {
  List<PsiClass> classesToImport = getClassesToImport();
  if (classesToImport.isEmpty()) return Result.POPUP_NOT_SHOWN;

  try {
    String name = getQualifiedName(myElement);
    if (name != null) {
      Pattern pattern = Pattern.compile(DaemonCodeAnalyzerSettings.getInstance().NO_AUTO_IMPORT_PATTERN);
      Matcher matcher = pattern.matcher(name);
      if (matcher.matches()) {
        return Result.POPUP_NOT_SHOWN;
      }
    }
  }
  catch (PatternSyntaxException e) {
    //ignore
  }
  final PsiFile psiFile = myElement.getContainingFile();
  if (classesToImport.size() > 1) {
    reduceSuggestedClassesBasedOnDependencyRuleViolation(psiFile, classesToImport);
  }
  PsiClass[] classes = classesToImport.toArray(new PsiClass[classesToImport.size()]);
  final Project project = myElement.getProject();
  CodeInsightUtil.sortIdenticalShortNameClasses(classes, myRef);

  final QuestionAction action = createAddImportAction(classes, project, editor);

  boolean canImportHere = true;

  if (classes.length == 1
      && (canImportHere = canImportHere(allowCaretNearRef, editor, psiFile, classes[0].getName()))
      && (FileTypeUtils.isInServerPageFile(psiFile) ?
          CodeInsightSettings.getInstance().JSP_ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY :
          CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY)
      && (ApplicationManager.getApplication().isUnitTestMode() || DaemonListeners.canChangeFileSilently(psiFile))
      && !autoImportWillInsertUnexpectedCharacters(classes[0])
      && !LaterInvocator.isInModalContext()
    ) {
    CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
      @Override
      public void run() {
        action.execute();
      }
    });
    return Result.CLASS_AUTO_IMPORTED;
  }

  if (allowPopup && canImportHere) {
    String hintText = ShowAutoImportPass.getMessage(classes.length > 1, classes[0].getQualifiedName());
    if (!ApplicationManager.getApplication().isUnitTestMode() && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) {
      HintManager.getInstance().showQuestionHint(editor, hintText, getStartOffset(myElement, myRef),
                                                 getEndOffset(myElement, myRef), action);
    }
    return Result.POPUP_SHOWN;
  }
  return Result.POPUP_NOT_SHOWN;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:58,代码来源:ImportClassFixBase.java

示例5: invokeImpl

import com.intellij.codeInsight.hint.QuestionAction; //导入依赖的package包/类
public static void invokeImpl(Project project, Editor editor, final PsiFile file, Injectable injectable) {
  final PsiLanguageInjectionHost host = findInjectionHost(editor, file);
  if (host == null) return;
  if (defaultFunctionalityWorked(host, injectable.getId())) return;

  try {
    host.putUserData(FIX_KEY, null);
    Language language = injectable.toLanguage();
    for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
      if (support.isApplicableTo(host) && support.addInjectionInPlace(language, host)) {
        return;
      }
    }
    if (TemporaryPlacesRegistry.getInstance(project).getLanguageInjectionSupport().addInjectionInPlace(language, host)) {
      final Processor<PsiLanguageInjectionHost> data = host.getUserData(FIX_KEY);
      String text = StringUtil.escapeXml(language.getDisplayName()) + " was temporarily injected.";
      if (data != null) {
        if (!ApplicationManager.getApplication().isUnitTestMode()) {
          final SmartPsiElementPointer<PsiLanguageInjectionHost> pointer =
            SmartPointerManager.getInstance(project).createSmartPsiElementPointer(host);
          final TextRange range = host.getTextRange();
          HintManager.getInstance().showQuestionHint(editor, text + "<br>Do you want to insert annotation? " + KeymapUtil
            .getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS)),
                                                     range.getStartOffset(), range.getEndOffset(), new QuestionAction() {
            @Override
            public boolean execute() {
              return data.process(pointer.getElement());
            }
          });
        }
      }
      else {
        HintManager.getInstance().showInformationHint(editor, text);
      }
    }
  }
  finally {
    if (injectable.getLanguage() != null) {    // no need for reference injection
      FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
    }
    else {
      ((PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker()).incCounter();
      DaemonCodeAnalyzer.getInstance(project).restart();
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:47,代码来源:InjectLanguageAction.java

示例6: doFix

import com.intellij.codeInsight.hint.QuestionAction; //导入依赖的package包/类
public Result doFix(@NotNull final Editor editor, boolean allowPopup, final boolean allowCaretNearRef) {
  List<PsiClass> classesToImport = getClassesToImport();
  if (classesToImport.isEmpty()) return Result.POPUP_NOT_SHOWN;

  try {
    String name = getQualifiedName(myElement);
    if (name != null) {
      Pattern pattern = Pattern.compile(DaemonCodeAnalyzerSettings.getInstance().NO_AUTO_IMPORT_PATTERN);
      Matcher matcher = pattern.matcher(name);
      if (matcher.matches()) {
        return Result.POPUP_NOT_SHOWN;
      }
    }
  }
  catch (PatternSyntaxException e) {
    //ignore
  }
  final PsiFile psiFile = myElement.getContainingFile();
  if (classesToImport.size() > 1) {
    reduceSuggestedClassesBasedOnDependencyRuleViolation(psiFile, classesToImport);
  }
  PsiClass[] classes = classesToImport.toArray(new PsiClass[classesToImport.size()]);
  final Project project = myElement.getProject();
  CodeInsightUtil.sortIdenticalShortNameClasses(classes, myRef);

  final QuestionAction action = createAddImportAction(classes, project, editor);

  DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project);

  boolean canImportHere = true;

  if (classes.length == 1
      && (canImportHere = canImportHere(allowCaretNearRef, editor, psiFile, classes[0].getName()))
      && (JspPsiUtil.isInJspFile(psiFile) ?
          CodeInsightSettings.getInstance().JSP_ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY :
          CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY)
      && (ApplicationManager.getApplication().isUnitTestMode() || codeAnalyzer.canChangeFileSilently(psiFile))
      && !autoImportWillInsertUnexpectedCharacters(classes[0])
      && !LaterInvocator.isInModalContext()
    ) {
    CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
      @Override
      public void run() {
        action.execute();
      }
    });
    return Result.CLASS_AUTO_IMPORTED;
  }

  if (allowPopup && canImportHere) {
    String hintText = ShowAutoImportPass.getMessage(classes.length > 1, classes[0].getQualifiedName());
    if (!ApplicationManager.getApplication().isUnitTestMode() && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) {
      HintManager.getInstance().showQuestionHint(editor, hintText, getStartOffset(myElement, myRef),
                                                 getEndOffset(myElement, myRef), action);
    }
    return Result.POPUP_SHOWN;
  }
  return Result.POPUP_NOT_SHOWN;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:60,代码来源:ImportClassFixBase.java

示例7: createQuestionAction

import com.intellij.codeInsight.hint.QuestionAction; //导入依赖的package包/类
@NotNull
protected abstract QuestionAction createQuestionAction(List<T> methodsToImport, @NotNull Project project, Editor editor);
 
开发者ID:consulo,项目名称:consulo-java,代码行数:3,代码来源:StaticImportMemberFix.java

示例8: doFix

import com.intellij.codeInsight.hint.QuestionAction; //导入依赖的package包/类
public Result doFix(@NotNull final Editor editor, boolean allowPopup, final boolean allowCaretNearRef)
{
	List<PsiClass> classesToImport = getClassesToImport();
	if(classesToImport.isEmpty())
	{
		return Result.POPUP_NOT_SHOWN;
	}

	try
	{
		String name = getQualifiedName(myElement);
		if(name != null)
		{
			Pattern pattern = Pattern.compile(DaemonCodeAnalyzerSettings.getInstance().NO_AUTO_IMPORT_PATTERN);
			Matcher matcher = pattern.matcher(name);
			if(matcher.matches())
			{
				return Result.POPUP_NOT_SHOWN;
			}
		}
	}
	catch(PatternSyntaxException e)
	{
		//ignore
	}
	final PsiFile psiFile = myElement.getContainingFile();
	if(classesToImport.size() > 1)
	{
		reduceSuggestedClassesBasedOnDependencyRuleViolation(psiFile, classesToImport);
	}
	PsiClass[] classes = classesToImport.toArray(new PsiClass[classesToImport.size()]);
	final Project project = myElement.getProject();
	CodeInsightUtil.sortIdenticalShortNamedMembers(classes, myRef);

	final QuestionAction action = createAddImportAction(classes, project, editor);

	boolean canImportHere = true;

	boolean isInModlessContext = ModalityPerProjectEAPDescriptor.is() ? !LaterInvocator.isInModalContextForProject(editor.getProject()) : !LaterInvocator.isInModalContext();

	if(classes.length == 1 && (canImportHere = canImportHere(allowCaretNearRef, editor, psiFile, classes[0].getName())) && isAddUnambiguousImportsOnTheFlyEnabled(psiFile) && (ApplicationManager
			.getApplication().isUnitTestMode() || DaemonListeners.canChangeFileSilently(psiFile)) && isInModlessContext && !autoImportWillInsertUnexpectedCharacters(classes[0]))
	{
		CommandProcessor.getInstance().runUndoTransparentAction(() -> action.execute());
		return Result.CLASS_AUTO_IMPORTED;
	}

	if(allowPopup && canImportHere)
	{
		String hintText = ShowAutoImportPass.getMessage(classes.length > 1, classes[0].getQualifiedName());
		if(!ApplicationManager.getApplication().isUnitTestMode() && !HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true))
		{
			HintManager.getInstance().showQuestionHint(editor, hintText, getStartOffset(myElement, myRef), getEndOffset(myElement, myRef), action);
		}
		return Result.POPUP_SHOWN;
	}
	return Result.POPUP_NOT_SHOWN;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:59,代码来源:ImportClassFixBase.java


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